0

I have integrated the Wepay payment gateway. But I have facing a problem to pass json object to wepay. It always shows a incorrect json format. Please look at the below code.

$forca_a = array(
  'debit_opt_in'=>true
);
$forca = json_encode($forca_a,JSON_FORCE_OBJECT);
$wepay_create_array = array(
  'name' =>"xxxx",
  'description' => "xxxxxxxxx xxxx",
  'callback_uri' => "xxxxxxx",
  'country' => "CA",
  'currencies' => array('CAD'),
  'country_options' => $forca,
  'rbits'=> array(
               array(
                  'receive_time'=>strtotime("now"),
                  'type' =>'website_uri',
                  'source' => 'partner_database',
                  'properties'=> array('uri'=>xxxxx)
               )
            )
);

If I won't pass the country_options, its seems to working but If I pass this parameter, it always give me an error says "Incorrect JSON format".

I sent an email to wepay help center. They told me that, you are passing the string "country_options":"{"debit_opt_in":true}" <--- this is a string Instead of "country_options":{"debit_opt_in":true} <--- this is a JSON object. So I'm confused. I have no idea how do I pass the JSON object. There is only way and is json_encode($object).

2 Answers 2

0

hey use below code to get proper json

<?php
$forca_a = array(
                  'debit_opt_in'=>true
           );
    // $forca = json_encode($forca_a);
    $wepay_create_array = array(
                  'name' =>"xxxx",
                  'description' => "xxxxxxxxx xxxx",
                  'callback_uri' => "xxxxxxx",
                  'country' => "CA",
                  'currencies' => array('CAD'),
                  'country_options' => $forca_a,
                  'rbits'=> array(
                               array(
                                  'receive_time'=>strtotime("now"),
                                  'type' =>'website_uri',
                                  'source' => 'partner_database',
                                  'properties'=> array('uri'=>'xxxxx')
                               )
                            )
                  );


print_r(json_encode($wepay_create_array));
                  ?>

this code will give following json output

{
        "name": "xxxx",
        "description": "xxxxxxxxx xxxx",
        "callback_uri": "xxxxxxx",
        "country": "CA",
        "currencies": ["CAD"],
        "country_options": {
            "debit_opt_in": true
        },
        "rbits": [{
            "receive_time": 1461561030,
            "type": "website_uri",
            "source": "partner_database",
            "properties": {
                "uri": "xxxxx"
            }
        }]
    }
Sign up to request clarification or add additional context in comments.

2 Comments

wepay.com/developer/reference/account#create. Please look this link. I just need to pass 'country_options' into json object, not the whole array.
Actually fixed it now. look my comment on above answer.
0

You have no need to make:

$forca = json_encode($forca_a,JSON_FORCE_OBJECT);

before you put it to $wepay_create_array. Before sending request, i think, you make json_encode($wepay_create_array), and yes, after that you will have 'string' for country_options key.

3 Comments

wepay.com/developer/reference/account#create. Please look this link. I just need to pass 'country_options' into json object, not the whole array.
See the difference between jsonObject and jsonArray in this answer: stackoverflow.com/a/16145788/5686207 You just have no need json_encode($forca) before pass it to the main request array.
Thank you anyway but I just passed the array and it seems to be working. Strange! In the above my code I just removed the json_encode and pass the array of the country_options and it's working for me. May be something coded in the libraries. By the way thanks for valuable effort.

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.