souidev/mastercard-gateway

A Laravel package for Mastercard Gateway REST API integration.

Maintainers

Package info

github.com/souidev/mastercard-gateway

pkg:composer/souidev/mastercard-gateway

Fund package maintenance!

souidev

Statistics

Installs: 29

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.0.3 2025-11-06 06:50 UTC

This package is auto-updated.

Last update: 2026-02-24 16:31:41 UTC


README

Latest Version on Packagist Total Downloads

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.