I am playing with a payment system around, which uses json. In result the user gets redirected to the checkout page. The PHP response in the end is something like this:
JSON:
{
"id": 150,
"full_page_checkout": "https://swipe.lv/client/payment/979ffe8e8e74dfcce30c517aca07a5f848ddf8bf2e079080f8b623a2e59afdd8/full_page/",
"iframe_checkout": "https://swipe.lv/client/payment/979ffe8e8e74dfcce30c517aca07a5f848ddf8bf2e079080f8b623a2e59afdd8/iframe/",
"errors": [],
"timestamp": 1447668000
}
My code lookes like this:
PHP:
session_start();
$name = $_POST['name'];
$email= $_POST['email'];
$tel = $_POST['tel'];
$adress = $_POST['adress'];
$city = $_POST['city'];
$plz = $_POST['plz'];
$how = $_POST['howtext'];
$quantity = $_POST['quantity'];
$dispatch = $_POST['dispatch'];
$payment = $_POST['payment'];
$price = $_POST['pricevalue'];
$comment = $_POST['comment'];
$public_key = '4838026a073b766840dbae4c2c5cbfab';
$private_key = '0000000000000000000000000000000000000000000000000000000';
$timestamp = (string)time();
$params = json_encode(array(
'client' => array('email' => 'email@email.com'),
'products' => array(
array(
'description' => 'Standard Cube',
'price' => 20.45,
'quantity' => 1
),
)
)
);
$authorization_message = $timestamp.' POST /api/v0.5/payments/ '.$params;
$authorization = hash_hmac('sha256', $authorization_message, $private_key);
$authorization_header = $public_key.','.$timestamp.','.$authorization;
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\nAuthorization: ".$authorization_header,
'method' => 'POST',
'content' => $params,
'ignore_errors' => true
),
);
$context = stream_context_create($options);
$result = file_get_contents('https://swipe.lv/api/v0.5/payments/ ', false, $context);
$link = substr($result,37,110);
echo json_encode($link);
To execute the link, I used a solution like this:
$link = substr($result,37,110);
echo json_encode($link);
Since the json changes depending on the values, I can't use the substr
function. What I want to do is convert the jason into an array and than echo the value of "full_page_checkout"
How can I achieve this?
EDIT:
By using json_decode and echoing the result, I get just Object : object
as result