[
'type' => 'payment-invoices',
'attributes' => [
'reference_id' => "beautyetc_{$id}",
'service' => 'payment_card_usd_hpp',
'currency' => 'USD',
/*'service' => 'payment_card_uah_hpp',
'currency' => 'UAH',*/
'amount' => 10,
'description' => "",
'customer' => [
'reference_id' => "beautyetc_{$id}",
'name' => $data['Name'],
'email' => $data['Email'],
],
'metadata' => [
'status_id' => $data['status_id']
],
'gateway_options' => [
'cardgate' => [
'theme_options' => [
'locale' => 'ru'
]
]
],
'return_urls' => [
'success' => "{$SITE_URL}thank.html",
'fail' => "{$SITE_URL}error.html"
],
]
]
];
if(isset($data['tildaspec-phone-part[]']) && $data['tildaspec-phone-part[]']){
$requestData['data']['attributes']['customer']['phone'] = $data['tildaspec-phone-part[]'];
}
if(isset($data['Количество вебинаров']) && $data['Количество вебинаров']){
$requestData['data']['attributes']['metadata']['Количество вебинаров'] = $data['Количество вебинаров'];
}
try {
$payload = json_encode($requestData);
$ch = curl_init('https://api.payelata.com/payment-invoices');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Accept: application/json',
'Content-Length: ' . strlen($payload),
'Authorization: Basic ' . base64_encode('coma_z2GbCkCsuUTVJMya:zTM3dg2rxZncpQJXutXkQTDQGOVe-m1pFnpm5kD3abk')
]
);
$result = json_decode(curl_exec($ch));
curl_close($ch);
header('Location: ' . $result->data->attributes->flow_data->action);
} catch (Exception $exception) {
header("Location: {$SITE_URL}error.html");
}