probleme de passage de sandbox au mode live
evrard1313
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Sep-28-2019
09:52 AM
Bonjour a tous, Voila je rencontre un petit problème avec mon code lors du passage de sandbox en mode live. En effet ayant change mon Client ID et mon Secret il ne marche toujours pas et ma page https://thelockedfile.com/payment.php est tout toute blanche comme si le code se refuse d'etre execute. Par contre ces memes codes fonctionnent sans aucun probleme en mode Sandbox. Voici mes differents codes :
subscribe.php
<?php
require 'inc/secret_header.php';
require 'inc/function.php';
require_once 'inc/db.php';
require 'inc/Offer.php';
logged_only();
if (isset($_POST['offer'])){
$_SESSION['offer_key'] = $_POST['offer'];
header('location: payment.php');
}
?>
<h3>S'abonner</h3>
<form action="" method="post" class="user">
<ul>
<?php foreach (Offer::getoffers() as $k => $offer😞 ?>
<li><input type="radio" name="offer" value="<?= $k; ?>"><?= $offer['name']; ?> = <?= $offer['price_text']; ?></li>
<?php endforeach; ?>
</ul>
<button class="btn btn-success" type="submit">S'Abonner</button>
pay.php
<?php
require_once 'inc/db.php';
require 'inc/function.php';
require 'inc/Offer.php';
require 'vendor/autoload.php';
logged_only();
$ids = require 'paypal.php';
//on cree un ApiContext ki contient nos identifiants
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$ids['id'],
$ids['secret']
)
);
//on recupere la liste des offres choisie par l'utilisateur
$key_offer = $_SESSION['offer_key'];
$offer = Offer::getoffers()[$key_offer];
//var_dump($offer);
//on recupere le paiement
$pay = $payemet = \PayPal\Api\Payment::get($_GET['paymentId'], $apiContext);
//on recupere les infos sur l'acheteur
$payer_infos = $payemet->getPayer()->getPayerInfo();
//on recupere les dates de debut et de fin d'inscription au forfait de l'acheteur et quelques donnees sur la transaction
$period_start = (new DateTime($_SESSION['payment']->create_time))->getTimestamp();
$_SESSION['subscription_start'] = $subscription_start = gmdate("Y-m-d H:i:s", $period_start);
$period = $offer['period'] === 'Month' ? new DateInterval($offer['interval']) : new DateInterval('P1Y');
$period_end = (new DateTime())->add($period)->getTimestamp();
$_SESSION['subscription_end'] = $subscription_end = gmdate("Y-m-d H:i:s", $period_end);
$payer_id = $payer_infos->payer_id;
$payer_email = $payer_infos->email;
$payer_first_name = $payer_infos->first_name;
$payer_last_name = $payer_infos->last_name;
$payer_country_code = $payer_infos->country_code;
$price_text = $offer['price_text'];
$username = $_SESSION['auth']->username;
$pdo->prepare("UPDATE users SET subscription_start = ?, subscription_end = ?, payer_id = ?, payer_email = ?, payer_first_name = ?, payer_last_name = ?, payer_country_code = ?, price_text = ? where username = ?")->execute([$_SESSION['subscription_start'], $_SESSION['subscription_end'], $payer_id, $payer_email, $payer_first_name, $payer_last_name, $payer_country_code, $price_text, $username]);
$execution = (new \PayPal\Api\PaymentExecution())
->setPayerId($_GET['PayerID'])
->setTransactions($payemet->getTransactions());
try {
$pay->execute($execution, $apiContext);
$_SESSION['flash']['success']="Votre paiement s'est deroulé avec succès et prendra effet lors de votre prochaine reconnection 😊";
header('location: logoutpaypal.php');
} catch (\Paypal\Exception\PayPalConnectionException $e) {
header('HTTP 500 Internal Server Error', true, 500);
var_dump(json_decode($e->getData()));
}
payment.php
<?php
require_once 'inc/db.php';
require 'inc/function.php';
require 'inc/Offer.php';
require 'vendor/autoload.php';
logged_only();
$ids = require 'paypal.php';
//on cree un ApiContext ki contient nos identifiants
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$ids['id'],
$ids['secret']
)
);
//on recupere le pannier selectionne par l'utilisateur
$key_offer = $_SESSION['offer_key'];
$offer = Offer::getoffers()[$key_offer];
//on cree une liste d'item
$list = new \PayPal\Api\ItemList();
if (isset($offer)) {
$item = (new \PayPal\Api\Item())
->setName($offer['name'])
->setPrice($offer['price'])
->setCurrency('EUR')
->setQuantity(1);
$list->addItem($item);
//on cree une partie amount ki contient le paiement et les details sur le paiement
$details = (new \PayPal\Api\Details())
->setSubtotal($offer['price'])
->setTax($offer['tax']);
$amount = (new \PayPal\Api\Amount())
->setTotal($offer['total_price'])
->setCurrency('EUR')
->setDetails($details);
//A la fin on envoie la transaction au paiement
$transaction = (new \PayPal\Api\Transaction())
->setItemList($list)
->setDescription($offer['description'])
->setAmount($amount)
->setCustom('id_utilisateur');
$payment = new \PayPal\Api\Payment();
$payment->setTransactions([$transaction]);
$payment->setIntent('sale');
$redirectUrls = (new \PayPal\Api\RedirectUrls())
//A modifier
->setReturnUrl('https://thelockedfile.com/pay.php')
->setCancelUrl('https://thelockedfile.com/subscribe.php');
//End modif
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer((new \PayPal\Api\Payer())->setPaymentMethod('paypal'));
try {
$payment->create($apiContext);
//on sauvegarde le tout dans une variable globale
$_SESSION['payment'] = $payment;
header('location: ' . $payment->getApprovalLink());
} catch (\Paypal\Exception\PayPalConnectionException $e) {
json_decode($e->getData());
}
}
Labels:
- Labels:
-
API
-
Express Checkout
-
Payouts
-
REST
-
SDK
0 REPLIES 0
![](/skins/images/BC6528466832E4059F46B7B785A17D7B/responsive_peak/images/icon_anonymous_message.png)
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- sandbox webhook api problem in Sandbox Environment
- Sandbox differs production have problem process button request and no notifications after pay. in Sandbox Environment
- Problems with Negative Testing on Sandbox or incorrect implementation in Sandbox Environment
- Account association problem in sandbox environment in Sandbox Environment
- Problem when creating a Sandbox business accounts in Sandbox Environment