2017-08-07 26 views
0

我正在使用以下Braintree代碼以通過customer_id找到客戶,但得到此錯誤customer with id "customer_id" not found。爲了做到這一點,我需要用一個代表Braintree Vault中客戶的客戶ID的變量替換字符串'customer_id'。未找到標識爲「customer_id」的客戶

我很喜歡這個變量,需要一些幫助!

User.rb

customer = Braintree::Customer.find(customer_id)# this string here need to be replaced 
customer_card = customer.payment_methods[0].token 
payment_method = Braintree::PaymentMethod.find(customer_card) 
sub = payment_method.subscriptions[0] 
sub.status 

create方法位於transactions_controller.rb

def create 
    nonce_from_the_client = params['payment_method_nonce'] 
    @result = Braintree::Customer.create(
    first_name: params[:first_name], 
    last_name: params[:last_name], 
    :payment_method_nonce => nonce_from_the_client 
) 

    if @result.success? 
    puts @result.customer.id 
    puts @result.customer.payment_methods[0].token 
    redirect_to showcase_index_path, notice: 'Subscribed' 

    else 
    redirect_back(fallback_location: (request.referer || root_path), 
       notice: "Something went wrong while processing your transaction. Please try again!") 
    end 
end 
+0

確保客戶表中有customer_id列。 – xiaocui

+0

感謝回覆@xiaocui ...我在我的用戶表中有customer_id,因爲我沒有客戶表,但仍然返回同樣的錯誤'customer id'customer_id「not found'。任何想法,我可能會在這裏想念? – Theopap

回答

0

你從哪裏得到的customer_id把布倫特裏:: Customer.find裏面?找到之前,您是否成功創建了客戶?可能會拋出異常,因爲Braintree無法在其系統上找到提供的客戶。您可以登錄Braintree並導出客戶列表以檢查提供的ID是否存在。

+1

感謝@泰坦團隊的回覆!爲了回答你的問題,customer_id只是Braintree的一個例子,我需要用一個變量代替字符串'customer_id',該變量表示Braintree Vault中的客戶的客戶ID。通過'@result =布倫特裏:: Customer.create()' – Theopap

+1

充分披露,我在布倫特裏的工作,如果你需要進一步的幫助,可隨時伸手[email protected] @Theopap你可以從成功創建客戶解析CUSTOMER_ID結果對象,例如: customer_id = result.customer.id 您可以隨時使用https://developers.braintreepayments.com/reference/request/customer/search搜索外部客戶,這將允許您搜索針對過去使用多個pa創建的客戶rameters。 – ThinkAboutIt

0

在您的transactions_controller.rb創建方法中,在調用Braintree :: Customer.create時,您可以提供:id參數以將您的用戶標識作爲客戶標識。 (因此,您可以在此情況下提供用戶表的ID)

如果您未提供:id參數,則Braintree會爲該客戶創建其自己的ID。

+0

感謝您的答覆@Katan Doshi..B braintree customer_id更獨特,並且有更多digit,然後是我的user_id,所以我想只使用Barinatree customer_id。任何關於使這項工作的指針? – Theopap