diff --git a/Dockerfile-wpdebug-php7 b/Dockerfile-wpdebug-php7
index a259284..99c80dc 100644
--- a/Dockerfile-wpdebug-php7
+++ b/Dockerfile-wpdebug-php7
@@ -1,5 +1,10 @@
FROM wordpress:6.0.2-php7.4-apache
+RUN apt-get update && apt-get -qq --force-yes install cron
+COPY wpcron.txt /etc/cron.d/wpcron
+RUN chmod 0744 /etc/cron.d/wpcron
+RUN crontab /etc/cron.d/wpcron
+
ENV XDEBUG_PORT 8999
ENV XDEBUG_IDEKEY docker
@@ -9,4 +14,6 @@ RUN pecl install "xdebug" \
RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/xdebug.ini && \
echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/xdebug.ini && \
echo "xdebug.client_port=${XDEBUG_PORT}" >> /usr/local/etc/php/conf.d/xdebug.ini && \
- echo "xdebug.idekey=${XDEBUG_IDEKEY}" >> /usr/local/etc/php/conf.d/xdebug.ini
\ No newline at end of file
+ echo "xdebug.idekey=${XDEBUG_IDEKEY}" >> /usr/local/etc/php/conf.d/xdebug.ini
+
+CMD cron && apache2-foreground
\ No newline at end of file
diff --git a/Dockerfile-wpdebug-php8 b/Dockerfile-wpdebug-php8
index 14b2c38..bd5a4b4 100644
--- a/Dockerfile-wpdebug-php8
+++ b/Dockerfile-wpdebug-php8
@@ -1,5 +1,10 @@
FROM wordpress:6.0.2-php8.1-apache
+RUN apt-get update && apt-get -qq --force-yes install cron
+COPY wpcron.txt /etc/cron.d/wpcron
+RUN chmod 0744 /etc/cron.d/wpcron
+RUN crontab /etc/cron.d/wpcron
+
ENV XDEBUG_PORT 8999
ENV XDEBUG_IDEKEY docker
@@ -9,4 +14,6 @@ RUN pecl install "xdebug" \
RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/xdebug.ini && \
echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/xdebug.ini && \
echo "xdebug.client_port=${XDEBUG_PORT}" >> /usr/local/etc/php/conf.d/xdebug.ini && \
- echo "xdebug.idekey=${XDEBUG_IDEKEY}" >> /usr/local/etc/php/conf.d/xdebug.ini
\ No newline at end of file
+ echo "xdebug.idekey=${XDEBUG_IDEKEY}" >> /usr/local/etc/php/conf.d/xdebug.ini
+
+CMD cron && apache2-foreground
\ No newline at end of file
diff --git a/assets/js/ledyer-checkout-for-woocommerce.js b/assets/js/ledyer-checkout-for-woocommerce.js
index 23ab255..fd963fb 100644
--- a/assets/js/ledyer-checkout-for-woocommerce.js
+++ b/assets/js/ledyer-checkout-for-woocommerce.js
@@ -19,7 +19,6 @@ jQuery(function ($) {
// Form fields.
shippingUpdated: false,
blocked: false,
- isValidating: false,
preventPaymentMethodChange: false,
@@ -31,8 +30,6 @@ jQuery(function ($) {
shippingEmailExists: false,
shippingPhoneExists: false,
- redirectUrl: null,
-
/**
* Triggers on document ready.
*/
@@ -326,8 +323,6 @@ jQuery(function ($) {
}
})
- lco_wc.isValidating = false;
-
const className = lco_params.pay_for_order ? 'div.woocommerce-notices-wrapper' : 'form.checkout';
// Update the checkout and reenable the form.
@@ -349,10 +344,9 @@ jQuery(function ($) {
/**
* Places the Ledyer order
- * @param {string} order_in_sessions
* @param {string} should_validate
*/
- placeLedyerOrder: function (order_in_sessions = false, should_validate = false) {
+ placeLedyerOrder: function (should_validate = false) {
lco_wc.blocked = true;
lco_wc.getLedyerOrder().done(function (response) {
if (response.success) {
@@ -377,23 +371,14 @@ jQuery(function ($) {
lco_wc.logToFile('Successfully validated order in WooCommerce.');
const url = new URL(data.redirect);
- if (order_in_sessions) {
- url.searchParams.append('lco_pending', 'yes');
- } else {
- url.searchParams.append('lco_pending', 'no');
- }
-
if (should_validate) {
window.ledyer.api.clientValidation({
shouldProceed: true
})
// Ledyer will respond with a new event when order is complete
// So don't redirect just yet
- lco_wc.isValidating = false;
- lco_wc.redirectUrl = url;
return;
}
- lco_wc.redirectUrl.searchParams.append('lco_purchase_complete', 'yes');
window.location.href = url.toString();
} else {
throw 'Result failed';
@@ -442,39 +427,27 @@ jQuery(function ($) {
$(document).on('ledyerCheckoutOrderComplete', function (event) {
lco_wc.logToFile('ledyerCheckoutOrderComplete from Ledyer triggered');
-
- if (lco_wc.redirectUrl !== null) {
- lco_wc.logToFile('Successfully placed order in Ledyer.');
- // This means that placeLedyerOrder was called successfully already
- // (Due to an earlier call caused by client validation)
- lco_wc.redirectUrl.searchParams.append('lco_purchase_complete', 'yes');
- window.location.href = lco_wc.redirectUrl.toString();
- return;
- }
-
if (!lco_params.pay_for_order) {
- lco_wc.placeLedyerOrder(false, lco_wc.isValidating);
+ lco_wc.placeLedyerOrder();
}
});
$(document).on('ledyerCheckoutOrderPending', function (event) {
lco_wc.logToFile('ledyerCheckoutOrderPending from Ledyer triggered');
if (!lco_params.pay_for_order) {
- lco_wc.placeLedyerOrder(true);
+ lco_wc.placeLedyerOrder();
}
});
$(document).on('ledyerCheckoutWaitingForClientValidation', function (event) {
lco_wc.logToFile('ledyerCheckoutWaitingForClientValidation from Ledyer triggered');
- lco_wc.isValidating = true;
-
if (lco_params.pay_for_order) {
window.ledyer.api.clientValidation({
shouldProceed: true
})
} else {
- lco_wc.placeLedyerOrder(false, lco_wc.isValidating);
+ lco_wc.placeLedyerOrder(true);
}
});
},
diff --git a/changelog.readme b/changelog.readme
index 042e3fd..0709ec8 100644
--- a/changelog.readme
+++ b/changelog.readme
@@ -1,3 +1,6 @@
+## 1.2.0
+* Fix: Notifications handling and basic order management
+
## 1.1.3
* Fix: Sanitize response url query parameters (wp review)
* Fix: Escape variables that we print in html markup
diff --git a/classes/admin/class-ledyer-meta-box.php b/classes/admin/class-ledyer-meta-box.php
index cac53b1..da7a720 100644
--- a/classes/admin/class-ledyer-meta-box.php
+++ b/classes/admin/class-ledyer-meta-box.php
@@ -82,9 +82,13 @@ public function print_standard_content( $ledyer_order ) {
?>
-
+
+
+
+
+
diff --git a/classes/class-ledyer-api.php b/classes/class-ledyer-api.php
index b1c04f3..c469557 100644
--- a/classes/class-ledyer-api.php
+++ b/classes/class-ledyer-api.php
@@ -85,4 +85,13 @@ public function update_order_reference( $order_id, $data ) {
public function acknowledge_order( $order_id ) {
return ( new \Ledyer\Requests\Order\Management\Acknowledge_Order( array( 'orderId' => $order_id, 'data' => array() ) ) )->request();
}
+
+ /**
+ * @param $order_id
+ *
+ * @return mixed|\WP_Error
+ */
+ public function get_payment_status( $order_id ) {
+ return ( new \Ledyer\Requests\Order\Management\Get_Payment_Status( array( 'orderId' => $order_id ) ) )->request();
+ }
}
\ No newline at end of file
diff --git a/classes/class-ledyer-confirmation.php b/classes/class-ledyer-confirmation.php
index d0cb600..92038c6 100644
--- a/classes/class-ledyer-confirmation.php
+++ b/classes/class-ledyer-confirmation.php
@@ -29,30 +29,22 @@ public function actions() {
/**
- * Confirm the order in Woo before redirecting the customer to thank you page.
+ * Confirm the order in Woo
*/
public function confirm_order() {
-
- $ledyer_purchase_complete = filter_input( INPUT_GET, 'lco_purchase_complete', FILTER_SANITIZE_STRING );
$ledyer_confirm = filter_input( INPUT_GET, 'lco_confirm', FILTER_SANITIZE_STRING );
$order_key = filter_input( INPUT_GET, 'key', FILTER_SANITIZE_STRING );
- $ledyer_pending = filter_input( INPUT_GET, 'lco_pending', FILTER_SANITIZE_STRING );
- if ( empty( $ledyer_confirm ) || empty( $order_key ) || empty( $ledyer_purchase_complete) ) {
+ if ( empty( $ledyer_confirm ) || empty( $order_key ) ) {
return;
}
$order_id = wc_get_order_id_by_order_key( $order_key );
- $order = wc_get_order( $order_id );
-
- $order_pending_order = ( 'yes' === $ledyer_pending ) ? true : false;
- $should_confirm_order = ( 'yes' === $ledyer_purchase_complete ) ? true : false;
+ if ( empty( $order_id ) ) {
+ return;
+ }
Logger::log( $order_id . ': Confirm the Ledyer order from the confirmation page.' );
-
- if ( $should_confirm_order ) {
- // Confirm the order.
- wc_ledyer_confirm_ledyer_order( $order_id, $order_pending_order );
- lco_unset_sessions();
- }
+ wc_ledyer_confirm_ledyer_order( $order_id );
+ lco_unset_sessions();
}
}
diff --git a/classes/class-ledyer-main.php b/classes/class-ledyer-main.php
index fbdeae9..fe187a4 100644
--- a/classes/class-ledyer-main.php
+++ b/classes/class-ledyer-main.php
@@ -51,7 +51,7 @@ class Ledyer_Checkout_For_WooCommerce {
*/
public $checkout;
- const VERSION = '1.1.3';
+ const VERSION = '1.2.0';
const SLUG = 'ledyer-checkout-for-woocommerce';
const SETTINGS = 'ledyer_checkout_for_woocommerce_settings';
@@ -62,7 +62,7 @@ public function actions() {
add_action( 'rest_api_init', function () {
register_rest_route( 'ledyer/v1', '/notifications/', array(
'methods' => 'POST',
- 'callback' => [ $this, 'update_order_status' ],
+ 'callback' => [ $this, 'handle_notification' ],
'permission_callback' => '__return_true'
) );
} );
@@ -77,149 +77,106 @@ public function actions() {
1,
);
+ add_action( 'schedule_process_notification', array( $this, 'process_notification' ), 10, 1 );
+
}
/**
- * Handles Order management from notifications endpoint
+ * Handles notification callbacks
* @param $request
*
* @return \WP_REST_Response
*/
- public function update_order_status( $request ) {
- $request_body = $request->get_body();
-
+ public function handle_notification( $request ) {
+ $request_body = json_decode( $request->get_body());
+ $response = new \WP_REST_Response();
- if( ! $this->is_json( $request_body ) ) {
+ if (json_last_error() !== JSON_ERROR_NONE) {
Logger::log( 'Request body isn\'t valid JSON string.' );
-
- $data = array(
- 'message' => 'Request body isn\'t valid JSON string.',
- 'json' => $request_body,
- );
-
- $response = new \WP_REST_Response( $data );
- $response->set_status( 404 );
-
+ $response->set_status( 400 );
return $response;
}
- $request_body = json_decode( $request_body, true );
+ $ledyer_event_type = $request_body->{'eventType'};
+ $ledyer_order_id = $request_body->{'orderId'};
- if( ! is_array( $request_body ) || empty( $request_body['orderId'] || empty( $request_body['eventType'] ) ) ) {
+ if ($ledyer_event_type === NULL || $ledyer_order_id === NULL) {
Logger::log( 'Request body doesn\'t hold orderId and eventType data.' );
-
- $data = array(
- 'message' => 'Request body doesn\'t hold orderId and eventType data.',
- 'json' => $request_body,
- );
-
- $response = new \WP_REST_Response( $data );
- $response->set_status( 404 );
-
+ $response->set_status( 400 );
return $response;
}
+
+ $scheduleId = as_schedule_single_action(time() + 120, 'schedule_process_notification', array($ledyer_order_id) );
+ Logger::log( 'Enqueued notification: ' . $ledyer_event_type . ", schedule-id:" . $scheduleId );
+ $response->set_status( 200 );
+ return $response;
+ }
- $order_id = $request_body['orderId'];
+ public function process_notification( $ledyer_order_id ) {
+ Logger::log( 'process notification: ' . $ledyer_order_id);
- $args = array(
+ $query_args = array(
'post_type' => 'shop_order',
'post_status' => 'any',
'meta_key' => '_wc_ledyer_order_id',
- 'meta_value' => $order_id,
+ 'meta_value' => $ledyer_order_id,
+ 'date_created' => '>' . ( time() - MONTH_IN_SECONDS ),
);
- $orders = new \WP_Query( $args );
-
- $ledyer_order = ledyer()->api->get_order( $order_id );
+ $orders = get_posts( $query_args );
+ $order_id = $orders[0]->ID;
+ $order = wc_get_order( $order_id );
- if ( ! $ledyer_order || ( is_object( $ledyer_order ) && is_wp_error( $ledyer_order ) ) || $ledyer_order['id'] !== $order_id ) {
- Logger::log( $order_id . ': Could not get Ledyer order.' );
-
- $data = array(
- 'message' => $order_id . ': Could not get Ledyer order.',
- 'ledyer_order_id' => $order_id,
- );
+ if ( !is_object( $order ) ) {
+ Logger::log('Could not find woo order with ledyer id: ' . $ledyer_order_id );
+ return;
+ }
- $response = new \WP_REST_Response( $data );
- $response->set_status( 404 );
+ $ledyer_payment_status = ledyer()->api->get_payment_status( $ledyer_order_id );
+ if ( is_wp_error($ledyer_payment_status) ) {
+ \Ledyer\Logger::log( 'Could not get ledyer payment status ' . $ledyer_order_id );
+ return;
+ }
- return $response;
+ $ackOrder = false;
+
+ switch( $ledyer_payment_status['status']) {
+ case \LedyerPaymentStatus::paymentPending:
+ $note = sprintf( __( 'New payment created in Ledyer with Payment ID %1$s. %2$s',
+ 'ledyer-checkout-for-woocommerce' ), $ledyer_order_id, $ledyer_payment_status['note'] );
+ $order->update_status('on-hold', $note);
+ $ackOrder = true;
+ break;
+ case \LedyerPaymentStatus::paymentConfirmed:
+ $note = sprintf( __( 'New payment created in Ledyer with Payment ID %1$s. %2$s',
+ 'ledyer-checkout-for-woocommerce' ), $ledyer_order_id, $ledyer_payment_status['note'] );
+ $order->add_order_note($note);
+ $order->payment_complete($ledyer_order_id);
+ $ackOrder = true;
+ break;
+ case \LedyerPaymentStatus::orderCaptured:
+ $order->update_status('completed');
+ break;
+ case \LedyerPaymentStatus::orderRefunded:
+ $order->update_status('refunded');
+ break;
+ case \LedyerPaymentStatus::orderCancelled:
+ $order->update_status('cancelled');
+ break;
}
- if ( $orders->have_posts() && in_array( $request_body['eventType'], array('com.ledyer.order.ready_for_capture', 'com.ledyer.order.create') ) ) {
- foreach ( $orders->posts as $order ) {
- if ( 'revision' !== $order->post_status ) {
-
- $order = wc_get_order( $order->ID );
-
- if( 'com.ledyer.order.create' === $request_body['eventType'] ) {
- $order->update_status('pending');
- $response = ledyer()->api->acknowledge_order( $order_id );
- if( is_wp_error( $response ) ) {
- \Ledyer\Logger::log( 'Couldn\'t acknowledge order ' . $order_id );
- }
-
- $ledyer_update_order = ledyer()->api->update_order_reference( $order_id, array( 'reference' => strval( $order->ID ) ) );
- if ( is_wp_error( $ledyer_update_order ) ) {
- \Ledyer\Logger::log( 'Couldn\'t set merchant reference ' . $order->ID );
- }
- }
-
- if( 'com.ledyer.order.ready_for_capture' === $request_body['eventType'] ) {
- $order->update_status('processing');
- }
-
- switch ( $ledyer_order['status'][0] ) {
- case 'fullyCaptured':
- $order->update_status( 'completed' );
- $order->add_order_note( sprintf( __( 'Payment Completed in Ledyer with Payment ID %1$s. Payment type - %2$s.', 'ledyer-checkout-for-woocommerce' ), $order_id, $request['paymentMethod']['type'] ) );
- break;
- case 'cancelled':
- $order->update_status( 'canceled' );
- $order->add_order_note( sprintf( __( 'Payment Canceled in Ledyer with Payment ID %1$s. Payment type - %2$s.', 'ledyer-checkout-for-woocommerce' ), $order_id, $request['paymentMethod']['type'] ) );
- break;
- case 'fullyRefunded':
- $order->update_status( 'refunded' );
- $order->add_order_note( sprintf( __( 'Payment Fully Refunded in Ledyer with Payment ID %1$s. Payment type - %2$s.', 'ledyer-checkout-for-woocommerce' ), $order_id, $request['paymentMethod']['type'] ) );
- break;
- }
- }
+ if ($ackOrder) {
+ $response = ledyer()->api->acknowledge_order( $ledyer_order_id );
+ if( is_wp_error( $response ) ) {
+ \Ledyer\Logger::log( 'Couldn\'t acknowledge order ' . $ledyer_order_id );
+ return;
+ }
+ $ledyer_update_order = ledyer()->api->update_order_reference( $ledyer_order_id, array( 'reference' => strval( $order->ID ) ) );
+ if ( is_wp_error( $ledyer_update_order ) ) {
+ \Ledyer\Logger::log( 'Couldn\'t set merchant reference ' . $order->ID );
+ return;
}
-
- $data = array(
- 'message' => 'successfully updated order status.',
- 'ledyer_order_id' => $order_id,
- );
-
- $response = new \WP_REST_Response( $data );
- $response->set_status( 201 );
-
- return $response;
- } else {
- Logger::log( $order_id . ': Could not find Ledyer order in Woo.' );
- $data = array(
- 'message' => 'Ledyer order '. $order_id .' doesn\'t exist in Woo.',
- 'ledyer_order_id' => $order_id,
- );
-
- $response = new \WP_REST_Response( $data );
- $response->set_status( 200 );
-
- return $response;
}
-
- }
-
- /**
- * Checks if given string is valid JSON string.
- * @param $string
- *
- * @return bool
- */
- public function is_json( $string ) {
- json_decode( $string );
-
- return json_last_error() === JSON_ERROR_NONE;
}
@@ -259,7 +216,7 @@ public function on_plugins_loaded() {
*/
public function include_files() {
include_once LCO_WC_PLUGIN_PATH . '/includes/lco-functions.php';
- include_once LCO_WC_PLUGIN_PATH . '/includes/lco-functions.php';
+ include_once LCO_WC_PLUGIN_PATH . '/includes/lco-types.php';
include_once LCO_WC_PLUGIN_PATH . '/classes/class-ledyer-singleton.php';
include_once LCO_WC_PLUGIN_PATH . '/classes/class-ledyer-logger.php';
include_once LCO_WC_PLUGIN_PATH . '/classes/admin/class-ledyer-meta-box.php';
@@ -270,6 +227,7 @@ public function include_files() {
include_once LCO_WC_PLUGIN_PATH . '/classes/requests/order/session/class-ledyer-update-order.php';
include_once LCO_WC_PLUGIN_PATH . '/classes/requests/order/management/class-ledyer-acknowledge-order.php';
include_once LCO_WC_PLUGIN_PATH . '/classes/requests/order/management/class-ledyer-get-order.php';
+ include_once LCO_WC_PLUGIN_PATH . '/classes/requests/order/management/class-ledyer-get-payment-status.php';
include_once LCO_WC_PLUGIN_PATH . '/classes/requests/order/management/class-ledyer-update-order-reference.php';
include_once LCO_WC_PLUGIN_PATH . '/classes/requests/helpers/class-ledyer-cart.php';
include_once LCO_WC_PLUGIN_PATH . '/classes/requests/helpers/class-ledyer-woocommerce-bridge.php';
diff --git a/classes/requests/order/management/class-ledyer-get-payment-status.php b/classes/requests/order/management/class-ledyer-get-payment-status.php
new file mode 100644
index 0000000..212bd31
--- /dev/null
+++ b/classes/requests/order/management/class-ledyer-get-payment-status.php
@@ -0,0 +1,31 @@
+url = sprintf( 'v1/orders/%s/paymentstatus', $this->arguments['orderId'] );
+
+ parent::get_request_url();
+ }
+}
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index 31059ba..0b6477c 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,6 +3,8 @@ services:
db:
image: mariadb:latest
restart: on-failure
+ ports:
+ - 13306:3306
environment:
MYSQL_DATABASE: testdb
MYSQL_USER: wordpress
diff --git a/includes/lco-functions.php b/includes/lco-functions.php
index 21c9217..bd0a243 100644
--- a/includes/lco-functions.php
+++ b/includes/lco-functions.php
@@ -167,8 +167,13 @@ function lco_wc_show_another_gateway_button() {
*
* @return void
*/
-function wc_ledyer_confirm_ledyer_order( $order_id, $ledyer_pending ) {
- $order = wc_get_order( $order_id );
+function wc_ledyer_confirm_ledyer_order( $order_id ) {
+ $order = wc_get_order( $order_id );
+ // If the order is already completed or on-hold, return.
+ if ( !empty($order->get_date_paid()) || $order->has_status(array('on-hold')) ) {
+ return;
+ }
+
$payment_id = get_post_meta( $order_id, '_wc_ledyer_order_id', true );
$session_id = get_post_meta( $order_id, '_wc_ledyer_session_id', true );
@@ -180,33 +185,58 @@ function wc_ledyer_confirm_ledyer_order( $order_id, $ledyer_pending ) {
$session_id = WC()->session->get( 'lco_wc_session_id' );
}
- if( ! $ledyer_pending ) {
- $request = ledyer()->api->get_order( $payment_id );
- } else {
- $request = ledyer()->api->get_order_session($payment_id);
+ $ledyer_payment_status = ledyer()->api->get_payment_status( $payment_id );
+ if ( is_wp_error($ledyer_payment_status) ) {
+ \Ledyer\Logger::log( 'Could not get ledyer payment status ' . $payment_id );
+ return;
}
- if ( isset( $request['orderAmount'] ) || isset( $request['id'] ) ) {
+ $ackOrder = false;
+
+ switch( $ledyer_payment_status['status']) {
+ case LedyerPaymentStatus::orderPending:
+ $note = sprintf( __( 'New session created in Ledyer with Payment ID %1$s. %2$s',
+ 'ledyer-checkout-for-woocommerce' ), $payment_id, $ledyer_payment_status['note'] );
+ $order->update_status('on-hold', $note);
+ break;
+ case LedyerPaymentStatus::paymentPending:
+ $note = sprintf( __( 'New payment created in Ledyer with Payment ID %1$s. %2$s',
+ 'ledyer-checkout-for-woocommerce' ), $payment_id, $ledyer_payment_status['note'] );
+ $order->update_status('on-hold', $note);
+ $ackOrder = true;
+ break;
+ case LedyerPaymentStatus::paymentConfirmed:
+ $note = sprintf( __( 'New payment created in Ledyer with Payment ID %1$s. %2$s',
+ 'ledyer-checkout-for-woocommerce' ), $payment_id, $ledyer_payment_status['note'] );
+ $order->add_order_note($note);
+ $order->payment_complete($payment_id);
+ $ackOrder = true;
+ break;
+ }
- do_action( 'ledyer_process_payment', $order_id, $request );
+ if ($ackOrder) {
+ $ledyer_order = ledyer()->api->get_order( $payment_id );
+ if ( is_wp_error($ledyer_order) ) {
+ \Ledyer\Logger::log( 'Could not get ledyer order ' . $payment_id );
+ return;
+ }
- update_post_meta( $order_id, 'ledyerpayment_type', $request['paymentMethod']['type'] );
- update_post_meta( $order_id, 'ledyer_payment_method', $request['paymentMethod']['provider'] );
- update_post_meta( $order_id, '_ledyer_date_paid', gmdate( 'Y-m-d H:i:s' ) );
+ do_action( 'ledyer_process_payment', $order_id, $ledyer_order );
- if( ! $ledyer_pending ) {
- $order->add_order_note( sprintf( __( 'New payment created in Ledyer with Payment ID %1$s. Payment type - %2$s. Awaiting capture.', 'ledyer-checkout-for-woocommerce' ), $payment_id, $request['paymentMethod']['type'] ) );
- } else {
- $order->update_status('on-hold');
- $order->add_order_note( sprintf( __( 'New pending payment created in Ledyer with Payment ID %1$s. Payment type - %2$s. Awaiting signature.', 'ledyer-checkout-for-woocommerce' ), $session_id, $request['paymentMethod']['type'] ) );
- }
+ update_post_meta( $order_id, 'ledyerpayment_type', $ledyer_order['paymentMethod']['type'] );
+ update_post_meta( $order_id, 'ledyer_payment_method', $ledyer_order['paymentMethod']['provider'] );
+ update_post_meta( $order_id, '_ledyer_date_paid', gmdate( 'Y-m-d H:i:s' ) );
- } else {
- // Purchase not finalized in Ledyer.
- // If this is a redirect checkout flow let's redirect the customer to cart page.
- wp_safe_redirect( html_entity_decode( $order->get_cancel_order_url() ) );
- exit;
+ $response = ledyer()->api->acknowledge_order( $payment_id );
+ if( is_wp_error( $response ) ) {
+ \Ledyer\Logger::log( 'Couldn\'t acknowledge order ' . $payment_id );
+ }
+ $ledyer_update_order = ledyer()->api->update_order_reference( $payment_id, array( 'reference' => strval( $order->ID ) ) );
+ if ( is_wp_error( $ledyer_update_order ) ) {
+ \Ledyer\Logger::log( 'Couldn\'t set merchant reference ' . $order->ID );
+ }
}
+
}
diff --git a/includes/lco-types.php b/includes/lco-types.php
new file mode 100644
index 0000000..cc49e88
--- /dev/null
+++ b/includes/lco-types.php
@@ -0,0 +1,14 @@
+\n"
"Language-Team: LANGUAGE \n"
diff --git a/ledyer-checkout-for-woocommerce.php b/ledyer-checkout-for-woocommerce.php
index 525b0f4..fbe881c 100644
--- a/ledyer-checkout-for-woocommerce.php
+++ b/ledyer-checkout-for-woocommerce.php
@@ -5,7 +5,7 @@
* Description: Ledyer Checkout payment gateway for WooCommerce.
* Author: Maksimer/Ledyer
* Author URI: https://www.maksimer.com/
- * Version: 1.1.3
+ * Version: 1.2.0
* Text Domain: ledyer-checkout-for-woocommerce
* Domain Path: /languages
*
diff --git a/readme.txt b/readme.txt
index 861c190..6ad56b2 100644
--- a/readme.txt
+++ b/readme.txt
@@ -7,6 +7,6 @@ Tested up to: 8.1.11
Requires PHP: 7.0
WC requires at least: 4.0.0
WC tested up to: 6.9.3
-Stable tag: 1.1.3
+Stable tag: 1.2.0
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
diff --git a/wpcron.txt b/wpcron.txt
new file mode 100644
index 0000000..e35a4b2
--- /dev/null
+++ b/wpcron.txt
@@ -0,0 +1,3 @@
+# must be ended with a new line "LF" (Unix) and not "CRLF" (Windows)
+* * * * * curl http://localhost/wp-cron.php?doing_wp_cron > /dev/null 2>&1
+# An empty line is required at the end of this file for a valid cron file.