Skip to content

Commit

Permalink
STRIPE-37: Stripe Split Order Payment (#33943)
Browse files Browse the repository at this point in the history
- Implemented CI fixes
  • Loading branch information
ikrynychanskyi authored Oct 5, 2022
1 parent 932fdf9 commit 5d36c1e
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected function configure()
$this->setDescription('Cancels expiring Stripe authorization holds and places new ones instead.')
->setHelp(
<<<'HELP'
The <info>%command.name%</info> command cancels expiring Stripe authorization holds and places new ones instead (payment card authorizations expire in Stripe after 7 days by default).
The <info>%command.name%</info> command cancels expiring Stripe authorization holds and places new ones instead
(payment card authorizations expire in Stripe after 7 days by default).
<info>php %command.full_name%</info>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function setLogger(LoggerInterface $logger): void
$this->logger = $logger;
}

/**
* @param AbstractCallbackEvent $event
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function onReturn(AbstractCallbackEvent $event)
{
$paymentTransaction = $event->getPaymentTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function reAuthorize(): void
/** @var StripePaymentConfig[] $configs */
$configs = array_filter(
(array)$this->paymentConfigsProvider->getConfigs(),
static fn(StripePaymentConfig $paymentConfig) => $paymentConfig->isReAuthorizationAllowed()
static fn (StripePaymentConfig $paymentConfig) => $paymentConfig->isReAuthorizationAllowed()
);

if (empty($configs)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ define(function(require) {
// Handle additional user actions (3D secure validation, etc.. )
const self = this;

const intentErrorHandler = function () {
const intentErrorHandler = function(result) {
mediator.execute(
'showFlashMessage',
'error',
Expand All @@ -61,7 +61,7 @@ define(function(require) {
);
};

const exceptionHandler = function (error) {
const exceptionHandler = function(error) {
console.log(error);
mediator.execute(
'showFlashMessage',
Expand All @@ -73,27 +73,27 @@ define(function(require) {
const stripe = stripeClient.getStripeInstance(this.options);
if (_.has(response, 'payment_intent_client_secret')) {
stripe.handleCardAction(response.payment_intent_client_secret)
.then(function (result) {
.then(function(result) {
if (result.error) {
intentErrorHandler();
intentErrorHandler(result);
} else if (result.hasOwnProperty('paymentIntent')) {
const paymentIntentId = result.paymentIntent.id;
const intentId = result.paymentIntent.id;
mediator.execute(
'redirectTo',
{url: eventData.responseData.returnUrl + '?paymentIntentId=' + paymentIntentId},
{url: eventData.responseData.returnUrl + '?paymentIntentId=' + intentId},
{redirect: true}
);
}
})
.catch(exceptionHandler)
.always(function () {
.always(function() {
mediator.execute('hideLoading');
});
} else if (_.has(response, 'setup_intent_client_secret')) {
stripe.confirmCardSetup(response.setup_intent_client_secret)
.then(function (result) {
.then(function(result) {
if (result.error) {
intentErrorHandler();
intentErrorHandler(result);
} else if (result.hasOwnProperty('setupIntent')) {
const setupIntentId = result.setupIntent.id;
mediator.execute(
Expand All @@ -104,12 +104,16 @@ define(function(require) {
}
})
.catch(exceptionHandler)
.always(function () {
.always(function() {
mediator.execute('hideLoading');
});
}
} else if (_.has(eventData.responseData, 'partiallyPaidUrl')) {
mediator.execute('redirectTo', {url: eventData.responseData.partiallyPaidUrl}, {redirect: true});
mediator.execute(
'redirectTo',
{url: eventData.responseData.partiallyPaidUrl},
{redirect: true}
);
} else {
mediator.execute('redirectTo', {url: eventData.responseData.errorUrl}, {redirect: true});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function createSetupIntentObject()
private function getStatus(string $card): string
{
return match ($card) {
self::NO_AUTH_CARD => 'succeeded',
self::NO_AUTH_CARD => 'succeeded',
self::AUTH_CARD => 'requires_action',
self::ERROR_CARD => 'error',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class LoadPaymentTransactions extends AbstractFixture implements ContainerAwareI

public function load(ObjectManager $manager): void
{
$transactionExpireHours = $this->container->getParameter('oro_stripe.authorization_transaction_expiration_hours');
$transactionExpireHours = $this->container
->getParameter('oro_stripe.authorization_transaction_expiration_hours');

$expireDate = (new \DateTime('now', new \DateTimeZone('UTC')))
->modify(sprintf('-%d hour', $transactionExpireHours + 1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
use Stripe\SetupIntent;
use Stripe\StripeClient;

/**
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class StripeGatewayTest extends TestCase
{
use SetReflectionPropertyTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function testResponseObject(
$this->assertEquals($expected, $responseData['data']);
}

/**
* @return \Generator
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function responseDataProvider(): \Generator
{
yield [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ public function testSendAuthorizationFailed()
$this->doctrineHelper->expects($this->never())
->method('getSingleEntityIdentifier');

$this->messageNotifications->sendAuthorizationFailed($paymentTransaction, ['[email protected]']);
$this->messageNotifications->sendAuthorizationFailed(
$paymentTransaction,
['[email protected]'],
'Payment card declined'
);
}

public function testSendAuthorizationFailedWhenEntityIsNotOrder()
Expand Down Expand Up @@ -188,4 +192,4 @@ public function testSendAuthorizationFailedWhenEntityIsNotOrder()
'Payment card declined'
);
}
}
}

0 comments on commit 5d36c1e

Please sign in to comment.