Commit 3ceef51e authored by root's avatar root

Initial push

parent 2c164dd7
<?php
if ('bitpay-class.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('<h2>Direct File Access Prohibited</h2>');
/*******************************************************************************
* PHP bitpay IPN Integration Class
*******************************************************************************
* Author: Rich Pedley
* Based on: Paypal class
*
* To submit an order to bitpay, have your order form POST to a file with:
*
* $p = new bitpay_class;
* $p->add_field('business', 'somebody@domain.com');
* $p->add_field('first_name', $_POST['first_name']);
* ... (add all your fields in the same manor)
* $p->submit_bitpay_post();
*
* To process an IPN, have your IPN processing file contain:
*
* $p = new bitpay_class;
* if ($p->validate_ipn()) {
* ... (IPN is verified. Details are in the ipn_data() array)
* }
*
*******************************************************************************
*/
class bitpay_class {
var $last_error; // holds the last error encountered
var $ipn_response; // holds the IPN response from paypal
var $ipn_data = array(); // array contains the POST values for IPN
var $fields = array(); // array holds the fields to submit to paypal
function bitpay_class() {
// initialization constructor. Called when class is created.
$this->last_error = '';
$this->ipn_response = '';
}
function add_field($field, $value) {
// adds a key=>value pair to the fields array, which is what will be
// sent to bitpay as POST variables. If the value is already in the
// array, it will be overwritten.
$this->fields["$field"] = $value;
}
function submit_bitpay_post() {
// The user will briefly see a message on the screen that reads:
// "Please wait, your order is being processed..." and then immediately
// is redirected to bitpay.
$echo= "<form method=\"post\" class=\"eshop eshop-confirm\" action=\"".$this->autoredirect."\"><div>\n";
/*
*
* Grab the standard data
*
*/
foreach ($this->fields as $name => $value) {
$pos = strpos($name, 'amount');
if ($pos === false) {
$echo.= "<input type=\"hidden\" name=\"$name\" value=\"$value\" />\n";
}else{
$echo .= eshopTaxCartFields($name,$value);
}
}
/*
* Changes the standard text of the redirect page.
*/
$refid=uniqid(rand());
$echo .= "<input type=\"hidden\" name=\"bitpayoption1\" value=\"$refid\" />\n";
$echo.='<label for="ppsubmit" class="finalize"><small>'.__('<strong>Note:</strong> Submit to finalize order at bitpay.','eshop').'</small><br />
<input class="button submit2" type="submit" id="ppsubmit" name="ppsubmit" value="'.__('Proceed to Checkout &raquo;','eshop').'" /></label>';
$echo.="</div></form>\n";
return $echo;
}
function eshop_submit_bitpay_post($myPOST) {
// The user will briefly see a message on the screen that reads:
// "Please wait, your order is being processed..." and then immediately
// is redirected to bitpay.
/*
*
* Grab the standard data, but adjust for your payment gateway as below
* remember most fields will actually be hidden for POSTing to your gateway
*
*/
global $eshopoptions, $blog_id;
$bitpay = $eshopoptions['bitpay'];
$echortn='<div id="process">
<p><strong>'.__('Please wait, your order is being processed&#8230;','eshop').'</strong></p>
<p>'. __('If you are not automatically redirected to bitpay, please use the <em>Proceed to bitpay</em> button.','eshop').'</p>
<form method="post" id="eshopgatbitpay" class="eshop" action="'.$this->bitpay_url.'">
<p>';
$replace = array("&#039;","'", "\"","&quot;","&amp;","&");
$bitpay = $eshopoptions['bitpay'];
/* your changes would replace this section: start*/
$Cost=$myPOST['amount'];
if(isset($myPOST['tax']))
$Cost += $myPOST['tax'];
if(isset($_SESSION['shipping'.$blog_id]['tax'])) $Cost += $_SESSION['shipping'.$blog_id]['tax'];
$Cost = number_format($Cost, 2, '.', '');
$refid=$myPOST['bitpayoption1'];
//print_r($eshopoptions);
//print_r(get_permalink($eshopoptions['cart_success']));
//print_r($bitpay);
//print_r($myPOST);
$echortn.='
<input type="hidden" name="action" value="checkout" />
<input type="hidden" name="posData" value="'.$refid.'" />
<input type="hidden" name="data" value="bT9VyKJ2tFjCk8jRwbs4A+ejt/+z+D6+1aS+xEapgmvtruoh/eISH9Qb9tIzejeSN39iQKsA8DZ8YH8xbXFN7u9FhqfdY5fDJYjLGe40Ij/nQ/455SjZ4p05dtA16gZMCQRwH7fS/xNUHQtQ+jvgXobwbYnRUNEkLxuJdYbv/yHZwAk5u1YgVFgZoHMO2D8zRZuDRnM9jhS59epYjM9gA128i5ylUzcTOIVl/8vQNsI=" />
<input name="price" type="hidden" placeholder="Amount" value="'.$Cost.'" />
<input name="currency" type="hidden" value="'.$bitpay['currency'].'" />
<input type="hidden" name="buyerEmail" value="'.$bitpay['email'].'" />
<input class="button" type="submit" id="bitpaysubmit" name="submit" value="'. __('Proceed to bitpay &raquo;','eshop').'" /></p>
</form>
</div>';
/* your changes would replace this section :end */
return $echortn;
}
function validate_ipn() {
// generate the post string from the _POST vars aswell as load the
// _POST vars into an arry so we can play with them from the calling
// script.
foreach ($_REQUEST as $field=>$value) {
$this->ipn_data["$field"] = $value;
}
}
}
?>
bitpay.png

6.11 KB

<?php
/*
Plugin Name: eShop bitpay MG
Plugin URI: https://github.com/nextime/bitpay-eshop-mg
Description: BitPay Merchant Gatway for eShop
Version: 0.0.1
Author: Franco Lanza
Author URI: http://www.nexlab.it
Copyright 2012 Franco Lanza (email : franco@unixmedia.it)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
register_activation_hook(__FILE__,'eshopbitpay_activate');
function eshopbitpay_activate(){
/*
* Activation routines
*/
global $wpdb;
$opts=get_option('active_plugins');
$eshopthere=false;
foreach($opts as $opt){
if($opt=='eshop/eshop.php')
$eshopthere=true;
}
if($eshopthere==false){
deactivate_plugins('eshop-bitpay-mg.php'); //Deactivate ourself
wp_die(__('ERROR! eShop is not active.','eshop'));
}
/*
* insert email template for use with this merchant gateway, if 151 is changed, then ipn.php needs amending as well
*/
$table = $wpdb->prefix ."eshop_emails";
$esubject=__('Your order from ','eshop').get_bloginfo('name');
$wpdb->query("INSERT INTO ".$table." (id,emailType,emailSubject) VALUES ('151','".__('Automatic bitpay email','eshop')."','$esubject')");
}
add_action('eshop_setting_merchant_load','eshopmgpage');
function eshopmgpage($thist){
/*
* adding the meta box for this gateway
*/
add_meta_box('eshop-m-bitpay', __('bitpay','eshop'), 'bitpay_box', $thist->pagehook, 'normal', 'core');
}
function bitpay_box($eshopoptions) {
/*
* the meta box content, obviously you have to set up the required fields for your gateway here
*/
if(isset($eshopoptions['bitpay'])){
$eshopbitpay = $eshopoptions['bitpay'];
}else{
$eshopbitpay['email']='';
$eshopbitpay['apiKey']='';
$eshopbitpay['currency']='BTC';
}
//add the image
$eshopmerchantimgpath=WP_PLUGIN_DIR.'/eshop-bitpay-mg/bitpay.png';
$eshopmerchantimgurl=WP_PLUGIN_URL.'/eshop-bitpay-mg/bitpay.png';
$dims[3]='';
if(file_exists($eshopmerchantimgpath))
$dims=getimagesize($eshopmerchantimgpath);
echo '<fieldset>';
echo '<p class="eshopgatbitpay"><img src="'.$eshopmerchantimgurl.'" '.$dims[3].' alt="bitpay" title="bitpay" /></p>'."\n";
?>
<p class="cbox"><input id="eshop_methodbitpay" name="eshop_method[]" type="checkbox" value="bitpay"<?php if(in_array('bitpay',(array)$eshopoptions['method'])) echo ' checked="checked"'; ?> /><label for="eshop_methodbitpay" class="eshopmethod"><?php _e('Accept payment by bitpay','eshop'); ?></label></p>
<label for="eshop_bitpayemail"><?php _e('Email address for notifications','eshop'); ?></label><input id="eshop_bitpayemail" name="bitpay[email]" type="text" value="<?php echo $eshopbitpay['email']; ?>" size="30" maxlength="50" /><br />
<label for="eshop_bitpayapiKey"><?php _e('bitpay button encrypted data','eshop'); ?></label><input id="eshop_bitpayapiKey" name="bitpay[apiKey]" type="text" value="<?php echo $eshopbitpay['apiKey']; ?>" size="200" maxlength="5000" /><br />
<label for="eshop_bitpaycurrency"><?php _e('Currency','eshop'); ?></label><input id="eshop_bitpaycurrency" name="bitpay[currency]" type="text" value="<?php echo $eshopbitpay['currency']; ?>" size="60" /><br />
</fieldset>
<?php
}
add_filter('eshop_setting_merchant_save','bitpaysave',10,2);
function bitpaysave($eshopoptions,$posted){
/*
* save routine for the fields you added above
*/
global $wpdb;
$bitpaypost['email']=$wpdb->escape($posted['bitpay']['email']);
$bitpaypost['apiKey']=$wpdb->escape($posted['bitpay']['apiKey']);
$bitpaypost['currency']=$wpdb->escape($posted['bitpay']['currency']);
$eshopoptions['bitpay']=$bitpaypost;
return $eshopoptions;
}
add_action('eshop_include_mg_ipn','eshopbitpay');
function eshopbitpay($eshopaction){
/*
* adding the necessary link for the instant payment notification of your gateway
*/
if($eshopaction=='bitpayipn'){
include_once WP_PLUGIN_DIR.'/eshop-bitpay-mg/ipn.php';
}
}
add_filter('eshop_merchant_img_bitpay','bitpayimg');
function bitpayimg($array){
/*
* adding the image for this gateway, for use on the front end of the site
*/
$array['path']=WP_PLUGIN_DIR.'/eshop-bitpay-mg/bitpay.png';
$array['url']=WP_PLUGIN_URL.'/eshop-bitpay-mg/bitpay.png';
return $array;
}
add_filter('eshop_mg_inc_path','bitpaypath',10,2);
function bitpaypath($path,$paymentmethod){
/*
* adding another necessary link for the instant payment notification of your gateway
*/
if($paymentmethod=='bitpay')
return WP_PLUGIN_DIR.'/eshop-bitpay-mg/ipn.php';
return $path;
}
add_filter('eshop_mg_inc_idx_path','bitpayidxpath',10,2);
function bitpayidxpath($path,$paymentmethod){
/*
* adding the necessary link to the class for this gateway
*/
if($paymentmethod=='bitpay')
return WP_PLUGIN_DIR.'/eshop-bitpay-mg/bitpay-class.php';
return $path;
}
//message on fail.
add_filter('eshop_show_success', 'eshop_bitpay_return_fail',10,3);
function eshop_bitpay_return_fail($echo, $eshopaction, $postit){
/*
* failed payment, you can add in details for this, will need tweaking for your gateway
*/
//these are the successful codes, all others fail
$bitpayrescodes=array('00','08','10','11','16');
if($eshopaction=='bitpayipn'){
if($postit['bitpayTrxnStatus']=='False' && !in_array($postit['bitpayresponseCode'],$bitpayrescodes))
$echo .= '<p>There was a problem with your order, please contact admin@ ... quoting Error Code '.$postit['bitpayresponseCode']."</p>\n";
}
return $echo;
}
?>
<?php
/*
* Bitpay IPN eshop gateway by Franco (nextime) Lanza
*
* based on:
* PHP paypal IPN Integration Class Demonstration File
* 4.16.2005 - Micah Carrick, email@micahcarrick.com
*/
/*
* default info
*/
global $wpdb,$wp_query,$wp_rewrite,$blog_id,$eshopoptions;
$detailstable=$wpdb->prefix.'eshop_orders';
$derror=__('There appears to have been an error, please contact the site admin','eshop');
//sanitise
include_once(WP_PLUGIN_DIR.'/eshop/cart-functions.php');
$_POST=sanitise_array($_POST);
/*
* reqd info for your gateway
*/
include_once (WP_PLUGIN_DIR.'/eshop-bitpay-mg/eshop-bitpay-mg.php');
// Setup class
require_once(WP_PLUGIN_DIR.'/eshop-bitpay-mg/bitpay-class.php'); // include the class file
$p = new bitpay_class; // initiate an instance of the class
$p->bitpay_url = 'https://bitpay.com/checkout'; // bitpay url
/*
* reqd info /end
*/
$this_script = site_url();
global $wp_rewrite;
if($eshopoptions['checkout']!=''){
$p->autoredirect=add_query_arg('eshopaction','redirect',get_permalink($eshopoptions['checkout']));
}else{
die('<p>'.$derror.'</p>');
}
// if there is no action variable, set the default action of 'process'
if(!isset($wp_query->query_vars['eshopaction']))
$eshopaction='process';
else
$eshopaction=$wp_query->query_vars['eshopaction'];
switch ($eshopaction) {
case 'redirect':
//auto-redirect bits
header('Cache-Control: no-cache, no-store, must-revalidate'); //HTTP/1.1
header('Expires: Sun, 01 Jul 2005 00:00:00 GMT');
header('Pragma: no-cache'); //HTTP/1.0
//enters all the data into the database
/*
* this works out eShop's security field
*/
$Cost=$_POST['amount'];
if(isset($_POST['tax']))
$Cost += $_POST['tax'];
if(isset($_SESSION['shipping'.$blog_id]['tax'])) $Cost += $_SESSION['shipping'.$blog_id]['tax'];
$theid=$eshopoptions['bitpay']['id'];
$Cost=number_format($Cost,2);
$checkid=md5($_POST['bitpayoption1'].$theid.'$'.$Cost);
//debug
//echo 'check: '.$_POST['bitpayoption1'].$theid.'$'.$Cost;
//
if(isset($_COOKIE['ap_id'])) $_POST['affiliate'] = $_COOKIE['ap_id'];
orderhandle($_POST,$checkid);
if(isset($_COOKIE['ap_id'])) unset($_POST['affiliate']);
$p = new bitpay_class;
/*
* more reqd info
*/
$p->bitpay_url = 'https://bitpay.com/checkout'; // bitpay url
$echoit.=$p->eshop_submit_bitpay_post($_POST);
break;
case 'process': // Process and order...
// There should be no output at this point. To process the POST data,
// the submit_bitpay_post() function will output all the HTML tags which
// contains a FORM which is submited instantaneously using the BODY onload
// attribute. In other words, don't echo or printf anything when you're
// going to be calling the submit_bitpay_post() function.
// This is where you would have your form validation and all that jazz.
// You would take your POST vars and load them into the class like below,
// only using the POST values instead of constant string expressions.
// For example, after ensureing all the POST variables from your custom
// order form are valid, you might have:
//
// $p->add_field('first_name', $_POST['first_name']);
// $p->add_field('last_name', $_POST['last_name']);
/****** The order has already gone into the database at this point ******/
//goes direct to this script as nothing needs showing on screen.
if($eshopoptions['cart_success']!=''){
$ilink=add_query_arg(array('eshopaction'=>'bitpayipn'),get_permalink($eshopoptions['cart_success']));
}else{
die('<p>'.$derror.'</p>');
}
$p->add_field('bitpayURL', $ilink);
$p->add_field('shipping_1',eshopShipTaxAmt());
$sttable=$wpdb->prefix.'eshop_states';
$getstate=$eshopoptions['shipping_state'];
if($eshopoptions['show_allstates'] != '1'){
$stateList=$wpdb->get_results("SELECT id,code,stateName FROM $sttable WHERE list='$getstate' ORDER BY stateName",ARRAY_A);
}else{
$stateList=$wpdb->get_results("SELECT id,code,stateName,list FROM $sttable ORDER BY list,stateName",ARRAY_A);
}
foreach($stateList as $code => $value){
$eshopstatelist[$value['id']]=$value['code'];
}
foreach($_POST as $name=>$value){
//have to do a discount code check here - otherwise things just don't work - but fine for free shipping codes
if(strstr($name,'amount_')){
if(isset($_SESSION['eshop_discount'.$blog_id]) && eshop_discount_codes_check()){
$chkcode=valid_eshop_discount_code($_SESSION['eshop_discount'.$blog_id]);
if($chkcode && apply_eshop_discount_code('discount')>0){
$discount=apply_eshop_discount_code('discount')/100;
$value = number_format(round($value-($value * $discount), 2),2);
$vset='yes';
}
}
if(is_discountable(calculate_total())!=0 && !isset($vset)){
$discount=is_discountable(calculate_total())/100;
$value = number_format(round($value-($value * $discount), 2),2);
}
}
if(sizeof($stateList)>0 && ($name=='state' || $name=='ship_state')){
if($value!='')
$value=$eshopstatelist[$value];
}
$p->add_field($name, $value);
}
if($eshopoptions['status']!='live' && is_user_logged_in() && current_user_can('eShop_admin')||$eshopoptions['status']=='live'){
$echoit .= $p->submit_bitpay_post(); // submit the fields to bitpay
}
break;
case 'bitpayipn':
/*
* the routine for when the merchant gateway sontacts your site to validate the order.
* may need altering to suit your gateway
*/
$_SESSION = array();
session_destroy();
break;
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment