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


PHP Stripe\Charge类代码示例

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


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

示例1: bill_user

 public function bill_user()
 {
     \Stripe\Stripe::setApiKey("sk_test_BzcfGDAVwQw9efuWp2eVvyVg");
     $stripe_info = $this->input->post();
     $billing = $this->user->get_billing_id($this->session->userdata("id"));
     $total = $this->cart->get_total_cents($this->cart->get_all());
     if ($billing["billing_id"]) {
         // var_dump($total);
         // die();
         \Stripe\Charge::create(array("amount" => $total, "currency" => "usd", "customer" => $billing["billing_id"]));
     } else {
         $customer = \Stripe\Customer::create(array("source" => $stripe_info["stripeToken"], "description" => "Example customer"));
         $this->user->set_billing_id($customer["id"]);
         try {
             $charge = \Stripe\Charge::create(array("amount" => $total, "currency" => "usd", "customer" => $customer["id"], "description" => "Example charge"));
         } catch (\Stripe\Error\Card $e) {
             // The card has been declined
         }
     }
     $cart_items = $this->cart->get_all();
     foreach ($cart_items as $item) {
         $this->cart->delete($item['product_id'], $item['recipient_id']);
         $this->wishlist->delete_from_wishlist($item['product_id'], $item['recipient_id']);
     }
     redirect("/carts/viewcart");
 }
开发者ID:Jeff-Ch,项目名称:Wishlist,代码行数:26,代码来源:billing.php

示例2: createCharge

 public function createCharge()
 {
     Stripe::setApiKey($this->stripeConfig['testSecretKey']);
     $stripeCharge = StripeCharge::create(['amount' => 2000, 'currency' => 'usd', 'card' => 'tok_16ZzIaH7PksWTbQLK6AvzuVR', 'description' => 'Describe your product']);
     echo '<pre>';
     print_r($stripeCharge);
     echo '</pre>';
 }
开发者ID:kongtoonarmy,项目名称:laravel-stripe,代码行数:8,代码来源:StripeController.php

示例3: mockStripeCharge

 /**
  * @throws \InvalidArgumentException
  *
  * @return MockInterface
  */
 private function mockStripeCharge() : MockInterface
 {
     if ($this->mockStripeCharge === null) {
         $this->mockStripeCharge = Mockery::mock(Charge::class);
         $this->mockStripeCharge->shouldIgnoreMissing()->asUndefined();
         app()->extend(Charge::class, function () {
             return $this->mockStripeCharge;
         });
     }
     return $this->mockStripeCharge;
 }
开发者ID:hughgrigg,项目名称:ching-shop,代码行数:16,代码来源:MockStripe.php

示例4: pay

 /**
  * @param string $stripeToken
  *
  * @throws \Exception
  *
  * @return Order
  */
 public function pay(string $stripeToken) : Order
 {
     Log::info(sprintf('Taking Stripe payment for %s (%s) with token `%s`.', $this->basket()->totalPrice()->formatted(), $this->basket()->totalPrice()->amount(), $stripeToken));
     $settlement = StripeSettlement::create(['token' => $stripeToken]);
     $order = $this->cashier->settle($this->basket(), $settlement);
     Log::info("Charging for order `{$order->publicId()}` with Stripe.");
     /** @var Charge $charge */
     $charge = $this->charge->create(['amount' => $this->basket()->totalPrice()->amount(), 'currency' => 'gbp', 'source' => $stripeToken, 'description' => "ching-shop.com order {$order->publicId()}"]);
     Log::info("Took payment for for order `{$order->publicId()}` with Stripe.");
     if ($charge instanceof Charge) {
         $settlement->fillFromCharge($charge)->save();
     }
     return $order;
 }
开发者ID:hughgrigg,项目名称:ching-shop,代码行数:21,代码来源:StripeCheckout.php

示例5: charge

 function charge($token, $billing_info, $cart, $user)
 {
     $data = $this->_form_data($billing_info);
     $data['amount'] = $cart['total'] * 100;
     //amount is in cents
     $data['source'] = $token;
     $data['description'] = $user['email'];
     try {
         //Set API Key
         \Stripe\Stripe::setApiKey($this->ci->config->item('test_secret_key'));
         $charge = \Stripe\Charge::create($data);
         return $charge;
     } catch (\Stripe\Error\Card $e) {
         return $e->getJsonBody();
     } catch (\Stripe\Error\InvalidRequest $e) {
         return $e->getJsonBody();
     } catch (\Stripe\Error\ApiConnection $e) {
         return $e->getJsonBody();
     } catch (\Stripe\Error\Api $e) {
         return $e->getJsonBody();
     } catch (\Stripe\Error\Authentication $e) {
         return $e->getJsonBody();
     } catch (\Stripe\Error\Base $e) {
         return $e->getJsonBody();
     }
 }
开发者ID:nbrady-techempower,项目名称:faithwraps,代码行数:26,代码来源:Stripe_api.php

示例6: completeDonation

 public function completeDonation()
 {
     // Validate amount
     $amount = $this->request->data('amount');
     if (!is_numeric($amount)) {
         throw new ForbiddenException('Donation amount must be numeric');
     } elseif ($amount < 1) {
         throw new ForbiddenException('Donation must be at least one dollar');
     }
     $metadata = [];
     if ($this->Auth->user('id')) {
         $metadata['Donor name'] = $this->Auth->user('name');
     } else {
         $metadata['Donor name'] = '';
     }
     $metadata['Donor email'] = $this->request->data('email');
     // Create the charge on Stripe's servers - this will charge the user's card
     $apiKey = Configure::read('Stripe.Secret');
     \Stripe\Stripe::setApiKey($apiKey);
     try {
         $description = 'Donation to MACC of $' . number_format($amount, 2);
         $charge = \Stripe\Charge::create(['amount' => $amount * 100, 'currency' => 'usd', 'source' => $this->request->data('stripeToken'), 'description' => $description, 'metadata' => $metadata, 'receipt_email' => $this->request->data('email')]);
     } catch (\Stripe\Error\Card $e) {
         throw new ForbiddenException('The provided credit card has been declined');
     }
     $this->viewBuilder()->layout('json');
     $this->set(['_serialize' => ['retval'], 'retval' => ['success' => true]]);
 }
开发者ID:PhantomWatson,项目名称:macc,代码行数:28,代码来源:DonationsController.php

示例7: chargeCustomer

 protected function chargeCustomer()
 {
     if ($this->isPostBack() && !$this->input('mark_payed')) {
         $this->post->amount->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputFloat()]);
         if (!$this->hasErrors()) {
             $amount = (double) $this->input('amount') * 100;
             try {
                 Stripe::setApiKey(env('STRIPE_KEY'));
                 $stripe = Charge::create(['customer' => $this->organisation->stripe_identifier_id, 'amount' => $amount, 'currency' => $this->settings->getCurrency(), 'description' => 'NinjaImg ' . date('m-Y', strtotime($this->startDate)) . '-' . date('m-Y', strtotime($this->endDate))]);
                 if (!isset($stripe->paid) || !$stripe->paid) {
                     $this->setError('Failed to charge credit-card');
                 }
                 if (!$this->hasErrors()) {
                     $payment = new ModelPayment();
                     $payment->amount = $amount;
                     $payment->currency = $this->settings->getCurrency();
                     $payment->period_start = $this->startDate;
                     $payment->period_end = $this->endDate;
                     $payment->transaction_id = $stripe->id;
                     $payment->organisation_id = $this->organisation->id;
                     $payment->save();
                 }
             } catch (\Exception $e) {
                 $this->setError($e->getMessage());
             }
             if (!$this->hasErrors()) {
                 $this->organisation->getPayment($this->startDate, $this->endDate)->updateFreeCredits();
                 $this->setMessage('Successfully charged ' . $this->input('amount') . ' ' . $this->settings->getCurrency(), 'success');
             }
             response()->refresh();
         }
     }
 }
开发者ID:Monori,项目名称:imgservice,代码行数:33,代码来源:Details.php

示例8: check

 public function check($bid)
 {
     $bid = Bids::findOrFail(Input::get("bid"));
     $offset = Input::get("offset");
     if ($offset < 0) {
         $now = \Carbon\Carbon::now()->subHours($offset);
     } else {
         $now = \Carbon\Carbon::now()->addHours($offset);
     }
     if (strtotime($bid->expiration) - strtotime($now) < 0) {
         //bid is expired
         if ($bid->amount < $bid->reservedPrice) {
             //void since bidding price is less then reserved price
             $bid->delete();
             return "Bidding price less then reserved price";
         } else {
             //proceed and Charge
             //since we get information about expiration from client we have to check it on the server as well
             //check wether winning user has its card working
             if ($bid->customerId) {
                 \Stripe\Stripe::setApiKey("sk_test_Z98H9hmuZWjFWfbkPFvrJMgk");
                 \Stripe\Charge::create(array("amount" => $bid->priceToCents(), "currency" => "usd", "customer" => $bid->customerId));
                 \Log::info('Charged: ' . $bid->amount);
             }
             $bid->complete = 1;
             $bid->save();
             $bid->delete();
         }
     } else {
         //someone is messing with javascript
         return "error";
     }
     return "Bidding is valid";
 }
开发者ID:alexandrzavalii,项目名称:auction,代码行数:34,代码来源:BidController.php

示例9: stripe_tls_check

 /**
  * Stripe TLS requirement.
  * https://support.stripe.com/questions/how-do-i-upgrade-my-stripe-integration-from-tls-1-0-to-tls-1-2
  */
 private static function stripe_tls_check($for_export)
 {
     global $sc_options;
     // Set Stripe API key. Force test key.
     Stripe_Checkout_Functions::set_key('true');
     $test_key = $sc_options->get_setting_value('test_secret_key');
     // If test key isn't set...
     if (empty($test_key)) {
         if ($for_export) {
             return __('Cannot test TLS 1.2 support until your Stripe Test Secret Key is entered.', 'stripe');
         } else {
             return '<mark class="error">' . __('Cannot test TLS 1.2 support until your Stripe Test Secret Key is entered.', 'stripe') . '</mark>';
         }
     }
     \Stripe\Stripe::$apiBase = 'https://api-tls12.stripe.com';
     try {
         \Stripe\Charge::all();
         if ($for_export) {
             return __('TLS 1.2 supported, no action required.', 'stripe');
         } else {
             return '<mark class="ok">' . __('TLS 1.2 supported, no action required.', 'stripe') . '</mark>';
         }
     } catch (\Stripe\Error\ApiConnection $e) {
         if ($for_export) {
             return sprintf(__('TLS 1.2 is not supported. You will need to upgrade your integration. See %1$s.', 'stripe'), 'https://stripe.com/blog/upgrading-tls');
         } else {
             return '<mark class="error">' . sprintf(__('TLS 1.2 is not supported. You will need to upgrade your integration. <a href="%1$s">Please read this</a> for more information.', 'stripe'), 'https://stripe.com/blog/upgrading-tls') . '</mark>';
         }
     }
 }
开发者ID:pcuervo,项目名称:wp-yolcan,代码行数:34,代码来源:class-stripe-checkout-shared-system-status.php

示例10: charge

 /**
  * @param array $data
  * @param       $token
  * @return Charge
  * @throws StripeException
  */
 public function charge(array $data, $token)
 {
     try {
         return Charge::create(["amount" => $data['amount'], "currency" => $data['currency'], "source" => $token, "description" => $data['email']]);
     } catch (Card $e) {
         $body = $e->getJsonBody();
         $err = $body['error'];
         $this->logger->error('Stripe error: ' . $err['type'] . ': ' . $err['code'] . ': ' . $err['message']);
         $error = $e->getMessage();
     } catch (InvalidRequest $e) {
         $body = $e->getJsonBody();
         $err = $body['error'];
         $this->logger->error('Stripe error: ' . $err['type'] . ': ' . $err['message']);
         $error = $err['message'];
     } catch (Authentication $e) {
         $body = $e->getJsonBody();
         $this->logger->error('Stripe error: API key rejected!');
         $error = 'Payment processor API key error. ' . $e->getMessage();
     } catch (Api $e) {
         $this->logger->error('Stripe error: Stripe could not be reached.');
         $error = 'Network communication with payment processor failed, try again later. ' . $e->getMessage();
     } catch (Exception $e) {
         $this->logger->error('Stripe error: Unknown error. ' . $e->getMessage());
         $error = 'There was an error, try again later. ' . $e->getMessage();
     }
     if ($error !== null) {
         // an error is always a string
         throw new StripeException($error);
     }
 }
开发者ID:iulyanp,项目名称:stripe-bundle,代码行数:36,代码来源:StripeBilling.php

示例11: charge

 public function charge($Token, $Amount, $Description, $Meta = array(), $Currency = 'gbp')
 {
     // Set your secret key: remember to change this to your live secret key in production
     // See your keys here https://dashboard.stripe.com/account/apikeys
     \Stripe\Stripe::setApiKey($this->config['secret_key']);
     // Create the charge on Stripe's servers - this will charge the user's card
     try {
         $charge = \Stripe\Charge::create(array("amount" => floatval($Amount) * 100, "currency" => $Currency, "source" => $Token, "description" => $Description, "metadata" => $Meta));
         return true;
     } catch (\Stripe\Error\ApiConnection $e) {
         // Network problem, perhaps try again.
         return $e;
     } catch (\Stripe\Error\InvalidRequest $e) {
         // You screwed up in your programming. Shouldn't happen!
         return $e;
     } catch (\Stripe\Error\Api $e) {
         // Stripe's servers are down!
         return $e;
     } catch (\Stripe\Error\Card $e) {
         // Card was declined.
         return $e;
     } catch (\Stripe\Error\Base $e) {
         // ?????
         return $e;
     } catch (\Stripe\Error\RateLimit $e) {
         // ?????
         return $e;
     }
     return false;
 }
开发者ID:Swift-Jr,项目名称:thmdhc,代码行数:30,代码来源:stripelib.php

示例12: testRetrieve

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

示例13: postPayment

 public function postPayment(PaymentFormRequest $request, $eventId, $attendeeId)
 {
     $registeredAttendee = $this->attendees->findById($attendeeId);
     $event = $this->events->findById($eventId);
     $input = $request->all();
     $token = $input['stripeToken'];
     if (empty($token)) {
         Flash::error('Your order could not be processed.  Please ensure javascript in enabled and try again.');
         return redirect()->back();
     }
     try {
         \Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
         $stripeCustomer = \Stripe\Customer::create(['source' => $token, 'description' => 'Stripe charge for AARMS customer: ' . $registeredAttendee->id, 'email' => $registeredAttendee->email]);
         $charge = \Stripe\Charge::create(['amount' => $event->price_cents, 'currency' => 'usd', 'customer' => $stripeCustomer->id, 'description' => 'Stripe charge for event: ' . $event->title]);
         if (!$charge) {
             Flash::error("Could not process Credit Card Payment");
             return redirect()->back();
         } else {
             $registeredAttendee->amount_paid = $event->price;
             $registeredAttendee->save();
             $sendMail = new SendInvoiceEmail($registeredAttendee);
             $this->dispatch($sendMail);
         }
         Flash::success("Payment successful!");
         return redirect()->back();
     } catch (\Stripe\Error\Card $e) {
         Flash::error($e->getMessage());
         return redirect()->back();
     }
 }
开发者ID:dirtyblankets,项目名称:allaccessrms,代码行数:30,代码来源:RegistrationPaymentController.php

示例14: processStripePayment

function processStripePayment($cents_amount, $email)
{
    if (isset($_POST['stripeToken'])) {
        $token = $_POST['stripeToken'];
        $customer = \Stripe\Customer::create(array('card' => $token, 'email' => strip_tags(trim($_POST['email']))));
        $customer_id = $customer->id;
        try {
            $charge = \Stripe\Charge::create(array("amount" => $cents_amount, "currency" => "usd", "description" => "Weblytics Sign-Up", "customer" => $customer_id));
            $mail = new PHPMailer();
            $mail->IsSMTP();
            // send via SMTP
            $mail->SMTPAuth = true;
            // turn on SMTP authentication
            $mail->SMTPSecure = 'tls';
            $mail->Host = 'smtp.gmail.com';
            $mail->Port = 587;
            $mail->Username = 'cs4753.eCommerce@gmail.com';
            // Enter your SMTP username
            $mail->Password = '12qwas3.';
            // SMTP password
            $mail->FromName = 'Weblytics';
            $mail->addAddress($email);
            $mail->Subject = 'Weblytics - Payment Received';
            $mail->Body = 'Your payment of $5.00 associated with our sign-up fee has been received.';
            if (!$mail->send()) {
                //error
            } else {
                //good
            }
        } catch (\Stripe\Error\Card $e) {
            //Card has been declined
        }
    }
}
开发者ID:johnmirby,项目名称:CS4753-eCommerce-Project,代码行数:34,代码来源:signup.php

示例15: capture

 /**
  * Capture a preauthorized charge.
  *
  * @param array $properties
  * 
  * @return Charge
  */
 public function capture(array $properties = array())
 {
     $this->info();
     $this->stripe_charge->capture(array('amount' => Arr::get($properties, 'amount') ? Arr::get($properties, 'amount') : null));
     $this->stripe_charge = null;
     return $this;
 }
开发者ID:autocar,项目名称:laravel-billing,代码行数:14,代码来源:Charge.php


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