souidev / mastercard-gateway
A Laravel package for Mastercard Gateway REST API integration.
Fund package maintenance!
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- phpunit/phpunit: ^11.5
- spatie/laravel-ray: ^1.35
README
This package provides a simple and expressive interface for interacting with the Mastercard Gateway REST API in Laravel applications.
Installation
You can install the package via composer:
composer require souidev/mastercard-gateway
Configuration
Publish the configuration file using the following command:
php artisan vendor:publish --provider="Souidev\MastercardGateway\MastercardGatewayServiceProvider"
This will create a config/mastercard-gateway.php file in your application. You should then configure your Mastercard Gateway credentials in your .env file:
MASTERCARD_GATEWAY_URL=https://test-tnpost.mtf.gateway.mastercard.com/api/rest
MASTERCARD_MERCHANT_ID=YOUR_MERCHANT_ID
MASTERCARD_API_USERNAME=merchant.YOUR_MERCHANT_ID
MASTERCARD_PASSWORD=YOUR_API_PASSWORD
MASTERCARD_VERSION=100
Usage
You can interact with the gateway using the MastercardGateway facade.
Making a Payment
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::pay([ 'orderId' => '12345', 'transactionId' => '1', 'order' => [ 'amount' => 100.00, 'currency' => 'USD', 'description' => 'Goods and Services', // optional ], 'sourceOfFunds' => [ 'type' => 'CARD', 'provided' => [ 'card' => [ 'number' => '5123456789012346', 'expiry' => [ 'month' => '01', 'year' => '39', ], 'securityCode' => '123', // optional ], ], ], ]); if ($response->isSuccessful()) { // Handle successful payment $order = $response->order; } else { // Handle failed payment }
Authorizing a Payment
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::authorize([ 'orderId' => '12345', 'transactionId' => '1', 'order' => [ 'amount' => 100.00, 'currency' => 'USD', 'description' => 'Goods and Services', // optional ], 'sourceOfFunds' => [ 'type' => 'CARD', 'provided' => [ 'card' => [ 'number' => '5123456789012346', 'expiry' => [ 'month' => '01', 'year' => '39', ], 'securityCode' => '123', // optional ], ], ], ]);
Capturing a Payment
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::capture('12345', 'TXN123', [ 'transaction' => [ 'amount' => 100.00, 'currency' => 'USD', ], ]);
Refunding a Payment
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::refund('12345', 'TXN123', [ 'transaction' => [ 'amount' => 100.00, 'currency' => 'USD', ], ]);
Voiding a Transaction
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::void('12345', 'TXN123', []);
Verifying a Card
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::verify([ 'orderId' => '12345', 'transactionId' => '1', 'order' => [ 'currency' => 'USD', ], 'sourceOfFunds' => [ 'type' => 'CARD', 'provided' => [ 'card' => [ 'number' => '5123456789012346', 'expiry' => [ 'month' => '01', 'year' => '39', ], 'securityCode' => '123', // optional ], ], ], ]);
Retrieving a Transaction
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::retrieveTransaction('12345', 'TXN123');
Retrieving an Order
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::retrieveOrder('12345');
Authenticating a Payer
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::authenticatePayer([ 'orderId' => '12345', 'transactionId' => '1', 'order' => [ 'currency' => 'USD', ], 'sourceOfFunds' => [ 'type' => 'CARD', 'provided' => [ 'card' => [ 'number' => '5123456789012346', 'expiry' => [ 'month' => '01', 'year' => '39', ], ], ], ], 'device' => [ // optional 'browser' => 'Mozilla/5.0', 'ipAddress' => '127.0.0.1', ], ]);
Tokenization
Creating a Token
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::createToken([ 'sourceOfFunds' => [ 'type' => 'CARD', 'provided' => [ 'card' => [ 'number' => '5123456789012346', 'expiry' => [ 'month' => '01', 'year' => '39', ], ], ], ], ]);
Updating a Token
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::updateToken('TOKEN_ID', [ 'sourceOfFunds' => [ 'type' => 'CARD', 'provided' => [ 'card' => [ 'number' => '5123456789012346', 'expiry' => [ 'month' => '01', 'year' => '39', ], ], ], ], ]);
Deleting a Token
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::deleteToken('TOKEN_ID');
Retrieving a Token
use Souidev\MastercardGateway\Facades\MastercardGateway; $response = MastercardGateway::retrieveToken('TOKEN_ID');
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.