forked from acolono/php-magento-api-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplace-order.php
89 lines (80 loc) · 2.45 KB
/
place-order.php
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
require_once 'api.php';
// The URL to your Magento 2 instance (ending with /index.php/rest/V1)
$api_url = 'http://your-domain.com/index.php/rest/V1';
// Set the integrations access token.
$token = 'your_access_token';
// Fill in the SKU of the product which should be ordered.
$sku = '24-WB04';
$magento = new MagentoClient($token, $api_url);
if (isset($_GET['cartId']) && !empty($_GET['cartId']))
{
$cart = $_GET['cartId'];
}
else
{
$cart = $magento->createCart();
$cart = str_replace('"', '', $cart);
$order_filled = $magento->addToCart($cart, $sku, 1);
// var_dump($order_filled);
$ship_to = array (
'addressInformation' =>
array (
'shippingAddress' =>
array (
'region' => 'Wien',
'region_id' => 95,
'country_id' => 'AT',
'street' =>
array (
0 => 'Fillgradergasse 12-14/1a',
),
'company' => 'acolono GmbH',
'telephone' => '1111111',
'postcode' => '1060',
'city' => 'Vienna',
'firstname' => 'Martin',
'lastname' => 'Testman',
'email' => '[email protected]',
'prefix' => 'address_',
'region_code' => 'W',
'sameAsBilling' => 1,
),
'billingAddress' =>
array (
'region' => 'Wien',
'region_id' => 95,
'country_id' => 'AT',
'street' =>
array (
0 => 'Fillgradergasse 12-14/1a',
),
'company' => 'acolono GmbH',
'telephone' => '1111111',
'postcode' => '1060',
'city' => 'Vienna',
'firstname' => 'Martin',
'lastname' => 'Testman',
'email' => '[email protected]',
'prefix' => 'address_',
'region_code' => 'W',
),
'shipping_method_code' => 'flatrate',
'shipping_carrier_code' => 'flatrate',
),
);
$order_shipment = $magento->setShipping($cart, $ship_to);
// var_dump($order_shipment);
if(!defined('STDIN'))
{
echo json_encode(["cartId" => $cart]);
return;
}
}
//$payment = $magento->getPaymentMethods($cart);
//var_dump($payment);
$additionalData = [
"cc_stripejs_token" => "pm_card_visa" // Use pm_card_threeDSecureRequired for 3D Secure authentication
];
$ordered = $magento->placeOrder($cart, 'stripe_payments', $additionalData);
echo "Order ID: $ordered";