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 #102 from 202-ecommerce/develop
Browse files Browse the repository at this point in the history
develop > master
  • Loading branch information
yves202 authored Nov 25, 2021
2 parents 694d89d + 48bbfb7 commit 5f88fdc
Show file tree
Hide file tree
Showing 62 changed files with 2,382 additions and 1,684 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/vendor
/vendor/*
!/vendor/totpsclasslib
/node_modules
/views/css
Expand Down
2 changes: 1 addition & 1 deletion 202/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<property name="src-dir" value="${basedir}" />
<property name="TARGETNAME" value="stripe_official" />
<property name="TARGETBRANCH" value="${env.GIT_BRANCH}" />
<property name="TARGETVERSION" value="2.3.6" />
<property name="TARGETVERSION" value="2.4.0" />
<property name="PHPVERSION" value="5.6" />
<property name="PSVERSION" value="1.7.5.x" />

Expand Down
2 changes: 1 addition & 1 deletion 202/classlib.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version: release/2.1.0
version: release/2.1.1
15 changes: 8 additions & 7 deletions _dev/js/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ $(function(){
* with Elements.
*
* Please note this form is not submitted when the user chooses the "Pay" button
* or Apple Pay, Google Pay, and Microsoft Pay since they provide name and
* or Apple Pay, and Google Pay since they provide name and
* shipping information directly.
*/
$submit.click(async event => {
Expand Down Expand Up @@ -292,18 +292,18 @@ $(function(){
cardFormPayment = false;
}

if (typeof stripe_compliance != 'undefined' && $('#uniform-cgv').find('input#cgv').prop("checked") !== true) {
/*if (typeof stripe_compliance != 'undefined' && $('#uniform-cgv').find('input#cgv').prop("checked") !== true) {
var error = { "message" : stripe_message.accept_cgv };
updateError($submitButtons, error);
return false;
}
}*/
}

// Disable the Pay button to prevent multiple click events.
disableSubmit(disableText, stripe_message.processing);
createPaymentIntent(payment, id_payment_method, false);

if (paymentIntentDatas.intent.status != 'succeeded') {
if (paymentIntentDatas && paymentIntentDatas.intent.status != 'succeeded') {
if (payment === 'card') {
if (typeof id_payment_method == 'undefined') {
// card payment via stripe form
Expand Down Expand Up @@ -542,11 +542,12 @@ $(function(){
saveCard = datas.saveCard;
},
error: function(err) {
console.log(err.responseText);
paymentIntentDatas = false;
console.log(err.responseText);
var error = {
'message': err.responseText
}
updateError($('#stripe-'+payment+'element'), error);
updateError($('#stripe-'+payment+'-element'), error);
}
});
}
Expand Down Expand Up @@ -646,7 +647,7 @@ $(function(){
// Update error message
function updateError(element, error) {
const $error = $(".stripe-payment-form:visible .stripe-error-message");
var elementError = $(element).siblings('.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') {
Expand Down
261 changes: 261 additions & 0 deletions classes/StripeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
<?php
/**
* 2007-2019 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 202-ecommerce <[email protected]>
* @copyright Copyright (c) Stripe
* @license Commercial license
*/

class StripeEvent extends ObjectModel
{
const CREATED_STATUS = 'CREATED';
const PENDING_STATUS = 'PENDING';
const AUTHORIZED_STATUS = 'AUTHORIZED';
const CAPTURED_STATUS = 'CAPTURED';
const REFUNDED_STATUS = 'REFUNDED';
const FAILED_STATUS = 'FAILED';
const EXPIRED_STATUS = 'EXPIRED';
const REQUIRES_ACTION_STATUS = 'REQUIRES_ACTION';

/**
* @var string $id_payment_intent
*/
public $id_payment_intent;
/**
* @var string $status
*/
public $status;
/**
* @var DateTime $date_add
*/
public $date_add;
/**
* @var bool $is_processed
*/
public $is_processed;
/**
* @var $flow_type
*/
public $flow_type = 'webhook';

/**
* @var array $definition
* @see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'stripe_event',
'primary' => 'id_stripe_event',
'fields' => array(
'id_payment_intent' => array(
'type' => ObjectModel::TYPE_STRING,
'validate' => 'isString',
'size' => 40,
),
'status' => array(
'type' => ObjectModel::TYPE_STRING,
'validate' => 'isString',
'size' => 30,
),
'date_add' => array(
'type' => ObjectModel::TYPE_DATE,
'validate' => 'isDate',
),
'is_processed' => array(
'type' => ObjectModel::TYPE_BOOL,
'validate' => 'isBool',
),
'flow_type' => array(
'type' => ObjectModel::TYPE_STRING,
'validate' => 'isString',
'size' => 30,
),
),
);

public function setIdPaymentIntent($id_payment_intent)
{
$this->id_payment_intent = $id_payment_intent;
}

public function getIdPaymentIntent()
{
return $this->id_payment_intent;
}

public function setStatus($status)
{
$this->status = $status;
}

public function getStatus()
{
return $this->status;
}

public function setDateAdd($date_add)
{
$this->date_add = $date_add;
}

public function getDateAdd()
{
return $this->date_add;
}

public function isProcessed()
{
return $this->is_processed;
}

public function setIsProcessed($is_processed)
{
$this->is_processed = $is_processed;
}

public function setFlowType($flow_type)
{
$this->flow_type = $flow_type;
}

public function getFlowType()
{
return $this->flow_type;
}

public function getLastRegisteredEventByPaymentIntent($paymentIntent)
{
$query = new DbQuery();
$query->select('*');
$query->from(static::$definition['table']);
$query->where('id_payment_intent = "' . pSQL($paymentIntent) . '"');
$query->orderBy('date_add DESC');

$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query->build());
if ($result == false) {
return $this;
}

$this->hydrate($result);

return $this;
}

public function getEventByPaymentIntentNStatus($paymentIntent, $status)
{
$query = new DbQuery();
$query->select('*');
$query->from(static::$definition['table']);
$query->where('id_payment_intent = "' . pSQL($paymentIntent) . '" AND status = "' . pSQL($status) . '"');

$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query->build());
if ($result == false) {
return $this;
}

$this->hydrate($result);

return $this;
}

public static function getStatusAssociatedToChargeType($chargeType)
{
switch ($chargeType)
{
case 'charge.succeeded':
case 'succeeded':
return StripeEvent::AUTHORIZED_STATUS;

case 'charge.captured':
case 'captured':
return StripeEvent::CAPTURED_STATUS;

case 'charge.refunded':
case 'refunded':
return StripeEvent::REFUNDED_STATUS;

case 'charge.failed':
case 'failed':
return StripeEvent::FAILED_STATUS;

case 'charge.expired':
case 'expired':
return StripeEvent::EXPIRED_STATUS;

case 'charge.pending':
case 'pending':
return StripeEvent::PENDING_STATUS;

case 'payment_intent.requires_action':
case 'requires_action':
return StripeEvent::REQUIRES_ACTION_STATUS;

default:
return false;
}
}

public static function getTransitionStatusByNewStatus($newStatus)
{
switch ($newStatus)
{
case StripeEvent::REQUIRES_ACTION_STATUS:
return [
StripeEvent::CREATED_STATUS,
];

case StripeEvent::PENDING_STATUS:
return [
StripeEvent::CREATED_STATUS,
StripeEvent::REQUIRES_ACTION_STATUS,
];

case StripeEvent::AUTHORIZED_STATUS:
case StripeEvent::FAILED_STATUS:
case StripeEvent::EXPIRED_STATUS:
return [
StripeEvent::CREATED_STATUS,
StripeEvent::REQUIRES_ACTION_STATUS,
StripeEvent::PENDING_STATUS,
];

case StripeEvent::CAPTURED_STATUS:
return [
StripeEvent::AUTHORIZED_STATUS,
];

case StripeEvent::REFUNDED_STATUS:
return [
StripeEvent::AUTHORIZED_STATUS,
StripeEvent::CAPTURED_STATUS,
];

case StripeEvent::CREATED_STATUS:
default:
return [];
}
}

public static function validateTransitionStatus($currentStatus, $newStatus)
{
$transitionStatus = self::getTransitionStatusByNewStatus($newStatus);

return in_array($currentStatus, $transitionStatus);
}
}
4 changes: 4 additions & 0 deletions classes/StripeIdempotencyKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public function getByIdPaymentIntent($id_payment_intent)
return $this;
}

/**
* @throws PrestaShopException
* @throws \Stripe\Exception\ApiErrorException
*/
public function createNewOne($id_cart, $datasIntent)
{
$idempotency_key = $id_cart.'_'.uniqid();
Expand Down
6 changes: 5 additions & 1 deletion classes/actions/ConfigurationActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ public function registerKeys()
&& (($secretKeyTest && $mode) || ($secretKeyLive && !$mode))) {
$secretKey = $mode ? $secretKeyTest : $secretKeyLive;
$stripeClient = new \Stripe\StripeClient($secretKey);
$stripeClient->webhookEndpoints->delete($webhookId);
try {
$stripeClient->webhookEndpoints->delete($webhookId);
} catch (\Stripe\Exception\ApiErrorException $e) {
$this->module->errors[] = $e->getMessage();
}
Configuration::updateValue(Stripe_official::WEBHOOK_SIGNATURE, '', false, $shopGroupId, $shopId);
}

Expand Down
Loading

0 comments on commit 5f88fdc

Please sign in to comment.