Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function buildResponse(stdClass $response)
 {
     if (!isset($response->payment)) {
         throw new Syspay_Merchant_UnexpectedResponseException('Unable to retrieve "payment" data from response', $response);
     }
     $payment = Syspay_Merchant_Entity_Payment::buildFromResponse($response->payment);
     return $payment;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function buildResponse(stdClass $response)
 {
     if (!isset($response->payments) || !is_array($response->payments)) {
         throw new Syspay_Merchant_UnexpectedResponseException('Unable to retrieve "payment" data from response', $response);
     }
     $payments = array();
     foreach ($response->payments as $p) {
         $payment = Syspay_Merchant_Entity_Payment::buildFromResponse($p);
         array_push($payments, $payment);
     }
     return $payments;
 }
Ejemplo n.º 3
0
 /**
  * Build a payment entity based on a json-decoded payment stdClass
  *
  * @param  stdClass $response The payment data
  * @return Syspay_Merchant_Entity_Payment The payment object
  */
 public static function buildFromResponse(stdClass $response)
 {
     $chargeback = new self();
     $chargeback->setId(isset($response->id) ? $response->id : null);
     $chargeback->setStatus(isset($response->status) ? $response->status : null);
     $chargeback->setAmount(isset($response->amount) ? $response->amount : null);
     $chargeback->setCurrency(isset($response->currency) ? $response->currency : null);
     $chargeback->setReasonCode(isset($response->reason_code) ? $response->reason_code : null);
     if (isset($response->processing_time) && !is_null($response->processing_time)) {
         $chargeback->setProcessingTime(Syspay_Merchant_Utils::tsToDateTime($response->processing_time));
     }
     if (isset($response->payment)) {
         $chargeback->setPayment(Syspay_Merchant_Entity_Payment::buildFromResponse($response->payment));
     }
     return $chargeback;
 }
Ejemplo n.º 4
0
 /**
  * Return the entity linked to the EMS call received
  * @return mixed One of the Syspay_Merchant_Entity classes depending on the event received
  * @throws Syspay_Merchant_EMSException If something went wrong while parsing the request
  */
 public function getEvent()
 {
     if (!$this->skipAuthCheck) {
         $this->checkChecksum();
     }
     $content = $this->getContent();
     if (!isset($content->type)) {
         throw new Syspay_Merchant_EMSException('Unable to get event type', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT);
     }
     if (!isset($content->data)) {
         throw new Syspay_Merchant_EMSException('Unable to get data from content', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT);
     }
     switch ($content->type) {
         case 'payment':
             if (!isset($content->data->payment)) {
                 throw new Syspay_Merchant_EMSException('Payment event received with no payment data', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT);
             }
             return Syspay_Merchant_Entity_Payment::buildFromResponse($content->data->payment);
             break;
         case 'refund':
             if (!isset($content->data->refund)) {
                 throw new Syspay_Merchant_EMSException('Refund event received with no refund data', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT);
             }
             return Syspay_Merchant_Entity_Refund::buildFromResponse($content->data->refund);
             break;
         case 'chargeback':
             if (!isset($content->data->chargeback)) {
                 throw new Syspay_Merchant_EMSException('Chargeback event received with no chargeback data', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT);
             }
             return Syspay_Merchant_Entity_Chargeback::buildFromResponse($content->data->chargeback);
             break;
         case 'billing_agreement':
             if (!isset($content->data->billing_agreement)) {
                 throw new Syspay_Merchant_EMSException('Billing agreement event received with no billing_agreement data', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT);
             }
             return Syspay_Merchant_Entity_BillingAgreement::buildFromResponse($content->data->billing_agreement);
             break;
         case 'subscription':
             if (!isset($content->data->subscription)) {
                 throw new Syspay_Merchant_EMSException('Subscription event received with no subscription data', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT);
             }
             return Syspay_Merchant_Entity_Subscription::buildFromResponse($content->data->subscription);
         default:
             throw new Syspay_Merchant_EMSException('Unknown type: ' . $content->type, Syspay_Merchant_EMSException::CODE_INVALID_CONTENT);
     }
 }
Ejemplo n.º 5
0
 /**
  * Build a payment entity based on a json-decoded payment stdClass
  *
  * @param  stdClass $response The payment data
  * @return Syspay_Merchant_Entity_Payment The payment object
  */
 public static function buildFromResponse(stdClass $response)
 {
     $refund = new self();
     $refund->setId(isset($response->id) ? $response->id : null);
     $refund->setReference(isset($response->reference) ? $response->reference : null);
     $refund->setAmount(isset($response->amount) ? $response->amount : null);
     $refund->setCurrency(isset($response->currency) ? $response->currency : null);
     $refund->setStatus(isset($response->status) ? $response->status : null);
     $refund->setExtra(isset($response->extra) ? $response->extra : null);
     $refund->setDescription(isset($response->description) ? $response->description : null);
     if (isset($response->processing_time) && !is_null($response->processing_time)) {
         $refund->setProcessingTime(Syspay_Merchant_Utils::tsToDateTime($response->processing_time));
     }
     if (isset($response->payment)) {
         $refund->setPayment(Syspay_Merchant_Entity_Payment::buildFromResponse($response->payment));
     }
     return $refund;
 }
Ejemplo n.º 6
0
 /**
  * Return the payment decoded from the redirection parameters
  * @param  array $source An array that contains a 'result', 'merchant', and 'checksum' parameters.
  *                       Typically this can be $_GET or $_REQUEST.
  * @return Syspay_Merchant_Entity_Payment The decoded payment
  * @throws Syspay_Merchant_RedirectException If something went wrong while parsing the request
  */
 public function getResult(array $source)
 {
     $result = isset($source['result']) ? $source['result'] : null;
     $merchant = isset($source['merchant']) ? $source['merchant'] : null;
     $checksum = isset($source['checksum']) ? $source['checksum'] : null;
     if (!$this->skipAuthCheck) {
         $this->checkChecksum($result, $merchant, $checksum);
     }
     $result = base64_decode($result);
     if ($result === false) {
         throw new Syspay_Merchant_RedirectException('Unable to decode the result parameter', Syspay_Merchant_RedirectException::CODE_INVALID_CONTENT);
     }
     $result = json_decode($result);
     if ($result === null || empty($result->payment)) {
         throw new Syspay_Merchant_RedirectException('Unable to decode the result parameter', Syspay_Merchant_RedirectException::CODE_INVALID_CONTENT);
     }
     return Syspay_Merchant_Entity_Payment::buildFromResponse($result->payment);
 }