/** * @test */ public function itShouldCreateAnIdealOrder() { $order = Order::create(1234, 'EUR', 'ideal', ['issuer_id' => 'ABNANL2A'], 'A nice description', 'my-order-id', 'http://www.example.com', 'PT10M'); $this->httpClient->shouldReceive('post')->once()->with('orders/', m::on(function (array $options) use($order) { $this->assertEquals(3, $options['timeout']); $this->assertEquals('application/json', $options['headers']['Content-Type']); $this->assertEquals(ArrayFunctions::withoutNullValues($order->toArray()), json_decode($options['body'], true)); return true; }))->andReturn($this->httpResponse); $this->httpResponse->shouldReceive('json')->once()->andReturn(ArrayFunctions::withoutNullValues($order->toArray())); $this->assertInstanceOf('GingerPayments\\Payment\\Order', $this->client->createIdealOrder(1234, 'EUR', 'ABNANL2A', 'A nice description', 'my-order-id', 'http://www.example.com', 'PT10M')); }
/** * @test */ public function itShouldGetTheFirstTransactionPaymentUrl() { $array = ['transactions' => [['payment_method' => 'credit-card', 'payment_url' => 'http://www.example.com']], 'amount' => 6200, 'currency' => 'EUR']; $order = Order::fromArray($array); $this->assertEquals('http://www.example.com', $order->firstTransactionPaymentUrl()); }
/** * PUT order data to Ginger API. * * @param Order $order * @return Order */ private function putOrder(Order $order) { try { return Order::fromArray($this->httpClient->put("orders/" . $order->id() . "/", ["timeout" => 3, "json" => $order->toArray()])->json()); } catch (RequestException $exception) { if ($exception->getCode() == 404) { throw new OrderNotFoundException('No order with that ID was found.', 404, $exception); } throw new ClientException('An error occurred while updating the order: ' . $exception->getMessage(), $exception->getCode(), $exception); } }
/** * @test */ public function itShouldUpdateFieldsThatAreNotReadOnly() { $customer = ['address' => "Radarweg 29 A-12 Amsterdam", 'address_type' => "customer", 'country' => "NL", 'email_address' => "*****@*****.**", 'first_name' => "Firstname", 'last_name' => "Lastname", 'merchant_customer_id' => "2", 'phone_numbers' => ["0123456789"], 'postal_code' => "1043 NX", 'housenumber' => "29", 'locale' => "en_US"]; $array = ['transactions' => [], 'amount' => 6200, 'currency' => 'EUR', 'description' => 'My amazing order', 'merchant_order_id' => 'my-order-id', 'return_url' => 'http://www.example.com', 'expiration_period' => 'P0Y0M0DT1H0M0S', 'id' => '6cc8bc83-c14a-4871-b91e-a8575db5556d', 'project_id' => '4e8207ef-caf2-429e-a8e1-be8d628beccb', 'created' => '2015-03-07T20:58:35+0100', 'modified' => '2015-03-07T20:58:35+0100', 'completed' => '2015-03-07T20:58:35+0100', 'status' => 'new', 'customer' => $customer, 'extra' => null, 'webhook_url' => 'http://www.example.com']; $updatedOrder = ['transactions' => [], 'amount' => 9999, 'currency' => 'EUR', 'description' => 'New Order Description', 'merchant_order_id' => 'NEW_MERCHANT_ORDER_ID', 'return_url' => 'http://www.example.com/API', 'expiration_period' => 'P0Y0M0DT2H0M0S', 'id' => '6cc8bc83-c14a-4871-b91e-a8575db5556d', 'project_id' => '4e8207ef-caf2-429e-a8e1-be8d628beccb', 'created' => '2015-03-07T20:58:35+0100', 'modified' => '2015-03-07T20:58:35+0100', 'completed' => '2015-03-07T20:58:35+0100', 'status' => 'new', 'customer' => $customer, 'extra' => null, 'webhook_url' => 'http://www.example.com/WEBHOOK']; $order = Order::fromArray($array); $this->assertEquals($order->toArray(), $array); $order->merchantOrderId("NEW_MERCHANT_ORDER_ID"); $this->assertNotEquals($order->toArray(), $array); $this->assertEquals($order->merchantOrderId("NEW_MERCHANT_ORDER_ID")->toString(), "NEW_MERCHANT_ORDER_ID"); $this->assertEquals($order->currency("EUR")->toString(), "EUR"); $this->assertEquals($order->amount(9999)->toInteger(), 9999); $this->assertEquals($order->expirationPeriod("P0Y0M0DT2H0M0S")->format('P%yY%mM%dDT%hH%iM%sS'), "P0Y0M0DT2H0M0S"); $this->assertEquals($order->description("New Order Description")->toString(), "New Order Description"); $this->assertEquals($order->returnUrl("http://www.example.com/API")->toString(), "http://www.example.com/API"); $this->assertEquals($order->webhookUrl("http://www.example.com/WEBHOOK")->toString(), "http://www.example.com/WEBHOOK"); $this->assertEquals($order->toArray(), $updatedOrder); }
/** * Post a new order. * * @param Order $order * @return Order */ private function postOrder(Order $order) { try { $response = $this->httpClient->post('orders/', ['timeout' => 3, 'headers' => ['Content-Type' => 'application/json'], 'body' => json_encode(ArrayFunctions::withoutNullValues($order->toArray()))]); } catch (RequestException $exception) { throw new ClientException('An error occurred while posting the order: ' . $exception->getMessage(), $exception->getCode(), $exception); } return Order::fromArray($response->json()); }