paypal / PayPal-PHP-SDK

PHP SDK for PayPal RESTful APIs
https://developer.paypal.com/docs/api/
Other
27 stars 100 forks source link

Cannot void an authorization #98

Closed wathek closed 10 years ago

wathek commented 10 years ago

I'm having a problem with void function. I've created an authorization and then I captured less than 100% of the amount and now I want to void the remaining funds, so I call the void function like in below :

    $apiContext = $this->getApiContext();
    $authorization = Authorization::get($id, $apiContext);
    try {
           $void = $authorization->void($apiContext);
    } catch (Exception $e) {
            print_r($e->getMessage());
            print_r($e->getData());
    }

The $id var contains the authId and I'm getting this return : Got Http response code 400 when accessing https://api.paypal.com/v1/payments/authorization/*********/void.{"name":"AUTHORIZATION_CANNOT_BE_VOIDED","message":"Authorization is in captured state and hence cannot be voided.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#AUTHORIZATION_CANNOT_BE_VOIDED","debug_id":"***"}

I cannot figure out what's wrong. I've checked the documentation at this link https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/authcapture/

And as described in the Lower Capture Amount :

  1. Your buyer orders a laser printer and a USB cable from your website.
  2. Your buyer enters payment information and authorizes payment.
  3. Send your buyer to PayPal using a hosted flow, specifying the variable paymentaction=authorization.
  4. PayPal initiates the authorization.
  5. Before you process the transaction, your buyer contacts you and requests to cancel the USB cable from the order.
  6. On day 6, you ship the laser printer and complete a partial capture for an amount less than the original authorization amount.
  7. You complete a void on the funds remaining on the authorization.

Any suggestion please ? Thank you

avidas commented 10 years ago

Hey @wathek , when you capture funds using https://developer.paypal.com/webapps/developer/docs/api/#capture-an-authorization, if you want to do a partial capture, you can set "is_final_capture":true to indicate that the remaining funds held by the authorization will be released in the funding instrument. Also it might be helpful to post the debug_id here.

wathek commented 10 years ago

Hey @avidas thank you for your response I've set the is_final_capture to true here's my code :

public function captureAuthorize($id, $amnt, $final = true) {
    $apiContext = $this->getApiContext();

    $amount = new Amount();
    $amount->setCurrency("EUR");
    $amount->setTotal($amnt);

    $captur = new Capture();
    $captur->setId($id);
    $captur->setAmount($amount);
    $captur->setIsFinalCapture($final);

    try {
        $authorization = Authorization::get($id, $apiContext);
        $capt = $authorization->capture($captur, $apiContext);
    } catch (Exception $ex) {
        echo "Exception: " . $ex->getMessage() . PHP_EOL;
        var_dump($ex->getData());
        exit(1);
    }

    return ($capt->toArray());
}

and I'm calling the function with the param final set to true.

avidas commented 10 years ago

Does that still give you an exception? Otherwise, if you fetch that authorization later, (the one you captured setting is_final to true) does the state say partially captured or captured. Again, if you get a debug_id, it would be really helpful here. Thanks.

wathek commented 10 years ago

here's the debugid 2118c85c856cc and the state says that it's captured.

The captureAuthorize function works well it doesn't give me any exception. Thanks a lot

avidas commented 10 years ago

If the state says captured, you should not need to void it yourself. The remaining funds on that prior authorization would get released automatically.

wathek commented 10 years ago

ok great this means that the isFinalCapture works ?

avidas commented 10 years ago

Ya that is expected behavior

wathek commented 10 years ago

ok great thank you so much @avidas