wpsc_activate_subscription

Located in: paypal-pro.merchant.php, paypal-standard.merchant.php

Functions that call this hook: process_gateway_notification()
Arguments Accepted: $cart_row[‘cart_item_id’],(product id) $this->paypal_ipn_values[‘subscr_id’](subscriber_id)
Version Introduced: 3.8

Description: triggered on return from PayPal Pro, the type of transaction must be a subscriber signup or a subscriber payment and the cart item must have recurring billing set.

You would use this hook to run any code that needs to be run after a subscription has been created within PayPal Pro.

Note: you can’t use this hook to create or send off subscriptions as it is only triggered if the subscription has been successfully created within PayPal Pro.

Code in context:
[php firstline=”256″ highlight=”293″]
/**
* process_gateway_notification method, receives data from the payment gateway
* @access public
*/
function process_gateway_notification() {
$status = false;
switch ( strtolower( $this->paypal_ipn_values[‘payment_status’] ) ) {
case ‘pending’:
$status = 2;
break;
case ‘completed’:
$status = 3;
break;
case ‘denied’:
$status = 6;
break;
}

// Compare the received store owner email address to the set one
if ( strtolower( $this->paypal_ipn_values[‘receiver_email’] ) == strtolower( get_option( ‘paypal_multiple_business’ ) ) ) {
switch ( $this->paypal_ipn_values[‘txn_type’] ) {
case ‘cart’:
case ‘express_checkout’:
if ( $status )
$this->set_transaction_details( $this->paypal_ipn_values[‘txn_id’], $status );
if ( in_array( $status, array( 2, 3 ) ) )
transaction_results($this->cart_data[‘session_id’],false);
break;

case ‘subscr_signup’:
case ‘subscr_payment’:
if ( in_array( $status, array( 2, 3 ) ) ) {
$this->set_transaction_details( $this->paypal_ipn_values[‘subscr_id’], $status );
transaction_results($this->cart_data[‘session_id’],false);
}
foreach ( $this->cart_items as $cart_row ) {
if ( $cart_row[‘is_recurring’] == true ) {
do_action( ‘wpsc_activate_subscription’, $cart_row[‘cart_item_id’], $this->paypal_ipn_values[‘subscr_id’] );
}
}
break;

case ‘subscr_cancel’:
case ‘subscr_eot’:
case ‘subscr_failed’:
foreach ( $this->cart_items as $cart_row ) {
$altered_count = 0;
if ( (bool)$cart_row[‘is_recurring’] == true ) {
$altered_count++;
wpsc_update_cartmeta( $cart_row[‘cart_item_id’], ‘is_subscribed’, 0 );
}
}
break;

default:
break;
}
}

$message = "
{$this->paypal_ipn_values[‘receiver_email’]} => " . get_option( ‘paypal_multiple_business’ ) . "
{$this->paypal_ipn_values[‘txn_type’]}
{$this->paypal_ipn_values[‘mc_gross’]} => {$this->cart_data[‘total_price’]}
{$this->paypal_ipn_values[‘txn_id’]}

" . print_r( $this->cart_items, true ) . "
{$altered_count}
";
}
[/php]