如何从付款方式列表中获取默认付款方式类型

时间:2016-03-18 14:53:32

标签: ruby braintree

我使用托管字段自定义了付款表单,并为一位工作正常的客户保存了一些付款方式。

我使用

添加了默认的最后一种付款方式
:options => {
              :make_default => true
            }

如何从付款方式列表中获取特定付款方式?分配默认值的付款方式没有任何默认属性。

以下是我的付款方式:

#<Braintree::CreditCard token: "95mp9m", billing_address: #<Braintree::Address:0x000000089f83e8 @gateway=#<Braintree::Gateway:0x0000000866cf30 @config=#<Braintree::Configuration:0x0000000866d160 @endpoint=nil, @environment=:sandbox, @public_key="spqbkwzjcc54x5dc", @private_key="[FILTERED]">>, @id="sg", @customer_id="29261218", @first_name=nil, @last_name=nil, @company=nil, @street_address="123 Abc Way", @extended_address=nil, @locality=nil, @region=nil, @postal_code=nil, @country_code_alpha2=nil, @country_code_alpha3=nil, @country_code_numeric=nil, @country_name=nil, @created_at=2016-03-17 15:59:33 UTC, @updated_at=2016-03-17 15:59:33 UTC>, bin: "401288", card_type: "Visa", cardholder_name: nil, created_at: 2016-03-17 15:59:34 UTC, customer_id: "29261218", expiration_month: "12", expiration_year: "2020", last_4: "1881", updated_at: 2016-03-17 15:59:34 UTC, prepaid: "No", payroll: "Unknown", commercial: "Unknown", debit: "Unknown", durbin_regulated: "Unknown", healthcare: "Unknown", country_of_issuance: "", issuing_bank: "Unknown", image_url: "https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox">

1 个答案:

答案 0 :(得分:0)

完全披露:我为Braintree工作。

default?是PaymentMethod对象上的方法,而不是字段,因此检查不会显示其默认状态。要解决您的问题,请迭代PaymentMethods列表,直到找到默认值。

customer = Braintree::Customer.find("customer_id")

default_payment_method = customer.payment_methods.find do |pm|
  pm.default?
end

如果您有任何其他问题,请随时联系Braintree support