Skip to content

Commit 8eef29a

Browse files
author
Fernando González
committed
Adding Stripe link payments
1 parent 4a9111c commit 8eef29a

File tree

60 files changed

+1131
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1131
-90
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The application is designed to be flexible enough so that it can handle any ente
5353
* Self hosted installation.
5454
* Translated user interface.
5555
* User community support.
56+
* Service payment by [Stripe Payment links](https://stripe.com/en-gb-es/payments/payment-links)
5657

5758
## Setup
5859

application/config/config.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,24 @@
458458
| Rate Limiting
459459
|--------------------------------------------------------------------------
460460
|
461-
| Toggle the rate limiting feature in your application. Using rate limiting
462-
| will control the number of requests a client can sent to the app.
461+
| Toggle the rate limiting feature in your application. Using rate limiting
462+
| will control the number of requests a client can sent to the app.
463463
|
464464
*/
465465
$config['rate_limiting'] = TRUE;
466466

467467

468+
/*
469+
|--------------------------------------------------------------------------
470+
| Stripe Payment Configuration
471+
|--------------------------------------------------------------------------
472+
|
473+
| Declare some of the global config values of the Stripe Payments
474+
|
475+
*/
476+
477+
$config['stripe_payment_feature'] = Config::STRIPE_PAYMENT_FEATURE;
478+
$config['stripe_api_key'] = Config::STRIPE_API_KEY;
479+
468480
/* End of file config.php */
469481
/* Location: ./application/config/config.php */

application/controllers/Booking.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function index()
9393

9494
foreach ($available_providers as &$available_provider)
9595
{
96-
// Only expose the required provider data.
96+
// Only expose the required provider data.
9797

9898
$this->providers_model->only($available_provider, [
9999
'id',
@@ -170,7 +170,7 @@ public function index()
170170
return;
171171
}
172172

173-
// Make sure the appointment can still be rescheduled.
173+
// Make sure the appointment can still be rescheduled.
174174

175175
$start_datetime = strtotime($results[0]['start_datetime']);
176176

@@ -203,6 +203,7 @@ public function index()
203203
$provider = $this->providers_model->find($appointment['id_users_provider']);
204204
$customer = $this->customers_model->find($appointment['id_users_customer']);
205205
$customer_token = md5(uniqid(mt_rand(), TRUE));
206+
$is_paid = $appointment['is_paid'];
206207

207208
// Cache the token for 10 minutes.
208209
$this->cache->save('customer-token-' . $customer_token, $customer['id'], 600);
@@ -214,6 +215,7 @@ public function index()
214215
$appointment = NULL;
215216
$provider = NULL;
216217
$customer = NULL;
218+
$is_paid = 0;
217219
}
218220

219221
script_vars([
@@ -271,9 +273,11 @@ public function index()
271273
'grouped_timezones' => $grouped_timezones,
272274
'manage_mode' => $manage_mode,
273275
'customer_token' => $customer_token,
276+
'is_paid' => $is_paid,
274277
'appointment_data' => $appointment,
275278
'provider_data' => $provider,
276279
'customer_data' => $customer,
280+
'company_email' => setting('company_email'),
277281
]);
278282

279283
$this->load->view('pages/booking');

application/controllers/Booking_confirmation.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct()
3030
$this->load->model('providers_model');
3131
$this->load->model('services_model');
3232
$this->load->model('customers_model');
33-
33+
3434
$this->load->library('google_sync');
3535
}
3636

@@ -52,14 +52,26 @@ public function of()
5252

5353
$appointment = $occurrences[0];
5454

55-
$add_to_google_url = $this->google_sync->get_add_to_google_url($appointment['id']);
55+
$add_to_google_url = $this->google_sync->get_add_to_google_url($appointment['id']);
56+
57+
$service = $this->services_model->find($appointment['id_services']);
58+
59+
$customer = $this->customers_model->find($appointment['id_users_customer']);
60+
61+
$payment_link_vars = array(
62+
'{$appointment_hash}' => $appointment['hash'],
63+
'{$customer_email}' => $customer['email'],
64+
);
65+
$payment_link = strtr($service['payment_link'], $payment_link_vars);
5666

5767
html_vars([
5868
'page_title' => lang('success'),
5969
'company_color' => setting('company_color'),
6070
'google_analytics_code' => setting('google_analytics_code'),
6171
'matomo_analytics_url' => setting('matomo_analytics_url'),
6272
'add_to_google_url' => $add_to_google_url,
73+
'is_paid' => $appointment['is_paid'],
74+
'payment_link' => $payment_link,
6375
]);
6476

6577
$this->load->view('pages/booking_confirmation');

application/controllers/Calendar.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public function index(string $appointment_hash = '')
134134
'secretary_providers' => $secretary_providers,
135135
'edit_appointment' => $edit_appointment,
136136
'customers' => $this->customers_model->get(NULL, 50, NULL, 'update_datetime DESC'),
137+
'stripe_payment_feature' => config('stripe_payment_feature'),
137138
]);
138139

139140
html_vars([
@@ -233,7 +234,7 @@ public function save_appointment()
233234
}
234235

235236
// If the appointment does not contain the customer record id, then it means that is going to be
236-
// inserted.
237+
// inserted.
237238
if ( ! isset($appointment['id_users_customer']))
238239
{
239240
$appointment['id_users_customer'] = $customer['id'] ?? $customer_data['id'];
@@ -256,6 +257,7 @@ public function save_appointment()
256257
'id_users_provider',
257258
'id_users_customer',
258259
'id_services',
260+
'is_paid',
259261
]);
260262

261263
$appointment['id'] = $this->appointments_model->save($appointment);
@@ -636,9 +638,9 @@ public function get_calendar_appointments()
636638
$end_date = $this->db->escape(date('Y-m-d', strtotime(request('end_date') . ' +1 day')));
637639

638640
$where_clause = $where_id . ' = ' . $record_id . '
639-
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
640-
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
641-
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
641+
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
642+
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
643+
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
642644
AND is_unavailability = 0
643645
';
644646

@@ -657,9 +659,9 @@ public function get_calendar_appointments()
657659
if ($filter_type == FILTER_TYPE_PROVIDER)
658660
{
659661
$where_clause = $where_id . ' = ' . $record_id . '
660-
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
661-
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
662-
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
662+
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
663+
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
664+
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
663665
AND is_unavailability = 1
664666
';
665667

0 commit comments

Comments
 (0)