Create Session in PHP

mail@pastecode.io avatar
unknown
php
2 years ago
4.5 kB
2
Indexable
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://checkout-test.placetopay.com/api/session');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n  \"locale\": \"es_CO\",\n  \"auth\": {\n    \"auth\": {\n      \"login\": \"c51ce410c124a10e0db5e4b97fc2af39\",\n      \"tranKey\": \"VQOcRcVH2DfL6Y4B4SaK6yhoH/VOUveZ3xT16OQnvxE=\",\n      \"nonce\": \"NjE0OWVkODgwYjNhNw==\",\n      \"seed\": \"2021-09-21T09:34:48-05:00\"\n    }\n  },\n  \"payer\": {\n    \"document\": \"1122334455\",\n    \"documentType\": \"CC\",\n    \"name\": \"John\",\n    \"surname\": \"Doe\",\n    \"company\": \"Evertec\",\n    \"email\": \"johndoe@app.com\",\n    \"mobile\": \"+5731111111111\",\n    \"address\": {\n      \"street\": \"Calle falsa 123\",\n      \"city\": \"Medellín\",\n      \"state\": \"Poblado\",\n      \"postalCode\": \"55555\",\n      \"country\": \"Colombia\",\n      \"phone\": \"+573111111111\"\n    }\n  },\n  \"buyer\": {\n    \"document\": \"1122334455\",\n    \"documentType\": \"CC\",\n    \"name\": \"John\",\n    \"surname\": \"Doe\",\n    \"company\": \"Evertec\",\n    \"email\": \"johndoe@app.com\",\n    \"mobile\": \"+5731111111111\",\n    \"address\": {\n      \"street\": \"Calle falsa 123\",\n      \"city\": \"Medellín\",\n      \"state\": \"Poblado\",\n      \"postalCode\": \"55555\",\n      \"country\": \"Colombia\",\n      \"phone\": \"+573111111111\"\n    }\n  },\n  \"payment\": {\n    \"reference\": \"12345\",\n    \"description\": \"Prueba de pago\",\n    \"amount\": {\n      \"currency\": \"COP\",\n      \"total\": 2000,\n      \"taxes\": [\n        {\n          \"kind\": \"valueAddedTax\",\n          \"amount\": 1000,\n          \"base\": 0\n        }\n      ],\n      \"details\": [\n        {\n          \"kind\": \"discount\",\n          \"amount\": 1000\n        }\n      ]\n    },\n    \"allowPartial\": false,\n    \"shipping\": {\n      \"document\": \"1122334455\",\n      \"documentType\": \"CC\",\n      \"name\": \"John\",\n      \"surname\": \"Doe\",\n      \"company\": \"Evertec\",\n      \"email\": \"johndoe@app.com\",\n      \"mobile\": \"+5731111111111\",\n      \"address\": {\n        \"street\": \"Calle falsa 123\",\n        \"city\": \"Medellín\",\n        \"state\": \"Poblado\",\n        \"postalCode\": \"55555\",\n        \"country\": \"Colombia\",\n        \"phone\": \"+573111111111\"\n      }\n    },\n    \"items\": [\n      {\n        \"sku\": \"12345\",\n        \"name\": \"product_1\",\n        \"category\": \"physical\",\n        \"qty\": \"1\",\n        \"price\": 1000,\n        \"tax\": 0\n      }\n    ],\n    \"fields\": [\n      {\n        \"keyword\": \"_test_field_value_\",\n        \"value\": \"_test_field_\",\n        \"displayOn\": \"approved\"\n      }\n    ],\n    \"recurring\": {\n      \"periodicity\": \"D\",\n      \"interval\": \"1\",\n      \"nextPayment\": \"2019-08-24\",\n      \"maxPeriods\": 1,\n      \"dueDate \": \"2019-09-24\",\n      \"notificationUrl \": \"https://checkout.placetopay.com\"\n    },\n    \"subscribe\": false,\n    \"dispersion\": [\n      {\n        \"agreement\": \"1299\",\n        \"agreementType\": \"MERCHANT\",\n        \"amount\": {\n          \"currency\": \"USD\",\n          \"total\": 200\n        }\n      }\n    ],\n    \"modifiers\": [\n      {\n        \"type\": \"FEDERAL_GOVERNMENT\",\n        \"code\": 17934,\n        \"additional\": {\n          \"invoice\": \"123345\"\n        }\n      }\n    ]\n  },\n  \"subscription\": {\n    \"reference\": \"12345\",\n    \"description\": \"Ejemplo de descripción\",\n    \"fields\": {\n      \"keyword\": \"1111\",\n      \"value\": \"lastDigits\",\n      \"displayOn\": \"none\"\n    }\n  },\n  \"fields\": [\n    {\n      \"keyword\": \"_processUrl_\",\n      \"value\": \"https://checkout.redirection.test/session/1/a592098e22acc709ec7eb30fc0973060\",\n      \"displayOn\": \"none\"\n    }\n  ],\n  \"paymentMethod\": \"visa\",\n  \"expiration\": \"2019-08-24T14:15:22Z\",\n  \"returnUrl\": \"https://commerce.test/return\",\n  \"cancelUrl\": \"https://commerce.test/cancel\",\n  \"ipAddress\": \"127.0.0.1\",\n  \"userAgent\": \"PlacetoPay Sandbox\",\n  \"skipResult\": false,\n  \"noBuyerFill\": false,\n  \"type\": \"checkin\"\n}");
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);