/** * Create and send the request * * @param array $options array of options to be send in POST request * @return gateway_response response object * */ public function send($options, $type = '') { $result = ''; try { if ($type == 'subscription') { $result = Stripe_Customer::create($options); } elseif ($type == 'plan') { $result = Stripe_Plan::create($options); } elseif ($type == 'retrieve') { $result = Stripe_Plan::retrieve($options); } elseif ($type == 'customer') { $result = Stripe_Customer::create($options); } elseif ($type == 'invoice') { $result = Stripe_InvoiceItem::create($options); // Stripe_Customer::invoiceItems($options); } elseif ($type == 'cancel') { $cu = Stripe_Customer::retrieve($options['customer']); $result = $cu->cancelSubscription(); } else { $result = Stripe_Charge::create($options); } } catch (Exception $ex) { $result = $ex; } $response = new stripe_response($result); return $response; }
public function indexAction(Request $request, $id) { // Vérifier que l'utilisateur a le droit de supprimer ce contrat // Set your secret key: remember to change this to your live secret key in production // See your keys here https://dashboard.stripe.com/account/apikeys $request = $this->container->get('request'); $message = ''; if ($request->isMethod('POST')) { \Stripe::setApiKey('sk_test_GyiB2fCxy62ydudovWhyyp6H'); $token = $request->get('stripeToken'); $customer = \Stripe_Customer::create(array('email' => '*****@*****.**', 'card' => $token)); $charge = \Stripe_Charge::create(array('customer' => $customer->id, 'amount' => 700, 'currency' => 'eur')); return $this->redirectToRoute("app_front_office_resiliation_preview", array("id" => $id)); } return $this->render('AppFrontOfficeBundle:Payment:index.html.twig', array("message" => $message)); }
/** * Prepare stripe data for processing. */ function fwd_stripe_prepare($data, $settings) { // Load stripe library? if (!class_exists('Stripe')) { require_once dirname(__FILE__) . '/stripe/lib/Stripe.php'; } // Set API key. Stripe::setApiKey($settings['secret_key']); $order = get("/orders/{$data['order_id']}"); $stripe = $order['billing']['stripe']; // Need to convert token to customer? if ($stripe['object'] == "token") { if ($stripe['used'] == 'true') { throw new Exception('Stripe token already used'); } $customer = Stripe_Customer::create(array('description' => $order['billing']['name'], 'card' => $stripe['id'])); $billing['stripe'] = $customer->__toArray(true); $billing['card'] = $billing['stripe']['active_card']; unset($billing['stripe']['active_card']); // Update order. put($order, array('billing' => $billing)); // Update account billing also? if (($account_billing = $order['account']['billing']) && $account_billing['method'] == 'card' && $account_billing['stripe']['id'] == $stripe['id']) { $account_billing['stripe'] = $billing['stripe']; $account_billing['card'] = $billing['card']; put($order['account'], array('billing' => $account_billing)); } } return $data; }
/** * @method POST */ function pay() { // get token $token = Utilities::ValidateJWTToken(apache_request_headers()); // check if token is not null if ($token != NULL) { // parse request parse_str($this->request->data, $request); $site = Site::GetBySiteId($token->SiteId); $siteId = $site['SiteId']; $email = $site['PrimaryEmail']; $status = 'Active'; $stripe_token = $request['token']; $plan = $request['plan']; // set API key Stripe::setApiKey(STRIPE_SECRET_KEY); // create a new customer and subscribe them to the plan $customer = Stripe_Customer::create(array("card" => $stripe_token, "plan" => $plan, "email" => $email)); // get back the id and the end period for the plan $id = $customer->id; // get subscription information $subscription = $customer->subscriptions->data[0]; $subscriptionId = $subscription->id; $stripe_status = $subscription->status; $stripe_plan = $subscription->plan->id; $stripe_planname = $subscription->plan->name; // subscribe to a plan Site::Subscribe($siteId, $status, $plan, 'stripe', $subscriptionId, $customerId); // return a json response return new Tonic\Response(Tonic\Response::OK); } else { return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
public function create() { if ($_POST) { $customer = Stripe_Customer::create(array('email' => $_POST['email'])); foreach ($_POST as $key => $value) { $_POST[$key] = urldecode($value); } include OTHERS . "PasswordHash.php"; $new_password = $_POST['password']; $salt = $this->_get_random_string(16); $hashed_password = create_hash($new_password . $salt); $stateSplit = explode(' - ', $_POST['state']); $key = $this->_get_random_string(50); $user = array('firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'password' => $hashed_password, 'salt' => $salt, 'phone' => $_POST['phone'], 'email' => $_POST['email'], 'country' => $_POST['country'], 'state' => $stateSplit[1], 'state_abbr' => $stateSplit[0], 'confirmation_key' => $key, 'stripe_customer_id' => $customer->id); if (isset($_POST['reg_plan_id'])) { $user['stripe_reg_plan_id'] = $_POST['reg_plan_id']; } else { $this->load->model('settings_model'); $general = transformArrayToKeyValue($this->settings_model->get(array('category' => 'general'))); $this->load->model('package_model'); $package = $this->package_model->getPackage($general['trial_period_package']->v); $user['stripe_reg_plan_id'] = $package->stripe_plan_id; } if ($this->user_model->add($user)) { echo "OK"; } } else { $this->index(); } }
/** * Function to update the customerinformation with customer id * Cases when card expired or new card. * @param Tokne id users strip token id * @param user id * @param amount to charge * @param description */ public function UpdateExistingCustomer($customerId, $token, $name, $amount, $description = "") { $this->setAPIKey(); $cu = Stripe_Customer::retrieve($customerId); $rr = json_decode($cu, true); //echo'<pre>';print_r($rr);echo'</pre>';die(); $r = $rr['error']['message']; $error_code = $rr['error']['code']; $error_type = $rr['error']['type']; //echo $error_code.'------------'.$error_type.'<br />'; if (empty($error_type) && empty($error_code)) { $cu->card = $token; if (!empty($description)) { $cu->description = $description; } $cu->save(); $result = Stripe_Charge::create(array("amount" => "{$amount}", "currency" => "usd", "customer" => "{$customerId}")); if ($result['paid'] === true) { $result_array = array("success" => "1"); return $result_array; } else { return $result; } } else { $result_array = array("update" => "1"); return $result_array; } }
/** * @method POST */ function pay() { // parse request parse_str($this->request->data, $request); $token = $request['token']; $plan = $request['plan']; // get an authuser $authUser = new AuthUser(); if (isset($authUser->UserUniqId)) { // check if authorized Stripe::setApiKey(STRIPE_API_KEY); // create a new customer and subscribe them to the plan $customer = Stripe_Customer::create(array("card" => $token, "plan" => $plan, "email" => $authUser->Email)); // get back the id and the end period for the plan $id = $customer->id; $end = $customer->subscription->current_period_end; // #debug print 'end='.$end; date_default_timezone_set('UTC'); // create a date from the timestamp returned by Stripe $renewalDate = gmdate("Y-m-d H:i:s", intval($end)); // #debug print ' renewalDate='.$renewalDate; // by default, you should not have to update a payment $updatePayment = 0; // update the db and session Site::SetSubscription($authUser->SiteUniqId, $plan, $id, $renewalDate, $updatePayment); AuthUser::SetPlan($plan, $renewalDate, $updatePayment); // return a json response return new Tonic\Response(Tonic\Response::OK); } else { return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
public static function updateSubscription($service, $customerId, $plan) { \Stripe::setApiKey($service['stripe']['secret_key']); $customer = \Stripe_Customer::retrieve($customerId); $customer->updateSubscription(array("plan" => $plan, "prorate" => true)); return ['id' => $customer->subscription->plan->id, 'name' => $customer->subscription->plan->name]; }
function email_transfer_failed($transfer) { $customer = Stripe_Customer::retrieve($transfer->customer); $subject = 'Your transfer was failed'; $headers = 'From: "Brandbits Support" <*****@*****.**>'; mail($customer->email, $subject, message_body(), $headers); }
static function pay($currency) { global $wpdb, $user_ID, $user_email; $_course = new NamasteLMSCourseModel(); $token = $_POST['stripeToken']; $course = get_post($_POST['course_id']); $fee = get_post_meta($course->ID, 'namaste_fee', true); $fee = apply_filters('namaste-coupon-applied', $fee); // coupon code from other plugin? try { $customer = Stripe_Customer::create(array('email' => $user_email, 'card' => $token)); $charge = Stripe_Charge::create(array('customer' => $customer->id, 'amount' => $fee * 100, 'currency' => $currency)); } catch (Exception $e) { wp_die($e->getMessage()); } // !!!!in the next version avoid this copy-paste // almost the same code is in models/payment.php for the paypal payments $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_PAYMENTS . " SET \n\t\t\t\t\t\tcourse_id=%d, user_id=%s, date=CURDATE(), amount=%s, status='completed', paycode=%s, paytype='stripe'", $_POST['course_id'], $user_ID, $fee, $token)); do_action('namaste-paid', $user_ID, $fee, "course", $_POST['course_id']); // enroll accordingly to course settings - this will be placed in a method once we // have more payment options $enroll_mode = get_post_meta($course->ID, 'namaste_enroll_mode', true); if (!NamasteLMSStudentModel::is_enrolled($user_ID, $course->ID)) { $status = $enroll_mode == 'free' ? 'enrolled' : 'pending'; $_course->enroll($user_ID, $course->ID, $status); } }
public function confirm() { $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); $amount = (int) ($this->currency->format($order_info['total'], $order_info['currency_code'], 1.0, false) * 100); //Load Stripe Library require_once './vendor/stripe/stripe-php/lib/Stripe.php'; if ($this->config->get('stripe_payments_mode') == 'live') { $stripe = array("secret_key" => $this->config->get('stripe_payments_private_key'), "publishable_key" => $this->config->get('stripe_payments_public_key')); } else { $stripe = array("secret_key" => $this->config->get('stripe_payments_private_key_test'), "publishable_key" => $this->config->get('stripe_payments_public_key_test')); } Stripe::setApiKey($stripe['secret_key']); $token = $_POST['stripeToken']; $error = null; try { $customer = Stripe_Customer::create(array('email' => $order_info['email'], 'card' => $token)); $charge = Stripe_Charge::create(array('customer' => $customer->id, 'amount' => $amount, 'currency' => $order_info['currency_code'], 'metadata' => array('order_id' => $this->session->data['order_id'], 'customer' => $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'], 'email' => $order_info['email'], 'phone' => $order_info['telephone']), 'description' => 'Order ID# ' . $this->session->data['order_id'])); } catch (Stripe_CardError $e) { // Error card processing $error = $e->jsonBody['error']; } //create object to use as json $json = array(); //If successful log transaction in opencart system if (!$error) { $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('stripe_payments_order_status_id')); $json['success'] = $this->url->link('checkout/success', '', 'SSL'); } else { $json['error'] = (string) $error['message']; $json['details'] = $error; } $this->response->setOutput(json_encode($json)); }
public function testUpcoming() { authorizeFromEnv(); $c = Stripe_Customer::create(array('card' => array('number' => '4242424242424242', 'exp_month' => 5, 'exp_year' => 2015))); $invoice = Stripe_Invoice::upcoming(array('customer' => $c->id)); $this->assertEqual($invoice->customer, $c->id); $this->assertEqual($invoice->attempted, false); }
public function testUpdateDescriptionNull() { $customer = self::createTestCustomer(array('description' => 'foo bar')); $customer->description = NULL; $customer->save(); $updatedCustomer = Stripe_Customer::retrieve($customer->id); $this->assertEqual(NULL, $updatedCustomer->description); }
public function saveUserPayment() { $payment_token = Input::get('stripeToken'); $owner_id = Session::get('user_id'); $owner_data = Owner::find($owner_id); try { if (Config::get('app.default_payment') == 'stripe') { Stripe::setApiKey(Config::get('app.stripe_secret_key')); $customer = Stripe_Customer::create(array("card" => $payment_token, "description" => $owner_data->email)); $last_four = substr(Input::get('number'), -4); if ($customer) { $customer_id = $customer->id; $payment = new Payment(); $payment->owner_id = $owner_id; $payment->customer_id = $customer_id; $payment->last_four = $last_four; $payment->card_token = $customer->cards->data[0]->id; $payment->save(); $message = "Your Card is successfully added."; $type = "success"; return Redirect::to('/user/payments')->with('message', $message)->with('type', $type); } else { $message = "Sorry something went wrong."; $type = "danger"; return Redirect::to('/user/payments')->with('message', $message)->with('type', $type); } } else { Braintree_Configuration::environment(Config::get('app.braintree_environment')); Braintree_Configuration::merchantId(Config::get('app.braintree_merchant_id')); Braintree_Configuration::publicKey(Config::get('app.braintree_public_key')); Braintree_Configuration::privateKey(Config::get('app.braintree_private_key')); $result = Braintree_Customer::create(array("firstName" => $owner_data->first_name, "lastName" => $owner_data->last_name, "creditCard" => array("number" => Input::get('number'), "expirationMonth" => Input::get('month'), "expirationYear" => Input::get('year'), "cvv" => Input::get('cvv')))); Log::info('result = ' . print_r($result, true)); if ($result->success) { $num = $result->customer->creditCards[0]->maskedNumber; $last_four = substr($num, -4); $customer_id = $result->customer->id; $payment = new Payment(); $payment->owner_id = $owner_id; $payment->customer_id = $customer_id; $payment->last_four = $last_four; $payment->card_token = $result->customer->creditCards[0]->token; $payment->save(); $message = "Your Card is successfully added."; $type = "success"; return Redirect::to('/user/payments')->with('message', $message)->with('type', $type); } else { $message = "Sorry something went wrong."; $type = "danger"; return Redirect::to('/user/payments')->with('message', $message)->with('type', $type); } } } catch (Exception $e) { $message = "Sorry something went wrong."; $type = "danger"; return Redirect::to('/user/payments')->with('message', $message)->with('type', $type); } }
public function testSave() { $customer = self::createTestCustomer(); $customer->email = '*****@*****.**'; $customer->save(); $this->assertEqual($customer->email, '*****@*****.**'); $customer2 = Stripe_Customer::retrieve($customer->id); $this->assertEqual($customer->email, $customer2->email); }
public function payForOrder($order) { // Create a new customer $customer = \Stripe_Customer::create(array('email' => $order['customerEmail'], 'card' => $order['token'])); // Pay for order $charge = \Stripe_Charge::create(array('customer' => $customer->id, 'amount' => $order['price'] * 100, 'currency' => 'usd')); // Return charge object return array('chargeId' => $charge->id, 'customerId' => $customer->id); }
public function testInvalidCredentials() { Stripe::setApiKey('invalid'); try { Stripe_Customer::create(); } catch (Stripe_AuthenticationError $e) { $this->assertEqual(401, $e->getHttpStatus()); } }
public function testInvalidObject() { self::authorizeFromEnv(); try { Stripe_Customer::retrieve('invalid'); } catch (Stripe_InvalidRequestError $e) { $this->assertEqual(404, $e->getHttpStatus()); } }
function stripeSubscribeCustomer() { // set your secret key: remember to change this to your live secret key in production // see your keys here https://manage.stripe.com/account Stripe::setApiKey("mDZRJuHrjeG3sSKJdmumEZdbGtr1TLDW"); // get the credit card details submitted by the form $token = $_POST['stripeToken']; $customer = Stripe_Customer::create(array("card" => $token, "plan" => "gold", "email" => "*****@*****.**")); }
public function stripeAction(Request $request) { $em = $this->getDoctrine()->getEntityManager(); $registerDetail = $em->createQueryBuilder()->select('SalonsolutionsUser')->from('SalonSolutionWebBundle:SalonsolutionsUser', 'SalonsolutionsUser')->addOrderBy('SalonsolutionsUser.id', 'DESC')->setMaxResults(1)->getQuery()->getResult(); $userId = $registerDetail[0]->id; $firstName = $registerDetail[0]->firstName; $email = $registerDetail[0]->email; $em = $this->getDoctrine()->getEntityManager(); $salonDetail = $em->createQueryBuilder()->select('SalonsolutionsSalon')->from('SalonSolutionWebBundle:SalonsolutionsSalon', 'SalonsolutionsSalon')->addOrderBy('SalonsolutionsSalon.id', 'DESC')->setMaxResults(1)->getQuery()->getResult(); $salonId = $salonDetail[0]->id; $request = $this->container->get('request'); $message = ''; if ($request->get('test')) { Stripe::setApiKey('sk_test_ZPmfNFOUBUAY3YyiSSzUPMA8'); $token = $request->get('stripeToken'); $customer = \Stripe_Customer::create(array('email' => $email, 'card' => $token)); $charge = \Stripe_Charge::create(array('customer' => $customer->id, 'amount' => 1000, 'currency' => 'usd', 'description' => $email)); $customerId = $customer->id; $customeremail = $customer->email; $times = date_create(); $time = date_format($times, 'H:i:s'); $mydate = getdate(date("U")); $date = $mydate['weekday'] . ',' . $mydate['month'] . ',' . $mydate['mday'] . ',' . $mydate['year']; $message = 'Successfully Paid $10.00 !'; $em = $this->getDoctrine()->getEntityManager(); $confirmedPayment = $em->createQueryBuilder()->select('SalonsolutionsUser')->update('SalonSolutionWebBundle:SalonsolutionsUser', 'SalonsolutionsUser')->set('SalonsolutionsUser.status', ':status')->setParameter('status', '1')->where('SalonsolutionsUser.email = :email')->setParameter('email', $email)->getQuery()->getResult(); $Payment = new SalonsolutionsPayment(); $Payment->setUserId($userId); $Payment->setSalonId($salonId); $Payment->setTransactionId($customerId); $Payment->setTransactionDate($date); $Payment->setTransactionTime($time); $Payment->setTransactionAmount('10'); $Payment->setPaymentMethodId('1'); $em = $this->getDoctrine()->getEntityManager(); $em->persist($Payment); $em->flush(); $employeeMessage = new SalonsolutionsEmployeeMessages(); $employeeMessage->setSalonOwnerId($userId); $employeeMessage->setType("Employee Message"); $employeeMessage->setMessage("This is a message to be displayed on Employee Dashboard "); $employeeMessage->setStatus('0'); $em = $this->getDoctrine()->getEntityManager(); $em->persist($employeeMessage); $em->flush(); $halfMessage = new SalonsolutionsEmployeeMessages(); $halfMessage->setSalonOwnerId($userId); $halfMessage->setMessage("Offering Message"); $halfMessage->setMessage("HALF PRICE SPRAY TANS EVERY FRIDAY !!! "); $halfMessage->setStatus('0'); $em = $this->getDoctrine()->getEntityManager(); $em->persist($halfMessage); $em->flush(); } return $this->render('SalonSolutionWebBundle:Home:stripe.html.twig', array('message' => $message, 'firstName' => $firstName)); }
public function testCancelSubscription() { authorizeFromEnv(); $c = Stripe_Customer::create(array('card' => array('number' => '4242424242424242', 'exp_month' => 5, 'exp_year' => 2015), 'plan' => 'gold')); $c->cancelSubscription(array('at_period_end' => true)); $this->assertEqual($c->subscription->status, 'active'); $this->assertTrue($c->subscription->cancel_at_period_end); $c->cancelSubscription(); $this->assertEqual($c->subscription->status, 'canceled'); }
public function testUpdateAllMetadata() { $customer = self::createTestCustomer(); $customer->metadata['shoe size'] = '7'; $customer->metadata['shirt size'] = 'XS'; $customer->save(); $customer->metadata = array('shirt size' => 'XL'); $customer->save(); $updatedCustomer = Stripe_Customer::retrieve($customer->id); $this->assertEqual('XL', $updatedCustomer->metadata['shirt size']); $this->assertFalse(isset($updatedCustomer->metadata['shoe size'])); }
public function indexAction() { $request = $this->container->get('request'); $message = ''; if ($request->get('test')) { \Stripe::setApiKey('pk_test_ur0ebwOGBrsNzQrpdCNENIu4'); $token = $request->get('stripeToken'); $customer = \Stripe_Customer::create(array('email' => '*****@*****.**', 'card' => $token)); $charge = \Stripe_Charge::create(array('customer' => $customer->id, 'amount' => 5000, 'currency' => 'usd')); $message = '<h1>Successfully charged $50.00!</h1>'; } return $this->render('AcmeTestBundle:Default:index.html.twig', array('message' => $message)); }
public function stripeAction() { $request = $this->container->get('request'); $message = ''; if ($request->get('test')) { \Stripe\Stripe::setApiKey('sk_test_ZPmfNFOUBUAY3YyiSSzUPMA8'); $token = $request->get('stripeToken'); $customer = \Stripe_Customer::create(array('email' => '*****@*****.**', 'card' => $token)); $charge = \Stripe_Charge::create(array('customer' => $customer->id, 'amount' => 5000, 'currency' => 'usd')); $message = '<h1>Successfully charged $50.00!</h1>'; } return $this->render('TestTestBundle:Page:stripe.html.twig', array('message' => $message)); }
public function return_credit_cards() { try { $this->sktest_setapikey(); $stripe_id = get_user_meta(get_current_user_id(), 'stripe_customer_id', true); $customerret = Stripe_Customer::retrieve($stripe_id); } catch (Stripe_Error $e) { $body = $e->getJsonBody(); $err = $body['error']; print $error[‘message’]; } $idtest = $customerret->id; echo $idtest; }
public function testDeletion() { authorizeFromEnv(); $id = 'test-coupon-' . self::randomString(); $coupon = Stripe_Coupon::create(array('percent_off' => 25, 'duration' => 'repeating', 'duration_in_months' => 5, 'id' => $id)); $customer = self::createTestCustomer(array('coupon' => $id)); $this->assertTrue(isset($customer->discount)); $this->assertTrue(isset($customer->discount->coupon)); $this->assertEqual($id, $customer->discount->coupon->id); $customer->deleteDiscount(); $this->assertFalse(isset($customer->discount)); $customer = Stripe_Customer::retrieve($customer->id); $this->assertFalse(isset($customer->discount)); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request CreateCharge */ RequestNotSupportedException::assertSupports($this, $request); $model = ArrayObject::ensureArrayObject($request->getModel()); $model->validateNotEmpty(array('plan')); if (false == $model['card']) { $this->gateway->execute(new ObtainToken($model)); } try { \Stripe::setApiKey($this->keys->getSecretKey()); $charge = \Stripe_Customer::create($model->toUnsafeArray()); $model->replace($charge->__toArray(true)); } catch (\Stripe_CardError $e) { $model->replace($e->getJsonBody()); } }
function wpestate_cancel_stripe() { global $current_user; require_once get_template_directory() . '/libs/stripe/lib/Stripe.php'; get_currentuserinfo(); $userID = $current_user->ID; $stripe_customer_id = get_user_meta($userID, 'stripe', true); $subscription_id = get_user_meta($userID, 'stripe_subscription_id', true); $stripe_secret_key = esc_html(get_option('wp_estate_stripe_secret_key', '')); $stripe_publishable_key = esc_html(get_option('wp_estate_stripe_publishable_key', '')); $stripe = array("secret_key" => $stripe_secret_key, "publishable_key" => $stripe_publishable_key); Stripe::setApiKey($stripe['secret_key']); $processor_link = wpestate_get_stripe_link(); $submission_curency_status = esc_html(get_option('wp_estate_submission_curency', '')); $cu = Stripe_Customer::retrieve($stripe_customer_id); $cu->subscriptions->retrieve($subscription_id)->cancel(array("at_period_end" => true)); update_user_meta($current_user->ID, 'stripe_subscription_id', ''); }
/** * Function that will actually charge the customers credit card * * @since 1.0.0 */ function sc_charge_card() { if (isset($_POST['stripeToken'])) { $redirect = $_POST['sc-redirect']; $fail_redirect = $_POST['sc-redirect-fail']; // Get the credit card details submitted by the form $token = $_POST['stripeToken']; $amount = $_POST['sc-amount']; $description = $_POST['sc-description']; $store_name = $_POST['sc-name']; $currency = $_POST['sc-currency']; $test_mode = isset($_POST['sc_test_mode']) ? $_POST['sc_test_mode'] : 'false'; $charge = array(); $query_args = array(); $meta = array(); $meta = apply_filters('sc_meta_values', $meta); sc_set_stripe_key($test_mode); // Create new customer $new_customer = Stripe_Customer::create(array('email' => $_POST['stripeEmail'], 'card' => $token)); $amount = apply_filters('sc_charge_amount', $amount); // Create the charge on Stripe's servers - this will charge the user's default card try { $charge = Stripe_Charge::create(array('amount' => $amount, 'currency' => $currency, 'customer' => $new_customer['id'], 'description' => $description, 'metadata' => $meta)); // Add Stripe charge ID to querystring. $query_args = array('charge' => $charge->id, 'store_name' => urlencode($store_name)); $failed = false; } catch (Stripe_CardError $e) { // Catch Stripe errors $redirect = $fail_redirect; $e = $e->getJsonBody(); // Add failure indicator to querystring. $query_args = array('charge' => $e['error']['charge'], 'charge_failed' => true); $failed = true; } unset($_POST['stripeToken']); do_action('sc_redirect_before'); if ($test_mode == 'true') { $query_args['test_mode'] = 'true'; } wp_redirect(add_query_arg($query_args, apply_filters('sc_redirect', $redirect, $failed))); do_action('sc_redirect_after'); exit; } }
/** * boot * * @param Application $app */ public function boot(Application $app) { if (empty($app['msiof.stripe']['keys']['secret'])) { throw new \RuntimeException('Stripe key not set msiof.stripe[keys][secret]. Cannot continue.'); } if (empty($app['msiof.stripe']['keys']['publishable'])) { throw new \RuntimeException('Stripe key not set msiof.stripe[keys][publishable]. Cannot continue.'); } \Stripe::setApiKey($app['msiof.stripe']['keys']['secret']); $app['dispatcher']->addListener(UserEvents::AFTER_INSERT, function (UserEvent $event) use($app) { $user = $event->getUser(); $customer = \Stripe_Customer::create(['email' => $user->getEmail(), 'metadata' => ['userid' => $user->getId()]]); $subscription = $customer->subscriptions->create(["plan" => $app['msiof.stripe']['plans']['free']]); $user->setCustomField('stripe_customer_id', $customer->id); $user->setCustomField('stripe_subscription_id_free', $subscription->id); $user->setCustomField('stripe_current_plan', $app['msiof.stripe']['plans']['free']); $app['user.manager']->update($user); }); }