Exemplo n.º 1
0
        public static GetBillingAgreementDetailsResponse InvokeGetBillingAgreementDetails(IOffAmazonPaymentsService service, GetBillingAgreementDetailsRequest request)
        {
            GetBillingAgreementDetailsResponse response = null;

            try
            {
                response = service.GetBillingAgreementDetails(request);

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

                Console.WriteLine("        GetBillingAgreementDetailsResponse");
                if (response.IsSetGetBillingAgreementDetailsResult())
                {
                    Console.WriteLine("            GetBillingAgreementDetailsResult");
                    GetBillingAgreementDetailsResult getBillingAgreementDetailsResult = response.GetBillingAgreementDetailsResult;
                    if (getBillingAgreementDetailsResult.IsSetBillingAgreementDetails())
                    {
                        Console.WriteLine("                BillingAgreementDetails");
                        BillingAgreementDetails billingAgreementDetails = getBillingAgreementDetailsResult.BillingAgreementDetails;
                        if (billingAgreementDetails.IsSetAmazonBillingAgreementId())
                        {
                            Console.WriteLine("                    AmazonBillingAgreementId");
                            Console.WriteLine("                        {0}", billingAgreementDetails.AmazonBillingAgreementId);
                        }
                        if (billingAgreementDetails.IsSetBillingAgreementLimits())
                        {
                            Console.WriteLine("                    BillingAgreementLimits");
                            BillingAgreementLimits billingAgreementLimits = billingAgreementDetails.BillingAgreementLimits;
                            if (billingAgreementLimits.IsSetAmountLimitPerTimePeriod())
                            {
                                Console.WriteLine("                        AmountLimitPerTimePeriod");
                                Price amountLimitPerTimePeriod = billingAgreementLimits.AmountLimitPerTimePeriod;
                                if (amountLimitPerTimePeriod.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", amountLimitPerTimePeriod.Amount);
                                }
                                if (amountLimitPerTimePeriod.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", amountLimitPerTimePeriod.CurrencyCode);
                                }
                            }
                            if (billingAgreementLimits.IsSetTimePeriodStartDate())
                            {
                                Console.WriteLine("                        TimePeriodStartDate");
                                Console.WriteLine("                            {0}", billingAgreementLimits.TimePeriodStartDate);
                            }
                            if (billingAgreementLimits.IsSetTimePeriodEndDate())
                            {
                                Console.WriteLine("                        TimePeriodEndDate");
                                Console.WriteLine("                            {0}", billingAgreementLimits.TimePeriodEndDate);
                            }
                            if (billingAgreementLimits.IsSetCurrentRemainingBalance())
                            {
                                Console.WriteLine("                        CurrentRemainingBalance");
                                Price currentRemainingBalance = billingAgreementLimits.CurrentRemainingBalance;
                                if (currentRemainingBalance.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", currentRemainingBalance.Amount);
                                }
                                if (currentRemainingBalance.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", currentRemainingBalance.CurrencyCode);
                                }
                            }
                        }
                        if (billingAgreementDetails.IsSetBuyer())
                        {
                            Console.WriteLine("                    Buyer");
                            Buyer buyer = billingAgreementDetails.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 (billingAgreementDetails.IsSetSellerNote())
                        {
                            Console.WriteLine("                    SellerNote");
                            Console.WriteLine("                        {0}", billingAgreementDetails.SellerNote);
                        }
                        if (billingAgreementDetails.IsSetPlatformId())
                        {
                            Console.WriteLine("                    PlatformId");
                            Console.WriteLine("                        {0}", billingAgreementDetails.PlatformId);
                        }
                        if (billingAgreementDetails.IsSetDestination())
                        {
                            Console.WriteLine("                    Destination");
                            Destination destination = billingAgreementDetails.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 (billingAgreementDetails.IsSetBillingAddress())
                        {
                            Console.WriteLine("                    BillingAddress");
                            BillingAddress billingAddress = billingAgreementDetails.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 (billingAgreementDetails.IsSetReleaseEnvironment())
                        {
                            Console.WriteLine("                    ReleaseEnvironment");
                            Console.WriteLine("                        {0}", billingAgreementDetails.ReleaseEnvironment);
                        }
                        if (billingAgreementDetails.IsSetSellerBillingAgreementAttributes())
                        {
                            Console.WriteLine("                    SellerBillingAgreementAttributes");
                            SellerBillingAgreementAttributes sellerBillingAgreementAttributes = billingAgreementDetails.SellerBillingAgreementAttributes;
                            if (sellerBillingAgreementAttributes.IsSetSellerBillingAgreementId())
                            {
                                Console.WriteLine("                        SellerBillingAgreementId");
                                Console.WriteLine("                            {0}", sellerBillingAgreementAttributes.SellerBillingAgreementId);
                            }
                            if (sellerBillingAgreementAttributes.IsSetStoreName())
                            {
                                Console.WriteLine("                        StoreName");
                                Console.WriteLine("                            {0}", sellerBillingAgreementAttributes.StoreName);
                            }
                            if (sellerBillingAgreementAttributes.IsSetCustomInformation())
                            {
                                Console.WriteLine("                        CustomInformation");
                                Console.WriteLine("                            {0}", sellerBillingAgreementAttributes.CustomInformation);
                            }
                        }
                        if (billingAgreementDetails.IsSetBillingAgreementStatus())
                        {
                            Console.WriteLine("                    BillingAgreementStatus");
                            BillingAgreementStatus billingAgreementStatus = billingAgreementDetails.BillingAgreementStatus;
                            if (billingAgreementStatus.IsSetState())
                            {
                                Console.WriteLine("                        State");
                                Console.WriteLine("                            {0}", billingAgreementStatus.State);
                            }
                            if (billingAgreementStatus.IsSetLastUpdatedTimestamp())
                            {
                                Console.WriteLine("                        LastUpdatedTimestamp");
                                Console.WriteLine("                            {0}", billingAgreementStatus.LastUpdatedTimestamp);
                            }
                            if (billingAgreementStatus.IsSetReasonCode())
                            {
                                Console.WriteLine("                        ReasonCode");
                                Console.WriteLine("                            {0}", billingAgreementStatus.ReasonCode);
                            }
                            if (billingAgreementStatus.IsSetReasonDescription())
                            {
                                Console.WriteLine("                        ReasonDescription");
                                Console.WriteLine("                            {0}", billingAgreementStatus.ReasonDescription);
                            }
                        }
                        if (billingAgreementDetails.IsSetConstraints())
                        {
                            Console.WriteLine("                    Constraints");
                            Constraints       constraints    = billingAgreementDetails.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 (billingAgreementDetails.IsSetCreationTimestamp())
                        {
                            Console.WriteLine("                    CreationTimestamp");
                            Console.WriteLine("                        {0}", billingAgreementDetails.CreationTimestamp);
                        }
                        if (billingAgreementDetails.IsSetExpirationTimestamp())
                        {
                            Console.WriteLine("                    ExpirationTimestamp");
                            Console.WriteLine("                        {0}", billingAgreementDetails.ExpirationTimestamp);
                        }
                        if (billingAgreementDetails.IsSetBillingAgreementConsent())
                        {
                            Console.WriteLine("                    BillingAgreementConsent");
                            Console.WriteLine("                        {0}", billingAgreementDetails.BillingAgreementConsent);
                        }
                    }
                }
                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(OffAmazonPaymentsServiceAutomaticPaymentsSimpleCheckout automaticPayments,
                                      string billingAgreementId, double paymentAmount, int shippingOption)
        {
            /************************************************************************
             * Invoke Get Billing Agreement Details Action
             ***********************************************************************/
            GetBillingAgreementDetailsResponse getDetailsResponse = automaticPayments.GetBillingAgreementDetails();

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

            /************************************************************************
             * Add the tax and shipping rates here
             * Get the rates by using the CountryCode and the StateOrRegionCode from the billingAgreementDetails
             ***********************************************************************/
            Destination         destination = getDetailsResponse.GetBillingAgreementDetailsResult.BillingAgreementDetails.Destination;
            TaxAndShippingRates rates       = new TaxAndShippingRates(destination);
            string totalAmount = rates.getTotalAmountWithTaxAndShipping(paymentAmount, 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 Billing Agreement Details Action
             ***********************************************************************/
            if (automaticPayments.SetBillingAgreementDetails() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from SetBillingAgreementDetails request is null");
            }
            Console.WriteLine("=============================================================================");

            /************************************************************************
             * Invoke Confirm Billing Agreement Action
             ***********************************************************************/
            if (automaticPayments.ConfirmBillingAgreement() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from ConfirmBillingAgreement request is null");
            }
            Console.WriteLine("=============================================================================");

            /************************************************************************
             * Invoke Validate Billing Agreement Action (Optional)
             ***********************************************************************/
            if (automaticPayments.ValidateBillingAgreement() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from ValidateBillingAgreement request is null");
            }
            Console.WriteLine("=============================================================================");

            /************************************************************************
             * Make the first payment
             ***********************************************************************/
            MakePayment(automaticPayments, totalAmount, 1, false);

            /************************************************************************
             * Make the second payment
             ***********************************************************************/
            MakePayment(automaticPayments, totalAmount, 2, false);

            /************************************************************************
             * Make the third payment with capture now
             ***********************************************************************/
            MakePayment(automaticPayments, totalAmount, 3, true);

            /************************************************************************
             * Invoke Close Billing Agreement Action
             ***********************************************************************/
            if (automaticPayments.CloseBillingAgreement() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from CloseBillingAgreement request is null");
            }
        }
        private void RunSample(OffAmazonPaymentsServiceAutomaticPaymentsSimpleCheckout automaticPayments,
                               string billingAgreementId, string paymentAmount, int shippingOption)
        {
            /************************************************************************
             * Invoke Get Billing Agreement Details Action
             ***********************************************************************/
            GetBillingAgreementDetailsResponse getDetailsResponse = automaticPayments.GetBillingAgreementDetails();

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

            /************************************************************************
             * Add the tax and shipping rates here
             * Get the rates by using the CountryCode and the StateOrRegionCode from the billingAgreementDetails
             ***********************************************************************/
            Destination         destination = getDetailsResponse.GetBillingAgreementDetailsResult.BillingAgreementDetails.Destination;
            TaxAndShippingRates rates       = new TaxAndShippingRates(destination);
            string totalAmount = rates.getTotalAmountWithTaxAndShipping(Convert.ToDouble(paymentAmount), 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 Billing Agreement Details Action
             ***********************************************************************/
            if (automaticPayments.SetBillingAgreementDetails() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from SetBillingAgreementDetails request is null");
            }

            /************************************************************************
             * Invoke Confirm Billing Agreement Action
             ***********************************************************************/
            if (automaticPayments.ConfirmBillingAgreement() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from ConfirmBillingAgreement request is null");
            }

            /************************************************************************
             * Invoke Validate Billing Agreement Action (Optional)
             ***********************************************************************/
            if (automaticPayments.ValidateBillingAgreement() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from ValidateBillingAgreement request is null");
            }

            /************************************************************************
             * Make the first payment
             ***********************************************************************/
            MakePayment(automaticPayments, totalAmount, 1, false);

            /************************************************************************
             * Make the second payment
             ***********************************************************************/
            MakePayment(automaticPayments, totalAmount, 2, false);

            /************************************************************************
             * Make the third payment with capture now
             ***********************************************************************/
            MakePayment(automaticPayments, totalAmount, 3, true);

            /************************************************************************
             * Invoke Close Billing Agreement Action
             ***********************************************************************/
            if (automaticPayments.CloseBillingAgreement() == null)
            {
                throw new OffAmazonPaymentsServiceException("The response from CloseBillingAgreement request is null");
            }

            /************************************************************************
             * Wait for the notification from ipn.aspx page in a loop, then print the corresponding information
             ***********************************************************************/
            lblNotification.Text += formatStringForDisplay(WaitAndGetNotificationDetails(billingAgreementId + "_BillingAgreement"));
        }