Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  *
  * @param Capture $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     $token = $request->getToken();
     if (isset($model['Status'])) {
         return;
     }
     $details = $this->api->prepareOffsiteDetails($model->toUnsafeArray());
     // filter model details for request
     $missing = $this->api->getMissingDetails($details);
     // sagepay's api is wayward we should check for presence of required minimum
     if (count($missing) > 0) {
         throw new LogicException(sprintf('Missing: %s details are mandatory for current payment request!', implode(", ", array_keys($missing))));
     }
     $model['state'] = StateInterface::STATE_WAITING;
     // we do not need any sync action
     // but payum by default do not set any afterUrl to notify token
     if ($token) {
         $model['afterUrl'] = $token->getAfterUrl();
     }
     $response = $this->api->createOffsitePurchase($details);
     $responseArr = $response->toArray();
     $model['state'] = $responseArr['Status'] == Api::STATUS_OK || $responseArr['Status'] == Api::STATUS_OK_REPEATED ? StateInterface::STATE_REPLIED : StateInterface::STATE_ERROR;
     $model->replace(array_merge((array) $model->toUnsafeArray(), (array) $response->toArray()));
     if ($responseArr['Status'] == Api::STATUS_OK || $responseArr['Status'] == Api::STATUS_OK_REPEATED) {
         throw new HttpRedirect($responseArr['NextURL'] . '=' . $responseArr['VPSTxId']);
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  *
  * @param Notify $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     // invalidate:
     // - we process only replied and notified payments
     if (!isset($model['state']) || !in_array($model['state'], array(StateInterface::STATE_REPLIED, StateInterface::STATE_NOTIFIED, StateInterface::STATE_CONFIRMED))) {
         // return;
     }
     $httpRequest = new GetHttpRequest();
     $this->gateway->execute($httpRequest);
     if ($httpRequest->method != 'POST') {
         return;
     }
     $status = Api::STATUS_OK;
     $model['state'] = StateInterface::STATE_NOTIFIED;
     $notification = $httpRequest->request;
     $redirectUrl = $model['afterUrl'];
     // check signature hash
     if ($this->api->tamperingDetected((array) $notification, (array) $model->toUnsafeArray())) {
         $status = Api::STATUS_INVALID;
         $statusDetails = "Tampering detected. Wrong hash.";
     } else {
         if ($notification['Status'] == Api::STATUS_OK) {
             $model['state'] = StateInterface::STATE_CONFIRMED;
         } elseif ($notification['Status'] == Api::STATUS_PENDING) {
             $model['state'] = StateInterface::STATE_REPLIED;
         } else {
             $model['state'] = StateInterface::STATE_ERROR;
         }
         $statusDetails = 'Transaction processed';
         if ($notification['Status'] == Api::STATUS_ERROR && isset($notification['Vendor']) && isset($notification['VendorTxCode']) && isset($notification['StatusDetail'])) {
             $status = Api::STATUS_ERROR;
             $statusDetails = 'Status of ERROR is seen, together with your Vendor, VendorTxCode and the StatusDetail.';
         }
     }
     $model['notification'] = (array) $notification;
     $model->replace($model->toUnsafeArray());
     $params = array('Status' => $status, 'StatusDetails' => $statusDetails, 'RedirectURL' => $redirectUrl);
     throw new NotifyResponse($params);
 }