Пример #1
4
 /**
  * @param $params
  * @return StripeCustomerMock|Customer
  */
 function customerCreate($params)
 {
     if (self::$testMode) {
         return StripeCustomerMock::create($params);
     } else {
         return Customer::create($params);
     }
 }
Пример #2
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");
 }
Пример #3
1
 protected function createStripeCustomer($token)
 {
     require_once '/api/stripe-php-2.1.1/init.php';
     \Stripe\Stripe::setApiKey($this->test_secret_key);
     $customer = \Stripe\Customer::create(array("source" => $token, "description" => "Razor Commerce Customer"));
     return $customer;
 }
Пример #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;
 }
Пример #5
1
 public function testSave()
 {
     $customer = self::createTestCustomer();
     $customer->email = '*****@*****.**';
     $customer->save();
     $this->assertEqual($customer->email, '*****@*****.**');
     $customer2 = Customer::retrieve($customer->id);
     $this->assertEqual($customer->email, $customer2->email);
 }
Пример #6
1
 public static function getCards($customerId)
 {
     $customer = \Stripe\Customer::retrieve($customerId);
     $cardsCollection = \Stripe\Customer::retrieve($customerId)->sources->all(['object' => 'card']);
     $cards = [];
     foreach ($cardsCollection['data'] as $card) {
         $cards[] = ['cardId' => $card->id, 'last4' => $card->last4, 'expMonth' => $card->exp_month, 'expYear' => $card->exp_year];
     }
     return $cards;
 }
Пример #7
1
 /**
  * @param User $user
  * @param $request
  * @return boolean
  */
 public function addCard(User $user, $request)
 {
     $stripeToken = $request->request->get('token');
     if ($stripeToken) {
         $customer = StripeCustomer::retrieve($this->getCustomerId($user));
         $card = $customer->sources->create(['source' => $stripeToken]);
         return $card instanceof StripeCard;
     }
     return false;
 }
Пример #8
0
 /**
  * Merge attributes of stripe in current customer
  *
  * @param  \Stripe\Customer $customer Customer instance from stripe
  * @return void
  */
 public function merge(\Stripe\Customer $customer)
 {
     // merge stripe customer attibutes into entity
     foreach ($customer->keys() as $key) {
         $this->{$key} = $customer->{$key};
     }
 }
 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();
     }
 }
 /**
  * Check stripe data.
  *
  * @access public
  * @return void
  */
 public function run()
 {
     $paymentGateway = Payment_gateways::findOneActiveBySlug('stripe');
     if ($paymentGateway->exists()) {
         \Stripe\Stripe::setApiKey($paymentGateway->getFieldValue('apiKey'));
         $subscriptions = new Subscription();
         $allSubscriptions = $subscriptions->where('status', Subscription::STATUS_ACTIVE)->get();
         /* @var Subscription $_subscription */
         foreach ($allSubscriptions as $_subscription) {
             $end = DateTime::createFromFormat('Y-m-d', $_subscription->end_date);
             if ($end->getTimestamp() > strtotime('now')) {
                 $paymentTransaction = $_subscription->payment_transaction->get();
                 if ($paymentTransaction->system == 'stripe') {
                     $user = new User($_subscription->user_id);
                     try {
                         $customer = \Stripe\Customer::retrieve($user->stripe_id);
                         $subscription = $customer->subscriptions->retrieve($paymentTransaction->payment_id);
                     } catch (Exception $e) {
                         log_message('CRON_ERROR', __FUNCTION__ . ' > ' . $e->getMessage());
                     }
                     if (!isset($subscription) || $subscription->status != 'active') {
                         $_subscription->deactivate();
                         $_subscription->save();
                     }
                 }
             }
         }
         log_message('CRON_SUCCESS', __FUNCTION__);
     }
 }
 /**
  * Check stripe data.
  *
  * @access public
  * @return void
  */
 public function run()
 {
     try {
         $paymentGateway = Payment_gateways::findOneActiveBySlug('stripe');
         if ($paymentGateway->exists()) {
             \Stripe\Stripe::setApiKey($paymentGateway->getFieldValue('apiKey'));
             $subscriptions = new Subscription();
             $allSubscriptions = $subscriptions->get();
             /* @var Subscription $_subscription */
             foreach ($allSubscriptions as $_subscription) {
                 if ($_subscription->end_date <= strtotime('now')) {
                     $paymentTransaction = $_subscription->payment_transaction->get();
                     if ($paymentTransaction->system == 'stripe') {
                         $user = new User($_subscription->user_id);
                         $customer = \Stripe\Customer::retrieve($user->stripe_id);
                         $subscription = $customer->subscriptions->retrieve($paymentTransaction->payment_id);
                         if ($subscription->status == 'active') {
                             $date = new DateTime();
                             $date->setTimestamp($subscription->current_period_end);
                             $_subscription->end_date = $date->format('Y-m-d');
                             $_subscription->activate();
                             $_subscription->save();
                         }
                     }
                 }
             }
             log_message('CRON_SUCCESS', __FUNCTION__);
         } else {
             log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'No Stripe Api key.');
         }
     } catch (Exception $e) {
         log_message('CRON_ERROR', __FUNCTION__ . ' > ' . $e->getMessage());
     }
 }
Пример #12
0
 /**
  * Delete a customer.
  * 
  * @return Customer
  */
 public function delete()
 {
     $this->info();
     $this->stripe_customer->delete();
     $this->stripe_customer = null;
     return $this;
 }
 function __construct()
 {
     \Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
     $order_items = array();
     $user = getLoggedInUser();
     $stripe_cust = $user->stripe_cust;
     $cart = Cache::get("cart", "session");
     if (!$stripe_cust) {
         try {
             $cu = \Stripe\Customer::create(array("description" => $user->email, "source" => getInput("stripeToken")));
         } catch (Exception $e) {
             new SystemMessage("There has been an error.  Please contact us.");
             forward("home");
         }
         $user->stripe_cust = $cu->id;
         $user->save();
     } else {
         $cu = \Stripe\Customer::retrieve($stripe_cust);
         try {
             $cu->source = getInput("stripeToken");
         } catch (Exception $e) {
             new SystemMessage("There has been an error.  Please contact us.");
             forward("home");
         }
         $cu->save();
     }
     foreach ($cart as $guid => $details) {
         $product = getEntity($guid);
         if ($product->interval == "one_time") {
             $order_item = array("type" => "sku", "parent" => $product->stripe_sku, "description" => $product->description . $details);
             $order_items[] = $order_item;
         } else {
             try {
                 $cu->subscriptions->create(array("plan" => $guid));
             } catch (Exception $e) {
                 new SystemMessage("There has been an error.  Please contact us.");
                 forward("home");
             }
         }
     }
     if (!empty($order_items)) {
         try {
             $order = \Stripe\Order::create(array("items" => $order_items, "currency" => "usd", "customer" => $cu->id));
             $order->pay(array("customer" => $cu->id, "email" => $user->email));
         } catch (Exception $e) {
             new SystemMessage("There has been an error.  Please contact us.");
             forward("home");
         }
     }
     $invoice = new Invoice();
     $invoice->items = $cart;
     $invoice->status = "paid";
     $invoice->owner_guid = getLoggedInUserGuid();
     $invoice->stripe_order = $order->id;
     $invoice->save();
     Cache::delete("cart", "session");
     new SystemMessage("Your purchase is complete.");
     forward("billing");
 }
Пример #14
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;
 }
Пример #15
0
 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');
 }
Пример #16
0
 /**
  * @param Request $request
  * @param string  $email
  *
  * @return Customer
  */
 public function createFromRequest(Request $request, $email = null)
 {
     if (!($token = $request->get(StripeFactory::TOKEN_REQUEST_PARAMETER))) {
         throw new \RuntimeException(sprintf('"%s" not found in given request.', StripeFactory::TOKEN_REQUEST_PARAMETER));
     }
     $stripeCustomer = StripeCustomer::create(array('source' => $token, 'email' => $email));
     $customer = $this->stripeToCustomerTransformer->transform($stripeCustomer);
     return $customer;
 }
Пример #17
0
 protected function onSuccess(array $data, $descriptionMetadata = null)
 {
     if ($descriptionMetadata) {
         $descriptionMetadata = $this->form->get($descriptionMetadata)->getData();
     }
     $customer = Customer::create(array("card" => $data['token'], "description" => '' . empty($descriptionMetadata) ? $this->description : $this->description . ' (' . $descriptionMetadata . ')'));
     $this->data = $data;
     $this->customer = $customer;
 }
Пример #18
0
 public function testInvalidObject()
 {
     authorizeFromEnv();
     try {
         Customer::retrieve('invalid');
     } catch (InvalidRequestError $e) {
         $this->assertEqual(404, $e->getHttpStatus());
     }
 }
Пример #19
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'));
 }
Пример #20
0
 /**
  * Create a new wallet object, representing a billing provider customer entity
  *
  * @param $owner
  * @return WalletInterface
  */
 public function createWallet($owner)
 {
     // Create the new stripe customer entity
     $customer = Customer::create(array("metadata" => ['customer_id' => $owner->id, 'customer_type' => get_class($owner)]));
     // Save the wallet info in the database
     $date = new \DateTime();
     $this->db->table('wallets')->insert(['ownerable_id' => $owner->id, 'ownerable_type' => get_class($owner), 'provider' => self::$provider, 'customer_token' => $customer->id, 'created_at' => $date, 'updated_at' => $date]);
     return new StripeWallet($customer->id);
 }
Пример #21
0
 public function deleteCreditCard($email, $index)
 {
     $cstmrAssocId = $this->getAssocCustomerId($email);
     $customer = \Stripe\Customer::retrieve($cstmrAssocId);
     $list = $this->getCreditCards($email);
     $card_id = $list[$index]["id"];
     $customer->sources->retrieve($card_id)->delete();
     return $this->getCreditCards($email);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($customerID)
 {
     Stripe::setApiKey($this->stripeConfig['testSecretKey']);
     $customerRetrieve = StripeCustomer::retrieve($customerID);
     /*echo '<pre>';
       print_r($customerRetrieve);
       echo '</pre>';*/
     return view('customer.show', compact('customerRetrieve'));
 }
Пример #23
0
 public function testInvalidCredentials()
 {
     Base::setApiKey('invalid');
     try {
         Customer::create();
     } catch (AuthenticationError $e) {
         $this->assertEqual(401, $e->getHttpStatus());
     }
 }
Пример #24
0
 function cancel_suscription($customer_id, $suscription_id)
 {
     try {
         $customer = \Stripe\Customer::retrieve($customer_id);
         $subscription = $customer->subscriptions->retrieve($suscription_id);
         $subscription->cancel();
     } catch (Exception $e) {
         http_response_code(404);
         return $e->getJsonBody();
     }
 }
Пример #25
0
 public function saveCard(Request $request)
 {
     $user = Auth::user();
     if ($request->get('stripe_token')) {
         \Stripe\Stripe::setApiKey("sk_test_Z98H9hmuZWjFWfbkPFvrJMgk");
         $customer = \Stripe\Customer::create(array("source" => $request->get('stripe_token'), "description" => $user->id));
         $user->update(['stripe_id' => $customer->id]);
         return \Redirect::route('user.index')->with('message', 'Card is saved');
     } else {
         return \Redirect::route('products.index')->withErrors('Failed to save');
     }
 }
Пример #26
0
 /**
  * @param $source
  * @param null $email
  * @return Customer
  */
 public function createNewCustomer($source, $email)
 {
     Stripe::setApiKey(env('STRIPE_API_KEY'));
     try {
         $customer = Customer::create(['source' => $source, 'email' => $email]);
     } catch (Card $e) {
         return response()->json(['success' => false, 'message' => 'Your card was declined, please try again.'], 402);
     } catch (Base $e) {
         return response()->json(['success' => false, 'message' => 'The transaction did not go through, please try again.'], 402);
     }
     return $customer;
 }
 public function charge(array $data)
 {
     try {
         if ($data['onetime'] == 1) {
             $customer = Customer::Create(['source' => $data['token'], 'description' => 'name', 'email' => $data['email']]);
             $charged = Charge::create(['customer' => $customer->id, 'amount' => 1000, 'currency' => 'usd']);
             return ['customer' => $customer, 'charge' => $charged];
         }
         return Charge::create(['amount' => 1000, 'currency' => 'usd', 'description' => $data['email'], 'card' => $data['token']]);
     } catch (Card $e) {
         dd($e->getMessage());
     }
 }
Пример #28
0
 public static function deleteCard($id)
 {
     self::init();
     // Return if no stripe token.
     if (!Auth::user()->stripe_key) {
         return true;
     }
     // Delete the card.
     $customer = \Stripe\Customer::retrieve(Auth::user()->stripe_key);
     $customer->sources->retrieve($id)->delete();
     // Return true;
     return true;
 }
Пример #29
0
 /**
  * {@inheritDoc}
  */
 public function execute($request)
 {
     /** @var $request CreateCustomer */
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     try {
         Stripe::setApiKey($this->keys->getSecretKey());
         $customer = Customer::create($model->toUnsafeArrayWithoutLocal());
         $model->replace($customer->__toArray(true));
     } catch (Error\Base $e) {
         $model->replace($e->getJsonBody());
     }
 }
Пример #30
-4
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
        }
    }
}