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
a53fb5d8
Commit
a53fb5d8
authored
3 years ago
by
Vadym Abramchuk
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3271932
: Payment processing error after changing the API key
parent
c56519ad
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!7
Issue #3271932: Payment processing error after changing the API key
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/Commerce/PaymentGateway/Omise.php
+42
-17
42 additions, 17 deletions
src/Plugin/Commerce/PaymentGateway/Omise.php
with
42 additions
and
17 deletions
src/Plugin/Commerce/PaymentGateway/Omise.php
+
42
−
17
View file @
a53fb5d8
...
...
@@ -17,6 +17,7 @@ use Drupal\Component\Datetime\TimeInterface;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Url
;
use
Drupal\user\UserInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\Request
;
...
...
@@ -185,11 +186,13 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface {
];
$owner
=
$payment_method
->
getOwner
();
if
(
$owner
&&
$owner
->
isAuthenticated
())
{
if
(
$owner
&&
$owner
->
isAuthenticated
()
&&
$remoteCustomer
=
$this
->
getRemoteOmiseCustomer
(
$owner
))
{
// Add remote customer ID if it's available; this is required for
// stored cards.
// @see doCreatePaymentMethod()
$transaction_data
[
'customer'
]
=
$
this
->
getR
emoteCustomer
Id
(
$owner
)
;
$transaction_data
[
'customer'
]
=
$
r
emoteCustomer
[
'id'
]
;
}
if
(
!
empty
(
$this
->
configuration
[
'3d_secure'
]))
{
...
...
@@ -370,12 +373,8 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface {
// Delete the remote record.
try
{
$owner
=
$payment_method
->
getOwner
();
if
(
$owner
&&
$remote_id
=
$this
->
getRemoteCustomerId
(
$owner
))
{
$customer
=
\OmiseCustomer
::
retrieve
(
$remote_id
,
$this
->
configuration
[
'public_key'
],
$this
->
configuration
[
'secret_key'
]
);
if
(
$owner
&&
$customer
=
$this
->
getRemoteOmiseCustomer
(
$owner
))
{
$customer
->
cards
()
->
retrieve
(
$payment_method
->
getRemoteId
())
->
destroy
();
}
}
...
...
@@ -458,22 +457,17 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface {
protected
function
doCreatePaymentMethod
(
PaymentMethodInterface
$payment_method
,
array
$payment_details
)
{
$owner
=
$payment_method
->
getOwner
();
$customer
_id
=
NULL
;
$customer
=
NULL
;
if
(
$owner
&&
$owner
->
isAuthenticated
())
{
$customer
_id
=
$this
->
getRemoteCustomer
Id
(
$owner
);
$customer
=
$this
->
getRemote
Omise
Customer
(
$owner
);
}
if
(
$customer
_id
)
{
// If the customer
id
already exists
if
(
$customer
)
{
// If the customer 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'
],
$this
->
configuration
[
'secret_key'
]
);
// Create a payment method for an existing customer.
$customer
->
update
([
'card'
=>
$payment_details
[
'omise_token'
]]);
...
...
@@ -612,4 +606,35 @@ class Omise extends OnsitePaymentGatewayBase implements OmiseInterface {
return
$cardByToken
[
'card'
][
'id'
];
}
/**
* Retrieves remote Omise customer object.
*
* @param \Drupal\user\UserInterface $account
* The user account.
*
* @return \OmiseCustomer|false
* Omise customer object or FALSE if not found.
*/
protected
function
getRemoteOmiseCustomer
(
UserInterface
$account
)
{
$customerId
=
$this
->
getRemoteCustomerId
(
$account
);
if
(
!
$customerId
)
{
return
FALSE
;
}
try
{
return
\OmiseCustomer
::
retrieve
(
$customerId
,
$this
->
configuration
[
'public_key'
],
$this
->
configuration
[
'secret_key'
]
);
}
catch
(
\OmiseNotFoundException
$e
)
{
if
(
!
$account
->
isAnonymous
())
{
$this
->
setRemoteCustomerId
(
$account
,
NULL
);
$account
->
save
();
}
return
FALSE
;
}
}
}
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