From 9689f7f2ff2b482df4cd15648da2c4c3fea6a90b Mon Sep 17 00:00:00 2001 From: John Malone Date: Mon, 21 Aug 2017 14:13:16 -0500 Subject: [PATCH 1/8] AP-5505 - adding offline order creation to the apruve-php library. --- src/Apruve/Order.php | 14 ++++++++++-- tests/Apruve/OrderTest.php | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/Apruve/Order.php b/src/Apruve/Order.php index 312588b..4ba1888 100644 --- a/src/Apruve/Order.php +++ b/src/Apruve/Order.php @@ -5,7 +5,7 @@ require_once 'ApruveObject.php'; class Order extends ApruveObject { - protected static $ORDERS_PATH = '/orders/'; + protected static $ORDERS_PATH = '/orders'; protected static $hash_order = [ 'merchant_id', 'merchant_order_id', @@ -63,7 +63,7 @@ public static function get( $order_id, $client = null ) { if ( $client == null ) { $client = new Client(); } - $response = $client->get( self::$ORDERS_PATH . $order_id ); + $response = $client->get( self::$ORDERS_PATH . '/' . $order_id ); if ( $response[0] == 200 ) { $object = new self( $response[1], $client ); @@ -132,6 +132,16 @@ public function addOrderItem( $order_item ) { } } + public function save() { + $response = $this->client->post( + self::$ORDERS_PATH, $this->toJson() ); + if ( $response[0] == 201 ) { + return new self( $response[1], $this->client ); + } else { + return $response[2]; + } + } + public function update() { $response = $this->client->put( sprintf( self::$UPDATE_PATH, $this->id ), $this->toJson() ); diff --git a/tests/Apruve/OrderTest.php b/tests/Apruve/OrderTest.php index 69ceb12..76dab9a 100644 --- a/tests/Apruve/OrderTest.php +++ b/tests/Apruve/OrderTest.php @@ -133,6 +133,53 @@ public function testGet() { $this->assertEquals( 'Apruve\Order', get_class( $po ) ); } + public function testSave() { + + $client = $this->getMockBuilder( 'Apruve\Client' ) + ->setMethods( [ 'post' ] ) + ->getMock(); + $client->expects( $this->Once() ) + ->method( 'post' ) + ->with( $this->equalTo( '/orders' ), + $this->anything() ) + ->will( $this->returnValue( [ + 201, + [ + 'id' => 'asdf1234', + 'amount_cents' => 6000, + 'currency' => 'USD', + 'order_items' => [ + [ + 'title' => 'a title', + 'amount_cents' => 4500, + 'order_id' => 'id', + ] + ] + ], + '' + ] ) + ); + + $item = new OrderItem( + [ + 'title' => 'a title', + 'amount_cents' => 4500, + 'order_id' => 'id', + ] + ); + $order = new Order( [ + "amount_cents" => 6000, + "merchant_notes" => 'some notes', + "order_items" => $item + ], $client ); + $i = $order->save(); + + $this->assertEquals( 'asdf1234', $i->id ); + $this->assertEquals( 'Apruve\Order', get_class( $i ) ); + $this->assertEquals( $i->order_items, $this->po->order_items ); + + } + public function testUpdate() { $client = $this->getMockBuilder( 'Apruve\Client' ) ->setMethods( [ 'put' ] ) From dcab37521a75b15e11b34521353dc58dd3d9337c Mon Sep 17 00:00:00 2001 From: John Malone Date: Mon, 21 Aug 2017 16:38:21 -0500 Subject: [PATCH 2/8] AP-5505 - more git fun. --- src/Apruve/ApruveObject.php | 7 +- src/Apruve/Client.php | 5 +- src/Apruve/CorporateAccount.php | 54 ++++++++++++++ tests/Apruve/CorporateAccountTest.php | 103 ++++++++++++++++++++++++++ 4 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 src/Apruve/CorporateAccount.php create mode 100644 tests/Apruve/CorporateAccountTest.php diff --git a/src/Apruve/ApruveObject.php b/src/Apruve/ApruveObject.php index 9b98758..b397cb4 100644 --- a/src/Apruve/ApruveObject.php +++ b/src/Apruve/ApruveObject.php @@ -38,7 +38,12 @@ public function toJsonArray() { if ( gettype( $this->$key ) == "array" ) { $jsonArr[ $key ] = []; foreach ( $this->$key as $item ) { - array_push( $jsonArr[ $key ], $item->toJsonArray() ); + if ( is_object( $item ) && get_class( $item ) ) { + array_push( $jsonArr[ $key ], $item->toJsonArray() ); + } else { + $jsonArr[ $key ] = [ $item ]; + break; + } } } else { $jsonArr[ $key ] = $this->$key; diff --git a/src/Apruve/Client.php b/src/Apruve/Client.php index 4f1e8d1..841c026 100644 --- a/src/Apruve/Client.php +++ b/src/Apruve/Client.php @@ -87,9 +87,12 @@ protected function initCurl( $url ) { return new CurlRequest( $url ); } - public function get( $path ) { + public function get( $path, $payload = null ) { $client = $this->restRequest( $path ); $client->setOption( CURLOPT_RETURNTRANSFER, true ); + if ( ! empty( $payload ) ) { + $client->setOption( CURLOPT_POSTFIELDS, $payload ); + } $response = $client->execute(); $ret = [ $client->getInfo( CURLINFO_HTTP_CODE ), json_decode( $response, true ), $client->error() ]; $client->close(); diff --git a/src/Apruve/CorporateAccount.php b/src/Apruve/CorporateAccount.php new file mode 100644 index 0000000..ffd32df --- /dev/null +++ b/src/Apruve/CorporateAccount.php @@ -0,0 +1,54 @@ +get( sprintf( self::$ACCOUNTS_PATH, $merchant_key ), $email_payload ); + + if ( $response[0] == 200 ) { + return new self( $response[1], $client ); + } else { + return $response[2]; + } + } +} diff --git a/tests/Apruve/CorporateAccountTest.php b/tests/Apruve/CorporateAccountTest.php new file mode 100644 index 0000000..7932491 --- /dev/null +++ b/tests/Apruve/CorporateAccountTest.php @@ -0,0 +1,103 @@ +corporate_account ) ); + + $this->assertEquals( array_keys( $vars ), [ + 'id', + 'customer_uuid', + 'merchant_uuid', + 'type', + 'payment_term_strategy_name', + 'name', + 'authorized_buyers', + ] ); + $this->assertEquals( 7, count( $vars ) ); + + } + + public function testToJson() { + $this->assertJsonStringEqualsJsonString( + '{ + "id": null, + "customer_uuid": "b76ac505389e7814eb10fb4fdc33a50b", + "merchant_uuid": "5ca2ab51d10b490cba7b22934c9fe913", + "type": "corporate", + "payment_term_strategy_name": "Net30", + "name": "MyCorporateAccount", + "authorized_buyers": [ + { + "id": "d9e10e59140513b61998e292088c8194", + "name": "Corporate Corbin", + "email" : "corporateuser@apruve.com" + } + ] + }', + $this->corporate_account->toJson() + ); + } + + public function testGet() { + $client = $this->getMockBuilder( 'Apruve\Client' ) + ->setMethods( [ 'get' ] ) + ->getMock(); + $client->expects( $this->Once() ) + ->method( 'get' ) + ->with( $this->equalTo( '/merchants/asdf1234/corporate_account' ) ) + ->will( $this->returnValue( [ + 200, + [ + 'id' => 'asdf1234', + 'customer_uuid' => 'b76ac505389e7814eb10fb4fdc33a50b', + 'merchant_uuid' => '5ca2ab51d10b490cba7b22934c9fe913', + 'type' => 'corporate', + 'payment_term_strategy_name' => 'Net30', + 'name' => 'MyCorporateAccount', + 'authorized_buyers' => [ + [ + 'id' => 'd9e10e59140513b61998e292088c8194', + 'name' => 'Corporate Corbin', + 'email' => 'corporateuser@apruve.com' + ] + ] + ], + '' + ] ) + ); + + $i = CorporateAccount::get( 'asdf1234', 'corporateuser@apruve.com', $client ); + + $this->assertEquals( 'asdf1234', $i->id ); + $this->assertEquals( 'Apruve\CorporateAccount', get_class( $i ) ); + } + + protected function setUp() { + Apruve\Client::init( 'a key', Apruve\Environment::DEV() ); + $this->corporate_account = new CorporateAccount( [ + 'customer_uuid' => 'b76ac505389e7814eb10fb4fdc33a50b', + 'merchant_uuid' => '5ca2ab51d10b490cba7b22934c9fe913', + 'type' => 'corporate', + 'payment_term_strategy_name' => 'Net30', + 'name' => 'MyCorporateAccount', + 'authorized_buyers' => [ + [ + 'id' => 'd9e10e59140513b61998e292088c8194', + 'name' => 'Corporate Corbin', + 'email' => 'corporateuser@apruve.com' + ] + ] + ] ); + + } + + +} + From 72ae39040104eb1fa6fe5a4a12ac27a5d6988fe6 Mon Sep 17 00:00:00 2001 From: John Malone Date: Wed, 23 Aug 2017 12:11:29 -0500 Subject: [PATCH 3/8] AP-5505 - tests passing. --- src/Apruve/ApruveObject.php | 28 +++++++--- src/Apruve/CorporateAccount.php | 17 +----- src/Apruve/Order.php | 11 ++++ src/Apruve/OrderItem.php | 9 ++-- tests/Apruve/CorporateAccountTest.php | 17 ++---- tests/Apruve/OrderItemTest.php | 33 ++++++------ tests/Apruve/OrderTest.php | 75 +++++++++++++++------------ 7 files changed, 100 insertions(+), 90 deletions(-) diff --git a/src/Apruve/ApruveObject.php b/src/Apruve/ApruveObject.php index b397cb4..04ecaad 100644 --- a/src/Apruve/ApruveObject.php +++ b/src/Apruve/ApruveObject.php @@ -12,8 +12,17 @@ public function __construct( $values = [], $client = null ) { } else { $this->client = $client; } - foreach ( $values as $name => $value ) { - $this->$name = $value; + if (is_array($values) || is_object($values)) { + foreach ( $values as $name => $value ) { + if ( is_array( $value ) ) { + $this->$name = []; + $this->$name = $value; + } else { + $this->$name = $value; + } + } + } else { + echo $values; } } @@ -21,7 +30,13 @@ public function toHashString() { $ret = ''; $called_class = get_called_class(); foreach ( $called_class::$hash_order as $key ) { - $ret .= $this->$key; + if(is_array($this->$key)){ + foreach ( $this->$key as $item ) { + $ret .= $item->toHashString(); + } + } else { + $ret .= $this->$key; + } } return $ret; @@ -38,11 +53,10 @@ public function toJsonArray() { if ( gettype( $this->$key ) == "array" ) { $jsonArr[ $key ] = []; foreach ( $this->$key as $item ) { - if ( is_object( $item ) && get_class( $item ) ) { - array_push( $jsonArr[ $key ], $item->toJsonArray() ); + if ( is_array( $item ) || is_string( $item ) ) { + array_push( $jsonArr[ $key ], $item ); } else { - $jsonArr[ $key ] = [ $item ]; - break; + array_push( $jsonArr[ $key ], $item->toJsonArray() ); } } } else { diff --git a/src/Apruve/CorporateAccount.php b/src/Apruve/CorporateAccount.php index ffd32df..11244c3 100644 --- a/src/Apruve/CorporateAccount.php +++ b/src/Apruve/CorporateAccount.php @@ -6,7 +6,7 @@ class CorporateAccount extends ApruveObject { - protected static $ACCOUNTS_PATH = '/merchants/%s/corporate_account'; + protected static $ACCOUNTS_PATH = '/merchants/%s/corporate_accounts'; protected static $hash_order = []; protected static $json_fields = [ 'id', @@ -26,24 +26,11 @@ class CorporateAccount extends ApruveObject { var $name; var $authorized_buyers = []; - public function __construct( $corporate_account = [], $client = null ) { - if ( array_key_exists( 'authorized_buyers', $corporate_account ) ) { - foreach ( $corporate_account['authorized_buyers'] as $buyer ) { - if ( is_array( $buyer ) ) { - $corporate_account['authorized_buyers'] += $buyer; - } - } - } - - parent::__construct( $corporate_account, $client ); - } - public static function get( $merchant_key, $email, $client = null ) { if ( $client == null ) { $client = new Client(); } - $email_payload = sprintf('{"email":"%s"}', $email); - $response = $client->get( sprintf( self::$ACCOUNTS_PATH, $merchant_key ), $email_payload ); + $response = $client->get( sprintf( self::$ACCOUNTS_PATH, $merchant_key ) . '?email=' . $email ); if ( $response[0] == 200 ) { return new self( $response[1], $client ); diff --git a/src/Apruve/Order.php b/src/Apruve/Order.php index 4ba1888..022528f 100644 --- a/src/Apruve/Order.php +++ b/src/Apruve/Order.php @@ -14,6 +14,8 @@ class Order extends ApruveObject { 'tax_cents', 'shipping_cents', 'expire_at', + 'accepts_payment_terms', + 'finalize_on_create', 'invoice_on_create' ]; protected static $json_fields = [ @@ -25,8 +27,13 @@ class Order extends ApruveObject { 'tax_cents', 'shipping_cents', 'expire_at', + 'accepts_payment_terms', + 'finalize_on_create', 'invoice_on_create', + 'payment_term', 'order_items', + 'shopper_id', + 'customer_id' ]; private static $UPDATE_PATH = '/orders/%s'; private static $CANCEL_PATH = '/orders/%s/cancel'; @@ -41,8 +48,11 @@ class Order extends ApruveObject { var $shipping_cents; var $currency; var $expire_at; + var $accepts_payment_terms; + var $finalize_on_create; var $invoice_on_create = 'false'; var $order_items = []; + var $payment_term = []; var $api_url; var $view_url; var $created_at; @@ -56,6 +66,7 @@ public function __construct( $order = [], $client = null ) { } } } + parent::__construct( $order, $client ); } diff --git a/src/Apruve/OrderItem.php b/src/Apruve/OrderItem.php index 8203668..2471538 100644 --- a/src/Apruve/OrderItem.php +++ b/src/Apruve/OrderItem.php @@ -8,8 +8,7 @@ class OrderItem extends ApruveObject { protected static $hash_order = [ 'title', - 'plan_code', - 'amount_cents', + 'price_total_cents', 'price_ea_cents', 'quantity', 'merchant_notes', @@ -21,8 +20,7 @@ class OrderItem extends ApruveObject { ]; protected static $json_fields = [ 'title', - 'plan_code', - 'amount_cents', + 'price_total_cents', 'price_ea_cents', 'quantity', 'merchant_notes', @@ -35,8 +33,7 @@ class OrderItem extends ApruveObject { var $id; var $order_id; var $title; - var $plan_code; - var $amount_cents; + var $price_total_cents; var $quantity; var $price_ea_cents; var $merchant_notes; diff --git a/tests/Apruve/CorporateAccountTest.php b/tests/Apruve/CorporateAccountTest.php index 7932491..4fcf6c5 100644 --- a/tests/Apruve/CorporateAccountTest.php +++ b/tests/Apruve/CorporateAccountTest.php @@ -27,7 +27,7 @@ public function testPropertiesAreDefined() { public function testToJson() { $this->assertJsonStringEqualsJsonString( '{ - "id": null, + "id": "asdf1234", "customer_uuid": "b76ac505389e7814eb10fb4fdc33a50b", "merchant_uuid": "5ca2ab51d10b490cba7b22934c9fe913", "type": "corporate", @@ -51,7 +51,7 @@ public function testGet() { ->getMock(); $client->expects( $this->Once() ) ->method( 'get' ) - ->with( $this->equalTo( '/merchants/asdf1234/corporate_account' ) ) + ->with( $this->equalTo( '/merchants/asdf1234/corporate_accounts?email=corporateuser@apruve.com' ) ) ->will( $this->returnValue( [ 200, [ @@ -61,13 +61,6 @@ public function testGet() { 'type' => 'corporate', 'payment_term_strategy_name' => 'Net30', 'name' => 'MyCorporateAccount', - 'authorized_buyers' => [ - [ - 'id' => 'd9e10e59140513b61998e292088c8194', - 'name' => 'Corporate Corbin', - 'email' => 'corporateuser@apruve.com' - ] - ] ], '' ] ) @@ -82,20 +75,20 @@ public function testGet() { protected function setUp() { Apruve\Client::init( 'a key', Apruve\Environment::DEV() ); $this->corporate_account = new CorporateAccount( [ + 'id' => 'asdf1234', 'customer_uuid' => 'b76ac505389e7814eb10fb4fdc33a50b', 'merchant_uuid' => '5ca2ab51d10b490cba7b22934c9fe913', 'type' => 'corporate', 'payment_term_strategy_name' => 'Net30', - 'name' => 'MyCorporateAccount', 'authorized_buyers' => [ [ 'id' => 'd9e10e59140513b61998e292088c8194', 'name' => 'Corporate Corbin', 'email' => 'corporateuser@apruve.com' ] - ] + ], + 'name' => 'MyCorporateAccount' ] ); - } diff --git a/tests/Apruve/OrderItemTest.php b/tests/Apruve/OrderItemTest.php index 279d528..00e2849 100644 --- a/tests/Apruve/OrderItemTest.php +++ b/tests/Apruve/OrderItemTest.php @@ -13,8 +13,7 @@ public function testPropertiesAreDefined() { 'id', 'order_id', 'title', - 'plan_code', - 'amount_cents', + 'price_total_cents', 'quantity', 'price_ea_cents', 'merchant_notes', @@ -24,12 +23,12 @@ public function testPropertiesAreDefined() { 'vendor', 'view_product_url', ) ); - $this->assertEquals( 13, count( $item_vars ) ); + $this->assertEquals( 12, count( $item_vars ) ); } public function testToHashString() { $this->assertEquals( - 'A titleplan340034001some notes.a description.some variation.skuACMEA Url.', + 'A title340034001some notes.a description.some variation.skuACMEA Url.', $this->item->toHashString() ); } @@ -38,8 +37,7 @@ public function testToJsonString() { $this->assertJsonStringEqualsJsonString( '{ "title": "A title", - "plan_code": "plan", - "amount_cents": 3400, + "price_total_cents": 3400, "price_ea_cents": 3400, "quantity": 1, "merchant_notes": "some notes.", @@ -54,18 +52,17 @@ public function testToJsonString() { protected function setUp() { $this->item = new OrderItem( [ - 'title' => 'A title', - 'sku' => 'sku', - 'plan_code' => 'plan', - 'amount_cents' => 3400, - 'price_ea_cents' => 3400, - 'quantity' => 1, - 'merchant_notes' => 'some notes.', - 'description' => 'a description.', - 'variant_info' => 'some variation.', - 'vendor' => 'ACME', - 'view_product_url' => 'A Url.', - 'order_id' => '1234', + 'title' => 'A title', + 'sku' => 'sku', + 'price_total_cents' => 3400, + 'price_ea_cents' => 3400, + 'quantity' => 1, + 'merchant_notes' => 'some notes.', + 'description' => 'a description.', + 'variant_info' => 'some variation.', + 'vendor' => 'ACME', + 'view_product_url' => 'A Url.', + 'order_id' => '1234', ], $this->getMockBuilder( 'Apruve\Client' ) ->setConstructorArgs( [ 'a key', Apruve\Environment::DEV() ] ) ->getMock() diff --git a/tests/Apruve/OrderTest.php b/tests/Apruve/OrderTest.php index 76dab9a..f31095e 100644 --- a/tests/Apruve/OrderTest.php +++ b/tests/Apruve/OrderTest.php @@ -24,45 +24,50 @@ public function testPropertiesAreDefined() { 'shipping_cents', 'currency', 'expire_at', + 'accepts_payment_terms', + 'finalize_on_create', 'invoice_on_create', 'order_items', + 'payment_term', 'api_url', 'view_url', 'created_at', 'updated_at', ] ); - $this->assertEquals( 16, count( $vars ) ); + $this->assertEquals( 19, count( $vars ) ); } public function testToJson() { $this->assertJsonStringEqualsJsonString( '{ - "id": "id", - "merchant_id": "asdf1234", - "merchant_order_id": "order1234", - "amount_cents": 6000, - "tax_cents": 500, - "shipping_cents": 1000, - "currency": "USD", - "expire_at": "2014-07-15T10:12:27-05:00", - "order_items": [ - { - "title": "a title", - "amount_cents": 4500, - "plan_code": null, - "price_ea_cents": null, - "quantity": null, - "merchant_notes": null, - "description": null, - "variant_info": null, - "sku": null, - "vendor": null, - "view_product_url": null - } - ], - "invoice_on_create": "false" - }', + "id": "id", + "merchant_id": "asdf1234", + "merchant_order_id": "order1234", + "amount_cents": 6000, + "currency": "USD", + "tax_cents": 500, + "shipping_cents": 1000, + "expire_at": "2014-07-15T10:12:27-05:00", + "accepts_payment_terms": null, + "finalize_on_create": null, + "invoice_on_create": "false", + "payment_term": [], + "order_items": [{ + "title": "a title", + "price_total_cents": null, + "price_ea_cents": null, + "quantity": null, + "merchant_notes": null, + "description": null, + "variant_info": null, + "sku": null, + "vendor": null, + "view_product_url": null + }], + "shopper_id": "foo", + "customer_id": "bar" +}', $this->po->toJson() ); } @@ -76,7 +81,7 @@ public function testToHashString() { public function testToSecureString() { $this->assertEquals( - 'asdf1234order12346000USD50010002014-07-15T10:12:27-05:00falsea title4500', + 'asdf1234order12346000USD50010002014-07-15T10:12:27-05:00falsea title', $this->po->toSecureString() ); } @@ -84,7 +89,7 @@ public function testToSecureString() { public function testToSecureHash() { Apruve\Client::init( 'a key', Apruve\Environment::DEV() ); $this->assertEquals( - hash( 'sha256', 'a keyasdf1234order12346000USD50010002014-07-15T10:12:27-05:00falsea title4500' ), + hash( 'sha256', 'a keyasdf1234order12346000USD50010002014-07-15T10:12:27-05:00falsea title' ), $this->po->toSecureHash() ); } @@ -148,7 +153,7 @@ public function testSave() { 'id' => 'asdf1234', 'amount_cents' => 6000, 'currency' => 'USD', - 'order_items' => [ + 'order_items' => [ [ 'title' => 'a title', 'amount_cents' => 4500, @@ -160,7 +165,7 @@ public function testSave() { ] ) ); - $item = new OrderItem( + $item = new OrderItem( [ 'title' => 'a title', 'amount_cents' => 4500, @@ -170,9 +175,11 @@ public function testSave() { $order = new Order( [ "amount_cents" => 6000, "merchant_notes" => 'some notes', - "order_items" => $item + 'shopper_id' => 'foo', + 'customer_id' => 'bar', + "order_items" => $item ], $client ); - $i = $order->save(); + $i = $order->save(); $this->assertEquals( 'asdf1234', $i->id ); $this->assertEquals( 'Apruve\Order', get_class( $i ) ); @@ -205,6 +212,8 @@ public function testUpdate() { $po = new Order( [ 'id' => 'asdf1234', 'merchant_id' => 'asdf1234', + 'shopper_id' => 'foo', + 'customer_id' => 'bar', 'merchant_order_id' => 'order1234', 'amount_cents' => 6000, 'currency' => 'USD' @@ -223,6 +232,8 @@ protected function setUp() { $this->po = new Order( [ 'id' => 'id', 'merchant_id' => 'asdf1234', + 'shopper_id' => 'foo', + 'customer_id' => 'bar', 'merchant_order_id' => 'order1234', 'amount_cents' => 6000, 'tax_cents' => 500, From d8b42f060e25bb9f04c7e0518a1900af3797c944 Mon Sep 17 00:00:00 2001 From: John Malone Date: Thu, 24 Aug 2017 13:50:53 -0500 Subject: [PATCH 4/8] AP-5505 - fixing indentation. --- src/Apruve/ApruveObject.php | 6 ++---- src/Apruve/CorporateAccount.php | 2 +- tests/Apruve/CorporateAccountTest.php | 17 +++++++++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Apruve/ApruveObject.php b/src/Apruve/ApruveObject.php index 04ecaad..e68dad1 100644 --- a/src/Apruve/ApruveObject.php +++ b/src/Apruve/ApruveObject.php @@ -12,7 +12,7 @@ public function __construct( $values = [], $client = null ) { } else { $this->client = $client; } - if (is_array($values) || is_object($values)) { + if ( is_array( $values ) || is_object( $values ) ) { foreach ( $values as $name => $value ) { if ( is_array( $value ) ) { $this->$name = []; @@ -21,8 +21,6 @@ public function __construct( $values = [], $client = null ) { $this->$name = $value; } } - } else { - echo $values; } } @@ -30,7 +28,7 @@ public function toHashString() { $ret = ''; $called_class = get_called_class(); foreach ( $called_class::$hash_order as $key ) { - if(is_array($this->$key)){ + if ( is_array( $this->$key ) ) { foreach ( $this->$key as $item ) { $ret .= $item->toHashString(); } diff --git a/src/Apruve/CorporateAccount.php b/src/Apruve/CorporateAccount.php index 11244c3..151b6eb 100644 --- a/src/Apruve/CorporateAccount.php +++ b/src/Apruve/CorporateAccount.php @@ -33,7 +33,7 @@ public static function get( $merchant_key, $email, $client = null ) { $response = $client->get( sprintf( self::$ACCOUNTS_PATH, $merchant_key ) . '?email=' . $email ); if ( $response[0] == 200 ) { - return new self( $response[1], $client ); + return new self( array_pop( $response[1] ), $client ); } else { return $response[2]; } diff --git a/tests/Apruve/CorporateAccountTest.php b/tests/Apruve/CorporateAccountTest.php index 4fcf6c5..62bf19e 100644 --- a/tests/Apruve/CorporateAccountTest.php +++ b/tests/Apruve/CorporateAccountTest.php @@ -55,14 +55,15 @@ public function testGet() { ->will( $this->returnValue( [ 200, [ - 'id' => 'asdf1234', - 'customer_uuid' => 'b76ac505389e7814eb10fb4fdc33a50b', - 'merchant_uuid' => '5ca2ab51d10b490cba7b22934c9fe913', - 'type' => 'corporate', - 'payment_term_strategy_name' => 'Net30', - 'name' => 'MyCorporateAccount', - ], - '' + [ + 'id' => 'asdf1234', + 'customer_uuid' => 'b76ac505389e7814eb10fb4fdc33a50b', + 'merchant_uuid' => '5ca2ab51d10b490cba7b22934c9fe913', + 'type' => 'corporate', + 'payment_term_strategy_name' => 'Net30', + 'name' => 'MyCorporateAccount', + ] + ] ] ) ); From cb3e835c60ce2a4ef6f7d3979d43becc85ca9beb Mon Sep 17 00:00:00 2001 From: John Malone Date: Thu, 24 Aug 2017 13:53:43 -0500 Subject: [PATCH 5/8] AP-5505 - more formatting changes. --- tests/Apruve/CorporateAccountTest.php | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/Apruve/CorporateAccountTest.php b/tests/Apruve/CorporateAccountTest.php index 62bf19e..fe31fdb 100644 --- a/tests/Apruve/CorporateAccountTest.php +++ b/tests/Apruve/CorporateAccountTest.php @@ -25,21 +25,20 @@ public function testPropertiesAreDefined() { } public function testToJson() { - $this->assertJsonStringEqualsJsonString( - '{ - "id": "asdf1234", - "customer_uuid": "b76ac505389e7814eb10fb4fdc33a50b", - "merchant_uuid": "5ca2ab51d10b490cba7b22934c9fe913", - "type": "corporate", - "payment_term_strategy_name": "Net30", - "name": "MyCorporateAccount", - "authorized_buyers": [ - { - "id": "d9e10e59140513b61998e292088c8194", - "name": "Corporate Corbin", - "email" : "corporateuser@apruve.com" - } - ] + $this->assertJsonStringEqualsJsonString( '{ + "id": "asdf1234", + "customer_uuid": "b76ac505389e7814eb10fb4fdc33a50b", + "merchant_uuid": "5ca2ab51d10b490cba7b22934c9fe913", + "type": "corporate", + "payment_term_strategy_name": "Net30", + "name": "MyCorporateAccount", + "authorized_buyers": [ + { + "id": "d9e10e59140513b61998e292088c8194", + "name": "Corporate Corbin", + "email" : "corporateuser@apruve.com" + } + ] }', $this->corporate_account->toJson() ); From 2cf143d737151454df28d0184608dea73538c471 Mon Sep 17 00:00:00 2001 From: John Malone Date: Mon, 28 Aug 2017 13:30:09 -0500 Subject: [PATCH 6/8] AP-5505 - fixing order and order_item hashes. --- src/Apruve/Order.php | 2 -- src/Apruve/OrderItem.php | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Apruve/Order.php b/src/Apruve/Order.php index 022528f..cd7f076 100644 --- a/src/Apruve/Order.php +++ b/src/Apruve/Order.php @@ -14,8 +14,6 @@ class Order extends ApruveObject { 'tax_cents', 'shipping_cents', 'expire_at', - 'accepts_payment_terms', - 'finalize_on_create', 'invoice_on_create' ]; protected static $json_fields = [ diff --git a/src/Apruve/OrderItem.php b/src/Apruve/OrderItem.php index 2471538..4d71639 100644 --- a/src/Apruve/OrderItem.php +++ b/src/Apruve/OrderItem.php @@ -8,7 +8,7 @@ class OrderItem extends ApruveObject { protected static $hash_order = [ 'title', - 'price_total_cents', + 'amount_cents', 'price_ea_cents', 'quantity', 'merchant_notes', @@ -20,7 +20,7 @@ class OrderItem extends ApruveObject { ]; protected static $json_fields = [ 'title', - 'price_total_cents', + 'amount_cents', 'price_ea_cents', 'quantity', 'merchant_notes', From 3dbb42530962fcd8192d2007ddad9ccd82c5006b Mon Sep 17 00:00:00 2001 From: John Malone Date: Mon, 28 Aug 2017 13:40:53 -0500 Subject: [PATCH 7/8] AP-5505 - fixing the hash order in the tests. --- tests/Apruve/OrderItemTest.php | 4 ++-- tests/Apruve/OrderTest.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Apruve/OrderItemTest.php b/tests/Apruve/OrderItemTest.php index 00e2849..b9900d3 100644 --- a/tests/Apruve/OrderItemTest.php +++ b/tests/Apruve/OrderItemTest.php @@ -37,7 +37,7 @@ public function testToJsonString() { $this->assertJsonStringEqualsJsonString( '{ "title": "A title", - "price_total_cents": 3400, + "amount_cents": 3400, "price_ea_cents": 3400, "quantity": 1, "merchant_notes": "some notes.", @@ -54,7 +54,7 @@ protected function setUp() { $this->item = new OrderItem( [ 'title' => 'A title', 'sku' => 'sku', - 'price_total_cents' => 3400, + 'amount_cents' => 3400, 'price_ea_cents' => 3400, 'quantity' => 1, 'merchant_notes' => 'some notes.', diff --git a/tests/Apruve/OrderTest.php b/tests/Apruve/OrderTest.php index f31095e..ed890d8 100644 --- a/tests/Apruve/OrderTest.php +++ b/tests/Apruve/OrderTest.php @@ -55,7 +55,7 @@ public function testToJson() { "payment_term": [], "order_items": [{ "title": "a title", - "price_total_cents": null, + "amount_cents": 4500, "price_ea_cents": null, "quantity": null, "merchant_notes": null, @@ -81,7 +81,7 @@ public function testToHashString() { public function testToSecureString() { $this->assertEquals( - 'asdf1234order12346000USD50010002014-07-15T10:12:27-05:00falsea title', + 'asdf1234order12346000USD50010002014-07-15T10:12:27-05:00falsea title4500', $this->po->toSecureString() ); } @@ -89,7 +89,7 @@ public function testToSecureString() { public function testToSecureHash() { Apruve\Client::init( 'a key', Apruve\Environment::DEV() ); $this->assertEquals( - hash( 'sha256', 'a keyasdf1234order12346000USD50010002014-07-15T10:12:27-05:00falsea title' ), + hash( 'sha256', 'a keyasdf1234order12346000USD50010002014-07-15T10:12:27-05:00falsea title4500' ), $this->po->toSecureHash() ); } From a6dcdac0591b2607eedf983d510e81305cec9349 Mon Sep 17 00:00:00 2001 From: John Malone Date: Tue, 29 Aug 2017 11:26:17 -0500 Subject: [PATCH 8/8] AP-5505 - bumping version number in the readme file. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c7308d..7386d3b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Please use [Github issues](https://github.com/apruve/apruve-php/issues) to reque Add this require to your `composer.json`: "require": { - "apruve/apruve-php": "~1.3" + "apruve/apruve-php": "~1.4" } **NOTE**: Be sure to update the version as you update the version of apruve-php