Credit Cards
Server-Side Implementation
Creating transactions
Using Transaction:Sale is the simplest way to create a credit card transaction.
You can create a transaction with just an Amount and a PaymentMethodNonce relayed from your client and immediately submit it for settlement.
Collect device data from the client and include the DeviceDataFromTheClient in the transaction.
- C#
var request = new TransactionRequest {
Amount = 10.00M,
PaymentMethodNonce = nonceFromTheClient,
DeviceData = deviceDataFromTheClient,
Options = new TransactionOptionsRequest {
SubmitForSettlement = true
}
};
Result<transaction> result = gateway.Transaction.Sale(request);
if (result.IsSuccess()) {
// See result.Target for details
} else {
// Handle errors
}
Card verification
When a payment method is a credit or debit card, you can use card verification to verify that the card data matches a valid, open account before storing or updating it in the Vault.
Braintree strongly recommends verifying all cards before they are stored in your Vault by enabling card verification in the Control Panel.
If you do not want to verify all cards by default, you can run one-time requests using Options.VerifyCard when:
In both cases, the gateway verifies cards by running either a $0 or $1 authorization and then automatically voiding it. If you'd like, you can specify a different Options.VerificationAmount to use for the authorization.- C#
PaymentMethodRequest request = new PaymentMethodRequest {
CustomerId = "the_customer_id",
PaymentMethodNonce = nonceFromTheClient,
Options = new PaymentMethodOptionsRequest {
VerifyCard = true,
VerificationMerchantAccountId = "the_merchant_account_id",
VerificationAmount = "2.00"
}
};
Result<paymentmethod> result = gateway.PaymentMethod.Create(request);
Verification results
If verification was successful, the result will contain a
CreditCard
response object, which will contain a
CreditCardVerification
response object.
- C#
PaymentMethodRequest request = new PaymentMethodRequest {
CustomerId = "the_customer_id",
PaymentMethodNonce = nonceFromTheClient,
Options = new PaymentMethodOptionsRequest {
VerifyCard = true
}
};
Result<paymentmethod> result = gateway.PaymentMethod.Create(request);
if (result.IsSuccess()) {
var verification = (CreditCard)result.Target.Verification;
}
Otherwise, you'll receive a CreditCardVerification response object directly on a Customer or PaymentMethod result. This occurs if:
- A verification ran, and
- It was returned with a Status of ProcessorDeclined or GatewayRejected
Reasons for unsuccessful verification results
You can check the
ProcessorResponseCode
and
ProcessorResponseText
for the specific reason that a verification was ProcessorDeclined- C#
PaymentMethodRequest request = new PaymentMethodRequest() {
CustomerId = "the_customer_id",
PaymentMethodNonce = nonceFromTheClient,
Options = new CreditCardOptionsRequest() {
VerifyCard = true
}
};
Result<paymentmethod> result = gateway.PaymentMethod.Create(request);
result.IsSuccess(); // false
CreditCardVerification verification = result.CreditCardVerification;
verification.Status; // "processor_declined"
verification.ProcessorResponseType; // "soft_declined"
verification.ProcessorResponseCode; // "2000"
verification.ProcessorResponseText; // "Do Not Honor"
- C#
Result<customer> result = gateway.Customer.Create(request);
result.IsSuccess()); // false
CreditCardVerification verification = result.CreditCardVerification;
verification.Status; // "gateway_rejected"
verification.GatewayRejectionReason; // TransactionGatewayRejectionReason.CVV
Verifications on sub-merchant accounts
For those using
Braintree Marketplace,
verifications can't be done using sub-merchant accounts. See
Braintree Marketplace Verifications
for more details.
See Also
- Creating transactions
- Creating and updating customers
- Creating and updating payment methods
- Credit card verification
- Verifying cards with Hosted Fields