Beispiel #1
0
 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;
 }
Beispiel #2
0
    $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();