我正在使用Paypal PHP SDK。
我可以得到这个值:
$mail = $payment->payer->payer_info->email;
$name = $payment->payer->payer_info->first_name;
$lname = $payment->payer->payer_info->last_name;
$contry = $payment->payer->payer_info->shipping_address->country_code;
但是,我无法获得SKU。我尝试了以下选项:
// Option #1
$sku = $payment->transactions->item_list->items->sku;
// Option #2
$sku = $payment->transactions->item_list->items->0->sku;
但是什么也没得到,第二个选项出错。
输出的一部分:
....
"payer": {
"payment_method": "paypal",
"status": "VERIFIED",
"payer_info": {
"email": "mymail@gmail.com",
"first_name": "name",
"last_name": "mylastname",
"payer_id": "00000000",
"shipping_address": {
.....
},
"country_code": "nnnnn",
"business_name": "nnnnn"
}
},
"transactions": [
{
"amount": {
"total": "0.01",
"currency": "USD",
"details": {}
},
"payee": {
"merchant_id": "00000000000",
"email": "mymail@gmail.com"
},
"description": "Payment description",
"invoice_number": "000000000",
"item_list": {
"items": [
{
"name": "nnnnnn",
"sku": "1562",
"price": "0.01",
"currency": "USD",
"quantity": 1
}
],
....
如何获取SKU(1562)的值?
答案 0 :(得分:0)
尝试一下:-
$sku = $payment['transactions']['item_list']['items']['sku'];
答案 1 :(得分:0)
我在这里找到了一些不错的代码:https://www.formget.com/paypal-transaction-details/
它必须像:
transactions[0]->item_list->items[0]->price ;
交易和项目是数组,就像 Gabor 所说。