forked from braintree/braintree_php_example
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreatecustomer.php
More file actions
39 lines (29 loc) · 873 Bytes
/
createcustomer.php
File metadata and controls
39 lines (29 loc) · 873 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
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require_once("../includes/braintree_init.php");
require_once("../includes/rest.php");
header('Content-Type: application/json');
$customer_id = 'vincenttestcustomer';
$params['id'] = $customer_id;
if (isset($request["payment_method_nonce"])) {
$params['paymentMethodNonce'] = $request["payment_method_nonce"];
}
$result = Braintree\Customer::create($params);
function object2array($object) {
$array = (array) $object;
foreach ($array as $key => $value) {
return $value;
}
return [];
}
$response["success"] = $result->success;
if ($result->success == 1) {
$response["customer"] = object2array($result->customer);
foreach($result->customer->creditCards as $card) {
$cards[] = object2array($card);
}
$response["customer"]["creditCards"] = $cards;
} else {
$response["error"] = $result->message;
}
echo json_encode($response, JSON_PRETTY_PRINT);
?>