public void AdditionalPaymentButton()
        {
            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000"
                          );

            request.WebCheckoutDetails.CheckoutMode          = CheckoutMode.ProcessOrder;
            request.AddressDetails.Name                      = "Paul Smith";
            request.AddressDetails.AddressLine1              = "9999 First Avenue";
            request.AddressDetails.City                      = "New York";
            request.AddressDetails.StateOrRegion             = "NY";
            request.AddressDetails.PostalCode                = "10016";
            request.AddressDetails.CountryCode               = "US";
            request.AddressDetails.PhoneNumber               = "212555555";
            request.AddressDetails.DistrictOrCounty          = "Manhattan";
            request.PaymentDetails.PaymentIntent             = PaymentIntent.AuthorizeWithCapture;
            request.PaymentDetails.ChargeAmount.Amount       = 10;
            request.PaymentDetails.ChargeAmount.CurrencyCode = Currency.USD;
            request.PaymentDetails.PresentmentCurrency       = Currency.USD;
            request.MerchantMetadata.MerchantReferenceId     = "Merchant Ref ID";
            request.MerchantMetadata.MerchantStoreName       = "Store Name";
            request.MerchantMetadata.NoteToBuyer             = "Buyer Note";

            // act
            string json  = request.ToJson();
            string json2 = request.ToJson();

            // assert
            Assert.AreEqual(json, json2);
            Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"addressDetails\":{\"districtOrCounty\":\"Manhattan\",\"name\":\"Paul Smith\",\"addressLine1\":\"9999 First Avenue\",\"city\":\"New York\",\"stateOrRegion\":\"NY\",\"postalCode\":\"10016\",\"countryCode\":\"US\",\"phoneNumber\":\"212555555\"},\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\",\"checkoutMode\":\"ProcessOrder\"},\"paymentDetails\":{\"paymentIntent\":\"AuthorizeWithCapture\",\"chargeAmount\":{\"amount\":10,\"currencyCode\":\"USD\"},\"presentmentCurrency\":\"USD\"},\"merchantMetadata\":{\"merchantReferenceId\":\"Merchant Ref ID\",\"merchantStoreName\":\"Store Name\",\"noteToBuyer\":\"Buyer Note\"}}", json);
        }
        public void CanConvertParameterlessCtorToJsonMinimal()
        {
            // arrange
            var request = new CreateCheckoutSessionRequest();

            // act
            string json  = request.ToJson();
            string json2 = request.ToJson();

            // assert
            Assert.AreEqual(json, json2);

            // verify request object still allows all setters after being serialized
            request.MerchantMetadata.CustomInformation   = metadataToTest.CustomInformation;
            request.MerchantMetadata.MerchantReferenceId = metadataToTest.MerchantReferenceId;
            request.MerchantMetadata.MerchantStoreName   = metadataToTest.MerchantStoreName;
            request.MerchantMetadata.NoteToBuyer         = metadataToTest.NoteToBuyer;
            request.ChargePermissionType                            = ChargePermissionType.Recurring;
            request.RecurringMetadata.Frequency.Unit                = FrequencyUnit.Variable;
            request.RecurringMetadata.Frequency.Value               = 2;
            request.RecurringMetadata.Amount.Amount                 = 12.34m;
            request.RecurringMetadata.Amount.CurrencyCode           = Currency.USD;
            request.DeliverySpecifications.AddressRestrictions.Type = RestrictionType.Allowed;
            request.DeliverySpecifications.AddressRestrictions.AddCountryRestriction("US")
            .AddZipCodesRestriction("12345");
            request.DeliverySpecifications.SpecialRestrictions.Add(SpecialRestriction.RestrictPackstations);
            request.DeliverySpecifications.SpecialRestrictions.Add(SpecialRestriction.RestrictPOBoxes);
            request.PaymentDetails.ChargeAmount.Amount           = 1080M;
            request.PaymentDetails.ChargeAmount.CurrencyCode     = Currency.EUR;
            request.PaymentDetails.TotalOrderAmount.Amount       = 1080M;
            request.PaymentDetails.TotalOrderAmount.CurrencyCode = Currency.EUR;
            request.PaymentDetails.PaymentIntent = PaymentIntent.Authorize;
        }
        public void CanConvertToJsonMinimalWithAllCheckoutSessionScopes()
        {
            CheckoutSessionScope[] scopes = new CheckoutSessionScope[] {
                CheckoutSessionScope.Name,
                CheckoutSessionScope.Email,
                CheckoutSessionScope.PostalCode,
                CheckoutSessionScope.ShippingAddress,
                CheckoutSessionScope.PhoneNumber,
                CheckoutSessionScope.PrimeStatus,
                CheckoutSessionScope.BillingAddress
            };

            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000",
                scopes
                          );

            // act
            string json  = request.ToJson();
            string json2 = request.ToJson();

            // assert
            Assert.AreEqual(json, json2);
            Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"scopes\":[\"name\",\"email\",\"postalCode\",\"shippingAddress\",\"phoneNumber\",\"primeStatus\",\"billingAddress\"],\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\"}}", json);
        }
        public void CanConvertToJsonRecurring()
        {
            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000"
                          );

            request.MerchantMetadata.CustomInformation   = metadataToTest.CustomInformation;
            request.MerchantMetadata.MerchantReferenceId = metadataToTest.MerchantReferenceId;
            request.MerchantMetadata.MerchantStoreName   = metadataToTest.MerchantStoreName;
            request.MerchantMetadata.NoteToBuyer         = metadataToTest.NoteToBuyer;
            request.ChargePermissionType                  = ChargePermissionType.Recurring;
            request.RecurringMetadata.Frequency.Unit      = FrequencyUnit.Variable;
            request.RecurringMetadata.Frequency.Value     = 2;
            request.RecurringMetadata.Amount.Amount       = 12.34m;
            request.RecurringMetadata.Amount.CurrencyCode = Currency.USD;

            // act
            string json  = request.ToJson();
            string json2 = request.ToJson();

            // assert
            Assert.AreEqual(json, json2);
            Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\"},\"merchantMetadata\":{\"merchantReferenceId\":\"123\",\"merchantStoreName\":\"myStore\",\"noteToBuyer\":\"myBuyerNote\",\"customInformation\":\"foo\"},\"chargePermissionType\":\"Recurring\",\"recurringMetadata\":{\"frequency\":{\"unit\":\"Variable\",\"value\":2},\"amount\":{\"amount\":12.34,\"currencyCode\":\"USD\"}}}", json);
        }
        public void DenySingleCountry()
        {
            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000"
                          );

            request.DeliverySpecifications.AddressRestrictions.Type = RestrictionType.NotAllowed;
            request.DeliverySpecifications.AddressRestrictions.AddCountryRestriction("US");

            // act
            var jsonResult  = request.ToJson();
            var jsonResult2 = request.ToJson();

            // assert
            Assert.AreEqual(jsonResult, jsonResult2);
            Assert.IsTrue(jsonResult.Contains("\"deliverySpecifications\":{\"addressRestrictions\":{\"type\":\"NotAllowed\",\"restrictions\":{\"US\":{}}}}"));
        }
        public void OneCountryWithOneStateAndOneZipCode()
        {
            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000"
                          );

            request.DeliverySpecifications.AddressRestrictions.Type = RestrictionType.Allowed;
            request.DeliverySpecifications.AddressRestrictions.AddCountryRestriction("DE").AddStateOrRegionRestriction("RLP").AddZipCodesRestriction("12345");

            // act
            var jsonResult  = request.ToJson();
            var jsonResult2 = request.ToJson();

            // assert
            Assert.AreEqual(jsonResult, jsonResult2);
            Assert.IsTrue(jsonResult.Contains("addressRestrictions\":{\"type\":\"Allowed\",\"restrictions\":{\"DE\":{\"statesOrRegions\":[\"RLP\"],\"zipCodes\":[\"12345\"]}}}}"));
        }
        public void OneCountryWithTwoStatesAndAnotherCountry()
        {
            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000"
                          );

            request.DeliverySpecifications.AddressRestrictions.Type = RestrictionType.Allowed;
            request.DeliverySpecifications.AddressRestrictions.AddCountryRestriction("US").AddStateOrRegionRestriction("WA").AddStateOrRegionRestriction("NY");
            request.DeliverySpecifications.AddressRestrictions.AddCountryRestriction("DE");

            // act
            var jsonResult  = request.ToJson();
            var jsonResult2 = request.ToJson();

            // assert
            Assert.AreEqual(jsonResult, jsonResult2);
            Assert.IsTrue(jsonResult.Contains("\"deliverySpecifications\":{\"addressRestrictions\":{\"type\":\"Allowed\",\"restrictions\":{\"US\":{\"statesOrRegions\":[\"WA\",\"NY\"]},\"DE\":{}}}}"));
        }
        public void AllowSingleCountryButApplySpecialRestrictions()
        {
            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000"
                          );

            request.DeliverySpecifications.AddressRestrictions.Type = RestrictionType.Allowed;
            request.DeliverySpecifications.AddressRestrictions.AddCountryRestriction("DE");
            request.DeliverySpecifications.SpecialRestrictions.Add(SpecialRestriction.RestrictPackstations);
            request.DeliverySpecifications.SpecialRestrictions.Add(SpecialRestriction.RestrictPOBoxes);

            // act
            var jsonResult  = request.ToJson();
            var jsonResult2 = request.ToJson();

            // assert
            Assert.AreEqual(jsonResult, jsonResult2);
            Assert.IsTrue(jsonResult.Contains("\"deliverySpecifications\":{\"specialRestrictions\":[\"RestrictPackstations\",\"RestrictPOBoxes\"],\"addressRestrictions\":{\"type\":\"Allowed\",\"restrictions\":{\"DE\":{}}}}"));
        }
        public void CanConvertToJsonMerchantMetaData()
        {
            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000"
                          );

            request.MerchantMetadata.CustomInformation   = metadataToTest.CustomInformation;
            request.MerchantMetadata.MerchantReferenceId = metadataToTest.MerchantReferenceId;
            request.MerchantMetadata.MerchantStoreName   = metadataToTest.MerchantStoreName;
            request.MerchantMetadata.NoteToBuyer         = metadataToTest.NoteToBuyer;

            // act
            string json  = request.ToJson();
            string json2 = request.ToJson();

            // assert
            Assert.AreEqual(json, json2);
            Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\"},\"merchantMetadata\":{\"merchantReferenceId\":\"123\",\"merchantStoreName\":\"myStore\",\"noteToBuyer\":\"myBuyerNote\",\"customInformation\":\"foo\"}}", json);
        }
        public void CanConvertToJsonDeliverySpecifications()
        {
            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000"
                          );

            request.DeliverySpecifications.AddressRestrictions.Type = RestrictionType.Allowed;
            request.DeliverySpecifications.AddressRestrictions.AddCountryRestriction("US").AddZipCodesRestriction("12345");
            request.DeliverySpecifications.SpecialRestrictions.Add(SpecialRestriction.RestrictPackstations);
            request.DeliverySpecifications.SpecialRestrictions.Add(SpecialRestriction.RestrictPOBoxes);

            // act
            string json  = request.ToJson();
            string json2 = request.ToJson();

            // assert
            Assert.AreEqual(json, json2);
            Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"deliverySpecifications\":{\"specialRestrictions\":[\"RestrictPackstations\",\"RestrictPOBoxes\"],\"addressRestrictions\":{\"type\":\"Allowed\",\"restrictions\":{\"US\":{\"zipCodes\":[\"12345\"]}}}},\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\"}}", json);
        }
        public void CanConvertToJsonMinimal()
        {
            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000"
                          );

            // act
            string json  = request.ToJson();
            string json2 = request.ToJson();

            // assert
            Assert.AreEqual(json, json2);
            Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\"}}", json);

            // verify request object still allows all setters after being serialized
            request.MerchantMetadata.CustomInformation   = metadataToTest.CustomInformation;
            request.MerchantMetadata.MerchantReferenceId = metadataToTest.MerchantReferenceId;
            request.MerchantMetadata.MerchantStoreName   = metadataToTest.MerchantStoreName;
            request.MerchantMetadata.NoteToBuyer         = metadataToTest.NoteToBuyer;
            request.ChargePermissionType                            = ChargePermissionType.Recurring;
            request.RecurringMetadata.Frequency.Unit                = FrequencyUnit.Variable;
            request.RecurringMetadata.Frequency.Value               = 2;
            request.RecurringMetadata.Amount.Amount                 = 12.34m;
            request.RecurringMetadata.Amount.CurrencyCode           = Currency.USD;
            request.DeliverySpecifications.AddressRestrictions.Type = RestrictionType.Allowed;
            request.DeliverySpecifications.AddressRestrictions.AddCountryRestriction("US").AddZipCodesRestriction("12345");
            request.DeliverySpecifications.SpecialRestrictions.Add(SpecialRestriction.RestrictPackstations);
            request.DeliverySpecifications.SpecialRestrictions.Add(SpecialRestriction.RestrictPOBoxes);
            request.PaymentDetails.ChargeAmount.Amount           = 1080M;
            request.PaymentDetails.ChargeAmount.CurrencyCode     = Currency.EUR;
            request.PaymentDetails.TotalOrderAmount.Amount       = 1080M;
            request.PaymentDetails.TotalOrderAmount.CurrencyCode = Currency.EUR;
            request.PaymentDetails.PaymentIntent = PaymentIntent.Authorize;
        }
        public void CanConvertToJsonWithCheckoutSessionScope()
        {
            CheckoutSessionScope[] scopes = new CheckoutSessionScope[] {
                CheckoutSessionScope.Name,
                CheckoutSessionScope.Email,
                CheckoutSessionScope.PostalCode,
            };

            // arrange
            var request = new CreateCheckoutSessionRequest
                          (
                checkoutReviewReturnUrl: "https://example.com/review.html",
                storeId: "amzn1.application-oa2-client.000000000000000000000000000000000",
                scopes
                          );

            // act
            string json  = request.ToJson();
            string json2 = request.ToJson();

            // assert
            Assert.AreEqual(json, json2);
            Assert.AreEqual("{\"storeId\":\"amzn1.application-oa2-client.000000000000000000000000000000000\",\"scopes\":[\"name\",\"email\",\"postalCode\"],\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"https://example.com/review.html\"}}", json);
        }
        /// <summary>
        /// Generates the signature string for the Amazon Pay Checkout button.
        /// </summary>
        /// <param name="request">The payload for generating a CheckoutSession as CreateCheckoutSessionRequest object.</param>
        /// <returns>Signature string that can be assigned to the front-end button's "signature" parameter.</returns>
        public string GenerateButtonSignature(CreateCheckoutSessionRequest request)
        {
            var signature = GenerateButtonSignature(request.ToJson());

            return(signature);
        }