1. Go to this page and download the library: Download ifthenpay/laravel 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/ */
// ifthenpay/laravel-ifthenpay/src/Contracts/IfthenpayResponse.php
public function isSuccessful(): bool; // result of payment generation
public function getMessage(): ?string; // error message, in case of failure
public function toArray(): array; // response payload with keys prepared for mass-assignment to ifthenpay_payments model
use Ifthenpay\Laravel\Facades\Ifthenpay;
use Ifthenpay\Laravel\Models\Payment;
$multibancoResponse = Ifthenpay::multibanco()->generatePayment(
orderId: '1000',
amount: '10.99',
description: 'Order #1887', // optional
expiryDays: 3, // optional
);
if(!$multibancoResponse->isSuccessful()) {
throw new Exception("Error Generating Payment", 1);
}
// store payment or another action
Payment::create($response->toArray());
use Ifthenpay\Laravel\Facades\Ifthenpay;
use Ifthenpay\Laravel\Models\Payment;
$mbwayResponse = Ifthenpay::mbway()->generatePayment(
orderId: '1000',
amount: '10.99',
mobileNumber: '351#912345678',
description: 'Order #1887', // optional
email: '[email protected]', // optional
expiryMinutes: 10, // optional
);
if(!$mbwayResponse->isSuccessful()) {
throw new Exception("Error Generating Payment", 1);
}
// store payment or another action
Payment::create($mbwayResponse->toArray());
use Ifthenpay\Laravel\Facades\Ifthenpay;
use Ifthenpay\Laravel\Models\Payment;
$payshopResponse = Ifthenpay::payshop()->generatePayment(
orderId: '1000',
amount: '10.99',
expiryDays: 5, // optional
);
if(!$payshopResponse->isSuccessful()) {
throw new Exception("Error Generating Payment", 1);
}
// store payment or another action
Payment::create($payshopResponse->toArray());
use Ifthenpay\Laravel\Facades\Ifthenpay;
use Ifthenpay\Laravel\Models\Payment;
$creditcardResponse = Ifthenpay::creditcard()->generatePayment(
orderId: '1000',
amount: '10.99',
successUrl: 'https://example.com/success',
errorUrl: 'https://example.com/error',
cancelUrl: 'https://example.com/cancel',
language: 'en', // optional
expiryMinutes: 15, // optional
);
if(!$creditcardResponse->isSuccessful()) {
throw new Exception("Error Generating Payment", 1);
}
// store payment or another action
Payment::create($creditcardResponse->toArray());
use Ifthenpay\Laravel\Facades\Ifthenpay;
use Ifthenpay\Laravel\Models\Payment;
$paybylinkResponse = Ifthenpay::paybylink()->generatePayment(
orderId: '1000',
amount: '10.99',
successUrl: 'https://example.com/success',
errorUrl: 'https://example.com/error',
cancelUrl: 'https://example.com/cancel',
description: 'Order #1887', // optional
expiryDays: 5, // optional
otp: false, // optional
lang: 'pt', // optional
btnCloseUrl: 'https://example.com/close', // optional
btnCloseLabel: 'Close', // optional
);
if(!$paybylinkResponse->isSuccessful()) {
throw new Exception("Error Generating Payment", 1);
}
// store payment or another action
Payment::create($paybylinkResponse->toArray());
use Ifthenpay\Laravel\Facades\Ifthenpay;
use Ifthenpay\Laravel\Models\Payment;
$multibancoResponse = Ifthenpay::multibanco()->generatePayment(orderId: 'order-1887', amount: '10.99', expiryDays: 3);
Payment::create($multibancoResponse->toArray());
// app/Models/Order.php
use Ifthenpay\Laravel\Traits\HasIfthenpayPayments;
class Order extends Model
{
use HasIfthenpayPayments;
}
// app/Http/Controllers/YourController.php
use App\Models\Order;
$order = Order::find(1);
$payment = $order->createMbwayPayment(orderId: 'order-1887', amount: '10.99', mobileNumber: '351#912345678');
$orderPayments = $order->payments; // all payments for this order (MorphMany)
$orderMbwayPayments = $order->mbwayPayments; // only its MB WAY payments
// /routes/console.php
use Illuminate\Support\Facades\Schedule;
Schedule::command('ifthenpay:payments:expire')->hourly();
use Ifthenpay\Laravel\Facades\Ifthenpay;
use Ifthenpay\Laravel\Models\Payment;
$payment = Payment::find(1);
$statusResponse = Ifthenpay::mbway()->checkStatus($payment);
if ($statusResponse->isSuccessful()) {
$payment->markAsPaid();
}
// ifthenpay/laravel-ifthenpay/src/Responses/MbwayStatusResponse.php
public function __construct(
public ?string $message,
public MbwayStatus $status,
) {}
use Ifthenpay\Laravel\Exceptions\IfthenpayException;
use Ifthenpay\Laravel\Facades\Ifthenpay;
use Ifthenpay\Laravel\Models\Payment;
$payment = Payment::where('order_id', request('orderId'))->firstOrFail();
try {
Ifthenpay::creditcard()->verifyPayment(secretKey: request('sk'), payment: $payment);
} catch (IfthenpayException $e) {
abort(403, 'Invalid payment return.');
}
// verification passed, safe to treat as returning from a genuine ifthenpay redirect
use Ifthenpay\Laravel\Events\PaymentExpired;
use Illuminate\Support\Facades\Event;
Event::listen(function (PaymentExpired $event) {
// $event->payment — the Payment model instance that was just marked as expired
});
use Ifthenpay\Laravel\Events\PaymentWebhookConfirmed;
use Illuminate\Support\Facades\Event;
Event::listen(function (PaymentWebhookConfirmed $event) {
// $event->payload — Ifthenpay\Laravel\DTO\WebhookPayload: method, orderId, reference, requestId, amount
});
use Ifthenpay\Laravel\Events\PaymentWebhookRefunded;
use Illuminate\Support\Facades\Event;
Event::listen(function (PaymentWebhookRefunded $event) {
// $event->payload — Ifthenpay\Laravel\DTO\WebhookPayload: method, orderId, reference, requestId, amount
});
use Ifthenpay\Laravel\Events\PaymentWebhookRejected;
use Illuminate\Support\Facades\Event;
Event::listen(function (PaymentWebhookRejected $event) {
// $event->payload — Ifthenpay\Laravel\DTO\WebhookPayload, built defensively from the raw (possibly invalid) query
// $event->reason — internal string explaining why the webhook was rejected
});
// app/Providers/AppServiceProvider.php
use Ifthenpay\Laravel\Contracts\LoggableEvent;
use Ifthenpay\Laravel\Listeners\LogIfthenpayEvent;
use Illuminate\Support\Facades\Event;
Event::listen(LoggableEvent::class, LogIfthenpayEvent::class);