作者:Jeff-C
项目:Wishlis
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");
}
作者:kongtoonarm
项目:laravel-strip
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>';
}
作者:hughgrig
项目:ching-sho
/**
* @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;
}
作者:hughgrig
项目:ching-sho
/**
* @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;
}
作者:nbrady-techempowe
项目:faithwrap
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();
}
}
作者:PhantomWatso
项目:mac
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]]);
}
作者:Monor
项目:imgservic
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();
}
}
}
作者:alexandrzavali
项目:auctio
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";
}
作者:pcuerv
项目:wp-yolca
/**
* 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>';
}
}
}
作者:iulyan
项目:stripe-bundl
/**
* @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);
}
}
作者:Swift-J
项目:thmdh
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;
}
作者:easybi
项目:stripe-ph
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);
}
作者:dirtyblanket
项目:allaccessrm
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();
}
}
作者:johnmirb
项目:CS4753-eCommerce-Projec
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
}
}
}
作者:autoca
项目:laravel-billin
/**
* 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;
}
作者:mathieumol
项目:Booksmar
public function checkout($bill)
{
$this->load->helper('url');
if (isset($_SESSION['id'])) {
try {
require_once './vendor/autoload.php';
\Stripe\Stripe::setApiKey("sk_test_ZR7R8cxse2Nz0TFsmxTDlwey");
//Replace with your Secret Key
$charge = \Stripe\Charge::create(array("amount" => $bill * 100, "currency" => "EUR", "card" => $_POST['stripeToken'], "description" => "Transaction BookSmart"));
$this->load->helper('url');
$this->load->database();
$ids = implode(",", $_SESSION['cart']);
$query10 = "UPDATE Book SET buyerid='" . $_SESSION['id'] . "' WHERE id IN (" . $ids . ");";
echo $query10;
$this->db->query($query10);
$data['payment'] = $bill;
unset($_SESSION['cart']);
$this->load->view('static_page', $data);
} catch (Stripe_CardError $e) {
} catch (Stripe_InvalidRequestError $e) {
} catch (Stripe_AuthenticationError $e) {
} catch (Stripe_ApiConnectionError $e) {
} catch (Stripe_Error $e) {
} catch (Exception $e) {
}
} else {
$data['log'] = "<h1> You must be log to sell a book</h1>";
$this->load->view('static_page', $data);
}
}
作者:jordanmannin
项目:Symfon
public function indexAction()
{
\Stripe\Stripe::setApiKey("sk_test_xN2J6grU84FCtP69dJEncERE");
$token = $_POST['stripeToken'];
$customer = \Stripe\Customer::create(array("source" => $token, "description" => "Example customer"));
\Stripe\Charge::create(array("amount" => 1000, "currency" => "gbp", "customer" => $customer->id));
return $this->render('TestStripeBundle:Stripe:index.html.twig');
}
作者:zhaoyiy
项目:php-projec
public function stripe($stripeToken)
{
$customer = \Stripe\Customer::create(array('email' => AuthModel::getUser('email'), 'source' => $stripeToken));
$charge = \Stripe\Charge::create(array('customer' => $customer->id, 'amount' => $_SESSION['grandPrice'][0] * 100, 'currency' => 'cad'));
unset($_SESSION['grandPrice']);
// TODO: need handle payment errors
return true;
}
作者:patternsee
项目:ecommerc
/**
* @param $params
* @return StripeChargeMock|Charge
*/
function chargeCreate($params)
{
if (self::$testMode) {
return StripeChargeMock::create($params);
} else {
return Charge::create($params);
}
}
作者:bizhu
项目:billin
/**
* Charge stripe token
*
* @param array $data
* @return void
*/
public function charge($data)
{
try {
return Charge::create(['amount' => $data['amount'], 'currency' => 'nzd', 'receipt_email' => $data['email'], 'description' => $data['description'], 'source' => $data['token'], 'metadata' => $data['metadata']]);
} catch (Card $e) {
var_dump('card was declined');
}
}