1. Go to this page and download the library: Download mhaggag/laravel-payments 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/ */
Payment::gateway(GatewayName::STRIPE)
// Special parameters for stripe
->payload([
'payment_method_types' => ['card'],
'customer' => $user->name,
'customer_email' => $user->email,
'client_reference_id' => $user->id, // Optional, the default will be payment->uuid
'subscription_data' => [], // if you want to create a subscription
'allow_promotion_codes' => true,
'source' => '', // Token, card reference, etc when using create method instead of checkout
'items' => [
// items can be
{
'name' => 'Product A',
'amount' => 10,
'quantity' => 2,
},
// Or
{
'price_id' => 'stripe_price_id',
'quantity' => 1,
},
// if you do not pass any items, the default will be the payment amount, and name will be description.
],
]);
/**
* Note: By using isSubscription() method to enable subscription mode
* You must provide at least one recurring price in `subscription` mode when using prices.
*/
Payment::gateway(GatewayName::STRIPE)
->withPayload([])
->isSubscription()
->items([
['price_id' => 'price_1St7q................', 'quantity' => 1]
])
Payment::gateway(GatewayName::PAYPAL)
// Special parameters for paypal
->payload([
'brand_name' => 'Your Brand', // default will be app name
'locale' => 'en_US', // default will be 'en_US'
'source' => '', // Token, card reference, etc when using create method instead of checkout
'items' => [
// items can be
{
'name' => 'Product A',
'amount' => 10,
'quantity' => 2,
'description' => 'Product A description'
},
// if you do not pass any items, the default will be the payment amount, and name will be description.
],
]);
/**
* Note: By using isSubscription() method to enable subscription mode
* You must send plan_id that you created in paypal.
*/
Payment::gateway(GatewayName::PAYPAL)
->withPayload([
'plan_id' => 'paypal_plan_id',
])
->isSubscription()
Payment::gateway(GatewayName::PAYMOB)
->withPayload([
'notification_url' => 'notification_url', // default will be configured in config/payments.php under the webhook key
'billing_data' => [
"email" => "[email protected]", // "building" => "dumy", // optional
"city" => "dumy", // optional
"country" => "dumy", // optional
"floor" => "dumy", // optional
"state" => "dumy" // optional
],
'items' => [ // optional
[
'name' => 'Item name',
'amount' => 100,
'quantity' => 1,
'description' => 'Item description'
],
],
'special_reference' => $user->uuid, // Optional, the default will be payment->uuid
]);
/**
* Note: By using isSubscription() method to enable subscription mode
* You must send plan_id that you created in next step.
*/
$plan = Payment::driver(GatewayName::PAYMOB)->createSubscriptionPlan([
'name' => 'Test Plan',
'amount' => 100,
'frequency' => 7, // Values can be (7, 15, 30, 60, 90, 180, 360)
'use_transaction_amount' => true, // default is true
'reminder_days' => 2, // optional
'retrial_days' => 2, // optional
'number_of_deductions' => 2, // default is null
'webhook_url' => 'webhook_url', // default will be configured in config/payments.php under the webhook key
]);
Payment::gateway(GatewayName::PAYMOB)
->withPayload([
'plan_id' => $plan['id'],
])
->isSubscription()
/**
* Subscription creation is being done by completing one 3DS transaction to save the customer's card and connect it with the subscription.
*/
namespace App\Payments\Gateways;
use MHaggag\Payments\Gateways\BaseGateway;
use Illuminate\Database\Eloquent\Model;
class MyCustomGateway extends BaseGateway
{
public function createCheckout(array $payload): array
{
// Implement logic to create checkout session/transaction
// Return ['checkout_url' => '...', 'session_id' => '...']
}
public function handleRedirect(array $payload): Model
{
// Verify payment status and update the payment model
}
// Implement other