0

I'm using Armenian bank API with woocommerce as extra payment method. When I place order it gives me Runtime error. I'm attaching the image or the error I receive and the code I am using.

        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 '';
         }
     }

    }

}

Error Screenshot: enter image description here

Let me know if someone can help me on this.

1
  • That looks like a problem with the bank's API, I suggest you contact them. Commented Nov 26, 2018 at 12:27

1 Answer 1

0

The problem was in this->backURL because it has / so the server feel like go to /another resource so you need to encode it using urlencode(this->backURL)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.