This repository was archived by the owner on May 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathClient.php
More file actions
2006 lines (1686 loc) · 88.3 KB
/
Copy pathClient.php
File metadata and controls
2006 lines (1686 loc) · 88.3 KB
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
namespace AmazonPay;
/* Class Client
* Takes configuration information
* Makes API calls to MWS for Amazon Pay
* returns Response Object
*/
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
class Client implements ClientInterface, LoggerAwareInterface
{
use LoggerAwareTrait;
const SDK_VERSION = '3.7.1';
const MWS_VERSION = '2013-01-01';
const MAX_ERROR_RETRY = 3;
// Construct User agent string based off of the application_name, application_version, PHP platform
private $userAgent = null;
private $parameters = null;
private $mwsEndpointPath = null;
private $mwsEndpointUrl = null;
private $profileEndpoint = null;
private $config = array(
'merchant_id' => null,
'secret_key' => null,
'access_key' => null,
'region' => null,
'currency_code' => null,
'sandbox' => false,
'platform_id' => null,
'cabundle_file' => null,
'application_name' => null,
'application_version' => null,
'proxy_host' => null,
'proxy_port' => -1,
'proxy_username' => null,
'proxy_password' => null,
'client_id' => null,
'app_id' => null,
'handle_throttle' => true,
'override_service_url' => null
);
private $modePath = null;
// Final URL to where the API parameters POST done, based off the config['region'] and respective $mwsServiceUrls
private $mwsServiceUrl = null;
private $mwsServiceUrls;
private $profileEndpointUrls;
private $regionMappings;
// Boolean variable to check if the API call was a success
public $success = false;
/* Takes user configuration array from the user as input
* Takes JSON file path with configuration information as input
* Validates the user configuration array against existing config array
*/
public function __construct($config = null)
{
$this->getRegionUrls();
if (!is_null($config)) {
if (is_array($config)) {
$configArray = $config;
} elseif (!is_array($config)) {
$configArray = $this->checkIfFileExists($config);
}
// Invoke sandbox setter to throw exception if not Boolean datatype
if (!empty($configArray['sandbox'])) {
$this->setSandbox($configArray['sandbox']);
}
if (is_array($configArray)) {
$this->checkConfigKeys($configArray);
} else {
throw new \Exception('$config is of the incorrect type ' . gettype($configArray) . ' and should be of the type array');
}
} else {
throw new \Exception('$config cannot be null.');
}
}
/* Helper function to log data within the Client */
private function logMessage($message) {
if ($this->logger) {
$this->logger->debug($message);
}
}
/* Get the Region specific properties from the Regions class.*/
private function getRegionUrls()
{
$regionObject = new Regions();
$this->mwsServiceUrls = $regionObject->mwsServiceUrls;
$this->regionMappings = $regionObject->regionMappings;
$this->profileEndpointUrls = $regionObject->profileEndpointUrls;
}
/* checkIfFileExists - check if the JSON file exists in the path provided */
private function checkIfFileExists($config)
{
if (file_exists($config)) {
$jsonString = file_get_contents($config);
$configArray = json_decode($jsonString, true);
$jsonError = json_last_error();
if ($jsonError != 0) {
$errorMsg = "Error with message - content is not in json format" . $this->getErrorMessageForJsonError($jsonError) . " " . $configArray;
throw new \Exception($errorMsg);
}
} else {
$errorMsg ='$config is not a Json File path or the Json File was not found in the path provided';
throw new \Exception($errorMsg);
}
return $configArray;
}
/* Checks if the keys of the input configuration matches the keys in the config array
* if they match the values are taken else throws exception
* strict case match is not performed
*/
private function checkConfigKeys($config)
{
$config = array_change_key_case($config, CASE_LOWER);
$config = $this->trimArray($config);
foreach ($config as $key => $value) {
if (array_key_exists($key, $this->config)) {
$this->config[$key] = $value;
} else {
throw new \Exception('Key ' . $key . ' is either not part of the configuration or has incorrect Key name.
check the config array key names to match your key names of your config array', 1);
}
}
}
/* Convert a json error code to a descriptive error message
*
* @param int $jsonError message code
*
* @return string error message
*/
private function getErrorMessageForJsonError($jsonError)
{
switch ($jsonError) {
case JSON_ERROR_DEPTH:
return " - maximum stack depth exceeded.";
break;
case JSON_ERROR_STATE_MISMATCH:
return " - invalid or malformed JSON.";
break;
case JSON_ERROR_CTRL_CHAR:
return " - control character error.";
break;
case JSON_ERROR_SYNTAX:
return " - syntax error.";
break;
default:
return ".";
break;
}
}
/* Setter for sandbox
* Sets the Boolean value for config['sandbox'] variable
*/
public function setSandbox($value)
{
if (is_bool($value)) {
$this->config['sandbox'] = $value;
} else {
throw new \Exception('sandbox value ' . $value . ' is of type ' . gettype($value) . ' and should be a boolean value');
}
}
/* Setter for config['client_id']
* Sets the value for config['client_id'] variable
*/
public function setClientId($value)
{
if (!empty($value)) {
$this->config['client_id'] = $value;
} else {
throw new \Exception('setter value for client ID provided is empty');
}
}
/* Setter for config['app_id']
* Sets the value for config['app_id'] variable
*/
public function setAppId($value)
{
if (!empty($value)) {
$this->config['app_id'] = $value;
} else {
throw new \Exception('setter value for app ID provided is empty');
}
}
/* Setter for Proxy
* input $proxy [array]
* @param $proxy['proxy_user_host'] - hostname for the proxy
* @param $proxy['proxy_user_port'] - hostname for the proxy
* @param $proxy['proxy_user_name'] - if your proxy required a username
* @param $proxy['proxy_user_password'] - if your proxy required a password
*/
public function setProxy($proxy)
{
if (!empty($proxy['proxy_user_host']))
$this->config['proxy_host'] = $proxy['proxy_user_host'];
if (!empty($proxy['proxy_user_port']))
$this->config['proxy_port'] = $proxy['proxy_user_port'];
if (!empty($proxy['proxy_user_name']))
$this->config['proxy_username'] = $proxy['proxy_user_name'];
if (!empty($proxy['proxy_user_password']))
$this->config['proxy_password'] = $proxy['proxy_user_password'];
}
/* Setter for $mwsServiceUrl
* Set the URL to which the post request has to be made for unit testing
*/
public function setMwsServiceUrl($url)
{
$this->mwsServiceUrl = $url;
}
/* Getter
* Gets the value for the key if the key exists in config
*/
public function __get($name)
{
if (array_key_exists(strtolower($name), $this->config)) {
return $this->config[strtolower($name)];
} else {
throw new \Exception('Key ' . $name . ' is either not a part of the configuration array config or the ' . $name . ' does not match the key name in the config array', 1);
}
}
/* Getter for parameters string
* Gets the value for the parameters string for unit testing
*/
public function getParameters()
{
return trim($this->parameters);
}
/* Trim the input Array key values */
private function trimArray($array)
{
foreach ($array as $key => $value) {
// Do not attemp to trim array variables, boolean variables, or the proxy password
// Trimming a boolean value (as a string) may not produce the expected output, so pass it through as-is
if (!is_array($value) && !is_bool($value) && $key !== 'proxy_password') {
$array[$key] = trim($value);
}
}
return $array;
}
/* GetUserInfo convenience function - Returns user's profile information from Amazon using the access token returned by the Button widget.
*
* @see http://login.amazon.com/website Step 4
* @param $accessToken [String]
*/
public function getUserInfo($accessToken)
{
// Get the correct Profile Endpoint URL based off the country/region provided in the config['region']
$this->profileEndpointUrl();
if (empty($accessToken)) {
throw new \InvalidArgumentException('Access Token is a required parameter and is not set');
}
// To make sure double encoding doesn't occur decode first and encode again.
$accessToken = urldecode($accessToken);
$url = $this->profileEndpoint . '/auth/o2/tokeninfo';
$httpCurlRequest = new HttpCurl($this->config);
$httpCurlRequest->setAccessToken($accessToken);
$httpCurlRequest->setHttpHeader();
$response = $httpCurlRequest->httpGet($url);
$data = json_decode($response);
// Ensure that the Access Token matches either the supplied Client ID *or* the supplied App ID
// Web apps and Mobile apps will have different Client ID's but App ID should be the same
// As long as one of these matches, from a security perspective, we have done our due diligence
if (!isset($data->aud)) {
throw new \Exception('The tokeninfo API call did not succeed');
}
if (($data->aud != $this->config['client_id']) && ($data->app_id != $this->config['app_id'])) {
// The access token does not belong to us
throw new \Exception('The Access Token belongs to neither your Client ID nor App ID');
}
// Exchange the access token for user profile
$url = $this->profileEndpoint . '/user/profile';
$httpCurlRequest = new HttpCurl($this->config);
$httpCurlRequest->setAccessToken($accessToken);
$httpCurlRequest->setHttpHeader();
$response = $httpCurlRequest->httpGet($url);
$userInfo = json_decode($response, true);
return $userInfo;
}
/* setParametersAndPost - sets the parameters array with non empty values from the requestParameters array sent to API calls.
* If Provider Credit Details is present, values are set by setProviderCreditDetails
* If Provider Credit Reversal Details is present, values are set by setProviderCreditDetails
*/
private function setParametersAndPost($parameters, $fieldMappings, $requestParameters)
{
/* For loop to take all the non empty parameters in the $requestParameters and add it into the $parameters array,
* if the keys are matched from $requestParameters array with the $fieldMappings array
*/
foreach ($requestParameters as $param => $value) {
// Do not use trim on boolean values, or it will convert them to '0' or '1'
if (!is_array($value) && !is_bool($value)) {
$value = trim($value);
}
// Ensure that no unexpected type coercions have happened
if ($param === 'capture_now' || $param === 'confirm_now' || $param === 'inherit_shipping_address' || $param === 'request_payment_authorization' || $param === 'expect_immediate_authorization') {
if (!is_bool($value)) {
throw new \Exception($param . ' value ' . $value . ' is of type ' . gettype($value) . ' and should be a boolean value');
}
} elseif ($param === 'provider_credit_details' || $param === 'provider_credit_reversal_details' || $param === 'order_item_categories' || $param === 'notification_configuration_list') {
if (!is_array($value)) {
throw new \Exception($param . ' value ' . $value . ' is of type ' . gettype($value) . ' and should be an array value');
}
}
// When checking for non-empty values, consider any boolean as non-empty
if (array_key_exists($param, $fieldMappings) && (is_bool($value) || $value!='')) {
if (is_array($value)) {
// If the parameter is a provider_credit_details or provider_credit_reversal_details, call the respective functions to set the values
if ($param === 'provider_credit_details') {
$parameters = $this->setProviderCreditDetails($parameters, $value);
} elseif ($param === 'provider_credit_reversal_details') {
$parameters = $this->setProviderCreditReversalDetails($parameters, $value);
} elseif ($param === 'order_item_categories') {
$parameters = $this->setOrderItemCategories($parameters, $value);
} elseif ($param == 'notification_configuration_list') {
$parameters = $this->setNotificationConfigurationList($parameters, $value);
}
} else {
$parameters[$fieldMappings[$param]] = $value;
}
}
}
$parameters = $this->setDefaultValues($parameters, $fieldMappings, $requestParameters);
$responseObject = $this->calculateSignatureAndPost($parameters);
return $responseObject;
}
/* calculateSignatureAndPost - convert the Parameters array to string and curl POST the parameters to MWS */
private function calculateSignatureAndPost($parameters)
{
// Call the signature and Post function to perform the actions. Returns XML in array format
$parametersString = $this->calculateSignatureAndParametersToString($parameters);
// POST using curl the String converted Parameters
$response = $this->invokePost($parametersString);
// Send this response as args to ResponseParser class which will return the object of the class.
$responseObject = new ResponseParser($response);
return $responseObject;
}
/* If merchant_id is not set via the requestParameters array then it's taken from the config array
*
* Set the platform_id if set in the config['platform_id'] array
*
* If currency_code is set in the $requestParameters and it exists in the $fieldMappings array, strtoupper it
* else take the value from config array if set
*/
private function setDefaultValues($parameters, $fieldMappings, $requestParameters)
{
if (empty($requestParameters['merchant_id']))
$parameters['SellerId'] = $this->config['merchant_id'];
if (array_key_exists('platform_id', $fieldMappings)) {
if (empty($requestParameters['platform_id']) && !empty($this->config['platform_id']))
$parameters[$fieldMappings['platform_id']] = $this->config['platform_id'];
}
if (array_key_exists('currency_code', $fieldMappings)) {
if (!empty($requestParameters['currency_code'])) {
$parameters[$fieldMappings['currency_code']] = strtoupper($requestParameters['currency_code']);
} else if (!(array_key_exists('Action', $parameters) &&
($parameters['Action'] === 'SetOrderAttributes' || $parameters['Action'] === 'ConfirmOrderReference' || $parameters['Action'] === 'SetBillingAgreementDetails'))) {
// Only supply a default CurrencyCode parameter if not using SetOrderAttributes, ConfirmOrderReference, or SetBillingAgreementDetails
$parameters[$fieldMappings['currency_code']] = strtoupper($this->config['currency_code']);
}
}
return $parameters;
}
/* setOrderItemCategories - helper function used by SetOrderAttributes API to set
* one or more Order Item Categories
*/
private function setOrderItemCategories($parameters, $categories)
{
$categoryIndex = 0;
$categoryString = 'OrderAttributes.SellerOrderAttributes.OrderItemCategories.OrderItemCategory.';
foreach ($categories as $value) {
$categoryIndex = $categoryIndex + 1;
$parameters[$categoryString . $categoryIndex] = $value;
}
return $parameters;
}
/* setMerchantNotificationUrls - helper function used by SetMerchantNotificationConfiguration API to set
* one or more Notification Configurations
*/
private function setNotificationConfigurationList($parameters, $configuration)
{
$configurationIndex = 0;
if (!is_array($configuration)) {
throw new \Exception('Notification Configuration List value ' . $configuration . ' is of type ' . gettype($configuration) . ' and should be an array value');
}
foreach ($configuration as $url => $events) {
$configurationIndex = $configurationIndex + 1;
$parameters['NotificationConfigurationList.NotificationConfiguration.' . $configurationIndex . '.NotificationUrl'] = $url;
$eventIndex = 0;
if (!is_array($events)) {
throw new \Exception('Notification Configuration Events value ' . $events . ' is of type ' . gettype($events) . ' and should be an array value');
}
foreach ($events as $event) {
$eventIndex = $eventIndex + 1;
$parameters['NotificationConfigurationList.NotificationConfiguration.' . $configurationIndex . '.EventTypes.EventTypeList.' . $eventIndex] = $event;
}
}
return $parameters;
}
/* setProviderCreditDetails - sets the provider credit details sent via the Capture or Authorize API calls
* @param provider_id - [String]
* @param credit_amount - [String]
* @optional currency_code - [String]
*/
private function setProviderCreditDetails($parameters, $providerCreditInfo)
{
$providerIndex = 0;
$providerString = 'ProviderCreditList.member.';
$fieldMappings = array(
'provider_id' => 'ProviderId',
'credit_amount' => 'CreditAmount.Amount',
'currency_code' => 'CreditAmount.CurrencyCode'
);
foreach ($providerCreditInfo as $key => $value) {
$value = array_change_key_case($value, CASE_LOWER);
$providerIndex = $providerIndex + 1;
foreach ($value as $param => $val) {
if (array_key_exists($param, $fieldMappings) && trim($val)!='') {
$parameters[$providerString.$providerIndex. '.' .$fieldMappings[$param]] = $val;
}
}
// If currency code is not entered take it from the config array
if (empty($parameters[$providerString.$providerIndex. '.' .$fieldMappings['currency_code']])) {
$parameters[$providerString.$providerIndex. '.' .$fieldMappings['currency_code']] = strtoupper($this->config['currency_code']);
}
}
return $parameters;
}
/* setProviderCreditReversalDetails - sets the reverse provider credit details sent via the Refund API call.
* @param provider_id - [String]
* @param credit_amount - [String]
* @optional currency_code - [String]
*/
private function setProviderCreditReversalDetails($parameters, $providerCreditInfo)
{
$providerIndex = 0;
$providerString = 'ProviderCreditReversalList.member.';
$fieldMappings = array(
'provider_id' => 'ProviderId',
'credit_reversal_amount' => 'CreditReversalAmount.Amount',
'currency_code' => 'CreditReversalAmount.CurrencyCode'
);
foreach ($providerCreditInfo as $key => $value) {
$value = array_change_key_case($value, CASE_LOWER);
$providerIndex = $providerIndex + 1;
foreach ($value as $param => $val) {
if (array_key_exists($param, $fieldMappings) && trim($val)!='') {
$parameters[$providerString.$providerIndex. '.' .$fieldMappings[$param]] = $val;
}
}
// If currency code is not entered take it from the config array
if (empty($parameters[$providerString.$providerIndex. '.' .$fieldMappings['currency_code']])) {
$parameters[$providerString.$providerIndex. '.' .$fieldMappings['currency_code']] = strtoupper($this->config['currency_code']);
}
}
return $parameters;
}
/* GetMerchantAccountStatus API call - Returns the status of the Merchant Account.
* @see TODO
* @param requestParameters['merchant_id'] - [String]
* @optional requestParameters['mws_auth_token'] - [String]
*/
public function getMerchantAccountStatus($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'GetMerchantAccountStatus';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'mws_auth_token' => 'MWSAuthToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* GetOrderReferenceDetails API call - Returns details about the Order Reference object and its current state.
* @see https://pay.amazon.com/developer/documentation/apireference/201751970
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_order_reference_id'] - [String]
* @optional requestParameters['address_consent_token'] - [String]
* @optional requestParameters['access_token'] - [String]
* @optional requestParameters['mws_auth_token'] - [String]
*
* You cannot pass both address_consent_token and access_token in
* the same call or you will encounter a 400/"AmbiguousToken" error
*/
public function getOrderReferenceDetails($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'GetOrderReferenceDetails';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'amazon_order_reference_id' => 'AmazonOrderReferenceId',
'address_consent_token' => 'AddressConsentToken',
'access_token' => 'AccessToken',
'mws_auth_token' => 'MWSAuthToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* ListOrderReference API call - Returns details about the Order Reference object and its current state from the sellers.
* @see https://pay.amazon.com/developer/documentation/apireference/201751970
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['query_id'] - [String]
* @param requestParameters['query_id_type'] - [String] (SellerOrderId)
* @optional requestParameters['page_size'] - [Int]
* @optional requestParameters['created_start_time'] - [String] (Date/Time ISO8601)
* @optional requestParameters['created_end_time'] - [String] (Date/Time ISO8601) Limited to 31 days
* @optional requestParameters['sort_order'] - [String] (Ascending/Descending)
* @optional requestParameters['mws_auth_token'] - [String]
* @optional requestParameters['order_status_list'] - [Array]
*/
public function listOrderReference($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'ListOrderReference';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$payment_domains = array(
"us" => "NA_USD",
"jp" => "FE_JPY",
"de" => "EU_EUR",
"uk" => "EU_GBP"
);
$requestParameters['payment_domain'] = $payment_domains[strtolower($this->config['region'])];
$fieldMappings = array(
'merchant_id' => 'SellerId',
'mws_auth_token' => 'MWSAuthToken',
'query_id' => 'QueryId',
'query_id_type' => 'QueryIdType',
'page_size' => 'PageSize',
'created_start_time' => 'CreatedTimeRange.StartTime',
'created_end_time' => 'CreatedTimeRange.EndTime',
'sort_order' => 'SortOrder',
'payment_domain' => 'PaymentDomain'
);
if( $requestParameters['order_status_list'] ){
$status_index = 0;
foreach ($requestParameters['order_status_list'] as $status) {
$status_index++;
$requestParameters['order_status_list_'.$status_index] = $status;
$fieldMappings['order_status_list_'.$status_index] = 'OrderReferenceStatusListFilter.OrderReferenceStatus.'.$status_index;
}
}
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* ListOrderReferenceByNextToken API call - Returns details about the Order Reference object and its current
* state from the sellers.
* @see https://pay.amazon.com/developer/documentation/apireference/201751970
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['next_token'] - [String]
* @optional requestParameters['mws_auth_token'] - [String]
*/
public function listOrderReferenceByNextToken($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'ListOrderReferenceByNextToken';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'mws_auth_token' => 'MWSAuthToken',
'next_page_token' => 'NextPageToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* SetOrderReferenceDetails API call - Sets order reference details such as the order total and a description for the order.
* @see https://pay.amazon.com/developer/documentation/apireference/201751960
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_order_reference_id'] - [String]
* @param requestParameters['amount'] - [String]
* @param requestParameters['currency_code'] - [String]
* @optional requestParameters['platform_id'] - [String]
* @optional requestParameters['seller_note'] - [String]
* @optional requestParameters['seller_order_id'] - [String]
* @optional requestParameters['store_name'] - [String]
* @optional requestParameters['custom_information'] - [String]
* @optional requestParameters['supplementary_data'] - [String]
* @optional requestParameters['request_payment_authorization'] - [Boolean]
* @optional requestParameters['mws_auth_token'] - [String]
*/
public function setOrderReferenceDetails($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'SetOrderReferenceDetails';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'amazon_order_reference_id' => 'AmazonOrderReferenceId',
'amount' => 'OrderReferenceAttributes.OrderTotal.Amount',
'currency_code' => 'OrderReferenceAttributes.OrderTotal.CurrencyCode',
'platform_id' => 'OrderReferenceAttributes.PlatformId',
'seller_note' => 'OrderReferenceAttributes.SellerNote',
'seller_order_id' => 'OrderReferenceAttributes.SellerOrderAttributes.SellerOrderId',
'store_name' => 'OrderReferenceAttributes.SellerOrderAttributes.StoreName',
'custom_information' => 'OrderReferenceAttributes.SellerOrderAttributes.CustomInformation',
'supplementary_data' => 'OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData',
'request_payment_authorization' => 'OrderReferenceAttributes.RequestPaymentAuthorization',
'mws_auth_token' => 'MWSAuthToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* SetOrderAttributes API call - Sets order reference details such as the order total and a description for the order.
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_order_reference_id'] - [String]
* @optional requestParameters['amount'] - [String]
* @optional requestParameters['currency_code'] - [String]
* @optional requestParameters['platform_id'] - [String]
* @optional requestParameters['seller_note'] - [String]
* @optional requestParameters['seller_order_id'] - [String]
* @optional requestParameters['store_name'] - [String]
* @optional requestParameters['custom_information'] - [String]
* @optional requestParameters['supplementary_data'] - [String]
* @optional requestParameters['request_payment_authorization'] - [Boolean]
* @optional requestParameters['payment_service_provider_id'] - [String]
* @optional requestParameters['payment_service_provider_order_id'] - [String]
* @optional requestParameters['order_item_categories'] - [array()]
* @optional requestParameters['mws_auth_token'] - [String]
*/
public function setOrderAttributes($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'SetOrderAttributes';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'amazon_order_reference_id' => 'AmazonOrderReferenceId',
'amount' => 'OrderAttributes.OrderTotal.Amount',
'currency_code' => 'OrderAttributes.OrderTotal.CurrencyCode',
'platform_id' => 'OrderAttributes.PlatformId',
'seller_note' => 'OrderAttributes.SellerNote',
'seller_order_id' => 'OrderAttributes.SellerOrderAttributes.SellerOrderId',
'store_name' => 'OrderAttributes.SellerOrderAttributes.StoreName',
'custom_information' => 'OrderAttributes.SellerOrderAttributes.CustomInformation',
'supplementary_data' => 'OrderAttributes.SellerOrderAttributes.SupplementaryData',
'request_payment_authorization' => 'OrderAttributes.RequestPaymentAuthorization',
'payment_service_provider_id' => 'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderId',
'payment_service_provider_order_id' => 'OrderAttributes.PaymentServiceProviderAttributes.PaymentServiceProviderOrderId',
'order_item_categories' => array(),
'mws_auth_token' => 'MWSAuthToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* ConfirmOrderReference API call - Confirms that the order reference is free of constraints and all required information has been set on the order reference.
* @see https://pay.amazon.com/developer/documentation/apireference/201751980
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_order_reference_id'] - [String]
* @optional requestParameters['success_url'] - [String]
* @optional requestParameters['failure_url'] - [String]
* @optional requestParameters['authorization_amount'] - [String]
* @optional requestParameters['currency_code'] - [String]
* @optional requestParameters['mws_auth_token'] - [String]
* @optional requestParameters['expect_immediate_authorization'] - [Boolean] Default value is false
*/
public function confirmOrderReference($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'ConfirmOrderReference';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'amazon_order_reference_id' => 'AmazonOrderReferenceId',
'success_url' => 'SuccessUrl',
'failure_url' => 'FailureUrl',
'authorization_amount' => 'AuthorizationAmount.Amount',
'currency_code' => 'AuthorizationAmount.CurrencyCode',
'mws_auth_token' => 'MWSAuthToken',
'expect_immediate_authorization' => 'ExpectImmediateAuthorization'
);
if (isset($requestParameters['authorization_amount']) && !isset($requestParameters['currency_code'])) {
$requestParameters['currency_code'] = strtoupper($this->config['currency_code']);
}
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* CancelOrderReference API call - Cancels a previously confirmed order reference.
* @see https://pay.amazon.com/developer/documentation/apireference/201751990
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_order_reference_id'] - [String]
* @optional requestParameters['cancelation_reason'] [String]
* @optional requestParameters['mws_auth_token'] - [String]
*/
public function cancelOrderReference($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'CancelOrderReference';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'amazon_order_reference_id' => 'AmazonOrderReferenceId',
'cancelation_reason' => 'CancelationReason',
'mws_auth_token' => 'MWSAuthToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* CloseOrderReference API call - Confirms that an order reference has been fulfilled (fully or partially)
* and that you do not expect to create any new authorizations on this order reference.
* @see https://pay.amazon.com/developer/documentation/apireference/201752000
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_order_reference_id'] - [String]
* @optional requestParameters['closure_reason'] [String]
* @optional requestParameters['mws_auth_token'] - [String]
*/
public function closeOrderReference($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'CloseOrderReference';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'amazon_order_reference_id' => 'AmazonOrderReferenceId',
'closure_reason' => 'ClosureReason',
'mws_auth_token' => 'MWSAuthToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* CloseAuthorization API call - Closes an authorization.
* @see https://pay.amazon.com/developer/documentation/apireference/201752070
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_authorization_id'] - [String]
* @optional requestParameters['closure_reason'] [String]
* @optional requestParameters['mws_auth_token'] - [String]
*/
public function closeAuthorization($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'CloseAuthorization';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'amazon_authorization_id' => 'AmazonAuthorizationId',
'closure_reason' => 'ClosureReason',
'mws_auth_token' => 'MWSAuthToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* Authorize API call - Reserves a specified amount against the payment method(s) stored in the order reference.
* @see https://pay.amazon.com/developer/documentation/apireference/201752010
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_order_reference_id'] - [String]
* @param requestParameters['authorization_amount'] [String]
* @param requestParameters['currency_code'] - [String]
* @param requestParameters['authorization_reference_id'] [String]
* @optional requestParameters['capture_now'] [Boolean]
* @optional requestParameters['provider_credit_details'] - [array (array())]
* @optional requestParameters['seller_authorization_note'] [String]
* @optional requestParameters['transaction_timeout'] [String] - Defaults to 1440 minutes
* @optional requestParameters['soft_descriptor'] - [String]
* @optional requestParameters['mws_auth_token'] - [String]
*/
public function authorize($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'Authorize';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'amazon_order_reference_id' => 'AmazonOrderReferenceId',
'authorization_amount' => 'AuthorizationAmount.Amount',
'currency_code' => 'AuthorizationAmount.CurrencyCode',
'authorization_reference_id' => 'AuthorizationReferenceId',
'capture_now' => 'CaptureNow',
'provider_credit_details' => array(),
'seller_authorization_note' => 'SellerAuthorizationNote',
'transaction_timeout' => 'TransactionTimeout',
'soft_descriptor' => 'SoftDescriptor',
'mws_auth_token' => 'MWSAuthToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* GetAuthorizationDetails API call - Returns the status of a particular authorization and the total amount captured on the authorization.
* @see https://pay.amazon.com/developer/documentation/apireference/201752030
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_authorization_id'] [String]
* @optional requestParameters['mws_auth_token'] - [String]
*/
public function getAuthorizationDetails($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'GetAuthorizationDetails';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'amazon_authorization_id' => 'AmazonAuthorizationId',
'mws_auth_token' => 'MWSAuthToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* Capture API call - Captures funds from an authorized payment instrument.
* @see https://pay.amazon.com/developer/documentation/apireference/201752040
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_authorization_id'] - [String]
* @param requestParameters['capture_amount'] - [String]
* @param requestParameters['currency_code'] - [String]
* @param requestParameters['capture_reference_id'] - [String]
* @optional requestParameters['provider_credit_details'] - [array (array())]
* @optional requestParameters['seller_capture_note'] - [String]
* @optional requestParameters['soft_descriptor'] - [String]
* @optional requestParameters['mws_auth_token'] - [String]
*/
public function capture($requestParameters = array())
{
$parameters = array();
$parameters['Action'] = 'Capture';
$requestParameters = array_change_key_case($requestParameters, CASE_LOWER);
$fieldMappings = array(
'merchant_id' => 'SellerId',
'amazon_authorization_id' => 'AmazonAuthorizationId',
'capture_amount' => 'CaptureAmount.Amount',
'currency_code' => 'CaptureAmount.CurrencyCode',
'capture_reference_id' => 'CaptureReferenceId',
'provider_credit_details' => array(),
'seller_capture_note' => 'SellerCaptureNote',
'soft_descriptor' => 'SoftDescriptor',
'mws_auth_token' => 'MWSAuthToken'
);
$responseObject = $this->setParametersAndPost($parameters, $fieldMappings, $requestParameters);
return ($responseObject);
}
/* GetCaptureDetails API call - Returns the status of a particular capture and the total amount refunded on the capture.
* @see https://pay.amazon.com/developer/documentation/apireference/201752060
*
* @param requestParameters['merchant_id'] - [String]
* @param requestParameters['amazon_capture_id'] - [String]
* @optional requestParameters['mws_auth_token'] - [String]
*/