Skip to content

Commit b7cdc7b

Browse files
authored
Merge pull request #47 from paynl/rc-1.1.0-2
RC 1.1.0 v2
2 parents 445cc06 + 44bdf25 commit b7cdc7b

339 files changed

Lines changed: 6003 additions & 20201 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/linters/phpcs.xml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/phpcs.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
release:
77
types: [published]
88

9-
109
jobs:
1110
phpcs:
1211
runs-on: ubuntu-latest
@@ -18,11 +17,11 @@ jobs:
1817
- name: Setup PHP
1918
uses: shivammathur/setup-php@v2
2019
with:
21-
php-version: "8.2"
20+
php-version: '8.2'
2221
coverage: none
2322

2423
- name: Install dependencies
2524
run: composer install --no-interaction --prefer-dist --no-progress
2625

2726
- name: Run PHPCS
28-
run: composer phpcs
27+
run: vendor/bin/phpcs

.gitignore

Lines changed: 7 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,16 @@
1-
# Custom added rules
2-
/bin/
1+
# IDE
2+
.idea
33

4-
# Created by https://www.toptal.com/developers/gitignore/api/composer,phpunit,phpstorm+all
5-
# Edit at https://www.toptal.com/developers/gitignore?templates=composer,phpunit,phpstorm+all
6-
7-
### Composer ###
8-
composer.phar
4+
# Composer
95
/vendor/
106

11-
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
12-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
13-
# composer.lock
14-
15-
### PhpStorm+all ###
16-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
17-
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
18-
19-
## Samples ##
7+
# Custom
208
/samples/OrderCreateCustom.php
219

22-
# User-specific stuff
23-
.idea/**/workspace.xml
24-
.idea/**/tasks.xml
25-
.idea/**/usage.statistics.xml
26-
.idea/**/dictionaries
27-
.idea/**/shelf
28-
29-
# AWS User-specific
30-
.idea/**/aws.xml
31-
32-
# Generated files
33-
.idea/**/contentModel.xml
34-
35-
# Sensitive or high-churn files
36-
.idea/**/dataSources/
37-
.idea/**/dataSources.ids
38-
.idea/**/dataSources.local.xml
39-
.idea/**/sqlDataSources.xml
40-
.idea/**/dynamic.xml
41-
.idea/**/uiDesigner.xml
42-
.idea/**/dbnavigator.xml
43-
44-
# Gradle
45-
.idea/**/gradle.xml
46-
.idea/**/libraries
47-
48-
# Gradle and Maven with auto-import
49-
# When using Gradle or Maven with auto-import, you should exclude module files,
50-
# since they will be recreated, and may cause churn. Uncomment if using
51-
# auto-import.
52-
# .idea/artifacts
53-
# .idea/compiler.xml
54-
# .idea/jarRepositories.xml
55-
# .idea/modules.xml
56-
# .idea/*.iml
57-
# .idea/modules
58-
# *.iml
59-
# *.ipr
60-
61-
# CMake
62-
cmake-build-*/
63-
64-
# Mongo Explorer plugin
65-
.idea/**/mongoSettings.xml
66-
67-
# File-based project format
68-
*.iws
69-
70-
# IntelliJ
71-
out/
72-
73-
# mpeltonen/sbt-idea plugin
74-
.idea_modules/
75-
76-
# JIRA plugin
77-
atlassian-ide-plugin.xml
78-
79-
# Cursive Clojure plugin
80-
.idea/replstate.xml
81-
82-
# SonarLint plugin
83-
.idea/sonarlint/
84-
85-
# Crashlytics plugin (for Android Studio and IntelliJ)
86-
com_crashlytics_export_strings.xml
87-
crashlytics.properties
88-
crashlytics-build.properties
89-
fabric.properties
90-
91-
# Editor-based Rest Client
92-
.idea/httpRequests
93-
94-
# Android studio 3.1+ serialized cache file
95-
.idea/caches/build_file_checksums.ser
96-
97-
### PhpStorm+all Patch ###
98-
# Ignore everything but code style settings and run configurations
99-
# that are supposed to be shared within teams.
100-
101-
.idea/*
102-
103-
!.idea/codeStyles
104-
!.idea/runConfigurations
105-
106-
### PHPUnit ###
107-
# Covers PHPUnit
108-
# Reference: https://phpunit.de/
109-
110-
# Generated files
10+
# PHPUnit
11111
.phpunit.result.cache
11212
.phpunit.cache
11313

114-
# PHPUnit
115-
/app/phpunit.xml
116-
/phpunit.xml
117-
118-
# Build data
14+
# Build
11915
/build/
120-
121-
# End of https://www.toptal.com/developers/gitignore/api/composer,phpunit,phpstorm+all
16+
/bin/

Tests/Unit/Model/PayOrderTest.php

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Unit;
6+
7+
use PayNL\Sdk\Model\Amount;
8+
use PayNL\Sdk\Model\Pay\PayOrder;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class PayOrderTest extends TestCase
12+
{
13+
public function testConstructorMapsPayloadObject(): void
14+
{
15+
$payload = [
16+
'object' => [
17+
'id' => 'PO-123',
18+
'description' => 'Test order',
19+
'reference' => 'REF-999',
20+
'status' => ['code' => 200, 'action' => 'PAID'],
21+
'amount' => ['value' => 1000, 'currency' => 'EUR'],
22+
'capturedAmount' => ['value' => 500, 'currency' => 'EUR'],
23+
'authorizedAmount'=> ['value' => 1000, 'currency' => 'EUR'],
24+
],
25+
];
26+
27+
$order = new PayOrder($payload);
28+
29+
$this->assertSame('PO-123', $order->getId());
30+
$this->assertSame('Test order', $order->getDescription());
31+
$this->assertSame('REF-999', $order->getReference());
32+
$this->assertSame(200, $order->getStatusCode());
33+
$this->assertSame('PAID', $order->getStatusName());
34+
}
35+
36+
public function testAmountRefundedIsNullWhenNotSet(): void
37+
{
38+
$order = new PayOrder();
39+
40+
$this->assertNull($order->getAmountRefunded());
41+
}
42+
43+
public function testAmountRefundedReturnsValueInUnits(): void
44+
{
45+
$order = new PayOrder();
46+
$amount = new Amount(1234, 'EUR');
47+
48+
$order->setAmountRefunded($amount);
49+
50+
$this->assertSame(12.34, $order->getAmountRefunded());
51+
}
52+
53+
public function testIsFastCheckoutTrueForPaymentBasedCheckout(): void
54+
{
55+
$order = new PayOrder();
56+
$order->setType('payment_based_checkout');
57+
58+
$this->assertTrue($order->isFastCheckout());
59+
}
60+
61+
public function testIsFastCheckoutFalseForOtherType(): void
62+
{
63+
$order = new PayOrder();
64+
$order->setType('something_else');
65+
66+
$this->assertFalse($order->isFastCheckout());
67+
}
68+
69+
public function testFastCheckoutDataDelegatesToCheckoutData(): void
70+
{
71+
$order = new PayOrder();
72+
$data = ['foo' => 'bar', 'baz' => 123];
73+
74+
$order->setCheckoutData($data);
75+
76+
$this->assertSame($data, $order->getFastCheckoutData());
77+
}
78+
79+
public function testStatusHelpersWithSetStatusCodeName(): void
80+
{
81+
$order = new PayOrder();
82+
83+
$order->setStatusCodeName(321, 'PENDING');
84+
85+
$this->assertSame(321, $order->getStatusCode());
86+
$this->assertSame('PENDING', $order->getStatusName());
87+
}
88+
89+
public function testStatusHelpersWithSetStatus(): void
90+
{
91+
$order = new PayOrder();
92+
$status = ['code' => 999, 'action' => 'SOMETHING'];
93+
94+
$order->setStatus($status);
95+
96+
$this->assertSame(999, $order->getStatusCode());
97+
$this->assertSame('SOMETHING', $order->getStatusName());
98+
$this->assertSame($status, $order->getStatus());
99+
}
100+
101+
public function testPaymentHelpersReturnFirstPaymentData(): void
102+
{
103+
$order = new PayOrder();
104+
105+
$payments = [
106+
[
107+
'paymentMethod' => ['id' => 'IDEAL'],
108+
'customerId' => 'CUST-1',
109+
'customerName' => 'John Doe',
110+
],
111+
];
112+
113+
$order->setPayments($payments);
114+
115+
$this->assertSame('IDEAL', $order->getPaymentMethod());
116+
$this->assertSame('CUST-1', $order->getCustomerId());
117+
$this->assertSame('John Doe', $order->getCustomerName());
118+
}
119+
120+
public function testPaymentHelpersReturnNullWhenNoPayments(): void
121+
{
122+
$order = new PayOrder();
123+
124+
$this->assertNull($order->getPaymentMethod());
125+
$this->assertNull($order->getCustomerId());
126+
$this->assertNull($order->getCustomerName());
127+
}
128+
129+
public function testIsTestmodeTrueWhenIntegrationTestFlagTrue(): void
130+
{
131+
$order = new PayOrder();
132+
133+
$order->setIntegration(['test' => true]);
134+
135+
$this->assertTrue($order->isTestmode());
136+
}
137+
138+
public function testIsTestmodeFalseWhenIntegrationTestFlagMissingOrFalse(): void
139+
{
140+
$order = new PayOrder();
141+
142+
$order->setIntegration(['foo' => 'bar']);
143+
$this->assertFalse($order->isTestmode());
144+
145+
$order->setIntegration(['test' => false]);
146+
$this->assertFalse($order->isTestmode());
147+
}
148+
149+
public function testAmountAndCurrency(): void
150+
{
151+
$order = new PayOrder();
152+
$amount = new Amount(2500, 'EUR'); // 25.00
153+
154+
$order->setAmount($amount);
155+
156+
$this->assertEquals(25.00, $order->getAmount());
157+
$this->assertSame('EUR', $order->getCurrency());
158+
}
159+
160+
161+
public function testPaymentAndStatusUrls(): void
162+
{
163+
$order = new PayOrder();
164+
165+
$links = [
166+
'redirect' => 'https://pay.nl/redirect/123',
167+
'status' => 'https://pay.nl/status/123',
168+
];
169+
170+
$order->setLinks($links);
171+
172+
$this->assertSame($links, $order->getLinks());
173+
$this->assertSame('https://pay.nl/redirect/123', $order->getPaymentUrl());
174+
$this->assertSame('https://pay.nl/status/123', $order->getStatusUrl());
175+
}
176+
177+
public function testChargebackDetection(): void
178+
{
179+
$order = new PayOrder();
180+
181+
$order->setStatus(['code' => 123, 'action' => 'CHARGEBACK']);
182+
$this->assertTrue($order->isChargeBack());
183+
184+
$order->setStatus(['code' => 123, 'action' => 'PAID']);
185+
$this->assertFalse($order->isChargeBack());
186+
}
187+
188+
public function testTransferDataGetterAndSetter(): void
189+
{
190+
$order = new PayOrder();
191+
192+
$data = ['some' => 'value', 'foo' => 'bar'];
193+
194+
$order->setTransferData($data);
195+
196+
$this->assertSame($data, $order->getTransferData());
197+
}
198+
199+
}

0 commit comments

Comments
 (0)