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

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

Transaction.sale()Subscription.create()result,如何在付款中访问信用卡详细信息?

我有以下方法:

  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

如您所见,该程序接受一次性捐赠或每月订阅。无论是哪一个,我都想获取信用卡详细信息,例如 last_4 以显示在自定义收据中。

您可以拨打

result.last_4

用于获取信用卡号的最后 4 位数字。 如需更多帮助,请访问 here

要访问信用卡字段,您需要键入

result.transaction.credit_card_details.{field you want}

您可以在交易后使用 byebug 暂停程序,然后在您的控制台中输入 result.inspect 以查看结果包含哪些字段。