/** * @param string $apiKey * @param string $apiVersion */ public function __construct($apiKey, $apiVersion = null) { $this->apiKey = $apiKey; $this->apiVersion = $apiVersion; \Stripe::setApiKey($this->apiKey); if ($this->apiVersion) { \Stripe::setApiVersion($this->apiVersion); } }
public function init() { require craft()->path->getPluginsPath() . 'charge/vendor/stripe/lib/Stripe.php'; $plugin = craft()->plugins->getPlugin('charge'); if (!$plugin) { throw new Exception('Couldn’t find the Charge plugin!'); } $settings = $plugin->getSettings(); $this->_mode = $settings->stripeAccountMode; $keyName = 'stripe' . ucwords($settings->stripeAccountMode) . 'CredentialsSK'; if (isset($settings->{$keyName})) { \Stripe::setApiKey($settings->{$keyName}); } \Stripe::setApiVersion($this->apiVersion); }
function __construct() { global $psts; //setup the Stripe API if (!class_exists('Stripe')) { require_once $psts->plugin_dir . "gateways/gateway-stripe-files/lib/Stripe.php"; } $stripe_secret_key = $psts->get_setting('stripe_secret_key'); Stripe::setApiKey($stripe_secret_key); // Stripe::setApiVersion( '2013-08-13' ); Stripe::setApiVersion('2015-02-16'); //make sure everyone is using the same API version. we can update this if/when necessary. if (!is_admin()) { add_action('wp_enqueue_scripts', array('ProSites_Gateway_Stripe', 'do_scripts')); } //settings add_action('psts_gateway_settings', array(&$this, 'settings')); add_action('psts_settings_process', array('ProSites_Gateway_Stripe', 'settings_process'), 10, 1); //checkout stuff add_filter('psts_force_ssl', array('ProSites_Gateway_Stripe', 'force_ssl')); //handle webhook notifications add_action('wp_ajax_nopriv_psts_stripe_webhook', array('ProSites_Gateway_Stripe', 'webhook_handler')); add_action('wp_ajax_psts_stripe_webhook', array('ProSites_Gateway_Stripe', 'webhook_handler')); //sync levels with Stripe add_action('update_site_option_psts_levels', array('ProSites_Gateway_Stripe', 'update_psts_levels'), 10, 3); //plug management page add_action('psts_subscription_info', array('ProSites_Gateway_Stripe', 'subscription_info')); add_action('psts_subscriber_info', array('ProSites_Gateway_Stripe', 'subscriber_info')); add_action('psts_modify_form', array('ProSites_Gateway_Stripe', 'modify_form')); add_action('psts_modify_process', array('ProSites_Gateway_Stripe', 'process_modify')); add_action('psts_transfer_pro', array('ProSites_Gateway_Stripe', 'process_transfer'), 10, 2); //filter payment info - Deprecated add_action('psts_payment_info', array('ProSites_Gateway_Stripe', 'payment_info'), 10, 2); //return next payment date for emails add_filter('psts_next_payment', array('ProSites_Gateway_Stripe', 'next_payment')); //cancel subscriptions on blog deletion add_action('delete_blog', array('ProSites_Gateway_Stripe', 'cancel_subscription')); //display admin notices add_action('admin_notices', array(&$this, 'admin_notices')); //transaction hooks add_filter('prosites_transaction_object_create', array('ProSites_Gateway_Stripe', 'create_transaction_object'), 10, 3); //update install script if necessary if ($psts->get_setting('stripe_version') != $psts->version) { $this->install(); } }
public function initialize($credentials) { if (!function_exists('curl_init')) { throw new Exception('stripe needs the CURL PHP extension.'); } $this->type = $credentials->type; $this->name = $credentials->name; $this->mode = $credentials->mode; $this->TRANSACTION_KEY = $credentials->fields['TRANSACTION_KEY']; $this->SECRET_KEY = $credentials->fields['SECRET_KEY']; Stripe::setApiKey($this->TRANSACTION_KEY); Stripe::setApiVersion("2014-11-05"); if (trim($credentials->mode) == 'test') { $this->AUTHORIZENET_SANDBOX = 'true'; } else { $this->AUTHORIZENET_SANDBOX = 'false'; } }
public function execute(\Payment $payment) { libraries_load('stripe-php'); $context =& $payment->contextObj; $api_key = $payment->method->controller_data['private_key']; switch ($context->value('donation_interval')) { case 'm': $interval = 'month'; break; case 'y': $interval = 'year'; break; default: $interval = NULL; break; } try { \Stripe::setApiKey($api_key); \Stripe::setApiVersion('2014-01-31'); $customer = $this->createCustomer($payment->method_data['stripe_payment_token'], $this->getName($context), $context->value('email')); $stripe = NULL; $plan_id = NULL; if (!$interval) { $stripe = $this->createCharge($customer, $payment); } else { $plan_id = $this->createPlan($customer, $payment, $interval); $stripe = $this->createSubscription($customer, $plan_id); } $payment->setStatus(new \PaymentStatusItem(PAYMENT_STATUS_SUCCESS)); $payment->save(); $params = array('pid' => $payment->pid, 'stripe_id' => $stripe->id, 'type' => $stripe->object, 'plan_id' => $plan_id); \Drupal::database()->insert('stripe_payment')->fields($params)->execute(); } catch (\Stripe_Error $e) { $payment->setStatus(new \PaymentStatusItem(PAYMENT_STATUS_FAILED)); $payment->save(); $message = '@method payment method encountered an error while contacting ' . 'the stripe server. The status code "@status" and the error ' . 'message "@message". (pid: @pid, pmid: @pmid)'; $variables = array('@status' => $e->getHttpStatus(), '@message' => $e->getMessage(), '@pid' => $payment->pid, '@pmid' => $payment->method->pmid, '@method' => $payment->method->title_specific); \Drupal::logger('stripe_payment')->error($message, []); } }
public function executeStripe() { $response = null; $userData = new AB_UserBookingData($this->getParameter('form_id')); if ($userData->load()) { if ($userData->get('service_id')) { Stripe::setApiKey(get_option('ab_stripe_secret_key')); Stripe::setApiVersion("2014-10-07"); $price = $userData->getFinalServicePrice() * $userData->get('number_of_persons'); $stripe_data = array('number' => $this->getParameter('ab_card_number'), 'exp_month' => $this->getParameter('ab_card_month'), 'exp_year' => $this->getParameter('ab_card_year'), 'cvc' => $this->getParameter('ab_card_code')); try { $charge = Stripe_Charge::create(array('card' => $stripe_data, 'amount' => intval($price * 100), 'currency' => get_option('ab_paypal_currency'), 'description' => "Charge for " . $userData->get('email'))); if ($charge->paid) { $appointment = $userData->save(); $customer_appointment = new AB_CustomerAppointment(); $customer_appointment->loadBy(array('appointment_id' => $appointment->get('id'), 'customer_id' => $userData->getCustomerId())); $payment = new AB_Payment(); $payment->set('total', $price); $payment->set('type', 'stripe'); $payment->set('customer_appointment_id', $customer_appointment->get('id')); $payment->set('created', current_time('mysql')); $payment->save(); $response = array('status' => 'success'); } else { $response = array('status' => 'error', 'error' => 'unknown error'); } } catch (Exception $e) { $response = array('status' => 'error', 'error' => $e->getMessage()); } } } else { $response = array('status' => 'error', 'error' => __('Session error.', 'bookly')); } // Output JSON response. wp_send_json($response); }
public function process_payment($order_id) { global $woocommerce; $wc_order = new WC_Order($order_id); $grand_total = $wc_order->order_total; $amount = (int) $grand_total; include plugin_dir_path(__FILE__) . "lib/Stripe.php"; Stripe::setApiKey($this->stripe_secretkey); Stripe::setApiVersion("2014-06-17"); $token_id = Stripe_Token::create(array("card" => array("number" => $_POST['cardno_stripe'], "exp_month" => $_POST['expmonth_stripe'], "exp_year" => $_POST['expyear_stripe'], "cvc" => $_POST['cardcvv_stripe']))); $charge = Stripe_Charge::create(array("amount" => $amount, "currency" => "USD", "card" => $token_id->id, "metadata" => array("order_id" => $order_id))); if ($token_id->id != '') { if ($charge->paid == true) { $wc_order->add_order_note(__(' Stripe payment completed. ', 'woocommerce')); $wc_order->payment_complete(); return array('result' => 'success', 'redirect' => $this->get_return_url($wc_order)); } else { $wc_order->add_order_note(__('Stripe payment failed. Payment declined.', 'woocommerce')); $woocommerce->add_error(__('Sorry, the transaction was declined.', 'woocommerce')); } } else { $wc_order->add_order_note(__('Stripe payment failed. Payment declined. Please Check your Admin settings', 'woocommerce')); $woocommerce->add_error(__('Sorry, the transaction was declined. Please Check your Admin settings', 'woocommerce')); } }
<?php // map class name to file Autoloader::map(array('Stripe' => __DIR__ . '/lib/Stripe.php')); Stripe::setApiKey(Config::get('stripe.api_key', '')); Stripe::setApiVersion(Config::get('stripe.api_version', ''));
function onPaymentNotification(&$statuses) { if (!$this->init()) { return false; } $order_id = (int) $_REQUEST['orderid']; $dbOrder = $this->getOrder($order_id); $this->loadPaymentParams($dbOrder); if (empty($this->payment_params)) { echo 'The system can\'t load the payment params'; return false; } $this->loadOrderData($dbOrder); $return_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id=' . $order_id . $this->url_itemid; $cancel_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=order&task=cancel_order&order_id=' . $order_id . $this->url_itemid; $currency = $this->currency->currency_code; $amout = round($dbOrder->order_full_price, 2) * 100; $desc = JText::sprintf('ORDER_NUMBER') . ' : ' . $order_id; Stripe::setApiKey(trim($this->payment_params->secret_key)); Stripe::setApiVersion('2013-12-03'); $token = $_POST['stripeToken']; try { $charge = Stripe_Charge::create(array("amount" => $amout, "currency" => $currency, "card" => $token, "description" => $desc)); } catch (Exception $e) { $this->modifyOrder($order_id, $this->payment_params->invalid_status, true, true); $this->app->redirect($cancel_url, 'Error charge : ' . $e->getMessage()); return false; } $this->modifyOrder($order_id, $this->payment_params->verified_status, true, true); $this->app->redirect($return_url); return true; }