当前位置: 首页>>代码示例>>PHP>>正文


PHP Stripe类代码示例

本文整理汇总了PHP中Stripe的典型用法代码示例。如果您正苦于以下问题:PHP Stripe类的具体用法?PHP Stripe怎么用?PHP Stripe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Stripe类的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;
 }
开发者ID:hhgr,项目名称:uksoccer,代码行数:27,代码来源:stripe.class.php

示例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;
     }
 }
开发者ID:raminabsari,项目名称:phonicsschool,代码行数:31,代码来源:stripe_gateway.php

示例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);
     }
 }
开发者ID:sanderdrummer,项目名称:Homepages,代码行数:37,代码来源:pay.php

示例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));
}
开发者ID:AnduZhang,项目名称:resource-center,代码行数:29,代码来源:stripe-payment.php

示例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];
 }
开发者ID:bigset1,项目名称:blueridge,代码行数:7,代码来源:Teller.php

示例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>";
     }
 }
开发者ID:hyrmedia,项目名称:builderengine,代码行数:34,代码来源:Stripegateway.php

示例7: callback

 /**
  * 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);
 }
开发者ID:knigherrant,项目名称:decopatio,代码行数:39,代码来源:stripe.php

示例8: __construct

 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'));
     }
 }
开发者ID:pcuervo,项目名称:ur-imprint,代码行数:31,代码来源:stripe-woocommerce-addon.php

示例9: execute

    /**
     * {@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());
        }
    }
开发者ID:xxspartan16,项目名称:BMS-Market,代码行数:28,代码来源:CreateChargeAction.php

示例10: 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;
}
开发者ID:kfuchs,项目名称:fwdcommerce,代码行数:33,代码来源:fwd-stripe.php

示例11: 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();
 }
开发者ID:BinaryGeometry,项目名称:aviate,代码行数:26,代码来源:InstallController.php

示例12: 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;
 }
开发者ID:Seravo,项目名称:wp-paid-subscriptions,代码行数:7,代码来源:class.pmprogateway_stripe.php

示例13: __construct

 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();
     }
 }
开发者ID:hscale,项目名称:webento,代码行数:35,代码来源:gateway-stripe.php

示例14: 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;
}
开发者ID:sekurtz1,项目名称:wordpress-stripe-integration,代码行数:26,代码来源:stripe-functions.php

示例15: processTransaction

 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;
 }
开发者ID:jmangarret,项目名称:webtuagencia24,代码行数:31,代码来源:stripeProcessor.php


注:本文中的Stripe类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。