Credit Cards

Server-Side Implementationanchor

GraphQL
Click here to view the server-side implementation using GraphQL.

Creating transactionsanchor

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.

  1. Callback
  2. Promise
gateway.transaction.sale({
  amount: "10.00",
  paymentMethodNonce: nonceFromTheClient,
  deviceData: deviceDataFromTheClient,
  options: {
    submitForSettlement: true
  }
}, (err, result) => {
  if (result.success) {
    // See result.transaction for details
  } else {
    // Handle errors
  }
});

If you want to create a new payment method in the Vault upon a successful transaction , use the options.storeInVaultOnSuccess option. If a customerId is not included, a new customer will be created.

Card verificationanchor

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.

  1. Callback
  2. Promise
gateway.paymentMethod.create({
  customerId: "theCustomerId",
  paymentMethodNonce: nonceFromTheClient,
  options: {
    verifyCard: true,
    verificationMerchantAccountId: "theMerchantAccountId",
    verificationAmount: "2.00",
  }
}, (err, result) => {
});
important

If you are using our Premium Fraud Management Tools, we strongly recommend passing deviceData each time you verify a card.

Verification resultsanchor

If verification was successful, the result will contain a CreditCard response object, which will contain a CreditCardVerification response object.

  1. Node
gateway.paymentMethod.create({
  customerId: "theCustomerId",
  paymentMethodNonce: nonceFromTheClient,
  options: {
    verifyCard: true
  }
}, (err, result) => {
  if (result.success) {
    verification = result.paymentMethod.verification;
  }
});

Otherwise, you'll receive a CreditCardVerification response object directly on a Customer or PaymentMethod result. This occurs if:

  1. A verification ran, and
  2. It was returned with a status of processor_declined or gateway_rejected

Reasons for unsuccessful verification resultsanchor

You can check the processorResponseCode and processorResponseText for the specific reason that a verification was processor_declined

  1. Callback
  2. Promise
gateway.paymentMethod.create({
    customerId: "the_customer_id",
    paymentMethodNonce: nonceFromTheClient,
    options: {
      verifyCard: true
    }
}, (err, result) => {
  result.success;
  // false

  result.verification.status;
  // "processor_declined"

  result.verification.processorResponseType;
  // "soft_declined"

  result.verification.processorResponseCode;
  // "2000"

  result.verification.processorResponseText;
  // "Do Not Honor"
});

If the status is gateway_rejected, you can check the gatewayRejectionReason for the specific reason. Learn more about gateway rejections.

  1. Node
result.success;
// false

result.verification.status;
// "gateway_rejected"

result.verification.gatewayRejectionReason;
// "cvv"

Verifications on sub-merchant accountsanchor

For those using Braintree Marketplace, verifications can't be done using sub-merchant accounts. See Braintree Marketplace Verifications for more details.

See also


Next Page: Testing and Go Live