Skip to content

Commit 0d4a758

Browse files
authored
Merge pull request #2 from h2akim/fulfillment_order_implementation
✨ Fulfillment order implementation
2 parents f93e9eb + 1e31c0f commit 0d4a758

11 files changed

+440
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"fulfillments": [
3+
{
4+
"id": 255858046,
5+
"order_id": 450789469,
6+
"status": "failure",
7+
"created_at": "2017-10-16T16:02:08-04:00",
8+
"service": "manual",
9+
"updated_at": "2017-10-16T16:02:08-04:00",
10+
"tracking_company": null,
11+
"shipment_status": null,
12+
"tracking_number": "1Z2345",
13+
"tracking_numbers": [
14+
"1Z2345"
15+
],
16+
"tracking_url": "http:\/\/wwwapps.ups.com\/etracking\/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track",
17+
"tracking_urls": [
18+
"http:\/\/wwwapps.ups.com\/etracking\/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track"
19+
],
20+
"receipt": {
21+
"testcase": true,
22+
"authorization": "123456"
23+
},
24+
"line_items": [
25+
{
26+
"id": 466157049,
27+
"variant_id": 39072856,
28+
"title": "IPod Nano - 8gb",
29+
"quantity": 1,
30+
"price": "199.00",
31+
"grams": 200,
32+
"sku": "IPOD2008GREEN",
33+
"variant_title": "green",
34+
"vendor": null,
35+
"fulfillment_service": "manual",
36+
"product_id": 632910392,
37+
"requires_shipping": true,
38+
"taxable": true,
39+
"gift_card": false,
40+
"name": "IPod Nano - 8gb - green",
41+
"variant_inventory_management": "shopify",
42+
"properties": [
43+
{
44+
"name": "Custom Engraving Front",
45+
"value": "Happy Birthday"
46+
},
47+
{
48+
"name": "Custom Engraving Back",
49+
"value": "Merry Christmas"
50+
}
51+
],
52+
"product_exists": true,
53+
"fulfillable_quantity": 1,
54+
"total_discount": "0.00",
55+
"fulfillment_status": null,
56+
"tax_lines": [
57+
{
58+
"title": "State Tax",
59+
"price": "3.98",
60+
"rate": 0.06
61+
}
62+
]
63+
}
64+
]
65+
}
66+
]
67+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"fulfillment_order": {
3+
"id": 1046000778,
4+
"shop_id": 548380009,
5+
"order_id": 450789469,
6+
"assigned_location_id": 24826418,
7+
"request_status": "submitted",
8+
"status": "open",
9+
"supported_actions": [
10+
"cancel_fulfillment_order"
11+
],
12+
"destination": {
13+
"id": 1046000778,
14+
"address1": "Chestnut Street 92",
15+
"address2": "",
16+
"city": "Louisville",
17+
"company": null,
18+
"country": "United States",
19+
"email": "[email protected]",
20+
"first_name": "Bob",
21+
"last_name": "Norman",
22+
"phone": "+1(502)-459-2181",
23+
"province": "Kentucky",
24+
"zip": "40202"
25+
},
26+
"line_items": [
27+
{
28+
"id": 1058737482,
29+
"shop_id": 548380009,
30+
"fulfillment_order_id": 1046000778,
31+
"quantity": 1,
32+
"line_item_id": 518995019,
33+
"inventory_item_id": 49148385,
34+
"fulfillable_quantity": 1,
35+
"variant_id": 49148385
36+
}
37+
],
38+
"fulfillment_service_handle": "mars-fulfillment",
39+
"assigned_location": {
40+
"address1": null,
41+
"address2": null,
42+
"city": null,
43+
"country_code": "DE",
44+
"location_id": 24826418,
45+
"name": "Apple Api Shipwire",
46+
"phone": null,
47+
"province": null,
48+
"zip": null
49+
},
50+
"merchant_requests": []
51+
}
52+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Shopify\Enum\Fields;
4+
5+
class AssignedLocationFields extends AbstractObjectEnum
6+
{
7+
public const LOCATION_ID = 'location_id'; // ✅
8+
public const NAME = 'name'; // ✅
9+
public const ADDRESS1 = 'address1'; // ✅
10+
public const ADDRESS2 = 'address2'; // ✅
11+
public const CITY = 'city'; // ✅
12+
public const ZIP = 'zip'; // ✅
13+
public const PROVINCE = 'province'; // ✅
14+
public const COUNTRY_CODE = 'country_code'; // ✅
15+
public const PHONE = 'phone'; // ✅
16+
17+
public function getFieldTypes()
18+
{
19+
return [
20+
'location_id' => 'integer',
21+
'name' => 'string',
22+
'address1' => 'string',
23+
'address2' => 'string',
24+
'city' => 'string',
25+
'zip' => 'string',
26+
'province' => 'string',
27+
'country_code' => 'string',
28+
'phone' => 'string'
29+
];
30+
}
31+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Shopify\Enum\Fields;
4+
5+
class DestinationLocationFields extends AbstractObjectEnum
6+
{
7+
public const ID = 'id'; // ✅
8+
public const ADDRESS1 = 'address1'; // ✅
9+
public const ADDRESS2 = 'address2'; // ✅
10+
public const CITY = 'city'; // ✅
11+
public const COMPANY = 'company'; // ✅
12+
public const COUNTRY = 'country'; // ✅
13+
public const EMAIL = 'email'; // ✅
14+
public const FIRST_NAME = 'first_name'; // ✅
15+
public const LAST_NAME = 'last_name'; // ✅
16+
public const PHONE = 'phone'; // ✅
17+
public const PROVINCE = 'province'; // ✅
18+
public const ZIP = 'zip'; // ✅
19+
20+
public function getFieldTypes()
21+
{
22+
return [
23+
'id' => 'integer',
24+
'address1' => 'string',
25+
'address2' => 'string',
26+
'city' => 'string',
27+
'company' => 'string',
28+
'country' => 'string',
29+
'email' => 'string',
30+
'first_name' => 'string',
31+
'last_name' => 'string',
32+
'phone' => 'string',
33+
'province' => 'string',
34+
'zip' => 'string',
35+
];
36+
}
37+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Shopify\Enum\Fields;
4+
5+
class FulfillmentOrderFields extends AbstractObjectEnum
6+
{
7+
public const ID = 'id';
8+
public const ORDER_ID = 'order_id';
9+
public const SHOP_ID = 'shop_id';
10+
public const ASSIGNED_LOCATION_ID = 'assigned_location_id';
11+
public const STATUS = 'status';
12+
public const SUPPORTED_ACTIONS = 'supported_actions';
13+
public const DESTINATION = 'destination';
14+
public const LINE_ITEMS = 'line_items';
15+
public const FULFILLMENT_SERVICE_BUNDLE = 'fulfillment_service_handle';
16+
public const ASSIGNED_LOCATION = 'assigned_location';
17+
public const MERCHANT_REQUESTS = 'merchant_requests';
18+
19+
public function getFieldTypes()
20+
{
21+
return array(
22+
'id' => 'integer',
23+
'order_id' => 'integer',
24+
'shop_id' => 'integer',
25+
'assigned_location_id' => 'integer',
26+
'status' => 'string',
27+
"supported_actions" => 'array',
28+
"destination" => 'DestinationLocation', // Probably need new fields
29+
'line_items' => 'LineItem[]',
30+
'fulfillment_service_handle' => 'string',
31+
"assigned_location" => 'AssignedLocation', // Probably need new fields
32+
"merchant_requests" => 'array', // Probably need new fields
33+
);
34+
}
35+
}

src/Enum/FulfillmentHoldReason.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Shopify\Enum;
4+
5+
class FulfillmentHoldReason
6+
{
7+
public const AWAITING_PAYMENT = 'awaiting_payment';
8+
public const HIGH_RISK_OF_FRAUD = 'high_risk_of_fraud';
9+
public const INCORRECT_ADDRESS = 'incorrect_address';
10+
public const INVENTORY_OUT_OF_STOCK = 'inventory_out_of_stock';
11+
public const OTHER = 'other';
12+
}

src/Object/AssignedLocation.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Shopify\Object\AssignedLocation
4+
*/
5+
6+
namespace Shopify\Object;
7+
8+
use Shopify\Enum\Fields\AssignedLocationFields;
9+
10+
class AssignedLocation extends AbstractObject
11+
{
12+
public static function getFieldsEnum()
13+
{
14+
return AssignedLocationFields::getInstance();
15+
}
16+
}

src/Object/DestinationLocation.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Shopify\Object\DestinationLocation
4+
*/
5+
6+
namespace Shopify\Object;
7+
8+
use Shopify\Enum\Fields\DestinationLocationFields;
9+
10+
class DestinationLocation extends AbstractObject
11+
{
12+
public static function getFieldsEnum()
13+
{
14+
return DestinationLocationFields::getInstance();
15+
}
16+
}

src/Object/FulfillmentOrder.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Shopify\Object;
4+
5+
use InvalidArgumentException;
6+
use Shopify\Enum\Fields\FulfillmentOrderFields;
7+
use Shopify\Enum\FulfillmentHoldReason;
8+
9+
class FulfillmentOrder extends AbstractObject
10+
{
11+
public static function getFieldsEnum()
12+
{
13+
return FulfillmentOrderFields::getInstance();
14+
}
15+
16+
public static function isValidHoldReason($reason)
17+
{
18+
if (!in_array($reason, [
19+
FulfillmentHoldReason::AWAITING_PAYMENT,
20+
FulfillmentHoldReason::HIGH_RISK_OF_FRAUD,
21+
FulfillmentHoldReason::INCORRECT_ADDRESS,
22+
FulfillmentHoldReason::INVENTORY_OUT_OF_STOCK,
23+
FulfillmentHoldReason::OTHER,
24+
])) {
25+
throw new InvalidArgumentException('Invalid fulfillment hold reason provided.');
26+
}
27+
28+
return $reason;
29+
}
30+
}

0 commit comments

Comments
 (0)