本文整理汇总了PHP中Stripe\Stripe类的典型用法代码示例。如果您正苦于以下问题:PHP Stripe类的具体用法?PHP Stripe怎么用?PHP Stripe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stripe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bill_user
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");
}
示例2: createCharge
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>';
}
示例3: init
public function init()
{
$stripe_setting = Stripe::findOne(1);
if ($stripe_setting) {
$api_key = $stripe_setting->private_key;
\Stripe\Stripe::setApiKey($api_key);
}
}
示例4: testGetApi
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);
}
示例5: checkout
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);
}
}
示例6: __construct
/**
* [__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";
}
}
}
示例7: __construct
function __construct($key)
{
$di = \Phalcon\DI::getDefault();
$this->di = $di;
// init stripe access
\Stripe\Stripe::setApiKey($key);
}
示例8: charge
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;
}
示例9: chargeCustomer
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();
}
}
}
示例10: __construct
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");
}
示例11: completeDonation
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]]);
}
示例12: checkout
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');
}
}
示例13: run
/**
* 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__);
}
}
示例14: check
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";
}
示例15: postPayment
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();
}
}