billplz billplz extension simplify the Billplz Payment integration (Subodh Kr. Prasad: pdsubodh@gmail.com)

  1. Authentication
  2. Requirements
  3. Installation
  4. Usage

Billplz API endpoints to start sending bills and collection payment. This API is organized around REST. JSON will be returned in all responses from the API, including errors.

Authentication

Billplz API by providing your API Secret Keys in the request. You can get your API keys from your account’s settings page. Authentication to the API occurs via HTTP Basic Auth. Provide your API key as the basic auth username. You do not need to provide a password. All API requests must be made over HTTPS. Calls made over plain HTTP will fail. You must authenticate for all requests.

Requirements

Yii 1.1 or above

Installation

1. Download the package and extract
2. Move files as per folder structure

Usage

main.php

'components' => array(
....
'billplz' => array(
			'class'=>'Billplz',			
			'callbackUrl'=>'<<host_url>>/Billplz/notify',
			'redirectUrl'=>'<<host_url>>/Billplz/success',
			'user' => '<<username>>',
			'password' => '',
			'collectionId' => '<<collectionid>>',
			'expireInDays' => 30,
			'deliver' => false, //true
			
		),
....
)
  • The Controller
    • controllers/BillplzController.php
public function actionIndex() {
		$paymentInfo['email'] = 'test@test.com';
		$paymentInfo['name'] = 'Test';
		$paymentInfo['amount'] = '1';  // 1 RM
		//Recipient’s mobile number. Format is +601XXXXXXXX.
		$paymentInfo['mobile'] = ''; //$mobile should be  11-12 didit excluding + sign
		//put additional data for payment into metadata
		$paymentInfo['metaData'] = array(
			'invoiceID' => 'INV000001',
			'transactionID' => 'TRNS4526',
			'description' => 'This is a test bill',
		);
		$billPlzInfo = Yii::app()->billplz->getPaymentButton($paymentInfo);
		$this->render('index', array('billPlzInfo' => $billPlzInfo));
	}
  • Billplz Callback
public function actionNotify() {
		try {
			$rawPostData = file_get_contents('php://input');
			if (strlen($rawPostData) > 0) {
				$rawPostArray = explode('&', $rawPostData);
				$post = array();
				foreach ($rawPostArray as $keyval) {
					$keyval = explode('=', $keyval);
					if (count($keyval) == 2)
						$post[$keyval[0]] = urldecode($keyval[1]);
				}

				if (count($post) > 0) {
					if (isset($post['id']) && $post['id'] != "" && isset($post['state']) && $post['state'] == 'paid') {
						$billId = $post['id'];
						$billPlzValidate = Yii::app()->billplz->getbill($billId);
						if (count($billPlzValidate) > 0) {
							//validate the data with return data
							if ($post['id'] == $billPlzValidate['id'] && $post['paid_amount'] == $billPlzValidate['paid_amount']) {
								//update database accordingly with following valued								
								$billId = $billPlzValidate['id'];
								$state = $billPlzValidate['state'];
								$paid = $billPlzValidate['paid'];
								$paidAmount = $billPlzValidate['paid_amount'];
								$email = $billPlzValidate['email'];
								$mobile = $billPlzValidate['mobile'];
								/* .
								  .
								  .print_r($billPlzValidate);
								  .
								 */
							} else {
								throw new Exception("Billplz Error-4: Params Mismatch: <pre>" . print_r($responseArray, true) . print_r($post, true) . "</pre>");
							}
						} else {
							throw new Exception("Billplz Error-3: Invalid Call back: <pre>" . print_r($responseArray, true) . "</pre>");
						}
					} else {
						throw new Exception("Billplz Error-3: Payment Fail: <pre>" . print_r($post, true) . "</pre>");
					}
				} else {
					throw new Exception("Billplz Error-2: Invalid Required Params: <pre>" . print_r($rawPostArray, true) . "</pre>");
				}
			} else {
				throw new Exception("Billplz Error-1: Missing Params");
			}
		} catch (Exception $e) {
			Yii::log($e->getMessage(), CLogger::LEVEL_ERROR);
		}
		exit;
	}
1 0
1 follower
97 downloads
Yii Version: all
License: BSD-2-Clause
Category: Others
Developed by: pd_subodh
Created on: Oct 30, 2015
Last updated: 4 years ago

Downloads

show all

Related Extensions