Beispiel #1
12
 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;
 }
 /**
  * @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;
 }
Beispiel #3
2
 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");
 }
Beispiel #4
1
 public static function charge($token, $email, $amount)
 {
     $key = Config::get('stripeKey');
     Stripe\Stripe::setApiKey($key);
     $customer = Stripe\Customer::create(array('email' => $email, 'card' => $token));
     $charge = Stripe\Charge::create(array('customer' => $customer->id, 'amount' => $amount, 'currency' => 'USD'));
     return $charge;
 }
Beispiel #5
0
 /**
  * @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;
 }
Beispiel #6
0
 /**
  * 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;
 }
 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);
     }
 }
 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();
     }
 }
 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]]);
 }
 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();
     }
 }
Beispiel #11
0
 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();
         }
     }
 }
 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";
 }
 /**
  * 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>';
         }
     }
 }
Beispiel #14
0
 /**
  * @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);
     }
 }
Beispiel #15
0
 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);
 }
 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');
 }
Beispiel #17
0
 /**
  * @param $params
  * @return StripeChargeMock|Charge
  */
 function chargeCreate($params)
 {
     if (self::$testMode) {
         return StripeChargeMock::create($params);
     } else {
         return Charge::create($params);
     }
 }
Beispiel #18
0
 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;
 }
Beispiel #19
0
 /**
  * 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');
     }
 }
 public function charge(array $data)
 {
     try {
         return Charge::create(['amount' => $data['amount'] * 100, 'currency' => 'usd', 'description' => $data['email'], 'source' => $data['token']]);
     } catch (Card $e) {
         dd('Card was declined');
     }
 }
 /**
  * @param Request $request
  * @param int     $amount
  * @param string  $currency
  * @param string  $description
  *
  * @return Charge
  */
 public function createFromRequest(Request $request, $amount = 0, $currency = CurrencyFactory::EURO_CURRENCY, $description = null)
 {
     if (!($token = $request->get(StripeFactory::TOKEN_REQUEST_PARAMETER))) {
         throw new \RuntimeException(sprintf('"%s" not found in given request.', StripeFactory::TOKEN_REQUEST_PARAMETER));
     }
     $stripeCharge = StripeCharge::create(array('amount' => $amount, 'currency' => $currency, 'source' => $token, 'description' => $description));
     $charge = $this->stripeToChargeTransformer->transform($stripeCharge);
     return $charge;
 }
 public function charge(array $data)
 {
     try {
         return Stripe\Charge::create(['amount' => $data['amount'] * 100, 'currency' => 'usd', 'description' => $data['email'], 'card' => $data['token']]);
     } catch (Stripe_CardError $e) {
         // card was declined
         return redirect('/event/' . $data['event_slug'] . '/invoice/' . $data['invoice_key'] . '/payment/declined');
     }
 }
Beispiel #23
0
 public function postProcess()
 {
     $cart = $this->context->cart;
     $customer = new Customer((int) $cart->id_customer);
     \Stripe\Stripe::setApiKey((string) Configuration::get('STRIPE_SECRET_KEY'));
     $token = Tools::getValue('stripeToken');
     $customer = \Stripe\Customer::create(array('email' => $customer->email, 'card' => $token));
     $charge = \Stripe\Charge::create(array('customer' => $customer->id, 'amount' => (int) ($cart->getOrderTotal(true, CART::BOTH) * 100), 'currency' => 'sek'));
 }
 public function testBadData()
 {
     authorizeFromEnv();
     try {
         Charge::create();
     } catch (InvalidRequestError $e) {
         $this->assertEqual(400, $e->getHttpStatus());
     }
 }
 public function charge(array $data)
 {
     try {
         return Charge::create(['amount' => 15000, 'currency' => 'usd', 'description' => $data['email'], 'card' => $data['token']]);
     } catch (Stripe_CardError $e) {
         //card was declined
         dd('card was declined');
     }
 }
 public function payTask($task, $card)
 {
     /*
     $task->id = $taskId;
     $task->title = 'Task example title';
     $task->total = 50.25;
     */
     $charge = Charge::create(['card' => $card, 'amount' => 2000, 'currency' => 'usd', 'description' => 'Payment for ' . $task->title, 'metadata' => ['task' => $task->id]]);
     return $charge;
 }
Beispiel #27
0
 public function charge(array $data)
 {
     try {
         return Charge::create(['amount' => Input::get('amount'), 'currency' => 'usd', 'description' => $data['email'], 'card' => Input::get('stripeToken')]);
         //, $data['stripeToken'
         //]
     } catch (Stripe_CardError $e) {
         dd('card was declined');
     }
 }
Beispiel #28
0
 public function charge()
 {
     \Stripe\Stripe::setApiKey("sk_test_UAlnU8CPVoBkKFT6FyWL3UbU");
     $token = $_POST['stripeToken'];
     try {
         $charge = \Stripe\Charge::create(array("amount" => $this->input->post('amount'), "currency" => "usd", "source" => $token, "description" => "Example charge"));
         redirect('/orders/create');
     } catch (\Stripe\Error\Card $e) {
     }
 }
 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>';
 }
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 = '******';
            // Enter your SMTP username
            $mail->Password = '******';
            // 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
        }
    }
}