显示0.00金额给Stripe。
P粉237125700
P粉237125700 2023-07-31 14:36:38
[PHP讨论组]
<p>我正在使用Stripe,在这里用户通过一次付款订阅不同的付费计划。付款成功进行,但主要问题是在3D Secure付款过程中(我们在欧洲运营,3D Secure付款检查是强制性的),显示给用户的金额是0,00。这不仅是错误的,更重要的是,对即将进行付款的人来说是令人困惑的。</p> <pre class="brush:php;toolbar:false;">public function purchase(Request $request, Plan $plan) { $user = $request-&gt;user(); $paymentMethod = $request-&gt;input('payment_method'); $encryptedSystemId = $request-&gt;input('system_id'); $encryptedBoxId = $request-&gt;input('box_id'); // Decrypt the encrypted IDs $systemId = Crypt::decrypt($encryptedSystemId); $boxId = Crypt::decrypt($encryptedBoxId); // Validate the IDs and user authorization $system = System::findOrFail($systemId); $box = Box::findOrFail($boxId); $total = $plan-&gt;price; try { $user-&gt;createOrGetStripeCustomer(); $user-&gt;updateDefaultPaymentMethod($paymentMethod); $user-&gt;charge($total * 100, $paymentMethod, [ 'metadata' =&gt; ['system_id' =&gt; $systemId, 'box_id' =&gt; $boxId, 'tenant_id '=&gt; $user-&gt;tenant-&gt;id, ] ]); // * 100 because Stripe deals with cents } catch (Exception $exception) { return back()-&gt;with('error', 'Error processing payment: ' . $exception-&gt;getMessage()); } &lt;script src="https://js.stripe.com/v3/"&gt;&lt;/script&gt; &lt;script&gt; let stripe = Stripe("{{ env('STRIPE_KEY') }}") let elements = stripe.elements() let style = { base: { color: '#32325d', fontFamily: '"Helvetica Neue", Helvetica, sans-serif', fontSmoothing: 'antialiased', fontSize: '16px', '::placeholder': { color: '#aab7c4' } }, invalid: { color: '#fa755a', iconColor: '#fa755a' } } let card = elements.create('card', { style: style }) card.mount('#card-element') let paymentMethod = null $('.card-form').on('submit', function(e) { $('#pay-btn').attr('disabled', true) if (paymentMethod) { return true } stripe.confirmCardSetup( "{{ $intent-&gt;client_secret }}", { payment_method: { card: card, billing_details: { name: $('.card_holder_name').val() } } } ).then(function(result) { if (result.error) { toastr.error( '__("rental.The data you entered contains errors! Review it and try again")') $('#pay-btn').removeAttr('disabled') } else { paymentMethod = result.setupIntent.payment_method $('.payment-method').val(paymentMethod) $('.card-form').submit() $('span.icon').removeAttr('hidden'); $('#pay-btn').attr('disabled', true) } }) return false }) &lt;div class="tab-content mt-4 " id="card-tab" style="display:none"&gt; &lt;form method="POST" action="{{ route('rentals.purchase', $plan) }}" class="card-form mt-3 mb-3"&gt; @csrf &lt;input type="hidden" name="payment_method" class="payment-method"&gt; &lt;input type="hidden" name="system_id" value="{{ encrypt($system-&gt;id) }}"&gt; &lt;input type="hidden" name="box_id" value="{{ encrypt($box-&gt;id) }}"&gt; &lt;div class="mb-4"&gt; &lt;input class="StripeElement form-input px-4 py-3 rounded-lg w-full" name="card_holder_name" placeholder="{{ __('rental.Cardholder Name') }}"&gt; &lt;/div&gt; &lt;div&gt; &lt;div id="card-element"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="card-errors" role="alert"&gt;&lt;/div&gt; &lt;div class="mt-3 text-center"&gt; &lt;button type="submit" class="bg-red-500 text-white font-bold py-2 px-4 rounded" id="pay-btn"&gt;{{ __('rental.Pay') }} {{ $plan-&gt;price }} &amp;euro; &lt;span class="icon" hidden&gt;&lt;i class="fas fa-sync fa-spin"&gt;&lt;/i&gt;&lt;/span&gt;&lt;/button&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; and this when I debug #_originalValues: array:39 [▼ "id" =&gt; "pi_3NZqdIC6ZwDjQHNX1R7KJLoO" "object" =&gt; "payment_intent" "amount" =&gt; 100 "amount_capturable" =&gt; 0 "amount_details" =&gt; array:1 [▼ "tip" =&gt; [] ] "amount_received" =&gt; 100</pre> <p><br /></p>
P粉237125700
P粉237125700

全部回复(1)
P粉403549616

根据您提供的代码,您正在使用SetupIntents来收集付款方式的详细信息。SetupIntents用于收集用于将来使用的付款方式详细信息:https://stripe.com/docs/payments/save-and-reuse。预计如果需要3DS,则金额为0.00,因为您在收集付款方式时不会对卡片收取任何金额。

如果您正在使用订阅功能,您应该按照此指南进行操作:https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements,在付款时收集和保存付款方式。

如果您正在使用一次性付款,则可以在付款同时收集和保存付款方式的详细信息:https://stripe.com/docs/payments/save-during-payment。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号