Skip to content

Instantly share code, notes, and snippets.

@media317
Created July 22, 2014 01:00
Show Gist options
  • Save media317/f14a1b9c2860064af0d4 to your computer and use it in GitHub Desktop.
Save media317/f14a1b9c2860064af0d4 to your computer and use it in GitHub Desktop.
Hopegivers WooCommerce to DonorPro
//* Send information to DonorPro
add_action( 'woocommerce_order_status_completed', 'hope_donor', 1, 5 );
/*
* Do something after WooCommerce sets an order on completed
*/
function hope_donor($user_id, $new_order, $paykey, $fields, $source) {
$order = new ID_Member_Order($new_order);
$the_order = $order->get_order();
if (!empty($the_order)) {
$price = $the_order->price;
$level_id = $the_order->level_id;
$txn_id = $the_order->transaction_id;
if (isset($level_id) && $level_id > 0) {
$level = ID_Member_Level::get_level($level_id);
if (isset($level)) {
$level_name = $level->level_name;
}
else {
$level_name = bloginfo('description');
}
$user = get_user_by('id', $user_id);
if (!empty($user)) {
$fname = $user->user_firstname;
$lname = $user->user_lastname;
$email = $user->user_email;
}
else {
$fname = '';
$lname = '';
$email = '';
}
$crm_settings = get_option('crm_settings');
if (!empty($crm_settings)) {
$shipping_info = $crm_settings['shipping_info'];
}
$address = '';
$city = '';
$state = '';
$zip = '';
if (isset($shipping_info) && $shipping_info == '1') {
$md_shipping_info = get_option('md_shipping_info', true);
if (!empty($md_shipping_info)) {
$address = $md_shipping_info['address'];
$city = $md_shipping_info['city'];
$state = $md_shipping_info['state'];
$zip = $md_shipping_info['zip'];
}
}
$url = 'https://asp1010.towercare.com:54220/webDonation';
// Required VARS
$REDIRECT_PATH = md_get_durl(); // thank you URL
$webSource = 99; // source of payment (bridge)
$webSourceID = $level_name; // description
$donorCompletion = 3; // payment status - 3 is paid
$aiWebMappingName = 'ignitiondeck'; // found in DP admin
// Additional Required VARS
$firstName = $fname;
$lastOrOrgName = $lname;
// Optional VARS
$emailAddress = $email;
$lineOne = $address;
$cityName = $city;
$stateProvinceCode = $state;
$postalCode = $zip;
$sessionTitle = $level_name; // Project Title
$query_array = array(
'REDIRECT_PATH' => 'anything',
'webSource' => $webSource,
'webSourceID' => $webSourceID,
//'donorCompletion' => $donorCompletion,
'aiWebMappingName' => $aiWebMappingName,
'firstName' => $firstName,
'lastOrOrgName' => $lastOrOrgName,
'emailAddress' => $emailAddress,
'lineOne' => $lineOne,
'cityName' => $cityName,
'stateProvinceCode' => $stateProvinceCode,
'postalCode' => $postalCode,
'sessionTitle' => $sessionTitle,
'amount' => $price,
'authNumber' => $txn_id,
'creditCardNumber' => '1111',
'expirationMonth' => '01',
'expirationYear' => '2017',
);
$query_string = http_build_query($query_array);
$query_url = $url.'?'.$query_string;
//echo $query_url;
/*
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $query_url);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$res = curl_exec($ch);
if (!curl_error($ch)) {
echo 'no error';
echo $res;
}
else {
echo 'error';
print_r(curl_error($ch));
}
curl_close($ch);*/
$response = file_get_contents($query_url);
//print_r($response);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment