PHPackages                             paymaya/paymaya-sdk - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. paymaya/paymaya-sdk

ActiveLibrary[HTTP &amp; Networking](/categories/http)

paymaya/paymaya-sdk
===================

PHP SDK for PayMaya APIs. Accept credit and debit card payments on your web app.

0.0.2(8y ago)4417.7k↓34.4%29[11 issues](https://github.com/PayMaya/PayMaya-PHP-SDK/issues)[1 PRs](https://github.com/PayMaya/PayMaya-PHP-SDK/pulls)1MITPHPPHP &gt;=5.3.0CI failing

Since Aug 15Pushed 5y ago19 watchersCompare

[ Source](https://github.com/PayMaya/PayMaya-PHP-SDK)[ Packagist](https://packagist.org/packages/paymaya/paymaya-sdk)[ Docs](https://github.com/PayMaya/PayMaya-PHP-SDK)[ RSS](/packages/paymaya-paymaya-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (6)Used By (1)

PayMaya-PHP-SDK
===============

[](#paymaya-php-sdk)

PayMaya PHP SDK allows your web applications to accept payments from your customers using any MasterCard and Visa enabled card (credit, debit, or prepaid).

[![Code Climate](https://camo.githubusercontent.com/e8b10875e1a5b5b729c6383951548547ffe7aa6c74fd951974d6f229fc375185/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f5061794d6179612f5061794d6179612d5048502d53444b2f6261646765732f6770612e737667)](https://codeclimate.com/github/PayMaya/PayMaya-PHP-SDK)

Prerequisites
-------------

[](#prerequisites)

- PHP 5.3 or above
- [curl](http://php.net/manual/en/book.curl.php), [json](http://php.net/manual/en/book.json.php) &amp; [openssl](http://php.net/manual/en/book.openssl.php) extensions must be enabled

Tests

- phpunit/phpunit: 4.8.\*

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

[](#installation)

- Via Composer

```
composer require "paymaya/paymaya-sdk:*"
```

- Direct download

Integrate the SDK by cloning this repo () and manually adding it to your project. You can look at the sample directory to guide you on using the SDK

Prerequisites
-------------

[](#prerequisites-1)

#### *API Keys*

[](#api-keys)

To use PayMaya PHP SDK, you need to have a different API key for Sandbox and Production environment.

##### *Sandbox Environment*

[](#sandbox-environment)

Sandbox credentials are useful for testing application integration. All transactions and money flow made in this environment are only simulated and does not reflect your production records. Sandbox API keys are available in the following:

##### *Production Environment*

[](#production-environment)

Upon successful integration testing, contact us in the PayMaya Developers Portal to know more about the merchant onboarding process. Once you are onboarded, we will provide your production API credentials. Upon receipt, just change your SDK initialization to use production environment to start accepting live transactions.

Usage
-----

[](#usage)

#### 1. Autoload the SDK. This will include all the files and classes to your autoloader. If you downloaded the SDK using composer, replace PayMaya-PHP-SDK with vendor.

[](#1-autoload-the-sdk-this-will-include-all-the-files-and-classes-to-your-autoloader-if-you-downloaded-the-sdk-using-composer-replace-paymaya-php-sdk-with-vendor)

```
// Used for composer based installation
require __DIR__  . '/vendor/autoload.php';
// Use below for direct download installation
// require __DIR__  . '/PayMaya-PHP-SDK/autoload.php';
```

#### 2. Initialize SDK with public-facing API key, secret API key, and the intended environment ("SANDBOX" or "PRODUCTION)

[](#2-initialize-sdk-with-public-facing-api-key-secret-api-key-and-the-intended-environment-sandbox-or-production)

```
//
PayMayaSDK::getInstance()->initCheckout(, , );
```

#### *Checkout*

[](#checkout)

##### 1. Create Checkout object

[](#1-create-checkout-object)

```
// Checkout
$itemCheckout = new Checkout();
$user = new User();
$itemCheckout->buyer = $user->buyerInfo();

// Item
$itemAmountDetails = new ItemAmountDetails();
$itemAmountDetails->shippingFee = "14.00";
$itemAmountDetails->tax = "5.00";
$itemAmountDetails->subtotal = "50.00";
$itemAmount = new ItemAmount();
$itemAmount->currency = "PHP";
$itemAmount->value = "69.00";
$itemAmount->details = $itemAmountDetails;
$item = new Item();
$item->name = "Leather Belt";
$item->code = "pm_belt";
$item->description = "Medium-sized belt made from authentic leather";
$item->quantity = "1";
$item->amount = $itemAmount;
$item->totalAmount = $itemAmount;

$itemCheckout->items = array($item);
$itemCheckout->totalAmount = $itemAmount;
$itemCheckout->requestReferenceNumber = "123456789";
$itemCheckout->redirectUrl = array(
	"success" => "https://shop.com/success",
	"failure" => "https://shop.com/failure",
	"cancel" => "https://shop.com/cancel"
	);
```

##### 2. Checkout methods

[](#2-checkout-methods)

- Execute Checkout - Method will assign checkout ID and checkout URL to checkout object. Use the checkout URL to redirect the buyer to Checkout page.

```
$itemCheckout->execute();

echo $itemCheckout->id // Checkout ID
echo $itemCheckout->url // Checkout URL
```

- Retrieve Checkout - Method will assign all available checkout information to the object give checkout ID.

```
$itemCheckout->retrieve();

/* The following properties will be populated
 *  $status
	*  $paymentType
	*  $transactionReferenceNumber
	*  $receiptNumber;
	*  $paymentStatus;
	*  $voidStatus;
	*  $metadata;
	*/

```

#### *Customization*

[](#customization)

##### 1. Create Customization object

[](#1-create-customization-object)

```
