Skip to content

Commit af117eb

Browse files
author
Chris Gårdenberg
committed
add: Support for programme bookings
1 parent 1c1332b commit af117eb

2 files changed

Lines changed: 61 additions & 23 deletions

File tree

class-edu-klarnacheckout.php

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,38 @@ public function __construct() {
2525
public function test_page( $attributes ) {
2626
$attributes = shortcode_atts(
2727
array(
28-
'bookingid' => 0,
28+
'bookingid' => 0,
29+
'programmebookingid' => 0,
2930
),
3031
normalize_empty_atts( $attributes ),
3132
'test_page'
3233
);
3334

34-
$event_booking = EDUAPI()->OData->Bookings->GetItem(
35-
intval( $attributes['bookingid'] ),
36-
null,
37-
'Customer($select=CustomerId;),ContactPerson($select=PersonId;),OrderRows',
38-
false
39-
);
40-
$_customer = EDUAPI()->OData->Customers->GetItem(
35+
if ( $attributes['bookingid'] > 0 ) {
36+
$event_booking = EDUAPI()->OData->Bookings->GetItem(
37+
$attributes['bookingid'],
38+
null,
39+
'Customer($select=CustomerId;),ContactPerson($select=PersonId;),OrderRows',
40+
false
41+
);
42+
} elseif ( $attributes['programmebookingid'] > 0 ) {
43+
$event_booking = EDUAPI()->OData->ProgrammeBookings->GetItem(
44+
$attributes['programmebookingid'],
45+
null,
46+
'Customer($select=CustomerId;),ContactPerson($select=PersonId;),OrderRows',
47+
false
48+
);
49+
}
50+
51+
EDU()->write_debug($event_booking);
52+
53+
$_customer = EDUAPI()->OData->Customers->GetItem(
4154
$event_booking['Customer']['CustomerId'],
4255
null,
4356
null,
4457
false
4558
);
46-
$_contact = EDUAPI()->OData->Persons->GetItem(
59+
$_contact = EDUAPI()->OData->Persons->GetItem(
4760
$event_booking['ContactPerson']['PersonId'],
4861
null,
4962
null,
@@ -67,7 +80,7 @@ public function intercept_booking( $ebi = null ) {
6780
return;
6881
}
6982

70-
if ( ! empty( $_POST['act'] ) && 'bookCourse' === $_POST['act'] ) {
83+
if ( ! empty( $_POST['act'] ) && ( 'bookCourse' === $_POST['act'] || 'bookProgramme' === $_POST['act'] ) ) {
7184
$ebi->NoRedirect = true;
7285
}
7386
}
@@ -178,22 +191,34 @@ public function create_checkout( $ebi = null ) {
178191

179192
$current_url = esc_url( "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" );
180193

194+
$booking_id = 0;
195+
$programme_booking_id = 0;
196+
197+
if ( ! empty( $ebi->EventBooking['BookingId'] ) ) {
198+
$booking_id = intval( $ebi->EventBooking['BookingId'] );
199+
}
200+
201+
if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
202+
$programme_booking_id = intval( $ebi->EventBooking['ProgrammeBookingId'] );
203+
}
181204

182205
$confirmation_url = add_query_arg(
183206
array(
184-
'klarna_order_id' => '{checkout.order.id}',
185-
'booking_id' => $ebi->EventBooking['BookingId'],
186-
'edu-valid-form' => wp_create_nonce( 'edu-booking-confirm' ),
187-
'act' => 'paymentCompleted'
207+
'klarna_order_id' => '{checkout.order.id}',
208+
'booking_id' => $booking_id,
209+
'programme_booking_id' => $programme_booking_id,
210+
'edu-valid-form' => wp_create_nonce( 'edu-booking-confirm' ),
211+
'act' => 'paymentCompleted',
188212
),
189213
$current_url
190214
);
191215

192216
$push_url = add_query_arg(
193217
array(
194-
'klarna_order_id' => '{checkout.order.id}',
195-
'booking_id' => $ebi->EventBooking['BookingId'],
196-
'status' => 'push',
218+
'klarna_order_id' => '{checkout.order.id}',
219+
'booking_id' => $booking_id,
220+
'programme_booking_id' => $programme_booking_id,
221+
'status' => 'push',
197222
),
198223
$current_url
199224
);
@@ -267,15 +292,28 @@ public function process_paymentstatus() {
267292

268293
$order->fetch();
269294

295+
$booking_id = intval( $_GET['booking_id'] );
296+
$programme_booking_id = intval( $_GET['programme_booking_id'] );
297+
298+
270299
if ( 'checkout_complete' === $order['status'] ) {
271300

272301
$patch_booking = new stdClass();
273302
$patch_booking->Paid = true;
274303

275-
EDUAPI()->REST->Booking->PatchBooking(
276-
intval( $_GET['booking_id'] ),
277-
$patch_booking
278-
);
304+
if ( $booking_id > 0 ) {
305+
EDUAPI()->REST->Booking->PatchBooking(
306+
$booking_id,
307+
$patch_booking
308+
);
309+
}
310+
311+
if ( $programme_booking_id > 0 ) {
312+
EDUAPI()->REST->ProgrammeBooking->PatchBooking(
313+
$programme_booking_id,
314+
$patch_booking
315+
);
316+
}
279317

280318
$update = array();
281319
$update['status'] = 'created';

eduadmin-wp-klarna-checkout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Plugin Name: EduAdmin Booking - Klarna Checkout-plugin
66
* Plugin URI: https://www.eduadmin.se
77
* Description: Plugin to EduAdmin Booking to enable Klarna Checkout-integration
8-
* Version: 1.0.0
8+
* Version: 1.0.1
99
* GitHub Plugin Uri: https://github.com/MultinetInteractive/eduadmin-wp-klarna-checkout
10-
* Requires at least: 3.0
10+
* Requires at least: 4.7
1111
* Tested up to: 4.9
1212
* Author: Chris Gårdenberg, MultiNet Interactive AB
1313
* Author URI: https://www.multinet.com

0 commit comments

Comments
 (0)