Skip to content

Commit

Permalink
Merge pull request #25 from JarrydLong/final
Browse files Browse the repository at this point in the history
Final Changes
  • Loading branch information
ideadude authored Jan 11, 2021
2 parents 337a19c + 2c965f1 commit e89d554
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
81 changes: 41 additions & 40 deletions classes/class.pmprogateway_ccbill.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,60 +457,61 @@ function sendToCCBill(&$order)

function cancel(&$order) {

//no matter what happens below, we're going to cancel the order in our system
$order->updateStatus("cancelled");
//require a payment transaction id
if(empty($order->subscription_transaction_id))
return false;
//no matter what happens below, we're going to cancel the order in our system
$order->updateStatus("cancelled");
//require a payment transaction id
if(empty($order->subscription_transaction_id))
return false;

//build the URL
$sms_link = "https://datalink.ccbill.com/utils/subscriptionManagement.cgi?";
//build the URL
$sms_link = "https://datalink.ccbill.com/utils/subscriptionManagement.cgi?";

$qargs = array();
$qargs["action"] = "cancelSubscription";
$qargs["clientSubacc"] = pmpro_getOption('ccbill_subaccount_number');
$qargs["subscriptionId"] = $order->subscription_transaction_id;
$qargs["clientAccnum"] = pmpro_getOption('ccbill_account_number');
$qargs["username"] = pmpro_getOption('ccbill_datalink_username'); //must be provided by CCBill
$qargs["password"] = pmpro_getOption('ccbill_datalink_password'); //must be provided by CCBill
$qargs = array();
$qargs["action"] = "cancelSubscription";
$qargs["clientSubacc"] = pmpro_getOption('ccbill_subaccount_number');
$qargs["subscriptionId"] = $order->subscription_transaction_id;
$qargs["clientAccnum"] = pmpro_getOption('ccbill_account_number');
$qargs["username"] = pmpro_getOption('ccbill_datalink_username'); //must be provided by CCBill
$qargs["password"] = pmpro_getOption('ccbill_datalink_password'); //must be provided by CCBill

$cancel_link = add_query_arg($qargs, $sms_link);
$response = wp_remote_get($cancel_link);
$cancel_link = add_query_arg($qargs, $sms_link);
$response = wp_remote_get($cancel_link);

$response_code = wp_remote_retrieve_response_code( $response );
$response_message = wp_remote_retrieve_response_message( $response );
$response_code = wp_remote_retrieve_response_code( $response );
$response_message = wp_remote_retrieve_response_message( $response );

$response_body = wp_remote_retrieve_body( $response );
$cancel_status = filter_var($response_body, FILTER_SANITIZE_NUMBER_INT);
$response_body = wp_remote_retrieve_body( $response );
$cancel_status = filter_var($response_body, FILTER_SANITIZE_NUMBER_INT);

if (200 != $response_code && !empty($response_message)) {
if (200 != $response_code && !empty($response_message)) {

//return new WP_Error( $response_code, $response_message );
$cancel_error = sprintf( __( 'Cancellation of subscription id: %s may have failed. Check CCBill Admin to confirm cancellation', 'pmpro-ccbill'), $order->subscription_transaction_id );
//return new WP_Error( $response_code, $response_message );
$cancel_error = sprintf( __( 'Cancellation of subscription id: %s may have failed. Check CCBill Admin to confirm cancellation', 'pmpro-ccbill'), $order->subscription_transaction_id );

$email = get_option("admin_email");
wp_mail($email, get_option("blogname") . __( ' CCBill Subscription Cancel Error', 'pmpro-ccbill' ), $cancel_error);
$email = get_option("admin_email");
wp_mail($email, get_option("blogname") . __( ' CCBill Subscription Cancel Error', 'pmpro-ccbill' ), $cancel_error);

} elseif ( 200 != $response_code ) {
//Unknown Error Occurred
$cancel_error = sprintf( __( 'Cancellation of subscription id: %s may have failed. Check CCBill Admin to confirm cancellation', 'pmpro-ccbill'), $order->subscription_transaction_id );
} elseif ( 200 != $response_code ) {
//Unknown Error Occurred
$cancel_error = sprintf( __( 'Cancellation of subscription id: %s may have failed. Check CCBill Admin to confirm cancellation', 'pmpro-ccbill'), $order->subscription_transaction_id );

$email = get_option("admin_email");
wp_mail($email, get_option("blogname") . __( ' CCBill Subscription Cancel Error', 'pmpro-ccbill' ), $cancel_error);
$email = get_option("admin_email");
wp_mail($email, get_option("blogname") . __( ' CCBill Subscription Cancel Error', 'pmpro-ccbill' ), $cancel_error);

} elseif( $cancel_status < 1) {
$error_code = $this->pmprocb_return_api_response( $cancel_status );
} elseif( $cancel_status < 1) {
$error_code = $this->pmprocb_return_api_response( $cancel_status );

//A CCBill Error has occured. They need to contact CCBill
$cancel_error = sprintf( __( 'Cancellation of subscription id: %s may have failed. Check CCBill Admin to confirm cancellation. Error: %s', 'pmpro-ccbill'), $order->subscription_transaction_id, $error_code );
//A CCBill Error has occured. They need to contact CCBill
$cancel_error = sprintf( __( 'Cancellation of subscription id: %s may have failed. Check CCBill Admin to confirm cancellation. Error: %s', 'pmpro-ccbill'), $order->subscription_transaction_id, $error_code );

$email = get_option("admin_email");
wp_mail($email, get_option("blogname") . __( ' CCBill Subscription Cancel Error', 'pmpro-ccbill' ), $cancel_error);
} else {
//success
}
$email = get_option("admin_email");
wp_mail($email, get_option("blogname") . __( ' CCBill Subscription Cancel Error', 'pmpro-ccbill' ), $cancel_error);
} else {
//success

}

return $order;
return $order;
}

function pmprocb_return_api_response( $code )
Expand Down
10 changes: 10 additions & 0 deletions webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ function pmpro_ccbill_Exit($redirect = false)
$log_email = get_option("admin_email");
wp_mail($log_email, get_option("blogname") . __( " CCBill Webhook Log", 'pmpro-ccbill' ), nl2br($logstr));
}

if( !empty( $_REQUEST['pmpro_orderid'] ) ){
//Coming back from the gateway, lets redirect back to membership confirmation
$morder = new MemberOrder( intval( $_REQUEST['pmpro_orderid'] ) );

if( !empty( $morder ) ){
$redirect = pmpro_url("confirmation", "?level=" . $morder->membership_id);
}
}

if(!empty($redirect))
wp_redirect($redirect);
exit;
Expand Down

0 comments on commit e89d554

Please sign in to comment.