duanqiao1961 2019-05-04 08:41
浏览 45

使用PayPal NVP ManageRecurringPaymentsProfileStatus后,IPN发送错误取消请求

When using ManageRecurringPaymentsProfileStatus through a while from rows returned for a MySQL database, instead of cancelling only the specified subscriptions, PayPal ends up cancelling all of them and sends IPN requests with the cancellations.

I did several verifications and the while loop only gets the necessary records from the database.

I am quite confused as to what happens and I would like to know if anyone could help me resolve that issue please.

The goal is to cancel all subscriptions, except the latest one.

Here is the original request:

$result = $db->query("SELECT * FROM REDACTED where subscr_id <>'" . $subscr_id . "' and txn_id <> '' and custom='" . $custom . "'");

while($row = mysqli_fetch_array($result))
{
 $profileid = $row[119];  
}

change_subscription_status( $profileid, 'Cancel' );
mysqli_free_result($result);

This does the same problematic behavior:

$result = $db->query("SELECT * FROM REDACTED where subscr_id <>'" . $subscr_id . "' and txn_id <> '' and custom='" . $custom . "'");

while($row = mysqli_fetch_array($result))
{
     change_subscription_status( $row[119], 'Cancel' );
}

mysqli_free_result($result);

Here is the code of the function:

<?php 
/**
 * Performs an Express Checkout NVP API operation as passed in $action.
 *
 * Although the PayPal Standard API provides no facility for cancelling a subscription, the PayPal
 * Express Checkout  NVP API can be used.
 */
function change_subscription_status( $profile_id, $action ) {

$api_request = 'USER=' . urlencode( 'REDACTED' )
            .  '&PWD=' . urlencode( 'REDACTED' )
            .  '&SIGNATURE=' . urlencode( 'REDACTED' )
            .  '&VERSION=76.0'
            .  '&METHOD=ManageRecurringPaymentsProfileStatus'
            .  '&PROFILEID=' . urlencode( $profile_id )
            .  '&ACTION=' . urlencode( $action )
            .  '&NOTE=' . urlencode( 'Profile cancelled at store' );

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp' ); // For live transactions, change to 'https://api-3t.paypal.com/nvp'
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );

// Uncomment these to turn off server and peer verification
// curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
// curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_POST, 1 );

// Set the API parameters for this transaction
curl_setopt( $ch, CURLOPT_POSTFIELDS, $api_request );

// Request response from PayPal
$response = curl_exec( $ch );

// If no response was received from PayPal there is no point parsing the response
if( ! $response )
    die( 'Calling PayPal to change_subscription_status failed: ' . curl_error( $ch ) . '(' . curl_errno( $ch ) . ')' );

curl_close( $ch );

// An associative array is more usable than a parameter string
parse_str( $response, $parsed_response );

return $parsed_response;
};

?>

Thank you for your time and help, it is greatly appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程