-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from apruve/AP-5505
Ap 5505 - adding in offline ordering and corporate account lookup
- Loading branch information
Showing
9 changed files
with
283 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
// Invoice | ||
namespace Apruve; | ||
|
||
require_once 'ApruveObject.php'; | ||
|
||
class CorporateAccount extends ApruveObject { | ||
|
||
protected static $ACCOUNTS_PATH = '/merchants/%s/corporate_accounts'; | ||
protected static $hash_order = []; | ||
protected static $json_fields = [ | ||
'id', | ||
'customer_uuid', | ||
'merchant_uuid', | ||
'type', | ||
'payment_term_strategy_name', | ||
'name', | ||
'authorized_buyers', | ||
]; | ||
|
||
var $id; | ||
var $customer_uuid; | ||
var $merchant_uuid; | ||
var $type; | ||
var $payment_term_strategy_name; | ||
var $name; | ||
var $authorized_buyers = []; | ||
|
||
public static function get( $merchant_key, $email, $client = null ) { | ||
if ( $client == null ) { | ||
$client = new Client(); | ||
} | ||
$response = $client->get( sprintf( self::$ACCOUNTS_PATH, $merchant_key ) . '?email=' . $email ); | ||
|
||
if ( $response[0] == 200 ) { | ||
return new self( array_pop( $response[1] ), $client ); | ||
} else { | ||
return $response[2]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
require_once dirname( __FILE__ ) . '/../../src/Apruve/CorporateAccount.php'; | ||
require_once dirname( __FILE__ ) . '/../../src/Apruve/Client.php'; | ||
require_once dirname( __FILE__ ) . '/../../src/Apruve/Environment.php'; | ||
|
||
use Apruve\CorporateAccount; | ||
|
||
class CorporateAccountTest extends PHPUnit_Framework_TestCase { | ||
|
||
public function testPropertiesAreDefined() { | ||
$vars = get_class_vars( get_class( $this->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": "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() | ||
); | ||
} | ||
|
||
public function testGet() { | ||
$client = $this->getMockBuilder( 'Apruve\Client' ) | ||
->setMethods( [ 'get' ] ) | ||
->getMock(); | ||
$client->expects( $this->Once() ) | ||
->method( 'get' ) | ||
->with( $this->equalTo( '/merchants/asdf1234/corporate_accounts?email=corporateuser@apruve.com' ) ) | ||
->will( $this->returnValue( [ | ||
200, | ||
[ | ||
[ | ||
'id' => 'asdf1234', | ||
'customer_uuid' => 'b76ac505389e7814eb10fb4fdc33a50b', | ||
'merchant_uuid' => '5ca2ab51d10b490cba7b22934c9fe913', | ||
'type' => 'corporate', | ||
'payment_term_strategy_name' => 'Net30', | ||
'name' => 'MyCorporateAccount', | ||
] | ||
] | ||
] ) | ||
); | ||
|
||
$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( [ | ||
'id' => 'asdf1234', | ||
'customer_uuid' => 'b76ac505389e7814eb10fb4fdc33a50b', | ||
'merchant_uuid' => '5ca2ab51d10b490cba7b22934c9fe913', | ||
'type' => 'corporate', | ||
'payment_term_strategy_name' => 'Net30', | ||
'authorized_buyers' => [ | ||
[ | ||
'id' => 'd9e10e59140513b61998e292088c8194', | ||
'name' => 'Corporate Corbin', | ||
'email' => 'corporateuser@apruve.com' | ||
] | ||
], | ||
'name' => 'MyCorporateAccount' | ||
] ); | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.