2016-05-27 34 views
0

Transaction.sale()Subscription.create()result中,如何訪問付款中的信用卡詳細信息?Braintree-如何從交易或訂閱中獲取last_4信用卡信息

我有以下幾種方法:

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之類的信用卡詳細信息以顯示在自定義收據中。

回答

0

要進入信用卡領域,你需要輸入

result.transaction.credit_card_details.{field you want} 

您可以在交易後byebug暫停程序,並在控制檯輸入result.inspect看什麼領域結果包含。

0

您可以撥打

result.last_4 

用於獲取最後4位數字的信用卡號碼。 如需更多幫助,請訪問here

+0

我得到了'NoMethodError異常:未定義的方法'last_4'爲# Mirror318