gpt4 book ai didi

php - 如何在没有 PayPal 账户的情况下取消 PayPal 订阅?

转载 作者:太空宇宙 更新时间:2023-11-03 15:59:49 24 4
gpt4 key购买 nike

我当前的项目允许用户在不注册 paypal 帐户的情况下订阅成员(member)资格。

用户的用户名和密码由我自己的应用程序而非 PayPal 创建和管理。

谁能告诉我如何创建一个可以取消该订阅的 HTML 表单?我可以通过发送 txn_id 来取消订阅吗??

我相信我可以使用 IPN 捕获此信息。

我还应该提一下,我是一名 DBA 而不是真正的开发人员,所以如果我有点新手,请多多包涵。

提前致谢。

最佳答案

这是我最终做的事情。

<?php
require 'core/init.php';
require 'core/conn.php';
/*The paypal_transactions table is a table I'm using to store the IPN data. This is necessary to capture the Profile_ID/Subscr_ID. The Custom parameter is being used to pass the username.*/

$profileid_sql = "select subscr_id from paypal_transactions where custom ='". escape($user->data()->username)."'";
$result=mysql_query($profileid_sql);

while($row=mysql_fetch_array($result)){
$profileid = $row['subscr_id'];
}


include 'functions/change_subscription_status.php';
change_subscription_status( $profileid, 'Cancel' );
header('Location: Cancelled.php');
?>

change_subscription_status 函数在这里...

<?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( '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;
}
?>

关于php - 如何在没有 PayPal 账户的情况下取消 PayPal 订阅?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33271948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com