forked from lemonwaysas/php-client-directkit-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RefundMoneyIn.php
69 lines (64 loc) · 2.75 KB
/
RefundMoneyIn.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
<?php
namespace LemonWay\Examples;
use LemonWay\Models\Operation;
use LemonWay\Models\Wallet;
use LemonWay\Models\Card;
require_once '../LemonWay/Autoloader.php';
require_once 'ExamplesBootstrap.php';
$api = ExamplesBootstrap::getApiInstance();
/**
* Case : Money-in without 3D Secure
* Steps :
* - RegisterWallet : creating customer wallet
* - MoneyIn : debiting 10 EUR from card, and automatically sending 2 EUR to your wallet (merchant).
* - GetWalletTransHistory : get transactions history of the wallet
*
* Note :
* - Lemon Way will automatically debit its fees from merchant wallet
* - After the MoneyIn call, 8 EUR will remain on customer wallet
* - The wkToken input can later be used to search for this payment
*/
$walletID = ExamplesDatas::getRandomId();
$res = $api->RegisterWallet(array('wallet' => $walletID,
'clientMail' => $walletID.'@mail.fr',
'clientTitle' => Wallet::MISTER,
'clientFirstName' => 'Paul',
'clientLastName' => 'Dupond'));
if (isset($res->lwError))
print 'Error, code '.$res->lwError->CODE.' : '.$res->lwError->MSG;
else {
print '<br/>Wallet created : ' . $res->wallet->ID;
$res2 = $api->MoneyIn(array('wkToken'=>ExamplesDatas::getRandomId(),
'wallet'=>$walletID,
'amountTot'=>'10.00',
'amountCom'=>'2.00',
'comment'=>'comment',
'cardType'=>Card::TYPE_CB,
'cardNumber'=>ExamplesDatas::CARD_SUCCESS_WITHOUT_3D,
'cardCrypto'=>ExamplesDatas::CARD_CRYPTO,
'cardDate'=>ExamplesDatas::CARD_DATE,
'autoCommission'=>Wallet::NO_AUTO_COMMISSION,
'isPreAuth'=>Wallet::NO_ATOS_PRE_AUTH));
if (isset($res2->lwError)){
print 'Error, code '.$res2->lwError->CODE.' : '.$res2->lwError->MSG;
return;
}
if ((string)$res2->operation->STATUS == Operation::STATUS_SUCCES) //if isPreAuth = 0
print '<br/>Money-in successful : ';
elseif ((string)$res2->operation->STATUS == Operation::STATUS_AWAITING_VALIDATION) //if isPreAuth = 1
print '<br/>Money-in successful (pending validation) : ';
print '<br/>ID : '. $res2->operation->ID;
print '<br/>AMOUNT CREDITED TO ACCOUNT (After merchant fees): '. $res2->operation->CRED;
print '<br/>CARD : '. $res2->operation->MLABEL;
print '<br/>AUTHORIZATION NUMBER : '. $res2->operation->EXTRA->AUTH;
//Refund
$res3 = $api->RefundMoneyIn(array('transactionId' => $res2->operation->ID,
'comment' => 'refund for example',
'amountToRefund' => '10.00'));
if (isset($res3->lwError)) {
print 'Error, code '.$res3->lwError->CODE.' : '.$res3->lwError->MSG;
} else {
print '<br/>ID : '. $res3->operation->ID;
print '<br/>REFUND AMOUNT : '. $res3->operation->DEB;
}
}