-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
486b89f
commit ed12d56
Showing
9 changed files
with
337 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php FreshRSS::preLayout(); ?> | ||
<!DOCTYPE html> | ||
<html lang="<?php echo FreshRSS_Context::$user_conf->language; ?>" xml:lang="<?php echo FreshRSS_Context::$user_conf->language; ?>"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="initial-scale=1.0" /> | ||
<?php echo self::headStyle(); ?> | ||
<?php echo self::headScript(); ?> | ||
<link rel="shortcut icon" id="favicon" type="image/x-icon" sizes="16x16 64x64" href="<?php echo Minz_Url::display('/favicon.ico'); ?>" /> | ||
<link rel="icon msapplication-TileImage apple-touch-icon" type="image/png" sizes="256x256" href="<?php echo Minz_Url::display('/themes/icons/favicon-256.png'); ?>" /> | ||
<link rel="apple-touch-icon" href="<?php echo Minz_Url::display('/themes/icons/apple-touch-icon.png'); ?>" /> | ||
<meta name="apple-mobile-web-app-capable" content="yes" /> | ||
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> | ||
<meta name="apple-mobile-web-app-title" content="<?php echo FreshRSS_Context::$system_conf->title; ?>"> | ||
<meta name="msapplication-TileColor" content="#FFF" /> | ||
<?php echo self::headTitle(); ?> | ||
<meta name="description" content="<?php echo htmlspecialchars(FreshRSS_Context::$name . ' | ' . FreshRSS_Context::$description, ENT_COMPAT, 'UTF-8'); ?>" /> | ||
</head> | ||
|
||
<body class="fl-layout-redirection"> | ||
<div class="fl-layout-container"> | ||
<?php | ||
flush(); | ||
$this->render(); | ||
?> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
<?php | ||
|
||
namespace Flus\services; | ||
|
||
class Stripe { | ||
public static function init($key) { | ||
\Stripe\Stripe::setApiKey($key); | ||
} | ||
|
||
public static function create($username, $frequency, $amount) { | ||
$user_conf = get_user_configuration($username); | ||
$email = $user_conf->mail_login; | ||
|
||
$return_url = \Minz_Url::display( | ||
['c' => 'billing', 'a' => 'return'], 'php', true | ||
); | ||
$cancel_url = \Minz_Url::display( | ||
['c' => 'billing', 'a' => 'cancel'], 'php', true | ||
); | ||
|
||
$session = \Stripe\Checkout\Session::create([ | ||
'customer_email' => $email, | ||
'payment_method_types' => ['card'], | ||
'line_items' => [[ | ||
'name' => 'Abonnement Flus', | ||
'amount' => $amount * 100, | ||
'currency' => 'eur', | ||
'quantity' => 1, | ||
]], | ||
'payment_intent_data' => [ | ||
'metadata' => [ | ||
'username' => $username, | ||
'frequency' => $frequency, | ||
], | ||
], | ||
'success_url' => $return_url, | ||
'cancel_url' => $cancel_url, | ||
'expand' => ['payment_intent'], | ||
]); | ||
|
||
return new Stripe($session); | ||
} | ||
|
||
public static function retrieve($session_id) { | ||
$session = \Stripe\Checkout\Session::retrieve([ | ||
'id' => $session_id, | ||
'expand' => ['payment_intent'], | ||
]); | ||
return new Stripe($session); | ||
} | ||
|
||
private $session = null; | ||
private $status = 'unknown'; | ||
private $invoice_number = ''; | ||
|
||
private function __construct($session) { | ||
$this->session = $session; | ||
} | ||
|
||
public function syncStatus() { | ||
$payment_intent = $this->session->payment_intent; | ||
if ($payment_intent->status === 'succeeded') { | ||
$this->status = 'paid'; | ||
} elseif ($payment_intent->status === 'canceled') { | ||
$this->status = 'canceled'; | ||
} else { | ||
$this->status = 'waiting'; | ||
} | ||
} | ||
|
||
public function cancel() { | ||
if ($this->status !== 'waiting') { | ||
$this->status = 'canceled'; | ||
$payment_intent = $this->session->payment_intent; | ||
$payment_intent->cancel(); | ||
} | ||
} | ||
|
||
public function save() { | ||
$user_conf = get_user_configuration($this->username()); | ||
|
||
$billing = $user_conf->billing; | ||
$billing['payments'][$this->id()] = $this->payment(); | ||
$user_conf->billing = $billing; | ||
|
||
return $user_conf->save(); | ||
} | ||
|
||
public function payment() { | ||
return array( | ||
'type' => 'stripe', | ||
'status' => $this->status, | ||
'date' => $this->date(), | ||
'frequency' => $this->frequency(), | ||
'amount' => $this->amount(), | ||
'invoice_number' => $this->invoice_number, | ||
); | ||
} | ||
|
||
public function id() { | ||
return $this->session->id; | ||
} | ||
|
||
public function isPaid() { | ||
return $this->status === 'paid'; | ||
} | ||
|
||
public function isCanceled() { | ||
return $this->status === 'canceled'; | ||
} | ||
|
||
public function isWaiting() { | ||
return $this->status === 'waiting'; | ||
} | ||
|
||
public function date() { | ||
$payment_intent = $this->session->payment_intent; | ||
return $payment_intent->created; | ||
} | ||
|
||
public function amount() { | ||
$payment_intent = $this->session->payment_intent; | ||
return $payment_intent->amount / 100; | ||
} | ||
|
||
public function address() { | ||
$user_conf = get_user_configuration($this->username()); | ||
$address = $user_conf->billing['address']; | ||
return [ | ||
'first_name' => $address['first_name'], | ||
'last_name' => $address['last_name'], | ||
'address1' => $address['address'], | ||
'postcode' => $address['postcode'], | ||
'city' => $address['city'], | ||
]; | ||
} | ||
|
||
public function username() { | ||
return $this->session->payment_intent->metadata['username']; | ||
} | ||
|
||
public function frequency() { | ||
return $this->session->payment_intent->metadata['frequency']; | ||
} | ||
|
||
public function generateInvoiceNumber() { | ||
$invoices_path = DATA_PATH . '/extensions-data/xExtension-Flus/invoices'; | ||
$lock_path = $invoices_path . '/.lock'; | ||
|
||
$lock_file = fopen($lock_path, 'r+'); | ||
|
||
if (flock($lock_file, LOCK_EX)) { | ||
$last_invoice_number = @fread($lock_file, filesize($lock_path)); | ||
$this->invoice_number = $this->getNextInvoiceNumber($last_invoice_number); | ||
$this->save(); | ||
|
||
rewind($lock_file); | ||
fwrite($lock_file, $this->invoice_number); | ||
|
||
flock($lock_file, LOCK_UN); | ||
} | ||
|
||
fclose($lock_file); | ||
|
||
return $this->invoice_number; | ||
} | ||
|
||
private function getNextInvoiceNumber($last_invoice_number) { | ||
$current_date = getdate(); | ||
$year = $current_date['year']; | ||
$month = $current_date['mon']; | ||
|
||
$invoice_sequence = 1; | ||
if ($last_invoice_number) { | ||
list( | ||
$last_invoice_year, | ||
$last_invoice_month, | ||
$last_invoice_sequence | ||
) = array_map('intval', explode('-', $last_invoice_number)); | ||
|
||
if ($last_invoice_year === $year) { | ||
$invoice_sequence = $last_invoice_sequence + 1; | ||
} | ||
} | ||
|
||
$invoice_format = '%04d-%02d-%04d'; | ||
return sprintf( | ||
$invoice_format, $year, $month, $invoice_sequence | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
if (!$this->subscription_is_overdue) { | ||
$this->partial('aside_configure'); | ||
} | ||
?> | ||
|
||
<div class="post"> | ||
<h1>Annulation du paiement</h1> | ||
|
||
<p> | ||
Le paiement a été annulé, il ne vous sera rien débité. | ||
</p> | ||
|
||
<p> | ||
<a href="<?= _url('billing', 'index') ?>">← Retour à la facturation</a> | ||
</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.