コード例 #1
0
 /**
  * Process a refund if supported
  * @param  int $order_id
  * @param  float $amount
  * @param  string $reason
  * @return  bool|wp_error True or false based on success, or a WP_Error object
  */
 public function process_refund($order_id, $amount = null, $reason = '')
 {
     do_action('angelleye_before_fc_refund', $order_id, $amount, $reason);
     $order = wc_get_order($order_id);
     $this->add_log('Begin Refund');
     $this->add_log('Order: ' . print_r($order, true));
     $this->add_log('Transaction ID: ' . print_r($order->get_transaction_id(), true));
     if (!$order || !$order->get_transaction_id() || !$this->paypal_user || !$this->paypal_password || !$this->paypal_vendor) {
         return false;
     }
     /*
      * Check if the PayPal_PayFlow class has already been established.
      */
     if (!class_exists('Angelleye_PayPal_PayFlow')) {
         require_once 'lib/angelleye/paypal-php-library/includes/paypal.class.php';
         require_once 'lib/angelleye/paypal-php-library/includes/paypal.payflow.class.php';
     }
     /**
      * Create PayPal_PayFlow object.
      */
     $PayPalConfig = array('Sandbox' => $this->testmode == 'yes' ? true : false, 'APIUsername' => $this->paypal_user, 'APIPassword' => trim($this->paypal_password), 'APIVendor' => $this->paypal_vendor, 'APIPartner' => $this->paypal_partner);
     $PayPal = new Angelleye_PayPal_PayFlow($PayPalConfig);
     $PayPalRequestData = array('TENDER' => 'C', 'TRXTYPE' => 'C', 'ORIGID' => $order->get_transaction_id(), 'AMT' => $amount, 'CURRENCY' => $order->get_order_currency());
     $this->add_log('Refund Request: ' . print_r($PayPalRequestData, true));
     $PayPalResult = $PayPal->ProcessTransaction($PayPalRequestData);
     /**
      *  cURL Error Handling #146 
      *  @since    1.1.8
      */
     AngellEYE_Gateway_Paypal::angelleye_paypal_for_woocommerce_curl_error_handler($PayPalResult, $methos_name = 'Refund Request', $gateway = 'PayPal Payments Pro 2.0 (PayFlow)', $this->error_email_notify);
     $this->add_log('Refund Information: ' . print_r($PayPalResult, true));
     add_action('angelleye_after_refund', $PayPalResult, $order, $amount, $reason);
     if (isset($PayPalResult['RESULT']) && ($PayPalResult['RESULT'] == 0 || $PayPalResult['RESULT'] == 126)) {
         $order->add_order_note('Refund Transaction ID:' . $PayPalResult['PNREF']);
         $max_remaining_refund = wc_format_decimal($order->get_total() - $order->get_total_refunded());
         if (!$max_remaining_refund > 0) {
             $order->update_status('refunded');
         }
         if (ob_get_length()) {
             ob_end_clean();
         }
         return true;
     } else {
         $fc_refund_error = apply_filters('ae_pppf_refund_error_message', $PayPalResult['RESPMSG'], $PayPalResult);
         return new WP_Error('paypal-error', $fc_refund_error);
     }
     return false;
 }
 /**
  * Process a refund if supported
  * @param  int $order_id
  * @param  float $amount
  * @param  string $reason
  * @return  bool|wp_error True or false based on success, or a WP_Error object
  */
 public function process_refund($order_id, $amount = null, $reason = '')
 {
     $order = wc_get_order($order_id);
     $this->add_log('Begin Refund');
     $this->add_log('Order: ' . print_r($order, true));
     $this->add_log('Transaction ID: ' . print_r($order->get_transaction_id(), true));
     if (!$order || !$order->get_transaction_id() || !$this->paypal_user || !$this->paypal_password || !$this->paypal_vendor) {
         return false;
     }
     /*
      * Check if the PayPal_PayFlow class has already been established.
      */
     if (!class_exists('PayPal_PayFlow')) {
         require_once 'lib/angelleye/paypal-php-library/includes/paypal.class.php';
         require_once 'lib/angelleye/paypal-php-library/includes/paypal.payflow.class.php';
     }
     /**
      * Create PayPal_PayFlow object.
      */
     $PayPalConfig = array('Sandbox' => $this->testmode == 'yes' ? true : false, 'APIUsername' => $this->paypal_user, 'APIPassword' => trim($this->paypal_password), 'APIVendor' => $this->paypal_vendor, 'APIPartner' => $this->paypal_partner);
     $PayPal = new Angelleye_PayPal_PayFlow($PayPalConfig);
     $PayPalRequestData = array('TENDER' => 'C', 'TRXTYPE' => 'C', 'ORIGID' => $order->get_transaction_id(), 'AMT' => $amount, 'CURRENCY' => $order->get_order_currency());
     $this->add_log('Refund Request: ' . print_r($PayPalRequestData, true));
     $PayPalResult = $PayPal->ProcessTransaction($PayPalRequestData);
     $this->add_log('Refund Information: ' . print_r($PayPalResult, true));
     if (isset($PayPalResult['RESULT']) && ($PayPalResult['RESULT'] == 0 || $PayPalResult['RESULT'] == 126)) {
         $order->update_status('refunded');
         return true;
     } else {
         return new WP_Error('paypal-error', $PayPalResult['RESPMSG']);
     }
     return false;
 }