admin管理员组

文章数量:1415484

its my first time to create wordpress plugin, my task is to create a payment gateway i study this sample and also did some code on php using cURL here is the code. and it works. now on wordpress when i try this

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

            $boundary = uniqid();
            $delimiter = '-------------' . $boundary;

            $url = $this->server_url;
            $fields = $this->createBody($order_id);
            $post_data = $this->build_data_files($boundary, $fields);

            // create body and header
            $header = array(
              "Content-Type: multipart/form-data; boundary=" . $delimiter,
              "Content-Length: " . strlen($post_data),
              "Accept: */*"
            );

            $args = array(
                'method'  =>  'POST',
                'headers' =>  $header,
                'sslverify' => false,
                'body'    =>  $post_data
              );


            $response = wp_remote_post( $url, $args );
            print_r($args);
            var_dump($response); 
}

i got an error 1. Fixed malformed JSON. Original: checkout.min.js:1 and the dump is:

    Array
(
    [method] => POST
    [headers] => Array
        (
            [0] => Content-Type: multipart/form-data; boundary=-------------5d6cbb175f652
            [1] => Content-Length: 1362
            [2] => Accept: */*
        )

    [sslverify] => 
    [body] => ---------------5d6cbb175f652
Content-Disposition: form-data; name="token"
7d8abe9734d15347bf17e542ced28b14
---------------5d6cbb175f652
Content-Disposition: form-data; name="firstname"
test stripe
---------------5d6cbb175f652
Content-Disposition: form-data; name="lastname"
justlastname
---------------5d6cbb175f652
Content-Disposition: form-data; name="cardnumber"
4321432143214321
---------------5d6cbb175f652
Content-Disposition: form-data; name="cardmonth"
03
---------------5d6cbb175f652
Content-Disposition: form-data; name="cardyear"
2020
---------------5d6cbb175f652
Content-Disposition: form-data; name="cvv"
123
---------------5d6cbb175f652
Content-Disposition: form-data; name="currency"
JPY
---------------5d6cbb175f652
Content-Disposition: form-data; name="customer_id[0]"
1
---------------5d6cbb175f652
Content-Disposition: form-data; name="contents_id[0]"
1
---------------5d6cbb175f652
Content-Disposition: form-data; name="contents_name[0]"
1
---------------5d6cbb175f652
Content-Disposition: form-data; name="amount[0]"
150.00
---------------5d6cbb175f652
Content-Disposition: form-data; name="loginname"
sang4
---------------5d6cbb175f652
Content-Disposition: form-data; name="charge_type"
6
---------------5d6cbb175f652
Content-Disposition: form-data; name="site_id"
258
---------------5d6cbb175f652--

)
object(WP_Error)#3406 (2) {
  ["errors"]=>
  array(1) {
    ["http_request_failed"]=>
    array(1) {
      [0]=>
      string(87) "cURL error 7: Failed to connect to api2.some-company port 8081: Connection refused"
    }
  }
  ["error_data"]=>
  array(0) {
  }
}
{"result":"failure","messages":"<ul class=\"woocommerce-error\" role=\"alert\">\n\t\t\t<li>\n\t\t\tConnection error.\t\t<\/li>\n\t<\/ul>\n","refresh":false,"reload":false}

but on insomia

it ok

can someone help me on this. thanks in advance

本文标签: pluginscustom payment gateway in woocommerce failed to connect to remote api server