Server-side setup
Generate a client token
To get started, generate a client token. Be sure to generate it on the server and make it accessible to your client.
If you are using a merchant account ID other than your default, specify the merchant_account_id when generating the client token. The merchant account ID used to create the client token must match the merchant account ID used to create the subsequent transaction.
Generate instant verification JWT(JSON Web Token)
Create a JWT that contains the return and cancel URLs for the Instant Verification flow. Generate it on the server and make it accessible to your client.
- Ruby
# Create JWT request object
request = Braintree::BankAccountInstantVerificationJwtRequest.new(
:business_name => "Your Business Name",
:return_url => "https://yoursite.com/bank_transactions?session_id=#{session_id}",
:cancel_url => "https://yoursite.com/bank_transactions?session_id=#{session_id}"
)
# setup gateway client
# https://developer.paypal.com/braintree/docs/start/hello-server/ruby/
# Create JWT using the braintree client gateway
result = gateway.bank_account_instant_verification.create_jwt(request)
if result.success?
jwt = result.bank_account_instant_verification_jwt.jwt
else
# Handle error
Rails.logger.error("JWT creation failed: #{result.message}")
endServer-side processing
Vault bank account
Call Payment Method:Create to specify the verification method (instant_verification_account_validation) and store the bank account information as a payment method in your vault.
- Ruby
# sample server method to submit nonce for vaulting
result = braintree_client.payment_method.create({
customer_id: "<customer_id>",
payment_method_nonce: "<nonce_from_instant_verification>",
options: {
us_bank_account_verification_method: "instant_verification_account_validation",
make_default: true
},
us_bank_account: {
ach_mandate_text: "<mandate text displayed to customer>",
ach_mandate_accepted_at: "2023-12-01T12:00:00Z"
}
})
if result.success?
render json: {
token: result.payment_method.token,
customer_id: "<customer_id>",
last_4: result.payment_method.last_4,
account_type: result.payment_method.account_type
}
else
render json: { error: result.message }, status: 422
endCreate transactions
Pass the nonce or payment method token to your server and create a transaction using Transaction:Sale.
device_data_from_the_client in the transaction.
- Ruby
# sample server method to submit nonce for one time payment transaction
result = braintree_client.transaction.sale({
amount: "10.00",
payment_method_nonce: "<nonce_from_instant_verification>",
merchant_account_id: "<merchant_account_id>",
options: {
submit_for_settlement: true
},
us_bank_account: {
ach_mandate_text: "<mandate text displayed to customer>",
ach_mandate_accepted_at: "2023-12-01T12:00:00Z"
}
})
if result.success?
# Transaction successful
render json: {
id: result.transaction.id,
status: result.transaction.status,
amount: result.transaction.amount
}
else
# Handle error
render json: { error: result.message }, status: 422
end