本文整理汇总了PHP中Stripe::setApiKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Stripe::setApiKey方法的具体用法?PHP Stripe::setApiKey怎么用?PHP Stripe::setApiKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stripe
的用法示例。
在下文中一共展示了Stripe::setApiKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: do_transaction
function do_transaction($amount, $cc, $cvc, $exp_month, $exp_year, $name, $description, $payment_data)
{
$result = array();
$stripe_settings = get_option('event_espresso_stripe_settings');
//Check for an alternate Stripe settings
if (isset($payment_data['event_meta']['stripe_secret_key']) && !empty($payment_data['event_meta']['stripe_secret_key'])) {
//Alternate Stripe settings
$secretKey = $payment_data['event_meta']['stripe_secret_key'];
} else {
$publishableKey = $stripe_settings['stripe_publishable_key'];
$secretKey = $stripe_settings['stripe_secret_key'];
}
$currencySymbol = $stripe_settings['stripe_currency_symbol'];
//$transactionPrefix = $stripe_settings['stripe_transaction_prefix'];
Stripe::setApiKey($secretKey);
$charge = "unknown";
try {
$charge = Stripe_Charge::create(array("amount" => $amount * 100, "currency" => $currencySymbol, "card" => array("number" => $cc, "exp_month" => $exp_month, "exp_year" => $exp_year, "cvc" => $cvc, "name" => $name), "description" => $description));
$result["status"] = 1;
$result["msg"] = "Transaction was completed successfully";
$result['txid'] = $charge->id;
} catch (Exception $e) {
$result["status"] = 0;
$result["error_msg"] = "Failed to charge the card.";
}
return $result;
}
示例2: send_to_stripe
protected function send_to_stripe()
{
global $woocommerce;
// 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($this->secret_key);
// Get the credit card details submitted by the form
$data = $this->getRequestData();
// Create the charge on Stripe's servers - this will charge the user's card
try {
$charge = Stripe_Charge::create(array("amount" => $data['amount'], "currency" => $data['currency'], "card" => $data['token'], "description" => $data['card']['name'], "capture" => !$this->capture));
error_log(var_export($charge, 1));
$this->transactionId = $charge['id'];
//Save data for the "Capture"
update_post_meta($this->order->id, 'transaction_id', $this->transactionId);
update_post_meta($this->order->id, 'key', $this->secret_key);
update_post_meta($this->order->id, 'auth_capture', $this->capture);
return true;
} catch (Stripe_Error $e) {
// The card has been declined, or other error
$body = $e->getJsonBody();
$err = $body['error'];
error_log('Stripe Error:' . $err['message'] . "\n");
if (function_exists('wc_add_notice')) {
wc_add_notice($err['message'], $notice_type = 'error');
} else {
$woocommerce->add_error(__('Payment error:', 'woothemes') . $err['message']);
}
return false;
}
}
示例3: 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);
}
}
示例4: gdlr_lms_stripe_payment
function gdlr_lms_stripe_payment()
{
global $gdlr_lms_option;
$ret = array();
Stripe::setApiKey($gdlr_lms_option['stripe-secret-key']);
if (!empty($_POST['token']) && !empty($_POST['invoice'])) {
global $wpdb;
$temp_sql = "SELECT * FROM " . $wpdb->prefix . "gdlrpayment ";
$temp_sql .= "WHERE id = " . $_POST['invoice'];
$result = $wpdb->get_row($temp_sql);
$payment_info = unserialize($result->payment_info);
try {
$charge = Stripe_Charge::create(array("amount" => floatval($result->price) * 100, "currency" => $gdlr_lms_option['stripe-currency-code'], "card" => $_POST['token'], "description" => $payment_info['email']));
$wpdb->update($wpdb->prefix . 'gdlrpayment', array('payment_status' => 'paid', 'attachment' => serialize($charge), 'payment_date' => date('Y-m-d H:i:s')), array('id' => $_POST['invoice']), array('%s', '%s', '%s'), array('%d'));
gdlr_lms_mail($payment_info['email'], __('Stripe Payment Received', 'gdlr-lms'), __('Your verification code is', 'gdlr-lms') . ' ' . $payment_info['code']);
$ret['status'] = 'success';
$ret['message'] = __('Payment complete, redirecting to the course page.', 'gdlr-lms');
$ret['redirect'] = get_permalink($result->course_id);
$ret['data'] = $result;
} catch (Stripe_CardError $e) {
$ret['status'] = 'failed';
$ret['message'] = $e->message;
}
} else {
$ret['status'] = 'failed';
$ret['message'] = __('Failed to retrieve the course, please made the payment from course page again.', 'gdlr-lms');
}
die(json_encode($ret));
}
示例5: 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];
}
示例6: process_payment
public function process_payment($order_id)
{
error_reporting(0);
$order = $this->api->getOrderByID($order_id);
$this->load_config();
$sandbox = true;
if ($this->m_config['STRIPE_SANDBOX']) {
$sandbox = false;
}
$amount = $order->gross * 100;
$currency = $order->currency;
$cardnumber = str_replace(" ", "", $_POST['credit_card_number']);
$cardname = $_POST['credit_card_name'];
$cardtype = $_POST['credit_card_type'];
$cvnnumber = $_POST['credit_card_cvn'];
$expdate = $_POST['credit_card_exp_month'] . $_POST['credit_card_exp_year'];
// API credentials only need to be defined once
define("STRIPE_TEST_API_KEY", $this->m_config['STRIPE_TEST_API_KEY']);
define("STRIPE_LIVE_API_KEY", $this->m_config['STRIPE_LIVE_API_KEY']);
define("STRIPE_SANDBOX", $sandbox);
if ($sandbox) {
Stripe::setApiKey(STRIPE_TEST_API_KEY);
} else {
Stripe::setApiKey(STRIPE_LIVE_API_KEY);
}
$c = Stripe_Charge::create(array("amount" => $amount, "currency" => $order->currency, "card" => array('number' => $cardnumber, 'exp_month' => $_POST['credit_card_exp_month'], 'exp_year' => $_POST['credit_card_exp_year']), "description" => "Charge for " . $cardname), array("idempotency_key" => $_POST['idempotency_key']));
if ($c->paid) {
$order->paid();
echo "<h2>Your payment was successfully processed. Thank you!</h2>";
echo "Success! Transaction ID:" . $c->receipt_number;
} else {
echo "<h2>Your card was declined.</h2>";
}
}
示例7: doMeta
public function doMeta()
{
$error = false;
// Set our metadata
Metadata::set(Input::except(['user', 'pass', '_token']));
Metadata::set('theme', 'default');
// Check the Stripe API key is valid
try {
Stripe::setApiKey(Metadata::item('stripe_key'));
Stripe\Balance::retrieve();
} catch (Exception $e) {
$error = 'That Stripe key doesn’t look valid!';
}
// Create the user
if (User::whereEmail(Input::get('user'))->exists()) {
// We're installing, can't have users already (I think)
// $error = 'Somebody’s already signed up with that email address!';
} else {
User::create(['username' => 'admin', 'name' => 'Administrator', 'level' => User::level('admin'), 'email' => Input::get('user'), 'password' => Input::get('pass')]);
}
if ($error === false) {
return Redirect::to('install/done');
}
View::share('error', $error);
return self::showMeta();
}
示例8: PMProGateway_stripe
function PMProGateway_stripe($gateway = NULL)
{
$this->gateway = $gateway;
$this->gateway_environment = pmpro_getOption("gateway_environment");
Stripe::setApiKey(pmpro_getOption("stripe_secretkey"));
return $this->gateway;
}
示例9: sktest_get_stripe_plans
function sktest_get_stripe_plans()
{
global $stripe_options;
// load the stripe libraries
if (!class_exists('Stripe')) {
require_once STRIPE_BASE_DIR . '/lib/Stripe.php';
}
// check if we are using test mode
if (isset($stripe_options['test_mode']) && $stripe_options['test_mode']) {
$secret_key = $stripe_options['test_secret_key'];
} else {
$secret_key = $stripe_options['live_secret_key'];
}
Stripe::setApiKey($secret_key);
// retrieve all plans from stripe
$plans_data = Stripe_Plan::all();
// setup a blank array
$plans = array();
if ($plans_data) {
foreach ($plans_data['data'] as $plan) {
// store the plan ID as the array key and the plan name as the value
$plans[$plan['id']] = $plan['name'];
}
}
return $plans;
}
示例10: __construct
public function __construct()
{
$this->id = 'stripe';
$this->icon = plugins_url('images/stripe.png', __FILE__);
$this->has_fields = true;
$this->method_title = 'Stripe Cards Settings';
$this->init_form_fields();
$this->init_settings();
$this->supports = array('default_credit_card_form', 'products', 'refunds');
$this->title = $this->get_option('stripe_title');
$this->stripe_testpublickey = $this->get_option('stripe_testpublickey');
$this->stripe_testsecretkey = $this->get_option('stripe_testsecretkey');
$this->stripe_livepublickey = $this->get_option('stripe_livepublickey');
$this->stripe_livesecretkey = $this->get_option('stripe_livesecretkey');
$this->stripe_storecurrency = $this->get_option('stripe_storecurrency');
$this->stripe_sandbox = $this->get_option('stripe_sandbox');
$this->stripe_authorize_only = $this->get_option('stripe_authorize_only');
$this->stripe_cardtypes = $this->get_option('stripe_cardtypes');
$this->stripe_enable_for_methods = $this->get_option('stripe_enable_for_methods', array());
$this->stripe_meta_cartspan = $this->get_option('stripe_meta_cartspan');
$this->stripe_zerodecimalcurrency = array("BIF", "CLP", "DJF", "GNF", "JPY", "KMF", "KRW", "MGA", "PYG", "RWF", "VND", "VUV", "XAF", "XOF", "XPF");
if (!defined("STRIPE_TRANSACTION_MODE")) {
define("STRIPE_TRANSACTION_MODE", $this->stripe_authorize_only == 'yes' ? false : true);
}
if ('yes' == $this->stripe_sandbox) {
Stripe::setApiKey($this->stripe_testsecretkey);
} else {
Stripe::setApiKey($this->stripe_livesecretkey);
}
if (is_admin()) {
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
}
}
示例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: processTransaction
public function processTransaction($data)
{
$log = Logger::getInstance();
$log->LogDebug("process transaction stripe - ");
if ($_POST) {
Stripe::setApiKey($this->SECRET_KEY);
$error = '';
$success = '';
try {
if (!isset($_POST['stripeToken'])) {
throw new Exception("The Stripe Token was not generated correctly");
}
Stripe_Charge::create(array("amount" => 1000, "currency" => "usd", "card" => $_POST['stripeToken']));
$success = 'Your payment was successful.';
} catch (Exception $e) {
$error = $e->getMessage();
}
}
$log->LogDebug("process response authorize - " . serialize($response));
if (isset($response->approved) && $response->approved == 1) {
$result->status = PAYMENT_SUCCESS;
$result->payment_status = PAYMENT_STATUS_PAID;
} else {
$result->status = PAYMENT_ERROR;
$result->payment_status = PAYMENT_STATUS_FAILURE;
$result->error_message = $response->error_message;
}
$result->transaction_id = 0;
$result->payment_date = date("Y-m-d");
$result->response_code = $response->approved;
$result->confirmation_id = $data->confirmation_id;
$result->processor_type = $this->type;
return $result;
}
示例13: 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;
}
示例14: 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);
}
}
示例15: __construct
public function __construct($passthru = false, $ajax = false)
{
date_default_timezone_set('EST');
if ($ajax) {
$this->ajax = true;
}
$this->passthru = $passthru;
error_reporting(E_ERROR | E_WARNING | E_PARSE);
openlog(config::APP_NAMESPACE, 0, LOG_LOCAL0);
$this->logFile = fopen(config::LOG_FILE, "a+");
$this->initDB();
// Bring up the database connection
$this->initMemcache();
$this->validateSession();
// Session startup and login validator
$this->escapeVars();
// Sanitation
$this->htmlData = base::init();
if (!$passthru) {
$this->buildUserObject();
}
// Build User Object
if ($this->getSetting('stripe_private')) {
Stripe::setApiKey($this->getSetting('stripe_private'));
}
}