コード例 #1
0
 /**
  * @param $data
  * @return $this
  */
 protected function setData($data)
 {
     $this->setStatuses($data);
     $this->transactionId = Helper::dataGet($data, 'transactionId', null);
     $this->acsUrl = Helper::dataGet($data, 'acsUrl', null);
     $this->paReq = Helper::dataGet($data, 'paReq', null);
     return $this;
 }
コード例 #2
0
ファイル: Void.php プロジェクト: academe/SagePay-Integration
 /**
  * @param array|object $data The parsed data returned by Sage Pay.
  * @return $this
  */
 protected function setData($data)
 {
     if ($date = Helper::dataGet($data, 'date')) {
         $this->date = Helper::parseDateTime($date);
     }
     $this->instructionType = Helper::dataGet($data, 'instructionType');
     return $this;
 }
コード例 #3
0
 /**
  * @param $data
  * @return $this
  */
 protected function setData($data)
 {
     $this->merchantSessionKey = Helper::dataGet($data, 'merchantSessionKey');
     $expiry = Helper::dataGet($data, 'expiry');
     if (isset($expiry)) {
         $this->expiry = Helper::parseDateTime($expiry);
     }
     return $this;
 }
コード例 #4
0
 /**
  * This can be set from either a direct response from Sage Pay, or fields
  * from the drop-in form (a server request).
  * TODO: other fields can be provided by the drop-in form, such as card-type.
  * CHECKME: is it worth merging this with Response\Model\Card, since both are
  * essentially card details returned from Sage Pay?
  *
  * @param array|object $data The parsed data returned by Sage Pay.
  * @return $this
  */
 protected function setData($data)
 {
     $this->cardIdentifier = Helper::dataGet($data, 'cardIdentifier', Helper::dataGet($data, 'card-identifier', null));
     if ($expiry = Helper::dataGet($data, 'expiry', null)) {
         $this->expiry = Helper::parseDateTime($expiry);
     }
     $this->cardType = Helper::dataGet($data, 'cardType', null);
     return $this;
 }
コード例 #5
0
 /**
  * Construct an instance from a PSR-7 response message.
  *
  * Here we can check for errors and return the appropriate error or error
  * collection object instead, avoiding the need for the factory every time?
  *
  * @param ResponseInterface $response
  * @returns static|ErrorCollection
  */
 public static function fromHttpResponse(ResponseInterface $response)
 {
     $httpCode = $response->getStatusCode();
     $data = static::parseBody($response);
     if ($httpCode >= Http::BAD_REQUEST || Helper::dataGet($data, 'errors')) {
         // 4xx and 5xx errors.
         // Return an error collection.
         return ErrorCollection::fromHttpResponse($response);
     }
     return static::fromData($data, $httpCode);
 }
コード例 #6
0
 /**
  * Return a response instance from response data.
  */
 public static function fromData($data, $httpCode = null)
 {
     // An error or error collection.
     if ($httpCode >= Http::BAD_REQUEST || Helper::dataGet($data, 'errors')) {
         // 4xx and 5xx errors.
         // Return an error collection.
         return Response\ErrorCollection::fromData($data, $httpCode);
     }
     // Session key.
     if (Helper::dataGet($data, 'merchantSessionKey') && Helper::dataGet($data, 'expiry')) {
         return Response\SessionKey::fromData($data, $httpCode);
     }
     // A card identifier.
     if (Helper::dataGet($data, 'cardIdentifier') || Helper::dataGet($data, 'card-identifier')) {
         return Response\CardIdentifier::fromData($data, $httpCode);
     }
     // A payment.
     if (Helper::dataGet($data, 'transactionId') && Helper::dataGet($data, 'transactionType') == AbstractRequest::TRANSACTION_TYPE_PAYMENT) {
         return Response\Payment::fromData($data, $httpCode);
     }
     // A repeat payment.
     if (Helper::dataGet($data, 'transactionId') && Helper::dataGet($data, 'transactionType') == AbstractRequest::TRANSACTION_TYPE_REPEAT) {
         return Response\Repeat::fromData($data, $httpCode);
     }
     // A refund payment.
     if (Helper::dataGet($data, 'transactionId') && Helper::dataGet($data, 'transactionType') == AbstractRequest::TRANSACTION_TYPE_REFUND) {
         return Response\Refund::fromData($data, $httpCode);
     }
     // 3D Secure response.
     // This is the simplest of all the messages - just a status and nothing else.
     // Make sure there is no transactionType field.
     $secure3dStatusList = Response\Secure3D::constantList('STATUS3D');
     $status = Helper::dataGet($data, 'status');
     if ($status && in_array($status, $secure3dStatusList) && !Helper::dataGet($data, 'transactionId')) {
         return Response\Secure3D::fromData($data, $httpCode);
     }
     // A 3D Secure redirect.
     // Like Secure3D, this one does not have a TransactionType, though shares many fields
     // with the abstract transaction response.
     if (Helper::dataGet($data, 'statusCode') == '2007' && Helper::dataGet($data, 'status') == AbstractTransaction::STATUS_3DAUTH) {
         return Response\Secure3DRedirect::fromData($data, $httpCode);
     }
     // A void instruction.
     if (Helper::dataGet($data, 'instructionType') == 'void') {
         return Response\Void::fromData($data, $httpCode);
     }
     // A 204 with an empty body is a quiet accpetance that what was send is successful.
     // e.g. returned when a CVV is linked to a card.
     if ($httpCode == 204 && empty($data)) {
         return Response\NoContent::fromData($data, $httpCode);
     }
 }
コード例 #7
0
 /**
  * Construct an instance from stored data (e.g. JSON serialised object).
  */
 public static function fromData($data)
 {
     // For convenience.
     if (is_string($data)) {
         $data = json_decode($data);
     }
     // The data will normally be in a "card" wrapper element.
     // Remove it to make processing easier.
     if ($card = Helper::dataGet($data, 'card')) {
         $data = $card;
     }
     return new static(Helper::dataGet($data, 'merchantSessionKey'), Helper::dataGet($data, 'cardIdentifier'));
 }
コード例 #8
0
ファイル: Card.php プロジェクト: academe/SagePay-Integration
 /**
  * Construct an instance from stored data (e.g. JSON serialised object).
  */
 public static function fromData($data)
 {
     // For convenience.
     if (is_string($data)) {
         $data = json_decode($data);
     }
     // The data will normally be in a "card" wrapper element.
     // Remove it to make processing easier.
     if ($card = Helper::dataGet($data, 'card')) {
         $data = $card;
     }
     return new static(Helper::dataGet($data, 'cardType'), Helper::dataGet($data, 'lastFourDigits'), Helper::dataGet($data, 'expiryDate'), Helper::dataGet($data, 'cardIdentifier'), Helper::dataGet($data, 'reusable'));
 }
コード例 #9
0
 /**
  * @inheritdoc
  */
 public static function isResponse($data)
 {
     return is_array(Helper::dataGet($data, 'errors')) || Helper::dataGet($data, 'status') == 'Error' || Helper::dataGet($data, 'status') == 'Invalid' || Helper::dataGet($data, 'card-identifier-error-code', '') != '';
 }
コード例 #10
0
 /**
  * @param $data
  * @return $this
  */
 protected function setData($data)
 {
     $this->status = Helper::dataGet($data, 'status', null);
     return $this;
 }
コード例 #11
0
 /**
  * Determine whether this message is active, i.e. has been sent to the application.
  * $data will be $request->getBody() for most implementations.
  *
  * @param array|object $data The ServerRequest body data.
  */
 public static function isRequest($data)
 {
     return !empty(Helper::dataGet($data, 'PaRes'));
 }
コード例 #12
0
 protected function setAmount($data)
 {
     // Optional "amount" and "currency", available only when fetching an
     // existing payment from Sage Pay.
     if (($currency = Helper::dataGet($data, 'currency')) != null) {
         $this->currency = new Currency($currency);
         // Only get the amounts if we have a currency to assign to them.
         if (($totalAmount = Helper::dataGet($data, 'amount.totalAmount')) !== null) {
             $this->totalAmount = new Amount($this->currency, $totalAmount);
         }
         if (($saleAmount = Helper::dataGet($data, 'amount.saleAmount')) !== null) {
             $this->saleAmount = new Amount($this->currency, $saleAmount);
         }
         if (($surchargeAmount = Helper::dataGet($data, 'amount.surchargeAmount')) !== null) {
             $this->surchargeAmount = new Amount($this->currency, $surchargeAmount);
         }
     }
 }
コード例 #13
0
 /**
  * Create a new instance from an array or object of values.
  *
  * @param array|object $data Address data using fields or elements for intialisation
  *
  * @return static New address object set up from the data
  */
 public static function fromData($data)
 {
     return new static(Helper::dataGet($data, 'address1', null), Helper::dataGet($data, 'address2', null), Helper::dataGet($data, 'city', null), Helper::dataGet($data, 'postalCode', null), Helper::dataGet($data, 'country', null), Helper::dataGet($data, 'state', null));
 }
コード例 #14
0
 /**
  * Parse the body of a PSR-7 message, into a PHP array.
  * TODO: if this message is a ServerRequestInterface, then the parsed body may already
  * be available through getParsedBody() - check that first. Maybe even move that check to
  * AbstractServerRequest and fall back to this (the parent) if not set.
  * @param $message MessageInterface
  * @return array|mixed
  */
 public static function parseBody(MessageInterface $message)
 {
     return Helper::parseBody($message);
 }