-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprocess_checkout.php
More file actions
81 lines (52 loc) · 2.07 KB
/
process_checkout.php
File metadata and controls
81 lines (52 loc) · 2.07 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
Checkout processing with Marketcloud and Braintree payments
*/
// Questo è lo script php che accoglie la chiamata di creazione dell'ordine
$order_data = json_decode($_POST["order"]);
$order_response = Marketcloud\Orders::create($order_data);
$order = $order_response->body->data;
//Marketcloud\Marketcloud::$apiBaseUrl = 'http://localhost:5000/v0';
// Controlliamo che l'ordine sia andato a buon fine
if ($order_response->body->status !== true) {
// L'ordine è valido
} else {
// Per fare testing, braintree mette a disposizione una serie di "nonce"
// che possono dare risultati diversi
// ad esempio "fake-processor-declined-visa-nonce"
$payment_response = Marketcloud\Payments::create(array(
"order_id" => $order->id,
"method" => "Braintree",
//"nonce" => $_POST["braintree_nonce"],
"nonce" => "fake-valid-nonce"
//"nonce" => "fake-processor-declined-visa-nonce"
));
if ($payment_response->body->status !== true) {
// Pagamento fallito
// Possiamo decidere di annullare l'ordine
Marketcloud\Orders::delete($order->id);
//Riportiamo l'utente al checkout dicendo che l'ordine è fallito
$error_message = "Failed payment";
require_once("checkout_form.php");
} else {
//Pagamento riuscito
//
//Resettiamo il carrello
//creandone uno nuovo e salvandolo in sessione
$cart_response = Marketcloud\Carts::create(array());
$_SESSION["marketcloud_cart_id"] = $cart_response->body->data->id;
//Sending the notification
/*$response = \Httpful\Request::post('https://api.marketcloud.it/v0/notifications/confirm_order/'.$order->id)
->expectsJson()
->addHeader('Authorization',Marketcloud\Marketcloud::getAuthorizationHeader())
->send();
if ($response->body->status !== true){
echo "Unable to send notification to the client".json_encode($response->body);
}
// Now we have automatic notifications
*/
//Portiamo l'utente ad una pagina di conferma dell'ordine
require_once("order_confirmed.php");
}
}
?>