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


PHP Stripe_Charge类代码示例

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


在下文中一共展示了Stripe_Charge类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: send

 /**
  * Create and send the request
  * 
  * @param array $options array of options to be send in POST request
  * @return gateway_response response object
  * 
  */
 public function send($options, $type = '')
 {
     $result = '';
     try {
         if ($type == 'subscription') {
             $result = Stripe_Customer::create($options);
         } elseif ($type == 'plan') {
             $result = Stripe_Plan::create($options);
         } elseif ($type == 'retrieve') {
             $result = Stripe_Plan::retrieve($options);
         } elseif ($type == 'customer') {
             $result = Stripe_Customer::create($options);
         } elseif ($type == 'invoice') {
             $result = Stripe_InvoiceItem::create($options);
             // Stripe_Customer::invoiceItems($options);
         } elseif ($type == 'cancel') {
             $cu = Stripe_Customer::retrieve($options['customer']);
             $result = $cu->cancelSubscription();
         } else {
             $result = Stripe_Charge::create($options);
         }
     } catch (Exception $ex) {
         $result = $ex;
     }
     $response = new stripe_response($result);
     return $response;
 }
开发者ID:shahadat014,项目名称:geleyi,代码行数:34,代码来源:gateway-request.php

示例2: charge

 public function charge(array $data)
 {
     try {
         return \Stripe_Charge::create(['amount' => '2000', 'currency' => 'usd', 'description' => $data['email'], 'card' => $data['token']]);
     } catch (Stripe_CardError $e) {
         dd('card was declined');
     }
 }
开发者ID:hopshoppub,项目名称:hopshop.dev,代码行数:8,代码来源:StripeBilling.php

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: testRetrieve

 public function testRetrieve()
 {
     authorizeFromEnv();
     $c = Stripe_Charge::create(array('amount' => 100, 'currency' => 'usd', 'card' => array('number' => '4242424242424242', 'exp_month' => 5, 'exp_year' => 2015)));
     $d = Stripe_Charge::retrieve($c->id);
     $this->assertEqual($d->id, $c->id);
 }
开发者ID:bulats,项目名称:chef,代码行数:7,代码来源:ChargeTest.php

示例8: put_charge

 function put_charge($request_data)
 {
     // permission
     /*if(!$this->permission->check($request_data)) {
     			return $this->permission->errorMessage();
     		};*/
     /*// validation
     		$this->filter->set_request_data($request_data);
     		if(!$this->filter->run()) {
     			$return["errors"] = $this->filter->get_errors('error');
     			return $return;
     		}
     		$request_data = $this->filter->get_request_data();*/
     $request_data = $this->filter->run($request_data);
     if ($this->filter->hasErrors()) {
         return $this->filter->getErrorsReturn();
     }
     $result = $this->db->select('customers', array('user_ID' => USER_ID));
     if (!$result) {
         return array('errors' => array('strip-customer' => 'No customer ID'));
     }
     $customer = $this->db->fetch_assoc($result);
     $c = Stripe_Customer::retrieve($customer['stripeTokens']);
     $c->updateSubscription(array("plan" => "basic", "prorate" => true));
     $charge = Stripe_Charge::create(array('customer' => $customer['stripeToken'], 'amount' => 5000, 'currency' => 'cad'));
 }
开发者ID:baki250,项目名称:angular-io-app,代码行数:26,代码来源:api.billing.php

示例9: 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));
 }
开发者ID:dsadinoff,项目名称:stripe-payments,代码行数:34,代码来源:stripe_payments.php

示例10: 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

示例11: 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

示例12: pay

 static function pay($currency)
 {
     global $wpdb, $user_ID, $user_email;
     $_course = new NamasteLMSCourseModel();
     $token = $_POST['stripeToken'];
     $course = get_post($_POST['course_id']);
     $fee = get_post_meta($course->ID, 'namaste_fee', true);
     $fee = apply_filters('namaste-coupon-applied', $fee);
     // coupon code from other plugin?
     try {
         $customer = Stripe_Customer::create(array('email' => $user_email, 'card' => $token));
         $charge = Stripe_Charge::create(array('customer' => $customer->id, 'amount' => $fee * 100, 'currency' => $currency));
     } catch (Exception $e) {
         wp_die($e->getMessage());
     }
     // !!!!in the next version avoid this copy-paste
     // almost the same code is in models/payment.php for the paypal payments
     $wpdb->query($wpdb->prepare("INSERT INTO " . NAMASTE_PAYMENTS . " SET \n\t\t\t\t\t\tcourse_id=%d, user_id=%s, date=CURDATE(), amount=%s, status='completed', paycode=%s, paytype='stripe'", $_POST['course_id'], $user_ID, $fee, $token));
     do_action('namaste-paid', $user_ID, $fee, "course", $_POST['course_id']);
     // enroll accordingly to course settings - this will be placed in a method once we
     // have more payment options
     $enroll_mode = get_post_meta($course->ID, 'namaste_enroll_mode', true);
     if (!NamasteLMSStudentModel::is_enrolled($user_ID, $course->ID)) {
         $status = $enroll_mode == 'free' ? 'enrolled' : 'pending';
         $_course->enroll($user_ID, $course->ID, $status);
     }
 }
开发者ID:Bnei-Baruch,项目名称:Namaste,代码行数:27,代码来源:stripe-model.php

示例13: charge

 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');
     }
 }
开发者ID:dioscouri,项目名称:f3-striper,代码行数:28,代码来源:PaymentRequest.php

示例14: 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;
 }
开发者ID:benji1979,项目名称:teszt1,代码行数:34,代码来源:Stripe.php

示例15: payForOrder

 public function payForOrder($order)
 {
     // Create a new customer
     $customer = \Stripe_Customer::create(array('email' => $order['customerEmail'], 'card' => $order['token']));
     // Pay for order
     $charge = \Stripe_Charge::create(array('customer' => $customer->id, 'amount' => $order['price'] * 100, 'currency' => 'usd'));
     // Return charge object
     return array('chargeId' => $charge->id, 'customerId' => $customer->id);
 }
开发者ID:hackathon-5,项目名称:power-ragers-repo,代码行数:9,代码来源:StripeController.php


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