Repository navigation
Expand file tree
/
Copy pathSendOrderExample.php
More file actions
66 lines (58 loc) · 1.78 KB
/
Copy pathSendOrderExample.php
File metadata and controls
66 lines (58 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
include __DIR__ . '/../vendor/autoload.php';
use PennyBlack\Api;
use PennyBlack\Exception\PennyBlackException;
use PennyBlack\Model\Order;
use PennyBlack\Model\Customer;
use GuzzleHttp\Psr7\HttpFactory;
use GuzzleHttp\Client;
$httpClient = new Client();
$streamFactory = new HttpFactory();
$requestFactory = new HttpFactory();
$apiKey = 'YOUR-API-KEY';
$isTest = true;
$api = new Api($httpClient, $requestFactory, $streamFactory, $apiKey, $isTest);
$order = new Order();
$order
->setId('1')
->setNumber('#100001')
->setCreatedAt(new \DateTime())
->setCurrency('GBP')
->setTotalAmount(123.45)
->setTotalItems(2)
->setBillingCity('London')
->setBillingCountry('GB')
->setBillingPostcode('SE15AB')
->setShippingCity('London')
->setShippingCountry('GB')
->setShippingPostcode('SE15AB')
->setGiftMessage('I hope you enjoy the socks, love Mum. xxx')
->setGiftMessageRecipient('Tim')
->setProductTitles(['Red Socks', 'Blue Socks'])
->setPromoCodes(['15OFF_SOCKS'])
->setSkus(['SK-R-1', 'SK-B-1'])
->setSubscriptionReorder(false)
->setTags(['tiktok order'])
->setAttributes([
'attribute1' => 'value1',
'attribute2' => 'value2',
]);
$customer = new Customer();
$customer->setEmail('john.doe@example.com')
->setFirstName('John')
->setLastName('Doe')
->setLanguage('en')
->setMarketingConsent(true)
->setVendorCustomerId('89714912')
->setTags(['VIP', 'Loyal Customer'])
->setTotalOrders(5)
->setTotalSpent(1234.56)
->setAttributes([
'customer_att1' => 'value1',
'customer_att2' => 'value2',
]);
try {
$api->sendOrder($order, $customer, 'magento', '1.0.1');
} catch (PennyBlackException $e) {
print 'OOPS! Something went wrong: ' . $e->getMessage();
}