当前位置: 首页>>代码示例>>PHP>>正文


PHP PayPal::refund方法代码示例

本文整理汇总了PHP中PayPal::refund方法的典型用法代码示例。如果您正苦于以下问题:PHP PayPal::refund方法的具体用法?PHP PayPal::refund怎么用?PHP PayPal::refund使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PayPal的用法示例。


在下文中一共展示了PayPal::refund方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: refundCreditCard

 public function refundCreditCard()
 {
     fb('PayPal refund');
     Attempt::setAttemptStatus($this->attemptModel, Attempt::INPROGRESS_STATUS);
     $successAttemptModel = Attempt::getSuccessAttempt($this->orderModel->order_id);
     $successAttemptCustomData = json_decode($successAttemptModel->custom_data, true);
     $options = array('username' => $this->gatewayModel->username, 'password' => $this->gatewayModel->routing_number, 'signature' => $this->gatewayModel->shared_secret);
     $transaction = new PayPal($options);
     if (self::$isTest) {
         $this->campaignModel->currency_id = 'USD';
         $transaction->setIsProduction(false);
     }
     $transaction->set('TRANSACTIONID', $successAttemptCustomData['tracking_number']);
     $transaction->set('AMT', number_format($this->attemptModel->amount, 2));
     $transaction->set('CURRENCYCODE', $this->campaignModel->currency_id);
     $transaction->set('NOTE', 'text');
     $transaction->refund();
     try {
         $response = $transaction->execute();
         fb($response);
     } catch (Exception $e) {
         $aErrors = array('Error processing your request');
         $this->attemptError($aErrors);
         return false;
     }
     if (!is_array($response) || !isset($response['ACK'])) {
         // payment server errors
         $aErrors = array('Error processing your request');
         $this->attemptError($aErrors);
         return false;
     }
     if (in_array($response['ACK'], array(Paypal::STATUS_SUCCESS, Paypal::STATUS_SUCCESS_WITH_WARNING))) {
         $this->attemptModel->status = Attempt::SUCCESS_STATUS;
         $this->_paymetnResponse->status = PaymentAPIResponse::SUCCESS_STATUS;
     } else {
         $this->attemptModel->status = Attempt::DECLINED_STATUS;
         $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS;
     }
     //Save custom data
     $customData = array();
     if (isset($response['TRANSACTIONID'])) {
         $customData['tracking_number'] = $response['REFUNDTRANSACTIONID'];
     }
     if (isset($response['CORRELATIONID'])) {
         $customData['correlation_id'] = $response['CORRELATIONID'];
     }
     if (isset($response['REFUNDSTATUS'])) {
         $customData['refund_status'] = $response['REFUNDSTATUS'];
     }
     if (isset($response['PENDINGREASON'])) {
         $customData['pending_reason'] = $response['PENDINGREASON'];
     }
     //Save status_note
     $errors = array();
     if (isset($response['L_ERRORCODE0'])) {
         $errors[] = 'Code: ' . $response['L_ERRORCODE0'];
     }
     if (isset($response['L_LONGMESSAGE0'])) {
         $errors[] = 'Message: ' . $response['L_LONGMESSAGE0'];
     }
     if ($errors) {
         $this->attemptModel->status_note = implode('. ', $errors);
     }
     $this->attemptModel->save();
     //Set success status to response
     $this->_paymetnResponse->attemptModel = $this->attemptModel;
     $this->_paymetnResponse->paymentModel = $this->paymentModel;
     OrderLog::createLog(0, $this->orderModel->order_id, 13, $this->attemptModel->amount . ' ' . $this->campaignModel->currency_id);
     return true;
 }
开发者ID:,项目名称:,代码行数:70,代码来源:

示例2: PayPal

    $payerid = $f3->get('GET.PayerID');
    // complete the transaction
    $paypal = new PayPal();
    $result = $paypal->complete($token, $payerid);
    if ($result['ACK'] != 'Success' && $result['ACK'] != 'SuccessWithWarning') {
        // Handle API error code
        die('Error with API call - ' . $result["L_ERRORCODE0"]);
    } else {
        // Update back office - save transaction id, payment status etc
        // Display thank you/receipt to the buyer.
        $f3->set('itemcount', 0);
        $f3->set('txnid', $result['PAYMENTINFO_0_TRANSACTIONID']);
        echo \Template::instance()->render('receipt.html');
    }
});
$f3->route('GET /refund', function ($f3) {
    // Get transaction id from URL
    $txnid = $f3->get('GET.txnid');
    // Refund the transaction
    $paypal = new PayPal();
    $result = $paypal->refund($txnid);
    if ($result['ACK'] != 'Success') {
        // Handle API error code
        die('Error with API call - ' . $result["L_ERRORCODE0"]);
    } else {
        echo "<pre>";
        print_r($result);
        echo "</pre>";
    }
});
$f3->run();
开发者ID:kreative,项目名称:f3-pypl,代码行数:31,代码来源:index.php


注:本文中的PayPal::refund方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。