Skip to content

Commit 1570491

Browse files
committed
Fixed nbrech when no schedule. Changed template for debugging. Added 'real' test script.
1 parent 7f79447 commit 1570491

File tree

6 files changed

+85
-9
lines changed

6 files changed

+85
-9
lines changed

Diff for: src/Action/StatusAction.php

+2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ public function execute($request)
4444
case "paiement" : // paiement accepté (en Production uniquement)
4545
$request->markCaptured();
4646
break;
47+
4748
case "Annulation" : // contacter l’émetteur de carte
4849
$request->markFailed();
4950
break;
51+
5052
default :
5153
$request->markUnknown();
5254
}

Diff for: src/Api/Api.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function createPaymentForm(array $data)
9595
'contexte_commande' => base64_encode(utf8_encode(json_encode($data['context']))),
9696
];
9797

98-
$fields['nbrech'] = count($data['schedule']);
98+
$fields['nbrech'] = (0 < $count = count($data['schedule'])) ? $count : null;
9999
for ($i = 1; $i < 5; $i++) {
100100
if (!isset($data['schedule'][$i])) {
101101
$fields['dateech' . $i] = null;
@@ -132,6 +132,7 @@ public function createPaymentForm(array $data)
132132
'action' => $this->getEndpointUrl(static::TYPE_PAYMENT),
133133
'method' => 'POST',
134134
'fields' => $fields,
135+
'debug' => $this->config['debug'],
135136
];
136137
}
137138

Diff for: src/Api/Options/Assert.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function string(int $max, bool $required = false): callable
4949

5050
$length = strlen($value);
5151

52-
return (1 < $length) && ($length <= $max);
52+
return (1 <= $length) && ($length <= $max);
5353
};
5454
}
5555

@@ -78,7 +78,7 @@ public static function integer(int $max, bool $required = false): callable
7878

7979
$length = strlen($value);
8080

81-
return (1 < $length) && ($length <= $max);
81+
return (1 <= $length) && ($length <= $max);
8282
};
8383
}
8484

Diff for: src/Resources/views/api_request.html.twig

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
{% extends layout ?: "@PayumCore/layout.html.twig" %}
22

3-
{% block payum_body %}
3+
{% block payum_body -%}
4+
{% if not debug -%}
45
<p id="message" style="text-align:center;padding-top:50px;display:none;">
56
Vous allez être redirigé vers le site de la banque&hellip;
67
</p>
8+
{%- endif %}
79
<form action="{{ action|raw }}" method="{{ method }}" name="MoneticoPaymentForm" id="MoneticoPaymentForm">
810
{% for name, value in fields -%}
911
<input type="hidden" name="{{ name }}" value="{{ value|raw }}">
1012
{%- endfor %}
11-
<noscript>
13+
{% if not debug %}<noscript>{% endif -%}
1214
<p style="text-align:center;padding-top:50px;">
13-
<button id="submit" type="submit" value="Continuer vers le site de la banque"></button>
15+
<button id="submit" type="submit">
16+
Continuer vers le site de la banque
17+
</button>
1418
</p>
15-
</noscript>
19+
{%- if not debug %}</noscript>{% endif %}
1620
</form>
21+
{% if not debug -%}
1722
<script type="application/javascript">
1823
document.getElementById('message').style.display = 'block';
1924
document.getElementById('MoneticoPaymentForm').submit();
2025
</script>
26+
{%- endif %}
2127
{% endblock %}

Diff for: tests/Api/ApiTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,16 @@ public function test_create_payment_form()
104104
'montantech2' => null,
105105
'montantech3' => null,
106106
'montantech4' => null,
107-
'nbrech' => 0,
107+
'nbrech' => null,
108108
'reference' => '100008783',
109109
'societe' => 'foobar',
110110
'texte-libre' => 'Commande&#x20;100008783',
111111
'url_retour_ok' => 'http://example.org',
112112
'url_retour_err' => 'http://example.org',
113113
'version' => '3.0',
114-
'MAC' => '14ea2a9f24e2ce030889a8176f0cf2c87abf5a10',
114+
'MAC' => '2ea1cd9bd82fbcbf5edf29c18e0269e6e5d7f86a',
115115
],
116+
'debug' => false,
116117
];
117118

118119
$this->assertEquals($expected, $actual);

Diff for: tests/test.php

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/*
4+
* Use this script to test your credentials.
5+
* 'php -S localhost:8000' to start a web server.
6+
*/
7+
8+
require __DIR__ . '/bootstrap.php';
9+
10+
use Ekyna\Component\Payum\Monetico\MoneticoGatewayFactory;
11+
use Ekyna\Component\Payum\Monetico\Request\PaymentForm;
12+
use League\Uri\Http;
13+
use Payum\Core\Model\Payment;
14+
use Payum\Core\PayumBuilder;
15+
use Payum\Core\Reply\HttpResponse;
16+
17+
$paymentClass = Payment::class;
18+
19+
$defaultConfig = [
20+
'mode' => '',
21+
'tpe' => '',
22+
'key' => '',
23+
'company' => '',
24+
'debug' => true,
25+
];
26+
27+
/** @var \Payum\Core\Payum $payum */
28+
$payum = (new PayumBuilder())
29+
->addDefaultStorages()
30+
->addGatewayFactory('monetico', new MoneticoGatewayFactory($defaultConfig))
31+
->addGateway('monetico', [
32+
'factory' => 'monetico',
33+
'sandbox' => true,
34+
])
35+
->getPayum();
36+
37+
/** @var \Payum\Core\Gateway $gateway */
38+
$gateway = $payum->getGateway('monetico');
39+
40+
$uri = Http::createFromServer($_SERVER);
41+
42+
$request = new PaymentForm([
43+
'date' => '25/08/2019:16:30:15',
44+
'amount' => '24.80',
45+
'currency' => 'EUR',
46+
'reference' => '100008784',
47+
'comment' => 'Commande 100008784',
48+
'locale' => 'FR',
49+
'email' => 'test@example.org',
50+
'success_url' => (string)$uri->withPath('/done.php'),
51+
'failure_url' => (string)$uri->withPath('/done.php'),
52+
'context' => [
53+
'billing' => [
54+
"addressLine1" => "101 Rue de Roisel",
55+
"city" => "Y",
56+
"postalCode" => "80190",
57+
"country" => "FR",
58+
],
59+
],
60+
]);
61+
62+
try {
63+
$gateway->execute($request);
64+
} catch (HttpResponse $response) {
65+
echo $response->getContent();
66+
}

0 commit comments

Comments
 (0)