php - 如何使用 php 自动取消订阅用户的 paypal(当他们升级到不同的订阅时)

标签 php paypal subscription paypal-ipn

当用户在我的网站上升级他们的订阅时,IPN 会联系我,然后我想使用 php 联系 paypal 以取消他们可能拥有的任何现有订阅。我该怎么做呢?我只能找到如何使用用户必须单击的按钮来完成此操作。

最佳答案

这是我找到的最好的解决方案:

http://thereforei.am/2012/07/03/cancelling-subscriptions-created-with-paypal-standard-via-the-express-checkout-api/

/**
 * 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( 'api_username' )
                .  '&PWD=' . urlencode( 'api_password' )
                .  '&SIGNATURE=' . urlencode( 'api_signature' )
                .  '&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;
}

例子:

change_subscription_status( 'I-NARPL1C00000', 'Cancel' );

希望对你有帮助

关于php - 如何使用 php 自动取消订阅用户的 paypal(当他们升级到不同的订阅时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10266987/

相关文章:

php - 扩展 FOSUserBundle 用户实体时的生命周期回调问题

php - 将参数从表单传递到 Controller Laravel

php - 支付宝支付方式

php - 使用新的 REST API 应用程序从经典(IPN 端点)搜索 Paypal 交易

类似 Javascript ||在 PHP 中

PHP:获取引用 ID

PayPal IPN 和 PDT 突然不能用了

powershell - 通过 PowerShell 添加共同管理员

ios - 如何测试自动续订?

ruby-on-rails - 如何取消 Paypal 订阅?