作者:Jeff-C
项目:Wishlis
public function bill_user()
{
\Stripe\Stripe::setApiKey("sk_test_BzcfGDAVwQw9efuWp2eVvyVg");
$stripe_info = $this->input->post();
$billing = $this->user->get_billing_id($this->session->userdata("id"));
$total = $this->cart->get_total_cents($this->cart->get_all());
if ($billing["billing_id"]) {
// var_dump($total);
// die();
\Stripe\Charge::create(array("amount" => $total, "currency" => "usd", "customer" => $billing["billing_id"]));
} else {
$customer = \Stripe\Customer::create(array("source" => $stripe_info["stripeToken"], "description" => "Example customer"));
$this->user->set_billing_id($customer["id"]);
try {
$charge = \Stripe\Charge::create(array("amount" => $total, "currency" => "usd", "customer" => $customer["id"], "description" => "Example charge"));
} catch (\Stripe\Error\Card $e) {
// The card has been declined
}
}
$cart_items = $this->cart->get_all();
foreach ($cart_items as $item) {
$this->cart->delete($item['product_id'], $item['recipient_id']);
$this->wishlist->delete_from_wishlist($item['product_id'], $item['recipient_id']);
}
redirect("/carts/viewcart");
}
作者:kongtoonarm
项目:laravel-strip
public function createCharge()
{
Stripe::setApiKey($this->stripeConfig['testSecretKey']);
$stripeCharge = StripeCharge::create(['amount' => 2000, 'currency' => 'usd', 'card' => 'tok_16ZzIaH7PksWTbQLK6AvzuVR', 'description' => 'Describe your product']);
echo '<pre>';
print_r($stripeCharge);
echo '</pre>';
}
作者:vinodchande
项目:module
public function init()
{
$stripe_setting = Stripe::findOne(1);
if ($stripe_setting) {
$api_key = $stripe_setting->private_key;
\Stripe\Stripe::setApiKey($api_key);
}
}
作者:Raistlfire
项目:stripe-api-ph
public function testGetApi()
{
$stripe = new Stripe("key");
$cards = $stripe->cards();
$this->assertInstanceOf('Stripe\\Api\\Cards', $cards);
$customers = $stripe->customers;
$this->assertInstanceOf('Stripe\\Api\\Customers', $customers);
$invoiceItems = $stripe->invoiceItems;
$this->assertInstanceOf('Stripe\\Api\\InvoiceItems', $invoiceItems);
}
作者:mathieumol
项目:Booksmar
public function checkout($bill)
{
$this->load->helper('url');
if (isset($_SESSION['id'])) {
try {
require_once './vendor/autoload.php';
\Stripe\Stripe::setApiKey("sk_test_ZR7R8cxse2Nz0TFsmxTDlwey");
//Replace with your Secret Key
$charge = \Stripe\Charge::create(array("amount" => $bill * 100, "currency" => "EUR", "card" => $_POST['stripeToken'], "description" => "Transaction BookSmart"));
$this->load->helper('url');
$this->load->database();
$ids = implode(",", $_SESSION['cart']);
$query10 = "UPDATE Book SET buyerid='" . $_SESSION['id'] . "' WHERE id IN (" . $ids . ");";
echo $query10;
$this->db->query($query10);
$data['payment'] = $bill;
unset($_SESSION['cart']);
$this->load->view('static_page', $data);
} catch (Stripe_CardError $e) {
} catch (Stripe_InvalidRequestError $e) {
} catch (Stripe_AuthenticationError $e) {
} catch (Stripe_ApiConnectionError $e) {
} catch (Stripe_Error $e) {
} catch (Exception $e) {
}
} else {
$data['log'] = "<h1> You must be log to sell a book</h1>";
$this->load->view('static_page', $data);
}
}
作者:205medi
项目:codeIgniter-stripe-librar
/**
* [__construct Youy need to put the configuration values in your config/config.php
* $config['stripe']['mode']='test';
* $config['stripe']['sk_test'] = 'sk_test_YOUR_KEY';
* $config['stripe']['pk_test'] = 'pk_test_YOUR_KEY';
* $config['stripe']['sk_live'] = 'sk_live_YOUR_KEY';
* $config['stripe']['pk_live'] = 'pk_live_YOUR_KEY';
* $config['stripe']['currency'] = 'usd';]
*/
public function __construct()
{
$this->ci =& get_instance();
$this->config = $this->ci->config->config['stripe'];
$mode = $this->config['mode'];
$this->config['secret_key'] = $this->config['sk_' . $mode];
$this->config['publishable_key'] = $this->config['pk_' . $mode];
try {
// Use Stripe's bindings...
\Stripe\Stripe::setApiKey($this->config['secret_key']);
} catch (\Stripe\Error\Authentication $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
if ($mode == 'test') {
$body = $e->getJsonBody();
$err = $body['error'];
print 'Status is:' . $e->getHttpStatus() . "\n";
print 'Type is:' . $err['type'] . "\n";
print 'Code is:' . $err['code'] . "\n";
// param is '' in this case
print 'Param is:' . $err['param'] . "\n";
print 'Message is:' . $err['message'] . "\n";
}
}
}
作者:jking688
项目:smores-ap
function __construct($key)
{
$di = \Phalcon\DI::getDefault();
$this->di = $di;
// init stripe access
\Stripe\Stripe::setApiKey($key);
}
作者:Swift-J
项目:thmdh
public function charge($Token, $Amount, $Description, $Meta = array(), $Currency = 'gbp')
{
// 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
\Stripe\Stripe::setApiKey($this->config['secret_key']);
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = \Stripe\Charge::create(array("amount" => floatval($Amount) * 100, "currency" => $Currency, "source" => $Token, "description" => $Description, "metadata" => $Meta));
return true;
} catch (\Stripe\Error\ApiConnection $e) {
// Network problem, perhaps try again.
return $e;
} catch (\Stripe\Error\InvalidRequest $e) {
// You screwed up in your programming. Shouldn't happen!
return $e;
} catch (\Stripe\Error\Api $e) {
// Stripe's servers are down!
return $e;
} catch (\Stripe\Error\Card $e) {
// Card was declined.
return $e;
} catch (\Stripe\Error\Base $e) {
// ?????
return $e;
} catch (\Stripe\Error\RateLimit $e) {
// ?????
return $e;
}
return false;
}
作者:Monor
项目:imgservic
protected function chargeCustomer()
{
if ($this->isPostBack() && !$this->input('mark_payed')) {
$this->post->amount->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputFloat()]);
if (!$this->hasErrors()) {
$amount = (double) $this->input('amount') * 100;
try {
Stripe::setApiKey(env('STRIPE_KEY'));
$stripe = Charge::create(['customer' => $this->organisation->stripe_identifier_id, 'amount' => $amount, 'currency' => $this->settings->getCurrency(), 'description' => 'NinjaImg ' . date('m-Y', strtotime($this->startDate)) . '-' . date('m-Y', strtotime($this->endDate))]);
if (!isset($stripe->paid) || !$stripe->paid) {
$this->setError('Failed to charge credit-card');
}
if (!$this->hasErrors()) {
$payment = new ModelPayment();
$payment->amount = $amount;
$payment->currency = $this->settings->getCurrency();
$payment->period_start = $this->startDate;
$payment->period_end = $this->endDate;
$payment->transaction_id = $stripe->id;
$payment->organisation_id = $this->organisation->id;
$payment->save();
}
} catch (\Exception $e) {
$this->setError($e->getMessage());
}
if (!$this->hasErrors()) {
$this->organisation->getPayment($this->startDate, $this->endDate)->updateFreeCredits();
$this->setMessage('Successfully charged ' . $this->input('amount') . ' ' . $this->settings->getCurrency(), 'success');
}
response()->refresh();
}
}
}
作者:socialapparatu
项目:socialapparatu
function __construct()
{
adminGateKeeper();
$guid = pageArray(2);
$product = getEntity($guid);
\Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
if ($product->interval != "one_time") {
try {
$plan = \Stripe\Plan::retrieve($guid);
$plan->delete();
} catch (Exception $e) {
forward();
}
} else {
if ($product->stripe_sku) {
$sku = \Stripe\SKU::retrieve($product->stripe_sku);
$sku->delete();
}
if ($product->stripe_product_id) {
$stripe_product = \Stripe\Product::retrieve($product->stripe_product_id);
$stripe_product->delete();
}
}
$product->delete();
new SystemMessage("Your product has been deleted.");
forward("store");
}
作者:PhantomWatso
项目:mac
public function completeDonation()
{
// Validate amount
$amount = $this->request->data('amount');
if (!is_numeric($amount)) {
throw new ForbiddenException('Donation amount must be numeric');
} elseif ($amount < 1) {
throw new ForbiddenException('Donation must be at least one dollar');
}
$metadata = [];
if ($this->Auth->user('id')) {
$metadata['Donor name'] = $this->Auth->user('name');
} else {
$metadata['Donor name'] = '';
}
$metadata['Donor email'] = $this->request->data('email');
// Create the charge on Stripe's servers - this will charge the user's card
$apiKey = Configure::read('Stripe.Secret');
\Stripe\Stripe::setApiKey($apiKey);
try {
$description = 'Donation to MACC of $' . number_format($amount, 2);
$charge = \Stripe\Charge::create(['amount' => $amount * 100, 'currency' => 'usd', 'source' => $this->request->data('stripeToken'), 'description' => $description, 'metadata' => $metadata, 'receipt_email' => $this->request->data('email')]);
} catch (\Stripe\Error\Card $e) {
throw new ForbiddenException('The provided credit card has been declined');
}
$this->viewBuilder()->layout('json');
$this->set(['_serialize' => ['retval'], 'retval' => ['success' => true]]);
}
作者:kili
项目:carsho
public function checkout(Request $request)
{
\Stripe\Stripe::setApiKey('sk_test_gzviHPn6POLwymNxUXTpFhhG');
$token = $request->input('stripeToken');
//Retriieve cart information
$cart = Cart::where('user_id', Auth::user()->id)->first();
$items = $cart->cartItems;
$total = 0;
foreach ($items as $item) {
$total += $item->product->price;
}
if (Auth::user()->charge($total * 100, ['source' => $token, 'receipt_email' => Auth::user()->email])) {
$order = new Order();
$order->total_paid = $total;
$order->user_id = Auth::user()->id;
$order->save();
foreach ($items as $item) {
$orderItem = new OrderItem();
$orderItem->order_id = $order->id;
$orderItem->product_id = $item->product->id;
$orderItem->file_id = $item->product->file->id;
$orderItem->save();
CartItem::destroy($item->id);
}
return redirect('/order/' . $order->id);
} else {
return redirect('/cart');
}
}
作者:andrewkru
项目:repucautio
/**
* Check stripe data.
*
* @access public
* @return void
*/
public function run()
{
$paymentGateway = Payment_gateways::findOneActiveBySlug('stripe');
if ($paymentGateway->exists()) {
\Stripe\Stripe::setApiKey($paymentGateway->getFieldValue('apiKey'));
$subscriptions = new Subscription();
$allSubscriptions = $subscriptions->where('status', Subscription::STATUS_ACTIVE)->get();
/* @var Subscription $_subscription */
foreach ($allSubscriptions as $_subscription) {
$end = DateTime::createFromFormat('Y-m-d', $_subscription->end_date);
if ($end->getTimestamp() > strtotime('now')) {
$paymentTransaction = $_subscription->payment_transaction->get();
if ($paymentTransaction->system == 'stripe') {
$user = new User($_subscription->user_id);
try {
$customer = \Stripe\Customer::retrieve($user->stripe_id);
$subscription = $customer->subscriptions->retrieve($paymentTransaction->payment_id);
} catch (Exception $e) {
log_message('CRON_ERROR', __FUNCTION__ . ' > ' . $e->getMessage());
}
if (!isset($subscription) || $subscription->status != 'active') {
$_subscription->deactivate();
$_subscription->save();
}
}
}
}
log_message('CRON_SUCCESS', __FUNCTION__);
}
}
作者:alexandrzavali
项目:auctio
public function check($bid)
{
$bid = Bids::findOrFail(Input::get("bid"));
$offset = Input::get("offset");
if ($offset < 0) {
$now = \Carbon\Carbon::now()->subHours($offset);
} else {
$now = \Carbon\Carbon::now()->addHours($offset);
}
if (strtotime($bid->expiration) - strtotime($now) < 0) {
//bid is expired
if ($bid->amount < $bid->reservedPrice) {
//void since bidding price is less then reserved price
$bid->delete();
return "Bidding price less then reserved price";
} else {
//proceed and Charge
//since we get information about expiration from client we have to check it on the server as well
//check wether winning user has its card working
if ($bid->customerId) {
\Stripe\Stripe::setApiKey("sk_test_Z98H9hmuZWjFWfbkPFvrJMgk");
\Stripe\Charge::create(array("amount" => $bid->priceToCents(), "currency" => "usd", "customer" => $bid->customerId));
\Log::info('Charged: ' . $bid->amount);
}
$bid->complete = 1;
$bid->save();
$bid->delete();
}
} else {
//someone is messing with javascript
return "error";
}
return "Bidding is valid";
}
作者:dirtyblanket
项目:allaccessrm
public function postPayment(PaymentFormRequest $request, $eventId, $attendeeId)
{
$registeredAttendee = $this->attendees->findById($attendeeId);
$event = $this->events->findById($eventId);
$input = $request->all();
$token = $input['stripeToken'];
if (empty($token)) {
Flash::error('Your order could not be processed. Please ensure javascript in enabled and try again.');
return redirect()->back();
}
try {
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$stripeCustomer = \Stripe\Customer::create(['source' => $token, 'description' => 'Stripe charge for AARMS customer: ' . $registeredAttendee->id, 'email' => $registeredAttendee->email]);
$charge = \Stripe\Charge::create(['amount' => $event->price_cents, 'currency' => 'usd', 'customer' => $stripeCustomer->id, 'description' => 'Stripe charge for event: ' . $event->title]);
if (!$charge) {
Flash::error("Could not process Credit Card Payment");
return redirect()->back();
} else {
$registeredAttendee->amount_paid = $event->price;
$registeredAttendee->save();
$sendMail = new SendInvoiceEmail($registeredAttendee);
$this->dispatch($sendMail);
}
Flash::success("Payment successful!");
return redirect()->back();
} catch (\Stripe\Error\Card $e) {
Flash::error($e->getMessage());
return redirect()->back();
}
}
作者:nbrady-techempowe
项目:faithwrap
function charge($token, $billing_info, $cart, $user)
{
$data = $this->_form_data($billing_info);
$data['amount'] = $cart['total'] * 100;
//amount is in cents
$data['source'] = $token;
$data['description'] = $user['email'];
try {
//Set API Key
\Stripe\Stripe::setApiKey($this->ci->config->item('test_secret_key'));
$charge = \Stripe\Charge::create($data);
return $charge;
} catch (\Stripe\Error\Card $e) {
return $e->getJsonBody();
} catch (\Stripe\Error\InvalidRequest $e) {
return $e->getJsonBody();
} catch (\Stripe\Error\ApiConnection $e) {
return $e->getJsonBody();
} catch (\Stripe\Error\Api $e) {
return $e->getJsonBody();
} catch (\Stripe\Error\Authentication $e) {
return $e->getJsonBody();
} catch (\Stripe\Error\Base $e) {
return $e->getJsonBody();
}
}
作者:andrewkru
项目:repucautio
/**
* Check stripe data.
*
* @access public
* @return void
*/
public function run()
{
try {
$paymentGateway = Payment_gateways::findOneActiveBySlug('stripe');
if ($paymentGateway->exists()) {
\Stripe\Stripe::setApiKey($paymentGateway->getFieldValue('apiKey'));
$subscriptions = new Subscription();
$allSubscriptions = $subscriptions->get();
/* @var Subscription $_subscription */
foreach ($allSubscriptions as $_subscription) {
if ($_subscription->end_date <= strtotime('now')) {
$paymentTransaction = $_subscription->payment_transaction->get();
if ($paymentTransaction->system == 'stripe') {
$user = new User($_subscription->user_id);
$customer = \Stripe\Customer::retrieve($user->stripe_id);
$subscription = $customer->subscriptions->retrieve($paymentTransaction->payment_id);
if ($subscription->status == 'active') {
$date = new DateTime();
$date->setTimestamp($subscription->current_period_end);
$_subscription->end_date = $date->format('Y-m-d');
$_subscription->activate();
$_subscription->save();
}
}
}
}
log_message('CRON_SUCCESS', __FUNCTION__);
} else {
log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'No Stripe Api key.');
}
} catch (Exception $e) {
log_message('CRON_ERROR', __FUNCTION__ . ' > ' . $e->getMessage());
}
}
作者:KonnectAgai
项目:laravel-stripe-2.
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
/*
* Load Stripe configuration
*
* API keys should be utilizing Laravel's "dot files" to keep them out of source
* control and making them easily overridable on dev environments
*
* Read more: http://laravel.com/docs/configuration#environment-configuration
*/
$api_key = isset($_ENV['stripe.api_key']) ? $_ENV['stripe.api_key'] : $this->app['config']->get('services.stripe')['api_key'];
\Stripe\Stripe::setApiKey($api_key);
// Set API Version (optional)
$api_version = isset($_ENV['stripe.api_version']) ? $_ENV['stripe.api_version'] : $this->app['config']->get('services.stripe')['api_version'];
if ($api_version !== null) {
\Stripe\Stripe::setApiVersion($api_version);
}
$publishableKey = isset($_ENV['stripe.publishable_key']) ? $_ENV['stripe.publishable_key'] : $this->app['config']->get('services.stripe')['publishable_key'];
/*
* Register blade compiler for the Stripe publishable key.
*/
$blade = $this->app['view']->getEngineResolver()->resolve('blade')->getCompiler();
$blade->extend(function ($value, $compiler) use($publishableKey) {
$matcher = "/(?<!\\w)(\\s*)@stripeKey/";
return preg_replace($matcher, $publishableKey, $value);
});
}
作者:DarshanKumar8
项目:seatherowithu
public function processPreLaunchPayment(Request $request)
{
$secret_key = config('seathero.stripe.secret_key');
Stripe::setApiKey($secret_key);
$this->oneTimePayment($request->stripeToken, config('seathero.stripe.pre_launch_sign_up_price'));
return view('thanks');
}
作者:socialapparatu
项目:socialapparatu
public function init($file)
{
if (!loggedIn()) {
return false;
}
if (!is_a($file, "SocialApparatus\\File")) {
return false;
}
$product = getEntity($file->container_guid);
if (!is_a($product, "SocialApparatus\\Product")) {
return false;
}
$user = getLoggedInUser();
if ($user->stripe_cust) {
\Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
$orders = \Stripe\Order::all(array("limit" => 300, "customer" => $user->stripe_cust));
foreach ($orders['data'] as $order) {
foreach ($order->items as $item) {
if ($item->description != "Taxes (included)" && $item->description != "Free shipping") {
$sku = $item->parent;
if ($sku == $product->stripe_sku) {
return true;
}
}
}
}
}
return false;
}