Skip to content

Commit

Permalink
release: 1.4.0
Browse files Browse the repository at this point in the history
- feat: Added EMD (Event data)
  • Loading branch information
itssimple committed Mar 4, 2020
1 parent 1fdeb94 commit 1060c4d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 22 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: mnchga
Tags: booking, participants, courses, events, eduadmin, lega online, klarna
Requires at least: 4.7
Tested up to: 5.3
Stable tag: 1.3.0
Stable tag: 1.4.0
Requires PHP: 5.2
License: GPL3
License-URI: https://www.gnu.org/licenses/gpl-3.0.en.html
Expand All @@ -28,6 +28,10 @@ Stats

== Changelog ==

### 1.4.0

- feat: Added EMD (Event data)

### 1.3.0

- feat: Added EMD (Extra Merchant Data) that is required by some customers
Expand Down
76 changes: 56 additions & 20 deletions class-edu-klarnacheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,29 +185,12 @@ public function create_checkout( $ebi = null ) {
$purchase_country = $organization["CountryCode"];

$emd_info = array(
'unique_account_identifier' => ( ! empty( $ebi->Contact['Email'] ) ? $ebi->Contact['Email'] : $ebi->Contact['PersonId'] ),
'unique_account_identifier' => ( ! empty( $ebi->Contact['Email'] ) ? $ebi->Contact['Email'] : "uid:" . $ebi->Contact['PersonId'] ),
'account_registration_date' => date( 'Y-m-d\TH:i', strtotime( $ebi->Contact['Created'] ) ),
'account_last_modified' => date( 'Y-m-d\TH:i' )
);

$emd_info = array( $emd_info );
$emd_attachment = json_encode( array(
'customer_account_info' => $emd_info
) );

$create['attachment'] = array();
$create['attachment']['content_type'] = 'application/vnd.klarna.internal.emd-v2+json';
$create['attachment']['body'] = $emd_attachment;

$create['locale'] = strtolower( str_replace( '_', '-', get_locale() ) );
$create['purchase_country'] = $purchase_country;
$create['purchase_currency'] = get_option( 'eduadmin-currency', 'SEK' );

$merchant = array();
$merchant['id'] = $this->get_option( 'eid', '' );
$merchant['terms_uri'] = $this->get_option( 'termsurl', '' );

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

$booking_id = 0;
$programme_booking_id = 0;
Expand All @@ -216,20 +199,73 @@ public function create_checkout( $ebi = null ) {

$_event = null;

$eventName = '';

$locationAddress = '';
$locationCountry = '';
$locationPostalCode = '';

if ( ! empty( $ebi->EventBooking['BookingId'] ) ) {
$booking_id = intval( $ebi->EventBooking['BookingId'] );
$reference_id = $booking_id;

$_event = EDUAPI()->OData->Events->GetItem( $ebi->EventBooking['EventId'] );
$_event = EDUAPI()->OData->Events->GetItem( $ebi->EventBooking['EventId'], null, "LocationAddress" );

$eventName = $_event['EventName'];

if ( ! empty( $_event['LocationAddress'] ) && $_event['LocationAdress'] != null ) {
$locationAddress = $_event['LocationAddress']['Address'];
$locationCountry = $_event['LocationAddress']['Country'];
$locationPostalCode = $_event['LocationAddress']['AddressZip'];
}
}

if ( ! empty( $ebi->EventBooking['ProgrammeBookingId'] ) ) {
$programme_booking_id = intval( $ebi->EventBooking['ProgrammeBookingId'] );
$reference_id = $programme_booking_id;

$_event = EDUAPI()->OData->ProgrammeStarts->GetItem( $ebi->EventBooking['ProgrammeStartId'] );

$eventName = $_event['ProgrammeStartName'];
}

$emd_event_info = array(
'event_name' => ( ! empty( $eventName ) ? $eventName : "" ),
'event_company' => $organization['OrganisationName'],
'genre_of_event' => ( ! empty( $_event['CategoryName'] ) ? $_event['CategoryName'] : "" ),
'arena_name' => ( ! empty( $_event['AddressName'] ) ? $_event['AddressName'] : "" ),
'arena_location' => array(
'street_address' => $locationAddress,
'postal_code' => $locationPostalCode,
'city' => ( ! empty( $_event['City'] ) ? $_event['City'] : "" ),
'country' => $locationCountry
),
'start_time' => date( 'Y-m-d\TH:i', strtotime( $_event['StartDate'] ) ),
'end_time' => date( 'Y-m-d\TH:i', strtotime( $_event['EndDate'] ) ),
'access_controlled_venue' => false
);

$emd_event_info = array( $emd_event_info );

$emd_attachment = array(
'customer_account_info' => $emd_info,
'event' => $emd_event_info
);

$create['attachment'] = array();
$create['attachment']['content_type'] = 'application/vnd.klarna.internal.emd-v2+json';
$create['attachment']['body'] = json_encode( $emd_attachment );

$create['locale'] = strtolower( str_replace( '_', '-', get_locale() ) );
$create['purchase_country'] = $purchase_country;
$create['purchase_currency'] = get_option( 'eduadmin-currency', 'SEK' );

$merchant = array();
$merchant['id'] = $this->get_option( 'eid', '' );
$merchant['terms_uri'] = $this->get_option( 'termsurl', '' );

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

$rowExtraInfo = "";

if ( null != $_event ) {
Expand Down
2 changes: 1 addition & 1 deletion eduadmin-wp-klarna-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin Name: EduAdmin Booking - Klarna Checkout-plugin
* Plugin URI: https://www.eduadmin.se
* Description: Plugin to EduAdmin Booking to enable Klarna Checkout-integration
* Version: 1.3.0
* Version: 1.4.0
* GitHub Plugin Uri: https://github.com/MultinetInteractive/eduadmin-wp-klarna-checkout
* Requires at least: 4.7
* Tested up to: 5.3
Expand Down

0 comments on commit 1060c4d

Please sign in to comment.