Skip to content

Commit

Permalink
Adding Stripe link payments
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando González committed Nov 13, 2022
1 parent d8634dc commit d29242d
Show file tree
Hide file tree
Showing 60 changed files with 1,131 additions and 90 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The application is designed to be flexible enough so that it can handle any ente
* Self hosted installation.
* Translated user interface.
* User community support.
* Service payment by [Stripe Payment links](https://stripe.com/en-gb-es/payments/payment-links)

## Setup

Expand Down
16 changes: 14 additions & 2 deletions application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,24 @@
| Rate Limiting
|--------------------------------------------------------------------------
|
| Toggle the rate limiting feature in your application. Using rate limiting
| will control the number of requests a client can sent to the app.
| Toggle the rate limiting feature in your application. Using rate limiting
| will control the number of requests a client can sent to the app.
|
*/
$config['rate_limiting'] = TRUE;


/*
|--------------------------------------------------------------------------
| Stripe Payment Configuration
|--------------------------------------------------------------------------
|
| Declare some of the global config values of the Stripe Payments
|
*/

$config['stripe_payment_feature'] = Config::STRIPE_PAYMENT_FEATURE;
$config['stripe_api_key'] = Config::STRIPE_API_KEY;

/* End of file config.php */
/* Location: ./application/config/config.php */
8 changes: 6 additions & 2 deletions application/controllers/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function index()

foreach ($available_providers as &$available_provider)
{
// Only expose the required provider data.
// Only expose the required provider data.

$this->providers_model->only($available_provider, [
'id',
Expand Down Expand Up @@ -170,7 +170,7 @@ public function index()
return;
}

// Make sure the appointment can still be rescheduled.
// Make sure the appointment can still be rescheduled.

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

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

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

script_vars([
Expand Down Expand Up @@ -271,9 +273,11 @@ public function index()
'grouped_timezones' => $grouped_timezones,
'manage_mode' => $manage_mode,
'customer_token' => $customer_token,
'is_paid' => $is_paid,
'appointment_data' => $appointment,
'provider_data' => $provider,
'customer_data' => $customer,
'company_email' => setting('company_email'),
]);

$this->load->view('pages/booking');
Expand Down
16 changes: 14 additions & 2 deletions application/controllers/Booking_confirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct()
$this->load->model('providers_model');
$this->load->model('services_model');
$this->load->model('customers_model');

$this->load->library('google_sync');
}

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

$appointment = $occurrences[0];

$add_to_google_url = $this->google_sync->get_add_to_google_url($appointment['id']);
$add_to_google_url = $this->google_sync->get_add_to_google_url($appointment['id']);

$service = $this->services_model->find($appointment['id_services']);

$customer = $this->customers_model->find($appointment['id_users_customer']);

$payment_link_vars = array(
'{$appointment_hash}' => $appointment['hash'],
'{$customer_email}' => $customer['email'],
);
$payment_link = strtr($service['payment_link'], $payment_link_vars);

html_vars([
'page_title' => lang('success'),
'company_color' => setting('company_color'),
'google_analytics_code' => setting('google_analytics_code'),
'matomo_analytics_url' => setting('matomo_analytics_url'),
'add_to_google_url' => $add_to_google_url,
'is_paid' => $appointment['is_paid'],
'payment_link' => $payment_link,
]);

$this->load->view('pages/booking_confirmation');
Expand Down
16 changes: 9 additions & 7 deletions application/controllers/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function index(string $appointment_hash = '')
'secretary_providers' => $secretary_providers,
'edit_appointment' => $edit_appointment,
'customers' => $this->customers_model->get(NULL, 50, NULL, 'update_datetime DESC'),
'stripe_payment_feature' => config('stripe_payment_feature'),
]);

html_vars([
Expand Down Expand Up @@ -233,7 +234,7 @@ public function save_appointment()
}

// If the appointment does not contain the customer record id, then it means that is going to be
// inserted.
// inserted.
if ( ! isset($appointment['id_users_customer']))
{
$appointment['id_users_customer'] = $customer['id'] ?? $customer_data['id'];
Expand All @@ -256,6 +257,7 @@ public function save_appointment()
'id_users_provider',
'id_users_customer',
'id_services',
'is_paid',
]);

$appointment['id'] = $this->appointments_model->save($appointment);
Expand Down Expand Up @@ -629,9 +631,9 @@ public function get_calendar_appointments()
$end_date = $this->db->escape(date('Y-m-d', strtotime(request('end_date') . ' +1 day')));

$where_clause = $where_id . ' = ' . $record_id . '
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
AND is_unavailability = 0
';

Expand All @@ -650,9 +652,9 @@ public function get_calendar_appointments()
if ($filter_type == FILTER_TYPE_PROVIDER)
{
$where_clause = $where_id . ' = ' . $record_id . '
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
AND ((start_datetime > ' . $start_date . ' AND start_datetime < ' . $end_date . ')
or (end_datetime > ' . $start_date . ' AND end_datetime < ' . $end_date . ')
or (start_datetime <= ' . $start_date . ' AND end_datetime >= ' . $end_date . '))
AND is_unavailability = 1
';

Expand Down

0 comments on commit d29242d

Please sign in to comment.