Skip to content

Commit

Permalink
PHPSDK-114: Adjustments in PaymentMethod object (#314)
Browse files Browse the repository at this point in the history
* PHPSDK-114: Adjustment in Payment Methods endpoint methods

* Remove extra lines (#315)
  • Loading branch information
danielcivit authored Dec 2, 2022
1 parent 52030fb commit ef9ce7b
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 27 deletions.
51 changes: 24 additions & 27 deletions src/Api/PaymentMethods/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PaymentMethod
public const APPS_KEY = 'apps';
public const TOKENIZATION_KEY = 'tokenization';
public const TOKENIZATION_MODELS_KEY = 'models';
public const TOKENIZATION_IS_ENABLED_KEY = 'is_enabled';
public const IS_ENABLED_KEY = 'is_enabled';
public const SHOPPING_CART_REQUIRED_KEY = 'shopping_cart_required';
public const PREFERRED_COUNTRIES_KEY = 'preferred_countries';
public const ALLOWED_COUNTRIES_KEY = 'allowed_countries';
Expand All @@ -37,13 +37,12 @@ class PaymentMethod
public const ICON_URLS_MEDIUM_KEY = 'medium';
public const ICON_URLS_VECTOR_KEY = 'vector';
public const REQUIRED_CUSTOMER_DATA_KEY = 'required_customer_data';
public const ALLOWED_APPS_PAYMENT_COMPONENT = 'payment_component';
public const ALLOWED_APPS_PAYMENT_COMPONENT_WITH_FIELDS = 'has_fields';
public const ALLOWED_APPS_FAST_CHECKOUT = 'fastcheckout';
public const RECURRING_MODEL_CARD_ON_FILE = 'cardonfile';
public const RECURRING_MODEL_SUBSCRIPTION = 'subscription';
public const RECURRING_MODEL_UNSCHEDULED = 'unscheduled';

public const PAYMENT_COMPONENT_KEY = 'payment_components';
public const PAYMENT_COMPONENT_HAS_FIELDS_KEY = 'has_fields';
public const FAST_CHECKOUT_KEY = 'fastcheckout';
public const RECURRING_MODEL_CARD_ON_FILE_KEY = 'cardonfile';
public const RECURRING_MODEL_SUBSCRIPTION_KEY = 'subscription';
public const RECURRING_MODEL_UNSCHEDULED_KEY = 'unscheduled';

/**
* @var string
Expand All @@ -61,7 +60,7 @@ class PaymentMethod
private $type;

/**
* $var array
* @var array
*/
private $allowedAmount;

Expand Down Expand Up @@ -110,7 +109,6 @@ class PaymentMethod
*/
private $requiredCustomerData;


/**
* Transaction constructor.
* @param array $data
Expand Down Expand Up @@ -266,27 +264,26 @@ public function getRequiredCustomerData(): ?array
*/
public function supportsPaymentComponent(): bool
{
return isset($this->apps[self::ALLOWED_APPS_PAYMENT_COMPONENT]) &&
$this->apps[self::ALLOWED_APPS_PAYMENT_COMPONENT_WITH_FIELDS] &&
$this->apps[self::ALLOWED_APPS_PAYMENT_COMPONENT];
return isset($this->apps[self::PAYMENT_COMPONENT_KEY]) &&
$this->apps[self::PAYMENT_COMPONENT_KEY][self::IS_ENABLED_KEY] &&
$this->apps[self::PAYMENT_COMPONENT_KEY][self::PAYMENT_COMPONENT_HAS_FIELDS_KEY];
}


/**
* @return bool
*/
public function supportsFastCheckout(): bool
{
return isset($this->apps[self::ALLOWED_APPS_FAST_CHECKOUT]) &&
$this->apps[self::ALLOWED_APPS_FAST_CHECKOUT];
return isset($this->apps[self::FAST_CHECKOUT_KEY]) &&
$this->apps[self::FAST_CHECKOUT_KEY][self::IS_ENABLED_KEY];
}

/**
* @return bool
*/
public function supportsTokenization(): bool
{
return $this->tokenization[self::TOKENIZATION_IS_ENABLED_KEY];
return $this->tokenization[self::IS_ENABLED_KEY];
}

/**
Expand All @@ -298,8 +295,8 @@ public function supportsTokenizationCardOnFile(): bool
return false;
}

return isset($this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_CARD_ON_FILE]) &&
$this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_CARD_ON_FILE];
return isset($this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_CARD_ON_FILE_KEY]) &&
$this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_CARD_ON_FILE_KEY];
}

/**
Expand All @@ -311,8 +308,8 @@ public function supportsTokenizationSubscription(): bool
return false;
}

return isset($this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_SUBSCRIPTION]) &&
$this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_SUBSCRIPTION];
return isset($this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_SUBSCRIPTION_KEY]) &&
$this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_SUBSCRIPTION_KEY];
}

/**
Expand All @@ -324,8 +321,8 @@ public function supportsTokenizationUnscheduled(): bool
return false;
}

return isset($this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_UNSCHEDULED]) &&
$this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_UNSCHEDULED];
return isset($this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_UNSCHEDULED_KEY]) &&
$this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_UNSCHEDULED_KEY];
}

/**
Expand All @@ -348,11 +345,11 @@ public function getData(): array
self::ALLOWED_COUNTRIES_KEY => $this->allowedCountries,
self::APPS_KEY => $this->apps,
self::TOKENIZATION_KEY => [
self::TOKENIZATION_IS_ENABLED_KEY => $this->tokenization[self::TOKENIZATION_IS_ENABLED_KEY] ?? false,
self::IS_ENABLED_KEY => $this->tokenization[self::IS_ENABLED_KEY] ?? false,
self::TOKENIZATION_MODELS_KEY => [
self::RECURRING_MODEL_CARD_ON_FILE => $this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_CARD_ON_FILE] ?? false,
self::RECURRING_MODEL_SUBSCRIPTION => $this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_SUBSCRIPTION] ?? false,
self::RECURRING_MODEL_UNSCHEDULED => $this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_UNSCHEDULED] ?? false,
self::RECURRING_MODEL_CARD_ON_FILE_KEY => $this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_CARD_ON_FILE_KEY] ?? false,
self::RECURRING_MODEL_SUBSCRIPTION_KEY => $this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_SUBSCRIPTION_KEY] ?? false,
self::RECURRING_MODEL_UNSCHEDULED_KEY => $this->tokenization[self::TOKENIZATION_MODELS_KEY][self::RECURRING_MODEL_UNSCHEDULED_KEY] ?? false,
],
],
self::SHOPPING_CART_REQUIRED_KEY => $this->shoppingCartRequired,
Expand Down
23 changes: 23 additions & 0 deletions tests/Functional/GetPaymentMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,27 @@ public function testGetPaymentMethodsWithWrongPath()
$this->expectException(ApiException::class);
$this->getClient()->createGetRequest('json/gateways-wrong');
}

/**
* @throws ClientExceptionInterface
*/
public function testGetPaymentMethodByCode()
{
$response = $this->getClient()->createGetRequest('json/payment-methods/VISA');
$paymentMethod = $response->getResponseData();

$this->assertIsArray($paymentMethod);
$this->assertNotEmpty($paymentMethod[PaymentMethod::ID_KEY]);
$this->assertNotEmpty($paymentMethod[PaymentMethod::NAME_KEY]);
$this->assertNotEmpty($paymentMethod[PaymentMethod::ALLOWED_AMOUNT_KEY]);
$this->assertIsArray($paymentMethod[PaymentMethod::ALLOWED_CURRENCIES_KEY]);
$this->assertIsArray($paymentMethod[PaymentMethod::BRANDS_KEY]);
$this->assertIsArray($paymentMethod[PaymentMethod::PREFERRED_COUNTRIES_KEY]);
$this->assertIsArray($paymentMethod[PaymentMethod::REQUIRED_CUSTOMER_DATA_KEY]);
$this->assertIsBool($paymentMethod[PaymentMethod::SHOPPING_CART_REQUIRED_KEY]);
$this->assertIsArray($paymentMethod[PaymentMethod::APPS_KEY]);
$this->assertIsArray($paymentMethod[PaymentMethod::TOKENIZATION_KEY]);
$this->assertNotEmpty($paymentMethod[PaymentMethod::TYPE_KEY]);
$this->assertIsArray($paymentMethod[PaymentMethod::ICON_URLS_KEY]);
}
}
16 changes: 16 additions & 0 deletions tests/Integration/Api/PaymentMethodManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,20 @@ public function testGetByCodeWithWrongCode()
$gateways = new PaymentMethodManager($mockClient);
$gateways->getByGatewayCode('WRONG');
}

/**
* @throws ClientExceptionInterface
* @throws Exception
*/
public function testGetVisa()
{
$mockClient = MockClient::getInstance();
$mockClient->mockResponseFromFixtureFile('payment-method-visa');

$paymentMethodManager = new PaymentMethodManager($mockClient);
$paymentMethod = $paymentMethodManager->getByGatewayCode('VISA');

$this->assertTrue($paymentMethod->supportsPaymentComponent());
$this->assertTrue($paymentMethod->supportsTokenization());
}
}
76 changes: 76 additions & 0 deletions tests/fixture-data/payment-method-visa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"data": {
"additional_data": {},
"allowed_amount": {
"max": null,
"min": 0
},
"allowed_countries": [],
"allowed_currencies": [
"AED",
"AUD",
"BRL",
"CAD",
"CHF",
"CLP",
"CNY",
"CZK",
"DKK",
"EUR",
"GBP",
"HKD",
"HRK",
"HUF",
"ILS",
"INR",
"ISK",
"JPY",
"MXN",
"MYR",
"NOK",
"NZD",
"PEN",
"PHP",
"PLN",
"RUB",
"SEK",
"SGD",
"THB",
"TRY",
"TWD",
"USD",
"VEF",
"ZAR"
],
"apps": {
"fastcheckout": {
"is_enabled": true
},
"payment_components": {
"has_fields": true,
"is_enabled": true
}
},
"brands": [],
"icon_urls": {
"large": "https://testmedia.multisafepay.com/img/methods/3x/visa.png",
"medium": "https://testmedia.multisafepay.com/img/methods/2x/visa.png",
"vector": "https://testmedia.multisafepay.com/img/methods/svg/visa.svg"
},
"id": "VISA",
"name": "Visa",
"preferred_countries": [],
"required_customer_data": [],
"shopping_cart_required": false,
"tokenization": {
"is_enabled": true,
"models": {
"cardonfile": true,
"subscription": true,
"unscheduled": true
}
},
"type": "payment-method"
},
"success": true
}

0 comments on commit ef9ce7b

Please sign in to comment.