Skip to content

Commit

Permalink
Merge pull request #29 from vippsas/publication-1.2.3
Browse files Browse the repository at this point in the history
Publication 1.2.3
  • Loading branch information
voleye authored Feb 25, 2019
2 parents 1b458a3 + d607711 commit 58aa7bd
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 43 deletions.
6 changes: 3 additions & 3 deletions Gateway/Command/CaptureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function __construct(
public function execute(array $commandSubject)
{
$amount = $this->subjectReader->readAmount($commandSubject);
$amount = (int)($this->formatPrice($amount) * 100);
$amount = (int)round($this->formatPrice($amount) * 100);

$response = $this->paymentDetailsProvider->get($commandSubject);
$transaction = $this->transactionBuilder->setData($response)->build();
Expand Down Expand Up @@ -219,14 +219,14 @@ private function captureBasedOnPaymentDetails($commandSubject, Transaction $tran
{
$payment = $this->subjectReader->readPayment($commandSubject);
$amount = $this->subjectReader->readAmount($commandSubject);
$amount = (int)($this->formatPrice($amount) * 100);
$amount = (int)round($this->formatPrice($amount) * 100);

$orderAdapter = $payment->getOrder();
$orderIncrementId = $orderAdapter->getOrderIncrementId();

$order = $this->orderRepository->get($orderAdapter->getId());

$magentoTotalDue = (int)($this->formatPrice($order->getTotalDue()) * 100);
$magentoTotalDue = (int)round($this->formatPrice($order->getTotalDue()) * 100);
$vippsTotalDue = $transaction->getTransactionSummary()->getRemainingAmountToCapture();

$deltaTotalDue = $magentoTotalDue - $vippsTotalDue;
Expand Down
6 changes: 3 additions & 3 deletions Gateway/Command/RefundCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function __construct(
public function execute(array $commandSubject)
{
$amount = $this->subjectReader->readAmount($commandSubject);
$amount = (int)($this->formatPrice($amount) * 100);
$amount = (int)round($this->formatPrice($amount) * 100);

$response = $this->paymentDetailsProvider->get($commandSubject);
$transaction = $this->transactionBuilder->setData($response)->build();
Expand Down Expand Up @@ -220,14 +220,14 @@ private function refundBasedOnPaymentDetails($commandSubject, Transaction $trans
{
$payment = $this->subjectReader->readPayment($commandSubject);
$amount = $this->subjectReader->readAmount($commandSubject);
$amount = (int)($this->formatPrice($amount) * 100);
$amount = (int)round($this->formatPrice($amount) * 100);

$orderAdapter = $payment->getOrder();
$orderIncrementId = $orderAdapter->getOrderIncrementId();

$order = $this->orderRepository->get($orderAdapter->getId());

$magentoTotalRefunded = (int)($this->formatPrice($order->getTotalRefunded()) * 100);
$magentoTotalRefunded = (int)round($this->formatPrice($order->getTotalRefunded()) * 100);
$vippsTotalRefunded = $transaction->getTransactionSummary()->getRefundedAmount();

$deltaTotalRefunded = $vippsTotalRefunded - $magentoTotalRefunded;
Expand Down
30 changes: 1 addition & 29 deletions Gateway/Http/Client/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ class Curl implements ClientInterface
*/
private $logger;

/**
* @var array
*/
private $allowedFields = [
'orderId',
'customerInfo',
'merchantInfo',
'transaction',
];

/**
* Curl constructor.
*
Expand Down Expand Up @@ -125,7 +115,7 @@ private function place(TransferInterface $transfer)
/** @var MagentoCurl $adapter */
$adapter = $this->adapterFactory->create();
$options = $this->getBasicOptions();
$requestBody = $this->preparePostFields($transfer->getBody());
$requestBody = $transfer->getBody();
if ($transfer->getMethod() === Request::METHOD_PUT) {
$options = $options +
[
Expand All @@ -152,24 +142,6 @@ private function place(TransferInterface $transfer)
}
}

/**
* Remove all fields that are not marked as known.
*
* @param array $fields
* @return array
*/
private function preparePostFields($fields)
{
$allowedFields = $this->allowedFields;
$fields = array_filter(
$fields,
function ($key) use ($allowedFields) { return in_array($key, $allowedFields);},
ARRAY_FILTER_USE_KEY
);

return $fields;
}

/**
* @param $headers
*
Expand Down
32 changes: 29 additions & 3 deletions Gateway/Http/TransferFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ class TransferFactory implements TransferFactoryInterface
*/
private $urlParams = [];

/**
* @var array
*/
private $allowedFields = [
'orderId',
'customerInfo',
'merchantInfo',
'transaction',
];

/**
* TransferFactory constructor.
*
Expand Down Expand Up @@ -91,9 +101,7 @@ public function create(array $request)
ClientInterface::HEADER_PARAM_X_REQUEST_ID => $request['requestId'] ?? $this->generateRequestId()
]);

if (isset($request['requestId'])) {
unset($request['requestId']);
}
$request = $this->filterPostFields($request);

$this->transferBuilder
->setBody($this->getBody($request))
Expand All @@ -103,6 +111,24 @@ public function create(array $request)
return $this->transferBuilder->build();
}

/**
* Remove all fields that are not marked as allowed.
*
* @param array $fields
* @return array
*/
private function filterPostFields($fields)
{
$allowedFields = $this->allowedFields;
$fields = array_filter(
$fields,
function ($key) use ($allowedFields) { return in_array($key, $allowedFields);},
ARRAY_FILTER_USE_KEY
);

return $fields;
}

/**
* Generating Url.
*
Expand Down
4 changes: 2 additions & 2 deletions Gateway/Request/Initiate/TransactionDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ public function build(array $buildSubject)
$quote = $payment->getQuote();

$amount = $this->subjectReader->readAmount($buildSubject);
$amount = (int)($this->formatPrice($amount) * 100);
$amount = (int)round($this->formatPrice($amount) * 100);

if ($buildSubject[self::PAYMENT_TYPE_KEY] == self::PAYMENT_TYPE_EXPRESS_CHECKOUT) {
$shippingAddress = $quote->getShippingAddress();
$shippingAddress->setShippingMethod(null);
$quote->collectTotals();

$amount = (int)($this->formatPrice($quote->getGrandTotal()) * 100);
$amount = (int)round($this->formatPrice($quote->getGrandTotal()) * 100);
}

return [
Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/TransactionDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function build(array $buildSubject)

$amount = $this->subjectReader->readAmount($buildSubject);
if ($amount) {
$transactionData[self::$transaction][self::$amount] = (int)($this->formatPrice($amount) * 100);
$transactionData[self::$transaction][self::$amount] = (int)round($this->formatPrice($amount) * 100);
}

return $transactionData;
Expand Down
2 changes: 1 addition & 1 deletion Model/OrderPlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private function prepareQuote($quote)
*/
private function validateAmount(CartInterface $quote, Transaction $transaction)
{
$quoteAmount = (int)($this->formatPrice($quote->getGrandTotal()) * 100);
$quoteAmount = (int)round($this->formatPrice($quote->getGrandTotal()) * 100);
$vippsAmount = (int)$transaction->getTransactionInfo()->getAmount();

if ($quoteAmount != $vippsAmount) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "magento2-module",
"description": "Vipps Payment Method",
"license": "proprietary",
"version": "1.2.2",
"version": "1.2.3",
"require": {
"magento/framework": "101.0.*",
"magento/module-sales": "101.0.*",
Expand Down

0 comments on commit 58aa7bd

Please sign in to comment.