forked from lemonwaysas/php-client-directkit-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rebill.php
86 lines (78 loc) · 2.82 KB
/
Rebill.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace LemonWay\Examples;
use LemonWay\Models\Card;
use LemonWay\Models\Wallet;
require_once '../LemonWay/Autoloader.php';
require_once 'ExamplesBootstrap.php';
$api = ExamplesBootstrap::getApiInstance();
/**
* Case : Save a bank card for later rebills. No 3D Secure.
* Steps :
* - RegisterWallet : creating customer wallet
* - RegisterCard : link a bank card to the wallet
* - MoneyInWithCardId : debit the card once
* - MoneyInWithCardId : debit the card again
*/
//RegisterWallet
$wallet = ExamplesDatas::getRandomId();
$res = $api->RegisterWallet(array('wallet' => $wallet,
'clientMail' => $wallet.'@mail.fr',
'clientTitle' => Wallet::UNKNOWN,
'clientFirstName' => 'Paul',
'clientLastName' => 'Dupond'));
if (isset($res->lwError)){
print 'Error, code '.$res->lwError->CODE.' : '.$res->lwError->MSG;
return;
}
print '<br/>Wallet created : ' . $res->wallet->ID;
//RegisterCard
$res2 = $api->RegisterCard(array('wallet'=>$wallet,
'cardType'=>Card::TYPE_CB,
'cardNumber'=>ExamplesDatas::CARD_SUCCESS_WITHOUT_3D,
'cardCode'=>ExamplesDatas::CARD_CRYPTO,
'cardDate'=>ExamplesDatas::CARD_DATE));
if (isset($res2->lwError)){
print 'Error, code '.$res2->lwError->CODE.' : '.$res2->lwError->MSG;
return;
}
print '<hr/><br/>Card saved. ID : '.$res2->card->ID;
if(isset($res2->card->EXTRA)){
print '<br/>Card EXTRA AUTH : '.$res2->card->EXTRA->AUTH;
print '<br/>Card EXTRA CTRY : '.$res2->card->EXTRA->CTRY;
}
//MoneyInWithCardId
$res3 = $api->MoneyInWithCardId(array('wkToken'=>ExamplesDatas::getRandomId(),
'wallet'=>$wallet,
'amountTot'=>'10.00',
'amountCom'=>'2.00',
'comment'=>'comment',
'cardId'=>$res2->card->ID,
'autoCommission'=>'0',
'isPreAuth'=>'0'));
if (isset($res3->lwError)){
print 'Error, code '.$res3->lwError->CODE.' : '.$res3->lwError->MSG;
return;
}
print '<hr/><br/>Money-in successful : ';
print '<br/>ID : '. $res3->operation->ID;
print '<br/>AMOUNT CREDITED TO ACCOUNT (After merchant fees): '. $res3->operation->CRED;
print '<br/>CARD : '. $res3->operation->MLABEL;
print '<br/>AUTHORIZATION NUMBER : '. $res3->operation->EXTRA->AUTH;
//MoneyInWithCardId
$res4 = $api->MoneyInWithCardId(array('wkToken'=>ExamplesDatas::getRandomId(),
'wallet'=>$wallet,
'amountTot'=>'11.00',
'amountCom'=>'2.00',
'comment'=>'comment',
'cardId'=>(string)$res2->lwXml->CARD->ID,
'autoCommission'=>'0',
'isPreAuth'=>'0'));
if (isset($res4->lwError)){
print 'Error, code '.$res4->lwError->CODE.' : '.$res4->lwError->MSG;
return;
}
print '<hr/><br/>Another Money-in successful : ';
print '<br/>ID : '. $res4->operation->ID;
print '<br/>AMOUNT CREDITED TO ACCOUNT (After merchant fees): '. $res4->operation->CRED;
print '<br/>CARD : '. $res4->operation->MLABEL;
print '<br/>AUTHORIZATION NUMBER : '. $res4->operation->EXTRA->AUTH;