简体   繁体   中英

Paypal sandbox Recurring Payments ipn

I am doing recurring payment. After the payment is complete and reverted back to the return url, I am not getting the ipn response. This is my code for recurring payment:

    $query = array();
    $query['cmd'] = '_xclick-subscriptions';
    $query['upload'] = '1';

    $query['business'] = $select_paypal_detail[0]->business_mail;

    $product = $_POST['package'];
    //$product_price = $_POST['price'];
    $product_quantity = $_POST['quantity'];

    $query['a3'] = $_POST['price'];
    $query['p3'] = 1;
    $query['t3'] = 'D';
    $query['no_note'] = 1;

    //$query['amount'] = $_POST['price'];

    $query['discount_rate'] = $_POST['discount'];
    $query['item_name'] = $_POST['package'];

    $query['quantity'] = $_POST['quantity'];

    $query['currency'] =  'CAD';
    $query['instId'] = '211616';
    $query['testMode'] = 100;
    $_SESSION['order_number'] = $order_number;
    $query['cartId'] = 'Order Number '.$_POST['order_number'];
    $query['return'] = $select_paypal_detail[0]->return_url;
    $query['notify_url'] = "http://theelitecoachingacademy.com/?AngellEYE_Paypal_Ipn_For_Wordpress&action=ipn_handler";

    // Prepare query string
    $query_string = http_build_query($query);   

    if( $select_paypal_detail[0]->payment_type == 'live' ){
    ?>

    <!--/header('Location: https://www.paypal.com/cgi-bin/webscr?' . $query_string);
    header('Location: https://www.sandbox.paypal.com/cgi-bin/webscr?' . $query_string);-->

    <script type="text/javascript">
                 window.location="https://www.paypal.com/cgi-bin/webscr?<? echo $query_string ?>";
    </script>
    <?php } else { ?>
    <script type="text/javascript">
                 window.location="https://www.sandbox.paypal.com/cgi-bin/webscr?<? echo $query_string ?>";
    </script>
    <?php
}?>

You don't need to use JavaScript to redirect in PHP first of all.

$paypalHost = $select_paypal_detail[0]->payment_type == 'live' ? 'paypal.com' : 'sandbox.paypal.com';

$query = array();
$query['cmd'] = '_xclick-subscriptions';
$query['upload'] = '1';

$query['business'] = $select_paypal_detail[0]->business_mail;

$product = $_POST['package'];
//$product_price = $_POST['price'];
$product_quantity = $_POST['quantity'];

$query['a3'] = $_POST['price'];
$query['p3'] = 1;
$query['t3'] = 'D';
$query['no_note'] = 1;

//$query['amount'] = $_POST['price'];

$query['discount_rate'] = $_POST['discount'];
$query['item_name'] = $_POST['package'];

$query['quantity'] = $_POST['quantity'];

$query['currency'] =  'CAD';
$query['instId'] = '211616';
$query['testMode'] = 100;
$_SESSION['order_number'] = $order_number;
$query['cartId'] = 'Order Number '.$_POST['order_number'];
$query['return'] = $select_paypal_detail[0]->return_url;
$query['notify_url'] = "http://theelitecoachingacademy.com/?AngellEYE_Paypal_Ipn_For_Wordpress&action=ipn_handler";

header('Location: https://www.' . $paypalHost . '/cgi-bin/webscr?' . http_build_query($query));
// usually, it's a good idea to exit after redirecting... in this case, it doesn't matter as the redirect is the last thing
exit;

In terms of your actual problem, I would check business variable is actually pointing to the right account depending on whether you are in sandbox mode or live mode because I would expect them to be different. As the documentation mention, the business variable is the PayPal ID or an email address associated with your account.

If you are sure that everything is correct, then I would check your IPN handler using the Paypal's IPN simulator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM