/** * 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; }