PHPackages                             dnetix/masterpass - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. dnetix/masterpass

ActiveLibrary[Payment Processing](/categories/payments)

dnetix/masterpass
=================

PHP Masterpass Merchant Checkout Service SDK for use with PHP Core SDK on MasterCard Developer Zone

0.2.4(4y ago)094.2k2MITPHPPHP &gt;=5.4

Since Nov 23Pushed 4y ago3 watchersCompare

[ Source](https://github.com/dnetix/masterpass)[ Packagist](https://packagist.org/packages/dnetix/masterpass)[ RSS](/packages/dnetix-masterpass/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (4)Versions (13)Used By (0)

Masterpass SDK Refactored Library
=================================

[](#masterpass-sdk-refactored-library)

With this code you will be able to quickly connect with the Masterpass service.

Installation
------------

[](#installation)

Using composer from your project

```
composer require dnetix/masterpass

```

Or If you just want to run the examples contained in this project run "composer install" to load the vendor autoload

Usage
-----

[](#usage)

Begin setting the environment variables, those values can be obtained from the Masterpass merchant portal

```
MasterCardApiConfig::setConsumerKey($consumerKey);
MasterCardApiConfig::setPrivateKey($privateKey);
MasterCardApiConfig::setSandBox(true);

$client = \Dnetix\MasterPass\MasterPassApi();

```

`$consumerKey` it's a string copied from the "Project Keys" section of the Mastercard Developers project

`$privateKey` There is a full paragraph explaining this at the end of this README

That client can be used for all of the services required for the process

This is an example of the merchant initialization required in order to obtain the request token used on the lightbox, this is made on the backend, could be with an ajax call

```
$token = $client->requestToken('http://your_callback_url.com');
$shoppingCartRequest = new ShoppingCartRequest([
    'ShoppingCart' => new ShoppingCart([
        'Subtotal' => 10000,
        'CurrencyCode' => 'COP,
        'ShoppingCartItem' => [
            new ShoppingCartItem([
                'ImageURL' => 'https://www.placetopay.com/images/providers/placetopay.full.png',
                'Value' => 10000,
                'Description' => 'Testing product',
                'Quantity' => 1,
            ]),
        ],
    ]),
    'OAuthToken' => $token->token(),
]);
$shoppingCartResponse = $client->shoppingCart($shoppingCartRequest);

$initialization = new MerchantInitializationRequest([
    'OriginUrl' => 'http://your_callback_url.com',
    'OAuthToken' => $token->token(),
]);
$initializationResponse = $client->merchantInitialization($initialization);

$merchantCheckoutId = 'OBTAINED ON THE CLIENT ONBOARDING';
$requestToken = $token->token();

```

Once you get the merchantCheckoutId and the requestToken, pass it to your javascript initialization of the lightbox

```
MasterPass.client.checkout({
    "requestToken": requestToken,
    "callbackUrl": 'http://your_callback_url.com',
    "failureCallback": console.log,
    "cancelCallback": masterpassCancelFunction,
    "successCallback": masterpassSuccessFunction,
    "merchantCheckoutId": merchantCheckoutId,
    "version": "v6",
    "suppressShippingAddressEnable": true
});
```

At that moment the lightbox will be launched and if it uses your successCallback that function needs to send the information to the backend could be another ajax call, or it could redirect to that callback Url so handle it properly

```
$accessTokenResponse = $client->accessToken($_REQUEST['oauth_token'], $_REQUEST['oauth_verifier']);
$checkoutData = $client->retrieveInformation($_REQUEST['checkout_resource_url'], $accessTokenResponse->token());

$creditCardNumber = $checkoutData->getCard()->accountNumber();
// Format 12/20 check the Dnetix\MasterPass\Model\Card to see other accessor
$expiration = $checkoutData->getCard()->expiration();

```

Now you can see the user's credit card information and access it and use it wisely.

### Obtaining the private key

[](#obtaining-the-private-key)

When you create a project you receive a p12 file, or, if you lose it, you can renew it, in order to obtain the private key from this file you need to obtain it with php, so with the command line just put yourself in the directory where the key is and follow the commands

```
php -a
```

Once in interactive mode

```
$keystore = [];
trim(openssl_pkcs12_read(file_get_contents(__DIR__ . '/NAME_OF_THE_P12_FILE.p12'), $keystore, 'THE_PASSWORD_OF_THE_P12'));
echo base64_encode($keystore['pkey']);
```

This will dump a lot of characters, copy all of them and provide them to the privateKey variable decoded

```
$privateKey = base64_decode('THE_TOTAL_CHARACTERS_OBTAINED');
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~180 days

Recently: every ~375 days

Total

12

Last Release

1475d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/03d2682a1a3738e26a24c2233b17f57a902d930b534dab3898a7d43616410580?d=identicon)[dnetix](/maintainers/dnetix)

---

Top Contributors

[![dnetix](https://avatars.githubusercontent.com/u/4644865?v=4)](https://github.com/dnetix "dnetix (50 commits)")[![chentepixtol](https://avatars.githubusercontent.com/u/178278?v=4)](https://github.com/chentepixtol "chentepixtol (2 commits)")[![eduarguz](https://avatars.githubusercontent.com/u/14934055?v=4)](https://github.com/eduarguz "eduarguz (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/dnetix-masterpass/health.svg)

```
[![Health](https://phpackages.com/badges/dnetix-masterpass/health.svg)](https://phpackages.com/packages/dnetix-masterpass)
```

###  Alternatives

[chargebee/chargebee-php

ChargeBee API client implementation for PHP

768.0M9](/packages/chargebee-chargebee-php)[imdhemy/google-play-billing

Google Play Billing

491.3M5](/packages/imdhemy-google-play-billing)[bitpay/sdk

Complete version of the PHP library for the new cryptographically secure BitPay API

42337.5k4](/packages/bitpay-sdk)[buckaroo/sdk

Buckaroo payment SDK

12189.1k9](/packages/buckaroo-sdk)[contica/facturador-electronico-cr

Un facturador de código libre para integrar facturación electrónica en Costa Rica a un proyecto PHP

2128.8k](/packages/contica-facturador-electronico-cr)[karson/mpesa-php-sdk

172.2k](/packages/karson-mpesa-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
