Skip to content

Commit

Permalink
PAYOSWXP-115: amazon pay: add platform_id
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy authored and janteuber committed Mar 27, 2024
1 parent 9718a48 commit 31ae088
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 54 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ abstract class AbstractAmazonRequestParameterBuilder extends AbstractRequestPara
{
final public const CLEARING_TYPE = parent::CLEARING_TYPE_WALLET;
final public const WALLET_TYPE = 'AMP';
final public const PLATFORM_ID = 'A1JKLSC6LUW5EW';

public function supports(AbstractRequestParameterStruct $arguments): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function getRequestParameter(AbstractRequestParameterStruct $arguments):
'request' => $arguments->getAction(),
'clearingtype' => self::CLEARING_TYPE,
'wallettype' => self::WALLET_TYPE,
'add_paydata[platform_id]' => self::PLATFORM_ID,
'add_paydata[storename]' => $this->getStoreName($arguments->getSalesChannelContext(), $arguments->getPaymentMethod()),
'add_paydata[checkoutMode]' => 'ProcessOrder',
'add_paydata[productType]' => 'PayAndShip',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace PayonePayment\Payone\RequestParameter\Builder\AmazonPayExpress;

use PayonePayment\PaymentHandler\PayoneAmazonPayExpressPaymentHandler;
use PayonePayment\Payone\RequestParameter\Builder\Amazon\AbstractAmazonRequestParameterBuilder;
use PayonePayment\Payone\RequestParameter\Struct\AbstractRequestParameterStruct;

abstract class AbstractRequestParameterBuilder extends \PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder
{
public function getRequestParameter(AbstractRequestParameterStruct $arguments): array
{
return [
'clearingtype' => AbstractAmazonRequestParameterBuilder::CLEARING_TYPE,
'wallettype' => AbstractAmazonRequestParameterBuilder::WALLET_TYPE,
'add_paydata[platform_id]' => AbstractAmazonRequestParameterBuilder::PLATFORM_ID,
];
}

public function supports(AbstractRequestParameterStruct $arguments): bool
{
return $arguments->getPaymentMethod() === PayoneAmazonPayExpressPaymentHandler::class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace PayonePayment\Payone\RequestParameter\Builder\AmazonPayExpress;

use PayonePayment\PaymentHandler\PayoneAmazonPayExpressPaymentHandler;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\Payone\RequestParameter\Builder\Amazon\AbstractAmazonRequestParameterBuilder;
use PayonePayment\Payone\RequestParameter\Struct\AbstractRequestParameterStruct;
use PayonePayment\Payone\RequestParameter\Struct\PaymentTransactionStruct;

Expand All @@ -17,19 +14,17 @@ class AuthorizeRequestParameterBuilder extends AbstractRequestParameterBuilder
*/
public function getRequestParameter(AbstractRequestParameterStruct $arguments): array
{
return [
return array_merge(parent::getRequestParameter($arguments), [
'request' => $arguments->getAction(),
'clearingtype' => AbstractAmazonRequestParameterBuilder::CLEARING_TYPE,
'wallettype' => AbstractAmazonRequestParameterBuilder::WALLET_TYPE,
];
]);
}

public function supports(AbstractRequestParameterStruct $arguments): bool
{
$action = $arguments->getAction();

return $arguments instanceof PaymentTransactionStruct
&& $arguments->getPaymentMethod() === PayoneAmazonPayExpressPaymentHandler::class
return parent::supports($arguments)
&& $arguments instanceof PaymentTransactionStruct
&& ($action === self::REQUEST_ACTION_AUTHORIZE || $action === self::REQUEST_ACTION_PREAUTHORIZE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use PayonePayment\Components\ConfigReader\ConfigReaderInterface;
use PayonePayment\Components\GenericExpressCheckout\Struct\CreateExpressCheckoutSessionStruct;
use PayonePayment\Configuration\ConfigurationPrefixes;
use PayonePayment\PaymentHandler\PayoneAmazonPayExpressPaymentHandler;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\Payone\RequestParameter\Builder\Amazon\AbstractAmazonRequestParameterBuilder;
use PayonePayment\Payone\RequestParameter\Struct\AbstractRequestParameterStruct;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
Expand All @@ -30,12 +27,11 @@ public function __construct(
*/
public function getRequestParameter(AbstractRequestParameterStruct $arguments): array
{
$requestParameters = [
$requestParameters = array_merge(parent::getRequestParameter($arguments), [
'request' => self::REQUEST_ACTION_GENERIC_PAYMENT,
'add_paydata[action]' => 'createCheckoutSessionPayload',
'clearingtype' => AbstractAmazonRequestParameterBuilder::CLEARING_TYPE,
'wallettype' => AbstractAmazonRequestParameterBuilder::WALLET_TYPE,
'add_paydata[addressRestrictions_type]' => 'Allowed',
];
]);

foreach ($this->getCountryCodes($arguments->getSalesChannelContext()) as $index => $countryCode) {
$requestParameters['add_paydata[addressRestrictions_country_' . $index . ']'] = $countryCode;
Expand All @@ -62,8 +58,7 @@ public function getRequestParameter(AbstractRequestParameterStruct $arguments):

public function supports(AbstractRequestParameterStruct $arguments): bool
{
return $arguments instanceof CreateExpressCheckoutSessionStruct
&& $arguments->getPaymentMethod() === PayoneAmazonPayExpressPaymentHandler::class;
return parent::supports($arguments) && $arguments instanceof CreateExpressCheckoutSessionStruct;
}

private function getCountryCodes(SalesChannelContext $context): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
namespace PayonePayment\Payone\RequestParameter\Builder\AmazonPayExpress;

use PayonePayment\Components\GenericExpressCheckout\Struct\GetCheckoutSessionStruct;
use PayonePayment\PaymentHandler\PayoneAmazonPayExpressPaymentHandler;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\Payone\RequestParameter\Builder\Amazon\AbstractAmazonRequestParameterBuilder;
use PayonePayment\Payone\RequestParameter\Struct\AbstractRequestParameterStruct;

class GetCheckoutSessionDetailsRequestParameterBuilder extends AbstractRequestParameterBuilder
Expand All @@ -17,16 +14,13 @@ class GetCheckoutSessionDetailsRequestParameterBuilder extends AbstractRequestPa
*/
public function getRequestParameter(AbstractRequestParameterStruct $arguments): array
{
return [
return array_merge(parent::getRequestParameter($arguments), [
'add_paydata[action]' => 'getCheckoutSession',
'clearingtype' => AbstractAmazonRequestParameterBuilder::CLEARING_TYPE,
'wallettype' => AbstractAmazonRequestParameterBuilder::WALLET_TYPE,
];
]);
}

public function supports(AbstractRequestParameterStruct $arguments): bool
{
return $arguments instanceof GetCheckoutSessionStruct
&& $arguments->getPaymentMethod() === PayoneAmazonPayExpressPaymentHandler::class;
return parent::supports($arguments) && $arguments instanceof GetCheckoutSessionStruct;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace PayonePayment\Payone\RequestParameter\Builder\AmazonPayExpress;

use PayonePayment\Components\Currency\CurrencyPrecisionInterface;
use PayonePayment\Payone\RequestParameter\Builder\AbstractRequestParameterBuilder;
use PayonePayment\Payone\RequestParameter\Builder\Amazon\AbstractAmazonRequestParameterBuilder;
use PayonePayment\Payone\RequestParameter\Struct\AbstractRequestParameterStruct;
use PayonePayment\Payone\RequestParameter\Struct\AmazonPayExpressUpdateCheckoutSessionStruct;
use Shopware\Core\Checkout\Cart\SalesChannel\CartService;
Expand All @@ -28,19 +26,17 @@ public function getRequestParameter(AbstractRequestParameterStruct $arguments):

$currency = $arguments->getSalesChannelContext()->getCurrency();

return [
return array_merge(parent::getRequestParameter($arguments), [
'request' => self::REQUEST_ACTION_GENERIC_PAYMENT,
'clearingtype' => AbstractAmazonRequestParameterBuilder::CLEARING_TYPE,
'wallettype' => AbstractAmazonRequestParameterBuilder::WALLET_TYPE,
'add_paydata[action]' => 'updateCheckoutSession',
'amount' => $this->currencyPrecision->getRoundedTotalAmount($cart->getPrice()->getTotalPrice(), $currency),
'currency' => $currency->getIsoCode(),
'workorderid' => $arguments->getWorkorderId(),
];
]);
}

public function supports(AbstractRequestParameterStruct $arguments): bool
{
return $arguments instanceof AmazonPayExpressUpdateCheckoutSessionStruct;
return parent::supports($arguments) && $arguments instanceof AmazonPayExpressUpdateCheckoutSessionStruct;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function testIfSuccessful(string $authMethod): void
static::assertIsString($requestParams['backurl']);
static::assertArrayHasKey('errorurl', $requestParams);
static::assertIsString($requestParams['errorurl']);
static::assertArrayHasKey('add_paydata[platform_id]', $requestParams);

// test only a few customer fields
static::assertArrayHasKey('email', $requestParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function testIfSuccessful(string $authMethod): void
static::assertIsString($requestParams['backurl']);
static::assertArrayHasKey('errorurl', $requestParams);
static::assertIsString($requestParams['errorurl']);
static::assertArrayHasKey('add_paydata[platform_id]', $requestParams);


// test only a few customer fields
static::assertArrayHasKey('email', $requestParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function testIfParametersGotCreatedSuccessfulWithoutRestriction(): void
PayoneAmazonPayExpressPaymentHandler::class
));

static::assertArrayHasKey('request', $requestParams);
static::assertEquals('genericpayment', $requestParams['request']);
static::assertArrayHasKey('clearingtype', $requestParams);
static::assertEquals('wlt', $requestParams['clearingtype']);
static::assertArrayHasKey('wallettype', $requestParams);
Expand All @@ -48,6 +50,7 @@ public function testIfParametersGotCreatedSuccessfulWithoutRestriction(): void
static::assertArrayHasKey('backurl', $requestParams);
static::assertArrayHasKey('errorurl', $requestParams);
static::assertArrayNotHasKey('add_paydata[specialRestrictions]', $requestParams);
static::assertArrayHasKey('add_paydata[platform_id]', $requestParams);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public function testIfParametersGotCreatedSuccessful(): void
static::assertEquals('getCheckoutSession', $requestParams['add_paydata[action]']);
static::assertArrayHasKey('workorderid', $requestParams);
static::assertEquals('woi-123456', $requestParams['workorderid']);
static::assertArrayHasKey('add_paydata[platform_id]', $requestParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ public function testIfSuccessful(): void
static::assertIsString($requestParams['currency']);
static::assertArrayHasKey('workorderid', $requestParams);
static::assertEquals('test-123', $requestParams['workorderid']);
static::assertArrayHasKey('add_paydata[platform_id]', $requestParams);
}
}

0 comments on commit 31ae088

Please sign in to comment.