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 TestCreatePaymentMethod() { var sm = new UpdatePaymentSM(); //sm.Number = "4111111111111111"; // Visa //https://developers.braintreepayments.com/ios+dotnet/guides/credit-cards sm.CVV = "1111"; // Visa sm.Number = "378282246310005"; //Amex sm.CVV = "1111"; // Amex sm.ExpirationYear = "2017"; sm.ExpirationMonth = "07"; sm.Nonce = "fake-valid-nonce"; sm.Customer = new NewPaymentCustomerSM { CustomerId = _testParentId.ToString(), Phone = "5125551212", LastName = "Smith" }; sm.CardholderName = sm.Customer.LastName; sm.Token = Guid.NewGuid().ToString(); UpdatePaymentResultSM result = _paymentManager.CreatePaymentMethod(sm); Assert.IsTrue(result.IsSuccess); }