forked from braintree/braintree_php_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout.php
More file actions
27 lines (22 loc) · 710 Bytes
/
checkout.php
File metadata and controls
27 lines (22 loc) · 710 Bytes
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
<?php
require_once("../includes/braintree_init.php");
$amount = $_POST["amount"];
$nonce = $_POST["payment_method_nonce"];
$result = $gateway->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: index.php");
}