public void CreateGiftCardValue()
        {
            const int valueToAdd = 1000;

            ICreateGiftCardValue  createInterface  = ClientModuleIntegrationTestingUtilities.GetSandboxedLevelUpModule <ICreateGiftCardValue>();
            ILookupUserLoyalty    loyaltyInterface = ClientModuleIntegrationTestingUtilities.GetSandboxedLevelUpModule <ILookupUserLoyalty>();
            IDestroyGiftCardValue destroyInterface = ClientModuleIntegrationTestingUtilities.GetSandboxedLevelUpModule <IDestroyGiftCardValue>();

            Loyalty initialLoyalty = loyaltyInterface.GetLoyalty(ClientModuleIntegrationTestingUtilities.SandboxedLevelUpUserAccessToken,
                                                                 LevelUpTestConfiguration.Current.MerchantId);

            var createdGiftCard = createInterface.GiftCardAddValue(ClientModuleIntegrationTestingUtilities.SandboxedLevelUpMerchantAccessToken,
                                                                   LevelUpTestConfiguration.Current.MerchantId,
                                                                   LevelUpTestConfiguration.Current.MerchantLocationId,
                                                                   LevelUpTestConfiguration.Current.ConsumerQrData,
                                                                   valueToAdd);

            Assert.AreEqual(createdGiftCard.AmountAddedInCents, valueToAdd);

            Loyalty postAdditionLoyalty = loyaltyInterface.GetLoyalty(ClientModuleIntegrationTestingUtilities.SandboxedLevelUpUserAccessToken,
                                                                      LevelUpTestConfiguration.Current.MerchantId);

            Assert.AreEqual(postAdditionLoyalty.PotentialCreditAmount - initialLoyalty.PotentialCreditAmount, valueToAdd);

            // Cleanup
            destroyInterface.GiftCardDestroyValue(ClientModuleIntegrationTestingUtilities.SandboxedLevelUpMerchantAccessToken,
                                                  LevelUpTestConfiguration.Current.MerchantId, LevelUpTestConfiguration.Current.ConsumerQrData, valueToAdd);

            Loyalty postDestructionLoyalty = loyaltyInterface.GetLoyalty(ClientModuleIntegrationTestingUtilities.SandboxedLevelUpUserAccessToken,
                                                                         LevelUpTestConfiguration.Current.MerchantId);

            Assert.AreEqual(postDestructionLoyalty.PotentialCreditAmount, initialLoyalty.PotentialCreditAmount);
        }
        private void AddThenDestroyGiftCardValue(int giftCardAmountToAdd, int giftCardAmountToDelete, string QrCode, string merchantToken)
        {
            IDestroyGiftCardValue destroyInterface = ClientModuleIntegrationTestingUtilities.GetSandboxedLevelUpModule <IDestroyGiftCardValue>();

            ClientModuleIntegrationTestingUtilities.RemoveAnyGiftCardCreditOnConsumerUserAccount();
            ClientModuleIntegrationTestingUtilities.AddGiftCardCreditOnConsumerUserAccount(giftCardAmountToAdd);

            var destroyed = destroyInterface.GiftCardDestroyValue(merchantToken,
                                                                  LevelUpTestConfiguration.Current.MerchantId,
                                                                  QrCode,
                                                                  giftCardAmountToDelete);

            Assert.AreEqual(destroyed.AmountRemovedInCents, giftCardAmountToDelete);
            Assert.AreEqual(destroyed.PreviousGiftCardAmountInCents, giftCardAmountToAdd);
            Assert.AreEqual(destroyed.NewGiftCardAmountInCents, giftCardAmountToAdd - giftCardAmountToDelete);

            IRetrieveMerchantFundedGiftCardCredit queryInterface = ClientModuleIntegrationTestingUtilities.GetSandboxedLevelUpModule <IRetrieveMerchantFundedGiftCardCredit>();
            var loyalty = queryInterface.GetMerchantFundedGiftCardCredit(
                ClientModuleIntegrationTestingUtilities.SandboxedLevelUpMerchantAccessToken,
                LevelUpTestConfiguration.Current.MerchantLocationId,
                LevelUpTestConfiguration.Current.ConsumerQrData);

            Assert.AreEqual(loyalty.TotalAmount, giftCardAmountToAdd - giftCardAmountToDelete);

            ClientModuleIntegrationTestingUtilities.RemoveAnyGiftCardCreditOnConsumerUserAccount();
        }
コード例 #3
0
        private static void RemoveAnyGiftCardOnAccount(int merchantId, int merchantLocationId, string userQrCode)
        {
            IRetrieveMerchantFundedGiftCardCredit creditClient = GetSandboxedLevelUpModule <IRetrieveMerchantFundedGiftCardCredit>();
            IDestroyGiftCardValue giftCardDestroyClient        = GetSandboxedLevelUpModule <IDestroyGiftCardValue>();

            var credit = creditClient.GetMerchantFundedGiftCardCredit(SandboxedLevelUpMerchantAccessToken,
                                                                      merchantLocationId, userQrCode);

            if (credit.TotalAmount == 0)
            {
                return;
            }

            giftCardDestroyClient.GiftCardDestroyValue(SandboxedLevelUpMerchantAccessToken,
                                                       merchantId, userQrCode, credit.TotalAmount);

            credit = creditClient.GetMerchantFundedGiftCardCredit(SandboxedLevelUpMerchantAccessToken,
                                                                  merchantLocationId, userQrCode);

            Assert.IsTrue(credit.TotalAmount == 0);
        }
        public void GiftCardDestroyValueShouldSucceed()
        {
            string paymentTokenData = "LU020000029080KFZ02I9A8V030000LU";
            int    merchantId       = 3;
            int    valueAmountCents = 100;
            int    initialTotalValueAtMerchantCents = 202;

            string expectedRequestUrl = string.Format(ClientModuleFunctionalTestingUtilities.SANDBOX_URL_PREFIX + "/v15/merchants/{0}/gift_card_value_removals", merchantId);

            string expectedRequestBody = string.Format("{{" +
                                                       "\"gift_card_value_removal\":{{" +
                                                       "\"payment_token_data\":\"{0}\"," +
                                                       "\"value_amount\":{1}" +
                                                       "}}" +
                                                       "}}",
                                                       paymentTokenData, valueAmountCents);


            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = string.Format("{{" +
                                           "\"gift_card_value_removal\":{{" +
                                           "\"removed_value_amount\":{0}," +
                                           "\"new_value_at_merchant_amount\":{1}," +
                                           "\"old_value_at_merchant_amount\":{2}," +
                                           "}}" +
                                           "}}",
                                           valueAmountCents, (initialTotalValueAtMerchantCents - valueAmountCents), initialTotalValueAtMerchantCents)
            };

            IDestroyGiftCardValue client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IDestroyGiftCardValue, GiftCardRemoveValueRequest>(
                expectedResponse, expectedRequestBody, expectedRequestUrl: expectedRequestUrl);

            var destroyed = client.GiftCardDestroyValue("not_checking_this", merchantId, paymentTokenData, valueAmountCents);

            Assert.AreEqual(destroyed.AmountRemovedInCents, valueAmountCents);
            Assert.AreEqual(destroyed.PreviousGiftCardAmountInCents, initialTotalValueAtMerchantCents);
            Assert.AreEqual(destroyed.NewGiftCardAmountInCents, initialTotalValueAtMerchantCents - valueAmountCents);
        }
        public void GiftCardDestroyValueShouldFailForBadHttpStatusCodes()
        {
            List <RestResponse> possibleErrors = new List <RestResponse>(new RestResponse[]
            {
                new RestResponse // Invalid QR code
                {
                    StatusCode = HttpStatusCode.NotFound
                },

                new RestResponse // Destroy value was negative
                {
                    StatusCode = (HttpStatusCode)422,
                    Content    = "[{\"error\":{\"object\":\"gift_cards/value_adder\",\"property\":\"base\",\"message\":\"You must remove a positive value.\"}}]"
                },

                new RestResponse // Destroy value was more than giftcard value
                {
                    StatusCode = (HttpStatusCode)422,
                    Content    = "[{\"error\":{\"object\":\"gift_cards/value_adder\",\"property\":\"base\",\"message\":\"This giftcard has a balance of $X.XX. Please retry with that amount.\"}}]"
                },

                new RestResponse // Bad merchant token
                {
                    StatusCode = HttpStatusCode.Unauthorized
                }
            });

            foreach (var response in possibleErrors)
            {
                IDestroyGiftCardValue client = ClientModuleFunctionalTestingUtilities.GetMockedLevelUpModule <IDestroyGiftCardValue>(response);

                try
                {
                    var destroyed = client.GiftCardDestroyValue("not_checking_this", 1, "not_checking_this", 1000);
                    Assert.Fail("GiftCardDestroyValue failed to throw for an invalid HTTP return code of " + response.StatusCode);
                }
                catch (LevelUp.Api.Http.LevelUpApiException) { }
            }
        }