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
04e35b26
Commit
04e35b26
authored
3 years ago
by
Vadym Abramchuk
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3270758
by abramm: Fix possible issue with adding new card to the customer account
parent
ec8fa305
No related branches found
No related tags found
1 merge request
!6
Issue #3270758: 3D Secure support
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/Commerce/PaymentGateway/Omise.php
+34
-4
34 additions, 4 deletions
src/Plugin/Commerce/PaymentGateway/Omise.php
with
34 additions
and
4 deletions
src/Plugin/Commerce/PaymentGateway/Omise.php
+
34
−
4
View file @
04e35b26
...
...
@@ -458,6 +458,10 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface {
if
(
$customer_id
)
{
// If the customer id already exists
// use the Omise form token to create the new card.
// Retrieve card ID by token. It will be later used to identify the newly
// created card in the customer's cards list.
$cardByToken
=
$this
->
retrieveCardIdByToken
(
$payment_details
[
'omise_token'
]);
$customer
=
\OmiseCustomer
::
retrieve
(
$customer_id
,
$this
->
configuration
[
'public_key'
],
...
...
@@ -466,8 +470,6 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface {
// Create a payment method for an existing customer.
$customer
->
update
([
'card'
=>
$payment_details
[
'omise_token'
]]);
// Unfortunately, there's no way to fetch the card we've just created so
// the best we can do here is to extract the newest one.
// Retrieve the list of cards, starting with the newest first.
$cards
=
\OmiseCustomer
::
retrieve
(
$customer
[
'id'
],
...
...
@@ -476,9 +478,15 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface {
)
->
cards
([
'order'
=>
'reverse_chronological'
]);
foreach
(
$cards
[
'data'
]
as
$card
)
{
return
$card
;
// Verify card was successfully added to the customer's account.
$newlyCreatedCards
=
array_filter
(
$cards
[
'data'
],
function
(
$card
)
use
(
$cardByToken
)
{
return
$card
[
'id'
]
===
$cardByToken
;
});
if
(
count
(
$newlyCreatedCards
)
!==
1
)
{
throw
new
\RuntimeException
(
'Could not retrieve newly created Omise card.'
);
}
return
reset
(
$newlyCreatedCards
);
}
elseif
(
$owner
&&
$owner
->
isAuthenticated
())
{
// Create both the customer and the payment method.
...
...
@@ -575,4 +583,26 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface {
throw
new
\LogicException
(
'Omise payment gateway does not support Notify method'
);
}
/**
* Retrieves card ID by token.
*
* @param string $token
* The token string.
*
* @return string
* The card ID.
*/
protected
function
retrieveCardIdByToken
(
$token
)
{
$cardByToken
=
\OmiseToken
::
retrieve
(
$token
,
$this
->
configuration
[
'public_key'
],
$this
->
configuration
[
'secret_key'
]
);
if
(
empty
(
$cardByToken
[
'card'
][
'id'
]))
{
throw
new
\RuntimeException
(
'Could not retrieve card ID using token.'
);
}
return
$cardByToken
[
'card'
][
'id'
];
}
}
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