Esempio n. 1
0
 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;
 }
 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;
     }
 }
Esempio n. 3
0
 /**
  * @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);
     }
 }
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));
}
Esempio n. 5
0
 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];
 }
Esempio n. 6
0
 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>";
     }
 }
Esempio n. 7
0
 /**
  * Payment callback function
  *
  * @param array $data
  * @return array
  */
 public function callback($data = array())
 {
     $data = $this->app->data->create($data);
     $id = (int) $data->get('order_id', null);
     if ($id) {
         $order = $this->app->zoocart->table->orders->get($id);
     } else {
         $order = $data->get('order', null);
     }
     // Check against frauds
     $isValid = $this->isValidIPN($data);
     if ($isValid) {
         try {
             $apiKey = $this->_getPrivateKey();
             Stripe::setApiKey($apiKey);
             $params = array('amount' => $data['amount'], 'currency' => $data['currency'], 'card' => $data['token'], 'description' => $data['description']);
             $transaction = Stripe_Charge::create($params);
         } catch (Exception $e) {
             $isValid = false;
             $data['failure_reason'] = $e->getMessage();
         }
     }
     if ($isValid && !empty($transaction['failure_message'])) {
         $isValid = false;
         $data['failure_reason'] = "Stripe failure: " . $transaction['failure_message'];
     }
     if (!$isValid) {
         $status = 0;
     } else {
         $status = $transaction['paid'] ? 1 : 0;
     }
     return array('status' => $status, 'transaction_id' => !empty($transaction) ? $transaction['balance_transaction'] : '', 'order_id' => $order->id, 'total' => $order->total);
 }
 public function __construct()
 {
     $this->id = 'stripe';
     $this->icon = apply_filters('woocommerce_stripe_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('products', 'refunds');
     $this->title = $this->get_option('stripe_title');
     $this->stripe_testsecretkey = $this->get_option('stripe_testsecretkey');
     $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');
     if (!defined("STRIPE_SANDBOX")) {
         define("STRIPE_SANDBOX", $this->stripe_sandbox == 'yes' ? true : false);
     }
     if (!defined("STRIPE_TRANSACTION_MODE")) {
         define("STRIPE_TRANSACTION_MODE", $this->stripe_authorize_only == 'yes' ? false : true);
     }
     if (STRIPE_SANDBOX == 'yes') {
         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'));
     }
 }
    /**
     * {@inheritDoc}
     */
    public function execute($request)
    {
        /** @var $request CreateCharge */
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());

        if (is_array($model['card'])) {
            throw new LogicException('The token has already been used.');
        }

        if (empty($model['card'])) {
            throw new LogicException('The token has to be set.');
        }

        try {
            \Stripe::setApiKey($this->keys->getSecretKey());

            $charge = \Stripe_Charge::create((array) $model);

            $model->replace($charge->__toArray(true));
        } catch (\Stripe_CardError $e) {
            $model->replace($e->getJsonBody());
        }
    }
Esempio n. 10
0
/**
 * 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;
}
Esempio n. 11
0
 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();
 }
 function PMProGateway_stripe($gateway = NULL)
 {
     $this->gateway = $gateway;
     $this->gateway_environment = pmpro_getOption("gateway_environment");
     Stripe::setApiKey(pmpro_getOption("stripe_secretkey"));
     return $this->gateway;
 }
Esempio n. 13
0
 function __construct()
 {
     global $psts;
     //setup the Stripe API
     require $psts->plugin_dir . "gateways/gateway-stripe-files/lib/Stripe.php";
     $stripe_secret_key = $psts->get_setting('stripe_secret_key');
     Stripe::setApiKey($stripe_secret_key);
     //settings
     add_action('psts_gateway_settings', array(&$this, 'settings'));
     add_filter('psts_settings_filter', array(&$this, 'settings_process'));
     //checkout stuff
     add_action('psts_checkout_page_load', array(&$this, 'process_checkout'));
     add_filter('psts_checkout_output', array(&$this, 'checkout_screen'), 10, 2);
     add_filter('psts_force_ssl', array(&$this, 'force_ssl'));
     //handle webhook notifications
     add_action('wp_ajax_nopriv_psts_stripe_webhook', array(&$this, 'webhook_handler'));
     //sync levels with Stripe
     add_action('network_admin_notices', array(&$this, 'levels_notice'));
     add_action('update_site_option_psts_levels', array(&$this, 'update_psts_levels'), 10, 3);
     add_filter('psts_setting_enabled_periods', array(&$this, 'disable_period_3'));
     //plug management page
     add_action('psts_subscription_info', array(&$this, 'subscription_info'));
     add_action('psts_subscriber_info', array(&$this, 'subscriber_info'));
     add_action('psts_modify_form', array(&$this, 'modify_form'));
     add_action('psts_modify_process', array(&$this, 'process_modify'));
     add_action('psts_transfer_pro', array(&$this, 'process_transfer'), 10, 2);
     //filter payment info
     add_action('psts_payment_info', array(&$this, 'payment_info'), 10, 2);
     //cancel subscriptions on blog deletion
     add_action('delete_blog', array(&$this, 'cancel_blog_subscription'));
     //update install script if necessary
     if ($psts->get_setting('stripe_version') != $psts->version) {
         $this->install();
     }
 }
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;
}
 public function processTransaction($data)
 {
     $log = Logger::getInstance();
     $log->LogDebug("process transaction stripe - ");
     $result = new stdClass();
     $result->status = PAYMENT_ERROR;
     $result->payment_status = PAYMENT_STATUS_FAILURE;
     Stripe::setApiKey($this->SECRET_KEY);
     $result->amount = $data->cost > 0 ? $data->cost : $data->total;
     $data->stripeToken = JRequest::getVar('stripeToken', null);
     $log->LogDebug("process transaction stripe - token -  " . $data->stripeToken);
     try {
         if (!isset($data->stripeToken)) {
             $result->error_message = "There was an error in processing your request. Please try again later.";
             $log->LogDebug("The Stripe Token was not generated correctly");
         } else {
             Stripe_Charge::create(array("amount" => $result->amount, "currency" => strtolower($data->reservationData->hotel->hotel_currency), "card" => $data->stripeToken));
             $result->status = PAYMENT_SUCCESS;
             $result->payment_status = PAYMENT_STATUS_PAID;
         }
     } catch (Exception $e) {
         $log->LogDebug($e->getMessage());
         $result->error_message = $e->getMessage();
     }
     $result->transaction_id = 0;
     $result->payment_date = date("Y-m-d");
     $result->response_code = 0;
     $result->confirmation_id = $data->confirmation_id;
     $result->processor_type = $this->type;
     return $result;
 }
 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'));
     }
 }
 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));
 }
Esempio n. 18
0
 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;
 }
Esempio n. 19
0
 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'));
     }
 }
Esempio n. 20
0
 /**
  * @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);
     }
 }
Esempio n. 21
0
 static function load()
 {
     require_once NAMASTE_PATH . '/lib/Stripe.php';
     $stripe = array('secret_key' => get_option('namaste_stripe_secret'), 'publishable_key' => get_option('namaste_stripe_public'));
     Stripe::setApiKey($stripe['secret_key']);
     return $stripe;
 }
Esempio n. 22
0
 public function charge()
 {
     $id = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'alnum');
     $request = $this->getModel()->setState('filter.id', $id)->getItem();
     $settings = \Striper\Models\Settings::fetch();
     // 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($settings->{$settings->mode . '.secret_key'});
     // Get the credit card token submitted by the form
     $token = $this->inputfilter->clean($this->app->get('POST.stripeToken'), 'string');
     // Create the charge on Stripe's servers - this will charge the user's card
     try {
         $charge = \Stripe_Charge::create(array("amount" => $request->amountForStripe(), "currency" => "usd", "card" => $token, "description" => $request->{'client.email'}));
         // this needs to be created empty in model
         $request->acceptPayment($charge);
         // SEND email to the client
         $request->sendChargeEmailClient($charge);
         $request->sendChargeEmailAdmin($charge);
         $this->app->set('charge', $charge);
         $this->app->set('paymentrequest', $request);
         $view = \Dsc\System::instance()->get('theme');
         echo $view->render('Striper/Site/Views::paymentrequest/success.php');
     } catch (\Stripe_CardError $e) {
         // The card has been declined
         $view = \Dsc\System::instance()->get('theme');
         echo $view->render('Striper/Site/Views::paymentrequest/index.php');
     }
 }
 public function __construct(EntityManager $em, $container)
 {
     parent::__construct($em);
     $this->container = $container;
     $stripeParams = $container->getParameter('stripe_params');
     $apiKey = $stripeParams['secret_key'];
     \Stripe::setApiKey($apiKey);
 }
Esempio n. 24
0
 /**
  * register the required scripts and style
  */
 function init()
 {
     //		$this->flashvars['src'] = "js:escape('".$src."')";
     $stripe = array("secret_key" => $this->secretKey, "publishable_key" => $this->publishableKey);
     Stripe::setApiKey($stripe['secret_key']);
     //$this->checkoutJsUrl = $this->baseUrl."/checkout.js";
     return parent::init();
 }
Esempio n. 25
0
function authorizeFromEnv()
{
    $apiKey = getenv('STRIPE_API_KEY');
    if (!$apiKey) {
        $apiKey = "tGN0bIwXnHdwOa85VABjPdSn8nWY7G7I";
    }
    Stripe::setApiKey($apiKey);
}
 /**
  * Generates Stripe Payment form thanks the Stripe API.
  *
  * @param object $oMembership The Object Membership Model.
  * @return void
  */
 public function buttonStripe($oMembership)
 {
     $oStripe = new Stripe();
     $oStripe->param('item_number', $oMembership->groupId)->param('member_id', $this->session->get('member_id'))->param('amount', $oMembership->price);
     echo '<form action="', $oStripe->getUrl(), '" method="post">', $oStripe->generate(), '<script
             src="https://checkout.stripe.com/checkout.js" class="stripe-button"
             data-key="', $this->config->values['module.setting']['stripe.publishable_key'], '"
             data-name="', $this->registry->site_name, '"
             data-description="', $oMembership->name, '"
             data-amount="', str_replace('.', '', $oMembership->price), '"
             data-currency="', $this->config->values['module.setting']['currency'], '"
             data-allow-remember-me="true"
             data-bitcoin="true">
         </script>
     </form>';
     unset($oStripe);
 }
Esempio n. 27
0
 public function __construct()
 {
     parent::__construct();
     include_once OTHERS . 'stripe/lib/Stripe.php';
     Stripe::setApiKey(STRIPE_SECRET_KEY);
     $this->load->library('session');
     $this->load->model('user_model');
 }
function authorizeFromEnv()
{
    $apiKey = getenv('STRIPE_API_KEY');
    if (!$apiKey) {
        throw new Stripe_Error('You need to set STRIPE_API_KEY');
    }
    Stripe::setApiKey($apiKey);
}
Esempio n. 29
0
 protected static function authorizeFromEnv()
 {
     $apiKey = getenv('STRIPE_API_KEY');
     if (!$apiKey) {
         $apiKey = self::API_KEY;
     }
     Stripe::setApiKey($apiKey);
 }
Esempio n. 30
0
 public function testSave()
 {
     Stripe::setApiKey('sk_test_JieJALRz7rPz7boV17oMma7a');
     $s = Source::create(array('type' => 'bitcoin', 'currency' => 'usd', 'amount' => '100', 'owner[email]' => '*****@*****.**'));
     $this->assertSame('bitcoin', $s->type);
     $source = Source::retrieve($s->id);
     $this->assertSame(100, $source->amount);
 }