PHP code example of digitaldev-lx / laravel-eupago
1. Go to this page and download the library: Download digitaldev-lx/laravel-eupago 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/ */
digitaldev-lx / laravel-eupago example snippets
use DigitaldevLx\LaravelEupago\MB\MB;
$order = Order::find(1);
$mb = new MB(
$order->value, // float: payment amount
$order->id, // string: external identifier
$order->date, // string: start date (Y-m-d)
$order->payment_limit_date, // string: end date (Y-m-d)
$order->value, // float: minimum value
$order->value, // float: maximum value
0 // bool: allow duplicated payments
);
try {
$mbReferenceData = $mb->create();
if ($mb->hasErrors()) {
// handle errors
}
$order->mbReferences()->create($mbReferenceData);
} catch (\Exception $e) {
// handle exception
}
use DigitaldevLx\LaravelEupago\Traits\Mbable;
class Order extends Model
{
use Mbable;
}
// Retrieve references
$order = Order::find(1);
$mbReferences = $order->mbReferences;
use DigitaldevLx\LaravelEupago\Traits\Mbwayable;
class Order extends Model
{
use Mbwayable;
}
// Retrieve references
$order = Order::find(1);
$mbwayReferences = $order->mbwayReferences;
use DigitaldevLx\LaravelEupago\Traits\Creditcardable;
use DigitaldevLx\LaravelEupago\Traits\Creditcardrecurrable;
class Order extends Model
{
use Creditcardable;
}
class Subscription extends Model
{
use Creditcardrecurrable;
}
use DigitaldevLx\LaravelEupago\GooglePay\GooglePay;
$googlePay = new GooglePay(
150.00, // float: amount
'ORDER-456', // string: identifier
'https://example.com/success', // string: success URL
'https://example.com/fail', // string: fail URL
'https://example.com/back', // string: back URL
'EN', // string: language
'EUR', // string: currency
'[email protected]', // string|null: email
'John', // string|null: first name
'Doe', // string|null: last name
'PT', // string|null: country code
true, // bool: notify customer
60 // int|null: minutes form up
);
try {
$result = $googlePay->create();
if ($result['success']) {
// Redirect to $result['redirect_url']
}
} catch (\Exception $e) {
// handle exception
}
use DigitaldevLx\LaravelEupago\Traits\Googlepayable;
class Order extends Model
{
use Googlepayable;
}
use DigitaldevLx\LaravelEupago\ApplePay\ApplePay;
$applePay = new ApplePay(
150.00, // float: amount
'ORDER-456', // string: identifier
'https://example.com/success', // string: success URL
'https://example.com/fail', // string: fail URL
'https://example.com/back', // string: back URL
'EN', // string: language
'EUR', // string: currency
'[email protected]', // string|null: email
'John', // string|null: first name
'Doe', // string|null: last name
'PT', // string|null: country code
true, // bool: notify customer
60 // int|null: minutes form up
);
try {
$result = $applePay->create();
if ($result['success']) {
// Redirect to $result['redirect_url']
}
} catch (\Exception $e) {
// handle exception
}
use DigitaldevLx\LaravelEupago\Traits\Applepayable;
class Order extends Model
{
use Applepayable;
}
use DigitaldevLx\LaravelEupago\Payouts\Payout;
$payout = new Payout(
'2024-01-01', // string: start date (yyyy-mm-dd)
'2024-01-31', // string: end date (yyyy-mm-dd)
'your-bearer-token' // string: OAuth Bearer Token
);
try {
$result = $payout->list();
if ($result['success']) {
foreach ($result['payouts'] as $payout) {
// Process payout data
}
}
} catch (\Exception $e) {
// handle exception
}
use DigitaldevLx\LaravelEupago\Payouts\PayoutTransaction;
$transactions = new PayoutTransaction(
'2024-01-01', // string: start date (yyyy-mm-dd)
'2024-01-31', // string: end date (yyyy-mm-dd)
'your-bearer-token' // string: OAuth Bearer Token
);
try {
$result = $transactions->list();
if ($result['success']) {
foreach ($result['transactions'] as $transaction) {
// Process transaction data
// Includes: trid, date, amount, payment_method, status
}
}
} catch (\Exception $e) {
// handle exception
}
// app/Listeners/HandleMBPayment.php
namespace App\Listeners;
use DigitaldevLx\LaravelEupago\Events\MBReferencePaid;
use Illuminate\Support\Facades\Mail;
class HandleMBPayment
{
public function handle(MBReferencePaid $event): void
{
$reference = $event->reference;
$reference->mbable->update(['status' => 'paid']);
Mail::to($reference->mbable->user)->send(
new \App\Mail\PaymentConfirmed($reference)
);
}
}
use DigitaldevLx\LaravelEupago\Events\MBReferencePaid;
use Illuminate\Support\Facades\Event;
public function boot(): void
{
Event::listen(
MBReferencePaid::class,
SendPaymentConfirmationEmail::class,
);
}
use DigitaldevLx\LaravelEupago\Events\MBReferencePaid;
use Illuminate\Support\Facades\Event;
Event::listen(function (MBReferencePaid $event) {
$reference = $event->reference;
$reference->mbable->update(['status' => 'paid']);
});
use Illuminate\Support\Facades\Schedule;
Schedule::command('eupago:check-expired')->daily();
protected function schedule(Schedule $schedule)
{
$schedule->command('eupago:check-expired')->daily();
}
use DigitaldevLx\LaravelEupago\Models\MbReference;
use DigitaldevLx\LaravelEupago\Models\MbwayReference;
use DigitaldevLx\LaravelEupago\Models\CreditCardReference;
use DigitaldevLx\LaravelEupago\Models\GooglePayReference;
use DigitaldevLx\LaravelEupago\Models\ApplePayReference;
// Create unpaid reference
$reference = MbReference::factory()->create();
// Create paid reference
$paidReference = MbReference::factory()->paid()->create();
// Create expired reference
$expiredReference = MbReference::factory()->expired()->create();
// Other payment methods
$mbwayReference = MbwayReference::factory()->create();
$ccReference = CreditCardReference::factory()->paid()->create();
$googlePayReference = GooglePayReference::factory()->create();
$applePayReference = ApplePayReference::factory()->paid()->create();