/**
  * {@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;
 }
示例#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;
 }
示例#3
0
 /**
  * {@inheritDoc}
  */
 public function getData()
 {
     $data = array();
     $data['flow'] = $this->flow;
     if (false === empty($this->billingAgreement)) {
         $data['billing_agreement'] = $this->billingAgreement ? 1 : 0;
     }
     if (false === empty($this->mode)) {
         $data['mode'] = $this->mode;
     }
     if (false == empty($this->threatMetrixSessionId)) {
         $data['threatmetrix_session_id'] = $this->threatMetrixSessionId;
     }
     if (false === empty($this->paymentMethod)) {
         $data['method'] = $this->paymentMethod;
     }
     if (false === empty($this->website)) {
         $data['website'] = intval($this->website);
     }
     if (false === empty($this->agent)) {
         $data['agent'] = intval($this->agent);
     }
     if (false === empty($this->redirectUrl)) {
         $data['redirect_url'] = $this->redirectUrl;
     }
     if (false === empty($this->emsUrl)) {
         $data['ems_url'] = $this->emsUrl;
     }
     if (false === empty($this->creditcard)) {
         $data['creditcard'] = $this->creditcard->toArray();
     }
     if (false === empty($this->customer)) {
         $data['customer'] = (array) $this->customer->toArray();
     }
     if (false === empty($this->payment)) {
         $data['payment'] = (array) $this->payment->toArray();
     }
     if (false === empty($this->allowedRetries)) {
         $data['allowed_retries'] = intval($this->allowedRetries);
     }
     if (false === empty($this->notify)) {
         $data['notify'] = $this->notify;
     }
     if (false === empty($this->bankCode)) {
         $data['bank_code'] = $this->bankCode;
     }
     return $data;
 }
示例#4
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;
 }
示例#5
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);
     }
 }
示例#6
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;
 }
示例#7
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);
 }
示例#8
0
 $payment_request->setMode(Syspay_Merchant_PaymentRequest::MODE_ONLINE);
 $website = SyspayTools::getWebsite(true, false);
 if (Configuration::get('SYSPAY_WEBSITE_ID')) {
     $payment_request->setWebsite((int) Configuration::get('SYSPAY_WEBSITE_ID'));
 }
 $payment_request->setEmsUrl($website . _MODULE_DIR_ . 'syspay/ems.php');
 $payment_request->setRedirectUrl($website . _MODULE_DIR_ . 'syspay/confirmation.php');
 if (Configuration::get('SYSPAY_REBILL') == 1 && Tools::getValue('SP_REBILL') == 'on') {
     $type_of_payment = $payment_type[2];
     $payment_request->setBillingAgreement(true);
 }
 $customer = new Syspay_Merchant_Entity_Customer();
 $customer->setEmail(Tools::getValue('email'));
 $customer->setLanguage(Tools::strtolower(Tools::getValue('language')));
 $payment_request->setCustomer($customer);
 $payment = new Syspay_Merchant_Entity_Payment();
 $payment->setReference(Tools::getValue('order_ref'));
 if (Configuration::get('SYSPAY_AUTHORIZED_PAYMENT') == 1 && (Configuration::get('SYSPAY_REBILL') == 0 || Configuration::get('SYSPAY_REBILL') == 1 && Tools::getValue('SP_REBILL') != 'on')) {
     $type_of_payment = $payment_type[1];
     $payment->setPreauth(true);
 }
 $payment->setAmount(Tools::getValue('amount') * 100);
 $payment->setCurrency(Tools::getValue('currency'));
 $payment->setDescription(Tools::getValue('extra'));
 $payment->setExtra(Tools::jsonEncode(Tools::getValue('extra')));
 $payment_request->setPayment($payment);
 $sql = 'SELECT redirect_url FROM ' . _DB_PREFIX_ . 'syspay_payment WHERE order_ref = "' . Tools::getValue('order_ref') . '"';
 $result = Db::getInstance()->getRow($sql);
 if ($result) {
     Tools::redirect($result['redirect_url']);
     return;