Skip to content

Instantly share code, notes, and snippets.

@aryeharmon
Created November 4, 2015 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aryeharmon/4b1a106315472ff319e8 to your computer and use it in GitHub Desktop.
Save aryeharmon/4b1a106315472ff319e8 to your computer and use it in GitHub Desktop.
yad eliezer donation script.
<?php
if( !isset( $_COOKIE['landing'] ) ){
setcookie("HTTP_REFERER", $_SERVER['HTTP_REFERER'], time() + (86400 * 30), "/");
setcookie("landing", "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", time() + (86400 * 30), "/");
}
function donation_btn_func( $atts ) {
$a = shortcode_atts( array(
'color' => 'pink',
'proj' => '',
'price' => '',
'ref' => '',
'text' => __('Donate now', 'roots'),
), $atts );
$color = 'btn-' . $a['color'];
if ($a['proj']) { $proj = 'proj=' . $a['proj']; }
if ($a['price']) { $price ='&price=' . $a['price']; };
if ($a['ref']) { $ref = '&ref=' . $a['ref']; };
return '<a class="btn ' . $color . '" href="'. don_page() . '?' . $proj . $price . $ref . '" role="button">' . $a['text'] . '</a>';
}
//[donation_btn color="yellow" proj="0" price="300" text="תרום עכשיו" ref="btn"]
add_shortcode( 'donation_btn', 'donation_btn_func' );
function donation_form_func() {
wp_enqueue_script('donation-script', get_template_directory_uri() . '/assets/js/donation_form.js', array(), '1.0', true);
echo '<!-- Facebook Conversion Code for דף תרומה -->
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement("script");
fbds.async = true;
fbds.src = "//connect.facebook.net/en_US/fbds.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(["track", "6022374209116", {"value":"0.00","currency":"ILS"}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6022374209116&amp;cd[value]=0.00&amp;cd[currency]=ILS&amp;noscript=1" /></noscript>';
ob_start();
$row_template = '
<div class="row donation">
<div class="col-sm-1 col-xs-2">
<button type="button" class="btn btn-link btn-block remove"><i class="fa fa-times"></i></button>
</div>
<div class="col-sm-3 col-xs-5">
<div class="form-group projects">
<label for="projectID">' . __('For project', 'roots') . '</label>
<select class="form-control" id="projectID" name="project[]">
<option value="0">' . __('General donation', 'roots') . '</option>
' . project_list("name") . '
<option value="1">' . __('Adopt Wedding', 'roots') . '</option>
<option value="2">' . __('Kol Kala', 'roots') . '</option>
</select>
</div>
</div>
<div class="col-sm-3 col-xs-5">
<div class="form-group prices">
<label for="priceID">' . __('Total', 'roots') . '</label>
<select class="form-control combobox" id="priceID" name="project_amount[]">
<option value="0">' . __('Choose or select an amount', 'roots') . '</option>
[the get price]
' . project_list("price") . '
<option value="1000" data-value="1000" data-parent="1">1000 ₪ עבור משפחה אחת</option>
<option value="750" data-value="750" data-parent="1">750 ₪ עבור משפחה אחת</option>
<option value="500" data-value="500" data-parent="1">500 ₪ עבור משפחה אחת</option>
<option value="200" data-value="200" data-parent="1">200 ₪ עבור משפחה אחת</option>
<option value="1800" data-value="1800" data-parent="2">1800 ₪ עבור משפחה אחת</option>
<option value="260" data-value="260" data-parent="2">260 ₪ עבור משפחה אחת</option>
<option value="180" data-value="180" data-parent="2">180 ₪ עבור משפחה אחת</option>
<option value="18" data-value="18" data-parent="2">18 ₪ עבור משפחה אחת</option>
</select>
</div>
</div>
<div class="col-sm-3 col-xs-12 new-donation">
<button type="button" class="btn btn-default btn-block add" id="add"><i class="fa fa-plus-circle"></i> ' . __('Add a new Donation', 'roots') . '</button>
</div>
<input type="hidden" name="project_amount_label[]">
</div>
';
function setID($projectID, $priceID, $row_template, $addclass, $currentvalue){
$row_template = str_replace("priceID", $priceID, $row_template);
if( $currentvalue > 0 ){
$row_template = str_replace('[the get price]', '<option value="'.$currentvalue.'" data-value="'.$currentvalue.'" data-parent="get_value" selected=selected>'.$currentvalue.'</option>', $row_template);
}
else{
$row_template = str_replace('[the get price]', '', $row_template);
}
if( $projectID ){
$row_template = str_replace('value="'.$projectID.'"', 'value="'.$projectID.'" selected=selected', $row_template);
}
$row_template = str_replace("row donation", "row donation".$addclass, $row_template);
return $row_template;
}
echo setID('', 'priceID', $row_template, ' template-row', 0);
if( pll_current_language() == 'he' ){
$country = '
<div class="col-sm-11 col-sm-offset-1">
<h4>' . __('I would like a taxable invoice:', 'roots') . '</h4>
<div class="radio">
<label>
<input type="radio" name="c_tax" class="c_tax" id="israel" value="israel" checked="checked">
' . __('Israel', 'roots') . '
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="c_tax" class="c_tax" id="france" value="france">
' . __('France', 'roots') . '
</label>
</div>
</div>
';
$currency = '
<option value="ILS">₪ - ' . __('Shekel', 'roots') . '</option>
<option value="EUR">€ - ' . __('Euro', 'roots') . '</option>
<option value="USD">$ - ' . __('Dollar', 'roots') . '</option>
';
}
elseif( pll_current_language() == 'fr' ){
$country = '
<div class="col-sm-11 col-sm-offset-1">
<h4>' . __('I would like a taxable invoice:', 'roots') . '</h4>
<div class="radio">
<label>
<input type="radio" name="c_tax" class="c_tax" id="france" value="france" checked="checked">
' . __('France', 'roots') . '
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="c_tax" class="c_tax" id="israel" value="israel">
' . __('Israel', 'roots') . '
</label>
</div>
</div>
';
$currency = '
<option value="EUR">€ - ' . __('Euro', 'roots') . '</option>
<option value="ILS">₪ - ' . __('Shekel', 'roots') . '</option>
<option value="USD">$ - ' . __('Dollar', 'roots') . '</option>
';
}elseif( pll_current_language() == 'es' ){
$country = '
<div class="col-sm-11 col-sm-offset-1">
<h4>' . __('I would like a taxable invoice:', 'roots') . '</h4>
<div class="radio">
<label>
<input type="radio" name="c_tax" class="c_tax" id="israel" value="israel" checked="checked">
' . __('Israel', 'roots') . '
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="c_tax" class="c_tax" id="france" value="france">
' . __('France', 'roots') . '
</label>
</div>
</div>
';
$currency = '
<option value="USD">$ - ' . __('Dollar', 'roots') . '</option>
<option value="EUR">€ - ' . __('Euro', 'roots') . '</option>
<option value="ILS">₪ - ' . __('Shekel', 'roots') . '</option>
';
}
$extra_form_content = setID('', 'price1', $row_template, '', $_GET['price']); // get the empty row html
if( $_POST['page'] == 'dates' ){ // if post came from dates page
$i = 1;
function add_extra_form_content($i, $amount, $row_template, $category){
$html = setID($category, 'added'.$i, $row_template, '', '').'<script> jQuery(document).ready(function() { jQuery("#added'.$i.'").combobox(); });</script>';
$html = str_replace('data-value="'.$amount.'" data-parent="'.$category.'"', 'data-value="'.$amount.'" data-parent="'.$category.'" selected=selected', $html);
return $html;
}
$extra_form_content = '';
if( $_POST['price'] ){
$dates['price'] = $_POST['price'];
$extra_form_content .= add_extra_form_content($i, $dates['price'], $row_template, 1);
$i++;
}
if( $_POST['bonus1'] ){
$dates['bonus1'] = $_POST['bonus1'];
$extra_form_content .= add_extra_form_content($i, $dates['bonus1'], $row_template, 2);
$i++;
}
if( $_POST['bonus2'] ){
$dates['bonus2'] = $_POST['bonus2'];
$extra_form_content .= add_extra_form_content($i, $dates['bonus2'], $row_template, 2);
$i++;
}
if( $_POST['bonus3'] ){
$dates['bonus3'] = $_POST['bonus3'];
$extra_form_content .= add_extra_form_content($i, $dates['bonus3'], $row_template, 2);
$i++;
}
if( $_POST['bonus4'] ){
$dates['bonus4'] = $_POST['bonus4'];
$extra_form_content .= add_extra_form_content($i, $dates['bonus4'], $row_template, 2);
$i++;
}
}
// onclick button events for Google Analytics
$ccte = "_gaq.push(['_trackEvent', 'Donation', 'CreditCart','Donation with Credit Cart']);";
$ppte = "_gaq.push(['_trackEvent', 'Donation', 'PayPal','Donation with PayPal']);";
echo '<button type="button" class="btn btn-lg btn-link btn-modal" data-toggle="modal" data-target="#taxModal"><i class="fa fa-external-link"></i> ' . __('Information about donation receipts for tax refund', 'roots') . '</button>
<div class="donation-form">
<form method="post" id="donation_form" name="donation_form">
<h3 class="pink-title col-sm-offset-1"><i class="fa fa-heart"></i> ' . __('Donation Details', 'roots') . '</h3>
<a class="col-sm-offset-1 collapsed edit-icon" data-toggle="collapse" href="#donation-info" aria-expanded="false" aria-controls="donation-info"><i class="fa fa-pencil"></i> ' . __('Edit', 'roots') . '</a>
<div class="collapse in" id="donation-info">
' . $extra_form_content . '
<hr>
<div class="row">
<div class="col-sm-2 col-sm-offset-1 col-xs-4">
<div class="form-group">
<label for="donation_type">' . __('Donation Type', 'roots') . '</label>
<select class="form-control" id="donation_type" name="donation_type">
<option value="single" checked="checked">' . __('One time donation', 'roots') . '</option>
<option value="cycles">' . __('Direct Debit', 'roots') . '</option>
</select>
</div>
</div>
<div class="col-sm-2 col-xs-4">
<div class="form-group payments">
<label for="payments">' . __('Payments', 'roots') . '</label>
<select class="form-control" id="payments" name="payments">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="18">18</option>
<option value="24">24</option>
<option value="36">36</option>
</select>
</div>
</div>
<div class="col-sm-2 col-xs-4">
<div class="form-group">
<label for="currency">' . __('Currency', 'roots') . '</label>
<select class="form-control" id="currency" name="currency">
'.$currency.'
</select>
</div>
</div>
<div class="col-sm-3 col-xs-12">
<div class="form-group total">
<label for="total">' . __('Total donation amount', 'roots') . '</label>
<div class="checkout-total-amount">
<span id="total_amount">0.00</span><span id="total_currency"> ₪</span>
</div>
<p class="help-block each-month"><span id="payment_amount">0.00</span> <span id="payment_currency">₪</span> ' . __('For each month', 'roots') . '</p>
</div>
</div>
</div>
<hr>
<h3 class="blue-title col-sm-offset-1"><i class="fa fa-user"></i> ' . __('Personal Imformation', 'roots') . '</h3>
<div class="row">
<div class="col-sm-3 col-sm-offset-1 col-xs-6">
<div class="form-group">
<label for="firstname">' . __('First name', 'roots') . '</label>
<input type="text" name="first_name" class="form-control" id="firstname">
</div>
</div>
<div class="col-sm-3 col-xs-6">
<div class="form-group">
<label for="lastname">' . __('Last name', 'roots') . '</label>
<input type="text" name="last_name" class="form-control" id="lastname">
</div>
</div>
<div class="col-sm-3 col-xs-6">
<div class="form-group">
<label for="phone">' . __('Phone', 'roots') . '</label>
<input type="text" name="phone" class="form-control" id="phone">
</div>
</div>
<div class="col-sm-3 col-sm-offset-1 col-xs-6">
<div class="form-group">
<label for="email">' . __('Email', 'roots') . '</label>
<input type="email" name="email" class="form-control" id="email">
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="form-group">
<label for="address">' . __('Address', 'roots') . '</label>
<input type="text" name="address" class="form-control" id="address" placeholder="' . __('Billing Address', 'roots') . '">
</div>
</div>
</div>
<hr>
<a class="open-collapse col-sm-offset-1 receipt-info collapsed" data-toggle="collapse" href="#receipt-info" aria-expanded="false" aria-controls="receipt-info"><i class="fa fa-caret-down"></i> ' . __('Show invoice options', 'roots') . '</a>
<div class="collapse" id="receipt-info">
<div class="row">
'.$country.'
</div>
<hr>
<a class="open-collapse col-sm-offset-1 receipt collapsed" data-toggle="collapse" href="#receipt" aria-expanded="false" aria-controls="receipt"><i class="fa fa-check-square-o"></i> ' . __('Invoice using another name', 'roots') . '</a>
<div class="collapse" id="receipt">
<div class="row">
<div class="col-sm-3 col-sm-offset-1 col-xs-6">
<div class="form-group">
<label for="firstname2">' . __('First name', 'roots') . '</label>
<input type="text" name="first_name_2" class="form-control" id="firstname">
</div>
</div>
<div class="col-sm-3 col-xs-6">
<div class="form-group">
<label for="lastname2">' . __('Last name', 'roots') . '</label>
<input type="text" name="last_name_2" class="form-control" id="lastname">
</div>
</div>
<div class="col-sm-3 col-xs-6">
<div class="form-group">
<label for="phone2">' . __('Phone', 'roots') . '</label>
<input type="text" name="phone_2" class="form-control" id="phone">
</div>
</div>
<div class="col-sm-3 col-sm-offset-1 col-xs-6">
<div class="form-group">
<label for="email2">' . __('Email', 'roots') . '</label>
<input type="email" name="email_2" class="form-control" id="email2">
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="form-group">
<label for="address2">' . __('Address', 'roots') . '</label>
<input type="text" name="address_2" class="form-control" id="address2" placeholder="' . __('Billing Address', 'roots') . '">
</div>
</div>
</div>
</div>
</div>
<hr>
</div>
<h3 class="green-title col-sm-offset-1"><i class="fa fa-credit-card"></i> ' . __('Summary and credit card information', 'roots') . '</h3>
<input type="hidden" name="USD" id="USD" value="' . get_field('field_54e5c6aa1b3ff', 'option') . '">
<input type="hidden" name="EUR" id="EUR" value="' . get_field('field_54e5c6451b3fe', 'option') . '">
<input type="hidden" name="postid" id="postid" value="">
<div class="col-sm-offset-1 payments-options" role="group">
<button type="button" name="credit_cart" class="btn btn-lg btn-pink" value="credit" id="pay_credit_card" onclick="' . $ccte . '">' . __('Donate by Credit Card', 'roots') . '</button>
<button type="submit" name="paypal" class="btn btn-lg btn-pink" value="paypal" onclick="' . $ppte . '">' . __('Donate by PayPal', 'roots') . '</button>
</div>
<div class="row">
<div class="col-sm-8 col-sm-offset-1 ajax-loader"><img src="'.get_template_directory_uri().'/assets/img/ajax-loader.gif" /></div>
<div class="col-sm-8 col-sm-offset-1" id="iframe"></div>
</div>
</form>
</div>
<!-- Modal -->
<div class="modal fade" id="taxModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">' . __('Information about donation receipts for tax refund', 'roots') . '</h4>
</div>
<div class="modal-body">
' . __('receipts are tax deductible invoices recognized by Israel (under section 46) or France (CERFA)', 'roots') . '
</br>
</br>
<strong>' . __('for Invoices recognized in the USA:', 'roots') . '</strong></br>
American Friends of Yad Eliezer</br>
American tax ID number: 11-3459952</br>
למעבר לתרומה באתר <a href="http://www.yadeliezer.org/" target="_blank">לחץ כאן</a></br>
</br>
<strong>' . __('for Invoices recognized in Canada you can conatct us:', 'roots') . '</strong></br>
Canadian Friend of Yad Eliezer</br>
Canadian Tax ID Number: BN889966867RR0001</br>
Tel: (1)- 514-735-283</br>
Email:info@yadeliezer.org</br>
</br>
<strong>' . __('for Invoices recognized in Britain you can conatct us:', 'roots') . '</strong></br>
Yad Eliezer Trust</br>
UK Registered Charity Number: 1115426</br>
Tel:(44)-0208-455-8394</br>
Email: benchontow@yadeliezer.org</br>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">' . __('Close', 'roots') . '</button>
</div>
</div>
</div>
</div>';
$output = ob_get_clean();
return $output;
}
add_shortcode( 'donation_form', 'donation_form_func' );
if ( isset( $_POST['credit_cart'] ) || isset( $_POST['paypal'] ) ) {
function clean($value){
return trim(strip_tags($value));
}
$first_name = clean($_POST['first_name']);
$last_name = clean($_POST['last_name']);
$phone = clean($_POST['phone']);
$email = clean($_POST['email']);
$address = clean($_POST['address']);
$country = clean($_POST['c_tax']);
$first_name_2 = clean($_POST['first_name_2']);
$last_name_2 = clean($_POST['last_name_2']);
$phone_2 = clean($_POST['phone_2']);
$email_2 = clean($_POST['email_2']);
$address_2 = clean($_POST['address_2']);
$payment_amount = clean($_POST['payments']);
$donation_type = clean($_POST['donation_type']);
$currency = clean($_POST['currency']);
$total_amount = 0;
foreach($_POST['project_amount'] as $key => $amount){
$total_amount += $amount;
}
$eachpayment = bcdiv($total_amount, $payment_amount, 2);
if( $payment_amount > 1 ){
$title_extra_text = "ב".$payment_amount." תשלומים"." ".$eachpayment." לחודש";
}
if( $donation_type == "month-to-month-payment" ){
$title_extra_text = "הוראת קבע";
}
$post = array(
'post_name' => "donation-",
'post_title' => "תרומה מס'",
'post_status' => 'draft',
'post_type' => 'donation',
);
if( !$_POST['postid'] ){ // if did not add a page already
$page_id = wp_insert_post( $post ); // add post
// update post name to id
$my_post = array(
'post_name' => "donation-" . $page_id, // The name (slug) for your post
'ID' => $page_id,
'post_title' => "תרומה מס' " . $page_id,
'post_status' => 'pending',
);
wp_update_post( $my_post );
}
else {
$page_id = $_POST['postid'];
}
//update cart fields
$field_key = "field_54e21f263246f";
foreach($_POST['project_amount'] as $key => $amount){
$value[] = array(
'for_project' => $_POST['project'][$key],
'price_label' => $_POST['project_amount_label'][$key],
'price_value' => $_POST['project_amount'][$key],
);
}
update_field( $field_key, $value, $page_id );
//update field first name
update_field( "field_54e3282113bbe", $first_name, $page_id );
//update field last name
update_field( "field_54e3287c13bbf", $last_name, $page_id );
//update field phone number
update_field( "field_54e3289013bc0", $phone, $page_id );
//update field email address
update_field( "field_54e328af13bc1", $email, $page_id );
//update field address
update_field( "field_54e328bf13bc2", $address, $page_id );
//update field country
update_field( "field_54e3293ae13b6", $country, $page_id );
//update field billing first name
update_field( "field_54e32995e13b7", $first_name_2, $page_id );
//update field billing last name
update_field( "field_54e329bee13b8", $last_name_2, $page_id );
//update field billing phone number
update_field( "field_54e329d3e13b9", $phone_2, $page_id );
//update field billing email address
update_field( "field_54e329e5e13ba", $email_2, $page_id );
//update field billing address
update_field( "field_54e329fce13bb", $address_2, $page_id );
//update field donation type
update_field( "field_54e32aa6113c2", $donation_type, $page_id );
//update field payment amount
update_field( "field_54e32ac7113c3", $payment_amount, $page_id );
//update field total amount
update_field( "field_54e32adb113c4", $total_amount, $page_id );
//update field currency
update_field( "field_54e33e10b32e7", $currency, $page_id );
//update pay status
update_field( "field_54e32af1113c5", "pending", $page_id );
//update lang
update_field( "field_54f301dcc6bfa", pll_current_language(), $page_id );
//update referer
if( isset( $_COOKIE['HTTP_REFERER'] ) ){
update_field( "field_5533c3f93d0f7", $_COOKIE['HTTP_REFERER'], $page_id );
setcookie('HTTP_REFERER', null, -1, '/');
}
//update landing
if( isset( $_COOKIE['landing'] ) ){
update_field( "field_5533c48c3d0f8", $_COOKIE['landing'], $page_id );
setcookie('landing', null, -1, '/');
}
function billing($value1, $value2){
if ($value2){
return $value2;
}
else{
return $value1;
}
}
if( isset( $_POST['paypal'] ) ){
if( $country == "israel" ){
$business = 'neomig@yadeliezer.org';
//update pay with
update_field( "field_54e32d82b7bd1", "pp1", $page_id );
}
elseif( $country == "france" ){
$business = 'sgoldish@yadeliezer.org';
//update pay with
update_field( "field_54e32d82b7bd1", "pp2", $page_id );
}
if( $payment_amount == 1 && $donation_type != 'month-to-month-payment') { //one time paypal
// Prepare GET data
$query = array();
$query['charset'] = 'UTF-8';
$query['txn_type'] = 'subscr_signup';
$query['notify_url'] = 'https://www.yadeliezer.org.il/?postid=' . $page_id . '&totalamount=' . $total_amount . '&paypalipn=yes';
$query['return'] = 'https://www.yadeliezer.org.il/?p=4297&donid=' . $page_id . '&total=' . $total_amount . '-' . $currency . '&phone=' . $phone . '&email=' . $email;
//$query['cmd'] = '_cart';
$query['cmd'] = '_donations';
$query['upload'] = '1';
$query['business'] = $business;
$query['first_name'] = billing($first_name,$first_name_2);
$query['last_name'] = billing($last_name,$last_name_2);
$query['email'] = billing($email,$email_2);
$query['currency_code'] = $currency;
$query['item_name'] = "תרומה עבור יד אליעזר";
$query['amount'] = $total_amount;
$i = 1;
foreach($_POST['project_amount'] as $key => $amount){
if ( $_POST['project_amount'][$key] > 0 ){
if( $_POST['project'][$key] ){
$query['item_name_'.$i] = "עבור "." ".html_entity_decode(get_the_title( $_POST['project'][$key] ), ENT_COMPAT, 'UTF-8');
}
else{
$query['item_name_'.$i] = "תרומה כללית";
}
$query['quantity_'.$i] = 1;
$query['amount_'.$i] = $_POST['project_amount'][$key];
$i++;
}
}
// Prepare query string
$query_string = http_build_query($query);
header('Location: https://www.paypal.com/cgi-bin/webscr?' . $query_string);
}
elseif($payment_amount > 1 || $donation_type == 'month-to-month-payment'){ //payments paypal
// Prepare GET data
$query = array();
//new fields
$query['charset'] = 'UTF-8';
$query['custom'] = '2445|00782e3092fb93311bb5e6e183278b90';
$query['custom'] = '2445|00782e3092fb93311bb5e6e183278b90';
$query['cbt'] = 'Click here to continue';
$query['return'] = 'https://www.yadeliezer.org.il/?p=4297&donid=' . $page_id . '&total=' . $total_amount . '-' . $currency . '&phone=' . $phone . '&email=' . $email;
$query['rm'] = '2';
$query['cmd'] = '_xclick-subscriptions';
if ($donation_type != 'month-to-month-payment'){
$query['srt'] = $payment_amount;
$query['item_name'] = "תרומה בתשלומים עבור יד אליעזר";
}
else{
$query['item_name'] = "תרומה בהוראת קבע עבור יד אליעזר";
}
$query['a3'] = $eachpayment;
$query['sra'] = '0';
$query['p3'] = '1';
$query['t3'] = 'M';
$query['src'] = '1';
$query['lc'] = 'IL';
$query['country'] = 'IL';
$query['notify_url'] = 'https://www.yadeliezer.org.il/?postid='.$page_id.'&totalamount='.$total_amount.'&paypalipn=yes';
$query['upload'] = '1';
$query['business'] = $business;
$query['first_name'] = billing($first_name,$first_name_2);
$query['last_name'] = billing($last_name,$last_name_2);
$query['email'] = billing($email,$email_2);
$query['currency_code'] = $currency;
$i = 1;
foreach($_POST['project_amount'] as $key => $amount){
if( $_POST['project'][$key] ){
$query['item_name_'.$i] = "עבור "." ".html_entity_decode(get_the_title( $_POST['project'][$key] ), ENT_COMPAT, 'UTF-8');
}
else{
$query['item_name_'.$i] = "תרומה כללית";
}
$query['quantity_'.$i] = 1;
$query['amount_'.$i] = $_POST['project_amount'][$key];
$i++;
}
// Prepare query string
$query_string = http_build_query($query);
header('Location: https://www.paypal.com/cgi-bin/webscr?' . $query_string);
}
}
elseif($_POST['credit_cart']){
//update pay with
update_field( "field_54e32d82b7bd1", "cc", $page_id );
$TerminalNumber = 11352;
$UserName = '94xsuOr6qleH5LvPbwMu';
$CreateInvoice = true;
$IsIframe = true;
if (isset($_GET['dbg'])) {
$TerminalNumber = 1000;
$UserName = 'card9611';
}
if( $donation_type != 'month-to-month-payment' ){
$vars = array();
$vars['TerminalNumber'] = $TerminalNumber;
$vars['UserName'] = $UserName;
$vars["APILevel"] = "9";
$vars['codepage'] = '65001';
// billing info article : http://kb.cardcom.co.il/article/AA-00243/0
$vars['ChargeInfo.SumToBill'] = $total_amount;
if($currency == "ILS"){
$billing_coin = "1";
}
elseif($currency == "USD"){
$billing_coin = "2";
}
elseif($currency == "EUR"){
$billing_coin = "978";
}
$vars['ChargeInfo.CoinID'] = $billing_coin;
$vars['ChargeInfo.Language'] = "he"; // page languge he- hebrew , en - english , ru , ar
$vars['ChargeInfo.ProductName'] = "Order Number ".$page_id;
$vars['ChargeInfo.SuccessRedirectUrl'] = 'https://www.yadeliezer.org.il/success/?donid=' . $page_id . '&total=' . $total_amount . '-' . $currency . '&phone=' . $phone . '&email=' . $email;
$vars['ChargeInfo.ErrorRedirectUrl'] = 'https://www.yadeliezer.org.il/?p=4602';
$vars['ChargeInfo.IndicatorUrl'] = 'https://www.yadeliezer.org.il/';
$vars["ChargeInfo.ReturnValue"] = $page_id;
$vars["ChargeInfo.MinNumOfPayments"] = $payment_amount;
$vars["ChargeInfo.MaxNumOfPayments"] = $payment_amount;
//$vars['ChargeInfo.Currency'] = "Dollar";
$vars['ChargeInfo.AddCustomerToDirectDebit'] = 1;
if ($CreateInvoice){
$vars['InvoiceHead.CoinID'] = $billing_coin;
$vars["InvoiceHead.CustName"] = billing($first_name,$first_name_2)." ".billing($last_name,$last_name_2);
$vars["InvoiceHead.SendByEmail"] = "true";
$vars["InvoiceHead.Language"] = "he"; // he or en only
$vars["InvoiceHead.Email"] = billing($email,$email_2); // value that will be return and save in CardCom system
foreach($_POST['project_amount'] as $key => $amount){
if ( $_POST['project_amount'][$key] > 0 ){
if( $_POST['project'][$key] ){
$vars["InvoiceLines".$i.".Description"] = "עבור "." ".html_entity_decode(get_the_title( $_POST['project'][$key] ), ENT_COMPAT, 'UTF-8');
}
else{
$vars["InvoiceLines".$i.".Description"] = "תרומה כללית";
}
$vars["InvoiceLines".$i.".Price"] = $_POST['project_amount'][$key];
$vars["InvoiceLines".$i.".Quantity"] = "1";
$i++;
}
}
}
function PostVars($vars,$PostVarsURL){
$urlencoded = http_build_query($vars);
if( function_exists( "curl_init" )) {
$CR = curl_init();
curl_setopt($CR, CURLOPT_URL, $PostVarsURL);
curl_setopt($CR, CURLOPT_POST, 1);
curl_setopt($CR, CURLOPT_FAILONERROR, true);
curl_setopt($CR, CURLOPT_POSTFIELDS, $urlencoded );
curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($CR, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($CR, CURLOPT_FAILONERROR,true);
$r = curl_exec( $CR );
$error = curl_error ( $CR );
if( !empty( $error )) {
echo $error." 123";
die();
}
curl_close( $CR );
return $r;
}
else{
echo "No curl_init" ;
die();
}
}
// Send Data To Bill Gold Server
$r = PostVars($vars,'https://secure.cardcom.co.il/interface/PerformSimpleCharge.aspx');
parse_str($r,$result); # parse result.
# Is Deal OK
if ($result['ResponseCode'] == '0' ){
# Iframe or Redicet User :
$newurl = "https://secure.cardcom.co.il/External/lowProfileClearing/".$TerminalNumber.".aspx?LowProfileCode=". $result['LowProfileCode'];
if ($IsIframe){
$iframe = '<iframe runat="server" width="100%" height="1000px" src="'.$newurl.'" frameborder="0"></iframe>';
} else { //redirect
header("Location:".$newurl);
}
}
# Show Error to developer only
else {
$error = true;
}
header('Content-Type: application/json');
if(!$error){
$array = array( 'iframe' => $iframe, 'coin' => $billing_coin, 'pageID' => $page_id, );
}
else{
$array = array( 'iframe' => $result['ResponseCode'].' '.$result['Description']." ".$billing_coin, 'pageID' => $page_id, );
}
echo json_encode($array);
die(); //end content so that json will work
}
else{ // הוראת קבע
$vars = array();
$vars['TerminalNumber'] = $TerminalNumber;
$vars['UserName'] = $UserName;
$vars["TokenToCreate.APILevel"] = "9";
$vars['codepage'] = '65001';
$vars['TokenToCreate.Salt'] = $page_id;
$vars['TokenToCreate.DeleteDate'] = "01/01/2025";
$vars["TokenToCreate.JValidateType"] = "2";
$vars["TokenToCreate.IsCardApproval"] = "false"; // חיוב ויצירת אסימון.
// billing info article : http://kb.cardcom.co.il/article/AA-00243/0
$vars['TokenToCreate.SumToBill'] = $total_amount; // Sum To Bill
if($currency == "ILS"){
$billing_coin = '1';
}
elseif($currency == "USD"){
$billing_coin = '2';
}
elseif($currency == "EUR"){
$billing_coin = '978';
}
$vars['TokenToCreate.CoinID'] = $billing_coin; // billing coin , 1- NIS , 2- USD other , article : http://kb.cardcom.co.il/article/AA-00247/0
$vars['TokenToCreate.Language'] = "he"; // page languge he- hebrew , en - english , ru , ar
$vars['TokenToCreate.ProductName'] = "Order Number ".$page_id; // Product Name
$vars['TokenToCreate.SuccessRedirectUrl'] = 'https://www.yadeliezer.org.il/success/?donid=' . $page_id . '&total=' . $total_amount . '-' . $currency . '&phone=' . $phone . '&email=' . $email;
$vars['TokenToCreate.ErrorRedirectUrl'] = 'https://www.yadeliezer.org.il/?p=4602';
$vars['TokenChargeInfo.IndicatorUrl'] = 'https://www.yadeliezer.org.il/';
// Other optinal vars :
$vars["TokenToCreate.ReturnValue"] = $page_id; // value that will be return and save in CardCom system
$vars["TokenChargeInfo.MinNumOfPayments"] = 1; // max num of payments to show to the user
$vars["TokenChargeInfo.MaxNumOfPayments"] = 1; // max num of payments to show to the user
//$vars['TokenToCreate.Currency'] = "Dollar";
$vars['TokenToCreate.AddCustomerToDirectDebit'] = 1;
$vars['TokenChargeInfo.SumInStars'] = 0;
if ($CreateInvoice){
// article for invoice vars: http://kb.cardcom.co.il/article/AA-00244/0
// customer info :
$vars['InvoiceHead.CoinID'] = $billing_coin;
$vars["InvoiceHead.CustName"] = billing($first_name,$first_name_2)." ".billing($last_name,$last_name_2); // customer name
$vars["InvoiceHead.SendByEmail"] = "true"; // will the invoice be send by email to the customer
$vars["InvoiceHead.Language"] = "he"; // he or en only
$vars["InvoiceHead.Email"] = billing($email,$email_2); // value that will be return and save in CardCom system
// products info
foreach($_POST['project_amount'] as $key => $amount){
if ( $_POST['project_amount'][$key] > 0 ){
if( $_POST['project'][$key] ){
$vars["InvoiceLines".$i.".Description"] = "עבור "." ".get_the_title( $_POST['project'][$key] );
}
else{
$vars["InvoiceLines".$i.".Description"] = "תרומה כללית";
}
$vars["InvoiceLines".$i.".Price"] = $_POST['project_amount'][$key];
$vars["InvoiceLines".$i.".Quantity"] = "1";
$vars["InvoiceLines".$i.".Quantity"] = "1";
$i++;
}
}
}
function PostVars($vars,$PostVarsURL){
$urlencoded = http_build_query($vars);
#init curl connection
if( function_exists( "curl_init" )) {
$CR = curl_init();
curl_setopt($CR, CURLOPT_URL, $PostVarsURL);
curl_setopt($CR, CURLOPT_POST, 1);
curl_setopt($CR, CURLOPT_FAILONERROR, true);
curl_setopt($CR, CURLOPT_POSTFIELDS, $urlencoded );
curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($CR, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($CR, CURLOPT_FAILONERROR,true);
#actual curl execution perfom
$r = curl_exec( $CR );
$error = curl_error ( $CR );
# some error , send email to developer
if( !empty( $error )) {
echo $error." 123";
die();
}
curl_close( $CR );
return $r;
}
else{
echo "No curl_init" ;
die();
}
}
// Send Data To Bill Gold Server
$r = PostVars($vars,'https://secure.cardcom.co.il/interface/CreateToken.aspx');
parse_str($r,$result); # parse result.
# Is Deal OK
if ($result['ResponseCode'] == '0' ){
# Iframe or Redicet User :
$newurl = "https://secure.cardcom.co.il/External/lowProfileClearing/".$TerminalNumber.".aspx?LowProfileCode=". $result['LowProfileCode'];
if ($IsIframe){
$iframe = '<iframe runat="server" ID="TestIfame" width="100%" height="1000px" src="'.$newurl.'" frameborder="0"></iframe>';
}
else { //redirect
header("Location:".$newurl);
}
}
# Show Error to developer only
else{
$error = true;
}
header('Content-Type: application/json');
if(!$error){
$array = array( 'iframe' => $iframe, 'coin' => $billing_coin, 'pageID' => $page_id, );
}
else{
$array = array( 'iframe' => $result['ResponseCode'].' '.$result['Description']." ".$billing_coin, );
}
echo json_encode($array);
//print_r($vars);
die(); //end content so that json will work
}
}
}
if( $_GET['OperationResponse'] != "" && $_GET['ReturnValue'] != ""){
//echo "message";
// the message
//$actual_link = $_GET['ReturnValue']." ".$_GET['OperationResponse']; // commented out
//update pay status
if( $_GET['OperationResponse'] == "0" ){
switch ($_GET['DealResponse']) { // check response
case '0':
$response_message = "תקין";
break;
case '3':
$response_message = "סרוב";
break;
case '4':
$response_message = "גנוב";
break;
default:
$response_message = $_GET['DealResponse'];
}
update_field( "field_54e32af1113c5", "paid", intval($_GET['ReturnValue']) ); // update payment status
update_field( "field_5533c51b346db", $_GET['lowprofilecode'], intval($_GET['ReturnValue']) ); // update transaction id
update_field( "field_5533c53f346dc", $response_message, intval($_GET['ReturnValue']) ); // update response message
if($_GET['InvoiceResponseCode'] != '0'){
update_field( "field_5533c5a8346de", 0, intval($_GET['ReturnValue']) ); // update sent invoice
}
else{
update_field( "field_5533c5a8346de", 1, intval($_GET['ReturnValue']) ); // update sent invoice
}
$my_post = array(
'ID' => intval($_GET['ReturnValue']),
'post_status' => 'paid',
);
wp_update_post( $my_post );
}
else{
update_field( "field_54e32af1113c5", "error", intval($_GET['ReturnValue']) );
$my_post = array(
'ID' => intval($_GET['ReturnValue']),
'post_status' => 'error',
);
wp_update_post( $my_post );
}
}
// paypal ipn
if( $_GET['paypalipn'] ){
//Build the data to post back to Paypal
$postback = 'cmd=_notify-validate';
// go through each of the posted vars and add them to the postback variable
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$postback .= "&$key=$value";
}
// build the header string to post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($postback) . "\r\n\r\n";
// Send to paypal or the sandbox depending on whether you're live or developing
// comment out one of the following lines
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp)
{
// HTTP ERROR Failed to connect
//error handling or email here
}
else // if we've connected OK
{
fputs ($fp, $header . $postback);//post the data back
while (!feof($fp))
{
$response = fgets ($fp, 1024);
if (strcmp ($response, "VERIFIED") == 0) //It's verified
{
// assign posted variables to local variables, apply urldecode to them all at this point as well, makes things simpler later
$payment_status = $_POST['payment_status'];//read the payment details and the account holder
if($payment_status == 'Completed')
{
update_field( "field_54e32af1113c5", "paid", $_GET['postid'] ); // update payment status
update_field( "field_5533c51b346db", $_POST['receipt_id'], $_GET['postid'] ); // update translation id
// update status
$my_post = array(
'ID' => $_GET['postid'],
'post_status' => 'paid',
);
wp_update_post( $my_post );
}
else if($payment_status == 'Denied' || $payment_status == 'Failed' || $payment_status == 'Refunded' || $payment_status == 'Reversed' || $payment_status == 'Voided')
{
update_field( "field_54e32af1113c5", "error", $_GET['postid'] );
$my_post = array(
'ID' => $_GET['postid'],
'post_status' => 'error',
);
wp_update_post( $my_post );
}
else if($payment_status == 'In-Progress' || $payment_status == 'Pending' || $payment_status == 'Processed')
{
update_field( "field_54e32af1113c5", "pending", $_GET['postid'] );
}
}
else if (strcmp ($response, "INVALID") == 0)
{
//the Paypal response is INVALID, not VERIFIED
}
} //end of while
fclose ($fp);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment