コード例 #1
0
 /**
  * @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];
 }
コード例 #2
0
 /**
  * Uses the State service to retrieve the active country's identifier and sets the active country.
  *
  * If the retrieved identifier is not an instance of the Identifier Interface, then it checks if it is a string,
  * which it uses to create a new Identifier object to set the active country.
  * @return void
  */
 public function restoreState()
 {
     if ($activeCountry = $this->sessionState->getByKey(self::ACTIVE_COUNTRY_KEY)) {
         $this->activeCountry = $activeCountry;
     }
 }