Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
commerce_omise
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
commerce_omise
Commits
fc2c9a88
Commit
fc2c9a88
authored
3 years ago
by
Vadym Abramchuk
Committed by
Vadym Abramchuk
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3270758
by abramm: Add new utility method for retrieving Omise payment from the order
parent
4c766a81
No related branches found
No related tags found
1 merge request
!6
Issue #3270758: 3D Secure support
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
commerce_omise.services.yml
+1
-0
1 addition, 0 deletions
commerce_omise.services.yml
src/OmiseUtil.php
+74
-0
74 additions, 0 deletions
src/OmiseUtil.php
src/OmiseUtilInterface.php
+15
-0
15 additions, 0 deletions
src/OmiseUtilInterface.php
with
90 additions
and
0 deletions
commerce_omise.services.yml
+
1
−
0
View file @
fc2c9a88
services
:
commerce_omise.util
:
class
:
Drupal\commerce_omise\OmiseUtil
arguments
:
[
"
@entity_type.manager"
]
This diff is collapsed.
Click to expand it.
src/OmiseUtil.php
+
74
−
0
View file @
fc2c9a88
...
...
@@ -2,18 +2,46 @@
namespace
Drupal\commerce_omise
;
use
Drupal\commerce_order
\Entity\OrderInterface
;
use
Drupal\commerce_payment
\Entity\PaymentGatewayInterface
;
use
Drupal\commerce_payment
\Exception\AuthenticationException
;
use
Drupal\commerce_payment
\Exception\DeclineException
;
use
Drupal\commerce_payment
\Exception\HardDeclineException
;
use
Drupal\commerce_payment
\Exception\InvalidRequestException
;
use
Drupal\commerce_payment
\Exception\InvalidResponseException
;
use
Drupal\commerce_price
\Price
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
/**
* The Omise utilities.
*/
class
OmiseUtil
implements
OmiseUtilInterface
{
/**
* The commerce_payment entity type storage.
*
* @var \Drupal\commerce_payment\PaymentStorageInterface
*/
protected
$paymentStorage
;
/**
* The commerce_payment_gateway config entity type storage.
*
* @var \Drupal\commerce_payment\PaymentGatewayStorageInterface
*/
protected
$paymentGatewayStorage
;
/**
* Constructs new OmiseUtil object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public
function
__construct
(
EntityTypeManagerInterface
$entityTypeManager
)
{
$this
->
paymentStorage
=
$entityTypeManager
->
getStorage
(
'commerce_payment'
);
$this
->
paymentGatewayStorage
=
$entityTypeManager
->
getStorage
(
'commerce_payment_gateway'
);
}
/**
* {@inheritdoc}
*/
...
...
@@ -72,4 +100,50 @@ class OmiseUtil implements OmiseUtilInterface {
}
}
/**
* {@inheritdoc}
*/
public
function
getOrderPayment
(
OrderInterface
$order
)
{
$payment_ids
=
$this
->
paymentStorage
->
getQuery
()
->
condition
(
'order_id'
,
$order
->
id
())
->
condition
(
'payment_gateway'
,
$this
->
getOmisePaymentGatewaysIds
(),
'IN'
)
->
execute
();
if
(
empty
(
$payment_ids
))
{
// Throw error early if the query returned empty result.
throw
new
\InvalidArgumentException
(
'No Omise payments found for order ID '
.
$order
->
id
());
}
$payments
=
$this
->
paymentStorage
->
loadMultiple
(
$payment_ids
);
if
(
count
(
$payments
)
>
1
)
{
throw
new
\InvalidArgumentException
(
'More than one Omise payment found for order ID '
.
$order
->
id
());
}
$payment
=
reset
(
$payments
);
if
(
!
$payment
)
{
throw
new
\InvalidArgumentException
(
'No Omise payments found for order ID '
.
$order
->
id
());
}
return
$payment
;
}
/**
* Returns list of IDs of all enabled Omise payment gateways.
*/
protected
function
getOmisePaymentGatewaysIds
()
{
$paymentGateways
=
array_filter
(
$this
->
paymentGatewayStorage
->
loadMultiple
(),
function
(
PaymentGatewayInterface
$gateway
)
{
return
$gateway
->
getPluginId
()
===
'omise'
&&
$gateway
->
status
();
});
return
array_map
(
function
(
PaymentGatewayInterface
$gateway
)
{
return
$gateway
->
id
();
},
$paymentGateways
);
}
}
This diff is collapsed.
Click to expand it.
src/OmiseUtilInterface.php
+
15
−
0
View file @
fc2c9a88
...
...
@@ -2,6 +2,7 @@
namespace
Drupal\commerce_omise
;
use
Drupal\commerce_order
\Entity\OrderInterface
;
use
Drupal\commerce_price
\Price
;
/**
...
...
@@ -42,4 +43,18 @@ interface OmiseUtilInterface {
*/
public
function
handleException
(
\OmiseException
$exception
);
/**
* Retrieves Omise payment from the order.
*
* @param \Drupal\commerce_order\Entity\OrderInterface $order
* The order entity.
*
* @return \Drupal\commerce_payment\Entity\PaymentInterface
* The Omise payment entity corresponding given order.
*
* @throws \InvalidArgumentException
* Thrown if there are no or more than one Omise payments for the order.
*/
public
function
getOrderPayment
(
OrderInterface
$order
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment