PHP code example of bajjour / stripe

1. Go to this page and download the library: Download bajjour/stripe library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bajjour / stripe example snippets


$response = $this->stripe->create_checkout_session([
            'currency' => 'paying-currency',
            'amount' => 'unit-amount-in-cents-to-be-charged',//for 1 dollar set to 100
            'product_name' => 'your product name',
            'success_url' => 'https://yourdomain.com/{success-route}',
            'ref_id' => 'your local reference id', //optional
            'quantity' => 'quantity', //optional, total price will be amount * quantity
            'product_description' => 'your-product-description', //optional
            'cancel_url' => 'https://yourdomain.com/{cancel-route}', //optional
        ]);

$this->stripe->get_checkout_session_status(session_id: 'your-checkout-session-id')

$response = $this->stripe->create_subscription([
    'currency' => 'pay-currency',
    'amount' => 'total-amount-to-pay',
    'product_name' => 'your product name',
    'success_url' => 'https://yourdomain.com/{success-route}',
    'product_description' => 'your-product-description', //optional
    'interval' => 'month', //day, week, month, or year
    'interval_count' => '1', //each one month
]);

//generate stripe link that allows user to securely save their payment info.
$response = $this->stripe->create_setup_intent([
    'success_url' => 'https://example.com/success',
    'cancel_url' => 'https://example.com/cancel', //optional
]);
// we need "id", "setup_intent", "url" parameters from response to the next steps.

//to get customer info (customer_id, payment_method_id), and status of session.
$this->stripe->get_setup_intent_status($setup_intent_id);

//create invoice generating invoice in stripe that can be charged directly from your side, or sent to user to pay it.
$response = $this->stripe->create_invoice([
    'customer_id' => $customer_id,
    'amount' => 'total-amount',
    'currency' => 'pay-currency',
    'description' => 'your-product-description',
]);
// essentials returned parameters (id, hosted_invoice_url, invoice_pdf, status).

// to charge invoice automatically
$response = $this->stripe->charge_invoice($invoice_id, $payment_method_id);
// you can depend on "status" parameter to know if invoice has been paid.

// you can check invoice status using the following function:
$response = $this->stripe->get_invoice_status($invoice_id);
// essentials returned parameters (id, hosted_invoice_url, invoice_pdf, status).
bash
php artisan vendor:publish --provider="Stripe\StripeServiceProvider" --tag="stripe-config"
bash
use Stripe\Services\StripeService;


public function __construct(StripeService $stripe)
{
    $this->stripe = $stripe;
}