使用Braintree DropUI将PayPal帐户关联到Vault的正确方法 [英] Correct way to link PayPal Accounts to vault with Braintree DropUI

查看:149
本文介绍了使用Braintree DropUI将PayPal帐户关联到Vault的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下控制器:

class PaymentsController < ApplicationController
    before_action :authenticate_user!, only: [:new]

    def new
        gon.client_token = generate_client_token
    end

    def create
        @result = Braintree::Transaction.sale(
                            amount: 60,
                            payment_method_nonce: params[:payment_method_nonce])
        if @result.success?
            puts @result.transaction.payment_instrument_type
            flash[:notice] = 'Yes, transaction completed'
        else
            flash[:alert] = "Something went wrong while processing your transaction. Please try again!"
      gon.client_token = generate_client_token
            render :new
        end
    end

    private

    def generate_client_token
        Braintree::ClientToken.generate(customer_id: current_user.braintree_customer_id)
    end
end

使用上面的代码,我正在测试是否将Paypal帐户与特定客户的金库关联.但是,它不会链接.我检查了文档参考,在我看来似乎不应该进行任何额外的调整.

With the above code, I was testing with linking a paypal account to the vault for a specific customer. However It won't link. I checked the documentation reference it seems to me it shouldn't be any extra tweak.

有任何提示吗?

推荐答案

我致力于使用python/javascript进行api开发的大脑树.您需要为交易创建braintree token.如果您有customer_id,则可以生成braintree令牌.您可以按照以下代码创建令牌:

I worked on the braintree for api development using python/javascript. You need to create the braintree token for the transaction.If you have the customer_id you can generate the braintree token. You can follow this code to create the token:

def checkout(request):
    api_token = request.session['token']
    nonce = request.POST['payment_method_nonce']
    customer = Customer.objects.get(user=request.user)
    # With this the PaymentMethod will be associated with the Customer
    result = braintree.PaymentMethod.create({
        "customer_id": customer.customer_id,
        "payment_method_nonce": nonce
    })
    token = result.payment_method.token
    print token
    # you the BT token to charge the user
    result = braintree.Transaction.sale({
        "amount": 10,
        "payment_method_token": token,
        "options": {'submit_for_settlement': True}
    })
    print result.transaction.id

这篇关于使用Braintree DropUI将PayPal帐户关联到Vault的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆