Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-13146 - Fixes a problem when checking transaction eligibility without PPCP #40

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Components/Services/OnboardingStatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ public function getIsCapableResult(

$this->loggerService->debug(sprintf('%s MERCHANT INTEGRATIONS: %s', __METHOD__, \json_encode($response)));

$capabilities = $response['capabilities'];
if (!\is_array($capabilities)) {
return new IsCapableResult(false);
}

$this->lastResponsePaymentsReceivable = $this->getBoolValueFromResponseArray(IsCapableResult::PAYMENTS_RECEIVABLE, $response);
$this->lastResponsePrimaryEmailConfirmed = $this->getBoolValueFromResponseArray(IsCapableResult::PRIMARY_EMAIL_CONFIRMED, $response);

if (!\array_key_exists('capabilities', $response) || !\is_array($response['capabilities'])) {
return new IsCapableResult(false, null, $this->lastResponsePaymentsReceivable, $this->lastResponsePrimaryEmailConfirmed);
}

$capabilities = $response['capabilities'];

$this->lastResponseCapabilities = $capabilities;
$this->expiry = (new DateTime())->add(new DateInterval(self::CACHE_LIFETIME));
}
Expand All @@ -127,7 +128,7 @@ public function getIsCapableResult(

return new IsCapableResult(
$isCapable,
$capability['limits'],
\array_key_exists('limits', $capability) ? $capability['limits'] : null,
$this->lastResponsePaymentsReceivable,
$this->lastResponsePrimaryEmailConfirmed
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,53 @@ public function getIsCapableResultShouldReturnValuesForPaymentsReceivableAndPrim
];
}

/**
* @dataProvider getIsCapableResultWithoutCapabilitiesTestDataProvider
*
* @param bool $paymentsReceivable
* @param bool $primaryEmailConfirmed
* @param bool $expectedPaymentsReceivableResult
* @param bool $expectedPrimaryEmailConfirmedResult
*
* @return void
*/
public function testGetIsCapableResultWithoutCapabilities(
$paymentsReceivable,
$primaryEmailConfirmed,
$expectedPaymentsReceivableResult,
$expectedPrimaryEmailConfirmedResult
) {
$response = [
'merchant_id' => 'FOOBAR42',
'products' => [],
'payments_receivable' => $paymentsReceivable,
'primary_email_confirmed' => $primaryEmailConfirmed,
];

$onboardingStatusService = $this->createOnboardingStatusService(
$this->createMerchantIntegrationsResourceMock($response)
);

$result = $onboardingStatusService->getIsCapableResult('anyPayerId', 1, false);

static::assertFalse($result->isCapable());
static::assertSame($expectedPaymentsReceivableResult, $result->getIsPaymentsReceivable());
static::assertSame($expectedPrimaryEmailConfirmedResult, $result->getIsPrimaryEmailConfirmed());
}

/**
* @return array<string, array<int, bool>>
*/
public function getIsCapableResultWithoutCapabilitiesTestDataProvider()
{
return [
'PaymentsReceivable is false and EmailConfirmed is false' => [false, false, false, false],
'PaymentsReceivable is true and EmailConfirmed is false' => [true, false, true, false],
'PaymentsReceivable is true and EmailConfirmed is true' => [true, true, true, true],
'PaymentsReceivable is false and EmailConfirmed is true' => [false, true, false, true],
];
}

/**
* @param array<string,mixed>|null $response
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SwagPaymentPayPalUnified\PayPalBundle\PaymentType;
use SwagPaymentPayPalUnified\Tests\Functional\ContainerTrait;
use SwagPaymentPayPalUnified\Tests\Functional\ReflectionHelperTrait;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;

class SofortValidatorHandlerTest extends TestCase
Expand All @@ -36,8 +37,12 @@ public function testCreateValidatorShouldNotContainItalyAsCountry()
);

static::assertCount(1, $violationList);
static::assertSame('The value you selected is not a valid choice.', $violationList[0]->getMessage());
static::assertSame('IT', $violationList[0]->getInvalidValue());

$violation = $violationList[0];
static::assertInstanceOf(ConstraintViolationInterface::class, $violation);

static::assertSame('The value you selected is not a valid choice.', $violation->getMessage());
static::assertSame('IT', $violation->getInvalidValue());
}

/**
Expand Down
11 changes: 10 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
<label lang="de">PayPal</label>
<label lang="en">PayPal</label>

<version>6.1.2</version>
<version>6.1.3</version>
<copyright>(c) by shopware AG</copyright>
<license>MIT</license>
<link>http://store.shopware.com</link>
<author>shopware AG</author>
<compatibility minVersion="5.2.27" maxVersion="5.99.99"/>

<changelog version="6.1.3">
<changes lang="de">
PT-13146 - Behebt ein Problem bei der Überprüfung der Transaktionsfähigkeit ohne PPCP;
</changes>
<changes lang="en">
PT-13146 - Fixes a problem when checking transaction eligibility without PPCP;
</changes>
</changelog>

<changelog version="6.1.2">
<changes lang="de">
PT-13142 - Verbessert die Bearbeitung von Webhooks;
Expand Down