-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout.php
23 lines (22 loc) · 730 Bytes
/
checkout.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
require_once("vendor/braintree/braintree_php/lib/Braintree.php");
$amount = $_POST["amount"];
$nonce = $_POST["payment_method_nonce"];
$result = Braintree\Transaction::sale([
'amount' => $amount,
'paymentMethodNonce' => $nonce,
'options' => [
'submitForSettlement' => true
]
]);
if ($result->success || !is_null($result->transaction)) {
$transaction = $result->transaction;
header("Location: transaction.php?id=" . $transaction->id);
} else {
$errorString = "";
foreach($result->errors->deepAll() as $error) {
$errorString .= 'Error: ' . $error->code . ": " . $error->message . "\n";
}
$_SESSION["errors"] = $errorString;
header("Location: braintree-test.php");
}