thephpleague / omnipay-paypal

PayPal driver for the Omnipay PHP payment processing library
MIT License
295 stars 174 forks source link

How to obtain Transaction ID of successful payment #249

Open HaikuOezu opened 3 years ago

HaikuOezu commented 3 years ago

I'm terribly sorry for asking here as this is not exactly a bug but I've searched far and wide and I just cannot find the answer to a simple question and it's driving me crazy.

I'm using omnipay-paypal to take payments, it's a very simple flow that uses the PayPal_Rest gateway to call purchase() and then completePurchase().

$response = $gateway->purchase([
      'returnUrl' => route('payment-received'),
      'cancelUrl' => route('profile'),
      'currency' => 'EUR',
      'amount' => $price,
      'description' => $description
    ])->send();
$response = $gateway->completePurchase([
      'transactionReference' => $request->paymentId,
      'PayerID' => $request->PayerID
    ])->send();

    if ($response->isSuccessful()) {
      if ($response->isRedirect()) {
        $response->redirect(); // this will automatically forward the customer
      }
      // Do stuff (save the order on DB etc)
    }

It works - the payment is processed and confirmed. However, in order to cross reference payments with our PayPal account I'd like to store the PayPal Transaction ID (the one you see on paypal.com) and I cannot for the life of me understand how.

All I get is the Payment ID which looks something like PAYID-XXXXXXXXX, I would like the 16 digit reference instead. How would I achieve that considering the payment has gone through? Is that even possible with the PayPal REST API?

iamjohnseun commented 2 years ago

I am also experiencing the same issue $response->isSuccessful() always returns false and there is no way to link a transaction to the data saved on paypal for the captured transaction for local database storage purposes.

dseeger commented 2 years ago

It is possible to get the transaction reference.

if ($response->isSuccessful()) {
    $reference = $response->getTransactionReference();

That reference is not the same as the one displayed on paypal.com but the payment can still be found with it if you enter it in the search field.

EDIT: Fixed the below mentioned typo

HaikuOezu commented 2 years ago

@dseeger I'm getting Call to undefined method Omnipay\PayPal\Message\RestResponse::getTransactionRefernce() when I try that

EDIT: Didn't notice the typo in your code lol, this actually works well enough for me - thank you!

judgej commented 2 years ago

getTransactionReference() - is that the spelling you used?

HaikuOezu commented 2 years ago

@judgej yeah I copy pasted the original comment which had a spelling mistake on "Reference" lol. Once I fixed that it worked just fine