Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 与表格价格相同的分条计费_Php_Laravel_Stripe Payments_Laravel Cashier - Fatal编程技术网

Php 与表格价格相同的分条计费

Php 与表格价格相同的分条计费,php,laravel,stripe-payments,laravel-cashier,Php,Laravel,Stripe Payments,Laravel Cashier,因此,我希望向客户(非用户)支付与条带表单中显示的金额相同的账单 <form action="/charge" method="POST"> {!! csrf_field() !!} <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"

因此,我希望向客户(非用户)支付与条带表单中显示的金额相同的账单

<form action="/charge" method="POST">
                 {!! csrf_field() !!}
                  <script
                    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
                    data-key="pk_test_key"
                    data-amount="{{ $note->price*100 }}"
                    data-name="Hello World"
                    data-description="{{$note->title}}"
                    data-image="/img/documentation/checkout/marketplace.png"
                    data-locale="auto"
                    data-currency="aud">
                  </script>
                </form>
我需要将“金额”设置为等于票据值

否则,付款将通过我的出纳测试帐户进行,其他大部分都需要正常工作


不过,这些客户不是注册用户

数量需要由服务器端计算,否则人们可以修改DOM并传递他们想要的任何数量

相反,将
id
存储在服务器端的缓存中,并将
注释作为依赖项传递给
充电
功能,然后比较2

/**
 * Assuming name of "view" page
 */
public function checkout(Note $note) 
{
    /**
     * Always forget this on each page load, so we can switch seamlessly between Notes.
     */
    Illuminate\Support\Facades\Cache::forget('nid')->put('nid', $note->id);
}
别忘了修改
收费
路线,以包含对我们的
注释
依赖关系的新引用

route::post('charge/{note}', 'Controller@charge')->name('charge');
请确保更新您的表单,以通过
注释

<form action="{{route('charge', $note)}}" method="POST">

@DanielPahor您可以,但我避免使用
会话
,并利用
redis
进行缓存。我更喜欢控制和安全性。不过,请对我的意见持保留态度。
<form action="{{route('charge', $note)}}" method="POST">
public function charge(Illuminate\Http\Request $request, Note $note)
{
    $nid = Illuminate\Support\Facades\Cache::get('nid');

    // id's match, no sneaky stuff. safe to use $note->price now
    if ($nid === $note->id) {
        //now we can process our payment.
        // Set your secret key: remember to change this to your live secret key in production
        // See your keys here https://dashboard.stripe.com/account/apikeys
        \Stripe\Stripe::setApiKey("sk_test_key");

        // Get the credit card details submitted by the form
        $token = $request->get('stripeToken');

        // Create the charge on Stripe's servers - this will charge the user's card
        try {
            $charge = \Stripe\Charge::create(array(
                "amount" => number_format($note->price, 0, '', ''), // amount in cents, again
                "currency" => "aud",
                "source" => $token,
                "description" => "Example charge"
            ));
        } catch(\Stripe\Error\Card $e) {
            // The card has been declined
        }    
    }
}