Closed sebastianhelbig closed 10 years ago
{
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [
{
"credit_card": {
"type": "visa",
"number": "xxxxxxxxxxxx0331",
"expire_month": "11",
"expire_year": "2019",
"first_name": "Joe",
"last_name": "Shopper"
}
}
]
},
"transactions": [
{
"amount": {
"total": "20.00",
"currency": "USD",
"details": {
"subtotal": "17.50",
"tax": "1.30",
"shipping": "1.20"
}
},
"description": "Payment description",
"item_list": {
"items": [
{
"name": "Ground Coffee 40 oz",
"price": "7.50",
"currency": "USD",
"quantity": "1"
},
{
"name": "Granola bars",
"price": "2.00",
"currency": "USD",
"quantity": "5"
}
]
},
"related_resources": [
{
"sale": {
"id": "8W754701YR607764V",
"create_time": "2014-09-17T16:53:22Z",
"update_time": "2014-09-17T16:53:43Z",
"amount": {
"total": "20.00",
"currency": "USD"
},
"state": "completed",
"parent_payment": "PAY-39861121J87096426KQM3ZAQ",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/8W754701YR607764V",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/8W754701YR607764V/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-39861121J87096426KQM3ZAQ",
"rel": "parent_payment",
"method": "GET"
}
]
}
}
]
}
],
"id": "PAY-39861121J87096426KQM3ZAQ",
"create_time": "2014-09-17T16:53:22Z",
"update_time": "2014-09-17T16:53:43Z",
"state": "approved",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-39861121J87096426KQM3ZAQ",
"rel": "self",
"method": "GET"
}
]
}
{
"id": "PAY-4MA422039F6217725KQM32BY",
"create_time": "2014-09-17T16:55:35Z",
"update_time": "2014-09-17T16:55:48Z",
"state": "approved",
"intent": "sale",
"payer": {
"payment_method": "paypal",
"payer_info": {
"email": "sample@buy.com",
"first_name": "SandboxTest",
"last_name": "Account",
"payer_id": "REABK2UGK7PLW",
"shipping_address": {
"line1": "1 Main St",
"line2": "",
"city": "San Jose",
"state": "CA",
"postal_code": "95131",
"country_code": "US",
"recipient_name": ""
}
}
},
"transactions": [
{
"amount": {
"total": "20.00",
"currency": "USD",
"details": {
"subtotal": "17.50",
"tax": "1.30",
"shipping": "1.20"
}
},
"description": "Payment description",
"item_list": {
"items": [
{
"name": "Ground Coffee 40 oz",
"price": "7.50",
"currency": "USD",
"quantity": "1"
},
{
"name": "Granola bars",
"price": "2.00",
"currency": "USD",
"quantity": "5"
}
],
"shipping_address": {
"recipient_name": "",
"line1": "1 Main St",
"line2": "",
"city": "San Jose",
"state": "CA",
"postal_code": "95131",
"country_code": "US"
}
},
"related_resources": [
{
"sale": {
"id": "4UU45725DN228182R",
"create_time": "2014-09-17T16:55:35Z",
"update_time": "2014-09-17T16:55:48Z",
"amount": {
"total": "20.00",
"currency": "USD"
},
"payment_mode": "INSTANT_TRANSFER",
"state": "completed",
"protection_eligibility": "ELIGIBLE",
"protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
"parent_payment": "PAY-4MA422039F6217725KQM32BY",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/4UU45725DN228182R",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/4UU45725DN228182R/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-4MA422039F6217725KQM32BY",
"rel": "parent_payment",
"method": "GET"
}
]
}
}
]
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-4MA422039F6217725KQM32BY",
"rel": "self",
"method": "GET"
}
]
}
P.S. I have used json_encode
command instead of var_dump
to echo the $result variables. This solves the issue with not showing complete information in var_dump
So...no real solution for me as a sdk user...
The reason we may not have the first name available all the time for the Payer Info is because of the feature that allows anyone to checkout using a credit card without having a paypal account. This restricts us from having Payer information for all times.
Do you have a suggestion in mind, that could make it easier for you to integrate with your system ?
The thing is, I just call $result->getPayer()->getPayerInfo()->getFirstName() I get a Payer Object and a PayerInfo Object and so I expect getFirstName() to -not- throw an error. An empty result would be entirely acceptable.
The thing is there is no PayerInfo object. So, that returns a null value. And you are trying to call getFirstName() method on a null value. Thats why it is causing such issue.
So basically, the issue is with the chained method invocation.
If we create an empty instance of PayerInfo even if it is not retrieved from API, it may cause a lot of confusion to all developers.
Okay, to clarify this: I have no problems if -my- code throws errors, as i can precheck this as you said. But(!) if you check the trace in my first post, you can clearly see, that in this case there was a PayerInfo Object, which called PPModel which throwed the notice. So the problem is in the sdk.
Trace: #0 ErrorHandler->handleError(8, Undefined index: first_name, /var/www/***.de/inc/vendor/paypal/sdk-core-php/lib/PayPal/Common/PPModel.php, 14, Array ([key] => first_name)) called at [/var/www/***.de/inc/class/MainController.php:140]
#1 errorHandler(8, Undefined index: first_name, /var/www/***.de/inc/vendor/paypal/sdk-core-php/lib/PayPal/Common/PPModel.php, 14, Array ([key] => first_name)) called at [/var/www/***.de/inc/vendor/paypal/sdk-core-php/lib/PayPal/Common/PPModel.php:14]
#2 PayPal\Common\PPModel->__get(first_name) called at [/var/www/***.de/inc/vendor/paypal/rest-api-sdk-php/lib/PayPal/Api/PayerInfo.php:69]
#3 PayPal\Api\PayerInfo->getFirstName() called at [/var/www/***.de/inc/class/SpendenController.php:129]
#4 SpendenController->perform(75b7a93a0aaa3c26) called at [/var/www/***.de/inc/class/MainController.php:786]
#5 MainController->perform() called at [/var/www/***.de/index.php:7]
Anything new here?
Hi @ktrhn , have you tried using the latest version of this SDK? @jaypatel512 has since added better handling for getting property values that aren't set and should resolve the original issue you brought up regarding the exception being thrown from the SDK.
After a paypal transaction has been approved I write the name and email of the buyer to our own db. But sometimes this fails: