php - 取消订阅每月定期付款?

标签 php paypal cakephp-2.0 payment-gateway payment

我正在使用 cakephp 2.0 框架。任何人都可以帮助我我在这里做错了什么我有退订功能 enter image description here

 public function unsubscribe() {
    if(isset($_POST['user_id']) && !empty($_POST['user_id'])){
        $this->loadModel('PaypalSinglePayment');
        $this->loadModel('PaypalRecurringPayment');
        $userDetails = $this->PaypalSinglePayment->find('first', array(
            'conditions'=> array(
                'user_id'=>$_POST['user_id'],
                'payment_type'=>"Month"
                )
            )
        );            
        if(!empty($userDetails))
        {            
            $profile_id=urlencode($userDetails['PaypalSinglePayment']['subscriber_id']);            
            $profileID=urlencode($profile_id);
            $action = urlencode('Cancel');
            $nvpStr="&PROFILEID=$profileID&ACTION=$action"; 
            $paypal = new PaypalPro(['live'=>1]);
            $resArray=$paypal->hashCall("ManageRecurringPaymentsProfileStatus",$nvpStr);
            $ack = strtoupper((string)$resArray["ACK"]); 
            if($ack=="SUCCESS"){ 
            $this->PaypalSinglePayment->id = $userDetails['PaypalSinglePayment']['id'];
            $data['payment_status'] = "Cancel";

            if($this->PaypalSinglePayment->save($data)){
              echo json_encode(array(
                          'status'=>'Success',
                          'responseCode'=>1
                       ) 
                   );
              die;
            }
            }
            else{
              echo json_encode( array('msg' => 'Something went wrong, please try again','status'=>'Error Occured','responseCode'=>0) );
              die;
            }             
        }
    }
    echo json_encode( array('msg' => 'Something went wrong, please try again','status'=>'Error Occured','responseCode'=>0) );
    die;
} 

当我在 Unscubscribe 函数中发送 user_id 时,它会转到其他条件,我已成功获得 subscriber_id。谁能帮我我做错了什么 这是 hashcallFunction

enter code here
public function hashCall($methodName,$nvpStr){
    // form header string
    $nvpheader = $this->nvpHeader();

    //setting the curl parameters.
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$this->apiEndpoint);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);

    //turning off the server and peer verification(TrustManager Concept).
    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);

    //in case of permission APIs send headers as HTTPheders
    if(!empty($this->authToken) && !empty($this->authSignature) && !empty($this->authTimestamp))
     {
        $headers_array[] = "X-PP-AUTHORIZATION: ".$nvpheader;
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_array);
        curl_setopt($ch, CURLOPT_HEADER, false);
    }
    else 
    {
        $nvpStr = $nvpheader.$nvpStr;
    }
    //if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
   //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php 
    if($this->useProxy)
        curl_setopt ($ch, CURLOPT_PROXY, $this->proxyHost.":".$this->proxyPort); 

    //check if version is included in $nvpStr else include the version.
    if(strlen(str_replace('VERSION=', '', strtoupper($nvpStr))) == strlen($nvpStr)) {
        $nvpStr = "&VERSION=" . urlencode($this->version) . $nvpStr;    
    }

    $nvpreq="METHOD=".urlencode($methodName).$nvpStr;
    //setting the nvpreq as POST FIELD to curl
    curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);

    //getting response from server
    $response = curl_exec($ch);

    //convrting NVPResponse to an Associative Array
    $nvpResArray = $this->deformatNVP($response);
    $nvpReqArray = $this->deformatNVP($nvpreq);
    $_SESSION['nvpReqArray']=$nvpReqArray;

    if (curl_errno($ch)) {
        die("CURL send a error during perform operation: ".curl_error($ch));
    } else {
        //closing the curl
        curl_close($ch);
    }

    return $nvpResArray;
}

最佳答案

您在 paypal_single_payments 表中可能没有任何 user_id=24 且 payment_type = "Month"的记录。 您也可以尝试调试 $_POST 和 $userDetails 的内容 变量以查看它们是否不为空。 我同意 SrQ 的观点,您应该使用 Cake 的数据结构和 $this->request->data 来访问 post 变量。

关于php - 取消订阅每月定期付款?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41359237/

相关文章:

php - 如何检查MySql字段是否等于1?

PHP 内存不足,但仅在一个系统上

php - WordPress 在主题支持中检索缩略图

php - 如何通过 Accept : application json header in call, 发布请求 Laravel 5.1

paypal - 如何在 Paypal 中重定向到 "Pay with a credit card"

android - 适用于 Android 的替代应用内购买方法

Magento 1.9.1 PayPal Express 评论页面为空

php - CakePHP 中的 requestAction 性能

cakephp - 在 Cakephp 中使用 $this->Auth 获取关联模型

php - 如何使用 xml 标签一次使用 'file_get_contents' 保存多个图像