1

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.com 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

enter image description here

it ok

can someone help me on this. thanks in advance

  • 1
    Your host might firewall off outbound connections by default, or you may need to configure your VM or VPC firewall or similar yourself depending on what your host has. Can you connect to that URL from command-line curl on the machine? – Rup Sep 2 at 9:30
  • hi @Rup $ curl --form "loginname=sang4" --form "charge_type=6" --form "site_id=258" --form "email=your@emailaddresshere.com" --form "firstname=sang4" --form "lastname=sang4" --form "cardnumber=4321432143214321" --form "cardmonth=03" --form "cardyear=2020" --form "cvv=999" --form "currency=JPY" --form "amount[0]=1980" --form "customer_id[0]=1" --form "contents_id[0]=1" --form "contents_name[0]=1" --form "token=2c4b4545a9b80dbac64f490f48cceca4" -X POST api2.something.com:8081/payment2.php – chris lim Sep 3 at 2:32
  • and the output is {"result":{"id":"","transaction":{"amount":"","transaction_id":""},"time":"2019-09-02 19:24:30.400907","status":"Failure","reason":"Input data error<b>\"\"<\/b>"}} – chris lim Sep 3 at 2:37
  • Does your stand-alone PHP script work when run from the server too? If not, I'd guess it's still networking configuration and there's an outbound HTTP proxy that you'll need to use and your shell user has the settings but not your service user. If it does, then it's either WordPress or again the service user: do you have a security plugin that might intercept PHP curl and filter outbound traffic? Are you running with selinux enabled, which might also prevent unexpected outbound connections from the web server process? – Rup Sep 3 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.