Я работаю над настройкой функции платного членства на нашем сайте WordPress.
Для целей оплаты мы пытаемся использовать греческий платежный процессор и соответствующие ему вызовы API с использованием PHP. В какой-то момент мне удалось добиться успеха, но я застрял в определенной точке.
Одна из предлагаемых функций API заключается в получении сведений об определенных заказах, используя в качестве ссылки идентификатор заказа. Моя проблема связана с обработкой возвращенного вывода.
Запрос будет вызываться с использованием:
GET /api/transactions/?ordercode=175936509216
И образец возврата будет в формате RAW:
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 1285
Expires: -1
Date: Wed, 16 Sep 2015 11:07:31 GMT
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
Cache-Control: no-cache
Pragma: no-cache
{ "ErrorCode" : 0,
"ErrorText" : null,
"TimeStamp" : "2015-09-16T14:07:31.4361544+03:00",
"Transactions" : [ { "Amount" : 20.0,
"ChannelId" : "d84f93ff-8ad0-4d97-a7a3-f187dd667553",
"ClearanceDate" : "2015-09-10T01:10:50.71",
"Commission" : 0.71999999999999997,
"CreatedBy" : null,
"CreditCard" : { "CardHolderName" : "Some name",
"CardType" : { "CardTypeId" : 0,
"Name" : "VISA"
},
"CountryCode" : "US",
"IssuingBank" : "Demo Bank",
"Number" : "411111XXXXXX1111",
"Token" : "B6D3CC438671F16B211D83BBC077FEBD843CBC28"
},
"CurrentInstallment" : 0,
"CustomerTrns" : null,
"Fee" : 0.0,
"InsDate" : "2015-09-09T16:15:09.42",
"IsManualRefund" : false,
"MerchantId" : "faae4194-7bf3-4b5c-9fc9-ec584397308c",
"MerchantTrns" : null,
"Order" : { "ChannelId" : "95d02b56-bace-4608-ad1b-c1a8da705e52",
"OrderCode" : 491831172603,
"RequestLang" : "en-US",
"ResellerId" : null,
"ResellerSourceCode" : null,
"SourceCode" : "Default",
"Tags" : [ ]
},
"ParentId" : null,
"Payment" : { "ChannelId" : "d84f93ff-8ad0-4d97-a7a3-f187dd667553",
"Email" : "some.email2@some.company.com",
"FullName" : "Some names",
"Installments" : 0,
"Phone" : "6969696969",
"RecurringSupport" : false
},
"ResellerId" : null,
"ResellerSourceCode" : null,
"SourceCode" : "Default",
"StatusId" : "F",
"TargetPersonId" : null,
"TotalInstallments" : 0,
"TransactionId" : "9b7af26e-bba7-4830-8d81-36dfd2bc3f3c",
"TransactionType" : { "Name" : "ChargeCard",
"TransactionTypeId" : 5
}
} ]
}
Который с помощью функции декодирования json преобразуется в массив и с помощью функции var_dumb мы получаем следующий результат:
array(4) {
["Transactions"]=>
array(1) {
[0]=>
array(24) {
["Fee"]=>
float(0)
["ParentId"]=>
NULL
["Amount"]=>
float(20)
["StatusId"]=>
string(1) "F"
["ChannelId"]=>
string(36) "d84f93ff-8ad0-4d97-a7a3-f187dd667553"
["MerchantId"]=>
string(36) "faae4194-7bf3-4b5c-9fc9-ec584397308c"
["ResellerId"]=>
NULL
["InsDate"]=>
string(22) "2015-09-09T16:15:09.42"
["CreatedBy"]=>
NULL
["SourceCode"]=>
string(7) "Default"
["TransactionId"]=>
string(36) "9b7af26e-bba7-4830-8d81-36dfd2bc3f3c"
["Commission"]=>
float(0.72)
["MerchantTrns"]=>
NULL
["CustomerTrns"]=>
NULL
["IsManualRefund"]=>
bool(false)
["TargetPersonId"]=>
NULL
["TotalInstallments"]=>
int(0)
["CurrentInstallment"]=>
int(0)
["ClearanceDate"]=>
string(22) "2015-09-10T01:10:50.71"
["ResellerSourceCode"]=>
NULL
["Order"]=>
array(7) {
["OrderCode"]=>
int(491831172603)
["ChannelId"]=>
string(36) "95d02b56-bace-4608-ad1b-c1a8da705e52"
["ResellerId"]=>
NULL
["SourceCode"]=>
string(7) "Default"
["Tags"]=>
array(0) {
}
["RequestLang"]=>
string(5) "en-US"
["ResellerSourceCode"]=>
NULL
}
["Payment"]=>
array(6) {
["Email"]=>
string(30) "somename@somecompany.com"
["Phone"]=>
string(10) "6969696969"
["ChannelId"]=>
string(36) "d84f93ff-8ad0-4d97-a7a3-f187dd667553"
["FullName"]=>
string(17) "Some Name"
["Installments"]=>
int(0)
["RecurringSupport"]=>
bool(false)
}
["TransactionType"]=>
array(2) {
["Name"]=>
string(10) "ChargeCard"
["TransactionTypeId"]=>
int(5)
}
["CreditCard"]=>
array(6) {
["Token"]=>
string(40) "B6D3CC438671F16B211D83BBC077FEBD843CBC28"
["Number"]=>
string(16) "411111XXXXXX1111"
["CountryCode"]=>
string(2) "US"
["IssuingBank"]=>
string(9) "Demo Bank"
["CardHolderName"]=>
string(17) "Some Name"
["CardType"]=>
array(2) {
["Name"]=>
string(4) "VISA"
["CardTypeId"]=>
int(0)
}
}
}
}
["ErrorCode"]=>
int(0)
["ErrorText"]=>
NULL
["TimeStamp"]=>
string(33) "2015-09-16T14:07:31.4361544+03:00"
}
Вопрос в том, как мне найти конкретный индекс этого массива для конкретной переменной, чтобы его можно было присвоить другой новой переменной для дальнейшей обработки. Например, если бы мне нужно было содержимое переменной электронной почты в массиве платежей, как бы я его сослал?
На данный момент API, над которым я работаю, находится в части демо-разработчиков, поэтому показанные здесь данные являются просто фиктивными данными
дополнением к запрошенному комментарию с помощью функции print_r
Array
(
[Transactions] => Array
(
[0] => Array
(
[Fee] => 0
[ParentId] =>
[Amount] => 20
[StatusId] => F
[ChannelId] => d84f93ff-8ad0-4d97-a7a3-f187dd667553
[MerchantId] => faae4194-7bf3-4b5c-9fc9-ec584397308c
[ResellerId] =>
[InsDate] => 2015-09-09T16:15:09.42
[CreatedBy] =>
[SourceCode] => Default
[TransactionId] => 9b7af26e-bba7-4830-8d81-36dfd2bc3f3c
[Commission] => 0.72
[MerchantTrns] =>
[CustomerTrns] =>
[IsManualRefund] =>
[TargetPersonId] =>
[TotalInstallments] => 0
[CurrentInstallment] => 0
[ClearanceDate] => 2015-09-10T01:10:50.71
[ResellerSourceCode] =>
[Order] => Array
(
[OrderCode] => 491831172603
[ChannelId] => 95d02b56-bace-4608-ad1b-c1a8da705e52
[ResellerId] =>
[SourceCode] => Default
[Tags] => Array
(
)
[RequestLang] => en-US
[ResellerSourceCode] =>
)
[Payment] => Array
(
[Email] => someone@somecompany.com
[Phone] => 6969696969
[ChannelId] => d84f93ff-8ad0-4d97-a7a3-f187dd667553
[FullName] => Some Name
[Installments] => 0
[RecurringSupport] =>
)
[TransactionType] => Array
(
[Name] => ChargeCard
[TransactionTypeId] => 5
)
[CreditCard] => Array
(
[Token] => B6D3CC438671F16B211D83BBC077FEBD843CBC28
[Number] => 411111XXXXXX1111
[CountryCode] => US
[IssuingBank] => Demo Bank
[CardHolderName] => Leonidas leonidas
[CardType] => Array
(
[Name] => VISA
[CardTypeId] => 0
)
)
)
)
[ErrorCode] => 0
[ErrorText] =>
[TimeStamp] => 2015-09-16T16:15:59.9665031+03:00
)
Подробнее здесь: https://stackoverflow.com/questions/326 ... ed-by-json