Download the PHP package chamikasamaraweera/payhere-php-sdk without Composer

On this page you can find all versions of the php package chamikasamaraweera/payhere-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package payhere-php-sdk

PayHere PHP SDK

Latest Version License PHP Version PHP Composer

A comprehensive PHP SDK for integrating PayHere Payment Gateway into your PHP applications.

Features

Requirements

Installation

Install via Composer:

Or manually add to your composer.json:

Quick Start

1. Initialize the SDK

2. Create a Payment Request

3. Handle Payment Notifications

Create a notification handler endpoint (e.g., notify.php):

Configuration

Merchant Credentials

You need two credentials from your PayHere account:

  1. Merchant ID: Found in Side Menu > Integrations
  2. Merchant Secret: Generate by adding your domain/app in Side Menu > Integrations

Sandbox vs Live

API Reference

PaymentRequest Methods

Method Description
setOrderId(string $orderId) Set unique order ID
setAmount(float $amount) Set payment amount
setCurrency(string $currency) Set currency (default: LKR)
setItems(string $name, int $number) Set item details
setCustomer(...) Set customer information
setReturnUrl(string $url) Set return URL after payment
setCancelUrl(string $url) Set cancel URL
setNotifyUrl(string $url) Set notification callback URL
setCustomFields(string $custom1, ?string $custom2) Set custom fields
getData() Get payment data array with hash
generateForm(string $buttonText, array $attrs) Generate HTML form
redirect() Auto-redirect to PayHere

NotificationHandler Methods

Method Description
verify() Verify notification hash
isSuccess() Check if payment was successful
getStatusCode() Get status code (2=success, 0=pending, -1=canceled, -2=failed)
getStatusText() Get status as text
getOrderId() Get order ID
getPaymentId() Get PayHere payment ID
getAmount() Get payment amount
getCurrency() Get currency
getCustom1() Get custom field 1
getCustom2() Get custom field 2
getCardHolderName() Get card holder name
getCardNo() Get masked card number
getMethod() Get payment method
getData() Get all notification data
get(string $key, $default) Get specific field

Payment Status Codes

Code Constant Description
2 STATUS_SUCCESS Payment successful
0 STATUS_PENDING Payment pending
-1 STATUS_CANCELED Payment canceled
-2 STATUS_FAILED Payment failed
-3 STATUS_CHARGEDBACK Payment chargedback

Complete Example

See the examples/ directory for complete working examples:

Security Best Practices

  1. Never expose your Merchant Secret in client-side code
  2. Always verify notifications using the verify() method
  3. Use HTTPS for all callback URLs
  4. Validate amounts in your notification handler
  5. Store payment records before redirecting to PayHere
  6. Use unique order IDs for each transaction

Testing

Use PayHere's sandbox environment for testing:

Test card details are available in PayHere's documentation.

Documentation

Support

Author

Chamika Samaraweera

License

MIT License - see the LICENSE file for details

Contributing

Contributions are welcome! Please read our Contributing Guide for details on how to submit pull requests.

Acknowledgments


All versions of payhere-php-sdk with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package chamikasamaraweera/payhere-php-sdk contains the following files

Loading the files please wait ...