74 lines
3.3 KiB
PHP
Executable File
74 lines
3.3 KiB
PHP
Executable File
<?php
|
|
use GuzzleHttp\Client;
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
// $baseUri = 'https://172.16.5.120/crm/api/v1.0/'; //endpoint de la API REST del CRM
|
|
// $token = '3d5fa4c9-e134-4e8b-b8d7-aae394d48d4d'; //Token para acceder a los recursos del CRM
|
|
$baseUri = 'https://172.16.5.134/crm/api/v1.0/'; //endpoint de la API REST del CRM
|
|
$token = '6abef18c-783d-4dd0-b530-be6e6a7bbd1d'; //Token para acceder a los recursos del CRM
|
|
|
|
$stripe = new \Stripe\StripeClient('sk_test_51OkG0REFY1WEUtgRH6UxBK5pu80Aq5Iy8EcdPnf0cOWzuVLQTpyLCd7CbPzqMsWMafZOHElCxhEHF7g8boURjWlJ00tBwE0W1M'); //Token de clave privada en modo prueba para la API de Stripe
|
|
//$stripe = new \Stripe\StripeClient('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'); //Token de clave privada en modo prodcucción para la API de Stripe
|
|
|
|
//cliente GuzzleHttp para consumir API del UISP CRM
|
|
$clientGuzzleHttp = new Client([
|
|
'base_uri' => $baseUri,
|
|
'headers' => [
|
|
'X-Auth-App-Key' => $token,
|
|
'Accept' => 'application/json',
|
|
],
|
|
'verify' => false,
|
|
]);
|
|
|
|
// Obtén el contenido del cuerpo de la solicitud
|
|
$input = @file_get_contents('php://input');
|
|
$event_json = json_decode($input);
|
|
$cadena = json_encode($event_json);
|
|
file_put_contents(__DIR__ . '/logsiip.log', "[" . date('Y-m-d H:i:s') . "] " . "Valor json: ".$cadena.PHP_EOL);
|
|
// Maneja el evento del webhook
|
|
if ($event_json) {
|
|
switch ($event_json->type) {
|
|
case 'cash_balance.funds_available':
|
|
$customer = $event_json->data->object;
|
|
$customerId = $customer->id;
|
|
$newBalance = $customer->balance; // El nuevo saldo del cliente
|
|
|
|
|
|
|
|
|
|
try {// Aquí puedes crear un nuevo PaymentIntent o un Cargo (Charge) usando el nuevo saldo
|
|
$paymentIntent = \Stripe\PaymentIntent::create([
|
|
'amount' => 30000,
|
|
'currency' => 'mxn',
|
|
'customer' => $customerId,
|
|
'payment_method_types' => ['customer_balance'],
|
|
'payment_method_data' => ['type' => 'customer_balance'],
|
|
'confirm' => true,
|
|
'payment_method_options' => [
|
|
'customer_balance' => [
|
|
'funding_type' => 'bank_transfer',
|
|
'bank_transfer' => ['type' => 'mx_bank_transfer']
|
|
],
|
|
],
|
|
'metadata' => [
|
|
'clientId' => $customerId, // ID del cliente en Ubiquiti
|
|
'createdBy' => 'UCRM', // ID de la factura en Ubiquiti
|
|
'paymentType' => 'card.one_time',
|
|
'signedInAdminId' => 1015,
|
|
],
|
|
]);
|
|
file_put_contents(__DIR__ . '/logsiip.log', "[" . date('Y-m-d H:i:s') . "] " . "PaymentIntent creado: " . $paymentIntent->id . PHP_EOL, FILE_APPEND);
|
|
|
|
|
|
|
|
} catch (\Stripe\Exception\ApiErrorException $e) {
|
|
file_put_contents(__DIR__ . '/logsiip.log', "[" . date('Y-m-d H:i:s') . "] " ."Error creando PaymentIntent: " . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
|
}
|
|
break;
|
|
// Otros eventos relevantes
|
|
}
|
|
}
|
|
|
|
http_response_code(200); // Responde con un 200 OK a Stripe
|