本文整理汇总了PHP中Stripe\Charge::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Charge::create方法的具体用法?PHP Charge::create怎么用?PHP Charge::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stripe\Charge
的用法示例。
在下文中一共展示了Charge::create方法的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");
}
示例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>';
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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";
}
示例6: 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;
}
示例7: 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);
}
示例8: 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();
}
}
示例9: checkout
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);
}
}
示例10: chargeToken
/**
* create token by using card information, you can also create via stripe.js
*
* @param String token generated of card information
* @return response in json format
*/
function chargeToken($token)
{
$this->setApiKey();
//charge card
$charge = \Stripe\Charge::create(array('amount' => 2000, 'currency' => 'usd', 'source' => $token['id']));
return $charge;
}
示例11: 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
}
}
}
示例12: 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]]);
}
示例13: 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();
}
}
}
示例14: 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();
}
}
示例15: charge
/**
* 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');
}
}