【问题标题】:Subscriptions in Braintree with laravel/cashier-braintree / Laravel 5.2使用 laravel/cashier-braintree / Laravel 5.2 在 Braintree 中订阅
【发布时间】:2016-07-31 11:10:50
【问题描述】:

需要在我的 Laravel 应用中集成 laravel/cashier-braintree。几乎没有使用 Braintree 集成的经验,很难让它发挥作用。有人可以逐步解释它是如何工作的,或者一些对此有好处的教程吗?尝试跟踪 Stripe 的集成,因为它们相似但没有成功。

这就是我的代码现在的样子

SubscriptionController.php

public function createToken()
    {
        $clientToken = \Braintree_ClientToken::generate(array('customerId' => ""));
        return $clientToken;
    }

    public function checkout()
    {
        $creditCardToken = $this->createToken();
        $data = [
            'paymentMethodNonce' => $creditCardToken,
            'creditCard' => [
                'number' => Input::get('number'),
                'expirationDate' => Input::get('expiration_date'),
                'cvv' => Input::get('cvv')
            ],
        ];
        $this->user->newSubscription(Input::get('plan'), Input::get('plan'))->create($creditCardToken, $data);

        if ($this->user->subscribed('Small')) {
            return 'Done!';
        }

        var_dump($this->user);
    }

所以,我明白了

Unable to create Braintree customer: Unknown payment_method_nonce.
Expiration date is required.
Credit card number is required.
Credit card must include number, payment_method_nonce, or venmo_sdk_payment_method_code.

如果我输入我的表单 name="" 我会收到 Unable to create Braintree customer: Unknown payment_method_nonce. 因此,名称可以通过,但 payment_method_nonce 出现问题。不明白为什么付款不能与 data-braintree-name 一起使用,因为出于安全考虑,仅 name 不是选项。如果有人知道我为什么会收到未知的 payment_method_nonce?

【问题讨论】:

    标签: php laravel-5.2 subscription braintree laravel-cashier


    【解决方案1】:

    解决方案:

    subscription.blade.php

    {!! Form::open(['route' => 'subscription', 'method' => 'post', 'id' => 'checkout'])!!}
    
    <h5>Choose:</h5>
    
    <select name="plan" id="plan" class="form-control">
        <option value="sm">Small</option>
        <option value="lg">Large</option>
    </select>
    
    <div class="form-group">
        <h5>Card number:</h5>
    
        <div id="number" class="form-control"></div>
    
    </div>
    
    <div class="row">
        <div class="col-md-6 col-sm-6">
            <div class="form-group">
                <h5>Date:</h5>
    
                <div id="expiration-date" class="form-control"></div>
    
            </div>
        </div>
    
        <div class="col-md-6 col-sm-6">
            <div class="form-group">
    
                <div id="cvv" class="form-control"></div>
    
            </div>
        </div>
    </div>
    
    {!! Form::close() !!}
    

    SubscriptionsController.php

    public function join()
        {
            $data = [
                'paymentMethodNonce' => Input::get('payment_method_nonce'),
            ];
            $this->user->newSubscription('main', Input::get('plan'))->create(Input::get('payment_method_nonce'), $data);
    
            return redirect('/');
        }
    

    脚本

    <script src="https://js.braintreegateway.com/v2/braintree.js"></script>
    <script>
        var colorTransition = 'color 100ms ease-out';
    
        braintree.setup("@braintreeClientToken", "custom", {
            id: "checkout",
            hostedFields: {
    
                number: {
                    selector: "#number"
                },
    
                expirationDate: {
                    selector: "#expiration-date"
                },
    
                cvv: {
                    selector: "#cvv"
                }
            }
        });
    </script>
    

    【讨论】:

      猜你喜欢
      • 2017-04-06
      • 2019-08-01
      • 2020-02-29
      • 2016-07-30
      • 2016-08-04
      • 2023-03-11
      • 1970-01-01
      • 2020-07-25
      • 2015-05-01
      相关资源
      最近更新 更多