Reputation: 8348
I'm using ActiveMerchant with Braintree as my payment processor. I want to take advantage of Braintree's customer vault functionality to store credit card info.
Storage goes fine, but I can't figure out the correct way to charge the credit card with the customer_vault_id
. It seems very straight-forward according to the Braintree documentation, but I'm not sure how to pass this through ActiveMerchant. I get validation errors from Braintree if I send a credit card with empty data, and errors from ActiveMerchant if I try nil
. The only thing that seems obvious is to send the customer_vault_id
in the purchase_options
hash, like:
GATEWAY.purchase(self.price_in_cents, self.credit_card,
:ip => self.ip_address,
:customer_vault_id => 12345)
Is this the correct way to use a stored customer vault?
If so, what is the correct second argument for this line if I want to use a stored customer vault as payment method?
Thanks.
Upvotes: 4
Views: 999
Reputation: 23
After you call #store on the gateway, you will get a response, which you need to store the authorization.
Per the docs found in the wiki: https://github.com/activemerchant/active_merchant/wiki/Patterns-&-Standards
store It's critical that store returns a token that can be used against purchase and authorize. Currently the standard is to return the token in the Response#authorization field.
payment method String/token: Representation of a payment method tokenized via store
e.g.
gateway = ActiveMerchant::Billing::BraintreeGateway.new(login: login, password: password)
credit_card = ActiveMerchant::Billing::CreditCard.new(
:first_name => 'Bob',
:last_name => 'Bobsen',
:number => '4242424242424242',
:month => '8',
:year => Time.now.year+1,
:verification_value => '000')
response = gateway.store(credit_card)
=> #<ActiveMerchant::Billing::Response:0x00007f8efb3df1a8
@authorization="1508682289#1508160804#cim_store",
@avs_result={"code"=>nil, "message"=>nil, "street_match"=>nil, "postal_match"=>nil},
@cvv_result={"code"=>nil, "message"=>nil},
@emv_authorization=nil,
@error_code=nil,
@fraud_review=false,
@message="Successful",
@params=
{"message_code"=>"1",
"message_text"=>"Successful",
"result_code"=>"Ok",
"test_request"=>nil,
"customer_profile_id"=>"1508682289",
"customer_payment_profile_id"=>"1508160804",
"direct_response"=>nil},
@success=true,
@test=true>
response.authorization
=> "1508682289#1508160804#cim_store"
gateway.purchase(100, response.authorization)
=> #<ActiveMerchant::Billing::Response:0x00007f8ede0027c8
@authorization="40036062888#XXXX4242#cim_purchase",
@avs_result=
{"code"=>"Y", "message"=>"Street address and 5-digit postal code match.", "street_match"=>"Y", "postal_match"=>"Y"},
@cvv_result={"code"=>"P", "message"=>"CVV not processed"},
@emv_authorization=nil,
@error_code=nil,
@fraud_review=false,
@message="This transaction has been approved.",
@params=
{"message_code"=>"1",
"message_text"=>"Successful",
"result_code"=>"Ok",
"test_request"=>nil,
"customer_profile_id"=>nil,
"customer_payment_profile_id"=>nil,
"direct_response"=>
"1,1,1,This transaction has been approved.,T91GL2,Y,40036062888,,,1.00,CC,auth_capture,2852040810cf440a4a13,Bob,Bobsen,,,,n/a,,,,,,,,,,,,,,,,,,,,P,2,,,,,,,,,,,XXXX4242,Visa,,,,,,,,,,,,,,,,,",
"response_code"=>1,
"response_subcode"=>"1",
"response_reason_code"=>"1",
"response_reason_text"=>"This transaction has been approved.",
"approval_code"=>"T91GL2",
"avs_result_code"=>"Y",
"transaction_id"=>"40036062888",
"invoice_number"=>"",
"order_description"=>"",
"amount"=>"1.00",
"method"=>"CC",
"transaction_type"=>"auth_capture",
"customer_id"=>"2852040810cf440a4a13",
"first_name"=>"Bob",
"last_name"=>"Bobsen",
"company"=>"",
"address"=>"",
"city"=>"",
"state"=>"n/a",
"zip_code"=>"",
"country"=>"",
"phone"=>"",
"fax"=>"",
"email_address"=>"",
"ship_to_first_name"=>"",
"ship_to_last_name"=>"",
"ship_to_company"=>"",
"ship_to_address"=>"",
"ship_to_city"=>"",
"ship_to_state"=>"",
"ship_to_zip_code"=>"",
"ship_to_country"=>"",
"tax"=>"",
"duty"=>"",
"freight"=>"",
"tax_exempt"=>"",
"purchase_order_number"=>"",
"md5_hash"=>"",
"card_code"=>"P",
"cardholder_authentication_verification_response"=>"2",
"account_number"=>"XXXX4242",
"card_type"=>"Visa",
"split_tender_id"=>"",
"requested_amount"=>"",
"balance_on_card"=>""},
@success=true,
@test=true>
Upvotes: 1
Reputation: 8348
I discovered that you can substitute the customer_vault_id
as a string for the ActiveMerchant::Billing::CreditCard
in the purchase method. The docs really don't have any indication of this :(
Upvotes: 2