Skip to content

Commit

Permalink
Meta data for card orders, Order Confirmation send for non-stripe ord…
Browse files Browse the repository at this point in the history
…ers, Card declined - order still sitting in created state
  • Loading branch information
tishonator authored and tishonator committed Jan 18, 2023
1 parent da0d4da commit 68cd11d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,16 @@ function init() {
function handleServerResponse(response) {
if (response.error) {
alert(response.error.message);
window.location.replace(document.getElementById('billingPageUrl').value);
$.ajax({
url: document.getElementById('stripeFailOrderURL').value,
method: 'POST',
dataType: 'json',
data: {
csrf_token: $('[name="csrf_token"]').val()
}
}).done(function () {
window.location.replace(document.getElementById('billingPageUrl').value);
});
} else if (response.requires_action) {
// Use Stripe.js to handle required card action
stripe.handleCardAction(response.payment_intent_client_secret).then(function (result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ function getOwnerDetails() {

function handleServerResponse(response) {
if (response.error) {
$.ajax({
url: document.getElementById('stripeFailOrderURL').value,
method: 'POST',
dataType: 'json',
data: {
csrf_token: $('[name="csrf_token"]').val()
}
});
alert(response.error.message);
window.location.replace(document.getElementById('billingPageUrl').value);
} else if (response.requires_action) {
Expand Down Expand Up @@ -413,6 +421,15 @@ document.querySelector('button.submit-payment').addEventListener('click', functi
return;
}

if ($('#dwfrm_billing .' + $('.tab-pane.active').attr('id') + ' .payment-form-fields input.form-control').val() === 'CREDIT_CARD') {
window.localStorage.setItem('stripe_payment_method', 'CREDIT_CARD');
} else if ($('#dwfrm_billing .' + $('.tab-pane.active').attr('id') + ' .payment-form-fields input.form-control').val() === 'STRIPE_PAYMENT_REQUEST_BTN') {
window.localStorage.setItem('stripe_payment_method', 'STRIPE_PAYMENT_REQUEST_BTN');
} else {
window.localStorage.setItem('stripe_payment_method', '');
return;
}

let billingForm = document.getElementById('dwfrm_billing');
$(billingForm).find('.form-control.is-invalid').removeClass('is-invalid');
if (!billingForm.reportValidity()) {
Expand Down Expand Up @@ -875,6 +892,10 @@ function handleStripeCardSubmitOrder() {
// v1
// eslint-disable-next-line consistent-return
document.querySelector('button.place-order').addEventListener('click', function (event) {
if (window.localStorage.getItem('stripe_payment_method') !== 'STRIPE_PAYMENT_ELEMENT' && window.localStorage.getItem('stripe_payment_method') !== 'CREDIT_CARD' && window.localStorage.getItem('stripe_payment_method') !== 'STRIPE_PAYMENT_REQUEST_BTN') {
return true;
}

event.stopImmediatePropagation();

// eslint-disable-next-line no-empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ exports.createPaymentIntent = function (paymentInstrument) {
createPaymentIntentPayload.setup_future_usage = 'off_session';
}

if (session.privacy.stripeOrderNumber) {
createPaymentIntentPayload.metadata = {};
createPaymentIntentPayload.metadata.order_id = session.privacy.stripeOrderNumber;
createPaymentIntentPayload.metadata.site_id = dw.system.Site.getCurrent().getID();
}

const stripeService = require('*/cartridge/scripts/stripe/services/stripeService');

const paymentIntent = stripeService.paymentIntents.create(createPaymentIntentPayload);
Expand Down

0 comments on commit 68cd11d

Please sign in to comment.