简体   繁体   English

PayPal IPN不起作用

[英]PayPal IPN not working

I'm setting up so that my customers can subscribe for x amount a month for a service. 我正在进行设置,以便我的客户可以每月订阅x金额的服务。

When a payment is made, everything is fine. 付款后,一切都很好。 But it seems that when somebody cancels a subscription it still goes through as a completed payment. 但是似乎当有人取消订阅时,它仍会作为完成的付款进行。

Any help would be greatly appreciated. 任何帮助将不胜感激。

$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
  $keyval = explode ('=', $keyval);
  if (count($keyval) == 2)
     $myPost[$keyval[0]] = urldecode($keyval[1]);
}

$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
   $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
   if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
        $value = urlencode(stripslashes($value)); 
   } else {
        $value = urlencode($value);
   }
   $req .= "&$key=$value";
}

$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

if( !($res = curl_exec($ch)) ) {
    // error_log("Got " . curl_error($ch) . " when processing IPN data");
    curl_close($ch);
    exit;
}
curl_close($ch);

if (strcmp ($res, "VERIFIED") == 0) {

    // assign posted variables to local variables
    $item_name = $_POST['item_name'];
    $item_number = $_POST['item_number'];
    $payment_status = $_POST['payment_status'];
    $payment_amount = $_POST['mc_gross'];
    $payment_currency = $_POST['mc_currency'];
    $txn_id = $_POST['txn_id'];
    $receiver_email = $_POST['receiver_email'];
    $email = $_POST['payer_email'];
    $custom = $_POST['custom'];


// MY SUCCESSFUL CODE HERE



} else if (strcmp ($res, "INVALID") == 0) {


}

There are different transaction types possible with PayPal IPN. PayPal IPN可能有不同的交易类型。 See here: https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/ 参见此处: https : //developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/

Typically, your back-end or administrative processes will perform specific actions based on the kind of IPN message received. 通常,您的后端或管理过程将根据收到的IPN消息的种类执行特定的操作。 You can use the txn_type variable in the message to trigger the kind of processing you want to perform. 您可以在消息中使用txn_type变量来触发要执行的处理类型。

It sounds like you are simply assuming the transaction type is a payment, but you are, in fact, getting an incomplete or canceled payment notification. 听起来您只是在假设交易类型为付款,但实际上您收到的付款通知不完整或已取消。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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