简体   繁体   English

Braintree-如何从交易或订阅中获取last_4信用卡详细信息

[英]Braintree—how do I get the last_4 credit card details from a transaction OR subscription

From the result of a Transaction.sale() OR a Subscription.create() , how do I access the credit card details in the payment? resultTransaction.sale()Subscription.create()我怎么访问支付的信用卡资料?

I have the following methods: 我有以下方法:

  def bt_make_customer(donation, nonce)
    result = Braintree::Customer.create(
      first_name: donation.user.first_name,
      last_name: donation.user.last_name,
      email: donation.user.email,
      payment_method_nonce: nonce
      )
  end

  def bt_make_payment(donation, customer, nonce)
    if donation.type == "ReoccurringDonation"
      result = Braintree::Subscription.create(
        payment_method_token: customer.payment_methods[0].token,
        price: donation.amount,
        plan_id: "pay-monthly"
        )
    elsif donation.type == "SingleDonation"
      result = Braintree::Transaction.sale(
        :amount => donation.amount,
        :payment_method_nonce => nonce,
        :options => {:submit_for_settlement => true}
        )
    end
  end

As you can see, the program accepts one-time donations, or monthly subscriptions. 如您所见,该程序接受一次性捐赠或每月订阅。 When either is made, I want to get the credit card details such as last_4 to display in a custom receipt. 无论哪种方式制作,我都希望获得信用卡详细信息(例如last_4)以显示在自定义收据中。

You can call 你可以打电话

result.last_4

for getting The last 4 digits of the credit card number. 用于获取信用卡号的最后4位数字。 For more help visit here 如需更多帮助,请访问此处

To access the credit card fields, you need to type 要访问信用卡字段,您需要输入

result.transaction.credit_card_details.{field you want}

You can pause the program with byebug after the transaction, and type result.inspect in your console to see what fields the result contains. 您可以在事务处理后用byebug暂停程序,然后在控制台中键入result.inspect以查看结果包含哪些字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM