本文整理汇总了PHP中Stripe\Stripe::setApiKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Stripe::setApiKey方法的具体用法?PHP Stripe::setApiKey怎么用?PHP Stripe::setApiKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stripe\Stripe
的用法示例。
在下文中一共展示了Stripe::setApiKey方法的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: init
public function init()
{
$stripe_setting = Stripe::findOne(1);
if ($stripe_setting) {
$api_key = $stripe_setting->private_key;
\Stripe\Stripe::setApiKey($api_key);
}
}
示例3: 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>';
}
示例4: 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);
}
}
示例5: __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";
}
}
}
示例6: onPostDispatchCheckout
/**
* @param \Enlight_Controller_ActionEventArgs $args
*/
public function onPostDispatchCheckout($args)
{
$action = $args->getSubject();
$request = $action->Request();
$view = $action->View();
$apiKey = $this->bootstrap->Config()->get('stripeSecretKey');
\Stripe\Stripe::setApiKey($apiKey);
$token = $request->getPost('stripeToken');
if (!empty($token)) {
try {
$this->onStripeToken($request);
} catch (\Stripe\Error\Card $e) {
$eJson = $e->getJsonBody();
$error = $eJson['error'];
$view->assign('sErrorMessages', [$error['message']]);
if ($request->getControllerName() == 'checkout') {
$action->forward('shippingPayment');
} else {
$action->forward('payment');
}
$request->setPost('stripeToken', null);
$action->Response()->clearHeader('Location')->setHttpResponseCode(200);
return;
}
}
if (!empty($view->sPayments) && !empty($view->sUserData['additional']['user']['viisonStripeCustomerId'])) {
$customerId = $view->sUserData['additional']['user']['viisonStripeCustomerId'];
$customer = \Stripe\Customer::retrieve($customerId);
$view->stripeSources = $this->convertCards($customer['sources']['data']);
}
}
示例7: 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__);
}
}
示例8: __construct
function __construct($key)
{
$di = \Phalcon\DI::getDefault();
$this->di = $di;
// init stripe access
\Stripe\Stripe::setApiKey($key);
}
示例9: 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;
}
示例10: init
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;
}
示例11: charge
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();
}
}
示例12: 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();
}
}
示例13: __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");
}
示例14: 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();
}
}
}
示例15: boot
/**
* 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);
});
}