Skip to content

Commit

Permalink
Merge pull request #5 from apruve/AP-5505
Browse files Browse the repository at this point in the history
Ap 5505 - adding invoiceItems, shipment, shipmentItems, and changing the watchr
  • Loading branch information
Pro777 committed Jul 26, 2017
2 parents 34e89b3 + 8921e1c commit 42b6426
Show file tree
Hide file tree
Showing 14 changed files with 450 additions and 27 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.2"
"apruve/apruve-php": "~1.3"
}

**NOTE**: Be sure to update the version as you update the version of apruve-php
Expand All @@ -30,10 +30,10 @@ Then run `composer install`:

$ vendor/bin/phpunit tests/

If you'd like to contribute, use the watchr ruby gem to assist.
If you'd like to contribute, use the observr ruby gem to assist.

$ gem install watchr
$ watchr ./autotest_watchr.rb
$ gem install observr
$ watchr ./autotest_observr.rb


## Contributing
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"php": ">=5.3.0"
"php": ">=5.4.0"
},
"autoload": {
"psr-0": {
Expand Down
10 changes: 9 additions & 1 deletion src/Apruve/Invoice.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// Invoice
namespace Apruve;

Expand All @@ -19,6 +18,7 @@ class Invoice extends ApruveObject {
var $order_id;
var $status;
var $amount_cents;
var $price_total_cents;
var $currency;
var $merchant_notes;
var $api_url;
Expand Down Expand Up @@ -63,4 +63,12 @@ public function save() {
}
}

public function addInvoiceItem( $invoice_item ) {
if ( get_class( $invoice_item ) == 'Apruve\InvoiceItem' ) {
return array_push( $this->invoice_items, $invoice_item );
} else {
return false;
}
}

}
3 changes: 2 additions & 1 deletion src/Apruve/InvoiceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class InvoiceItem extends ApruveObject {
protected static $json_fields = [
'title',
'amount_cents',
'price_total_cents',
'quantity',
'price_ea_cents',
'merchant_notes',
Expand All @@ -19,7 +20,7 @@ class InvoiceItem extends ApruveObject {
'view_product_url',
];
var $title;
var $amount_cents;
var $price_total_cents;
var $quantity;
var $price_ea_cents;
var $merchant_notes;
Expand Down
3 changes: 3 additions & 0 deletions src/Apruve/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Order extends ApruveObject {
'tax_cents',
'shipping_cents',
'expire_at',
'invoice_on_create'
];
protected static $json_fields = [
'id',
Expand All @@ -24,6 +25,7 @@ class Order extends ApruveObject {
'tax_cents',
'shipping_cents',
'expire_at',
'invoice_on_create',
'order_items',
];
private static $UPDATE_PATH = '/orders/%s';
Expand All @@ -39,6 +41,7 @@ class Order extends ApruveObject {
var $shipping_cents;
var $currency;
var $expire_at;
var $invoice_on_create = 'false';
var $order_items = [];
var $api_url;
var $view_url;
Expand Down
105 changes: 105 additions & 0 deletions src/Apruve/Shipment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php
// Shipment
namespace Apruve;

require_once 'ApruveObject.php';

class Shipment extends ApruveObject {

protected static $SHIPMENTS_PATH = '/invoices/%s/shipments';
protected static $hash_order = [
'id',
'amount_cents',
'invoice_id',
'shipper',
'tracking_number',
'shipped_at',
'delivered_at',
'merchant_notes',
'uuid',
'created_at',
'currency',
'tax_cents',
'shipping_cents',
'merchant_invoice_id',
'shipment_items',
];
protected static $json_fields = [
'id',
'amount_cents',
'invoice_id',
'shipper',
'tracking_number',
'shipped_at',
'delivered_at',
'merchant_notes',
'uuid',
'created_at',
'currency',
'tax_cents',
'shipping_cents',
'status',
'merchant_shipment_id',
'shipment_items',
];
var $id;
var $amount_cents;
var $invoice_id;
var $shipper;
var $tracking_number;
var $shipped_at;
var $delivered_at;
var $merchant_notes;
var $uuid;
var $created_at;
var $currency;
var $tax_cents;
var $shipping_cents;
var $status;
var $merchant_shipment_id;
var $shipment_items = [];

public function __construct( $shipment = [], $client = null ) {
if ( array_key_exists( 'shipment_items', $shipment ) ) {
foreach ( $shipment['shipment_items'] as $key => $shipment_item ) {
if ( is_array( $shipment_item ) ) {
$shipment['shipment_items'][ $key ] = new ShipmentItem( $shipment_item );
}
}
}

parent::__construct( $shipment, $client );
}

public static function get( $invoice_id, $client = null ) {
if ( $client == null ) {
$client = new Client();
}
$response = $client->get( sprintf( self::$SHIPMENTS_PATH, $invoice_id ) );

if ( $response[0] == 200 ) {
return new self( $response[1], $client );
} else {
return $response[2];
}
}

public function save() {
$response = $this->client->post(
sprintf(
self::$SHIPMENTS_PATH, $this->invoice_id ), $this->toJson() );
if ( $response[0] == 201 ) {
return new self( $response[1], $this->client );
} else {
return $response[2];
}
}

public function addShipmentItem( $shipment_item ) {
if ( get_class( $shipment_item ) == 'Apruve\ShipmentItem' ) {
return array_push( $this->shipment_items, $shipment_item );
} else {
return false;
}
}
}
59 changes: 59 additions & 0 deletions src/Apruve/ShipmentItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
// Shipment Item
namespace Apruve;

require_once 'ApruveObject.php';

class ShipmentItem extends ApruveObject {

protected static $hash_order = [
'title',
'amount_cents',
'price_total_cents',
'quantity',
'price_ea_cents',
'merchant_notes',
'description',
'variant_info',
'sku',
'vendor',
'sku',
'view_product_url',
'shipping_cents',
'tax_cents',
'price_total_cents',
'currency',
];
protected static $json_fields = [
'title',
'amount_cents',
'price_total_cents',
'quantity',
'price_ea_cents',
'merchant_notes',
'description',
'variant_info',
'sku',
'vendor',
'sku',
'view_product_url',
'shipping_cents',
'tax_cents',
'price_total_cents',
'currency',
];
var $title;
var $amount_cents;
var $quantity;
var $price_ea_cents;
var $merchant_notes;
var $description;
var $variant_info;
var $sku;
var $vendor;
var $view_product_url;
var $shipping_cents;
var $tax_cents;
var $price_total_cents;
var $currency;
}
6 changes: 4 additions & 2 deletions src/Apruve/SubscriptionAdjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public static function get( $subscription_id, $subscription_adjustment_id, $clie
if ( $client == null ) {
$client = new Client();
}
$response = $client->get( sprintf( self::$SUBSCRIPTION_ADJUSTMENT_PATH, $subscription_id ) . $subscription_adjustment_id );
$response = $client->get( sprintf( self::$SUBSCRIPTION_ADJUSTMENT_PATH,
$subscription_id ) . $subscription_adjustment_id );
if ( $response[0] == 200 ) {
return new self( $response[1], $client );
} else {
Expand All @@ -49,7 +50,8 @@ public static function delete( $subscription_id, $subscription_adjustment_id, $c
if ( $client == null ) {
$client = new Client();
}
$response = $client->delete( sprintf( self::$SUBSCRIPTION_ADJUSTMENT_PATH, $subscription_id ) . $subscription_adjustment_id );
$response = $client->delete( sprintf( self::$SUBSCRIPTION_ADJUSTMENT_PATH,
$subscription_id ) . $subscription_adjustment_id );
if ( $response[0] == 200 ) {
return new self( $response[1], $client );
} else {
Expand Down
24 changes: 13 additions & 11 deletions tests/Apruve/InvoiceItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function testPropertiesAreDefined() {

$this->assertEquals( array_keys( $item_vars ), array(
'title',
'amount_cents',
'price_total_cents',
'quantity',
'price_ea_cents',
'merchant_notes',
Expand All @@ -29,6 +29,7 @@ public function testToJsonString() {
'{
"title": "A title",
"amount_cents": 3400,
"price_total_cents": 3400,
"quantity": 1,
"price_ea_cents": 3400,
"merchant_notes": "some notes.",
Expand All @@ -43,16 +44,17 @@ public function testToJsonString() {

protected function setUp() {
$this->item = new InvoiceItem( [
'title' => 'A title',
'amount_cents' => 3400,
'quantity' => 1,
'price_ea_cents' => 3400,
'merchant_notes' => 'some notes.',
'description' => 'a description.',
'variant_info' => 'some variation.',
'sku' => 'a sku',
'vendor' => 'ACME',
'view_product_url' => 'A Url.',
'title' => 'A title',
'amount_cents' => 3400,
'price_total_cents' => 3400,
'quantity' => 1,
'price_ea_cents' => 3400,
'merchant_notes' => 'some notes.',
'description' => 'a description.',
'variant_info' => 'some variation.',
'sku' => 'a sku',
'vendor' => 'ACME',
'view_product_url' => 'A Url.',
], $this->getMockBuilder( 'Apruve\Client' )
->setConstructorArgs( [ 'a key', Apruve\Environment::DEV() ] )
->getMock()
Expand Down
7 changes: 5 additions & 2 deletions tests/Apruve/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function testPropertiesAreDefined() {
'order_id',
'status',
'amount_cents',
'price_total_cents',
'currency',
'merchant_notes',
'api_url',
Expand All @@ -25,7 +26,7 @@ public function testPropertiesAreDefined() {
'updated_at',
'invoice_items',
] );
$this->assertEquals( 11, count( $vars ) );
$this->assertEquals( 12, count( $vars ) );

}

Expand All @@ -46,7 +47,8 @@ public function testToJson() {
"variant_info": null,
"sku": null,
"vendor": null,
"view_product_url": null
"view_product_url": null,
"price_total_cents": null
}
]
}',
Expand Down Expand Up @@ -123,6 +125,7 @@ protected function setUp() {
'amount_cents' => 100,
'quantity' => 1,
'price_ea_cents' => 100

]
]
] );
Expand Down
Loading

0 comments on commit 42b6426

Please sign in to comment.