如何通过PayPal的API取消定期付款,并在我的网站上获得即时通知 使用IPN



我希望用户可以通过Paypal的API取消经常性付款,并使用Paypal的IPN来获得即时通知。如何实现即时通知。

我使用以下代码来取消定期付款:-

$cancel_payment = change_subscription_status($paypal_profile, 'Cancel');

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' );
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;
 }

我强烈建议您阅读IPN文档,以便完全熟悉它。

在大多数情况下,你可以在API调用中定义一个IPN URL,但是,使用循环支付是行不通的。您需要确保在您的PayPal帐户配置文件中配置了它。

最新更新