Skip to content

Commit aa1a672

Browse files
authored
Merge pull request #52 from AltaPay/support-selected-scheme
Add option to set selected_scheme for initiatePayment request
2 parents d4849f9 + 0c745d3 commit aa1a672

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [3.4.7] - 2025-02-06
8+
### Added
9+
- Provide `setSelectedScheme` method to set `selected_scheme` for `initiatePayment`.
10+
- Added the `SelectedSchemes` class to define allowed values for `setSelectedScheme` method.
11+
712
## [3.4.6] - 2025-01-14
813
### Added
914
- Include `AuthenticationResult` in `Transaction` class.

src/AbstractApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ abstract class AbstractApi
5555
/**
5656
* PHP API version
5757
*/
58-
const PHP_API_VERSION = '3.4.6';
58+
const PHP_API_VERSION = '3.4.7';
5959

6060
/**
6161
* Event dispatcher

src/Api/Payments/InitiatePayment.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ public function setShippingMethod($shippingMethod)
183183
return $this;
184184
}
185185

186+
/**
187+
* Sets the selected card scheme.
188+
*
189+
* @param string $selecteScheme
190+
*
191+
* @return $this
192+
*/
193+
public function setSelectedScheme($selecteScheme)
194+
{
195+
$this->unresolvedOptions['selected_scheme'] = $selecteScheme;
196+
197+
return $this;
198+
}
199+
186200
/**
187201
* Configure options
188202
*
@@ -215,8 +229,10 @@ protected function configureOptions(OptionsResolver $resolver)
215229
'transaction_info',
216230
'agreement',
217231
'fraud_service',
218-
'customer_info'
232+
'customer_info',
233+
'selected_scheme'
219234
]);
235+
$resolver->setAllowedValues('selected_scheme', Types\SelectedSchemes::getAllowed());
220236
$resolver->setNormalizer('cardnum', function (Options $options, $value) {
221237
if (isset($options['credit_card_token'])) {
222238
throw new \InvalidArgumentException(

src/Types/SelectedSchemes.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2025 AltaPay
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is furnished
10+
* to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
24+
namespace Altapay\Types;
25+
26+
/**
27+
* Allowed selected schemes
28+
*/
29+
class SelectedSchemes implements TypeInterface
30+
{
31+
/**
32+
* Allowed selected schemes
33+
*
34+
* @var array<int, string>
35+
*/
36+
private static $schemes = [
37+
'VISA',
38+
'VISA ELECTRON',
39+
'DANKORT',
40+
'MASTERCARD',
41+
'MAESTRO',
42+
'JCB',
43+
'DINERS',
44+
'DISCOVER',
45+
'BANKAXEPT',
46+
'AMERICAN EXPRESS',
47+
'FORBRUGSFORENINGEN',
48+
'UNKNOWN CARD',
49+
];
50+
51+
/**
52+
* Get allowed values
53+
*
54+
* @return array<int, string>
55+
*/
56+
public static function getAllowed()
57+
{
58+
return self::$schemes;
59+
}
60+
61+
/**
62+
* Is the requested value allowed
63+
*
64+
* @param string $value
65+
*
66+
* @return bool
67+
*/
68+
public static function isAllowed($value)
69+
{
70+
return in_array($value, self::$schemes);
71+
}
72+
}

0 commit comments

Comments
 (0)