Skip to content

Commit

Permalink
Merge pull request #52 from AltaPay/support-selected-scheme
Browse files Browse the repository at this point in the history
Add option to set  selected_scheme for initiatePayment request
  • Loading branch information
emicha authored Feb 7, 2025
2 parents d4849f9 + 0c745d3 commit aa1a672
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.4.7] - 2025-02-06
### Added
- Provide `setSelectedScheme` method to set `selected_scheme` for `initiatePayment`.
- Added the `SelectedSchemes` class to define allowed values for `setSelectedScheme` method.

## [3.4.6] - 2025-01-14
### Added
- Include `AuthenticationResult` in `Transaction` class.
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ abstract class AbstractApi
/**
* PHP API version
*/
const PHP_API_VERSION = '3.4.6';
const PHP_API_VERSION = '3.4.7';

/**
* Event dispatcher
Expand Down
18 changes: 17 additions & 1 deletion src/Api/Payments/InitiatePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ public function setShippingMethod($shippingMethod)
return $this;
}

/**
* Sets the selected card scheme.
*
* @param string $selecteScheme
*
* @return $this
*/
public function setSelectedScheme($selecteScheme)
{
$this->unresolvedOptions['selected_scheme'] = $selecteScheme;

return $this;
}

/**
* Configure options
*
Expand Down Expand Up @@ -215,8 +229,10 @@ protected function configureOptions(OptionsResolver $resolver)
'transaction_info',
'agreement',
'fraud_service',
'customer_info'
'customer_info',
'selected_scheme'
]);
$resolver->setAllowedValues('selected_scheme', Types\SelectedSchemes::getAllowed());
$resolver->setNormalizer('cardnum', function (Options $options, $value) {
if (isset($options['credit_card_token'])) {
throw new \InvalidArgumentException(
Expand Down
72 changes: 72 additions & 0 deletions src/Types/SelectedSchemes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Copyright (c) 2025 AltaPay
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Altapay\Types;

/**
* Allowed selected schemes
*/
class SelectedSchemes implements TypeInterface
{
/**
* Allowed selected schemes
*
* @var array<int, string>
*/
private static $schemes = [
'VISA',
'VISA ELECTRON',
'DANKORT',
'MASTERCARD',
'MAESTRO',
'JCB',
'DINERS',
'DISCOVER',
'BANKAXEPT',
'AMERICAN EXPRESS',
'FORBRUGSFORENINGEN',
'UNKNOWN CARD',
];

/**
* Get allowed values
*
* @return array<int, string>
*/
public static function getAllowed()
{
return self::$schemes;
}

/**
* Is the requested value allowed
*
* @param string $value
*
* @return bool
*/
public static function isAllowed($value)
{
return in_array($value, self::$schemes);
}
}

0 comments on commit aa1a672

Please sign in to comment.