Last active
November 29, 2020 02:57
-
-
Save raketbizdev/925cebdb5b27e875fcfb803c0d9b0451 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gravity Forms Paynamics Add-On. | |
* | |
* @since 1.0 | |
* @package GravityForms | |
* @author Rocketgenius | |
* @copyright Copyright (c) 2009 - 2018, Rocketgenius | |
*/ | |
// Include the payment add-on framework. | |
GFForms::include_payment_addon_framework(); | |
public function init() { | |
add_action( 'gform_after_submission', array( $this, 'paynamics_after_submission' ), 10, 3 ); | |
parent::init(); | |
} | |
public function paynamics_after_submission($entry, $form, $feed) { | |
$_mid = $this->get_plugin_setting( 'merchant_id'); | |
$_requestid = substr(uniqid(), 0, 13); | |
$_ipaddress = $_SERVER['SERVER_ADDR']; | |
$_noturl = $this->get_plugin_setting( 'notif_url'); | |
$_resurl = $this->get_plugin_setting( 'res_url'); | |
$_cancelurl = $this->get_plugin_setting( 'cancel_url'); | |
$_fname = rgar( $entry, '1.3' ); | |
$_mname = rgar( $entry, '1.4' ); | |
$_lname = rgar( $entry, '1.6' ); | |
$_addr1 = rgar( $entry, '14.1' ); | |
$_addr2 = rgar( $entry, '14.2' ); | |
$_city = rgar( $entry, '14.3' ); | |
$_state = rgar( $entry, '14.4' ); | |
$_country = rgar( $entry, '14.6' ); | |
$_zip = rgar( $entry, '14.5' ); | |
$_sec3d = rgar( $entry, '17' ); | |
$_email = rgar( $entry, '2' ); | |
$_phone = ""; | |
$_mobile = rgar( $entry, '3' ); | |
$_clientip = $_SERVER['REMOTE_ADDR']; | |
$_amount = rgar( $entry, '8' ); | |
$_currency = "PHP"; | |
$cert = $this->get_plugin_setting( 'merchant_key'); | |
$_logo = $this->get_plugin_setting( 'logo_url'); | |
$paynamics_url = $this->get_plugin_setting( 'frontend_url'); | |
$forSign = $_mid . $_requestid . $_ipaddress . $_noturl . $_resurl . $_fname . $_lname . $_mname . $_addr1 . $_addr2 . $_city . $_state . $_country . $_zip . $_email . $_phone . $_clientip . $_amount . $_currency . $_sec3d; | |
$_sign = hash("sha512", $forSign.$cert); | |
$xmlstr = ""; | |
$strxml = ""; | |
$strxml = $strxml . "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"; | |
$strxml = $strxml . "<Request>"; | |
$strxml = $strxml . "<orders>"; | |
$strxml = $strxml . "<items>"; | |
$strxml = $strxml . "<Items>"; | |
$strxml = $strxml . "<itemname>Donation</itemname><quantity>1</quantity><amount>" . $_amount . "</amount>"; | |
$strxml = $strxml . "</Items>"; | |
$strxml = $strxml . "</items>"; | |
$strxml = $strxml . "</orders>"; | |
$strxml = $strxml . "<mid>" . $_mid . "</mid>"; | |
$strxml = $strxml . "<request_id>" . $_requestid . "</request_id>"; | |
$strxml = $strxml . "<ip_address>" . $_ipaddress . "</ip_address>"; | |
$strxml = $strxml . "<notification_url>" . $_noturl . "</notification_url>"; | |
$strxml = $strxml . "<response_url>" . $_resurl . "</response_url>"; | |
$strxml = $strxml . "<cancel_url>" . $_cancelurl . "</cancel_url>"; | |
$strxml = $strxml . "<mtac_url>http://www.paynamics.com/index.html</mtac_url>"; | |
$strxml = $strxml . "<descriptor_note>'My Descriptor .18008008008'</descriptor_note>"; | |
$strxml = $strxml . "<fname>" . $_fname . "</fname>"; | |
$strxml = $strxml . "<lname>" . $_lname . "</lname>"; | |
$strxml = $strxml . "<mname>" . $_mname . "</mname>"; | |
$strxml = $strxml . "<address1>" . $_addr1 . "</address1>"; | |
$strxml = $strxml . "<address2>" . $_addr2 . "</address2>"; | |
$strxml = $strxml . "<city>" . $_city . "</city>"; | |
$strxml = $strxml . "<state>" . $_state . "</state>"; | |
$strxml = $strxml . "<country>" . $_country . "</country>"; | |
$strxml = $strxml . "<zip>" . $_zip . "</zip>"; | |
$strxml = $strxml . "<secure3d>" . $_sec3d . "</secure3d>"; | |
$strxml = $strxml . "<trxtype>sale</trxtype>"; | |
$strxml = $strxml . "<email>" . $_email . "</email>"; | |
$strxml = $strxml . "<phone>" . $_phone . "</phone>"; | |
$strxml = $strxml . "<mobile>" . $_mobile . "</mobile>"; | |
$strxml = $strxml . "<client_ip>" . $_clientip . "</client_ip>"; | |
$strxml = $strxml . "<amount>" . $_amount . "</amount>"; | |
$strxml = $strxml . "<currency>" . $_currency . "</currency>"; | |
$strxml = $strxml . "<mlogo_url>" . $_logo . "</mlogo_url>"; | |
$strxml = $strxml . "<pmethod></pmethod>";//CC, GC, PP, DP | |
$strxml = $strxml . "<signature>" . $_sign . "</signature>"; | |
$strxml = $strxml . "</Request>"; | |
$b64string = base64_encode($strxml); | |
// $this->log_debug( __METHOD__ . '(): feed => ' . print_r( $strxml, true ) ); | |
$request = new WP_Http(); | |
$response = $request->post( $paynamics_url, array( 'body' => $b64string ) ); | |
$this->log_debug( __METHOD__ . '(): body => ' . print_r( $response, true ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment