?
| Current Path : /home/webyoo/www/leumi/site/ |
| Current File : /home/webyoo/www/leumi/site/paypal_create_plan.php |
<?php
// =====================================================================
// OUTIL À USAGE UNIQUE — Crée le Product + le Plan d'abonnement PayPal
// (99 ILS / mois) et affiche le plan_id à copier dans agent-subscribe.php
//
// âš ï¸ APRÈS AVOIR RÉCUPÉRÉ LE plan_id : SUPPRIME ce fichier du serveur
// (il contient ton secret PayPal).
// =====================================================================
// ---- 1) À REMPLIR ----------------------------------------------------
$MODE = 'sandbox'; // 'sandbox' (test) puis 'live' (réel)
$CLIENT_ID = 'REMPLACER_CLIENT_ID';
$SECRET = 'REMPLACER_SECRET';
$PLAN_NAME = '×ž× ×•×™ מתווך ×שכרה'; // nom affiché
$PRICE = '99'; // montant
$CURRENCY = 'ILS'; // devise
// ---------------------------------------------------------------------
$BASE = ($MODE === 'live') ? 'https://api-m.paypal.com' : 'https://api-m.sandbox.paypal.com';
header('Content-Type: text/html; charset=utf-8');
echo "<pre style='font:14px/1.6 monospace;direction:ltr;text-align:left;padding:20px'>";
echo "Mode : $MODE\nBase : $BASE\n\n";
function pp_call($url, $headers, $body = null, $basic = null) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
if ($basic !== null) { curl_setopt($ch, CURLOPT_USERPWD, $basic); }
if ($body !== null) { curl_setopt($ch, CURLOPT_POSTFIELDS, $body); }
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$resp = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err = curl_error($ch);
curl_close($ch);
return array($code, $resp, $err);
}
if ($CLIENT_ID === 'REMPLACER_CLIENT_ID' || $SECRET === 'REMPLACER_SECRET') {
exit("⌠Remplis d'abord \$CLIENT_ID et \$SECRET en haut du fichier.\n");
}
// ---- 2) Token OAuth ----
list($code, $resp) = pp_call(
"$BASE/v1/oauth2/token",
array('Accept: application/json'),
'grant_type=client_credentials',
$CLIENT_ID . ':' . $SECRET
);
$tok = json_decode($resp, true);
if ($code !== 200 || empty($tok['access_token'])) {
exit("⌠Échec du token (HTTP $code) :\n$resp\n");
}
$access = $tok['access_token'];
echo "✅ Token OK\n";
$authHeaders = array(
'Content-Type: application/json',
'Authorization: Bearer ' . $access
);
// ---- 3) Product ----
$productBody = json_encode(array(
'name' => 'Ashkara - Abonnement Metavekh',
'type' => 'SERVICE',
'category' => 'SOFTWARE'
));
list($code, $resp) = pp_call("$BASE/v1/catalogs/products", $authHeaders, $productBody);
$prod = json_decode($resp, true);
if (($code !== 201 && $code !== 200) || empty($prod['id'])) {
exit("⌠Échec création product (HTTP $code) :\n$resp\n");
}
$productId = $prod['id'];
echo "✅ Product créé : $productId\n";
// ---- 4) Plan (mensuel, montant fixe, renouvellement infini) ----
$planBody = json_encode(array(
'product_id' => $productId,
'name' => $PLAN_NAME,
'status' => 'ACTIVE',
'billing_cycles' => array(array(
'frequency' => array('interval_unit' => 'MONTH', 'interval_count' => 1),
'tenure_type' => 'REGULAR',
'sequence' => 1,
'total_cycles' => 0, // 0 = infini (jusqu'Ã annulation)
'pricing_scheme' => array(
'fixed_price' => array('value' => $PRICE, 'currency_code' => $CURRENCY)
)
)),
'payment_preferences' => array(
'auto_bill_outstanding' => true,
'setup_fee' => array('value' => '0', 'currency_code' => $CURRENCY),
'setup_fee_failure_action' => 'CONTINUE',
'payment_failure_threshold' => 1
)
), JSON_UNESCAPED_UNICODE);
list($code, $resp) = pp_call("$BASE/v1/billing/plans", $authHeaders, $planBody);
$plan = json_decode($resp, true);
if (($code !== 201 && $code !== 200) || empty($plan['id'])) {
exit("⌠Échec création plan (HTTP $code) :\n$resp\n");
}
$planId = $plan['id'];
echo "\n=====================================================\n";
echo "🎉 SUCCÈS !\n";
echo " PRODUCT ID : $productId\n";
echo " PLAN ID : $planId\n";
echo "=====================================================\n\n";
echo "âž¡ï¸ Copie ce PLAN ID dans agent-subscribe.php :\n";
echo " \$PAYPAL_PLAN_ID = '$planId';\n";
echo " \$PAYPAL_CLIENT_ID = '$CLIENT_ID';\n\n";
echo "âš ï¸ SUPPRIME ensuite ce fichier (paypal_create_plan.php) du serveur.\n";
echo "</pre>";