Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #110 from 202-ecommerce/release/2.4.x
Browse files Browse the repository at this point in the history
Release 2.4.2 RC2
  • Loading branch information
clotairer authored Jan 13, 2022
2 parents bf58419 + 1835fc9 commit f24f07f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 40 deletions.
18 changes: 9 additions & 9 deletions _dev/js/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $(function(){
// Create references to the submit button.
const $submit = $('#payment-confirmation button[type="submit"], .stripe-europe-payments[data-method="bancontact"], .ideal-submit-button[data-method="ideal"], .stripe-europe-payments[data-method="giropay"], .stripe-europe-payments[data-method="sofort"], .stripe-europe-payments[data-method="fpx"], .stripe-europe-payments[data-method="eps"], .stripe-europe-payments[data-method="p24"], .stripe-europe-payments[data-method="sepa_debit"], .stripe-submit-button, .sepa_debit-submit-button');
const $submitButtons = $('#payment-confirmation button[type="submit"], .stripe-submit-button');
const submitInitialText = $submitButtons.text();
const submitInitialText = $submitButtons.first().text();

$form = $('#stripe-card-payment');
let payment = '';
Expand Down Expand Up @@ -647,10 +647,14 @@ $(function(){
// Update error message
function updateError(element, error) {
const $error = $(".stripe-payment-form:visible .stripe-error-message");
var elementError = $(element).find('.stripe-error-message');
var disableElement = $(element).siblings('.stripe-submit-button');
if (error) {
if (stripe_ps_version == '1.6') {
if (stripe_ps_version === '1.6') {
let elementError;
if (payment === 'card') {
elementError = $('#stripe-card-payment .stripe-error-message');
} else {
elementError = $('#stripe-'+ payment +'-element .stripe-error-message');
}
$(elementError).text(error.message).show();
} else {
$error.text(error.message).show();
Expand All @@ -660,11 +664,7 @@ $(function(){
}
enableSubmit($submitButtons);
} else {
if (stripe_ps_version == '1.6') {
$(elementError).text("").hide();
} else {
$error.text("").hide();
}
$error.text("").hide();
}
}

Expand Down
12 changes: 8 additions & 4 deletions controllers/front/createIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ public function initContent()
$paymentOption = Tools::getValue('payment_option');
$paymentMethodId = Tools::getValue('id_payment_method');

$intentData = $this->constructIntentData($amount, $currency, $paymentOption, $paymentMethodId);
$intentData = $this->constructIntentData($amount, $currency->iso_code, $paymentOption, $paymentMethodId);

$cardData = $this->constructCardData($paymentMethodId);

$intent = $this->createIdempotencyKey($intentData);

$this->registerStripeEvent($intent);
} catch (Exception $e) {
ProcessLoggerHandler::logError(
"Retrieve Stripe Account Error => ".$e->getMessage(),
Expand Down Expand Up @@ -227,9 +225,14 @@ private function createIdempotencyKey($intentData)
$stripeIdempotencyKey = new StripeIdempotencyKey();
$stripeIdempotencyKey = $stripeIdempotencyKey->getByIdCart($cart->id);

if (empty($stripeIdempotencyKey->id) === true) {
$lastRegisteredEvent = new StripeEvent();
$lastRegisteredEvent = $lastRegisteredEvent->getLastRegisteredEventByPaymentIntent($stripeIdempotencyKey->id);

if (empty($stripeIdempotencyKey->id) === true || $lastRegisteredEvent->status === 'FAILED') {
$intent = $stripeIdempotencyKey->createNewOne($cart->id, $intentData);
$this->registerStripeEvent($intent);
} else {
unset($intentData['capture_method']);
$intent = $stripeIdempotencyKey->updateIntentData($intentData);
}

Expand Down Expand Up @@ -282,6 +285,7 @@ private function registerStripeEvent($intent)
$stripeEvent->setStatus(StripeEvent::CREATED_STATUS);
$stripeEvent->setDateAdd($intent->created);
$stripeEvent->setIsProcessed(1);
$stripeEvent->setFlowType('direct');

if ($stripeEvent->save()) {
ProcessLoggerHandler::logInfo(
Expand Down
59 changes: 40 additions & 19 deletions controllers/front/orderSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ private function registerStripeEvent($paymentIntent)

$stripeEventStatus = $this->checkEventStatus($paymentIntent);

if (empty($stripeEventStatus) === true) {
return false;
}

$stripeEventDate = new DateTime();
$stripeEventDate = $stripeEventDate->setTimestamp($eventCharge->created);

Expand Down Expand Up @@ -196,7 +200,8 @@ private function handleWebhookActions($intent)
'addTentative'
);
} elseif (($eventType == 'pending' && $payment_method == 'sofort')
|| (($eventType == 'succeeded' || $eventType == 'requires_action') && $payment_method != 'sofort')
|| (($eventType == 'succeeded' || $eventType == 'requires_action')
&& Stripe_official::$paymentMethods[$payment_method]['flow'] == 'redirect')
) {
ProcessLoggerHandler::logInfo(
'Payment method flow with redirection',
Expand All @@ -214,7 +219,7 @@ private function handleWebhookActions($intent)
);
}

if (!$handler->process('ValidationOrder')) {
if (!$handler->process('ValidationOrderActions')) {
// Handle error
ProcessLoggerHandler::logError(
'Order creation process disrupted.',
Expand Down Expand Up @@ -266,24 +271,40 @@ private function displayOrderConfirmation($id_intent)
$secure_key = false;
}

$url = Context::getContext()->link->getPageLink(
'order-confirmation',
true,
null,
array(
'id_cart' => $stripePayment->id_cart,
'id_module' => (int)$this->module->id,
'id_order' => $id_order,
'key' => $secure_key
)
);
if ($id_order === 0) {
$url = Context::getContext()->link->getModuleLink(
'stripe_official',
'orderFailure',
array(),
true
);

ProcessLoggerHandler::logInfo(
'Confirmation order url => '.$url,
null,
null,
'orderSuccess - displayOrderConfirmation'
);
ProcessLoggerHandler::logInfo(
'Failed order url => '.$url,
null,
null,
'orderSuccess - displayOrderConfirmation'
);
} else {
$url = Context::getContext()->link->getPageLink(
'order-confirmation',
true,
null,
array(
'id_cart' => $stripePayment->id_cart,
'id_module' => (int)$this->module->id,
'id_order' => $id_order,
'key' => $secure_key
)
);

ProcessLoggerHandler::logInfo(
'Confirmation order url => '.$url,
null,
null,
'orderSuccess - displayOrderConfirmation'
);
}
ProcessLoggerHandler::closeLogger();

Tools::redirect($url);
Expand Down
2 changes: 1 addition & 1 deletion controllers/front/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function initContent()
}

// Process actions chain
if ($handler->process('ValidationOrder')) {
if ($handler->process('ValidationOrderActions')) {
// Retrieve and use resulting data
$returnValues = $handler->getConveyor();
} else {
Expand Down
5 changes: 3 additions & 2 deletions controllers/front/webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ private function handleWebhookActions($handler, $event)
'addTentative'
);
} elseif (($eventType == 'charge.pending' && $paymentMethodType == 'sofort')
|| (($eventType == 'charge.succeeded' || $eventType == 'payment_intent.requires_action') && $paymentMethodType != 'sofort')
|| (($eventType == 'charge.succeeded' || $eventType == 'payment_intent.requires_action')
&& Stripe_official::$paymentMethods[$paymentMethodType]['flow'] == 'redirect')
) {
ProcessLoggerHandler::logInfo(
'Payment method flow with redirection',
Expand All @@ -570,7 +571,7 @@ private function handleWebhookActions($handler, $event)
}

// Process actions chain
if (!$handler->process('ValidationOrder')) {
if (!$handler->process('ValidationOrderActions')) {
// Handle error
ProcessLoggerHandler::logError(
'Webhook actions process failed.',
Expand Down
10 changes: 5 additions & 5 deletions stripe_official.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ public function getContent()
'registerWebhookSignature'
);

$handler->process('Configuration');
$handler->process('ConfigurationActions');
}

$shopGroupId = Stripe_official::getShopGroupIdContext();
Expand Down Expand Up @@ -1408,9 +1408,9 @@ public function getPaymentMethods()
$query->from('configuration');
$query->where('name LIKE "STRIPE_PAYMENT%"');
$query->where('value = "on"');
if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') === 1) {
$query->where('id_shop = '.$this->context->shop->id);
}
$query->where('id_shop_group = '.$this->context->shop->id_shop_group);
$query->where('id_shop = '.$this->context->shop->id);

$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query->build());

foreach ($results as &$result) {
Expand Down Expand Up @@ -1678,7 +1678,7 @@ public function hookHeader()
'stripe_pk' => $this->getPublishableKey(),
'stripe_merchant_country_code' => $merchantCountry->iso_code,

'stripe_currency' => Tools::strtolower($currency),
'stripe_currency' => Tools::strtolower($currency->iso_code),
'stripe_amount' => Tools::ps_round($amount, 2),

'stripe_fullname' => $stripe_fullname,
Expand Down

0 comments on commit f24f07f

Please sign in to comment.