diff --git a/src/MetisFW/Stripe/UI/PaymentControl.php b/src/MetisFW/Stripe/UI/PaymentControl.php index 0fb13e1..8641d49 100644 --- a/src/MetisFW/Stripe/UI/PaymentControl.php +++ b/src/MetisFW/Stripe/UI/PaymentControl.php @@ -44,7 +44,7 @@ public function getTemplateFilePath() { } public function handleSuccess() { - $paymentIntentId = $this->getPresenter()->getParameter('paymentIntentId'); + $paymentIntentId = $this->getPresenter()->getParameter('paymentIntentId') ?? $this->getPresenter()->getParameter('payment_intent'); try { $paidPayment = $this->operation->handleSuccess($paymentIntentId); diff --git a/src/MetisFW/Stripe/UI/templates/PaymentControl.latte b/src/MetisFW/Stripe/UI/templates/PaymentControl.latte index 6839123..d283c18 100644 --- a/src/MetisFW/Stripe/UI/templates/PaymentControl.latte +++ b/src/MetisFW/Stripe/UI/templates/PaymentControl.latte @@ -1,9 +1,40 @@ -
- -
- -
+
+ + \ No newline at end of file + var stripeElements = stripe.elements({ clientSecret: {$clientSecret} }); + + var stripePayment = stripeElements.create("payment"); + stripePayment.mount("#"+stripePaymentId); + + stripeButtonEl.addEventListener('click', function(ev) { + ev.preventDefault(); + stripeElements.submit(); + stripe.confirmPayment({ + elements: stripeElements, + clientSecret: {$clientSecret}, + confirmParams: { + return_url: {$successLink} + } + }).then(function(result) { + if (result.error) { + console.log("Stripe error:" + result.error.message); + } else { + console.log("Stripe result: Payment " + result.paymentIntent.status) + if (result.paymentIntent.status === 'succeeded') { + window.location.href = {$successLink} + "&paymentIntentId=" + result.paymentIntent.id; + } else { + console.log("payment error") + } + } + }); + }); + +