Woocommerce:我下订单使用银行API处理付款时出现运行时错误

时间:2018-11-26 12:25:02

标签: php wordpress woocommerce

我将带有woocommerce的亚美尼亚银行API用作额外的付款方式。当我下订单时,它给我运行时错误。我要附加图像或收到的错误以及正在使用的代码。


        id = 'ameriabank'; // payment gateway plugin ID
        $this->icon = ''; // URL of the icon that will be displayed on checkout page near your gateway name
        $this->has_fields = true; // in case you need a custom credit card form
        $this->method_title = 'Ameria Bank Gateway';
        $this->method_description = 'Description of Ameria payment gateway'; 


        $this->supports = array(
            'products',
          'subscriptions'
        );

        // Method with all the options fields
        $this->init_form_fields();

        // Load the settings.
        $this->init_settings();
        $this->title = $this->get_option( 'title' );
        $this->description = $this->get_option( 'description' );
        $this->enabled = $this->get_option( 'enabled' );
        //$this->testmode = 'yes' === $this->get_option( 'testmode' );
        $this->ClientID = $this->get_option( 'ClientID' );
        $this->Username = $this->get_option( 'Username' );
        $this->Password = $this->get_option( 'Password' );


        // This action hook saves the settings
        add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );

        // We need custom JavaScript to obtain a token
        //add_action( 'wp_enqueue_scripts', array( $this, 'payment_scripts' ) );

        // You can also register a webhook here
        // add_action( 'woocommerce_api_{webhook name}', array( $this, 'webhook' ) );

            }

            /**
             * Plugin options, we deal with it in Step 3 too
             */
         public function init_form_fields(){

        $this->form_fields = array(
            'enabled' => array(
                'title'       => 'Enable/Disable',
                'label'       => 'Enable AmeriaBank Gateway',
                'type'        => 'checkbox',
                'description' => '',
                'default'     => 'no'
            ),
            'title' => array(
                'title'       => 'Title',
                'type'        => 'text',
                'description' => 'This controls the title which the user sees during checkout.',
                'default'     => 'Credit Card',
                'desc_tip'    => true,
            ),
            'description' => array(
                'title'       => 'Description',
                'type'        => 'textarea',
                'description' => 'This controls the description which the user sees during checkout.',
                'default'     => 'Pay with your credit card via our super-cool payment gateway.',
            ),
            'ClientID' => array(
                'title'       => 'Client ID',
                'type'        => 'text'
            ),
            'Username' => array(
                'title'       => 'Username',
                'type'        => 'text'
            ),
        'Password' => array(
                'title'       => 'Password',
                'type'        => 'text'
            )
        );
     }

     public function process_payment( $order_id ) {
         global $woocommerce;


         $order = new WC_Order( $order_id );
         // Ameria bank params

         $this->description = "[description]";
         $this->orderID = $order_id;
         $this->paymentAmount = $order->get_total();
         $_SESSION['eli_cart_total'] = $this->paymentAmount;
         $this->backURL = add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(woocommerce_get_page_id('thanks'))));


         $options = array(
                 'soap_version'    => SOAP_1_1,
                 'exceptions'      => true,
                 'trace'           => 1,
                 'wdsl_local_copy' => true
                 );

         $client = new SoapClient("https://testpayments.ameriabank.am/webservice/PaymentService.svc?wsdl", $options);

         $args['paymentfields'] = array(
                 'ClientID' => $this->ClientID,
                 'Username' => $this->Username,
                 'Password' => $this->Password,
                 'Description' => $this->description,
                 'OrderID' => $this->orderID,
                 'PaymentAmount' => $this->paymentAmount,
                 'backURL' => $this->backURL
             );

         $webService = $client->GetPaymentID($args);


         $_SESSION['pid'] = $webService->GetPaymentIDResult->PaymentID;
         $this->liveurl = 'https://testpayments.ameriabank.am/forms/frm_paymentstype.aspx?clientid='.$this->ClientID.'&clienturl='.$this->backURL.'&lang=am&paymentid='.$webService->GetPaymentIDResult->PaymentID;

         // Return thankyou redirect
         return array(
             'result'    => 'success',
             'redirect'  => $this->liveurl
         );

     }

     /**
      * Output for the order received page.
      *
      * @access public
      * @return void
      */
     function thankyou_page($order_id) {
         global $woocommerce;
         $options = array(
                 'soap_version'    => SOAP_1_1,
                 'exceptions'      => true,
                 'trace'           => 1,
                 'wdsl_local_copy' => true
                 );

         $client = new SoapClient("https://testpayments.ameriabank.am/webservice/PaymentService.svc?wsdl", $options);
         $total = $_SESSION['eli_cart_total'];
         $args['paymentfields'] = array(
                 'ClientID' => $this->ClientID,
                 'Username' => $this->Username,
                 'Password' => $this->Password,
                 'PaymentAmount' => $total,
                 'OrderID' => $order_id
             );
         $webService = $client->GetPaymentFields($args);

         if($webService->GetPaymentFieldsResult->respcode == "00") {
             $order = new WC_Order( $order_id );
                 $type = $webService->GetPaymentFieldsResult->paymenttype;
                 if( $type == "1" ) {
                     $client->Confirmation($args);
                 }

                 $order->update_status('on-hold', __( 'Awaiting credit card payment', 'woocommerce' ));
                 // Reduce stock levels
                 $order->reduce_order_stock();

                 // Remove cart
                 $woocommerce->cart->empty_cart();

         } else {
             //echo '';
         }
     }

    }

}

错误屏幕截图: enter image description here

让我知道是否有人可以帮助我。

1 个答案:

答案 0 :(得分:0)

问题出在this->backURL中,因为它有/,因此服务器感觉就像要转到/另一个资源,因此您需要使用urlencode(this->backURL)对其进行编码