Skip to content

Instantly share code, notes, and snippets.

@raketbizdev
Created January 8, 2019 18:29
Show Gist options
  • Save raketbizdev/b5a985a892e6ce8af869f3d1ab073275 to your computer and use it in GitHub Desktop.
Save raketbizdev/b5a985a892e6ce8af869f3d1ab073275 to your computer and use it in GitHub Desktop.
public function init() {
filter( 'gform_field_content', array( $this, 'add_paynamics_inputs' ), 10, 5 );
add_action( 'gform_after_submission', array( $this, 'paynamics_after_submission' ), 10, 3 );
add_shortcode( 'paynamics_donation', array( $this,'paynamics_donation'), 10, 3 );
parent::init();
}
public function paynamics_data($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 = "try3d";
$_email = rgar( $entry, '2' );
$_phone = "";
$_mobile = rgar( $entry, '3' );
$_clientip = $_SERVER['REMOTE_ADDR'];
$_amount = rgar( $entry, '8' );
$_currency = rgar( $entry, '18' );
$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( $paynamics_url, true ) );
return $b64string;
}
public function paynamics_after_submission($entry, $form, $feed) {
$paynamics_url = $this->get_plugin_setting( 'frontend_url');
$data = $this->paynamics_data($entry, $form, $feed);
$this->log_debug( __METHOD__ . '(): body => ' . print_r( $data, true ) );
$forms = '<form name="form1" method="post" name="paynamics_payment" action="'.$paynamics_url.'">
<input type="hidden" name="paymentrequest" id="paymentrequest" value="'.$data.'">
<input type="submit">
</form>';
return $forms;
}
public function paynamics_donation($entry, $form, $feed) {
$forms = $this->paynamics_after_submission($entry, $form, $feed);
return $forms;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment