Welcome Guest, Not a member yet? Register   Sign In
Stripe Library
#5

Hi InsiteFX,

I have a success  Big Grin

Turns out I can ignore the undefined type 'Stripe\StripeClient' error flagged by intelephense, although I suspect intelephense will be strictly correct. btw - the intelephense vcs extension is awesome, if anyone is interested  Angel

I'm not an OOP guru, but have grasp of the main concepts. I'm going to post some of my code here , if anyone else is looking to add Stripe to their app.

As per the docs, I installed Stripe via composer.

I have a FrontController that extends the baseController and then I have a "Front" folder (under app/Controllers) of controllers that extend the FrontController - one of them is called Main.php

Here is the beginning of Main.php showing that I've temporarily hijacked the about page to test my Stripe connection.

Code:
<?php

namespace App\Controllers\Front;

use App\Controllers\FrontController;

class Main extends FrontController
{

  public function __construct()
  {
    parent::__construct();
  }

  public function index()
  {
    $this->loadPage('homepage');
  }

  public function about()
  {
    $stripe = new \App\Libraries\StripePayments();

    var_dump($stripe->listCustomers());
    die;

I have a StripePayments.php file under app/Libraries

Here is the beginning of the code showing listCustomers and getBalance functions

Code:
<?php

namespace App\Libraries;

use Stripe;

class StripePayments
{
  protected $stripe;

  public function __construct()
  {
    $this->stripe = new Stripe\StripeClient([
      'api_key' => getenv('stripe.secretkey'),
      'stripe_version' => '2020-08-27'
    ]);
  }

  public function listCustomers(array $params = [])
  {
    $result = $this->stripe->customers->all($params);
    return $result->toArray();
  }

  public function getBalance()
  {
    $result = $this->stripe->balance->retrieve();
    return $result->toArray();
  }


I did not need to add anything to app/Config/Autoload.php

Hope this helps others. Feel free to tell me I "this is not the way" or I should be using services  Tongue
Reply


Messages In This Thread
Stripe Library - by paulkd - 05-14-2021, 12:48 AM
RE: Stripe Library - by InsiteFX - 05-14-2021, 01:32 AM
RE: Stripe Library - by paulkd - 05-14-2021, 02:26 AM
RE: Stripe Library - by InsiteFX - 05-14-2021, 06:07 AM
RE: Stripe Library - by paulkd - 05-14-2021, 07:48 AM
RE: Stripe Library - by InsiteFX - 05-14-2021, 11:02 AM
RE: Stripe Library - by paulkd - 05-16-2021, 12:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB