isCallbackValid() public method

1. A customer payment or a refund triggers IPN. This payment can be via Website Payments Standard FORMs or via the PayPal Web Services APIs for Express Checkout, MassPay, or RefundTransaction. If the payment has a “Pending” status, you receive another IPN when the payment clears, fails, or is denied. 2. PayPal posts HTML FORM variables to a program at a URL you specify. You can specify this URL either in your Profile or with the notify_url variable on each transaction. This post is the heart of IPN. Included in the notification is the customer’s payment information (such as customer name, payment amount). All possible variables in IPN posts are detailed in . When your server receives a notification, it must process the incoming data. 3. Your server must then validate the notification to ensure that it is legitimate. {@inheritdoc}
public isCallbackValid ( Sonata\Component\Payment\TransactionInterface $transaction )
$transaction Sonata\Component\Payment\TransactionInterface
Example #1
0
 public function testIsCallbackValid()
 {
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $paypal = new Paypal($router, $translator);
     $order = $this->getMock('Sonata\\Component\\Order\\OrderInterface');
     $order->expects($this->any())->method('getCreatedAt')->will($this->returnValue(new \DateTime()));
     $order->expects($this->any())->method('isValidated')->will($this->returnValue(true));
     $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface');
     $transaction->expects($this->any())->method('getOrder')->will($this->returnValue($order));
     $this->assertFalse($paypal->isCallbackValid($transaction), "Paypal::isCallbackValid false because request invalid");
     $check = sha1($order->getReference() . $order->getCreatedAt()->format("m/d/Y:G:i:s") . $order->getId());
     $transaction->expects($this->any())->method('get')->will($this->returnValue($check));
     $this->assertFalse($paypal->isCallbackValid($transaction), "Paypal::isCallbackValid false because order not validated");
     $order = $this->getMock('Sonata\\Component\\Order\\OrderInterface');
     $order->expects($this->any())->method('getCreatedAt')->will($this->returnValue(new \DateTime()));
     $order->expects($this->any())->method('isValidated')->will($this->returnValue(false));
     $check = sha1($order->getReference() . $order->getCreatedAt()->format("m/d/Y:G:i:s") . $order->getId());
     $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface');
     $transaction->expects($this->any())->method('getOrder')->will($this->returnValue($order));
     $transaction->expects($this->any())->method('get')->will($this->returnValue($check));
     $this->assertFalse($paypal->isCallbackValid($transaction), "Paypal::isCallbackValid false because payment_status invalid.");
     $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface');
     $transaction->expects($this->any())->method('getOrder')->will($this->returnValue($order));
     $transaction->expects($this->any())->method('get')->will($this->returnCallback(function () use($check) {
         $asked = func_get_arg(0);
         switch ($asked) {
             case 'check':
                 return $check;
             case 'payment_status':
                 return "Pending";
         }
     }));
     $this->assertTrue($paypal->isCallbackValid($transaction), "Paypal::isCallbackValid true because payment_status pending.");
     $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface');
     $transaction->expects($this->any())->method('getOrder')->will($this->returnValue($order));
     $transaction->expects($this->any())->method('get')->will($this->returnCallback(function () use($check) {
         $asked = func_get_arg(0);
         switch ($asked) {
             case 'check':
                 return $check;
             case 'payment_status':
                 return "Completed";
         }
     }));
     $this->assertTrue($paypal->isCallbackValid($transaction), "Paypal::isCallbackValid true because payment_status completed.");
     $transaction = $this->getMock('Sonata\\Component\\Payment\\TransactionInterface');
     $transaction->expects($this->any())->method('getOrder')->will($this->returnValue($order));
     $transaction->expects($this->any())->method('get')->will($this->returnCallback(function () use($check) {
         $asked = func_get_arg(0);
         switch ($asked) {
             case 'check':
                 return $check;
             case 'payment_status':
                 return "Cancelled";
         }
     }));
     $this->assertTrue($paypal->isCallbackValid($transaction), "Paypal::isCallbackValid true because payment_status cancelled.");
 }