Skip to content

Instantly share code, notes, and snippets.

@abhij89
Last active October 11, 2023 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhij89/55d481944571cf4d9489423a3f18b236 to your computer and use it in GitHub Desktop.
Save abhij89/55d481944571cf4d9489423a3f18b236 to your computer and use it in GitHub Desktop.
Stripe Calls
// Creating customer:
$customer = $this->stripeClient->customers->all( [ 'email' => auth()->user()->email ] );
if ( empty( $customer->data[0] ) ) {
// Create new customer
$customer = $this->stripeClient->customers->create( array(
"email" => auth()->user()->email,
"name" => auth()->user()->first_name . ' ' . auth()->user()->last_name,
) );
$customerID = $customer->id;
} else {
$customerID = $customer->data[0]->id;
}
// Stripe connect express account login link
$connectLoginLinkObj = $this->stripeClient->accounts->createLoginLink(auth()->user()->stripe_connect_id, []);
if(!empty($connectLoginLinkObj->url)) {
$connectLoginLink = $connectLoginLinkObj->url;
}
// Create payment intent before initiating payment
$intent = $this->stripeClient->paymentIntents->create( [
"amount" => "some-amount",
"currency" => "usd",
"customer" => $customerID,
'automatic_payment_methods' => [ 'enabled' => true ],
"description" => "Payment for the campaign " . $campaign->name . " from " . $campaign->owner->name . " for " . $campaign->videos . " creator video(s)"
] );
// Confirm payment status
if ( $request->get( 'redirect_status' ) == 'succeeded' ) {
Session::flash( 'message', 'Your payment was successful, and your campaign has been created.' );
} elseif ( $request->get( 'redirect_status' ) == 'payment_failed' ) {
Session::flash( 'error', 'Payment failed. Please try again later.' );
} elseif ( $request->get( 'redirect_status' ) == 'processing' ) {
Session::flash( 'info', 'Payment is still processing. Please wait for few minutes or try again later.' );
} else {
Session::flash( 'info', 'Something went wrong. Please try again later.' );
}
// Transfer
$transfer = $this->stripeClient->transfers->create([
'amount' => 100, // Get it from creator price agreement
'currency' => 'usd',
'destination' => "customer_stripe_connect_id"
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment