Last active
July 17, 2017 14:06
-
-
Save New0/85cdf453a2dd6f264fd673e07bd1e474 to your computer and use it in GitHub Desktop.
Send affiliate manager plugin information after Direct Stripe Payment ( UNTESTED )
This file contains 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
function my_direct_stripe_payment_completed( $charge_id, $post_id, $button_id, $user_id ) { | |
$charge = \Stripe\Charge::retrieve($charge_id); | |
$user = get_user_by('id', $user_id); | |
WPAM_Logger::log_debug('Stripe Payments Integration – asp_stripe_payment_completed hook triggered.'); | |
//Required Parameters | |
$amount = $charge->amount; | |
$purchaseAmount = number_format( $amount , '2' );//Sale Amount | |
$order_id = $charge->id;//Transaction ID | |
$buyer_email = $user->user_email;//Email address | |
//Optional parameter | |
$reference = $charge->description;//Use the item name as the reference | |
$ip_address = (isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : ''; | |
//Check the referrer data | |
$wpam_id = (isset($_COOKIE['wpam_id']) && !empty($_COOKIE['wpam_id'])) ? $_COOKIE['wpam_id'] : ''; | |
if(empty($wpam_id) && !empty($ip_address)){ | |
WPAM_Logger::log_debug('Stripe Payments integration – Checking affiliate ID using customer IP address.'); | |
$wpam_id = WPAM_Click_Tracking::get_referrer_id_from_ip_address($ip_address); | |
} | |
if (empty($wpam_id)) { | |
WPAM_Logger::log_debug('Stripe Payments integration – affiliate ID is not present. This customer was not referred by an affiliate.'); | |
return; | |
} | |
$args = array(); | |
$args['txn_id'] = $order_id; | |
$args['amount'] = $purchaseAmount; | |
$args['aff_id'] = $wpam_id; | |
$args['email'] = $buyer_email; | |
WPAM_Logger::log_debug('Stripe Payments integration – awarding commission for order ID: ' . $order_id . ', Purchase amount: ' . $purchaseAmount . ', Affiliate ID: ' . $wpam_id . ', Buyer Email: ' . $buyer_email); | |
do_action('wpam_process_affiliate_commission', $args); | |
} | |
add_action( 'direct_stripe_before_success_redirection', 'my_direct_stripe_payment_completed', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment