-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PaymentControl uses whole payment element instead of just card element
- Loading branch information
1 parent
4352bb1
commit 9f9348d
Showing
2 changed files
with
39 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,40 @@ | ||
<div n:attr="(expand)$attrs"> | ||
<input id="card-name" type="text"> | ||
<div id="card-element"></div> | ||
<button id="card-button" data-secret="{$clientSecret}">{$text}</button> | ||
</div> | ||
<div id="stripe-payment-el-{$elementId}"></div> | ||
<button id="stripe-payment-button-{$elementId}" data-secret="{$clientSecret}">{$text}</button> | ||
|
||
<script> | ||
var stripePaymentId = "stripe-payment-el-" + {$elementId}; | ||
var stripeButtonId = "stripe-payment-button-" + {$elementId}; | ||
var stripePaymentEl = document.getElementById(stripePaymentId); | ||
var stripeButtonEl = document.getElementById(stripeButtonId); | ||
var stripe = Stripe({$publicApiKey}); | ||
var elements = stripe.elements(); | ||
</script> | ||
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") | ||
} | ||
} | ||
}); | ||
}); | ||
</script> |