/**
  * Called after the Transaction is stored.
  * Tells the storage service to store all the information held in the ShippingHandler
  * @param \Heystack\Core\Storage\Event $event
  * @param string $eventName
  * @param \Heystack\Core\EventDispatcher $dispatcher
  * @return void
  */
 public function onTransactionStored(StorageEvent $event, $eventName, EventDispatcher $dispatcher)
 {
     $this->shippingService->setParentReference($event->getParentReference());
     $this->storageService->process($this->shippingService);
     $this->eventService->dispatch(Events::STORED);
     $this->stateService->removeByKey(ShippingHandler::IDENTIFIER);
 }
 /**
  * @covers \Heystack\Core\Storage\Storage::process
  * @depends testObjectCanBeConstructedWithNoArguments
  */
 public function testCanProcessStorableInterface(Storage $s)
 {
     $storable = $this->getMock('Heystack\\Core\\Storage\\StorableInterface');
     $storable->expects($this->once())->method('getStorableBackendIdentifiers')->will($this->returnValue([self::MOCK_IDENTIFIER]));
     $mockBackend = $this->getMock('Heystack\\Core\\Storage\\BackendInterface');
     $mockBackend->expects($this->any())->method('getIdentifier')->will($this->returnValue(new Identifier(self::MOCK_IDENTIFIER)));
     $mockBackend->expects($this->once())->method('write')->with($storable)->will($this->returnValue($do = $this->getMock('DataObject')));
     $s->addBackend($mockBackend);
     $results = $s->process($storable);
     $this->assertTrue(isset($results[self::MOCK_IDENTIFIER]));
     $this->assertEquals($do, $results[self::MOCK_IDENTIFIER]);
 }
 /**
  * @param  \SS_HTTPRequest $request
  * @return array
  */
 public function process(\SS_HTTPRequest $request)
 {
     $httpMethod = $request->httpMethod();
     if ($httpMethod == 'POST' && $request->param('ID') == 'complete') {
         //get the payment dps txnref from the database
         //1. Get session id for transaction from state
         //2. Get payment from storage
         //3. Use txn ref from storage to complete the payment
         $sessionId = $this->state->getByKey(self::IDENTIFIER . '.sessionid');
         if ($sessionId) {
             // get the PXFusion payment associated with this sessionid
             $payment = \DataList::create('StoredPXFusionPayment')->filter("SessionId", $sessionId)->first();
             if ($payment instanceof \StoredPXFusionPayment && $payment->DpsTxnRef) {
                 // Set the transaction status to processing
                 $this->transaction->setStatus('Processing');
                 // Keep track of the payment status
                 $paymentSuccessful = false;
                 $storedPxPostPayment = false;
                 $paymentResponse = $this->paymentService->completeTransaction($payment->DpsTxnRef);
                 if ($paymentResponse instanceof PXPostPaymentResponse) {
                     // Store the payment response
                     $storedPxPostPayment = $this->storage->process($paymentResponse)[Backend::IDENTIFIER];
                     $paymentResponse->updateTransaction($this->transaction);
                     $paymentSuccessful = (bool) $paymentResponse->Success;
                 }
                 // store the transaction
                 $storedTransaction = $this->storage->process($this->transaction)[Backend::IDENTIFIER];
                 $payment->ParentID = $storedTransaction->ID;
                 if ($storedPxPostPayment && $storedTransaction) {
                     // set the parents of each object
                     $payment->PXPostPaymentID = $storedPxPostPayment->ID;
                     $payment->write();
                     $storedPxPostPayment->ParentID = $storedTransaction->ID;
                     $storedPxPostPayment->write();
                 } else {
                     $payment->write();
                     return ['Success' => false];
                 }
                 return ['Success' => $paymentSuccessful, 'Complete' => true, 'Data' => $paymentResponse];
             }
         }
     } elseif ($httpMethod == 'GET' && $request->param('ID') == 'check') {
         $paymentResponse = $this->paymentService->checkTransaction($request->getVar('sessionid'));
         $this->state->setByKey(self::IDENTIFIER . '.sessionid', $request->getVar('sessionid'));
         $this->storage->process($paymentResponse);
         if ($paymentResponse->StatusCode === 0) {
             return ['Success' => true, 'Data' => $paymentResponse];
         } else {
             return ['Success' => false, 'CheckFailure' => true];
         }
     }
     return ['Success' => false];
 }
 /**
  * After the transaction is stored, store the deal.
  * @param \Heystack\Core\Storage\Event $event
  * @param string $eventName
  * @param \Heystack\Core\EventDispatcher $dispatcher
  * @return void
  */
 public function onTransactionStored(StorageEvent $event, $eventName, EventDispatcher $dispatcher)
 {
     if ($this->dealHandler->getConditionsMetCount() > 0) {
         $this->dealHandler->setParentReference($event->getParentReference());
         $results = $this->storageService->process($this->dealHandler);
         // Store the Coupons associated with the deal
         if (!empty($results[Backend::IDENTIFIER])) {
             $storedDeal = $results[Backend::IDENTIFIER];
             $coupons = $this->couponHolder->getCoupons($this->dealHandler->getIdentifier());
             foreach ($coupons as $coupon) {
                 if ($coupon instanceof CouponInterface) {
                     $coupon->setParentReference($storedDeal->ID);
                     $this->storageService->process($coupon);
                 }
             }
         }
         $this->eventService->dispatch(Events::STORED);
         $this->stateService->removeByKey($this->dealHandler->getIdentifier()->getFull());
     }
 }
 /**
  * Method that facilitates storing the Transaction
  * @return void
  */
 public function onStore()
 {
     $this->storageService->process($this->transaction);
 }