public function testFailedPayRequest() { $response = new Ulink_PaymentResponse(); $response->setAmount(new Ulink_Money("23.50")); $response->setCurrency("EUR"); $response->setTimestamp(123); $response->setClientTransactionId(456); $response->setSuccess(false); $response->setTest(false); $response->addError("Wrong signature"); $response->addErrorCode(17987); $this->assertEquals("{\"type\":\"pay-response\",\"timestamp\":123,\"response-url\":null,\"back-url\":null,\"id\":456,\"data\":{\"amount\":\"23.50\",\"currency\":\"EUR\"},\"success\":false,\"test\":false,\"errors\":[\"Wrong signature\"],\"errorCodes\":[17987]}", $response->toJson()); }
public static function createFromJson($json) { $data = $json->data; $response = new Ulink_PaymentResponse(); $response->setAmount(new Ulink_Money($data->amount)); $response->setCurrency($data->currency); if (isset($json->id) && $json->id) { $response->setClientTransactionId($json->id); } if (isset($json->{'response-url'}) && $json->{'response-url'}) { $request->setResponseUrl($json->{'response-url'}); } if (isset($json->{'back-url'}) && $json->{'back-url'}) { $request->setGoBackUrl($json->{'back-url'}); } if (isset($data->order)) { $response->setOrder(Ulink_Order::createFromJson($data->order)); } $response->setSuccess($json->success); if (isset($data->test)) { $response->setTest($json->test); } $response->setErrors($json->errors); $response->setErrorCodes($json->errorCodes); return $response; }