Skip to content

Commit

Permalink
Refacto of order_amount in order cart estimate (#111) (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdichaouch authored Apr 19, 2018
1 parent 779d397 commit ab032b2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Oyst PHP API Wrapper

[![Build Status](https://travis-ci.org/oystparis/oyst-php.svg?branch=master)](https://travis-ci.org/oystparis/oyst-php)
[![Latest Stable Version](https://img.shields.io/badge/latest-6.3.0-green.svg)](https://github.com/oystparis/oyst-php/releases)
[![Latest Stable Version](https://img.shields.io/badge/latest-6.2.1-green.svg)](https://github.com/oystparis/oyst-php/releases)
[![PHP >= 5.3](https://img.shields.io/badge/php-%3E=5.3-green.svg)](#)

You can sign up for an Oyst account at https://backoffice.oyst.com.
Expand Down
6 changes: 3 additions & 3 deletions src/Api/OystApiClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
*/
class OystApiClientFactory
{
// 6.3.0
// 7.0.0
private static $version = array(
'major' => '6',
'minor' => '3',
'major' => '7',
'minor' => '0',
'patch' => '0',
);

Expand Down
3 changes: 2 additions & 1 deletion src/Classes/OneClickItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ public function toArray()
'message' => $this->message,
);

$oneClickItemProperty = array('reference', 'amount', 'quantity', 'images', 'crossedOutAmount', 'message');
foreach (get_object_vars($this) as $property => $value) {
if (in_array($property, array('reference', 'amount', 'quantity', 'images', 'crossedOutAmount', 'message'))) {
if (in_array($property, $oneClickItemProperty)) {
continue;
}

Expand Down
18 changes: 10 additions & 8 deletions src/Classes/OneClickOrderCartEstimate.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class OneClickOrderCartEstimate implements OystArrayInterface
*
* @var OystPrice
*/
private $orderAmount;
private $cartAmount;

/**
* Optional
Expand Down Expand Up @@ -181,19 +181,19 @@ public function setMessage($message)
/**
* @return OystPrice
*/
public function getOrderAmount()
public function getCartAmount()
{
return $this->orderAmount;
return $this->cartAmount;
}

/**
* @param OystPrice $orderAmount
* @param OystPrice $cartAmount
*
* @return $this
*/
public function setOrderAmount(OystPrice $orderAmount)
public function setCartAmount(OystPrice $cartAmount)
{
$this->orderAmount = $orderAmount;
$this->cartAmount = $cartAmount;

return $this;
}
Expand Down Expand Up @@ -248,7 +248,9 @@ public function setMerchantDiscounts($merchantDiscounts)
if (!empty($merchantDiscounts)) {
foreach ($merchantDiscounts as $merchantDiscount) {
if (!$merchantDiscount instanceof OneClickMerchantDiscount) {
throw new \InvalidArgumentException('$merchantDiscounts must be an array of Oyst\Classes\OneClickMerchantDiscount');
throw new \InvalidArgumentException(
'$merchantDiscounts must be an array of Oyst\Classes\OneClickMerchantDiscount'
);
}
}

Expand Down Expand Up @@ -330,7 +332,7 @@ public function toArray()
$oneClickOrderCartEstimate = array(
'shipments' => $oystCollectionHelper->collectionToArray($this->shipments),
'items' => $oystCollectionHelper->collectionToArray($this->items),
'order_amount' => $this->orderAmount instanceof OystPrice ? $this->orderAmount->toArray() : array(),
'cart_amount' => $this->cartAmount instanceof OystPrice ? $this->cartAmount->toArray() : array(),
'free_items' => $oystCollectionHelper->collectionToArray($this->freeItems),
'merchant_discounts' => $oystCollectionHelper->collectionToArray($this->merchantDiscounts),
'message' => $this->message,
Expand Down
29 changes: 23 additions & 6 deletions tests/Oyst/Test/Api/OneClickApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@ public function testAuthorizeOrderWithSimpleProductDematerialize($apiKey, $userA
*
* @dataProvider fakeData
*/
public function testAuthorizeOrderWithSimpleProductAndOrderParams($apiKey, $userAgent, $product, $oneClickOrderParams)
{
public function testAuthorizeOrderWithSimpleProductAndOrderParams(
$apiKey,
$userAgent,
$product,
$oneClickOrderParams
) {
/** @var OystOneClickAPI $oneClickApi */
$oneClickApi = $this->getApi($apiKey, $userAgent);

Expand Down Expand Up @@ -159,8 +163,14 @@ public function testAuthorizeOrderWithSimpleProductAndContext($apiKey, $userAgen
*
* @dataProvider fakeData
*/
public function testAuthorizeOrderWithSimpleProductAndNotification($apiKey, $userAgent, $product, $oneClickOrderParams, $oneClickOrderContext, $oneClickNotifications)
{
public function testAuthorizeOrderWithSimpleProductAndNotification(
$apiKey,
$userAgent,
$product,
$oneClickOrderParams,
$oneClickOrderContext,
$oneClickNotifications
) {
/** @var OystOneClickAPI $oneClickApi */
$oneClickApi = $this->getApi($apiKey, $userAgent);

Expand All @@ -184,8 +194,15 @@ public function testAuthorizeOrderWithSimpleProductAndNotification($apiKey, $use
*
* @dataProvider fakeData
*/
public function testAuthorizeOrderV2WithSimpleProduct($apiKey, $userAgent, $product, $oneClickOrderParams, $oneClickOrderContext, $oneClickNotifications, $user)
{
public function testAuthorizeOrderV2WithSimpleProduct(
$apiKey,
$userAgent,
$product,
$oneClickOrderParams,
$oneClickOrderContext,
$oneClickNotifications,
$user
) {
/** @var OystOneClickAPI $oneClickApi */
$oneClickApi = $this->getApi($apiKey, $userAgent);

Expand Down
11 changes: 7 additions & 4 deletions tests/Oyst/Test/Api/OystApiClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class OystApiClientFactoryTest extends \PHPUnit_Framework_TestCase
public function clientUrlData()
{
return array(
// @codingStandardsIgnoreLine
array(OystApiClientFactory::ENTITY_CATALOG, OystApiClientFactory::ENV_PROD, 'https://localhost', 'https://api.oyst.com/catalog/v1'),
array(OystApiClientFactory::ENTITY_ORDER, null, 'https://localhost', 'https://localhost/order/v2'),
// @codingStandardsIgnoreLine
array(OystApiClientFactory::ENTITY_ONECLICK, OystApiClientFactory::ENV_PROD, null, 'https://api.oyst.com/oneclick/'),
array(OystApiClientFactory::ENTITY_PAYMENT, null, 'https://localhost', 'https://localhost/payment'),
);
Expand Down Expand Up @@ -88,11 +90,12 @@ public function clientDataException()
*/
public function configurationData()
{
$url = 'https://localhost';
return array(
array(OystApiClientFactory::ENTITY_CATALOG, null, 'https://localhost', 'catalog', 'https://localhost/catalog'),
array(OystApiClientFactory::ENTITY_ORDER, null, 'https://localhost', 'order', 'https://localhost/order'),
array(OystApiClientFactory::ENTITY_PAYMENT, null, 'https://localhost', 'payment', 'https://localhost/payment'),
array(OystApiClientFactory::ENTITY_ONECLICK, null, 'https://localhost', 'oneclick', 'https://localhost/oneclick'),
array(OystApiClientFactory::ENTITY_CATALOG, null, $url, 'catalog', 'https://localhost/catalog'),
array(OystApiClientFactory::ENTITY_ORDER, null, $url, 'order', 'https://localhost/order'),
array(OystApiClientFactory::ENTITY_PAYMENT, null, $url, 'payment', 'https://localhost/payment'),
array(OystApiClientFactory::ENTITY_ONECLICK, null, $url, 'oneclick', 'https://localhost/oneclick'),
);
}

Expand Down
11 changes: 7 additions & 4 deletions tests/Oyst/Test/Entrypoint/OneClickOrderCartEstimateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function testOneClickOrderCartEstimateRequired()
$fakeResponse = new Response(
200,
array('Content-Type' => 'application/json'),
// @codingStandardsIgnoreLine
'{"shipments":[{"amount":{"value":490,"currency":"EUR"},"delay":48,"primary":true,"carrier":{"id":"colissimo","name":"Colissimo","type":"home_delivery"}}]}'
);

Expand Down Expand Up @@ -55,7 +56,8 @@ public function testOneClickOrderCartEstimateFull()
$fakeResponse = new Response(
200,
array('Content-Type' => 'application/json'),
'{"shipments":[{"amount":{"value":490,"currency":"EUR"},"delay":48,"primary":true,"carrier":{"id":"colissimo","name":"Colissimo","type":"home_delivery"}}],"items":[{"reference":"33245342","amount":{"value":3490,"currency":"EUR"},"quantity":1,"crossed_out_amount":{"value":3800,"currency":"EUR"}}],"order_amount":{"value":3490,"currency":"EUR"},"free_items":[{"reference":"4323","amount":{"value":0,"currency":"EUR"},"quantity":1,"title":"Special gift"}],"merchant_discounts":[{"amount":{"value":1337,"currency":"EUR"},"name":"bday discount"}],"message":"Happy bday","discount_coupon_error":"Invalid coupon"}'
// @codingStandardsIgnoreLine
'{"shipments":[{"amount":{"value":490,"currency":"EUR"},"delay":48,"primary":true,"carrier":{"id":"colissimo","name":"Colissimo","type":"home_delivery"}}],"items":[{"reference":"33245342","amount":{"value":3490,"currency":"EUR"},"quantity":1,"crossed_out_amount":{"value":3800,"currency":"EUR"}}],"cart_amount":{"value":3490,"currency":"EUR"},"free_items":[{"reference":"4323","amount":{"value":0,"currency":"EUR"},"quantity":1,"title":"Special gift"}],"merchant_discounts":[{"amount":{"value":1337,"currency":"EUR"},"name":"bday discount"}],"message":"Happy bday","discount_coupon_error":"Invalid coupon"}'
);

$colissimo = new OneClickShipmentCatalogLess(
Expand All @@ -73,7 +75,7 @@ public function testOneClickOrderCartEstimateFull()

$oneClickOrderCartEstimate = new OneClickOrderCartEstimate($shipments);
$oneClickOrderCartEstimate->setItems($items);
$oneClickOrderCartEstimate->setOrderAmount(new OystPrice(34.90, 'EUR'));
$oneClickOrderCartEstimate->setCartAmount(new OystPrice(34.90, 'EUR'));

$freeItems4323 = new OneClickItem('4323', new OystPrice(0, 'EUR'), 1);
$freeItems4323->__set('title', 'Special gift');
Expand All @@ -99,7 +101,8 @@ public function testOneClickOrderCartEstimateDefaultPrimary()
$fakeResponse = new Response(
200,
array('Content-Type' => 'application/json'),
'{"shipments":[{"amount":{"value":490,"currency":"EUR"},"delay":48,"primary":true,"carrier":{"id":"colissimo","name":"Colissimo","type":"home_delivery"}}],"items":[{"reference":"33245342","amount":{"value":3800,"currency":"EUR"},"quantity":1}],"order_amount":{"value":3490,"currency":"EUR"}}'
// @codingStandardsIgnoreLine
'{"shipments":[{"amount":{"value":490,"currency":"EUR"},"delay":48,"primary":true,"carrier":{"id":"colissimo","name":"Colissimo","type":"home_delivery"}}],"items":[{"reference":"33245342","amount":{"value":3800,"currency":"EUR"},"quantity":1}],"cart_amount":{"value":3490,"currency":"EUR"}}'
);

$colissimo = new OneClickShipmentCatalogLess(
Expand All @@ -117,7 +120,7 @@ public function testOneClickOrderCartEstimateDefaultPrimary()
$oneClickOrderCartEstimate = new OneClickOrderCartEstimate($shipments);
$oneClickOrderCartEstimate->setDefaultPrimaryShipmentByType();
$oneClickOrderCartEstimate->setItems($items);
$oneClickOrderCartEstimate->setOrderAmount(new OystPrice(34.90, 'EUR'));
$oneClickOrderCartEstimate->setCartAmount(new OystPrice(34.90, 'EUR'));

$this->assertEquals(
$fakeResponse->getBody(true),
Expand Down

0 comments on commit ab032b2

Please sign in to comment.