public static ProviderCreditSummaryList CheckCaptureForProviderCreditSummaryList(string amazonCaptureId, OffAmazonPaymentsServicePropertyCollection propertiesCollection, IOffAmazonPaymentsService service)
        {
            //used to check if the ProviderCreditSummaryList is available
            TimeSpan startTime = DateTime.Now.TimeOfDay;
            GetCaptureDetailsResponse getCaptureDetailsResponse = GetCaptureDetailsSample.GetCaptureDetails(propertiesCollection, service, amazonCaptureId);

            while (getCaptureDetailsResponse.IsSetGetCaptureDetailsResult() && (!getCaptureDetailsResponse.GetCaptureDetailsResult.CaptureDetails.IsSetProviderCreditSummaryList() || getCaptureDetailsResponse.GetCaptureDetailsResult.CaptureDetails.ProviderCreditSummaryList.member.Count < 1))
            {
                if (DateTime.Now.TimeOfDay.Milliseconds - startTime.Milliseconds > 60000)
                {
                    throw new OffAmazonPaymentsServiceException("The ProviderCreditSummaryList not found.");
                }
                System.Threading.Thread.Sleep(8000);
                Console.WriteLine("Waiting until ProviderCreditSummaryList is found in GetCaptureDetailsResponse");
                getCaptureDetailsResponse = GetCaptureDetailsSample.GetCaptureDetails(propertiesCollection, service, amazonCaptureId);
            }
            return(getCaptureDetailsResponse.GetCaptureDetailsResult.CaptureDetails.ProviderCreditSummaryList);
        }
示例#2
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 GetCaptureDetailsResponse InvokeGetCaptureDetails(IOffAmazonPaymentsService service, GetCaptureDetailsRequest request)
        {
            GetCaptureDetailsResponse response = null;

            try
            {
                response = service.GetCaptureDetails(request);
                Console.WriteLine("Service Response");
                Console.WriteLine("=============================================================================");
                Console.WriteLine();
                Console.WriteLine("        GetCaptureDetailsResponse");
                if (response.IsSetGetCaptureDetailsResult())
                {
                    Console.WriteLine("            GetCaptureDetailsResult");
                    GetCaptureDetailsResult getCaptureDetailsResult = response.GetCaptureDetailsResult;
                    if (getCaptureDetailsResult.IsSetCaptureDetails())
                    {
                        Console.WriteLine("                CaptureDetails");
                        CaptureDetails captureDetails = getCaptureDetailsResult.CaptureDetails;
                        if (captureDetails.IsSetAmazonCaptureId())
                        {
                            Console.WriteLine("                    AmazonCaptureId");
                            Console.WriteLine("                        {0}", captureDetails.AmazonCaptureId);
                        }
                        if (captureDetails.IsSetCaptureReferenceId())
                        {
                            Console.WriteLine("                    CaptureReferenceId");
                            Console.WriteLine("                        {0}", captureDetails.CaptureReferenceId);
                        }
                        if (captureDetails.IsSetSellerCaptureNote())
                        {
                            Console.WriteLine("                    SellerCaptureNote");
                            Console.WriteLine("                        {0}", captureDetails.SellerCaptureNote);
                        }
                        if (captureDetails.IsSetCaptureAmount())
                        {
                            Console.WriteLine("                    CaptureAmount");
                            Price captureAmount = captureDetails.CaptureAmount;
                            if (captureAmount.IsSetAmount())
                            {
                                Console.WriteLine("                        Amount");
                                Console.WriteLine("                            {0}", captureAmount.Amount);
                            }
                            if (captureAmount.IsSetCurrencyCode())
                            {
                                Console.WriteLine("                        CurrencyCode");
                                Console.WriteLine("                            {0}", captureAmount.CurrencyCode);
                            }
                        }
                        if (captureDetails.IsSetRefundedAmount())
                        {
                            Console.WriteLine("                    RefundedAmount");
                            Price refundedAmount = captureDetails.RefundedAmount;
                            if (refundedAmount.IsSetAmount())
                            {
                                Console.WriteLine("                        Amount");
                                Console.WriteLine("                            {0}", refundedAmount.Amount);
                            }
                            if (refundedAmount.IsSetCurrencyCode())
                            {
                                Console.WriteLine("                        CurrencyCode");
                                Console.WriteLine("                            {0}", refundedAmount.CurrencyCode);
                            }
                        }
                        if (captureDetails.IsSetCaptureFee())
                        {
                            Console.WriteLine("                    CaptureFee");
                            Price captureFee = captureDetails.CaptureFee;
                            if (captureFee.IsSetAmount())
                            {
                                Console.WriteLine("                        Amount");
                                Console.WriteLine("                            {0}", captureFee.Amount);
                            }
                            if (captureFee.IsSetCurrencyCode())
                            {
                                Console.WriteLine("                        CurrencyCode");
                                Console.WriteLine("                            {0}", captureFee.CurrencyCode);
                            }
                        }
                        if (captureDetails.IsSetCreationTimestamp())
                        {
                            Console.WriteLine("                    CreationTimestamp");
                            Console.WriteLine("                        {0}", captureDetails.CreationTimestamp);
                        }
                        if (captureDetails.IsSetProviderCreditSummaryList())
                        {
                            Console.WriteLine("                    ProviderCreditSummaryList");
                            foreach (ProviderCreditSummary providerCreditSummary in captureDetails.ProviderCreditSummaryList.member)
                            {
                                if (providerCreditSummary.IsSetProviderCreditId())
                                {
                                    Console.WriteLine("                         ProviderCreditId");
                                    Console.WriteLine("                             {0}", providerCreditSummary.ProviderCreditId);
                                }
                                if (providerCreditSummary.IsSetProviderId())
                                {
                                    Console.WriteLine("                         ProviderId");
                                    Console.WriteLine("                             {0}", providerCreditSummary.ProviderId);
                                }
                            }
                        }
                        if (captureDetails.IsSetCaptureStatus())
                        {
                            Console.WriteLine("                    CaptureStatus");
                            Status captureStatus = captureDetails.CaptureStatus;
                            if (captureStatus.IsSetState())
                            {
                                Console.WriteLine("                        State");
                                Console.WriteLine("                            {0}", captureStatus.State);
                            }
                            if (captureStatus.IsSetLastUpdateTimestamp())
                            {
                                Console.WriteLine("                        LastUpdateTimestamp");
                                Console.WriteLine("                            {0}", captureStatus.LastUpdateTimestamp);
                            }
                            if (captureStatus.IsSetReasonCode())
                            {
                                Console.WriteLine("                        ReasonCode");
                                Console.WriteLine("                            {0}", captureStatus.ReasonCode);
                            }
                            if (captureStatus.IsSetReasonDescription())
                            {
                                Console.WriteLine("                        ReasonDescription");
                                Console.WriteLine("                            {0}", captureStatus.ReasonDescription);
                            }
                        }
                    }
                }
                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);
        }
        private static void RunSample(string orderReferenceId, double orderAmount, int shippingOption, OffAmazonPaymentsServiceProviderCheckout providerCheckout, 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(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 = providerCheckout.SetOrderReferenceDetails(totalAmount);

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

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

            /************************************************************************
             * Invoke Authorize Action
             ***********************************************************************/
            AuthorizeResponse authResponse = providerCheckout.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
                 ***********************************************************************/
                providerCheckout.CheckAuthorizationStatus(authResponse);
            }

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

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

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

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

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


            /************************************************************************
             * Invoke GetProviderCreditDetails Action
             ***********************************************************************/
            if (!String.IsNullOrEmpty(providerId) && !String.IsNullOrEmpty(creditAmount))
            {
                //Wait till the the ProviderCreditSummaryList is available in the GetCaptureDetailsResponse
                ProviderCreditSummaryList providerCreditSummaryList = providerCheckout.CheckCaptureForProviderCreditSummaryList(captureResponse);
                foreach (ProviderCreditSummary providerCreditSummary in providerCreditSummaryList.member)
                {
                    GetProviderCreditDetailsResponse getProviderCreditDetailsResponse = providerCheckout.GetProviderCreditDetails(providerCreditSummary);
                    if (getProviderCreditDetailsResponse == null)
                    {
                        throw new OffAmazonPaymentsServiceException("The response from GetProviderCreditDetails request is null for ProviderCreditId:" + providerCreditSummary.ProviderCreditId);
                    }
                    Console.WriteLine("=============================================================================");
                }
            }

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