簡體   English   中英

Braintree-如何從交易或訂閱中獲取last_4信用卡詳細信息

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

resultTransaction.sale()Subscription.create()我怎么訪問支付的信用卡資料?

我有以下方法:

  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位數字。 如需更多幫助,請訪問此處

要訪問信用卡字段,您需要輸入

result.transaction.credit_card_details.{field you want}

您可以在事務處理后用byebug暫停程序,然后在控制台中鍵入result.inspect以查看結果包含哪些字段。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM