dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
payment_validation_test.php
Go to the documentation of this file.
1<?php
2
3require_once dirname(__DIR__) . '/include/dbxShopPayPal.class.php';
4require_once dirname(__DIR__) . '/include/dbxShopAmazonPay.class.php';
5
8
9$fail = static function (string $message, int $code): void {
10 fwrite(STDERR, "FAIL: $message\n");
11 exit($code);
12};
13
14$order = array(
15 'id' => 7,
16 'order_no' => 'S-SECURITY-1',
17 'total_gross' => 119.90,
18 'currency' => 'EUR',
19);
20
22 'id' => 'PAYPAL-ORDER-1',
23 'status' => 'COMPLETED',
24 'purchase_units' => array(array(
25 'reference_id' => 'S-SECURITY-1',
26 'invoice_id' => 'S-SECURITY-1',
27 'payments' => array('captures' => array(array(
28 'id' => 'CAPTURE-1',
29 'status' => 'COMPLETED',
30 'amount' => array('value' => '119.90', 'currency_code' => 'EUR'),
31 ))),
32 )),
33);
34
35$paypal = new dbxShopPayPal();
36try {
37 $paypal->validateCapture($paypalResult, $order, 'PAYPAL-ORDER-1');
38} catch (Throwable $e) {
39 $fail('Gueltiger PayPal-Capture wurde abgelehnt: ' . $e->getMessage(), 1);
40}
41
43$badPayPal['purchase_units'][0]['payments']['captures'][0]['amount']['value'] = '19.90';
44try {
45 $paypal->validateCapture($badPayPal, $order, 'PAYPAL-ORDER-1');
46 $fail('PayPal-Betragsabweichung wurde akzeptiert.', 2);
47} catch (RuntimeException $e) {
48 // Erwartet.
49}
50
52 '_http_status' => 200,
53 'checkoutSessionId' => 'AMAZON-SESSION-1',
54 'statusDetails' => array('state' => 'Completed'),
55 'merchantMetadata' => array('merchantReferenceId' => 'S-SECURITY-1'),
56 'paymentDetails' => array(
57 'chargeAmount' => array('amount' => '119.90', 'currencyCode' => 'EUR'),
58 ),
59);
60
61$amazon = new dbxShopAmazonPay();
62try {
63 $status = $amazon->validateCompletion($amazonResult, $order, 'AMAZON-SESSION-1');
64 if ($status !== 'completed') $fail('Amazon-Pay-Status wurde falsch normalisiert.', 3);
65} catch (Throwable $e) {
66 $fail('Gueltige Amazon-Pay-Antwort wurde abgelehnt: ' . $e->getMessage(), 4);
67}
68
70$badAmazon['merchantMetadata']['merchantReferenceId'] = 'ANDERE-BESTELLUNG';
71try {
72 $amazon->validateCompletion($badAmazon, $order, 'AMAZON-SESSION-1');
73 $fail('Amazon-Pay-Antwort einer anderen Bestellung wurde akzeptiert.', 5);
74} catch (RuntimeException $e) {
75 // Erwartet.
76}
77
78$paypalSource = file_get_contents(dirname(__DIR__) . '/include/dbxShopPayPal.class.php');
79$amazonSource = file_get_contents(dirname(__DIR__) . '/include/dbxShopAmazonPay.class.php');
80if (strpos((string)$paypalSource, 'PayPal-Request-Id: dbx-') === false
81 || strpos((string)$amazonSource, "'checkout|' . (string)(\$order['order_no'] ?? '')") === false) {
82 $fail('Provider-Create/Capture-Aufrufe besitzen keine stabile Idempotenz-ID.', 6);
83}
84
85echo "OK shop payment validation\n";
exit
Definition index.php:146
catch(RuntimeException $e) $paypalSource
catch(RuntimeException $e) $amazonResult
catch(Throwable $e) $badAmazon
catch(Throwable $e) $badPayPal