Skip to content

Commit 53542f1

Browse files
authored
Merge pull request #64 from AltaPay/add_misisng_customerinfo_param
Add support for new customer organization fields
2 parents b1e1b06 + 89f58b6 commit 53542f1

8 files changed

Lines changed: 204 additions & 4 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: SonarQube Analysis
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ["**"]
7+
8+
jobs:
9+
build:
10+
name: Run SonarQube Analysis
11+
runs-on: self-hosted
12+
13+
steps:
14+
- uses: actions/checkout@v5
15+
with:
16+
fetch-depth: 0
17+
18+
- name: SonarQube Scan
19+
uses: sonarsource/sonarqube-scan-action@v6
20+
env:
21+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
22+
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
23+
24+
- name: SonarQube Quality Gate check
25+
id: sonarqube-quality-gate-check
26+
uses: sonarsource/sonarqube-quality-gate-action@v1.2.0
27+
with:
28+
pollingTimeoutSec: 600
29+
env:
30+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
31+
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

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.5.6] - 2025-10-27
8+
### Added
9+
- Add support for new customer organization fields: `organisation_name`, `organisation_entity_type`, and `organisation_vat_id` with proper validation.
10+
- Deprecate legacy customer fields (`company_name`, `company_type`, `vat_id`, `type`) with runtime warnings and migration guidance.
11+
712
## [3.5.5] - 2025-10-09
813
### Fixes
914
- Fix deprecation warnings on PHP 8.4

docs/request/customerinfo.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ setBankPhone(string) | Customer bank phone | string
4646
setBirthdate(DateTime) | Customer birthdate | DateTime
4747
setCreatedDate(DateTime) | When was the customer created | DateTime
4848
setOrganisationNumber(string) | The country specific organisation number for the customer, if it is a corporate customer. | string
49+
setOrganisationName(string) | The organisation name. **Preferred over setCompanyName()** | string
50+
setOrganisationEntityType(string) | The organisation nature. **Validated values:** ltd (limited company), plc (public limited company), public_institution (public institution), other (all other types). **Preferred over setCompanyType()** | string
51+
setVatId(string) | **Deprecated:** The VAT identifier. Use setOrganisationVatId() instead | string
52+
setOrganisationVatId(string) | The organisation VAT identifier. **Preferred method for VAT ID** | string
4953
setPersonalIdentifyNumber(string) | The country specific personal identity number for the customer, for countries where it is applicable. eg. Norway, Sweden, Finland | string
5054
setGender(string) | What gender is the customer | String (f, female, m, male)
5155
setCardHolderName(string) | Set the cardholder name associated with the customer | string
56+
**Deprecated Methods** | |
57+
setType(string) | **Deprecated:** Customer type indicator. Any organisation_* field automatically triggers business customer | string
58+
setCompanyName(string) | **Deprecated:** Use setOrganisationName() instead | string
59+
setCompanyType(string) | **Deprecated:** Use setOrganisationEntityType() instead | string
5260
```php
5361
$customer->setEmail('email@email.com');
5462
$customer->setBirthdate(new \DateTime('1982-07-23'));

sonar-project.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sonar.projectKey=AltaPay_api-php_90804e1e-91c4-43f6-a024-51f03ac0e4e8
2+
sonar.projectBaseDir=src
3+
sonar.coverage.exclusions=**

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.5.5';
58+
const PHP_API_VERSION = '3.5.6';
5959

6060
/**
6161
* Event dispatcher

src/Request/Customer.php

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace Altapay\Request;
2525

2626
use Altapay\Exceptions\Exception;
27+
use Altapay\Types\OrganisationEntityTypes;
2728

2829
class Customer extends AbstractSerializer
2930
{
@@ -47,27 +48,31 @@ class Customer extends AbstractSerializer
4748
/**
4849
* Indicator of whether the customer is an individual or a business.
4950
*
51+
* @deprecated Any customer_info[organisation_*] field set will trigger the business customer indicator.
5052
* @var string
5153
*/
5254
private $type;
5355

5456
/**
5557
* Name of the customer,if the customer type is Business.
5658
*
59+
* @deprecated Use customer_info[organisation_name] field instead.
5760
* @var string
5861
*/
5962
private $companyName;
6063

6164
/**
6265
* The nature of the company.
6366
*
67+
* @deprecated Use customer_info[organisation_entity_type] field instead.
6468
* @var string
6569
*/
6670
private $companyType;
6771

6872
/**
6973
* The company's VAT registration number.
7074
*
75+
* @deprecated Use customer_info[organisation_vat_id] field instead.
7176
* @var string
7277
*/
7378
private $vatId;
@@ -114,6 +119,27 @@ class Customer extends AbstractSerializer
114119
*/
115120
private $organisationNumber;
116121

122+
/**
123+
* The organisation name.
124+
*
125+
* @var string
126+
*/
127+
private $organisationName;
128+
129+
/**
130+
* The organisation nature (ltd, plc, public_institution, other).
131+
*
132+
* @var string
133+
*/
134+
private $organisationEntityType;
135+
136+
/**
137+
* The organisation VAT identifier.
138+
*
139+
* @var string
140+
*/
141+
private $organisationVatId;
142+
117143
/**
118144
* The country specific personal identity number for the customer,
119145
* for countries where it is applicable. eg. Norway, Sweden, Finland
@@ -315,6 +341,7 @@ public function setUsername($username)
315341
/**
316342
* Set Customer Type
317343
*
344+
* @deprecated Any customer_info[organisation_*] field set will trigger the business customer indicator.
318345
* @param string $type
319346
*
320347
* @return $this
@@ -329,6 +356,7 @@ public function setType($type)
329356
/**
330357
* Set Company Name
331358
*
359+
* @deprecated Use setOrganisationName() method instead.
332360
* @param string $companyName
333361
*
334362
* @return $this
@@ -343,6 +371,7 @@ public function setCompanyName($companyName)
343371
/**
344372
* Set Company Type
345373
*
374+
* @deprecated Use setOrganisationEntityType() method instead.
346375
* @param string $companyType
347376
*
348377
* @return $this
@@ -357,6 +386,7 @@ public function setCompanyType($companyType)
357386
/**
358387
* Set VAT Id
359388
*
389+
* @deprecated Use setOrganisationVatId() method instead. The vat_id field is deprecated.
360390
* @param string $vatId
361391
*
362392
* @return $this
@@ -500,6 +530,54 @@ public function setOrganisationNumber($organisationNumber)
500530
return $this;
501531
}
502532

533+
/**
534+
* Set Organisation Name
535+
*
536+
* @param string $organisationName
537+
*
538+
* @return $this
539+
*/
540+
public function setOrganisationName($organisationName)
541+
{
542+
$this->organisationName = $organisationName;
543+
544+
return $this;
545+
}
546+
547+
/**
548+
* Set Organisation Entity Type
549+
*
550+
* @param string $organisationEntityType
551+
*
552+
* @return $this
553+
*
554+
* @throws Exception
555+
*/
556+
public function setOrganisationEntityType($organisationEntityType)
557+
{
558+
if (!OrganisationEntityTypes::isAllowed($organisationEntityType)) {
559+
throw new Exception('setOrganisationEntityType() only allows the values: ' . implode(', ', OrganisationEntityTypes::getAllowed()));
560+
}
561+
562+
$this->organisationEntityType = $organisationEntityType;
563+
564+
return $this;
565+
}
566+
567+
/**
568+
* Set Organisation VAT ID
569+
*
570+
* @param string $organisationVatId
571+
*
572+
* @return $this
573+
*/
574+
public function setOrganisationVatId($organisationVatId)
575+
{
576+
$this->organisationVatId = $organisationVatId;
577+
578+
return $this;
579+
}
580+
503581
/**
504582
* @param string $personalIdentifyNumber
505583
*
@@ -793,9 +871,20 @@ public function serialize()
793871
}
794872

795873
if ($this->organisationNumber) {
796-
$output['organisationNumber'] = $this->organisationNumber;
874+
$output['organisation_number'] = $this->organisationNumber;
875+
}
876+
877+
if ($this->organisationName) {
878+
$output['organisation_name'] = $this->organisationName;
797879
}
798880

881+
if ($this->organisationEntityType) {
882+
$output['organisation_entity_type'] = $this->organisationEntityType;
883+
}
884+
885+
if ($this->organisationVatId) {
886+
$output['organisation_vat_id'] = $this->organisationVatId;
887+
}
799888
if ($this->personalIdentifyNumber) {
800889
$output['personalIdentifyNumber'] = $this->personalIdentifyNumber;
801890
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 organisation entity types
28+
*/
29+
class OrganisationEntityTypes implements TypeInterface
30+
{
31+
/**
32+
* Allowed organisation entity types
33+
*
34+
* @var list<string>
35+
*/
36+
private static $types = [
37+
'ltd',
38+
'plc',
39+
'public_institution',
40+
'other',
41+
];
42+
43+
/**
44+
* Get allowed values
45+
*
46+
* @return list<string>
47+
*/
48+
public static function getAllowed()
49+
{
50+
return self::$types;
51+
}
52+
53+
/**
54+
* Is the requested value allowed
55+
*
56+
* @param string $value
57+
*
58+
* @return bool
59+
*/
60+
public static function isAllowed($value)
61+
{
62+
return in_array($value, self::$types);
63+
}
64+
}

tests/Request/CustomerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public function test_customer(): void
2121
$customer->setGender('f');
2222
$serialized = $customer->serialize();
2323

24-
$this->assertArrayHasKey('organisationNumber', $serialized);
24+
$this->assertArrayHasKey('organisation_number', $serialized);
2525
$this->assertArrayHasKey('personalIdentifyNumber', $serialized);
2626
$this->assertArrayHasKey('gender', $serialized);
2727

28-
$this->assertSame('123', $serialized['organisationNumber']);
28+
$this->assertSame('123', $serialized['organisation_number']);
2929
$this->assertSame('20304050', $serialized['personalIdentifyNumber']);
3030
$this->assertSame('F', $serialized['gender']);
3131

0 commit comments

Comments
 (0)