Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
commerce-3222305
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Issue forks
commerce-3222305
Commits
59a6f5d0
Commit
59a6f5d0
authored
7 years ago
by
Bojan Živanović
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2928972
by bojanz: Add PaymentGatewayBase::toMinorUnits()
parent
70ab01e5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php
+25
-0
25 additions, 0 deletions
...src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php
with
25 additions
and
0 deletions
modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php
+
25
−
0
View file @
59a6f5d0
...
...
@@ -9,6 +9,7 @@ use Drupal\commerce_payment\Exception\HardDeclineException;
use
Drupal\commerce_payment
\Exception\InvalidRequestException
;
use
Drupal\commerce_payment
\PaymentMethodTypeManager
;
use
Drupal\commerce_payment
\PaymentTypeManager
;
use
Drupal\commerce_price
\Calculator
;
use
Drupal\commerce_price
\Price
;
use
Drupal\Component\Datetime\TimeInterface
;
use
Drupal\Component\Utility\NestedArray
;
...
...
@@ -360,6 +361,30 @@ abstract class PaymentGatewayBase extends PluginBase implements PaymentGatewayIn
return
$operations
;
}
/**
* Converts the given amount to its minor units.
*
* For example, 9.99 USD becomes 999.
*
* @param \Drupal\commerce_price\Price $amount
* The amount.
*
* @return int
* The amount in minor units, as an integer.
*/
protected
function
toMinorUnits
(
Price
$amount
)
{
$currency_storage
=
$this
->
entityTypeManager
->
getStorage
(
'commerce_currency'
);
/** @var \Drupal\commerce_price\Entity\CurrencyInterface $currency */
$currency
=
$currency_storage
->
load
(
$amount
->
getCurrencyCode
());
$fraction_digits
=
$currency
->
getFractionDigits
();
$number
=
$amount
->
getNumber
();
if
(
$fraction_digits
>
0
)
{
$number
=
Calculator
::
multiply
(
$number
,
pow
(
10
,
$fraction_digits
));
}
return
round
(
$number
,
0
);
}
/**
* Gets the remote customer ID for the given user.
*
...
...
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