本文整理汇总了PHP中Stripe_Customer类的典型用法代码示例。如果您正苦于以下问题:PHP Stripe_Customer类的具体用法?PHP Stripe_Customer怎么用?PHP Stripe_Customer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stripe_Customer类的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;
}
示例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));
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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();
}
}
示例6: UpdateExistingCustomer
/**
* 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;
}
}
示例7: 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);
}
}
示例8: updateSubscription
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];
}
示例9: email_transfer_failed
function email_transfer_failed($transfer)
{
$customer = Stripe_Customer::retrieve($transfer->customer);
$subject = 'Your transfer was failed';
$headers = 'From: "Brandbits Support" <support@brandbits.com>';
mail($customer->email, $subject, message_body(), $headers);
}
示例10: 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);
}
}
示例11: 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));
}
示例12: 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);
}
示例13: testUpdateDescriptionNull
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);
}
示例14: 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);
}
}
示例15: testSave
public function testSave()
{
$customer = self::createTestCustomer();
$customer->email = 'gdb@stripe.com';
$customer->save();
$this->assertEqual($customer->email, 'gdb@stripe.com');
$customer2 = Stripe_Customer::retrieve($customer->id);
$this->assertEqual($customer->email, $customer2->email);
}