Ejemplo n.º 1
0
        private void RunSample(string orderReferenceId, string orderAmount, OffAmazonPaymentsServiceSimpleCheckout instance)
        {
            /************************************************************************
             * Invoke Set Order Reference Details Action
             ***********************************************************************/
            SetOrderReferenceDetailsResponse setOrderDetailsResponse = instance.SetOrderReferenceDetails(orderAmount);

            if (setOrderDetailsResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from SetOrderReference request is null");
            }

            /************************************************************************
             * Invoke Confirm Order Reference Action
             ***********************************************************************/
            if (instance.ConfirmOrderReferenceObject() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from ConfirmOrderResponse request is null");
            }

            /************************************************************************
             * Invoke Authorize Action
             ***********************************************************************/
            AuthorizeResponse authResponse = instance.AuthorizeAction(setOrderDetailsResponse, 1);

            if (authResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from Authorization Response request is null");
            }

            /************************************************************************
             * Wait for the notification from ipn.aspx page in a loop, then print the corresponding information
             ***********************************************************************/
            lblNotification.Text += WaitAndGetNotificationDetails(authResponse.AuthorizeResult.AuthorizationDetails.AmazonAuthorizationId + "_Authorize");

            instance.CheckAuthorizationStatus(authResponse);

            OffAmazonPaymentsServiceCancellation cancelInstance = new OffAmazonPaymentsServiceCancellation();

            /************************************************************************
             * Invoke Cancel Order Reference Action
             ***********************************************************************/
            CancelOrderReferenceResponse cancelResponse = cancelInstance.CancelOrderReference(orderReferenceId);

            if (cancelResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from the CancelOrderReference request is null");
            }
        }
Ejemplo n.º 2
0
        private void RunSampleMultiShipments(string orderAmount, OffAmazonPaymentsServiceMultipleShipment instance)
        {
            /************************************************************************
             * Invoke Get Order Reference Details Action
             ***********************************************************************/
            GetOrderReferenceDetailsResponse getOrderDetails = instance.GetOrderReferenceDetails();

            if (getOrderDetails == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from GetOrderReference request is null");
            }

            Address address = getOrderDetails.GetOrderReferenceDetailsResult.OrderReferenceDetails.Destination.PhysicalDestination;

            lblShipping.Text = "The shipping address is: " + address.City + "<br>" + address.StateOrRegion + "<br>" + address.PostalCode + "<br>";

            /************************************************************************
             * Invoke Set Order Reference Details Action
             ***********************************************************************/
            SetOrderReferenceDetailsResponse setOrderDetailsResponse = instance.SetOrderReferenceDetails(orderAmount);

            if (setOrderDetailsResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from SetOrderReference request is null");
            }

            /************************************************************************
             * Invoke Confirm Order Reference Action
             ***********************************************************************/
            if (instance.ConfirmOrderReferenceObject() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from ConfirmOrderResponse request is null");
            }

            //iterate the authoriztion amount in the authList
            for (int i = 0; i < numberOfShipment; i++)
            {
                String eachOrderAmount = amountEachShip[i].ToString();

                /************************************************************************
                 * Invoke Authorize Action
                 ***********************************************************************/
                AuthorizeResponse authResponse = instance.AuthorizeAction(eachOrderAmount, indicator);
                if (authResponse == null)
                {
                    throw new OffAmazonPaymentsServiceException("The response from Authorization Response request is null");
                }

                /************************************************************************
                 * Wait for the notification from ipn.aspx page in a loop, then print the corresponding information
                 ***********************************************************************/
                lblNotification.Text += WaitAndGetNotificationDetails(authResponse.AuthorizeResult.AuthorizationDetails.AmazonAuthorizationId + "_Authorize");

                instance.CheckAuthorizationStatus(authResponse);

                /************************************************************************
                 * Invoke Capture Action
                 ***********************************************************************/
                CaptureResponse captureResponse = instance.CaptureAction(authResponse, eachOrderAmount, indicator);
                if (captureResponse == null)
                {
                    throw new OffAmazonPaymentsServiceException("The response from Caputre Response request is null");
                }

                lblNotification.Text += WaitAndGetNotificationDetails(captureResponse.CaptureResult.CaptureDetails.AmazonCaptureId + "_Capture");

                /************************************************************************
                 * Invoke Get Capture Details Action
                 ***********************************************************************/
                if (instance.GetCaptureDetails(captureResponse) == null)
                {
                    throw new OffAmazonPaymentsServiceException("The response from GetCaputreDetails Response request is null");
                }

                indicator++;
            }

            /************************************************************************
             * Invoke Close Order Reference Action
             ***********************************************************************/
            if (instance.CloseOrderReference() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from CloseOrderReference Response request is null");
            }

            lblNotification.Text += WaitAndGetNotificationDetails(orderReferenceId + "_OrderReference");
        }
        private static void RunSampleMultiShipments(string orderReferenceId, string orderAmount, OffAmazonPaymentsServiceMultipleShipment instance)
        {
            /************************************************************************
             * Invoke Get Order Reference Details Action
             ***********************************************************************/
            GetOrderReferenceDetailsResponse getOrderDetails = instance.GetOrderReferenceDetails();

            if (getOrderDetails == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from GetOrderReference request is null");
            }
            Console.WriteLine("=======================================================");

            /************************************************************************
             * Invoke Set Order Reference Details Action
             ***********************************************************************/
            SetOrderReferenceDetailsResponse setOrderDetailsResponse = instance.SetOrderReferenceDetails(orderAmount);

            if (setOrderDetailsResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from SetOrderReference request is null");
            }
            Console.WriteLine("=======================================================");

            /************************************************************************
             * Invoke Confirm Order Reference Action
             ***********************************************************************/
            if (instance.ConfirmOrderReferenceObject() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from ConfirmOrderResponse request is null");
            }
            Console.WriteLine("=======================================================");
            Console.WriteLine("===========================================");
            Console.WriteLine("Here is the demo of one capture per authorization.");
            Console.WriteLine("===========================================");
            Console.WriteLine();

            IDictionary <string, OrderItem> orderList = instance.OrderList;

            Console.WriteLine("Current orders are listed as below: ");
            instance.ShowCurrentOrders();
            System.Threading.Thread.Sleep(3000);

            //iterate the authoriztion amount in the authList
            foreach (string item in orderList.Keys)
            {
                String eachOrderAmount = (orderList[item].Price * orderList[item].Number).ToString();

                /************************************************************************
                 * Invoke Authorize Action
                 ***********************************************************************/
                AuthorizeResponse authResponse = instance.AuthorizeAction(eachOrderAmount, indicator);
                if (authResponse == null)
                {
                    throw new OffAmazonPaymentsServiceException("The response from Authorization Response request is null");
                }
                Console.WriteLine("=======================================================");

                /************************************************************************
                 * Check the authorization status unitl it is not "PENDING" any more
                 * GetAuthorizeDetails is contained in this method
                 ***********************************************************************/
                instance.CheckAuthorizationStatus(authResponse);

                /************************************************************************
                 * Invoke Capture Action
                 ***********************************************************************/
                CaptureResponse captureResponse = instance.CaptureAction(authResponse, eachOrderAmount, indicator);
                if (captureResponse == null)
                {
                    throw new OffAmazonPaymentsServiceException("The response from Caputre Response request is null");
                }
                Console.WriteLine("=======================================================");

                /************************************************************************
                 * Invoke GetCaptureDetails Action
                 ***********************************************************************/
                if (instance.GetCaptureDetails(captureResponse) == null)
                {
                    throw new OffAmazonPaymentsServiceException("The response from GetCaputreDetails Response request is null");
                }
                Console.WriteLine("=======================================================");

                indicator++;
            }

            /************************************************************************
             * Invoke CloseOrderReference Action
             ***********************************************************************/
            if (instance.CloseOrderReference() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from CloseOrderReference Response request is null");
            }
        }
        //Invoke the Authorize method
        public AuthorizeResponse AuthorizeAction(SetOrderReferenceDetailsResponse setOrderReferenceDetailsResponse, int authorizationOption)
        {
            string orderAmount = setOrderReferenceDetailsResponse.SetOrderReferenceDetailsResult.OrderReferenceDetails.OrderTotal.Amount;

            return(AuthorizeSample.AuthorizeAction(propertiesCollection, service, orderReferenceId, orderAmount, 0, authorizationOption));
        }
Ejemplo n.º 5
0
        private void RunSample(OffAmazonPaymentsServiceProviderCheckout providerCheckout,
                               string orderReferenceId, string orderAmount, int shippingOption, int authorizationOption, string providerId, string creditAmount)
        {
            /************************************************************************
             * Invoke Get Order Reference Details Action
             ***********************************************************************/
            GetOrderReferenceDetailsResponse getOrderDetails = providerCheckout.GetOrderReferenceDetails();

            if (getOrderDetails == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from GetOrderReference request is null");
            }

            /************************************************************************
             * Add the tax and shipping rates here
             * Get the rates by using the CountryCode and the StateOrRegionCode from the orderReferenceDetails
             ***********************************************************************/
            Destination         destination = getOrderDetails.GetOrderReferenceDetailsResult.OrderReferenceDetails.Destination;
            TaxAndShippingRates rates       = new TaxAndShippingRates(destination);
            string totalAmount = rates.getTotalAmountWithTaxAndShipping(Convert.ToDouble(orderAmount), shippingOption).ToString("0.##");

            Address address = destination.PhysicalDestination;

            lblShipping.Text = "The shipping address is: <br>" + address.City + "<br>" + address.StateOrRegion + "<br>" + address.PostalCode + "<br>"
                               + "The total amount with tax and shipping is: " + totalAmount + "<br>";

            /************************************************************************
             * Invoke Set Order Reference Details Action
             ***********************************************************************/
            SetOrderReferenceDetailsResponse setOrderDetailsResponse = providerCheckout.SetOrderReferenceDetails(totalAmount);

            if (setOrderDetailsResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from SetOrderReference request is null");
            }

            /************************************************************************
             * Invoke Confirm Order Reference Action
             ***********************************************************************/
            if (providerCheckout.ConfirmOrderReferenceObject() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from ConfirmOrderResponse request is null");
            }

            /************************************************************************
             * Invoke Authorize Action
             ***********************************************************************/
            AuthorizeResponse authResponse = providerCheckout.AuthorizeAction(setOrderDetailsResponse, authorizationOption);

            if (authResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from Authorization Response request is null");
            }

            /************************************************************************
             * Wait for the notification from ipn.aspx page in a loop, then print the corresponding information
             ***********************************************************************/
            lblNotification.Text += formatStringForDisplay(WaitAndGetNotificationDetails(authResponse.AuthorizeResult.AuthorizationDetails.AmazonAuthorizationId + "_Authorize"));
            GetAuthorizationDetailsResponse response = providerCheckout.CheckAuthorizationStatus(authResponse);

            /************************************************************************
             * On an IPN callback, call GetAuthorizationDetails to retreive additional
             * information about the authorization - this is done as part of the
             * previous call to check the status.
             ***********************************************************************/
            StringWriter stringWriter = new StringWriter();

            GetAuthorizationDetailsSample.printGetAuthorizationDetailsResponseToBuffer(response, stringWriter);
            lblNotification.Text += formatStringForDisplay(stringWriter.ToString());

            /************************************************************************
             * Invoke Capture Action
             ***********************************************************************/
            CaptureResponse captureResponse = providerCheckout.CaptureActionWithProviderCredit(authResponse, totalAmount, providerId, creditAmount);

            if (captureResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from Caputre Response request is null");
            }

            /************************************************************************
             * Wait for the notification from ipn.aspx page in a loop, then print the corresponding information
             ***********************************************************************/
            lblNotification.Text += formatStringForDisplay(WaitAndGetNotificationDetails(captureResponse.CaptureResult.CaptureDetails.AmazonCaptureId + "_Capture"));

            /************************************************************************
             * Invoke Get Capture Details Action
             ***********************************************************************/
            GetCaptureDetailsResponse getCaptureDetailsResponse = providerCheckout.GetCaptureDetails(captureResponse);

            if (getCaptureDetailsResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from GetCaputreDetails Response request is null");
            }

            /************************************************************************
             * Invoke GetProviderCreditDetails Action
             ***********************************************************************/
            if (!String.IsNullOrEmpty(providerId) && !String.IsNullOrEmpty(creditAmount))
            {
                /************************************************************************
                 * Wait till the the ProviderCreditSummaryList is available in the GetCaptureDetailsResponse
                 ***********************************************************************/
                OffAmazonPaymentsService.Model.ProviderCreditSummaryList providerCreditSummaryList = providerCheckout.CheckCaptureForProviderCreditSummaryList(captureResponse);
                foreach (OffAmazonPaymentsService.Model.ProviderCreditSummary providerCreditSummary in providerCreditSummaryList.member)
                {
                    /************************************************************************
                     * Wait for the notification from ipn.aspx page in a loop, then print the corresponding information
                     ***********************************************************************/
                    lblNotification.Text += formatStringForDisplay(WaitAndGetNotificationDetails(providerCreditSummary.ProviderCreditId + "_ProviderCredit"));
                    GetProviderCreditDetailsResponse getProviderCreditDetailsResponse = providerCheckout.GetProviderCreditDetails(providerCreditSummary);
                    if (getProviderCreditDetailsResponse == null)
                    {
                        throw new OffAmazonPaymentsServiceException("The response from GetProviderCreditDetails request is null for ProviderCreditId:" + providerCreditSummary.ProviderCreditId);
                    }
                }
            }

            /************************************************************************
             * Invoke CloseOrderReference Action
             ***********************************************************************/
            if (providerCheckout.CloseOrderReference() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from CloseOrderReference Response request is null");
            }

            /************************************************************************
             * Wait for the notification from ipn.aspx page in a loop, then print the corresponding information
             ***********************************************************************/
            lblNotification.Text += formatStringForDisplay(WaitAndGetNotificationDetails(orderReferenceId + "_OrderReference"));
        }
        public static SetOrderReferenceDetailsResponse InvokeSetOrderReferenceDetails(IOffAmazonPaymentsService service, SetOrderReferenceDetailsRequest request)
        {
            SetOrderReferenceDetailsResponse response = null;

            try
            {
                response = service.SetOrderReferenceDetails(request);
                Console.WriteLine("Service Response");
                Console.WriteLine("=============================================================================");
                Console.WriteLine();
                Console.WriteLine("        SetOrderReferenceDetailsResponse");
                if (response.IsSetSetOrderReferenceDetailsResult())
                {
                    Console.WriteLine("            SetOrderReferenceDetailsResult");
                    SetOrderReferenceDetailsResult setOrderReferenceDetailsResult = response.SetOrderReferenceDetailsResult;
                    if (setOrderReferenceDetailsResult.IsSetOrderReferenceDetails())
                    {
                        Console.WriteLine("                OrderReferenceDetails");
                        OrderReferenceDetails orderReferenceDetails = setOrderReferenceDetailsResult.OrderReferenceDetails;
                        if (orderReferenceDetails.IsSetAmazonOrderReferenceId())
                        {
                            Console.WriteLine("                    AmazonOrderReferenceId");
                            Console.WriteLine("                        {0}", orderReferenceDetails.AmazonOrderReferenceId);
                        }
                        if (orderReferenceDetails.IsSetBuyer())
                        {
                            Console.WriteLine("                    Buyer");
                            Buyer buyer = orderReferenceDetails.Buyer;
                            if (buyer.IsSetName())
                            {
                                Console.WriteLine("                        Name");
                                Console.WriteLine("                            {0}", buyer.Name);
                            }
                            if (buyer.IsSetEmail())
                            {
                                Console.WriteLine("                        Email");
                                Console.WriteLine("                            {0}", buyer.Email);
                            }
                            if (buyer.IsSetPhone())
                            {
                                Console.WriteLine("                        Phone");
                                Console.WriteLine("                            {0}", buyer.Phone);
                            }
                        }
                        if (orderReferenceDetails.IsSetOrderTotal())
                        {
                            Console.WriteLine("                    OrderTotal");
                            OrderTotal orderTotal = orderReferenceDetails.OrderTotal;
                            if (orderTotal.IsSetCurrencyCode())
                            {
                                Console.WriteLine("                        CurrencyCode");
                                Console.WriteLine("                            {0}", orderTotal.CurrencyCode);
                            }
                            if (orderTotal.IsSetAmount())
                            {
                                Console.WriteLine("                        Amount");
                                Console.WriteLine("                            {0}", orderTotal.Amount);
                            }
                        }
                        if (orderReferenceDetails.IsSetSellerNote())
                        {
                            Console.WriteLine("                    SellerNote");
                            Console.WriteLine("                        {0}", orderReferenceDetails.SellerNote);
                        }
                        if (orderReferenceDetails.IsSetPlatformId())
                        {
                            Console.WriteLine("                    PlatformId");
                            Console.WriteLine("                        {0}", orderReferenceDetails.PlatformId);
                        }
                        if (orderReferenceDetails.IsSetDestination())
                        {
                            Console.WriteLine("                    Destination");
                            Destination destination = orderReferenceDetails.Destination;
                            if (destination.IsSetDestinationType())
                            {
                                Console.WriteLine("                        DestinationType");
                                Console.WriteLine("                            {0}", destination.DestinationType);
                            }
                            if (destination.IsSetPhysicalDestination())
                            {
                                Console.WriteLine("                        PhysicalDestination");
                                Address physicalDestination = destination.PhysicalDestination;
                                if (physicalDestination.IsSetName())
                                {
                                    Console.WriteLine("                            Name");
                                    Console.WriteLine("                                {0}", physicalDestination.Name);
                                }
                                if (physicalDestination.IsSetAddressLine1())
                                {
                                    Console.WriteLine("                            AddressLine1");
                                    Console.WriteLine("                                {0}", physicalDestination.AddressLine1);
                                }
                                if (physicalDestination.IsSetAddressLine2())
                                {
                                    Console.WriteLine("                            AddressLine2");
                                    Console.WriteLine("                                {0}", physicalDestination.AddressLine2);
                                }
                                if (physicalDestination.IsSetAddressLine3())
                                {
                                    Console.WriteLine("                            AddressLine3");
                                    Console.WriteLine("                                {0}", physicalDestination.AddressLine3);
                                }
                                if (physicalDestination.IsSetCity())
                                {
                                    Console.WriteLine("                            City");
                                    Console.WriteLine("                                {0}", physicalDestination.City);
                                }
                                if (physicalDestination.IsSetCounty())
                                {
                                    Console.WriteLine("                            County");
                                    Console.WriteLine("                                {0}", physicalDestination.County);
                                }
                                if (physicalDestination.IsSetDistrict())
                                {
                                    Console.WriteLine("                            District");
                                    Console.WriteLine("                                {0}", physicalDestination.District);
                                }
                                if (physicalDestination.IsSetStateOrRegion())
                                {
                                    Console.WriteLine("                            StateOrRegion");
                                    Console.WriteLine("                                {0}", physicalDestination.StateOrRegion);
                                }
                                if (physicalDestination.IsSetPostalCode())
                                {
                                    Console.WriteLine("                            PostalCode");
                                    Console.WriteLine("                                {0}", physicalDestination.PostalCode);
                                }
                                if (physicalDestination.IsSetCountryCode())
                                {
                                    Console.WriteLine("                            CountryCode");
                                    Console.WriteLine("                                {0}", physicalDestination.CountryCode);
                                }
                                if (physicalDestination.IsSetPhone())
                                {
                                    Console.WriteLine("                            Phone");
                                    Console.WriteLine("                                {0}", physicalDestination.Phone);
                                }
                            }
                        }
                        if (orderReferenceDetails.IsSetBillingAddress())
                        {
                            Console.WriteLine("                    BillingAddress");
                            BillingAddress billingAddress = orderReferenceDetails.BillingAddress;
                            if (billingAddress.IsSetAddressType())
                            {
                                Console.WriteLine("                        AddressType");
                                Console.WriteLine("                            {0}", billingAddress.AddressType);
                            }
                            if (billingAddress.IsSetPhysicalAddress())
                            {
                                Console.WriteLine("                        PhysicalAddress");
                                Address physicalAddress = billingAddress.PhysicalAddress;
                                if (physicalAddress.IsSetName())
                                {
                                    Console.WriteLine("                            Name");
                                    Console.WriteLine("                                {0}", physicalAddress.Name);
                                }
                                if (physicalAddress.IsSetAddressLine1())
                                {
                                    Console.WriteLine("                            AddressLine1");
                                    Console.WriteLine("                                {0}", physicalAddress.AddressLine1);
                                }
                                if (physicalAddress.IsSetAddressLine2())
                                {
                                    Console.WriteLine("                            AddressLine2");
                                    Console.WriteLine("                                {0}", physicalAddress.AddressLine2);
                                }
                                if (physicalAddress.IsSetAddressLine3())
                                {
                                    Console.WriteLine("                            AddressLine3");
                                    Console.WriteLine("                                {0}", physicalAddress.AddressLine3);
                                }
                                if (physicalAddress.IsSetCity())
                                {
                                    Console.WriteLine("                            City");
                                    Console.WriteLine("                                {0}", physicalAddress.City);
                                }
                                if (physicalAddress.IsSetCounty())
                                {
                                    Console.WriteLine("                            County");
                                    Console.WriteLine("                                {0}", physicalAddress.County);
                                }
                                if (physicalAddress.IsSetDistrict())
                                {
                                    Console.WriteLine("                            District");
                                    Console.WriteLine("                                {0}", physicalAddress.District);
                                }
                                if (physicalAddress.IsSetStateOrRegion())
                                {
                                    Console.WriteLine("                            StateOrRegion");
                                    Console.WriteLine("                                {0}", physicalAddress.StateOrRegion);
                                }
                                if (physicalAddress.IsSetPostalCode())
                                {
                                    Console.WriteLine("                            PostalCode");
                                    Console.WriteLine("                                {0}", physicalAddress.PostalCode);
                                }
                                if (physicalAddress.IsSetCountryCode())
                                {
                                    Console.WriteLine("                            CountryCode");
                                    Console.WriteLine("                                {0}", physicalAddress.CountryCode);
                                }
                                if (physicalAddress.IsSetPhone())
                                {
                                    Console.WriteLine("                            Phone");
                                    Console.WriteLine("                                {0}", physicalAddress.Phone);
                                }
                            }
                        }
                        if (orderReferenceDetails.IsSetReleaseEnvironment())
                        {
                            Console.WriteLine("                    ReleaseEnvironment");
                            Console.WriteLine("                        {0}", orderReferenceDetails.ReleaseEnvironment);
                        }
                        if (orderReferenceDetails.IsSetSellerOrderAttributes())
                        {
                            Console.WriteLine("                    SellerOrderAttributes");
                            SellerOrderAttributes sellerOrderAttributes = orderReferenceDetails.SellerOrderAttributes;
                            if (sellerOrderAttributes.IsSetSellerOrderId())
                            {
                                Console.WriteLine("                        SellerOrderId");
                                Console.WriteLine("                            {0}", sellerOrderAttributes.SellerOrderId);
                            }
                            if (sellerOrderAttributes.IsSetStoreName())
                            {
                                Console.WriteLine("                        StoreName");
                                Console.WriteLine("                            {0}", sellerOrderAttributes.StoreName);
                            }
                            if (sellerOrderAttributes.IsSetOrderItemCategories())
                            {
                                Console.WriteLine("                        OrderItemCategories");
                                OrderItemCategories orderItemCategories   = sellerOrderAttributes.OrderItemCategories;
                                List <String>       orderItemCategoryList = orderItemCategories.OrderItemCategory;
                                foreach (String orderItemCategory in orderItemCategoryList)
                                {
                                    Console.WriteLine("                            OrderItemCategory");
                                    Console.WriteLine("                                {0}", orderItemCategory);
                                }
                            }
                            if (sellerOrderAttributes.IsSetCustomInformation())
                            {
                                Console.WriteLine("                        CustomInformation");
                                Console.WriteLine("                            {0}", sellerOrderAttributes.CustomInformation);
                            }
                        }
                        if (orderReferenceDetails.IsSetOrderReferenceStatus())
                        {
                            Console.WriteLine("                    OrderReferenceStatus");
                            OrderReferenceStatus orderReferenceStatus = orderReferenceDetails.OrderReferenceStatus;
                            if (orderReferenceStatus.IsSetState())
                            {
                                Console.WriteLine("                        State");
                                Console.WriteLine("                            {0}", orderReferenceStatus.State);
                            }
                            if (orderReferenceStatus.IsSetLastUpdateTimestamp())
                            {
                                Console.WriteLine("                        LastUpdateTimestamp");
                                Console.WriteLine("                            {0}", orderReferenceStatus.LastUpdateTimestamp);
                            }
                            if (orderReferenceStatus.IsSetReasonCode())
                            {
                                Console.WriteLine("                        ReasonCode");
                                Console.WriteLine("                            {0}", orderReferenceStatus.ReasonCode);
                            }
                            if (orderReferenceStatus.IsSetReasonDescription())
                            {
                                Console.WriteLine("                        ReasonDescription");
                                Console.WriteLine("                            {0}", orderReferenceStatus.ReasonDescription);
                            }
                        }
                        if (orderReferenceDetails.IsSetConstraints())
                        {
                            Console.WriteLine("                    Constraints");
                            Constraints       constraints    = orderReferenceDetails.Constraints;
                            List <Constraint> constraintList = constraints.Constraint;
                            foreach (Constraint constraint in constraintList)
                            {
                                Console.WriteLine("                        Constraint");
                                if (constraint.IsSetConstraintID())
                                {
                                    Console.WriteLine("                            ConstraintID");
                                    Console.WriteLine("                                {0}", constraint.ConstraintID);
                                }
                                if (constraint.IsSetDescription())
                                {
                                    Console.WriteLine("                            Description");
                                    Console.WriteLine("                                {0}", constraint.Description);
                                }
                            }
                        }
                        if (orderReferenceDetails.IsSetCreationTimestamp())
                        {
                            Console.WriteLine("                    CreationTimestamp");
                            Console.WriteLine("                        {0}", orderReferenceDetails.CreationTimestamp);
                        }
                        if (orderReferenceDetails.IsSetExpirationTimestamp())
                        {
                            Console.WriteLine("                    ExpirationTimestamp");
                            Console.WriteLine("                        {0}", orderReferenceDetails.ExpirationTimestamp);
                        }
                        if (orderReferenceDetails.IsSetIdList())
                        {
                            Console.WriteLine("                    IdList");
                            IdList        idList     = orderReferenceDetails.IdList;
                            List <String> memberList = idList.member;
                            foreach (String member in memberList)
                            {
                                Console.WriteLine("                        member");
                                Console.WriteLine("                            {0}", member);
                            }
                        }
                    }
                }
                if (response.IsSetResponseMetadata())
                {
                    Console.WriteLine("            ResponseMetadata");
                    ResponseMetadata responseMetadata = response.ResponseMetadata;
                    if (responseMetadata.IsSetRequestId())
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", responseMetadata.RequestId);
                    }
                }
            }
            catch (OffAmazonPaymentsServiceException ex)
            {
                PrintException(ex);
            }
            return(response);
        }
 //Invoke the Authorize method
 public AuthorizeResponse AuthorizeAction(SetOrderReferenceDetailsResponse setOrderReferenceDetailsResponse, int authorizationOption)
 {
     string orderAmount = setOrderReferenceDetailsResponse.SetOrderReferenceDetailsResult.OrderReferenceDetails.OrderTotal.Amount;
     return AuthorizeSample.AuthorizeAction(propertiesCollection, service, orderReferenceId, orderAmount, 0, authorizationOption);
 }
        private static void RunSample(string orderReferenceId, double orderAmount, int shippingOption, int authorizationOption, OffAmazonPaymentsServiceSimpleCheckout simpleCheckout)
        {
            /************************************************************************
             * Invoke Get Order Reference Details Action
             ***********************************************************************/
            GetOrderReferenceDetailsResponse getOrderDetails = simpleCheckout.GetOrderReferenceDetails();

            if (getOrderDetails == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from GetOrderReference request is null");
            }

            /************************************************************************
             * Add the tax and shipping rates here
             * Get the rates by using the CountryCode and the StateOrRegionCode from the orderReferenceDetails
             ***********************************************************************/

            Destination         destination = getOrderDetails.GetOrderReferenceDetailsResult.OrderReferenceDetails.Destination;
            TaxAndShippingRates rates       = new TaxAndShippingRates(destination);
            string totalAmount = rates.getTotalAmountWithTaxAndShipping(orderAmount, shippingOption).ToString("0.##");

            Console.WriteLine("=========================Tax and Shipping Calculation========================");
            Console.WriteLine("The tax and shipping rate will be calculated based on the CountryCode: " + destination.PhysicalDestination.CountryCode
                              + " and the StateOrRegionCode: " + destination.PhysicalDestination.StateOrRegion);
            Console.WriteLine("The total amount is " + totalAmount);
            Console.WriteLine("=============================================================================");

            /************************************************************************
             * Invoke Set Order Reference Details Action
             ***********************************************************************/
            SetOrderReferenceDetailsResponse setOrderDetailsResponse = simpleCheckout.SetOrderReferenceDetails(totalAmount);

            if (setOrderDetailsResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from SetOrderReference request is null");
            }
            Console.WriteLine("=============================================================================");

            /************************************************************************
             * Invoke Confirm Order Reference Action
             ***********************************************************************/
            if (simpleCheckout.ConfirmOrderReferenceObject() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from ConfirmOrderResponse request is null");
            }
            Console.WriteLine("=============================================================================");

            /************************************************************************
             * Invoke Authorize Action
             ***********************************************************************/
            AuthorizeResponse authResponse = simpleCheckout.AuthorizeAction(setOrderDetailsResponse, authorizationOption);

            if (authResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from Authorization request is null");
            }
            Console.WriteLine("=============================================================================");

            /************************************************************************
             * When Regular Asynchronous Authorization is used, the Authorization
             * State remains in pending and we need to wait for the state change.
             * Fast Authorization has a synchronous response and doesn't require this.
             ***********************************************************************/
            if (authorizationOption == 1)
            {
                /************************************************************************
                 * Check the authorization status unitl it is not "PENDING" any more
                 * GetAuthorizeDetails is contained in this method
                 ***********************************************************************/
                simpleCheckout.CheckAuthorizationStatus(authResponse);
            }

            /************************************************************************
             * Invoke Capture Action
             ***********************************************************************/
            CaptureResponse captureResponse = simpleCheckout.CaptureAction(authResponse, totalAmount);

            if (captureResponse == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from Caputre request is null");
            }

            Console.WriteLine("=============================================================================");

            /************************************************************************
             * Invoke GetCaptureDetails Action
             ***********************************************************************/
            if (simpleCheckout.GetCaptureDetails(captureResponse) == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from GetCaputreDetails request is null");
            }
            Console.WriteLine("=============================================================================");

            /************************************************************************
             * Invoke CloseOrderReference Action
             ***********************************************************************/
            if (simpleCheckout.CloseOrderReference() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from CloseOrderReference request is null");
            }
        }