Credit Cards
Server-Side Implementation
Important
Your integration may be impacted by upcoming certificate changes. Visit our best practices guide to learn more.
GraphQL
Click here to view the server-side implementation using GraphQL.
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.
- Java
TransactionRequest request = new TransactionRequest()
.amount(new BigDecimal("10.00"))
.paymentMethodNonce(nonceFromTheClient)
.deviceData(deviceDataFromTheClient)
.options()
.submitForSettlement(true)
.done();
Result<transaction> result = gateway.transaction().sale(request);
if (result.isSuccess()) {
// See result.getTarget() 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.
- Java
PaymentMethodRequest request = new PaymentMethodRequest()
.customerId("the_customer_id")
.paymentMethodNonce(nonceFromTheClient)
.options()
.verifyCard(true)
.verificationMerchantAccountId("the_merchant_account_id")
.verificationAmount("2.00")
.done();
Result<? extends PaymentMethod> result = gateway.paymentMethod().create(request);
Important
If you are using our Premium Fraud Management Tools, we strongly recommend passing
deviceData
each time you verify a card.
Verification results
If verification was successful, the result will contain a
CreditCard
response object, which will contain a
CreditCardVerification
response object.
- Java
PaymentMethodRequest request = new PaymentMethodRequest()
.customerId("the_customer_id")
.paymentMethodNonce(nonceFromTheClient)
.options()
.verifyCard(true)
.done();
Result<? extends PaymentMethod> result = gateway.paymentMethod().create(request);
if (result.isSuccess()) {
CreditCardVerification verification = (CreditCard)result.getTarget().getVerification();
}
- 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- Java
PaymentMethodRequest request = new PaymentMethodRequest()
.customerId("the_customer_id")
.paymentMethodNonce(nonceFromTheClient)
.options()
.verifyCard(true)
.done();
Result<? extends PaymentMethod> result = gateway.paymentMethod().create(request);
result.isSuccess(); // false
CreditCardVerification verification = result.getCreditCardVerification();
verification.getStatus(); // "PROCESSOR_DECLINED"
verification.getProcessorResponseType(); // ProcessorResponseType.SOFT_DECLINED
verification.getProcessorResponseCode(); // 2000
verification.getProcessorResponseText(); // Do Not Honor
- Java
result.isSuccess(); // false CreditCardVerification verification = result.getCreditCardVerification(); verification.getStatus(); // "GATEWAY_REJECTED" verification.getGatewayRejectionReason(); // GatewayRejectionReason.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
Next Page: →