@@ -14,18 +14,60 @@ public function __construct() {
1414 add_action ( 'eduadmin-checkpaymentplugins ' , array ( $ this , 'intercept_booking ' ) );
1515 add_action ( 'eduadmin-processbooking ' , array ( $ this , 'process_booking ' ) );
1616 add_action ( 'wp_loaded ' , array ( $ this , 'process_klarnaresponse ' ) );
17+
18+ add_shortcode ( 'eduadmin-klarna-testpage ' , array ( $ this , 'test_page ' ) );
19+ }
20+
21+ /**
22+ * @param int $booking_id
23+ */
24+ public function test_page ( $ attributes ) {
25+ $ attributes = shortcode_atts (
26+ array (
27+ 'bookingid ' => 0 ,
28+ ),
29+ normalize_empty_atts ( $ attributes ),
30+ 'test_page '
31+ );
32+
33+ $ event_booking = EDUAPI ()->OData ->Bookings ->GetItem (
34+ intval ( $ attributes ['bookingid ' ] ),
35+ null ,
36+ 'Customer($select=CustomerId;),ContactPerson($select=PersonId;) '
37+ );
38+ $ _customer = EDUAPI ()->OData ->Customers ->GetItem ( $ event_booking ['Customer ' ]['CustomerId ' ] );
39+ $ _contact = EDUAPI ()->OData ->Persons ->GetItem ( $ event_booking ['ContactPerson ' ]['PersonId ' ] );
40+
41+ $ ebi = new EduAdmin_BookingInfo ( $ event_booking , $ _customer , $ _contact );
42+
43+ do_action ( 'eduadmin-processbooking ' , $ ebi );
1744 }
1845
19- public function intercept_booking () {
46+ /**
47+ * @param EduAdmin_BookingInfo|null $ebi
48+ */
49+ public function intercept_booking ( $ ebi = null ) {
2050 if ( 'no ' === $ this ->get_option ( 'enabled ' , 'no ' ) ) {
2151 return ;
2252 }
53+
54+ if ( ! empty ( $ _POST ['act ' ] ) && 'bookCourse ' === $ _POST ['act ' ] ) {
55+ $ ebi ->NoRedirect = true ;
56+ }
2357 }
2458
25- public function process_booking () {
59+ /**
60+ * @param EduAdmin_BookingInfo|null $ebi
61+ */
62+ public function process_booking ( $ ebi = null ) {
2663 if ( 'no ' === $ this ->get_option ( 'enabled ' , 'no ' ) ) {
2764 return ;
2865 }
66+
67+ $ ebi ->NoRedirect = true ;
68+
69+ $ checkout = $ this ->create_checkout ( $ ebi );
70+ include_once 'checkout-page.php ' ;
2971 }
3072
3173 public function process_klarnaresponse () {
@@ -62,5 +104,33 @@ public function init_form_fields() {
62104 ),
63105 );
64106 }
107+
108+ /**
109+ * @param EduAdmin_BookingInfo|null $ebi
110+ *
111+ * @return Klarna_Checkout_Order
112+ */
113+ public function create_checkout ( $ ebi = null ) {
114+ $ create = array ();
115+ $ create ['locale ' ] = strtolower ( str_replace ( '_ ' , '- ' , get_locale () ) );
116+ $ create ['cart ' ] = array ();
117+ $ create ['cart ' ]['items ' ] = array ();
118+
119+ try {
120+ $ connector = Klarna_Checkout_Connector::create (
121+ '' ,
122+ Klarna_Checkout_Connector::BASE_TEST_URL
123+ );
124+
125+ $ order = new Klarna_Checkout_Order ( $ connector );
126+ $ order ->create ( $ create );
127+
128+ return $ order ;
129+ } catch ( Klarna_Checkout_ApiErrorException $ ex ) {
130+ EDU ()->write_debug ( $ ex ->getMessage () );
131+ EDU ()->write_debug ( $ ex ->getPayload () );
132+ EDU ()->write_debug ( $ create );
133+ }
134+ }
65135 }
66136}
0 commit comments