当前位置: 首页>>代码示例>>PHP>>正文


PHP Stripe_Customer::create方法代码示例

本文整理汇总了PHP中Stripe_Customer::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Stripe_Customer::create方法的具体用法?PHP Stripe_Customer::create怎么用?PHP Stripe_Customer::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stripe_Customer的用法示例。


在下文中一共展示了Stripe_Customer::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: send

 /**
  * 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;
 }
开发者ID:shahadat014,项目名称:geleyi,代码行数:34,代码来源:gateway-request.php

示例2: indexAction

 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' => 'customer@example.com', '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));
 }
开发者ID:skycri,项目名称:MyAbos,代码行数:16,代码来源:PaymentController.php

示例3: pay

 /**
  * @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);
     }
 }
开发者ID:eavesmonkey,项目名称:respond,代码行数:35,代码来源:pay.php

示例4: confirm

 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));
 }
开发者ID:dsadinoff,项目名称:stripe-payments,代码行数:34,代码来源:stripe_payments.php

示例5: get_customer

 /**
  * Get a Stripe customer object instance.
  *
  * @param integer $user_id If it's for an existing user; pass the user's ID (optional).
  * @param string  $email Customer's email address (optional).
  * @param string  $fname Customer's first name (optional).
  * @param string  $lname Customer's last name (optional).
  * @param array   $metadata Any metadata (optional).
  *
  * @return Stripe_Customer|string Customer object; else error message.
  */
 public static function get_customer($user_id = 0, $email = '', $fname = '', $lname = '', $metadata = array())
 {
     $input_time = time();
     // Initialize.
     $input_vars = get_defined_vars();
     // Arguments.
     require_once dirname(__FILE__) . '/stripe-sdk/lib/Stripe.php';
     Stripe::setApiKey($GLOBALS['WS_PLUGIN__']['optimizemember']['o']['pro_stripe_api_secret_key']);
     try {
         try {
             if ($user_id && ($customer_id = get_user_option('optimizemember_subscr_cid', $user_id))) {
                 $customer = Stripe_Customer::retrieve($customer_id);
             }
         } catch (exception $exception) {
             // Fail silently; create a new customer below in this case.
         }
         if (empty($customer) || !is_object($customer)) {
             $customer = Stripe_Customer::create(array('email' => $email, 'description' => trim($fname . ' ' . $lname), 'metadata' => $metadata));
         }
         self::log_entry(__FUNCTION__, $input_time, $input_vars, time(), $customer);
         return $customer;
         // Stripe customer object.
     } catch (exception $exception) {
         self::log_entry(__FUNCTION__, $input_time, $input_vars, time(), $exception);
         return self::error_message($exception);
     }
 }
开发者ID:JalpMi,项目名称:v2contact,代码行数:38,代码来源:stripe-utilities.inc.php

示例6: fwd_stripe_prepare

/**
 * 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;
}
开发者ID:kfuchs,项目名称:fwdcommerce,代码行数:33,代码来源:fwd-stripe.php

示例7: pay

 /**
  * @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);
     }
 }
开发者ID:sanderdrummer,项目名称:Homepages,代码行数:37,代码来源:pay.php

示例8: pay

 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);
     }
 }
开发者ID:Bnei-Baruch,项目名称:Namaste,代码行数:27,代码来源:stripe-model.php

示例9: create

 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();
     }
 }
开发者ID:jrdncchr,项目名称:merlinleads,代码行数:30,代码来源:registration.php

示例10: updatePlan

 public function updatePlan(User $user, Plan $plan, $coupon_id = null)
 {
     $customer_id = $user->getProfile() ? $user->getProfile()->getCustomerId() : null;
     $new_plan_id = $plan->getId();
     if ($customer_id) {
         $customer = \Stripe_Customer::retrieve($customer_id);
         if ($coupon_id && $this->getCuponById($coupon_id)) {
             $customer->coupon = $coupon_id;
             $customer->save();
         }
         if ($new_plan_id !== 1) {
             $currentSubscription = $this->getCurrentSubscription($user, $customer);
             $subscription = $customer->subscriptions->retrieve($currentSubscription['id']);
             $subscription->plan = $new_plan_id;
             $proration_date = new \DateTime();
             $subscription->proration_date = $proration_date->getTimestamp();
             $subscription->tax_percent = 7;
             $subscription->save();
             $current_plan_id = $user->getCurrentPlan()->getPlan()->getId();
             if ($current_plan_id != 1) {
                 $invoice = \Stripe_Invoice::create(array("customer" => $customer_id, "subscription" => $subscription['id']));
                 $result = $invoice->pay();
                 if ($result->paid != true) {
                     $invoice->closed = true;
                     $invoice->save();
                     $customer->updateSubscription(array('plan' => $current_plan_id, 'prorate' => false, 'application_fee_percent' => 4, 'tax_percent' => 7));
                 }
             }
         }
     } else {
         //Inscribir al Usuario en el Plan Free por primera vez
         $customer = \Stripe_Customer::create(array("plan" => $new_plan_id, "email" => $user->getEmail()));
         $customer_id = $customer->id;
     }
     //Update Current Plan
     if (is_array($customer->subscriptions->data)) {
         foreach ($customer->subscriptions->data as $data) {
             if ($data->status == 'active') {
                 $dateStart = $data->current_period_start;
                 $dateEnd = $data->current_period_end;
                 break;
             }
         }
     } else {
         $dateStart = $customer->subscriptions->data->current_period_start;
         $dateEnd = $customer->subscriptions->data->current_period_end;
     }
     $dateTimeStart = new \DateTime();
     $dateTimeStart->setTimestamp($dateStart);
     $dateTimeEnd = new \DateTime();
     $dateTimeEnd->setTimestamp($dateEnd);
     $userPlan = new UserPlan($user, $plan);
     $userPlan->setDateStart($dateTimeStart);
     $userPlan->setDateEnd($dateTimeEnd);
     $user->getProfile()->setCustomerId($customer_id);
     $user->addPlan($userPlan);
     $this->saveData($user);
     return $plan;
 }
开发者ID:atorresgonzalez339,项目名称:symfony,代码行数:59,代码来源:UpgradeBusiness.php

示例11: testUpcoming

 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);
 }
开发者ID:KillerDesigner,项目名称:OpenVBX-Plugin-Stripe,代码行数:8,代码来源:InvoiceTest.php

示例12: saveUserPayment

 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);
     }
 }
开发者ID:netGALAXYStudios,项目名称:ourmovingapp,代码行数:58,代码来源:WebUserController.php

示例13: stripeSubscribeCustomer

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" => "payinguser@example.com"));
}
开发者ID:rncrtr,项目名称:clscHTML,代码行数:9,代码来源:functions.php

示例14: createCustomer

 /**
  * Create a new customer
  * @param ElggUser $user
  * @param array $data
  * @return Stripe_Customer|false
  */
 public function createCustomer($user = null, $data = array())
 {
     $fields = array('account_balance', 'card', 'coupon', 'plan', 'quantity', 'trial_end', 'metadata', 'description', 'email');
     try {
         foreach ($data as $key => $value) {
             if (!in_array($key, $fields)) {
                 $data[$key] = '';
             }
         }
         $data = array_filter($data);
         if ($user) {
             if (!$data['email']) {
                 $data['email'] = $user->email;
             }
             if (!$data['description']) {
                 $data['description'] = $user->name;
             }
             if (!is_array($data['metadata'])) {
                 $data['metadata'] = array();
             }
             $data['metadata']['guid'] = $user->guid;
             $data['metadata']['username'] = $user->username;
         }
         $customer = Stripe_Customer::create($data);
         if ($user && $user->guid) {
             // Store any customer IDs this user might have for reference
             $stripe_ids = $user->stripe_customer_id;
             if (!$stripe_ids) {
                 $stripe_ids = array();
             } else {
                 if (!is_array($stripe_ids)) {
                     $stripe_ids = array($stripe_ids);
                 }
             }
             if (!in_array($customer->id, $stripe_ids)) {
                 create_metadata($user->guid, 'stripe_customer_id', $customer->id, '', $user->guid, ACCESS_PUBLIC, true);
             }
             // Store current Customer ID
             $user->setPrivateSetting('stripe_customer_id', $customer->id);
         } else {
             // Store customer IDs with their email reference locally
             // so that users can be assigned their existing customer ID upon registration
             $customer_ref = elgg_get_plugin_setting($customer->email, 'stripe');
             if ($customer_ref) {
                 $customer_ref = unserialize($customer_ref);
             } else {
                 $customer_ref = array();
             }
             array_unshift($customer_ref, $customer->id);
             elgg_set_plugin_setting($customer->email, serialize($customer_ref), 'stripe');
         }
         return $customer;
     } catch (Exception $ex) {
         $this->log($ex);
         return false;
     }
 }
开发者ID:Daltonmedia,项目名称:stripe,代码行数:63,代码来源:StripeClient.php

示例15: payForOrder

 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);
 }
开发者ID:hackathon-5,项目名称:power-ragers-repo,代码行数:9,代码来源:StripeController.php


注:本文中的Stripe_Customer::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。