Skip to content

Commit a8881ab

Browse files
[HSDK-6] examples
1 parent a91adf5 commit a8881ab

File tree

5 files changed

+193
-0
lines changed

5 files changed

+193
-0
lines changed

examples/authorization.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
require_once realpath(__DIR__.'/../src/autoload.php');
3+
4+
$ecommerce = new \Sipay\Ecommerce(realpath(__DIR__."/../etc/config.ini"));
5+
6+
$amount = new \Sipay\Amount(200, 'EUR');
7+
8+
$card = new \Sipay\Paymethods\Card('6712009000000205', 2018, 12);
9+
10+
$options = array(
11+
'order' => 'order-test',
12+
'reference' => '1234',
13+
'token' => 'new-token'
14+
);
15+
16+
$auth = $ecommerce->authorization($card, $amount, $options);
17+
18+
if($auth->code == 0) {
19+
print("Autorización aceptada, el pago ha sido completado!\n");
20+
}else{
21+
print("Error: ".$auth->description."\n");
22+
}
23+
24+
$stored_card = new \Sipay\Paymethods\StoredCard('new-token');
25+
26+
$auth2 = $ecommerce->authorization($stored_card, $amount, $options);
27+
28+
if($auth2->code == 0) {
29+
print("Autorización aceptada, el pago ha sido completado!\n");
30+
}else{
31+
print("Error: ".$auth2->description."\n");
32+
}
33+
34+
$fast_pay = new \Sipay\Paymethods\FastPay('0f266784e7ba4e438040fdd1dbbfcd73');
35+
36+
$auth3 = $ecommerce->authorization($fast_pay, $amount, $options);
37+
38+
if($auth3->code == 0) {
39+
print("Autorización aceptada, el pago ha sido completado!\n");
40+
}else{
41+
print("Error: ".$auth3->description."\n");
42+
}

examples/cancellation.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
require_once realpath(__DIR__.'/../src/autoload.php');
3+
4+
$ecommerce = new \Sipay\Ecommerce(realpath(__DIR__."/../etc/config.ini"));
5+
6+
$amount = new \Sipay\Amount(200, 'EUR');
7+
8+
$card = new \Sipay\Paymethods\Card('6712009000000205', 2018, 12);
9+
10+
$auth = $ecommerce->authorization($card, $amount);
11+
12+
if($auth->code == 0) {
13+
print("Autorización aceptada, el pago ha sido completado!\n");
14+
}else{
15+
print("Error: ".$auth->description."\n");
16+
}
17+
18+
$cancel = $ecommerce->cancellation($auth->transaction_id);
19+
20+
if($cancel->code == 0) {
21+
print("Cancelación aceptada!\n");
22+
}else{
23+
print("Error: ".$cancel->description."\n");
24+
}

examples/query.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
require_once realpath(__DIR__.'/../src/autoload.php');
3+
4+
$ecommerce = new \Sipay\Ecommerce(realpath(__DIR__."/../etc/config.ini"));
5+
6+
$amount = new \Sipay\Amount(200, 'EUR');
7+
8+
$card = new \Sipay\Paymethods\Card('6712009000000205', 2018, 12);
9+
10+
$options = array(
11+
'order' => 'order-test'
12+
);
13+
14+
$auth = $ecommerce->authorization($card, $amount, $options);
15+
16+
if($auth->code == 0) {
17+
print("Autorización aceptada, el pago ha sido completado!\n");
18+
}else{
19+
print("Error: ".$auth->description."\n");
20+
}
21+
22+
$auth2 = $ecommerce->authorization($card, $amount, $options);
23+
24+
if($auth2->code == 0) {
25+
print("Autorización aceptada, el pago ha sido completado!\n");
26+
}else{
27+
print("Error: ".$auth2->description."\n");
28+
}
29+
30+
$query = $ecommerce->query(array('order' => 'order-test'));
31+
32+
if($query->code == 0) {
33+
print(count($query->transactions)." transacciones recuperadas con éxito!\n");
34+
}else{
35+
print("Error: ".$query->description."\n");
36+
}

examples/refund.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
require_once realpath(__DIR__.'/../src/autoload.php');
3+
4+
$ecommerce = new \Sipay\Ecommerce(realpath(__DIR__."/../etc/config.ini"));
5+
6+
$amount = new \Sipay\Amount(200, 'EUR');
7+
8+
$card = new \Sipay\Paymethods\Card('6712009000000205', 2018, 12);
9+
10+
$options = array(
11+
'order' => 'order-test',
12+
'reference' => '1234',
13+
'token' => 'new-token'
14+
);
15+
16+
$refund = $ecommerce->refund($card, $amount, $options);
17+
18+
if($refund->code == 0) {
19+
print("Devolución aceptada!\n");
20+
}else{
21+
print("Error: ".$refund->description."\n");
22+
}
23+
24+
$stored_card = new \Sipay\Paymethods\StoredCard('new-token');
25+
26+
$refund2 = $ecommerce->refund($stored_card, $amount, $options);
27+
28+
if($refund2->code == 0) {
29+
print("Devolución aceptada!\n");
30+
}else{
31+
print("Error: ".$refund2->description."\n");
32+
}
33+
34+
$fast_pay = new \Sipay\Paymethods\FastPay('0f266784e7ba4e438040fdd1dbbfcd73');
35+
36+
$refund3 = $ecommerce->refund($fast_pay, $amount, $options);
37+
38+
if($refund3->code == 0) {
39+
print("Devolución aceptada!\n");
40+
}else{
41+
print("Error: ".$refund3->description."\n");
42+
}
43+
44+
45+
46+
$auth = $ecommerce->authorization($card, $amount, $options);
47+
48+
if($auth->code == 0) {
49+
print("Autorización aceptada, el pago ha sido completado!\n");
50+
}else{
51+
print("Error: ".$auth->description."\n");
52+
}
53+
54+
55+
$refund4 = $ecommerce->refund($auth->transaction_id, $amount, $options);
56+
57+
if($refund4->code == 0) {
58+
print("Devolución aceptada!\n");
59+
}else{
60+
print("Error: ".$refund4->description."\n");
61+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
require_once realpath(__DIR__.'/../src/autoload.php');
3+
4+
$ecommerce = new \Sipay\Ecommerce(realpath(__DIR__."/../etc/config.ini"));
5+
6+
$card = new \Sipay\Paymethods\Card('6712009000000205', 2018, 12);
7+
8+
$register = $ecommerce->register($card, $token = 'new-token');
9+
10+
if($register->code == 0) {
11+
print("Tarjeta registrada con éxito!\n");
12+
}else{
13+
print("Error: ".$register->description."\n");
14+
}
15+
16+
$masked_card = $ecommerce->card($token);
17+
18+
if($masked_card->code == 0) {
19+
print("Tarjeta consultada con éxito!\n");
20+
}else{
21+
print("Error: ".$masked_card->description."\n");
22+
}
23+
24+
$unregiter = $ecommerce->unregister($token);
25+
26+
if($unregiter->code == 0) {
27+
print("Tarjeta borrada con éxito!\n");
28+
}else{
29+
print("Error: ".$unregiter->description."\n");
30+
}

0 commit comments

Comments
 (0)