Coder Social home page Coder Social logo

paymaya-php-sdk's Introduction

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

Prerequisites

Tests

  • phpunit/phpunit: 4.8.*

Installation

  • Via Composer
composer require "paymaya/paymaya-sdk:*"
  • Direct download

Integrate the SDK by cloning this repo (https://github.com/PayMaya/PayMaya-PHP-SDK) and manually adding it to your project. You can look at the sample directory to guide you on using the SDK

Prerequisites

API Keys

To use PayMaya PHP SDK, you need to have a different API key for Sandbox and Production 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:

https://developers.paymaya.com/blog/entry/checkout-api-test-credit-card-account-numbers

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

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)

//
PayMayaSDK::getInstance()->initCheckout(<PUBLIC_API_KEY>, <SECRET_API_KEY>, <ENVIRONMENT>);

Checkout

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
  • 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

1. Create Customization object
<?php
$shopCustomization = new Customization();
$shopCustomization->logoUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg";
$shopCustomization->iconUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico";
$shopCustomization->appleTouchIconUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico";
$shopCustomization->customTitle = "Checkout Page Title";
$shopCustomization->colorScheme = "#368d5c";
2. Customization methods
  • Set Customization - Used to set a merchant's checkout page customization.
$shopCustomization->set();

echo "Logo URL: " . $shopCustomization->logoUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg
echo "Icon URL: " . $shopCustomization->iconUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico
echo "Apple Touch Icon URL: " . $shopCustomization->appleTouchIconUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico
echo "Custom Title: " . $shopCustomization->customTitle . "\n";
// Checkout Page Title
echo "Color Scheme: " . $shopCustomization->colorScheme . "\n";
// #368d5c
  • Get Customization - Used to get a merchant's checkout page customization.
$shopCustomization->get();

echo "Logo URL: " . $shopCustomization->logoUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg
echo "Icon URL: " . $shopCustomization->iconUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico
echo "Apple Touch Icon URL: " . $shopCustomization->appleTouchIconUrl . "\n";
// https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico
echo "Custom Title: " . $shopCustomization->customTitle . "\n";
// Checkout Page Title
echo "Color Scheme: " . $shopCustomization->colorScheme . "\n";
// #368d5c
  • Remove Customization - Used to remove a merchant's checkout page customization.
$shopCustomization->remove();

echo "Logo URL: " . $shopCustomization->logoUrl . "\n";
// null
echo "Icon URL: " . $shopCustomization->iconUrl . "\n";
// null
echo "Apple Touch Icon URL: " . $shopCustomization->appleTouchIconUrl . "\n";
// null
echo "Custom Title: " . $shopCustomization->customTitle . "\n";
// null
echo "Color Scheme: " . $shopCustomization->colorScheme . "\n";
// null

Webhook

1. Create Webhook object
$successWebhook = new Webhook();
$successWebhook->name = Webhook::CHECKOUT_SUCCESS;
$successWebhook->callbackUrl = "http://shop.someserver.com/success";
2. Webhook methods
  • Register webhook - Used to register an event-based webhook.
$successWebhook->register();
  • Update webhook - Used to update an existing event-based webhook.
$successWebhook->callbackUrl .= "Updated";
$successWebhook->update();

// $successWebhook->callbackUrl = "http://shop.someserver.com/successUpdated"
  • Delete webhook - Used to delete an existing webhook. You cannot undo this action.
$successWebhook->delete();
  • Retrieve webhooks - Used to retrieve the list of merchant registered webhooks.
Webhook::retrieve();

Summary

  • These docs in the SDK include an overview of usage, step-by-step integration instructions, and sample code.
  • A sample app is included in the sample folder in the project.
  • Checkout API Documentation and Payments API Documentation are currently available which cover error codes and server-side integration instructions.

Contribution

  • If you would like to contribute, please fork the repo and send in a pull request.

paymaya-php-sdk's People

Contributors

brianchiko avatar clark21 avatar diwadm avatar ebcayabyab avatar lloricode avatar rjarce avatar rmrhz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

paymaya-php-sdk's Issues

2 undefined properties

 ------ ----------------------------------------------------------------
  Line   PayMaya/API/Checkout.php
 ------ ----------------------------------------------------------------
  37     Access to an undefined property PayMaya\API\Checkout::$id.
  45     Access to an undefined property PayMaya\API\Checkout::$id.
  48     Access to an undefined property PayMaya\API\Checkout::$status.
 ------ ----------------------------------------------------------------

Discovered by @phpstan

Cant install: Installation request for psr/log (locked at 1.1.2) -> satisfiable by psr/log[1.1.2]

I get this message when trying to install the SDK via composer. I am using Laravel Framework for this

 D:\Files and Projects\Projects\SakuraSmartWeb>composer require "paymaya/paymaya-sdk:*"./composer.json has been updated
  Loading composer repositories with package information
  Updating dependencies (including require-dev)
  Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for psr/log (locked at 1.1.2) -> satisfiable by psr/log[1.1.2].
    - paymaya/paymaya-sdk 0.0.2 requires psr/log 1.0.2 -> satisfiable by psr/log[1.0.2].
    - paymaya/paymaya-sdk dev-curl-error-patch requires psr/log 1.0.2 -> satisfiable by psr/log[1.0.2].
     - paymaya/paymaya-sdk dev-dev-master requires psr/log 1.0.2 -> satisfiable by psr/log[1.0.2].
     - paymaya/paymaya-sdk dev-master requires psr/log 1.0.2 -> satisfiable by psr/log[1.0.2].
     - Conclusion: don't install psr/log 1.0.2
     - paymaya/paymaya-sdk 0.0.1 requires psr/log 1.0.0 -> satisfiable by psr/log[1.0.0].
     - paymaya/paymaya-sdk dev-dev requires psr/log 1.0.0 -> satisfiable by psr/log[1.0.0].
     - Conclusion: don't install psr/log 1.0.0
     - Installation request for paymaya/paymaya-sdk * -> satisfiable by paymaya/paymaya-sdk[0.0.1, 0.0.2, dev-curl-error-patch, dev-dev, dev-dev-master, dev-master].

Installation failed, reverting ./composer.json to its original content.

API Key has expired

Using the following api keys it returns a response that the "Key has expired"

Screenshot

Inline documentation

It would be better to have inline doc blocks for API documentation. I'll contribute along the way once I figure out how to use the SDK. Very promising.

Non-configurable cURL Options in HTTPConfig

The default cURL options in PayMaya\Core\HTTPConfig are fixed and are not very flexible. There are installations of PHP 5.6 and above where libcurl uses NSS instead of OpenSSL as the SSL/TLS provider, which means hard-coding CURLOPT_SSL_CIPHER_LIST to 'TLSv1' will be incompatible to these PHP installations, after setting said options through curl_setopt_array() in PayMaya\Core\HTTPConnection::execute(), as 'TLSv1' is only a valid value if OpenSSL is cURL's back-end. (See https://curl.haxx.se/libcurl/c/CURLOPT_SSL_CIPHER_LIST.html)

In addition, it is best to leave CURLOPT_SSLVERSION alone. See the corresponding entry at https://www.php.net/manual/en/function.curl-setopt.php for a description.

In closing, I highly recommend removing the CURLOPT_SSL_CIPHER_LIST and CURLOPT_SSLVERSION options from PayMaya\Core\HTTPConfig for better compatibility. The API's web server configuration on the other hand will be able to dictate which ciphers to be used on negotiation anyway. See the ssl_protocols, ssl_ciphers, and ssl_prefer_server_ciphers directives for NGINX as examples.

dependency check psr/log

on command 'compose require composer require "paymaya/paymaya-sdk:*"'

cli error appear: ''Conclusion: don't install psr/log 1.0.2"

Note: this is in Laravel 7

Undefined index: paymentType

I have followed the example given, when I try to retrieve checkout method it gives me an error of Undefined index: paymentType. what would I do?

Payment Failure.

I used your sample Checkout.php.
Tried all the Test Cards for checking out.

image

Same results.
I dont know if this is because im using sandbox or not.

Not Production-Ready / SemVer compliance

Hi. I'd like to know when will this be ready for production use?

Thanks. Any response is much appreciated.

Also, I suggest you use SemVer (as composer recommends) for your release version pattern.

Undefined index: ID in Register WEBHOOK

$successWebhook = new Webhook();
$successWebhook->id = $itemCheckout->id;
$successWebhook->name = Webhook::CHECKOUT_SUCCESS;
$successWebhook->callbackUrl = "http://localhost:8000/paymaya/success";
$successWebhook->register();

i was getting this error, I'm using Symfony Framework 3.3

Undefined index: ID

even though I already set the ID returned by PayMaya Checkout.

Error API call

Trying to run your sample code and encountered an error.

<br /> <b>Fatal error</b>: Uncaught Exception: Error API call in /storage/ssd4/275/12315275/public_html/paymaya/vendor/paymaya/paymaya-sdk/lib/PayMaya/Core/HTTPConnection.php:50 Stack trace: #0 /storage/ssd4/275/12315275/public_html/paymaya/vendor/paymaya/paymaya-sdk/lib/PayMaya/Core/CheckoutAPIManager.php(57): PayMaya\Core\HTTPConnection-&gt;execute('{&quot;url&quot;:null,&quot;bu...') #1 /storage/ssd4/275/12315275/public_html/paymaya/vendor/paymaya/paymaya-sdk/lib/PayMaya/API/Checkout.php(34): PayMaya\Core\CheckoutAPIManager-&gt;initiateCheckout(Array) #2 /storage/ssd4/275/12315275/public_html/paymaya/vendor/paymaya/paymaya-sdk/sample/Checkout/ItemCheckout.php(44): PayMaya\API\Checkout-&gt;execute() #3 {main} thrown in <b>/storage/ssd4/275/12315275/public_html/paymaya/vendor/paymaya/paymaya-sdk/lib/PayMaya/Core/HTTPConnection.php</b> on line <b>50</b><br />

Undefined Index voidStatus, metadata

Good Day Paymaya,

I was testing php sdk in sandbox environment.

I was following your checkout example here:
https://github.com/PayMaya/PayMaya-PHP-SDK/blob/master/sample/Checkout/ItemCheckout.php

When I reach line 45 of your sample code as shown below:
$itemCheckout->retrieve();

I encounter these error:
Undefined index: voidStatus (8)
Undefined index: metadata (8)

The code involved is:
File: lib/PayMaya/API/Checkout.php
Function: retrieve

Upon investigation, the returned json indeed did not have fields voidStatus and metadata.

Below is sample response:
{
"merchant":{
"currency":"PHP",
"name":"Test Merchant for Core 5",
"email":"[email protected]",
"locale":"en",
"homepageUrl":"http://paymaya.com",
"isEmailToMerchantEnabled":true,
"isEmailToBuyerEnabled":true,
"isPaymentFacilitator":false,
"isPageCustomized":true,
"supportedSchemes":[
"Mastercard",
"Visa"
],
"expressCheckout":false,
"canPayPal":false
},
"buyer":{
"firstName":"John",
"middleName":"Michaels",
"lastName":"Doe",
"contact":{
"phone":"+63(2)1234567890",
"email":"[email protected]"
},
"shippingAddress":{
"line1":"9F Robinsons Cybergate 3",
"line2":"Pioneer Street",
"city":"Mandaluyong City",
"state":"Metro Manila",
"zipCode":"12345",
"countryCode":"PH"
},
"billingAddress":{
"line1":"9F Robinsons Cybergate 3",
"line2":"Pioneer Street",
"city":"Mandaluyong City",
"state":"Metro Manila",
"zipCode":"12345",
"countryCode":"PH"
}
},
"items":[
{
"name":"Leather Belt",
"code":"pm_belt",
"description":"Medium-sized belt made from authentic leather",
"quantity":"1",
"amount":{
"value":"69.00",
"details":{
"discount":"0.00",
"serviceCharge":"0.00",
"shippingFee":"14.00",
"tax":"5.00",
"subtotal":"50.00"
}
},
"totalAmount":{
"value":"69.00",
"details":{
"discount":"0.00",
"serviceCharge":"0.00",
"shippingFee":"14.00",
"tax":"5.00",
"subtotal":"50.00"
}
}
}
],
"status":"CREATED",
"id":"ee0e3f70-c200-4812-8c4c-02ababa4fbb3",
"totalAmount":{
"currency":"PHP",
"value":"69.00",
"details":{
"discount":"0.00",
"serviceCharge":"0.00",
"shippingFee":"14.00",
"tax":"5.00",
"subtotal":"50.00"
}
},
"requestReferenceNumber":"123456789",
"transactionReferenceNumber":null,
"receiptNumber":null,
"createdAt":"2017-10-30T13:12:57.612Z",
"updatedAt":"2017-10-30T13:12:57.612Z",
"expiredAt":"2017-10-30T14:12:57.605Z",
"paymentType":"CREDIT_CARD",
"paymentStatus":"PENDING",
"redirectUrl":{
"success":"https://shop.com/success",
"failure":"https://shop.com/failure",
"cancel":"https://shop.com/cancel"
},
"refundedAmount":"0",
"expressCheckout":false,
"canPayPal":false
}

Thank you.

Undefined Index paymentType

No paymentType in responses. I assumed it's paymentScheme now.

this is the json response I got.

"merchant" => array:14 [▶]
"buyer" => []
"items" => array:1 [▶]
"status" => "CREATED"
"id" => "ca23efd8-9017-4e35-9af1-7d7ab4846c41"
"totalAmount" => array:3 [▶]
"requestReferenceNumber" => "46fe3f6241ee479153965a056a114dd95"
"transactionReferenceNumber" => null
"receiptNumber" => null
"createdAt" => "2017-11-10T08:57:40.624Z"
"updatedAt" => "2017-11-10T08:57:40.624Z"
"expiredAt" => "2017-11-10T09:57:40.622Z"
"paymentScheme" => "CREDIT_CARD"
"paymentStatus" => "PENDING"
"redirectUrl" => array:3 [▶]
"refundedAmount" => "0"
"expressCheckout" => false
"canPayPal" => false

Undefined index during checkout

Am I missing something?

image

Here is my code:

`<?php

require __DIR__ . '/vendor/autoload.php';

use PayMaya\PayMayaSDK;
use PayMaya\API\Checkout;
use PayMaya\Model\Checkout\Item;
use PayMaya\Model\Checkout\ItemAmount;
use PayMaya\Model\Checkout\ItemAmountDetails;

use PayMaya\Model\Checkout\Buyer;
use PayMaya\Model\Checkout\Address;
use PayMaya\Model\Checkout\Contact;

class PaymayaClass{
    private $publicApiKey;
    private $secretApiKey;
    private $environment;

    function __construct($config){
        $this->publicApiKey = $config['publicApiKey'];
        $this->secretApiKey = $config['secretApiKey'];
        $this->environment = $config['environment'];
    }

    function checkout($paymentArray){

        PayMayaSDK::getInstance()->initCheckout($this->publicApiKey, $this->secretApiKey, $this->environment);

        $itemCheckout = new Checkout();

        $itemAmountDetails = new ItemAmountDetails();
        $itemAmountDetails->shippingFee = $paymentArray['shippingFee'];
        $itemAmountDetails->tax = $paymentArray['tax'];
        $itemAmountDetails->subtotal = $paymentArray['subTotal'];

        $itemAmount = new ItemAmount();
        $itemAmount->currency = $paymentArray['currency'];
        $itemAmount->value = $paymentArray['totalAmount'];
        $itemAmount->details=$itemAmountDetails;
        $item = new Item();
        $item->name=$paymentArray['itemName'];
        $item->code=$paymentArray['itemCode'];
        $item->description=$paymentArray['itemDescription'];
        $item->quantity=$paymentArray['quantity'];
        $item->amount=$itemAmount;
        $item->totalAmount = $itemAmount;

        $itemCheckout->items = array($item);
        $itemCheckout->totalAmount = $itemAmount;
        $itemCheckout->requestReferenceNumber='123';
        $itemCheckout->redirectUrl = array(
            'success'=>'https://demo.hamiliserver.com/APIReceiver/',
            'faliure'=>'https://demo.hamiliserver.com/APIReceiver/',
            'cancel'=>'https://demo.hamiliserver.com/APIReceiver/'
        );

        $itemCheckout->execute();

    }

}

?>
`

PayMaya PHP SDK V2

Good Day,

Is your sample code or syntax for PayMaya PHP still working? because it seems outdated when I look at the syntax in your guide isn't?, because I'm looking for a code for how to write a Request to make a payment in PHP, this documentation("https://s3-us-west-2.amazonaws.com/developers.paymaya.com.pg/pay-by-paymaya/index.html#scan-dynamic-qr-payment-create-payment-post") just shows the header and the body of the Request but don't have a guide how to create a Request in PHP, could you help me where can I find a complete guide how to create a Request for create payment in PHP?

psr/log version depedency locked only on 1.0.0

Request:

psr/log : 1.0.0 - psr/log : ~1.0

It would be nice you can adjust psr/log dependency to support version > 1.0,
at least to update composer.json to require ~1.0.

I encountered this dependency version conflict on laravel5.4 as all module requires ~1.0. (1.0.2 specifically) and the sdk is trying to install 1.0.0 version.

 Problem 1
    - Can only install one of: psr/log[1.0.0, 1.0.2]. <-- trying to install two version 
    - Can only install one of: psr/log[1.0.2, 1.0.0].
    - Can only install one of: psr/log[1.0.0, 1.0.2].
    - paymaya/paymaya-sdk 0.0.1 requires psr/log 1.0.0 -> satisfiable by psr/log[1.0.0].
    - Installation request for paymaya/paymaya-sdk * -> satisfiable by paymaya/paymaya-sdk[0.0.1].
    - Installation request for psr/log (locked at 1.0.2, required as ^1.0) -> satisfiable by psr/log[1.0.2].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.