-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_customer.php
41 lines (36 loc) · 1.05 KB
/
create_customer.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
<?php
/*
Author:Minhazul Min
Website: https://minhazulmin.github.io/
*/
require_once 'stripe_header.php';
$payment_intent_id = !empty( $jsonObj->payment_intent_id ) ? $jsonObj->payment_intent_id : '';
$fullname = !empty( $jsonObj->fullname ) ? $jsonObj->fullname : '';
$email = !empty( $jsonObj->email ) ? $jsonObj->email : '';
// Add new customer fullname and email to stripe
try {
$customer = \Stripe\Customer::create( [
'name' => $fullname,
'email' => $email,
] );
} catch ( Exception $e ) {
$error = $e->getMessage();
}
if ( empty( $error ) && !empty( $customer ) ) {
try {
// Attach Customer Data with PaymentIntent using customer ID
\Stripe\PaymentIntent::update( $payment_intent_id, [
'customer' => $customer->id,
] );
} catch ( Exception $e ) {
$error = $e->getMessage();
}
$output = [
'customer_id' => $customer->id,
];
echo json_encode( $output );
} else {
http_response_code( 500 );
echo json_encode( ['error' => $error] );
}
?>