Bonjour,
Voila je rencontre un petit problème avec mon code.
static function getOffers()
{
return [
[
'name' => 'Abonnement mensuel',
'price' => 5,
'price_text' => '5€/mois',
'period' => 'Month'
],
[
'name' => 'Abonnement annuel',
'price' => 47,
'price_text' => '47€/ans',
'period' => 'Year'
]
];
}
Décrivez ici votre code ou ce que vous cherchez à faire
Je voudrais pouvoir mettre une autre possibilité qui serait de s'abonner à vie, ou/est de faire une version d'essaie de 7 jours gratuitement et sans obligation d'achat derrière.
Je pense que la version d'essaie est plus dure à réaliser, mais je n'y arrive pas, avec aucun des deux.
La period n'est pas réglable comme cela, il faut aussi regler dans un autre bout de code, mais je ne sais pas exactement lequel (après avoir cherché bien sur).
public function getCheckoutDetail($token)
{
$data = [
'METHOD' => 'GetExpressCheckoutDetails',
'TOKEN' => $token
];
return $this->nvp($data);
}
/**
* Crée un profile côté paypal et sauvegarde les informations au niveau de la base de données
* @param $token
* @param $user_id
* @param $db
* @throws Exception
*/
public function doSubscribe($token, $user_id, $db)
{
$detail = $this->getCheckoutDetail($token);
$offer_id = $detail['PAYMENTREQUEST_0_CUSTOM'];
if (!isset($this->offers[$offer_id])) {
throw new Exception('Cette offre n\'existe pas');
}
$offer = $this->offers[$offer_id];
$period = $offer['period'] === 'Month' ? new DateInterval('P1M') : new DateInterval('P1Y');
$start = (new DateTime())->add($period)->getTimestamp();
$response = $this->nvp([
'METHOD' => 'CreateRecurringPaymentsProfile',
'TOKEN' => $token,
'PAYERID' => $detail['PAYERID'],
'DESC' => $offer['name'],
'AMT' => $offer['price'],
'TAXAMT' => $offer['price'] * 0.2,
'BILLINGPERIOD' => $offer['period'],
'BILLINGFREQUENCY' => 1,
'CURRENCYCODE' => 'EUR',
'COUNTRYCODE' => 'FR',
'MAXFAILEDPAYMENTS' => 3,
'PROFILESTARTDATE' => gmdate("Y-m-d\TH:i:s\Z", $start),
'INITAMT' => $offer['price'] * 1.2
]);
if ($response['ACK'] === 'Success') {
$db->query('UPDATE users SET payer_id = ?, profile_id = ? WHERE id = ?', [
$detail['PAYERID'],
$response['PROFILEID'],
$user_id
]);
} else { /*IL ME MET LE PROBLEME ICI QUAND JE CHANGE LA PERIOD A "LIFE"
throw new Exception($response['L_LONGMESSAGE0']);
}
}
/**
* Obtient les détails concernant un profil d'abonnement
* @param $profile_id
* @return array
*/
public function getProfileDetail($profile_id)
{
return $this->nvp([
'METHOD' => 'GetRecurringPaymentsProfileDetails',
'PROFILEID' => $profile_id
]);
}
Mon erreurs est au niveau du throw new.... (j'ai mit en commentaire)
Merci de votre aide.