Esempio n. 1
0
 /**
  * @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());
 }
Esempio n. 2
0
 /**
  * @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);
 }
Esempio n. 3
0
 /**
  * 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());
 }
Esempio n. 4
0
 /**
  * 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);
     }
 }
Esempio n. 5
0
 /**
  * @test
  */
 public function itShouldThrowAClientExceptionWhenUpdatingOrder()
 {
     $orderData = ['transactions' => [['payment_method' => 'credit-card']], 'amount' => 9999, 'currency' => 'EUR', 'id' => 'c384b47e-7a5e-4c91-ab65-c4eed7f26e85', 'expiration_period' => 'PT10M', 'merchant_order_id' => '123', 'description' => "Test", 'return_url' => "http://example.com"];
     $request = m::mock('GuzzleHttp\\Message\\Request');
     $this->httpClient->shouldReceive('put')->once()->andThrow(new HttpClientException('Something happened', $request));
     $this->setExpectedException('GingerPayments\\Payment\\Client\\ClientException');
     $this->client->updateOrder(Order::fromArray($orderData));
 }