Last active
June 22, 2017 01:29
-
-
Save treetrum/cb05204826949d2a2aabbb2d37e661b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add contact | |
$donation->setContact( | |
$safe_data['contact-title'], | |
$safe_data['contact-firstname'], | |
$safe_data['contact-surname'], | |
$safe_data['addressline1'], | |
$safe_data['addressline2'], | |
$safe_data['suburb'], | |
$safe_data['state'], | |
$safe_data['postcode'], | |
$safe_data['eveningtelephone'], | |
$safe_data['mobilenumber'], | |
$safe_data['emailaddress'], | |
$dob_formatted, | |
$safe_data['gender'] | |
); | |
// Attempt donation | |
try { | |
// If it's a recurring donation... | |
if ( $is_recurring ) { | |
$payment_id; | |
// If 1 is chosen for numberOfPayments, call pledgeOnceOff() | |
if ( $safe_data['numberOfPayments'] === '1' ) { | |
$payment_id = $donation->pledgeOnceOff( | |
$donationAmount, | |
'Credit Card', | |
$cc_type, | |
$cc_number_formatted, | |
$safe_data['card-holders-name'], | |
$cc_expiry, | |
$safe_data['cvc'], | |
$safe_data['source-code'], | |
$safe_data['source-code-2'], | |
$safe_data['destination-code'], | |
$safe_data['destination-code-2'], | |
$recurrence_date | |
); | |
} | |
// If 'indefinitely' is chosen for numberOfPayments, call pledgeContinuousMonthly() | |
elseif ( $safe_data['numberOfPayments'] === 'indefinitely' ) { | |
$payment_id = $donation->pledgeContinuousMonthly( | |
$donationAmount, | |
'Credit Card', | |
$cc_type, | |
$cc_number_formatted, | |
$safe_data['card-holders-name'], | |
$cc_expiry, | |
$safe_data['cvc'], | |
$safe_data['source-code'], | |
$safe_data['source-code-2'], | |
$safe_data['destination-code'], | |
$safe_data['destination-code-2'], | |
$recurrence_date | |
); | |
} | |
// Otherwise, call pledgeFixedMonthly | |
else { | |
$payment_id = $donation->pledgeFixedMonthly( | |
$donationAmount, | |
'Credit Card', | |
$cc_type, | |
$cc_number_formatted, | |
$safe_data['card-holders-name'], | |
$cc_expiry, | |
$safe_data['cvc'], | |
$safe_data['numberOfPayments'], | |
$safe_data['source-code'], | |
$safe_data['source-code-2'], | |
$safe_data['destination-code'], | |
$safe_data['destination-code-2'], | |
$recurrence_date | |
); | |
} | |
} | |
// If it's not a recurring donation, call donate() | |
else { | |
$payment_id = $donation->donate( | |
$donationAmount, | |
'Credit Card', | |
$cc_type, | |
$cc_number_formatted, | |
$safe_data['card-holders-name'], | |
$cc_expiry, | |
$safe_data['cvc'], | |
$safe_data['source-code'], | |
$safe_data['source-code-2'], | |
$safe_data['destination-code'], | |
$safe_data['destination-code-2'] | |
); | |
} | |
// Email reciept to user | |
$donationHelper->sendEmailReciept( | |
$safe_data['emailaddress'], | |
$safe_data['card-holders-name'], | |
$safe_data['donation-amount'], | |
$is_recurring, | |
get_the_title($safe_data['referral-page']), | |
$payment_id | |
); | |
// Redirect user on success. | |
wp_redirect( get_permalink(11228), 302 ); | |
exit; | |
} catch (ThankQ\ThankQException $ex) { | |
// Error handling Code | |
$error = array( | |
'message' => $ex->getMessage(), | |
'code' => $ex->getCode(), | |
'trace' => $ex->getTrace(), | |
'xml' => $ex->getRawRequestXml() | |
); | |
ob_start(); | |
print_r($error['trace']); | |
$tracePrintR = ob_get_clean(); | |
// Log the error as a donation-error post | |
$post_added = wp_insert_post(array( | |
'post_title' => frg_current_sydney_time('Y-m-d h:ia') . ' (' . $safe_data['card-holders-name'] . ')', | |
'post_content' => '<h3>Error Code:</h3><p>' . $error['code'] . '</p><h3>Error Message:</h3><p>' . $error['message'] . '</p><h3>Trace details:</h3><pre>' . $tracePrintR . '</pre><h3>Raw XML</h3><pre>' . htmlentities( $error['xml'] ) . '</pre>', | |
'post_type' => 'donation-error', | |
'post_status' => 'private' | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment