Ruby on rails 如何在ActiveMerchant中使用存储的付款来源进行购买?
我使用带Braintree的ActiveMerchant作为我的支付处理器。我想利用Braintree的客户保险库功能来存储信用卡信息 存储正常,但我无法找到使用Ruby on rails 如何在ActiveMerchant中使用存储的付款来源进行购买?,ruby-on-rails,payment-gateway,activemerchant,braintree,Ruby On Rails,Payment Gateway,Activemerchant,Braintree,我使用带Braintree的ActiveMerchant作为我的支付处理器。我想利用Braintree的客户保险库功能来存储信用卡信息 存储正常,但我无法找到使用客户保险库id向信用卡收费的正确方法。这看起来很直截了当,但我不知道如何通过ActiveMerchant。如果我发送一张数据为空的信用卡,我会从Braintree收到验证错误,如果我尝试nil,我会从ActiveMerchant收到错误。唯一显而易见的是在purchase\u options散列中发送customer\u vault\u
客户保险库id
向信用卡收费的正确方法。这看起来很直截了当,但我不知道如何通过ActiveMerchant。如果我发送一张数据为空的信用卡,我会从Braintree收到验证错误,如果我尝试nil
,我会从ActiveMerchant收到错误。唯一显而易见的是在purchase\u options
散列中发送customer\u vault\u id
,如:
GATEWAY.purchase(self.price_in_cents, self.credit_card,
:ip => self.ip_address,
:customer_vault_id => 12345)
这是使用存储的客户保险库的正确方法吗
如果是,如果我想使用存储的客户保险库作为付款方式,那么此行的第二个正确参数是什么
谢谢。我发现您可以在购买方法中将
customer\u vault\u id
替换为ActiveMerchant::Billing::CreditCard
。文档中确实没有这方面的任何指示:(在您在网关上调用#store之后,您将得到一个响应,您需要该响应来存储授权
根据在wiki中找到的文档:
商店
store返回可用于购买和授权的令牌非常重要。目前的标准是在Response#authorization字段中返回令牌
付款方式
字符串/令牌:通过存储标记化的支付方法的表示
e、 g
gateway=ActiveMerchant::Billing::BraintreeGateway.new(登录名:登录名,密码:密码)
信用卡=ActiveMerchant::账单::CreditCard.new(
:first_name=>“Bob”,
:last_name=>“Bobsen”,
:number=>“4242”,
:月=>'8',
:year=>Time.now.year+1,
:验证值=>'000')
响应=网关商店(信用卡)
=>nil,“消息”=>nil,“街道匹配”=>nil,“邮政匹配”=>nil},
@cvv_结果={“代码”=>nil,“消息”=>nil},
@emv_授权=零,
@错误代码=零,
@欺诈审查=错误,
@message=“成功”,
@params=
{“消息代码”=>“1”,
“消息文本”=>“成功”,
“结果代码”=>“确定”,
“测试请求”=>无,
“客户配置文件\u id”=>“1508682289”,
“客户\付款\配置文件\ id”=>“1508160804”,
“直接响应”=>nil},
@成功=正确,
@测试=真>
答复.授权
=>“1508682289#1508160804#cim#U商店”
网关。购买(100,响应。授权)
=>#“Y”,“消息”=>“街道地址和5位邮政编码匹配”,“街道匹配”=>“Y”,“邮政匹配”=>“Y”},
@cvv_结果={“代码”=>“P”,“消息”=>“cvv未处理”},
@emv_授权=零,
@错误代码=零,
@欺诈审查=错误,
@message=“此交易已被批准。”,
@params=
{“消息代码”=>“1”,
“消息文本”=>“成功”,
“结果代码”=>“确定”,
“测试请求”=>无,
“客户配置文件id”=>无,
“客户\付款\配置文件\ id”=>无,
“直接响应”=>
“1,1,1,此交易已被批准,T91GL2,Y,40036062888,,,1.00,抄送,认证捕获,2852040810cf440a4a13,Bob,Bobsen,,,,,,,,,n和#47;a,
“响应_代码”=>1,
“响应_子代码”=>“1”,
“响应原因代码”=>“1”,
“响应\u原因\u文本”=>“此交易已被批准。”,
“批准代码”=>“T91GL2”,
“avs_结果_代码”=>“Y”,
“交易id”=>“40036062888”,
“发票号”=>“”,
“订单描述”=>“”,
“金额”=>“1.00”,
“方法”=>“抄送”,
“事务类型”=>“身份验证捕获”,
“客户id”=>“2852040810cf440a4a13”,
“名字”=>“鲍勃”,
“姓氏”=>“Bobsen”,
“公司”=>“”,
“地址”=>“”,
“城市”=>“”,
“州”=>“n/;a”,
“邮政编码”=>“”,
“国家”=>“”,
“电话”=>“”,
“传真”=>“”,
“电子邮件地址”=>“”,
“发货至第一名”=>“”,
“发送至您的姓氏”=>“”,
“发货至公司”=>“”,
“发送至地址”=>“”,
“运送至城市”=>“”,
“发货至州”=>“”,
“配送至邮政编码”=>“”,
“发送到国家/地区”=>“”,
“税”=>“,
“职责”=>“,
“运费”=>“”,
“免税”=>“”,
“采购订单编号”=>“”,
“md5_哈希”=>“”,
“卡号”=>“P”,
“持卡人认证验证响应”=>“2”,
“账号”=>“XX4242”,
“卡片类型”=>“Visa”,
“拆分投标id=>”,
“请求的金额”=>“”,
“卡上余额”=>“”},
@成功=正确,
@测试=真>
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>