2016-05-27 37 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

相关问题