I’m trying to figure out how i can use Stripe check out inside my theme im building. I installed bedrock as the base and the sage theme is inside. I’m trying to figure out how to access Stripe through the vendor directory. Would i include it in the sage_includes array? If so how do i navigate to the vendor directory?
If not would i have to just download the release and put it in the lib folder then link to it that way?
@ben I have a class i made inside lib folder in my sage theme to process Stripe transactions, but it doesnt have access to Stripe. How would i give it access to Stripe? use \Stripe\Stripe; doesnt work, is there a proper way to give my class access to it?
<?php namespace Roots\Sage\Charge;
if(isset($_POST)){
$charge = new StripeCharge($_POST);
$charge->process();
}
class StripeCharge{
private $data;
public function __construct($data){
$this->data = $data;
}
public function process(){
$token = $this->data['stripeToken'];
$customer = Stripe\Customer::create(array(
'email' => $this->data['stripeEmail'],
'card' => $token
));
$charge = Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 5000,
'currency' => 'usd'
));
echo '<h1>Successfully charged $50.00!</h1>';
}
}
Although classes may not have been covered as in depth as functions, the same rules apply. You are referencing the Stripe Customer and Charge classes directly, since you are appending the forward slash:
In that case you don’t need to use the use keyword. If you use the use keyword then it would be this:
use Stripe\Customer;
use Stripe\Charge;
...
$customer = Customer::create();
$charge = Charge::create()
However, since you are still getting an unfound class error, did you run composer install or most likely composer update if you added stripe-php manually to your composer.json file to ensure that the stripe-php package is actually downloaded and autoloaded?
@kalenjohnson Alright that all makes sense, but i’m not sure why its still not working… I ran composer update and made sure the stripe package is there, which it is.