2016-03-18 31 views
1

我使用託管字段自定義付款方式,併爲客戶工作良好的方式保存了少量付款方式。如何從支付方式列表中獲取默認付款方式

我最後添加的付款方式爲使用默認值,

: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"> 

回答

0

全面披露:我布倫特裏的工作。

default? PaymentMethod對象上的方法而不是字段,因此檢查將不會顯示其默認狀態。要解決您的問題,請遍歷PaymentMethods列表,直到找到默認值。

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

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

如果您還有其他問題,請隨時聯繫Braintree support