Inheritance: Braintree.Request
        public Result<PaymentMethod> Create(PaymentMethodRequest request)
        {
            NodeWrapper response = new NodeWrapper(service.Post("/payment_methods", request));

            if (response.GetName() == "paypal-account")
            {
                return new ResultImpl<PayPalAccount>(response, service);
            }
            else if (response.GetName() == "credit-card")
            {
                return new ResultImpl<CreditCard>(response, service);
            }
            else if (response.GetName() == "apple-pay-card")
            {
                return new ResultImpl<ApplePayCard>(response, service);
            }
            else if (response.GetName() == "android-pay-card")
            {
                return new ResultImpl<AndroidPayCard>(response, service);
            }
            else if (response.GetName() == "coinbase-account")
            {
                return new ResultImpl<CoinbaseAccount>(response, service);
            }
            else
            {
                return new ResultImpl<UnknownPaymentMethod>(response, service);
            }
        }
        public Result<PaymentMethod> Update(string token, PaymentMethodRequest request)
        {
            var response = new NodeWrapper(service.Put(service.MerchantPath() + "/payment_methods/any/" + token, request));

            if (response.GetName() == "paypal-account")
            {
                return new ResultImpl<PayPalAccount>(response, gateway);
            }
            else if (response.GetName() == "credit-card")
            {
                return new ResultImpl<CreditCard>(response, gateway);
            }
            else if (response.GetName() == "apple-pay-card")
            {
                return new ResultImpl<ApplePayCard>(response, gateway);
            }
            else if (response.GetName() == "android-pay-card")
            {
                return new ResultImpl<AndroidPayCard>(response, gateway);
            }
            else
            {
                return new ResultImpl<UnknownPaymentMethod>(response, gateway);
            }
        }
Beispiel #3
0
        public Result <PaymentMethod> Create(PaymentMethodRequest request)
        {
            NodeWrapper response = new NodeWrapper(service.Post("/payment_methods", request));

            if (response.GetName() == "paypal-account")
            {
                return(new ResultImpl <PayPalAccount>(response, service));
            }
            else if (response.GetName() == "credit-card")
            {
                return(new ResultImpl <CreditCard>(response, service));
            }
            else if (response.GetName() == "apple-pay-card")
            {
                return(new ResultImpl <ApplePayCard>(response, service));
            }
            else if (response.GetName() == "android-pay-card")
            {
                return(new ResultImpl <AndroidPayCard>(response, service));
            }
            else if (response.GetName() == "coinbase-account")
            {
                return(new ResultImpl <CoinbaseAccount>(response, service));
            }
            else
            {
                return(new ResultImpl <UnknownPaymentMethod>(response, service));
            }
        }
Beispiel #4
0
        public Result <PaymentMethod> Update(string token, PaymentMethodRequest request)
        {
            var response = new NodeWrapper(service.Put(service.MerchantPath() + "/payment_methods/any/" + token, request));

            if (response.GetName() == "paypal-account")
            {
                return(new ResultImpl <PayPalAccount>(response, gateway));
            }
            else if (response.GetName() == "coinbase-account")
            {
                return(new ResultImpl <CoinbaseAccount>(response, gateway));
            }
            else if (response.GetName() == "credit-card")
            {
                return(new ResultImpl <CreditCard>(response, gateway));
            }
            else if (response.GetName() == "apple-pay-card")
            {
                return(new ResultImpl <ApplePayCard>(response, gateway));
            }
            else if (response.GetName() == "android-pay-card")
            {
                return(new ResultImpl <AndroidPayCard>(response, gateway));
            }
            else
            {
                return(new ResultImpl <UnknownPaymentMethod>(response, gateway));
            }
        }
Beispiel #5
0
        public void CreatePaymentMethod(string email, string cardHolderName, string number, string cvv, string expirationMonth, string expirationYear)
        {
            Customer c = GetCustomer(email);

            Braintree.PaymentMethodRequest request = new Braintree.PaymentMethodRequest();
            {
                request.CardholderName  = cardHolderName;
                request.Number          = number;
                request.CVV             = cvv;
                request.ExpirationMonth = expirationMonth;
                request.ExpirationYear  = expirationYear;
            }
            gateway.PaymentMethod.Create(request);
        }
        public void Vault()
        {
            Result<Customer> customerResult = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(customerResult.IsSuccess());

            PaymentMethodRequest request = new PaymentMethodRequest()
            {
                CustomerId = customerResult.Target.Id,
                PaymentMethodNonce = Nonce.Coinbase
            };
            var createResult = gateway.PaymentMethod.Create(request);
            Assert.IsTrue(createResult.IsSuccess());

            var findResult = gateway.PaymentMethod.Find(createResult.Target.Token);
            Assert.IsTrue(findResult is CoinbaseAccount);
        }
        public ActionResult AddPaymentMethod(string id, string payment_method_nonce)
        {
            var request = new PaymentMethodRequest
            {
                CustomerId = id,
                PaymentMethodNonce = payment_method_nonce
            };

            var result = gateway.PaymentMethod.Create(request);
            if (result.IsSuccess())
                TempData["success"] = "New payment method saved successfully";
            else
                TempData["error"] = "Payment method not saved. Error: " + result.Message;

            return RedirectToAction("Details", new { id });
        }
        public void Create_CreatesCreditCardWithNonce()
        {
            String nonce = TestHelper.GenerateUnlockedNonce(gateway);
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());

            var request = new PaymentMethodRequest
            {
                CustomerId = result.Target.Id,
                PaymentMethodNonce = nonce
            };
            Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(paymentMethodResult.IsSuccess());
            Assert.IsNotNull(paymentMethodResult.Target.Token);
            Assert.IsInstanceOfType(typeof(CreditCard), paymentMethodResult.Target);
        }
        public void Create_CreatesPayPalAccountWithFuturePaymentNonce()
        {
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());

            String nonce = TestHelper.GenerateFuturePaymentPayPalNonce(gateway);
            var request = new PaymentMethodRequest
            {
                CustomerId = result.Target.Id,
                PaymentMethodNonce = nonce
            };
            Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(paymentMethodResult.IsSuccess());
            Assert.IsNotNull(paymentMethodResult.Target.Token);
            Assert.IsNotNull(paymentMethodResult.Target.ImageUrl);
            Assert.IsInstanceOfType(typeof(PayPalAccount), paymentMethodResult.Target);
        }
        public void Create_CreatesPayPalAccountWithOneTimePaymentNonceFails()
        {
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());

            String nonce = TestHelper.GenerateOneTimePayPalNonce(gateway);
            var request = new PaymentMethodRequest
            {
                CustomerId = result.Target.Id,
                PaymentMethodNonce = nonce
            };
            Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

            Assert.IsFalse(paymentMethodResult.IsSuccess());
            Assert.AreEqual(
                ValidationErrorCode.PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT,
                paymentMethodResult.Errors.ForObject("paypal-account").OnField("base")[0].Code
            );
        }
Beispiel #11
0
        public Result <PaymentMethod> Create(PaymentMethodRequest request)
        {
            var response = new NodeWrapper(service.Post(service.MerchantPath() + "/payment_methods", request));

            if (response.GetName() == "paypal-account")
            {
                return(new ResultImpl <PayPalAccount>(response, gateway));
            }
            else if (response.GetName() == "us-bank-account")
            {
                return(new ResultImpl <UsBankAccount>(response, gateway));
            }
            else if (response.GetName() == "credit-card")
            {
                return(new ResultImpl <CreditCard>(response, gateway));
            }
            else if (response.GetName() == "apple-pay-card")
            {
                return(new ResultImpl <ApplePayCard>(response, gateway));
            }
            else if (response.GetName() == "android-pay-card")
            {
                return(new ResultImpl <AndroidPayCard>(response, gateway));
            }
            else if (response.GetName() == "amex-express-checkout-card")
            {
                return(new ResultImpl <AmexExpressCheckoutCard>(response, gateway));
            }
            else if (response.GetName() == "coinbase-account")
            {
                return(new ResultImpl <CoinbaseAccount>(response, gateway));
            }
            else if (response.GetName() == "venmo-account")
            {
                return(new ResultImpl <VenmoAccount>(response, gateway));
            }
            else
            {
                return(new ResultImpl <UnknownPaymentMethod>(response, gateway));
            }
        }
        public void Find_ReturnsPayPalAccountByToken()
        {
            Result<Customer> customerResult = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(customerResult.IsSuccess());

            var request = new PaymentMethodRequest
            {
                CustomerId = customerResult.Target.Id,
                PaymentMethodNonce = Nonce.PayPalFuturePayment
            };
            Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(result.IsSuccess());
            Assert.IsNotNull(result.Target.ImageUrl);

            PayPalAccount found = gateway.PayPalAccount.Find(result.Target.Token);
            Assert.IsNotNull(found);
            Assert.IsNotNull(found.Email);
            Assert.IsNotNull(found.ImageUrl);
            Assert.IsNotNull(found.CreatedAt);
            Assert.IsNotNull(found.UpdatedAt);
            Assert.AreEqual(found.Email, ((PayPalAccount) result.Target).Email);
        }
        public Result<PaymentMethod> Create(PaymentMethodRequest request)
        {
            var response = new NodeWrapper(service.Post(service.MerchantPath() + "/payment_methods", request));

            if (response.GetName() == "paypal-account")
            {
                return new ResultImpl<PayPalAccount>(response, gateway);
            }
            else if (response.GetName() == "credit-card")
            {
                return new ResultImpl<CreditCard>(response, gateway);
            }
            else if (response.GetName() == "apple-pay-card")
            {
                return new ResultImpl<ApplePayCard>(response, gateway);
            }
            else if (response.GetName() == "android-pay-card")
            {
                return new ResultImpl<AndroidPayCard>(response, gateway);
            }
            else if (response.GetName() == "amex-express-checkout-card")
            {
                return new ResultImpl<AmexExpressCheckoutCard>(response, gateway);
            }
            else if (response.GetName() == "coinbase-account")
            {
                return new ResultImpl<CoinbaseAccount>(response, gateway);
            }
            else if (response.GetName() == "venmo-account")
            {
                return new ResultImpl<VenmoAccount>(response, gateway);
            }
            else
            {
                return new ResultImpl<UnknownPaymentMethod>(response, gateway);
            }
        }
        public void Find_FindsAndroidPayCard()
        {
            var request = new PaymentMethodRequest
            {
                CustomerId = gateway.Customer.Create(new CustomerRequest()).Target.Id,
                PaymentMethodNonce = Nonce.AndroidPay
            };
            Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);
            Assert.IsTrue(result.IsSuccess());

            PaymentMethod found = gateway.PaymentMethod.Find(result.Target.Token);
            Assert.AreEqual(result.Target.Token, found.Token);
            Assert.IsInstanceOfType(typeof(AndroidPayCard), found);
        }
        public void Delete_DeletesPayPalAccount()
        {
            var request = new PaymentMethodRequest
            {
                CustomerId = gateway.Customer.Create(new CustomerRequest()).Target.Id,
                PaymentMethodNonce = Nonce.PayPalFuturePayment
            };
            Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);
            Assert.IsTrue(result.IsSuccess());

            gateway.PaymentMethod.Delete(result.Target.Token);
        }
        public void Find_FindsPayPalAccount()
        {
            var request = new PaymentMethodRequest
            {
                CustomerId = gateway.Customer.Create(new CustomerRequest()).Target.Id,
                PaymentMethodNonce = Nonce.PayPalFuturePayment
            };
            Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);
            Assert.IsTrue(result.IsSuccess());

            PaymentMethod found = gateway.PaymentMethod.Find(result.Target.Token);
            Assert.AreEqual(result.Target.Token, found.Token);
        }
        public UpdatePaymentResultSM CreatePaymentMethod(UpdatePaymentSM sm)
        {
            var updateResult = new UpdatePaymentResultSM();

            // STEP - If customer not found, create
            Customer customer = FindCustomer(sm.Customer.CustomerId);
            if (customer == null)
            {
                NewCustomerResultSM createCustomerResult = CreateCustomer(sm.Customer);
                if (!updateResult.IsSuccess)
                {
                    updateResult.IsSuccess = false;
                    updateResult.Error = string.Format("Customer Not found with id {0}, and update to create. Message: {1}", sm.Customer.CustomerId, createCustomerResult.Error);
                    return updateResult;
                }
            }

            var updateRequest = new PaymentMethodRequest
            {
                Options = new PaymentMethodOptionsRequest
                {
                    MakeDefault = true,
                }
            };

            updateRequest.Number = sm.Number;
            updateRequest.CVV = sm.CVV;
            updateRequest.ExpirationYear = sm.ExpirationYear;
            updateRequest.ExpirationMonth = sm.ExpirationMonth;
            updateRequest.CardholderName = sm.CardholderName;
            updateRequest.CustomerId = sm.Customer.CustomerId;
            updateRequest.PaymentMethodNonce = sm.Nonce;
            updateRequest.Token = sm.Token;

            Result<PaymentMethod> btRet = _gateway.PaymentMethod.Create(updateRequest);

            if (btRet.IsSuccess())
            {
                updateResult.IsSuccess = true;
            }
            else
            {
                updateResult.IsSuccess = false;
                updateResult.Error = btRet.Message;
            }

            return updateResult;
        }
        public void Delete_DeletesCreditCard()
        {
            var request = new PaymentMethodRequest
            {
                CustomerId = gateway.Customer.Create(new CustomerRequest()).Target.Id,
                PaymentMethodNonce = Nonce.Transactable
            };
            Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);
            Assert.IsTrue(result.IsSuccess());

            gateway.PaymentMethod.Delete(result.Target.Token);
        }
        public void ToXml_IncludesDeviceData()
        {
            var request = new PaymentMethodRequest()
            {
                DeviceData = "{\"device_session_id\":\"my_dsid\", \"fraud_merchant_id\":\"my_fmid\"}"
            };

            Assert.IsTrue(request.ToXml().Contains("device_session_id"));
            Assert.IsTrue(request.ToXml().Contains("my_dsid"));
            Assert.IsTrue(request.ToXml().Contains("fraud_merchant_id"));
            Assert.IsTrue(request.ToXml().Contains("my_fmid"));
        }
        public void Create_CreatesAmexExpressCheckoutCardWithNonce()
        {
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());

            var request = new PaymentMethodRequest
            {
                CustomerId = result.Target.Id,
                PaymentMethodNonce = Nonce.AmexExpressCheckout
            };
            Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(paymentMethodResult.IsSuccess());
            Assert.IsNotNull(paymentMethodResult.Target.Token);
            Assert.IsNotNull(paymentMethodResult.Target.ImageUrl);
            Assert.IsInstanceOfType(typeof(AmexExpressCheckoutCard), paymentMethodResult.Target);
            AmexExpressCheckoutCard amexExpressCheckoutCard = (AmexExpressCheckoutCard) paymentMethodResult.Target;

            Assert.IsNotNull(amexExpressCheckoutCard.CardType);
            Assert.IsNotNull(amexExpressCheckoutCard.Bin);
            Assert.IsNotNull(amexExpressCheckoutCard.ExpirationMonth);
            Assert.IsNotNull(amexExpressCheckoutCard.ExpirationYear);
            Assert.IsNotNull(amexExpressCheckoutCard.CardMemberNumber);
            Assert.IsNotNull(amexExpressCheckoutCard.CardMemberExpiryDate);
            Assert.IsNotNull(amexExpressCheckoutCard.ImageUrl);
            Assert.IsNotNull(amexExpressCheckoutCard.SourceDescription);
            Assert.IsNotNull(amexExpressCheckoutCard.IsDefault);
            Assert.IsNotNull(amexExpressCheckoutCard.CreatedAt);
            Assert.IsNotNull(amexExpressCheckoutCard.UpdatedAt);
            Assert.IsNotNull(amexExpressCheckoutCard.Subscriptions);
        }
        public void Create_CreatesAndroidPayCardWithNonce()
        {
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());

            var request = new PaymentMethodRequest
            {
                CustomerId = result.Target.Id,
                PaymentMethodNonce = Nonce.AndroidPay
            };
            Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(paymentMethodResult.IsSuccess());
            Assert.IsNotNull(paymentMethodResult.Target.Token);
            Assert.IsNotNull(paymentMethodResult.Target.ImageUrl);
            Assert.IsInstanceOfType(typeof(AndroidPayCard), paymentMethodResult.Target);
            AndroidPayCard androidPayCard = (AndroidPayCard) paymentMethodResult.Target;
            Assert.IsNotNull(androidPayCard.IsDefault);
            Assert.IsNotNull(androidPayCard.CardType);
            Assert.IsNotNull(androidPayCard.VirtualCardType);
            Assert.IsNotNull(androidPayCard.SourceCardType);
            Assert.IsNotNull(androidPayCard.Last4);
            Assert.IsNotNull(androidPayCard.VirtualCardLast4);
            Assert.IsNotNull(androidPayCard.SourceCardLast4);
            Assert.IsNotNull(androidPayCard.Bin);
            Assert.IsNotNull(androidPayCard.ExpirationMonth);
            Assert.IsNotNull(androidPayCard.ExpirationYear);
            Assert.IsNotNull(androidPayCard.GoogleTransactionId);
            Assert.IsNotNull(androidPayCard.CreatedAt);
            Assert.IsNotNull(androidPayCard.UpdatedAt);
            Assert.IsNotNull(androidPayCard.Subscriptions);
        }
        public void Create_CreatesAbstractPaymentMethod()
        {
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());

            var request = new PaymentMethodRequest
            {
                CustomerId = result.Target.Id,
                PaymentMethodNonce = Nonce.AbstractTransactable
            };
            Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(paymentMethodResult.IsSuccess());
            Assert.IsNotNull(paymentMethodResult.Target.Token);
            Assert.IsNotNull(paymentMethodResult.Target.ImageUrl);
        }
        public void Delete_DeletesApplePayAccount()
        {
            var request = new PaymentMethodRequest
            {
                CustomerId = gateway.Customer.Create(new CustomerRequest()).Target.Id,
                PaymentMethodNonce = Nonce.ApplePayVisa
            };
            Result<PaymentMethod> createResult = gateway.PaymentMethod.Create(request);
            Assert.IsTrue(createResult.IsSuccess());

            Result<PaymentMethod> deleteResult = gateway.PaymentMethod.Delete(createResult.Target.Token);

            Assert.IsTrue(deleteResult.IsSuccess());
        }
        public void Create_CreatesVenmoAccountWithNonce()
        {
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());

            var request = new PaymentMethodRequest
            {
                CustomerId = result.Target.Id,
                PaymentMethodNonce = Nonce.VenmoAccount
            };

            Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);
            Assert.IsTrue(paymentMethodResult.IsSuccess());

            VenmoAccount venmoAccount = (VenmoAccount) paymentMethodResult.Target;

            Assert.IsNotNull(venmoAccount.Username);
            Assert.IsNotNull(venmoAccount.VenmoUserId);
            Assert.IsNotNull(venmoAccount.ImageUrl);
            Assert.IsNotNull(venmoAccount.SourceDescription);
            Assert.IsNotNull(venmoAccount.IsDefault);
            Assert.IsNotNull(venmoAccount.CreatedAt);
            Assert.IsNotNull(venmoAccount.UpdatedAt);
            Assert.IsNotNull(venmoAccount.CustomerId);
            Assert.IsNotNull(venmoAccount.Subscriptions);
        }
        public void Create_CreatesApplePayCardWithNonce()
        {
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());

            var request = new PaymentMethodRequest
            {
                CustomerId = result.Target.Id,
                PaymentMethodNonce = Nonce.ApplePayAmex
            };
            Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(paymentMethodResult.IsSuccess());
            Assert.IsNotNull(paymentMethodResult.Target.Token);
            Assert.IsNotNull(paymentMethodResult.Target.ImageUrl);
            Assert.IsInstanceOfType(typeof(ApplePayCard), paymentMethodResult.Target);
            ApplePayCard applePayCard = (ApplePayCard) paymentMethodResult.Target;
            Assert.IsNotNull(applePayCard.CardType);
            Assert.IsNotNull(applePayCard.ExpirationMonth);
            Assert.IsNotNull(applePayCard.ExpirationYear);
            Assert.IsNotNull(applePayCard.CreatedAt);
            Assert.IsNotNull(applePayCard.UpdatedAt);
            Assert.IsNotNull(applePayCard.Subscriptions);
            Assert.IsNotNull(applePayCard.PaymentInstrumentName);
        }
        public void Update_CanUpdateToken()
        {
            Result<Customer> customerResult = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(customerResult.IsSuccess());

            var request = new PaymentMethodRequest
            {
                CustomerId = customerResult.Target.Id,
                PaymentMethodNonce = Nonce.PayPalFuturePayment
            };
            Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(result.IsSuccess());

            string newToken = Guid.NewGuid().ToString();
            var updateRequest = new PayPalAccountRequest
            {
                Token = newToken
            };
            var updateResult = gateway.PayPalAccount.Update(result.Target.Token, updateRequest);

            Assert.IsTrue(updateResult.IsSuccess());
            Assert.AreEqual(newToken, updateResult.Target.Token);
        }
        public void Create_CreatesCreditCardWithNonceAndDeviceData()
        {
            string nonce = TestHelper.GenerateUnlockedNonce(gateway);
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());

            var request = new PaymentMethodRequest()
            {
                CustomerId = result.Target.Id,
                PaymentMethodNonce = nonce,
                Options = new PaymentMethodOptionsRequest()
                {
                    VerifyCard = true
                },
                DeviceData = "{\"device_session_id\":\"my_dsid\", \"fraud_merchant_id\":\"my_fmid\"}"
            };
            Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(paymentMethodResult.IsSuccess());
            Assert.IsNotNull(paymentMethodResult.Target.Token);
        }
        public void Find_FindsAbstractPaymentMethod()
        {
            var request = new PaymentMethodRequest
            {
                CustomerId = gateway.Customer.Create(new CustomerRequest()).Target.Id,
                PaymentMethodNonce = Nonce.AbstractTransactable
            };
            Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);
            Assert.IsTrue(result.IsSuccess());

            PaymentMethod found = gateway.PaymentMethod.Find(result.Target.Token);
            Assert.AreEqual(result.Target.Token, found.Token);
        }
        public void Create_CanMakeDefaultAndSetToken()
        {
            Result<Customer> customerResult = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(customerResult.IsSuccess());
            var creditCardRequest = new CreditCardRequest
            {
                CustomerId = customerResult.Target.Id,
                Number = "5105105105105100",
                ExpirationDate = "05/12"
            };
            CreditCard creditCard = gateway.CreditCard.Create(creditCardRequest).Target;
            Assert.IsTrue(creditCard.IsDefault.Value);

            String nonce = TestHelper.GenerateUnlockedNonce(gateway);
            Random random = new Random();
            int randomNumber = random.Next(0, 10000);
            var token = "token_" + randomNumber;
            var request = new PaymentMethodRequest
            {
                CustomerId = customerResult.Target.Id,
                PaymentMethodNonce = nonce,
                Token = token,
                Options = new PaymentMethodOptionsRequest
                {
                    MakeDefault = true
                }
            };
            Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(paymentMethodResult.IsSuccess());
            Assert.IsTrue(paymentMethodResult.Target.IsDefault.Value);
            Assert.AreEqual(token, paymentMethodResult.Target.Token);
        }
        public async Task <Result <PaymentMethod> > CreateAsync(PaymentMethodRequest request)
        {
            var response = new NodeWrapper(await service.PostAsync(service.MerchantPath() + "/payment_methods", request).ConfigureAwait(false));

            return(ExtractResultFromResponse(response));
        }
        public void Update_CanMakeDefault()
        {
            Result<Customer> customerResult = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(customerResult.IsSuccess());

            var creditCardRequest = new CreditCardRequest
            {
                CustomerId = customerResult.Target.Id,
                Number = "5105105105105100",
                ExpirationDate = "05/12"
            };
            CreditCard creditCard = gateway.CreditCard.Create(creditCardRequest).Target;
            Assert.IsTrue(creditCard.IsDefault.Value);

            var request = new PaymentMethodRequest
            {
                CustomerId = customerResult.Target.Id,
                PaymentMethodNonce = Nonce.PayPalFuturePayment
            };
            Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);

            Assert.IsTrue(result.IsSuccess());

            var updateRequest = new PayPalAccountRequest
            {
                Options = new PayPalOptionsRequest
                {
                    MakeDefault = true
                }
            };
            var updateResult = gateway.PayPalAccount.Update(result.Target.Token, updateRequest);

            Assert.IsTrue(updateResult.IsSuccess());
            Assert.IsTrue(updateResult.Target.IsDefault.Value);
        }
        public Result <PaymentMethod> Create(PaymentMethodRequest request)
        {
            var response = new NodeWrapper(service.Post(service.MerchantPath() + "/payment_methods", request));

            return(ExtractResultFromResponse(response));
        }
        public async Task <Result <PaymentMethod> > UpdateAsync(string token, PaymentMethodRequest request)
        {
            var response = new NodeWrapper(await service.PutAsync(service.MerchantPath() + "/payment_methods/any/" + token, request));

            return(ExtractResultFromResponse(response));
        }