-
Notifications
You must be signed in to change notification settings - Fork 33
/
PaylineSDK.php
2482 lines (2316 loc) · 97 KB
/
PaylineSDK.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* This file is part of the Payline package.
*
* (c) Monext <http://www.monext.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Payline;
use Payline\MerchantAuthentication;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Payline\Browser;
use SoapClient;
use SoapVar;
use Payline\Payment;
use Payline\Order;
use Payline\OrderDetail;
use Payline\Card;
use Payline\PaymentData;
use Payline\Buyer;
use Payline\Address;
use Payline\AddressOwner;
use Payline\Owner;
use Payline\Authentication3DSecure;
use Payline\BillingRecordForUpdate;
use Payline\Wallet;
use Payline\Authorization;
use Payline\Creditor;
use Payline\Cheque;
use Payline\Recurring;
use Payline\ThreeDSInfo;
use Payline\Sdk;
class PaylineSDK
{
/**
* Payline release corresponding to this version of the package
* @see https://docs.payline.com/display/DT/API+version+history
*/
const SDK_RELEASE = 'PHP SDK 4.64.1';
/**
* development environment flag
*/
const ENV_DEV = "DEV";
/**
* integration environment flag
*/
const ENV_INT = "INT";
/**
* homologation environment flag
*/
const ENV_HOMO = "HOMO";
/**
* homologation environment flag - uses certificate-based authentication
*/
const ENV_HOMO_CC = "HOMO_CC";
/**
* production environment flag
*/
const ENV_PROD = "PROD";
/**
* production environment flag - uses certificate-based authentication
*/
const ENV_PROD_CC = "PROD_CC";
/**
* name of Payline DirectPaymentAPI
*/
const DIRECT_API = 'DirectPaymentAPI';
/**
* name of Payline ExtendedAPI
*/
const EXTENDED_API = 'ExtendedAPI';
/**
* name of Payline WebPaymentAPI
*/
const WEB_API = 'WebPaymentAPI';
/**
* namespace used in web services desciptor
*/
const PAYLINE_NAMESPACE = 'http://obj.ws.payline.experian.com';
/**
* SOAP name of authorization object
*/
const SOAP_AUTHORIZATION = 'authorization';
/**
* SOAP name of card object
*/
const SOAP_CARD = 'card';
/**
* SOAP name of order object
*/
const SOAP_ORDER = 'order';
/**
* SOAP name of orderDetail object
*/
const SOAP_ORDERDETAIL = 'orderDetail';
/**
* SOAP name of payment object
*/
const SOAP_PAYMENT = 'payment';
/**
* SOAP name of paymentData object
*/
const SOAP_PAYMENT_DATA = 'paymentData';
/**
* SOAP name of privateData object
*/
const SOAP_PRIVATE_DATA = 'privateData';
/**
* SOAP name of buyer object
*/
const SOAP_BUYER = 'buyer';
/**
* SOAP name of owner object
*/
const SOAP_OWNER = 'owner';
/**
* SOAP name of address object
*/
const SOAP_ADDRESS = 'address';
/**
* SOAP name of addressOwner object
*/
const SOAP_ADDRESS_OWNER = 'addressOwner';
/**
* SOAP name of authentication3DSecure object
*/
const SOAP_AUTHENTICATION_3DSECURE = 'authentication3DSecure';
/**
* SOAP name of bankAccountData object
*/
const SOAP_BANK_ACCOUNT_DATA = 'bankAccountData';
/**
* SOAP name of cheque object
*/
const SOAP_CHEQUE = 'cheque';
/**
* SOAP name of creditor object
*/
const SOAP_CREDITOR = 'creditor';
/**
* SOAP name of billingRecordForUpdate object
*/
const SOAP_BILLING_RECORD_FOR_UPDATE = 'billingRecordForUpdate';
/**
* SOAP name of recurring object
*/
const SOAP_RECURRING = 'recurring';
/**
* SOAP name of subMerchant object
*/
const SOAP_SUBMERCHANT = 'subMerchant';
/**
* SOAP name of threeDSInfo object
*/
const SOAP_THREEDSINFO = 'threeDSInfo';
/**
* SOAP name of browser object
*/
const SOAP_BROWSER = 'browser';
/**
* SOAP name of sdk object
*/
const SOAP_SDK = 'sdk';
/**
* SOAP name of merchantAuthentication object
*/
const SOAP_MERCHANT_AUTHENTICATION = 'merchantAuthentication';
/**
* SOAP name of wallet object
*/
const SOAP_WALLET = 'wallet';
/**
* web services endpoint in development environment
*/
const DEV_ENDPOINT = 'https://ws.dev.payline.com/V4/services/';
/**
* web services endpoint in integration environment
*/
const INT_ENDPOINT = 'https://ws.int.payline.com/V4/services/';
/**
* standard web services endpoint in homologation environment
*/
const HOMO_ENDPOINT = 'https://homologation.payline.com/V4/services/';
/**
* certificate-based authentication web services endpoint in homologation environment
*/
const HOMO_CC_ENDPOINT = 'https://homologation-cc.payline.com/V4/services/';
/**
* standard web services endpoint in production environment
*/
const PROD_ENDPOINT = 'https://services.payline.com/V4/services/';
/**
* certificate-based authentication web services endpoint in production environment
*/
const PROD_CC_ENDPOINT = 'https://services-cc.payline.com/V4/services/';
/**
* URL of getToken servlet, used by AJAX API, in development environment
*/
const DEV_GET_TOKEN_SERVLET = "https://webpayment.dev.payline.com/webpayment/getToken";
/**
* URL of getToken servlet, used by AJAX API, in integration environment
*/
const INT_GET_TOKEN_SERVLET = "https://webpayment.int.payline.com/webpayment/getToken";
/**
* URL of getToken servlet, used by AJAX API, in homologation environment
*/
const HOMO_GET_TOKEN_SERVLET = "https://homologation-webpayment.payline.com/webpayment/getToken";
/**
* URL of getToken servlet, used by AJAX API, in production environment
*/
const PROD_GET_TOKEN_SERVLET = "https://webpayment.payline.com/webpayment/getToken";
/**
* Widget JavaScript in development environment
*/
const DEV_WDGT_JS = "https://webpayment.dev.payline.com/payline-widget/scripts/widget-min.js";
/**
* Widget JavaScript in homologation environment
*/
const HOMO_WDGT_JS = "https://homologation-payment.payline.com/scripts/widget-min.js";
/**
* Widget JavaScript in production environment
*/
const PROD_WDGT_JS = "https://payment.payline.com/scripts/widget-min.js";
/**
* Widget css in development environment
*/
const DEV_WDGT_CSS = "https://webpayment.dev.payline.com/payline-widget/styles/widget-min.css";
/**
* Widget css in homologation environment
*/
const HOMO_WDGT_CSS = "https://homologation-payment.payline.com/styles/widget-min.css";
/**
* Widget css in production environment
*/
const PROD_WDGT_CSS = "https://payment.payline.com/styles/widget-min.css";
/**
* homologation administration center URL
*/
const HOMO_CA = 'https://homologation-admin.payline.com';
/**
* administration center URL
*/
const PROD_CA = 'https://admin.payline.com';
/**
* error code/shortMessage returned when Payline can't be reached
*/
const ERR_CODE = 'XXXXX';
const ERR_SHORT_MESSAGE = 'ERROR';
/**
* @var Logger
*/
private $logger;
/**
* tool / e-commerce module using this library
*/
private $usedBy = null;
/**
* array containing order details
*/
private $orderDetails;
/**
* array containing private data
*/
private $privateData;
/**
* array containing parent-child nodes associations
*/
private $parentNode = array(
'cards' => 'cardsList',
'billingRecord' => 'billingRecordList',
'walletId' => 'walletIdList',
'transaction' => 'transactionList',
'pointOfSell' => 'listPointOfSell',
'contract' => 'contracts',
'customPaymentPageCode' => 'customPaymentPageCodeList',
'function' => 'functions',
'details' => 'details',
'privateData' => 'privateDataList',
'associatedTransactions' => 'associatedTransactionsList',
'statusHistory' => 'statusHistoryList',
'paymentAdditional' => 'paymentAdditionalList',
'CustomerTrans' => 'CustomerTransHist',
'PaymentMeansTrans' => 'PaymentMeansTransHist',
'AlertsTrans' => 'AlertsTransHist'
);
/**
* PaylineSDK class constructor
*
* @param string $merchant_id
* the merchant identifier
* @param string $access_key
* the access key generated in Payline Administration Center
* @param string $proxy_host
* host of your proxy (set null if no proxy)
* @param string $proxy_port
* port used by your proxy (set null if no proxy)
* @param string $proxy_login
* login required by your proxy (set null if no proxy)
* @param string $proxy_password
* password required by your proxy (set null if no proxy)
* @param string $environment
* target Payline environment : set PaylineSDK::ENV_HOMO for homologation, PaylineSDK::ENV_PROD for production
* @param string $pathLog
* path to your custom log folder, must end by directory separator. If null, default logs folder is used. Default : null
* @param int $logLevel
* \Monolog\Logger log level. Default : Logger::INFO
* @param Logger $externalLogger
* \Monolog\Logger instance, used by PaylineSDK but external to it
*/
public function __construct($merchant_id, $access_key, $proxy_host, $proxy_port, $proxy_login, $proxy_password, $environment, $pathLog = null, $logLevel = Logger::INFO, $externalLogger = null, $defaultTimezone = "Europe/Paris")
{
if (is_int($merchant_id)) {
$merchant_id = (string) $merchant_id;
}
if ($externalLogger) {
$this->logger = $externalLogger;
} else {
$this->logger = new Logger('PaylineSDK');
}
$logfileDate = (new \DateTime('now', new \DateTimeZone($defaultTimezone)))->format('Y-m-d');
if (is_null($pathLog)) {
$this->logger->pushHandler(new StreamHandler(realpath(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . $logfileDate . '.log', $logLevel)); // set default log folder
} elseif (strlen($pathLog) > 0) {
$this->logger->pushHandler(new StreamHandler($pathLog . $logfileDate . '.log', $logLevel)); // set custom log folder
}
$this->logger->info('__construct', array(
'merchant_id' => $this->hideChars($merchant_id, 6, 1),
'access_key' => $this->hideChars($access_key, 1, 3),
'proxy_host' => $proxy_host,
'proxy_port' => $proxy_port,
'proxy_login' => $proxy_login,
'proxy_password' => $this->hideChars($proxy_password, 1, 1),
'environment' => $environment
));
$this->soapclient_options = array();
$this->soapclient_options['login'] = $merchant_id;
$this->soapclient_options['password'] = $access_key;
if ($proxy_host != '') {
$this->soapclient_options['proxy_host'] = $proxy_host;
$this->soapclient_options['proxy_port'] = $proxy_port;
$this->soapclient_options['proxy_login'] = $proxy_login;
$this->soapclient_options['proxy_password'] = $proxy_password;
}
$plnInternal = false;
if (strcmp($environment, self::ENV_HOMO) == 0) {
$this->webServicesEndpoint = self::HOMO_ENDPOINT;
} elseif (strcmp($environment, self::ENV_HOMO_CC) == 0) {
$this->webServicesEndpoint = self::HOMO_CC_ENDPOINT;
} elseif (strcmp($environment, self::ENV_PROD) == 0) {
$this->webServicesEndpoint = self::PROD_ENDPOINT;
} elseif (strcmp($environment, self::ENV_PROD_CC) == 0) {
$this->webServicesEndpoint = self::PROD_CC_ENDPOINT;
} elseif (strcmp($environment, self::ENV_DEV) == 0) {
$this->webServicesEndpoint = self::DEV_ENDPOINT;
$plnInternal = true;
} elseif (strcmp($environment, self::ENV_INT) == 0) {
$this->webServicesEndpoint = self::INT_ENDPOINT;
$plnInternal = true;
} else {
$this->webServicesEndpoint = false; // Exception is raised in PaylineSDK::webServiceRequest
}
$this->soapclient_options['style'] = defined('SOAP_DOCUMENT') ? SOAP_DOCUMENT : 2;
$this->soapclient_options['use'] = defined('SOAP_LITERAL') ? SOAP_LITERAL : 2;
$this->soapclient_options['connection_timeout'] = defined('SOAP_CONNECTION_TIMEOUT') ? SOAP_CONNECTION_TIMEOUT : 5;
$this->soapclient_options['trace'] = false;
$this->soapclient_options['soap_client'] = false;
if($plnInternal){
$this->soapclient_options['stream_context'] = stream_context_create(
array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false
)
)
);
}
$this->orderDetails = array();
$this->privateData = array();
ini_set('user_agent', "PHP\r\nversion: " . self::SDK_RELEASE);
}
/**
* reset OrderDetails
*/
public function resetOrderDetails()
{
$this->orderDetails = array();
}
/**
* reset Private Data
*/
public function resetPrivateData()
{
$this->privateData = array();
}
/**
* build Payment instance from $array and make SoapVar object for payment
*
* @param array $array
* the array keys are listed in Payment class
* @return SoapVar representation of Payment instance
*/
protected function payment(array $array)
{
return $this->buildSoapObject($array, new Payment(), self::SOAP_PAYMENT);
}
/**
* build PaymentData instance from $array and make SoapVar object for payment
*
* @param array $array
* the array keys are listed in PaymentData class
* @return SoapVar representation of PaymentData instance
*/
protected function paymentData(array $array)
{
return $this->buildSoapObject($array, new PaymentData(), self::SOAP_PAYMENT_DATA);
}
/**
* build Order instance from $array and make SoapVar object for order
*
* @param array $array
* the array keys are listed in Order CLASS.
* @return SoapVar representation of Order instance
*/
protected function order(array $array)
{
$order = new Order();
if ($array) {
foreach ($array as $k => $v) {
if (property_exists($order, $k) && (strlen($v))) {
$order->$k = $v;
}
}
}
// insert orderDetails
$order->details = $this->orderDetails;
return new \SoapVar($order, SOAP_ENC_OBJECT, self::SOAP_ORDER, self::PAYLINE_NAMESPACE);
}
/**
* build Card instance from $array and make SoapVar object for card
*
* @param array $array
* the array keys are listed in Card CLASS.
* @return SoapVar representation of Card instance
*/
protected function card(array $array)
{
$card = new Card();
if ($array) {
foreach ($array as $k => $v) {
if (property_exists($card, $k) && (strlen($v))) {
$card->$k = $v;
}
}
}
$card->paymentData = null;
if (isset($array['paymentData'])) {
$card->paymentData = $this->paymentData($array['paymentData']);
}
return new \SoapVar($card, SOAP_ENC_OBJECT, self::SOAP_CARD, self::PAYLINE_NAMESPACE);
}
/**
* build Buyer instance from $array, $shippingAdress and $billingAddress, and make SoapVar object for buyer
*
* @param array $array
* the array keys are listed in Buyer CLASS.
* @param array $shippingAdress
* the array keys are listed in Address CLASS.
* @param array $billingAddress
* the array keys are listed in Address CLASS.
* @param array $merchantAuthentication
* the array keys are listed in MerchantAuthentication CLASS.
* @return SoapVar representation of Buyer instance
*/
protected function buyer(array $array, array $shippingAdress, array $billingAddress, array $merchantAuthentication)
{
$buyer = new Buyer();
if ($array) {
foreach ($array as $k => $v) {
if (property_exists($buyer, $k) && (strlen($v))) {
$buyer->$k = $v;
}
}
}
$buyer->shippingAdress = $this->address($shippingAdress);
$buyer->billingAddress = $this->address($billingAddress);
$buyer->merchantAuthentication = $this->merchantAuthentication($merchantAuthentication);
return new \SoapVar($buyer, SOAP_ENC_OBJECT, self::SOAP_BUYER, self::PAYLINE_NAMESPACE);
}
/**
* build Address instance from $array and make SoapVar object for address.
*
* @param array $array
* the array keys are listed in Address CLASS.
* @return SoapVar representation of Address instance
*/
protected function address(array $array)
{
return $this->buildSoapObject($array, new Address(), self::SOAP_ADDRESS);
}
/**
* build AddressOwner instance from $array and make SoapVar object for addressOwner.
*
* @param array $array
* the array keys are listed in AddressOwner CLASS.
* @return SoapVar representation of AddressOwner instance
*/
protected function addressOwner(array $array)
{
return $this->buildSoapObject($array, new AddressOwner(), self::SOAP_ADDRESS_OWNER);
}
/**
* build Owner instance from $array and make SoapVar object for owner
*
* @param array $array
* the array keys are listed in Owner CLASS.
* @param array $addressOwner
* the array keys are listed in AddressOwner CLASS.
* @return SoapVar representation of Owner instance
*
*/
protected function owner(array $array, array $addressOwner)
{
if ($array !== null) {
$owner = new Owner();
if ($array) {
foreach ($array as $k => $v) {
if (property_exists($owner, $k) && (strlen($v))) {
$owner->$k = $v;
}
}
}
$owner->billingAddress = $this->addressOwner($addressOwner);
return new \SoapVar($owner, SOAP_ENC_OBJECT, self::SOAP_OWNER, self::PAYLINE_NAMESPACE);
} else {
return null;
}
}
/**
* build Authentication3DSecure instance from $array and make SoapVar object for authentication3DSecure
*
* @param array $array
* the array keys are listed in Authentication3DSecure CLASS.
* @return SoapVar representation of Authentication3DSecure instance
*/
protected function authentication3DSecure(array $array)
{
return $this->buildSoapObject($array, new Authentication3DSecure(), self::SOAP_AUTHENTICATION_3DSECURE);
}
/**
* build BankAccountData instance from $array and make SoapVar object for authentication3DSecure
*
* @param array $array
* the array keys are listed in BankAccountData CLASS.
* @return SoapVar representation of BankAccountData instance
*/
protected function bankAccountData(array $array)
{
return $this->buildSoapObject($array, new BankAccountData(), self::SOAP_BANK_ACCOUNT_DATA);
}
/**
* build BillingRecordForUpdate instance from $array and make SoapVar object for billingRecordForUpdate
*
* @param array $array
* the array keys are listed in BillingRecordForUpdate CLASS.
* @return SoapVar representation of BillingRecordForUpdate instance
*/
protected function billingRecordForUpdate(array $array)
{
return $this->buildSoapObject($array, new BillingRecordForUpdate(), self::SOAP_BILLING_RECORD_FOR_UPDATE);
}
/**
* build Wallet instance from $array and make SoapVar object for wallet
*
* @param array $inWallet
* the array keys are listed in Wallet CLASS.
* @param array $address
* the array keys are listed in Address CLASS.
* @param array $card
* the array keys are listed in Card CLASS.
* @return SoapVar representation of Wallet instance
*/
protected function wallet(array $inWallet, array $address, array $card)
{
$wallet = new Wallet();
if ($inWallet) {
foreach ($inWallet as $k => $v) {
if (property_exists($wallet, $k) && (strlen($v))) {
$wallet->$k = $v;
}
}
}
$wallet->shippingAddress = $this->address($address);
$wallet->card = $this->card($card);
return new \SoapVar($wallet, SOAP_ENC_OBJECT, self::SOAP_WALLET, self::PAYLINE_NAMESPACE);
}
/**
* build Authorization instance from $array and make SoapVar object for authorization
*
* @param array $array
* the array keys are listed in Authorization CLASS.
* @return SoapVar representation of Authorization instance
*
*/
protected function authorization(array $array)
{
return $this->buildSoapObject($array, new Authorization(), self::SOAP_AUTHORIZATION);
}
/**
* build Creditor instance from $array and make SoapVar object for creditor
*
* @param array $array
* the array keys are listed in Creditor CLASS.
* @return SoapVar representation of Creditor instance
*/
protected function creditor(array $array)
{
return $this->buildSoapObject($array, new Creditor(), self::SOAP_CREDITOR);
}
/**
* build Cheque instance from $array and make SoapVar object for cheque
*
* @param array $array
* the array keys are listed in Cheque CLASS.
* @return SoapVar representation of Cheque instance
*/
protected function cheque(array $array)
{
return $this->buildSoapObject($array, new Cheque(), self::SOAP_CHEQUE);
}
/**
* build Recurring instance from $array and make SoapVar object for recurring
*
* @param array $array
* the array keys are listed in Recurring CLASS.
* @return SoapVar representation of Recurring instance
*/
protected function recurring(array $array)
{
return $this->buildSoapObject($array, new Recurring(), self::SOAP_RECURRING);
}
/**
* build SubMerchant instance from $array and make SoapVar object for subMerchant
*
* @param array $array
* the array keys are listed in SubMerchant CLASS.
* @return SoapVar representation of SubMerchant instance
*/
protected function subMerchant(array $array)
{
return $this->buildSoapObject($array, new SubMerchant(), self::SOAP_SUBMERCHANT);
}
/**
* build ThreeDSInfo instance froù $array and make SoapVar object for threeDSInfo
*
* @param array $array
* the array keys liste in ThreeDSInfo CLASS.
* @param array $arrayBrowser
* the array keys liste in Browser CLASS.
* @param array $arraySdk
* the array keys liste in Sdk CLASS.
* @return SoapVar representation of ThreeDSInfo instance
*/
protected function threeDSInfo(array $array, array $arrayBrowser, array $arraySdk)
{
$threeDSInfo = new ThreeDSInfo();
if ($array) {
foreach ($array as $k => $v) {
if (property_exists($threeDSInfo, $k) && (strlen($v))) {
$threeDSInfo->$k = $v;
}
}
}
$threeDSInfo->sdk = $this->sdk($arraySdk);
$threeDSInfo->browser = $this->browser($arrayBrowser);
return new \SoapVar($threeDSInfo, SOAP_ENC_OBJECT, self::SOAP_THREEDSINFO, self::PAYLINE_NAMESPACE);
}
/**
* build Browser instance from $array and make SoapVar object for browser
*
* @param array $array
* the array keys list in Browser CLASS.
* @return SoapVar representation of Browser instance
*/
protected function browser(array $array) {
return $this->buildSoapObject($array, new Browser(), self::SOAP_BROWSER);
}
/**
* build MerchantAuthentication instance from $array and make SoapVar object for merchantAuthentication
*
* @param array $array
* the array keys list in MerchantAuthentication CLASS.
* @return SoapVar representation of MerchantAuthentication instance
*/
protected function merchantAuthentication(array $array) {
return $this->buildSoapObject($array, new MerchantAuthentication(), self::SOAP_MERCHANT_AUTHENTICATION);
}
/**
* build Sdk instance from $array and make SoapVar object for sdk
*
* @param array $array
* the array keys list in Sdk CLASS.
* @return SoapVar representation of Sdk instance
*/
protected function sdk(array $array) {
return $this->buildSoapObject($array, new Sdk(), self::SOAP_SDK);
}
/**
* Hide characters in a string
*
* @param String $inString
* the string to hide
* @param int $n1
* number of characters shown at the begining of the string
* @param int $n2
* number of characters shown at end begining of the string
*/
protected function hideChars($inString, $n1, $n2)
{
$inStringLength = strlen($inString);
if ($inStringLength < ($n1 + $n2)) {
return $inString;
}
$outString = substr($inString, 0, $n1);
$outString .= substr("********************", 0, $inStringLength - ($n1 + $n2));
$outString .= substr($inString, - ($n2));
return $outString;
}
/**
*
* @param String $nodeName name of a node in a web service response
* @param String $parentName name of its parent
* @return boolean whether $nodeName is child from a list or not
*/
protected function isChildFromList($nodeName,$parentName){
if(array_key_exists($nodeName, $this->parentNode)){
if(strcmp($this->parentNode[$nodeName],$parentName) == 0){
return true;
}
}
return false;
}
/**
* make an array from a payline server response object.
*
* @param object $node
* response node from payline web service
* @param string $parent
* name of the node's parent
* @return array representation of the object
*/
protected function responseToArray($node, $parent = null)
{
$array = array();
foreach ($node as $k => $v) {
if ($this->isChildFromList($k, $parent)) { // current value is a list
if ($v instanceof \Countable && count($v) == 1 && $k != '0') { // a list with 1 element. It's returned with a 0-index
$array[$k][0] = PaylineSDK::responseToArray($v, $k);
} elseif (is_object($v) || is_array($v)) { // a list with more than 1 element
$array[$k] = PaylineSDK::responseToArray($v, $k);
} else {
$array[$k] = $v;
}
} else {
if (is_object($v) || is_array($v)) {
$array[$k] = PaylineSDK::responseToArray($v, $k);
} else {
$array[$k] = $v;
}
}
}
return $array;
}
/**
* Adds indexes with empty values to the web services request array, in order to prevent SOAP format exception
*
* @param array $array
* associative array containing web services parameters
*/
private static function formatRequest(&$array)
{
if (!isset($array['buyer'])) {
$array['buyer'] = array();
}
if (!isset($array['3DSecure'])) {
$array['3DSecure'] = array();
}
if (!isset($array['bankAccountData'])) {
$array['bankAccountData'] = array();
}
if (!isset($array['cancelURL']) || !strlen($array['cancelURL'])) {
$array['cancelURL'] = null;
}
if (!isset($array['notificationURL']) || !strlen($array['notificationURL'])) {
$array['notificationURL'] = null;
}
if (!isset($array['returnURL']) || !strlen($array['returnURL'])) {
$array['returnURL'] = null;
}
if (!isset($array['languageCode']) || !strlen($array['languageCode'])) {
$array['languageCode'] = null;
}
if (!isset($array['securityMode']) || !strlen($array['securityMode'])) {
$array['securityMode'] = null;
}
if (!isset($array['billingAddress'])) {
$array['billingAddress'] = array();
}
if (!isset($array['shippingAddress'])) {
$array['shippingAddress'] = array();
}
if (!isset($array['owner'])) {
$array['owner'] = array();
}
if (!isset($array['ownerAddress'])) {
$array['ownerAddress'] = array();
}
if (!isset($array['contracts']) || !strlen($array['contracts'][0]) || !is_array($array['contracts'])) {
$array['contracts'] = null;
}
if (!isset($array['secondContracts']) || !strlen($array['secondContracts'][0]) || !is_array($array['secondContracts'])) {
$array['secondContracts'] = null;
}
if (!isset($array['walletContracts']) || !strlen($array['walletContracts'][0]) || !is_array($array['walletContracts'])) {
$array['walletContracts'] = null;
}
if (!isset($array['customPaymentPageCode']) || !strlen($array['customPaymentPageCode'])) {
$array['customPaymentPageCode'] = null;
}
if (!isset($array['customPaymentTemplateURL']) || !strlen($array['customPaymentTemplateURL'])) {
$array['customPaymentTemplateURL'] = null;
}
if (!isset($array['recurring'])) {
$array['recurring'] = array();
}
if (!isset($array['orderRef']) || !strlen($array['orderRef'])) {
$array['orderRef'] = null;
}
if (!isset($array['orderDate']) || !strlen($array['orderDate'])) {
$array['orderDate'] = null;
}
if (!isset($array['walletIds']) || !strlen($array['walletIds'][0] || !is_array($array['walletIds']))) {
$array['walletIds'] = null;
}
if (!isset($array['merchantName'])) {
$array['merchantName'] = null;
}
if (!isset($array['miscData'])) {
$array['miscData'] = null;
}
if (!isset($array['subMerchant'])) {
$array['subMerchant'] = array();
}
if (!isset($array['asynchronousRetryTimeout'])) {
$array['asynchronousRetryTimeout'] = null;
}
if (!isset($array['merchantAuthentication'])) {
$array['merchantAuthentication'] = array();
}
if (!isset($array['browser'])) {
$array['browser'] = array();
}
if (!isset($array['sdk'])) {
$array['sdk'] = array();
}
if (!isset($array['threeDSInfo'])) {
$array['threeDSInfo'] = array();
}
if (!isset($array['updatePersonalDetails'])) {
$array['updatePersonalDetails'] = null;
}
}
/**
* Create the SoapClient instance and make the web service call
*
* @param array $array
* the associative array passed to the public function
* @param array $WSRequest
* the SOAP-formated request
* @param string $PaylineAPI
* the Payline API to be called
* @param string $Method
* the name of the web service
*/
protected function webServiceRequest(array $array, array $WSRequest, $PaylineAPI, $Method)
{
$logRequest = array();
$logResponse = array(
'result.code' => null
);
try {
if(!$this->webServicesEndpoint){
throw new \Exception('Endpoint error (check `environment` parameter of PaylineSDK constructor)');
}
if ($this->soapclient_options['soap_client'] instanceof \SoapClient) {
$client = $this->soapclient_options['soap_client'];
} else {
$client = new SoapClient(__DIR__ . '/wsdl/' . $PaylineAPI . '.wsdl', $this->soapclient_options);
}
$client->__setLocation($this->webServicesEndpoint . $PaylineAPI);