ebisbe/paga-mas-tarde-omnipay
Installation
composer require ebisbe/paga-mas-tarde-omnipay
Ensure omnipay/omnipay is also installed (this package is an Omnipay gateway driver).
Basic Configuration
Add the gateway to your Laravel app in config/services.php:
'paga_mas_tarde' => [
'merchant_id' => env('PAGA_MAS_TARDE_MERCHANT_ID'),
'secret_key' => env('PAGA_MAS_TARDE_SECRET_KEY'),
'test_mode' => env('PAGA_MAS_TARDE_TEST_MODE', false),
],
First Use Case: Create a Payment
use Omnipay\Omnipay;
$gateway = Omnipay::create('PagaMasTarde');
$gateway->setMerchantId(config('services.paga_mas_tarde.merchant_id'));
$gateway->setSecretKey(config('services.paga_mas_tarde.secret_key'));
$gateway->setTestMode(config('services.paga_mas_tarde.test_mode'));
$response = $gateway->purchase([
'amount' => '100.00',
'currency' => 'MXN',
'description' => 'Order #12345',
'installments' => 3, // Optional: Number of installments
'customer' => [
'name' => 'John Doe',
'email' => '[email protected]',
],
])->send();
Redirect to Paga Más Tarde
if ($response->isRedirect()) {
$response->redirect(); // Redirects to Paga Más Tarde's payment page
}
Standard Purchase Flow
purchase() for one-time payments.authorize() for authorizations (e.g., subscriptions).capture() later.Installment Payments
$response = $gateway->purchase([
'amount' => '500.00',
'installments' => 6, // 6 monthly payments
])->send();
Webhook Handling Paga Más Tarde sends notifications for successful/failed payments. Set up a Laravel route to handle these:
Route::post('/paga-mas-tarde/webhook', [PaymentWebhookController::class, 'handle']);
Verify the webhook signature using the secret_key before processing.
Refunds
$response = $gateway->refund([
'transaction_id' => 'pmt_txn_12345',
'amount' => '50.00',
])->send();
OmnipayServiceProvider.\Log::debug('Paga Más Tarde Response', ['response' => $response->getData()]);
test_mode to test transactions without real charges. Sandbox credentials are provided by Paga Más Tarde.Webhook Verification
signature header in webhook requests to prevent spoofing:
use Illuminate\Support\Facades\Http;
public function handle(Request $request) {
$signature = $request->header('X-Signature');
$payload = $request->getContent();
$expectedSignature = hash_hmac('sha256', $payload, config('services.paga_mas_tarde.secret_key'));
if (!hash_equals($expectedSignature, $signature)) {
abort(403, 'Invalid signature');
}
}
Transaction IDs
transaction_id for each payment. Store this in your database to reference later for refunds or inquiries.Currency and Amount
'100.00'), not integers or floats, to avoid precision issues.Test Mode Quirks
Enable Omnipay Logging
Add to config/omnipay.php:
'log' => [
'enabled' => true,
'level' => 'debug',
'file' => storage_path('logs/omnipay.log'),
],
Common Errors
InvalidMerchantId: Double-check merchant_id in config.InvalidSignature: Verify secret_key and webhook payloads.InsufficientFunds: Ensure the card/bank account has sufficient balance in test mode.Custom Fields
Paga Más Tarde supports additional fields like reference, customer_ip, or metadata. Pass these via the data array:
$gateway->purchase([
'amount' => '100.00',
'data' => [
'reference' => 'INV-2023-001',
'customer_ip' => $request->ip(),
],
])->send();
Custom Responses Extend the gateway to handle custom responses:
$gateway->getHttpClient()->setDecorator(new class implements \Omnipay\Common\Decorator\DecoratorInterface {
public function decorate(array $data, \Omnipay\Common\Message\AbstractRequest $request) {
$data['custom_field'] = 'value';
return $data;
}
});
Localization Set the language for the payment page (if supported):
$gateway->purchase([
'amount' => '100.00',
'language' => 'es', // Spanish
])->send();
How can I help you explore Laravel packages today?