如何设置取消Paypal定期付款的API?

时间:2017-01-20 02:22:50

标签: php paypal

我想在我的网站上为客户提供取消定期Paypal订阅的选项。我有代码,但调用该函数时它无法正常工作。

function change_subscription_status($subID) {
    $api_request = 'USER=' . urlencode( 'api_user' )
                .  '&PWD=' . urlencode( 'api_pass' )
                .  '&SIGNATURE=' . urlencode( 'api_sig' )
                .  '&VERSION=124.0'
                .  '&METHOD=ManageRecurringPaymentsProfileStatus'
                .  '&PROFILEID=' . urlencode( $subID )
                .  '&ACTION=' . urlencode( 'Cancel' )
                .  '&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 );
}

0 个答案:

没有答案