0

I'm trying to send payments to paypal from my laravel app via Omnipay. This works fine, I'm getting a response, getData() shows Success and stuff but...

How do I know, which payment I received?

Let's say I pay 1 Euro for Order No. 100 - How do I assign the Order No. 100 to the payment ?

I have three methods:

postOrder() which has:

                $paypal_setitems = [];
                foreach(Cart::contents() as $item) {
                    $paypal_setitems[] = array('name' => $item->name, 'quantity' => $item->quantity, 'price' => ($item->price * (1 + 19.00 / 100.0) ));
                }
                # Send response to PP
                $response = $gateway->purchase($this->getApiInfos($order->id))->setItems($paypal_setitems)->send();

                return $response->redirect();  

getSuccessPayment() which has:

    public function getSuccessPayment() {
    $gatewayFactory = new \Omnipay\Common\GatewayFactory;
    $gateway = $gatewayFactory->create('PayPal_Express');
    #Test API Sandbox
    $gateway->setUsername('buy-facilitator_api1.xxxxxx.de');
    $gateway->setPassword('xxxxx');
    $gateway->setSignature('xxxxx.xxxxx.xxxx.xxxxx');
    $gateway->setTestMode(true);

    $response = $gateway->completePurchase($this->getApiInfos())->send();
    $data = $response->getData(); // this is the raw response object

    if($data['ACK'] == 'Success'):
        echo '<pre>';
        print_r($data);
        //return Redirect::to('order/success')->with('order', $this->order);
    endif;
}  

and getApiInfos() with:

public function getApiInfos($order = NULL) {
  return array(
    'amount'=> Cart::total(),
    'cancelUrl' => \URL::route('paypal_cancel_order'),
    'returnUrl' => \URL::route('paypal_return'),
    'description' => 'Your Payment at - Order #',
    'currency' => 'EUR',
    'order' => $order
  );
}  

I tried to assign 'order' => $order to the array but this doesn't work.

Any Ideas?
I just need to save a successful payment (and the transactionId and other stuff) to the order but I don't know how.

Marek123
  • 1,193
  • 7
  • 35
  • 75
  • Side notes here. I've had a lot of people integrating PayPal contact me when using the OmniPay library with issues. I give them [this one instead](https://github.com/angelleye/paypal-php-library), and they generally get a long a lot better with it. One example of why is where you're checking ACK == SUCCESS. You'll run into problems with this because some transactions could be SUCCESSWITHWARNING, in which case the money was moved, but your app would treat it as a failure. My library handles that sort of thing for you so you don't have to worry about it. Just one example.Maybe take a look. – Drew Angell Oct 18 '14 at 05:07
  • I will but right now I have no time to change the package. Maybe in a future release. – Marek123 Oct 19 '14 at 13:18
  • Definitely want to make sure you adjust that line checking the ACK value. That can cause big headaches if you overlook it. – Drew Angell Oct 19 '14 at 14:40
  • any suggestions what I can check there to be safe? – Marek123 Oct 19 '14 at 15:01
  • You just need to add SUCCESSWITHWARNING. Right now you're only checking for SUCCESS, so SUCCESSWITHWARNING would be treated as a failure when it's not. – Drew Angell Oct 19 '14 at 20:57
  • Do not ignore ACK value and SUCCESSWITHWARNING... I did and it really blew up in my face later. – Mihai P. Oct 29 '14 at 00:05

0 Answers0