如何在 ActiveMerchant 中使用存储的付款来源进行购买?
Posted
技术标签:
【中文标题】如何在 ActiveMerchant 中使用存储的付款来源进行购买?【英文标题】:How do I use a stored payment source for a purchase in ActiveMerchant? 【发布时间】:2010-11-06 17:34:39 【问题描述】:我使用 ActiveMerchant 和 Braintree 作为我的支付处理器。我想利用 Braintree 的客户保险库功能来存储信用卡信息。
存储没问题,但我不知道用customer_vault_id
向信用卡收费的正确方法。根据Braintree documentation,这似乎非常简单,但我不确定如何通过 ActiveMerchant 传递它。如果我发送一张包含空数据的信用卡,我会从 Braintree 收到验证错误,如果我尝试nil
,则会从 ActiveMerchant 收到错误。唯一看起来很明显的是在purchase_options
哈希中发送customer_vault_id
,例如:
GATEWAY.purchase(self.price_in_cents, self.credit_card,
:ip => self.ip_address,
:customer_vault_id => 12345)
这是使用存储客户保险库的正确方法吗?
如果是这样,如果我想使用存储的客户保险库作为付款方式,此行的正确第二个参数是什么?
谢谢。
【问题讨论】:
【参考方案1】:在网关上调用#store后会得到响应,需要存储授权。
根据 wiki 中的文档:https://github.com/activemerchant/active_merchant/wiki/Patterns-&-Standards
商店 商店返回可用于购买和授权的令牌至关重要。目前的标准是在 Response#authorization 字段中返回令牌。
付款方式 字符串/令牌:通过商店标记化的支付方式的表示
例如
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>
【讨论】:
【参考方案2】:我发现您可以在购买方法中将customer_vault_id
替换为ActiveMerchant::Billing::CreditCard
的字符串。文档真的没有任何迹象表明这一点:(
【讨论】:
以上是关于如何在 ActiveMerchant 中使用存储的付款来源进行购买?的主要内容,如果未能解决你的问题,请参考以下文章
在 ActiveMerchant 中测试 Paypal Express