diff --git a/README.md b/README.md
index fdb2323..c6d5460 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,10 @@
# woocommerce3-pointcheckout
-woocommerce3-pointcheckout wooCommerce 3 on top of Word Press 4 extension for PointCheckout
-
-This guide walks you through on how to setup PointCheckout as a payment method on magento 1.9
+This guide walks you through on how to setup PointCheckout rewards and card as payment methods on woocommerce
1. Download the extension zip file from releases tab
-2. Extract the extionsion and copy the extracted folder pointcheckout_pointcheckoutpay to {store home}/wp-content/plugins
-3. Activate PointCheckout plugin under {admin} -> plugins -> Installed Plugins
+2. Extract the extionsion and copy the extracted folders `pointcheckout_payment_card` and `pointcheckout_payment_rewards` to {store home}/wp-content/plugins
+3. Activate PointCheckout rewards an PointCheckout card plugins under {admin} -> plugins -> Installed Plugins
4. Manage PointCheckout settings from {admin} -> WooCommerce -> Settings -> Payments
diff --git a/pointcheckout_payment_card/assets/images/pointcheckout.png b/pointcheckout_payment_card/assets/images/pointcheckout.png
new file mode 100644
index 0000000..9897037
Binary files /dev/null and b/pointcheckout_payment_card/assets/images/pointcheckout.png differ
diff --git a/pointcheckout_payment_card/assets/js/checkout.js b/pointcheckout_payment_card/assets/js/checkout.js
new file mode 100755
index 0000000..64a6158
--- /dev/null
+++ b/pointcheckout_payment_card/assets/js/checkout.js
@@ -0,0 +1,78 @@
+
+
+jQuery('form.checkout').on('submit', function (e){
+ var paymentMethod = jQuery('input[name=payment_method]:checked').val();
+ if("pointcheckout_card" === paymentMethod ) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ return pointcheckoutCardFormHandler(jQuery(this));
+ }
+});
+
+
+function showError(form, data) {
+ // Remove notices from all sources
+ jQuery( '.woocommerce-error, .woocommerce-message' ).remove();
+
+ // Add new errors returned by this event
+ if ( data.messages ) {
+ form.prepend( '
' + data.messages + '
' );
+ } else {
+ form.prepend( data );
+ }
+
+ // Lose focus for all fields
+ form.find( '.input-text, select, input:checkbox' ).blur();
+
+ // Scroll to top
+ jQuery( 'html, body' ).animate( {
+ scrollTop: ( jQuery( form ).offset().top - 100 )
+ }, 1000 );
+}
+
+function pointcheckoutCardFormHandler(form) {
+ if (form.is(".processing")) return !1;
+ initPointCheckoutCardPayment(form);
+}
+
+
+function initPointCheckoutCardPayment(form) {
+ var data = jQuery(form).serialize();
+ var ajaxUrl = wc_checkout_params.checkout_url;
+ jQuery.ajax({
+ 'url': ajaxUrl,
+ 'type': 'POST',
+ 'dataType': 'json',
+ 'data': data,
+ 'async': false
+ }).complete(function (response) {
+ data = '';
+ if(response.form) {
+ data = response;
+ }
+ else{
+ var code = response.responseText;
+ var newstring = code.replace(/
+
+
+form_fields = array(
+ 'enabled' => array(
+ 'title' => __('Enable/Disable', 'pointcheckout_card'),
+ 'type' => 'select',
+ 'label' => __('Enable the PointCheckout gateway', 'pointcheckout_card'),
+ 'default' => '0',
+ 'options' => array(
+ '1' => __('Enabled', 'pointcheckout_card'),
+ '0' => __('Disabled', 'pointcheckout_card'),
+ )
+ ),
+ 'description' => array(
+ 'title' => __('Description', 'pointcheckout_card'),
+ 'type' => 'text',
+ 'description' => __('This is the description the user sees during checkout.', 'pointcheckout_card'),
+ 'default' => __('Pay using your card', 'pointcheckout_card')
+ ),
+ 'mode' => array(
+ 'title' => 'Mode',
+ 'type' => 'select',
+ 'options' => $staging_enabled ? array(
+ '1' => __('live', 'pointcheckout_card'),
+ '0' => __('testing', 'pointcheckout_card'),
+ '2' => __('Staging', 'pointcheckout_card'),
+ ) : array(
+ '1' => 'live',
+ '0' => 'testing',
+ ),
+ 'default' => '0',
+ 'desc_tip' => true,
+ 'description' => sprintf(__('Logs additional information.
Log file path: %s', 'pointcheckout_card'), 'Your admin panel -> WooCommerce -> System Status -> Logs'),
+ 'placeholder' => '',
+ 'class' => 'wc-enhanced-select',
+ ),
+ 'Api_Key' => array(
+ 'title' => __('Api Key', 'pointcheckout_card'),
+ 'type' => 'text',
+ 'description' => __('Your Api Key, you can find in your PointCheckout account settings.', 'pointcheckout_card'),
+ 'default' => '',
+ 'desc_tip' => true,
+ 'placeholder' => ''
+ ),
+ 'Api_Secret' => array(
+ 'title' => __('Api Secret', 'pointcheckout_card'),
+ 'type' => 'text',
+ 'description' => __('Your Api Secret, you can find in your PointCheckout account settings.', 'pointcheckout_card'),
+ 'default' => '',
+ 'desc_tip' => true,
+ 'placeholder' => ''
+ ),
+ 'allow_specific' => array(
+ 'title' => __('Applicable Countries', 'pointcheckout_card'),
+ 'type' => 'select',
+ 'options' => array(
+ '0' => __('All Countries', 'pointcheckout_card'),
+ '1' => __('Specific countries only', 'pointcheckout_card')
+ )
+ ),
+ 'specific_countries' => array(
+ 'title' => __('Specific Countries', 'pointcheckout_card'),
+ 'desc' => '',
+ 'css' => 'min-width: 350px;min-height:300px;',
+ 'default' => 'wc_get_base_location()',
+ 'type' => 'multiselect',
+ 'options' => $this->getCountries()
+ ),
+ 'allow_user_specific' => array(
+ 'title' => __('Applicable User Roles', 'pointcheckout_card'),
+ 'type' => 'select',
+ 'options' => array(
+ '0' => __('All User Roles', 'pointcheckout_card'),
+ '1' => __('Specific Roles only', 'pointcheckout_card')
+ )
+ ),
+ 'specific_user_roles' => array(
+ 'title' => __('Specific User Roles', 'pointcheckout_card'),
+ 'desc' => '',
+ 'css' => 'min-width: 350px;min-height:300px;',
+ 'default' => 'wc_get_base_role()',
+ 'type' => 'multiselect',
+ 'options' => $this->getRoles()
+ )
+ );
+ }
+
+
+ function getCountries()
+ {
+ $countries_obj = new WC_Countries();
+ $countries = $countries_obj->__get('countries');
+
+ return $countries;
+ }
+
+ function getRoles()
+ {
+ global $wp_roles;
+ $all_roles = $wp_roles->roles;
+ $editable_roles = apply_filters('editable_roles', $all_roles);
+ $user_roles = array();
+
+ foreach ($editable_roles as $k => $v) {
+ $user_roles[$k] = $k;
+ }
+ return $user_roles;
+ }
+
+ function process_payment($order_id)
+ {
+ $order = new WC_Order($order_id);
+ if (!isset($_GET['response_code'])) {
+ update_post_meta($order->id, '_payment_method_title', 'Card');
+ update_post_meta($order->id, '_payment_method', 'pointcheckout_card');
+ }
+ $form = $this->paymentService->getPaymentRequestForm();
+ $note = $this->paymentService->getOrderHistoryMessage($form['response']->result->id, 0, $form['response']->result->status, '');
+ $order->add_order_note($note);
+ $result = array('result' => 'success', 'form' => $form['form']);
+ if (isset($_POST['woocommerce_pay']) && isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-pay')) {
+ wp_send_json($result);
+ exit;
+ } else {
+ return $result;
+ }
+ }
+
+
+
+ public function process_response()
+ {
+
+ global $woocommerce;
+ //send the secound call to pointcheckout to confirm payment
+ $success = $this->paymentService->checkPaymentStatus();
+
+ $order = wc_get_order($_REQUEST['reference']);
+ if ($success['success']) {
+ $order->payment_complete();
+ WC()->session->set('refresh_totals', true);
+ $redirectUrl = $this->get_return_url($order);
+ } else {
+ $redirectUrl = esc_url($woocommerce->cart->get_checkout_url());
+ $order->cancel_order();
+ }
+ echo '';
+ exit;
+ }
+}
diff --git a/pointcheckout_pointcheckoutpay/lib/pointcheckout/classes/Config.php b/pointcheckout_payment_card/includes/lib/class-pc-config.php
similarity index 66%
rename from pointcheckout_pointcheckoutpay/lib/pointcheckout/classes/Config.php
rename to pointcheckout_payment_card/includes/lib/class-pc-config.php
index cdf1722..0c29484 100755
--- a/pointcheckout_pointcheckoutpay/lib/pointcheckout/classes/Config.php
+++ b/pointcheckout_payment_card/includes/lib/class-pc-config.php
@@ -1,36 +1,25 @@
logFileDir = WC_LOG_DIR. 'pointcheckout.log';
-
- $this->init_settings();
$this->language = $this->_getShoppingCartConfig('language');
$this->enabled = $this->_getShoppingCartConfig('enabled');
$this->Api_Key = $this->_getShoppingCartConfig('Api_Key');
@@ -43,15 +32,16 @@ public function __construct()
$this->allowUserSpecific = $this->_getShoppingCartConfig('allow_user_specific');
$this->specific_uesr_roles = $this->_getShoppingCartConfig('specific_user_roles');
$this->new_order_status = $this->_getShoppingCartConfig('new_order_status');
+ $this->description = $this->_getShoppingCartConfig('description');
}
/**
- * @return PointCheckout_PointCheckoutPay_Config
+ * @return Config
*/
public static function getInstance()
{
if (self::$instance === null) {
- self::$instance = new PointCheckout_PointCheckoutPay_Config();
+ self::$instance = new PointCheckout_Card_Config();
}
return self::$instance;
}
@@ -67,7 +57,7 @@ public function getLanguage()
}
-
+
public function getEnabled()
{
return $this->enabled;
@@ -79,7 +69,7 @@ public function getMode()
}
-
+
public function getSuccessOrderStatusId()
@@ -87,7 +77,7 @@ public function getSuccessOrderStatusId()
return $this->successOrderStatusId;
}
-
+
public function isActive()
{
@@ -96,30 +86,35 @@ public function isActive()
}
return false;
}
-
- public function isSpecificCountries(){
- return $this->allowSpecific == 1?true:false;
+
+ public function isSpecificCountries()
+ {
+ return $this->allowSpecific == 1 ? true : false;
}
-
- public function getSpecificCountries(){
+
+ public function getSpecificCountries()
+ {
return $this->specific_countries;
}
-
- public function isSpecificUserRoles(){
- return $this->allowUserSpecific == 1?true:false;
+
+ public function isSpecificUserRoles()
+ {
+ return $this->allowUserSpecific == 1 ? true : false;
}
-
- public function getSpecificUserRoles(){
+
+ public function getSpecificUserRoles()
+ {
return $this->specific_uesr_roles;
}
-
- public function getNewOrderStatus(){
+
+ public function getNewOrderStatus()
+ {
return $this->new_order_status;
}
-
-
-
+
+
+
public function getOrderPlacement()
{
return $this->orderPlacement;
@@ -141,33 +136,33 @@ public function orderPlacementIsOnSuccess()
return false;
}
- public function isEnabled(){
- return $this->enabled == 1?true:false;
+ public function isEnabled()
+ {
+ return $this->enabled == 1 ? true : false;
}
- public function getApiKey(){
+ public function getApiKey()
+ {
return $this->Api_Key;
}
-
- public function getApiSecret(){
+
+ public function getApiSecret()
+ {
return $this->Api_Secret;
}
-
- public function isLiveMode(){
- return $this->Mode == 1?true:false;
- }
-
- public function isStagingMode(){
- return $this->Mode == 2?true:false;
- }
-
+ public function isLiveMode()
+ {
+ return $this->Mode == 1 ? true : false;
+ }
- public function getLogFileDir()
+ public function isStagingMode()
{
- return $this->logFileDir;
+ return $this->Mode == 2 ? true : false;
}
+ public function getDescription()
+ {
+ return $this->description;
+ }
}
-
-?>
\ No newline at end of file
diff --git a/pointcheckout_pointcheckoutpay/lib/pointcheckout/classes/Order.php b/pointcheckout_payment_card/includes/lib/class-pc-order.php
similarity index 88%
rename from pointcheckout_pointcheckoutpay/lib/pointcheckout/classes/Order.php
rename to pointcheckout_payment_card/includes/lib/class-pc-order.php
index e3d63bb..55b2c9d 100755
--- a/pointcheckout_pointcheckoutpay/lib/pointcheckout/classes/Order.php
+++ b/pointcheckout_payment_card/includes/lib/class-pc-order.php
@@ -1,17 +1,10 @@
pfConfig = PointCheckout_PointCheckoutPay_Config::getInstance();
- }
public function loadOrder($orderId)
{
@@ -112,5 +105,3 @@ public function getStatusId()
}
}
-
-?>
\ No newline at end of file
diff --git a/pointcheckout_payment_card/includes/lib/class-pc-parent.php b/pointcheckout_payment_card/includes/lib/class-pc-parent.php
new file mode 100755
index 0000000..b8db123
--- /dev/null
+++ b/pointcheckout_payment_card/includes/lib/class-pc-parent.php
@@ -0,0 +1,11 @@
+
\ No newline at end of file
diff --git a/pointcheckout_payment_card/includes/lib/class-pc-payment-service.php b/pointcheckout_payment_card/includes/lib/class-pc-payment-service.php
new file mode 100755
index 0000000..f4ed0f5
--- /dev/null
+++ b/pointcheckout_payment_card/includes/lib/class-pc-payment-service.php
@@ -0,0 +1,210 @@
+pcOrder = new PointCheckout_Card_Order();
+ $this->pcConfig = PointCheckout_Card_Config::getInstance();
+ $this->pcUtils = new PointCheckout_Card_Utils();
+ }
+
+ public static function getInstance()
+ {
+ if (self::$instance === null) {
+ self::$instance = new PointCheckout_Card_Payment();
+ }
+ return self::$instance;
+ }
+
+ public function getPaymentRequestParams()
+ {
+ $orderId = $this->pcOrder->getSessionOrderId();
+ $order = new WC_order($orderId);
+ $this->pcOrder->loadOrder($orderId);
+ $order->update_status($this->pcConfig->getNewOrderStatus());
+
+ $params = array(
+ 'transactionId' => $orderId,
+ );
+
+ $cartItems = $order->get_items();
+ $items = array();
+ $i = 0;
+ foreach ($cartItems as $item_id => $item_data) {
+ $product = $item_data->get_product();
+ $item = (object) array(
+ 'name' => $product->get_name(),
+ 'sku' => $product->get_sku(),
+ 'quantity' => $item_data->get_quantity(),
+ 'type' => $product->get_type(),
+ 'total' => $item_data->get_total()
+ );
+ //in case of bundles the bundle group item total is set to zero here to prevent conflict in totals
+ if ($product->get_type() == 'bundle') {
+ $item->total = 0;
+ }
+ $items[$i++] = $item;
+ }
+ $params['items'] = array_values($items);
+ $params['amount'] = $this->pcOrder->getTotal();
+ $params['tax'] = $this->pcOrder->getTaxAmount();
+ $params['shipping'] = $this->pcOrder->getShippingAmount();
+ $params['subtotal'] = $this->pcOrder->getSubtotal();
+ $params['discount'] = $this->pcOrder->getDiscountAmount();
+ $params['currency'] = $this->pcOrder->getCurrencyCode();
+ $params['paymentMethods'] = ["CARD"];
+ $params['resultUrl'] = get_site_url() . "?wc-api=wc_gateway_pointcheckout_card_process_response";
+
+ $customer = array();
+
+ $billingAddress = array();
+ $billingAddress['name'] = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
+ $billingAddress['address1'] = $order->get_billing_address_1();
+ $billingAddress['address2'] = $order->get_billing_address_2();
+ $billingAddress['city'] = $order->get_billing_city();
+ $billingAddress['country'] = $order->get_billing_country();
+
+ $shippingAddress = array();
+ $shippingAddress['name'] = $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name();
+ $shippingAddress['address1'] = $order->get_shipping_address_1();
+ $shippingAddress['address2'] = $order->get_shipping_address_2();
+ $shippingAddress['city'] = $order->get_shipping_city();
+ $shippingAddress['country'] = $order->get_shipping_country();
+
+ $customer['billingAddress'] = $billingAddress;
+ $customer['shippingAddress'] = $shippingAddress;
+ $customer['firstname'] = $order->get_billing_first_name();
+ $customer['lastname'] = $order->get_billing_last_name();
+ $customer['email'] = $order->get_billing_email();
+ $customer['phone'] = $order->get_billing_phone();
+
+ $params['customer'] = $customer;
+
+ return $params;
+ }
+
+ /**
+ * build payment form
+ */
+ public function getPaymentRequestForm()
+ {
+
+ if (!$this->pcConfig->isEnabled()) {
+ return null;
+ }
+ $paymentRequestParams = $this->getPaymentRequestParams();
+ $response = $this->postCheckout($paymentRequestParams);
+ if (($response->success == 'true')) {
+ $actionUrl = $response->result->redirectUrl;
+ WC()->session->set('checkoutId', $response->result->id);
+ } else {
+ $this->pcUtils->log('Failed while sending first request to pointchckout resone: ' . $response->error);
+ wc_add_notice(sprintf(__('Failed to process payment please try again later', 'error')));
+ $actionUrl = get_site_url() . '/index.php/checkout';
+ }
+ $this->pcOrder->clearSessionCurrentOrder();
+ $form = '