/**
  * Build an event entity based on a json-decoded event stdClass
  *
  * @param  stdClass $response The subscription event
  * @return Syspay_Merchant_Entity_SubscriptionEvent The event object
  */
 public static function buildFromResponse(stdClass $response)
 {
     $event = new self();
     $event->setScheduledDate(isset($response->scheduled_date) ? Syspay_Merchant_Utils::tsToDateTime($response->scheduled_date) : null);
     $event->setEventType(isset($response->event_type) ? $response->event_type : null);
     $event->raw = $response;
     return $event;
 }
Example #2
0
 /**
  * Validate the request's checksum
  * @throws Syspay_Merchant_RedirectException If the checksum didn't validate
  */
 private function checkChecksum($result, $merchant, $checksum)
 {
     if (empty($merchant) || empty($checksum) || empty($result)) {
         throw new Syspay_Merchant_RedirectException('Missing parameter', Syspay_Merchant_RedirectException::CODE_MISSING_PARAM);
     }
     if (empty($this->secrets[$merchant])) {
         throw new Syspay_Merchant_RedirectException('Unknown merchant: ' . $merchant, Syspay_Merchant_RedirectException::CODE_UNKNOWN_MERCHANT);
     }
     if (!Syspay_Merchant_Utils::checkChecksum($result, $this->secrets[$merchant], $checksum)) {
         throw new Syspay_Merchant_RedirectException('Invalid checksum', Syspay_Merchant_RedirectException::CODE_INVALID_CHECKSUM);
     }
 }
Example #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;
 }
Example #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)
 {
     $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;
 }
Example #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)
 {
     $payment = new self();
     $payment->setId(isset($response->id) ? $response->id : null);
     $payment->setReference(isset($response->reference) ? $response->reference : null);
     $payment->setAmount(isset($response->amount) ? $response->amount : null);
     $payment->setCurrency(isset($response->currency) ? $response->currency : null);
     $payment->setStatus(isset($response->status) ? $response->status : null);
     $payment->setExtra(isset($response->extra) ? $response->extra : null);
     $payment->setDescription(isset($response->description) ? $response->description : null);
     $payment->setWebsite(isset($response->website) ? $response->website : null);
     $payment->setFailureCategory(isset($response->failure_category) ? $response->failure_category : null);
     $payment->setChipAndPinStatus(isset($response->chip_and_pin_status) ? $response->chip_and_pin_status : null);
     $payment->setPaymentType(isset($response->payment_type) ? $response->payment_type : null);
     $payment->setWebsiteUrl(isset($response->website_url) ? $response->website_url : null);
     $payment->setContract(isset($response->contract) ? $response->contract : null);
     $payment->setDescriptor(isset($response->descriptor) ? $response->descriptor : null);
     $payment->setAccountId(isset($response->account_id) ? $response->account_id : null);
     $payment->setMerchantLogin(isset($response->merchant_login) ? $response->merchant_login : null);
     $payment->setMerchantId(isset($response->merchant_id) ? $response->merchant_id : null);
     if (isset($response->settlement_date) && !is_null($response->settlement_date)) {
         $payment->setSettlementDate(Syspay_Merchant_Utils::tsToDateTime($response->settlement_date));
     }
     if (isset($response->processing_time) && !is_null($response->processing_time)) {
         $payment->setProcessingTime(Syspay_Merchant_Utils::tsToDateTime($response->processing_time));
     }
     if (isset($response->billing_agreement) && $response->billing_agreement instanceof stdClass) {
         $billingAgreement = Syspay_Merchant_Entity_BillingAgreement::buildFromResponse($response->billing_agreement);
         $payment->setBillingAgreement($billingAgreement);
     }
     if (isset($response->subscription) && $response->subscription instanceof stdClass) {
         $subscription = Syspay_Merchant_Entity_Subscription::buildFromResponse($response->subscription);
         $payment->setSubscription($subscription);
     }
     if (isset($response->payment_method) && $response->payment_method instanceof stdClass) {
         $paymentMethod = Syspay_Merchant_Entity_PaymentMethod::buildFromResponse($response->payment_method);
         $payment->setPaymentMethod($paymentMethod);
     }
     $payment->raw = $response;
     return $payment;
 }
Example #6
0
 /**
  * Build a billing agreement entity based on a json-decoded billing agreement stdClass
  *
  * @param  stdClass $response The billing agreement data
  * @return Syspay_Merchant_Entity_BillingAgreement The billing agreement object
  */
 public static function buildFromResponse(stdClass $response)
 {
     $billingAgreement = new self();
     $billingAgreement->setId(isset($response->id) ? $response->id : null);
     $billingAgreement->setStatus(isset($response->status) ? $response->status : null);
     $billingAgreement->setCurrency(isset($response->currency) ? $response->currency : null);
     $billingAgreement->setExtra(isset($response->extra) ? $response->extra : null);
     $billingAgreement->setEndReason(isset($response->end_reason) ? $response->end_reason : null);
     if (isset($response->expiration_date) && !is_null($response->expiration_date)) {
         $billingAgreement->setExpirationDate(Syspay_Merchant_Utils::tsToDateTime($response->expiration_date));
     }
     if (isset($response->payment_method) && $response->payment_method instanceof stdClass) {
         $paymentMethod = Syspay_Merchant_Entity_PaymentMethod::buildFromResponse($response->payment_method);
         $billingAgreement->setPaymentMethod($paymentMethod);
     }
     if (isset($response->customer) && $response->customer instanceof stdClass) {
         $customer = Syspay_Merchant_Entity_Customer::buildFromResponse($response->customer);
         $billingAgreement->setCustomer($customer);
     }
     return $billingAgreement;
 }
Example #7
0
 /**
  * Build a subscription entity based on a json-decoded subscription stdClass
  *
  * @param  stdClass $response The subscription data
  * @return Syspay_Merchant_Entity_Subscription The subscription object
  */
 public static function buildFromResponse(stdClass $response)
 {
     $subscription = new self();
     $subscription->setId(isset($response->id) ? $response->id : null);
     $subscription->setPlanId(isset($response->plan_id) ? $response->plan_id : null);
     $subscription->setPlanType(isset($response->plan_type) ? $response->plan_type : null);
     $subscription->setReference(isset($response->reference) ? $response->reference : null);
     $subscription->setStatus(isset($response->status) ? $response->status : null);
     $subscription->setPhase(isset($response->phase) ? $response->phase : null);
     $subscription->setExtra(isset($response->extra) ? $response->extra : null);
     $subscription->setEmsUrl(isset($response->ems_url) ? $response->ems_url : null);
     $subscription->setWebsiteId(isset($response->website_id) ? $response->website_id : null);
     $subscription->setCreated(isset($response->created) ? Syspay_Merchant_Utils::tsToDateTime($response->created) : null);
     $subscription->setStartDate(isset($response->start_date) ? Syspay_Merchant_Utils::tsToDateTime($response->start_date) : null);
     $subscription->setEndDate(isset($response->end_date) ? Syspay_Merchant_Utils::tsToDateTime($response->end_date) : null);
     $subscription->setEndReason(isset($response->end_reason) ? $response->end_reason : null);
     if (isset($response->payment_method) && $response->payment_method instanceof stdClass) {
         $paymentMethod = Syspay_Merchant_Entity_PaymentMethod::buildFromResponse($response->payment_method);
         $subscription->setPaymentMethod($paymentMethod);
     }
     if (isset($response->customer) && $response->customer instanceof stdClass) {
         $customer = Syspay_Merchant_Entity_Customer::buildFromResponse($response->customer);
         $subscription->setCustomer($customer);
     }
     if (isset($response->plan) && $response->plan instanceof stdClass) {
         $plan = Syspay_Merchant_Entity_Plan::buildFromResponse($response->plan);
         $subscription->setPlan($plan);
     }
     if (isset($response->next_event) && $response->next_event instanceof stdClass) {
         $nextEvent = Syspay_Merchant_Entity_SubscriptionEvent::buildFromResponse($response->next_event);
         $subscription->setNextEvent($nextEvent);
     }
     $subscription->raw = $response;
     return $subscription;
 }
Example #8
0
    if ($status == 'OPEN') {
        $sql = 'INSERT INTO ' . _DB_PREFIX_ . 'syspay_payment VALUES(' . (int) $payment->getId() . ', ' . $payment->getDescription() . ', 
				"' . Tools::getValue('order_ref') . '", "' . $payment->getRedirect() . '", "' . $type_of_payment . '")';
        Db::getInstance()->Execute($sql);
        if (version_compare(_PS_VERSION_, '1.5', '>=')) {
            Tools::redirect($payment->getRedirect());
        } else {
            Tools::redirectLink($payment->getRedirect());
        }
        return;
    } elseif ($status == 'SUCCESS') {
        $sql = 'INSERT INTO ' . _DB_PREFIX_ . 'syspay_payment VALUES(' . (int) $payment->getId() . ', ' . $payment->getDescription() . ', 
				"' . Tools::getValue('order_ref') . '", "' . $payment->getRedirect() . '", "' . $type_of_payment . '")';
        Db::getInstance()->Execute($sql);
        $params = array('result' => base64_encode(Tools::jsonEncode($client->getData())), 'merchant' => $client->getUsername());
        $params['checksum'] = Syspay_Merchant_Utils::getChecksum($params['result'], $client->getSecret());
        $website = SyspayTools::getWebsite(true, false);
        $redirect = sprintf($website . _MODULE_DIR_ . 'syspay/confirmation.php?%s', http_build_query($params));
        if (version_compare(_PS_VERSION_, '1.5', '>=')) {
            Tools::redirect($redirect);
        } else {
            Tools::redirectLink($redirect);
        }
        return;
    } else {
        $website = SyspayTools::getWebsite(true, false);
        if (version_compare(_PS_VERSION_, '1.5', '>=')) {
            Tools::redirect('/index.php?controller=order&step=3&err=1');
        } else {
            Tools::redirectLink($website . '/order.php?step=3&err=1');
        }
Example #9
0
 /**
  * Build a plan entity based on a json-decoded plan stdClass
  *
  * @param  stdClass $response The plan data
  * @return Syspay_Merchant_Entity_Plan The plan object
  */
 public static function buildFromResponse(stdClass $response)
 {
     $plan = new self();
     $plan->setId(isset($response->id) ? $response->id : null);
     $plan->setStatus(isset($response->status) ? $response->status : null);
     $plan->setName(isset($response->name) ? $response->name : null);
     $plan->setDescription(isset($response->description) ? $response->description : null);
     $plan->setCurrency(isset($response->currency) ? $response->currency : null);
     $plan->setTrialAmount(isset($response->trial_amount) ? $response->trial_amount : null);
     $plan->setTrialPeriod(isset($response->trial_period) ? $response->trial_period : null);
     $plan->setTrialPeriodUnit(isset($response->trial_period_unit) ? $response->trial_period_unit : null);
     $plan->setTrialCycles(isset($response->trial_cycles) ? $response->trial_cycles : null);
     $plan->setBillingAmount(isset($response->billing_amount) ? $response->billing_amount : null);
     $plan->setBillingPeriod(isset($response->billing_period) ? $response->billing_period : null);
     $plan->setBillingPeriodUnit(isset($response->billing_period_unit) ? $response->billing_period_unit : null);
     $plan->setBillingCycles(isset($response->billing_cycles) ? $response->billing_cycles : null);
     $plan->setInitialAmount(isset($response->initial_amount) ? $response->initial_amount : null);
     $plan->setRetryMapId(isset($response->retry_map_id) ? $response->retry_map_id : null);
     $plan->setType(isset($response->type) ? $response->type : null);
     if (isset($response->created) && !is_null($response->created)) {
         $plan->setCreated(Syspay_Merchant_Utils::tsToDateTime($response->created));
     }
     return $plan;
 }
Example #10
0
 /**
  * Validate the header's checksum
  * @throws Syspay_Merchant_EMSException If the checksum didn't validate
  */
 private function checkChecksum()
 {
     if (empty($this->headers['x-merchant'])) {
         throw new Syspay_Merchant_EMSException('Missing x-merchant header', Syspay_Merchant_EMSException::CODE_MISSING_HEADER);
     }
     if (empty($this->headers['x-checksum'])) {
         throw new Syspay_Merchant_EMSException('Missing x-checksum header', Syspay_Merchant_EMSException::CODE_MISSING_HEADER);
     }
     if (!isset($this->secrets[$this->headers['x-merchant']])) {
         throw new Syspay_Merchant_EMSException('Unknown merchant: ' . $this->headers['x-merchant'], Syspay_Merchant_EMSException::CODE_UNKNOWN_MERCHANT);
     }
     if (!Syspay_Merchant_Utils::checkChecksum($this->content, $this->secrets[$this->headers['x-merchant']], $this->headers['x-checksum'])) {
         throw new Syspay_Merchant_EMSException('Invalid checksum', Syspay_Merchant_EMSException::CODE_INVALID_CHECKSUM);
     }
 }
Example #11
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)
 {
     $payment = new self();
     $payment->setId(isset($response->id) ? $response->id : null);
     $payment->setReference(isset($response->reference) ? $response->reference : null);
     $payment->setAmount(isset($response->amount) ? $response->amount : null);
     $payment->setCurrency(isset($response->currency) ? $response->currency : null);
     $payment->setStatus(isset($response->status) ? $response->status : null);
     $payment->setExtra(isset($response->extra) ? $response->extra : null);
     $payment->setDescription(isset($response->description) ? $response->description : null);
     $payment->setWebsite(isset($response->website) ? $response->website : null);
     $payment->setFailureCategory(isset($response->failure_category) ? $response->failure_category : null);
     $payment->setChipAndPinStatus(isset($response->chip_and_pin_status) ? $response->chip_and_pin_status : null);
     if (isset($response->processing_time) && !is_null($response->processing_time)) {
         $payment->setProcessingTime(Syspay_Merchant_Utils::tsToDateTime($response->processing_time));
     }
     if (isset($response->billing_agreement) && $response->billing_agreement instanceof stdClass) {
         $billingAgreement = Syspay_Merchant_Entity_BillingAgreement::buildFromResponse($response->billing_agreement);
         $payment->setBillingAgreement($billingAgreement);
     }
     if (isset($response->subscription) && $response->subscription instanceof stdClass) {
         $subscription = Syspay_Merchant_Entity_Subscription::buildFromResponse($response->subscription);
         $payment->setSubscription($subscription);
     }
     return $payment;
 }