Example #1
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 #2
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;
 }