路径自定义数据到stripe.js
我有三个订阅课程,所以我按了三个按钮。
index.html.twig
<form action="{{ path('acme_payment_charge') }}" method="POST">
<input type="hidden" name="plan" value="basic"><!-- I wish it works.-->
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_FpfPjy1etetetetetete"
data-amount="2980"
data-name="basic"
data-description="TESTTEST"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="ja"
data-currency="jpy">
</script>
<form action="{{ path('acme_payment_charge') }}" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_FpfPjy1etetetetetete"
data-amount="2980"
data-name="standard"
data-description="TESTTEST"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="ja"
data-currency="jpy">
</script>
<form action="{{ path('acme_payment_charge') }}" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_FpfPjy1eRtetetetetete"
data-amount="2980"
data-name="professional"
data-description="TESTTEST"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="ja">
data-currency="jpy">
</script>
我在php中捕获了Request,但我想知道选择了哪个按钮。
是否可以通过stripe.js发送自定义数据
(或者,如果我可以将data-name
从index.html.twig传递到php中的script.js。)
DefaultController.php
public function chargeAction(Request $request){
var_dump($request) // there is not either 'basic','standard' nor 'professional'.
//only 'stripeToken','stripeTokenType','stripeEmail' are returned.
\Stripe\Stripe::setApiKey("sk_test_Xltetetetetete");
$token = $request->request->get('stripeToken');
$customer = \Stripe\Customer::create(array(
"email" => $request->request->get('stripeEmail'),
"source" => $request->request->get('stripeToken'),
"plan" => "professional" // I want to change here dynamically.
));