daily pastebin goal
7%
SHARE
TWEET

Stripe charge creation

a guest Sep 30th, 2015 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function auth($reservation_id, $token, $beneficiary_stripe_account_id, $amount_in_dollars, $is_app_fee_applied = null)
  2.     {
  3.         \Stripe\Stripe::setApiKey(STRIPE_SECRET_KEY);
  4.  
  5.         $amount_in_cents = $amount_in_dollars * 100;
  6.  
  7.         $payment_details = [
  8.             'amount'            => $amount_in_cents,
  9.             'currency'          => 'usd',
  10.             'capture'           => false,
  11.             'source'            => $token,
  12.             'description'       => 'description',
  13.         ];
  14.  
  15.         if ($is_app_fee_applied) {
  16.             $payment_details['application_fee'] = ceil($amount_in_cents * 0.121 - 30);
  17.         }
  18.  
  19.         $payment_headers = [
  20.             'stripe_account' => $beneficiary_stripe_account_id,
  21.         ];
  22.  
  23.         try {
  24.             return \Stripe\Charge::create($payment_details, $payment_headers);
  25.         }
  26.         catch (\Stripe\Error\Card $e) {
  27.             return $e->getJsonBody()['error']['message'];
  28.         }
  29.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top