添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hello,
after I've created a payment (method is paypal) I want to execute it on my return site via following code:

$paymentId = $persInfos['paymentId'];
$payment = Payment::get($paymentId, $apiContext);
$execution = new PaymentExecution();
$execution->setPayerId($persInfos['PayerID']);
$result = $payment->execute($execution, $apiContext);

$persInfo is an array where i save all the field from the $_GET var => field names are the same.
Sadly, I get a 400 "PAYMENT_STATE_INVALID" exception
However on the paypal dashboard notifications i can see that the payment has been validated and i got a corresponding message both to the buyer and the payer.
I don't know what causes this behavior, since the api samples on my localhost seem to work fine.
Is this issue already known or does anybody has an idea what causes this exception?
Thanks.

  • Are you facing this on live or sandbox.
  • Can you pass the logs that got generated in sandbox. If not done already, you could follow the instructions shown here .
  • Can you pass the URL that you get when it returns from paypal. The one that should have all the paymentId and PayerId thing.
  • If you could pass these three information, it would be extremely helpful.

    [22-02-2015 11:13:11] PayPal\Core\PayPalHttpConnection: INFO : POST https://api.sandbox.paypal.com/v1/payments/payment/PAY-09U75417FE3417549KTVGEWY/execute
    [22-02-2015 11:13:12] PayPal\Core\PayPalHttpConnection: DEBUG : Request Headers : POST /v1/payments/payment/PAY-09U75417FE3417549KTVGEWY/execute HTTP/1.1, Host: api.sandbox.paypal.com, Accept: / , Content-Type: application/json, User-Agent: PayPalSDK/PayPal-PHP-SDK 1.2.0 (lang=PHP;v=5.4.35;bit=32;os=Linux_info_3.0_#1337_SMP_Tue_Jan_01_00:00:00_CEST_2000_all_GNU/Linux_Linux_info_3.0_#1337_SMP_Tue_Jan_01_00:00:00_CEST_2000_all_GNU/Linux;machine=Linux info 3.0 #1337 SMP Tue Jan 01 00:00:00 CEST 2000 all GNU/Linux;openssl=0.9.8o;curl=7.21.0), Authorization: Bearer A0159y4qjcwts0Zj7ums9wngbZtT6ajasqxnefkGHGPvGSk, PayPal-Request-Id: 13865695277766142464679058800, Content-Length: 28, ,
    [22-02-2015 11:13:12] PayPal\Core\PayPalHttpConnection: DEBUG : Request Data : {"payer_id":"ANGRECDBDXD78"}

    [22-02-2015 11:13:12] PayPal\Core\PayPalHttpConnection: INFO : Response Status : 400
    [22-02-2015 11:13:12] PayPal\Core\PayPalHttpConnection: DEBUG : Response Headers : HTTP/1.1 400 Bad Request, Server: Apache-Coyote/1.1, PROXY_SERVER_INFO: host=slcsbplatformapiserv3002.slc.paypal.com;threadId=465213, Paypal-Debug-Id: d13abf66e4c39, SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=4706&TopLevelTxnStartTime=14bb390e37f&Host=slcsbpaymentsplatformserv3002.slc.paypal.com&pid=1310, Content-Language: *, Date: Sun, 22 Feb 2015 23:13:11 GMT, Connection: close, Content-Type: application/json, Content-Length: 235, Connection: close, ,
    [22-02-2015 11:13:12] PayPal\Core\PayPalHttpConnection: ERROR : Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAY-09U75417FE3417549KTVGEWY/execute . {"name":"PAYMENT_STATE_INVALID","message":"This request is invalid due to the current state of the payment","information_link":" https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_STATE_INVALID","debug_id":"d13abf66e4c39"}
    [22-02-2015 11:13:12] PayPal\Core\PayPalHttpConnection: DEBUG :

    To 3: Return URL seems OK. I get the following $_GET fields in my script:
    PayerID: ANGRECDBDXD78
    TOKEN: EC-349161776N519233J
    PaymentID: PAY-6EF7685356305431SKTVFJ7I

    The funny thing is, that when I go back to the payment page it says:

    This invoice has already been paid. For more information, please contact the merchant.
    There's a problem with the merchant's PayPal account. Please try again later.

    Is there something wrong with my test credentials?

    The paypal sample gives me an empty request object after the execution on my localhost:
    Payment with ID: PAY-8WL90547RE1171601KTWPQYY
    Request Object
    No Data

    When I go back it's the same message: ,,The invoice has already been paid..."
    I'm sorry but my webservice is down due to database maintenance so I just can you provide what I already got a few does ago.
    If there is anything more that could help you feel free to say so.
    Big thanks.

    Btw, just to make sure, are you using "paypal" as "payment_method" when creating that payment ?

    "payer": {
            "payment_method": "paypal"
    

    Let me get back to you after reviewing the payment. I think I have all that I need here. I will let you know as soon as possible.

    $payer = new Payer();
    $payer->setPaymentMethod("paypal");
    $payer->setPayerInfo($payerInfo);
    

    This is what i set to the payer to make it a paypal payment.

    Any news concerning this problem?
    Is it possible, that my paypal acc or the api settings are missing something?

    EDIT:
    I dont know if it helps but:
    In the Dashboard under transaction I can see that all the payments done with the api samples are set to completed. where the payments done within my website are marked as pending.

    Referencing to related Stack Overflow Issues:

  • http://stackoverflow.com/questions/15685963/paypal-certificate-invalid-or-not-found
  • http://stackoverflow.com/questions/24437381/paypal-rest-error-payment-state-invalid
  • Btw, from the debug messages that I was able to retrieve, I saw that the PayerID that you are passing doesnt seem to match the one used for execute.

    Can you please confirm if they are the same. Btw, PayerId is now returned as a part of return URL when paypal redirects the browser to your /execute page.

    For E.g. Sample code returns something like this:

    http://localhost/paypal/PayPal-PHP-SDK/sample/payments/ExecutePayment.php?success=true&paymentId=PAY-60C519777S7370508KTZX4EY&token=EC-5K097793LN8781320&PayerID=REABK2UGK7PLW
    

    As you can see, you could use the PayerID=REABK2UGK7PLW value using $_GET['PayerID'] command as shown in the sample code here.

    Can you please let me know if that is infact what you are doing. I could further debug into the issue.

    Btw, I was a bit occupied with the recent issue that we faced in PayPal-PHP-SDK, and couldn't get back to you sooner.

    Also, @jziaja pointed me out to confirm if you have not enabled Payment Review in your developer dashboard.

    Please have a look at reference issue: https://github.com/paypal/PayPal-NET-SDK/issues/79#issuecomment-74086718

    thank you so much for your time.

    Yes I receive the payerID with the $_Get and it seems to be the same. After that I use it to execute the payment. The same way like in the samples.
    When I echo the payment state within my execution code it say:
    Before execution: created
    After execution: approved.
    But the payment state for the payments over my website are still pending (sandbox -> transactions)
    while the ones made with the samples are set to completed.

    Payment Review is not enabled.

    Interesting. Let me get the Payment Team involved more into debugging this issue. Can you, in the mean time, create a new clientId and try to replicate it.

    My apologies for you running through this issue, but I assure you, we will fix it :)

    Hey @borki23 ! Is it possible for you to send your clientId. Or create a new one, and send it to us.

    The issue you are facing seems to be specific to your account. Btw, Can you please try out these steps:

  • Go to sample/bootstrap.php Line 29
  • And replace the clientId and secret with yours.
  • Run the sample, and see if you are still getting Pending error.
  • This should help us understand if there might be something in your server code that might be causing the issue.

    Hello,
    I've created a new App with new Buyer and Seller account.
    I have chosen payment card to paypal and visa card to none.
    When i go into the transaction tap all incoming payments from my website with currency EUR are now set so completed. The ones from the sample code with currency US are set to pending.
    Before that it was the other way around.
    But I still get a 400 exception while excecuting. Strangely, this happens a few seconds after the execution of the payment, so other parts of my code are getting called anyway.

    I will send you my clientId to you email if you're okay with that.

    Thank you.

    EDIT: I changed the currency in the samples to EUR and now their status is completed aswell. So this seemed to be my mistake. Sorry. But I still get the exception after the execution.

    Yes. Please send me your clientId at [email protected].

    Also, I will be online 10-5 CST approximately, and if possible, we could setup a quick chat/hangout session to discuss this quicker than over the issue tracker.

    Thanks.

    EDIT:

    Just had a skype chat with jaypatel512.
    The problem was that I accidentally executed the payment twice.
    So, the first time everything went fine. But the second execution threw the 400 exception
    For all you guys having trouble: try to check the state of the payment before executing it.

    //get payment
    if ($payment->getState() == 'created') {
        //execute payment if it was created successfully
    

    Thank you.

    You can get more information exact detail about that 400. You can add a catch exception as shown here: https://github.com/paypal/PayPal-PHP-SDK/wiki/exception-%27PayPal%5CException%5CPayPalConnectionException%27-with-message-%27Got-Http-response-code-400-when-accessing

    Can you let us know what the error data is in that exception, and we can help you further.

    I have made the curl request for access token of sandbox account using below code:

    $ch = curl_init();
    $curlConfig = array(
    CURLOPT_URL => "https://api.sandbox.paypal.com/v1/oauth2/token",
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => array(
    'Accept' => 'application/json',
    'Accept-Language' => 'en_US',
    'Client Key' => 'Secret Key',
    'grant_type' => 'client_credentials'
    curl_setopt_array($ch, $curlConfig);
    $result = curl_exec($ch);
    curl_close($ch);

    And get following error:

    {"name":"AUTHENTICATION_FAILURE","message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.","links":[{"href":"https://developer.paypal.com/docs/api/overview/#error","rel":"information_link"}]}

    Please help me to resolve this issue.
    Thanks in advance.