Skip to content

Instantly share code, notes, and snippets.

@olivierroy
Last active March 27, 2020 13:44
Show Gist options
  • Save olivierroy/8710326 to your computer and use it in GitHub Desktop.
Save olivierroy/8710326 to your computer and use it in GitHub Desktop.
Payza payment option for PancakeApp (system/pancake/modules/gateways/models/payza_m.php)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* The Payza Gateway
*
* @subpackage Gateway
* @category Payments
*/
class Payza_m extends Gateway {
public $title = 'Payza';
public $frontend_title = 'Payza';
public $version = '1.0';
public $fee = null;
public $autosubmit = true;
public function __construct() {
parent::__construct(__CLASS__);
$this->fields = array(
'merchant_id' => "Payza Email",
'merchant_key' => "Security Code"
);
}
public function generate_payment_form($unique_id, $item_name, $amount, $success, $cancel, $notify, $currency_code) {
# Let's round the amount.
$amount = round($amount, 2);
return '<form method="post" action="https://secure.payza.com/checkout" name="payza_form"><input type="hidden" name="ap_purchasetype" value="item"/><input type="hidden" name="ap_merchant" value="'.$this->get_field('merchant_id').'"/><input type="hidden" name="ap_itemname" value="'.$item_name.'"/><input type="hidden" name="ap_currency" value="'.$currency_code.'"/><input type="hidden" name="ap_returnurl" value="'.$success.'"/><input type="hidden" name="ap_cancelurl" value="'.$cancel.'"/><input type="hidden" name="ap_quantity" value="1"/><input type="hidden" name="ap_amount" value="'.$amount.'"/><input type="hidden" name="ap_itemcode" value="'.$unique_id.'"/><input type="hidden" name="ap_alerturl" value="'.$notify.'"/><input type="hidden" name="ap_ipnversion" value="1"/><input type="image" name="ap_image" src="https://www.payza.com/images/payza-buy-now.png"/></form>';
}
public function process_notification($unique_id) {
//Definitions
$merchant_id = $this->get_field('merchant_id'); // Your Merchant ID
$merchant_key = $this->get_field('merchant_key'); // Your Merchant Key
if ($merchant_key == $_POST['ap_securitycode'] AND $merchant_id == $_POST['ap_merchant']) {
if($_POST['ap_status']=="Success") {
return array(
'txn_id' => $_POST['ap_referencenumber'], // the gateway transaction ID
'payment_gross' => number_format($_POST['ap_totalamount'],2), // the amount paid, rounded to 2 decimal places
'transaction_fee' => number_format($_POST['ap_feeamount'],2), // the fee charged by the gateway, rounded to 2 decimal places
'payment_date' => time(), // a UNIX timestamp for the payment date
'payment_status' => 'Completed', // One of: Completed/Pending/Refunded/Unpaid
'item_name' => $_POST['ap_itemname'], // the item name (passed to the gateway in generate_payment_form())
'is_paid' => true, // true or false, depending on whether payment was successful or not
);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment