Skip to content

Commit

Permalink
Merge pull request #2 from dzung2t/master
Browse files Browse the repository at this point in the history
Updated latest lib and added User Profile API support
  • Loading branch information
Roman Sevastyanov committed Aug 3, 2015
2 parents 9ee03cd + 52f0be0 commit 79b8419
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 130 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2010-2014 Paymentwall, Inc.
Copyright (c) 2010-2015 Paymentwall, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#About WooCommerce module
Paymentwall module for WordPress WooCommerce.

### Requirement
* Woocommerce v2.0 or greater
* WordPress v3.8 or greater
* PHP 5.2.4 or greater

#Installation
To install Paymentwall WooCommerce module, please follow the [instructions](https://www.paymentwall.com/en/documentation/WooCommerce/1409).
To install Paymentwall WooCommerce module, please follow the [instructions](https://www.paymentwall.com/en/documentation/WooCommerce/1409).

After cloning the repository don't forget to install Paymentwall PHP API library (**required**):
`git submodule init` and then `git submodule update`
Binary file modified src/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 29 additions & 6 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

/*
* Plugin Name: Paymentwall for WooCommerce
* Plugin URI: http://www.paymentwall.com/
* Description: Paymentwall Gateway for WooCommerce
* Version: 1.0.0
* Plugin URI: https://www.paymentwall.com/en/documentation/WooCommerce/1409
* Description: Official Paymentwall module for WordPress WooCommerce.
* Version: 1.0.1
* Author: The Paymentwall Team
* Author URI: http://www.paymentwall.com/
* License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
* License: The MIT License (MIT)
*
*/

define('REQUEST_CHARGE_BACK', 2);
define('DEFAULT_SUCCESS_PINGBACK_VALUE', 'OK');
define('WC_ORDER_STATUS_PENDING', 'wc-pending');
define('WC_ORDER_STATUS_COMPLETED', 'wc-completed');
Expand All @@ -32,5 +31,29 @@ function WcPwGateway($methods)
}
add_filter('woocommerce_payment_gateways', 'WcPwGateway');
}
add_action('plugins_loaded', 'loadPaymentwallGateway', 0);

add_action('plugins_loaded', 'loadPaymentwallGateway', 0);
/**
* Require the woocommerce plugin installed first
*/
add_action('admin_init', 'child_plugin_has_parent_plugin');
function child_plugin_has_parent_plugin()
{
if (is_admin() && current_user_can('activate_plugins') && !is_plugin_active('woocommerce/woocommerce.php')) {
add_action('admin_notices', 'child_plugin_notice');

deactivate_plugins(plugin_basename(__FILE__));
if (isset($_GET['activate'])) {
unset($_GET['activate']);
}
}
}

function child_plugin_notice()
{
?>
<div class="error">
<p>Sorry, but Paymentwall Plugin requires the Woocommerce plugin to be installed and active.</p>
</div>
<?php
}
249 changes: 128 additions & 121 deletions src/paymentwall_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*
* Description: Official Paymentwall module for WordPress WooCommerce.
* Plugin URI: https://www.paymentwall.com/en/documentation/WooCommerce/1409
* Version: 1.0.0
* Version: 1.0.1
* Author: Paymentwall
* License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
* License: The MIT License (MIT)
*
*/

Expand Down Expand Up @@ -57,21 +57,20 @@ function receipt_page($order_id)

$order = new WC_Order($order_id);

$extraData = $this->prepareExtraPrarams($order);

$extraData = array_merge($extraData, array(
'email' => $order->billing_email,
'integration_module' => 'woocommerce',
'test_mode' => $this->settings['test_mode']
));

$widget = new Paymentwall_Widget(
$order->billing_email,
$this->settings['widget'],
array(
new Paymentwall_Product($order->id, $order->order_total, $order->order_currency, 'Order #' . $order->id)
),
$extraData
array_merge(
array(
'email' => $order->billing_email,
'integration_module' => 'woocommerce',
'test_mode' => $this->settings['test_mode']
),
$this->prepareUserProfileData($order)
)
);

$iframe = $widget->getHtmlCode(array(
Expand Down Expand Up @@ -130,62 +129,6 @@ function prepareProcessPaymentResult($order, $pageId)
);
}

/*
* Display administrative fields under the Payment Gateways tab in the Settings page
*/
function init_form_fields()
{

$this->form_fields = array(
'enabled' => array(
'title' => __('Enable/Disable', 'woocommerce'),
'type' => 'checkbox',
'label' => __('Enable the Paymentwall Payment Solution', 'woocommerce'),
'default' => 'yes'
),
'title' => array(
'title' => __('Title', 'woocommerce'),
'type' => 'text',
'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'),
'default' => __('Paymentwall', 'woocommerce')
),
'description' => array(
'title' => __('Description', 'woocommerce'),
'type' => 'text',
'description' => __('This controls the description which the user sees during checkout.', 'woocommerce'),
'default' => __("Pay via Paymentwall.", 'woocommerce')
),
'appkey' => array(
'title' => __('Project Key', 'woocommerce'),
'type' => 'text',
'description' => __('Your Paymentwall Project Key', 'woocommerce'),
'default' => ''
),
'secretkey' => array(
'title' => __('Secret Key', 'woocommerce'),
'type' => 'text',
'description' => __('Your Paymentwall Secret Key', 'woocommerce'),
'default' => ''
),
'widget' => array(
'title' => __('Widget Code', 'woocommerce'),
'type' => 'text',
'description' => __('Enter your preferred widget code', 'woocommerce'),
'default' => ''
),
'test_mode' => array(
'title' => __('Test Mode', 'woocommerce'),
'type' => 'select',
'description' => __('Enable test mode', 'woocommerce'),
'options' => array(
'0' => 'No',
'1' => 'Yes'
),
'default' => '0'
)
);
} // End init_form_fields()

/*
* Displays a short description to the user during checkout
*/
Expand Down Expand Up @@ -220,23 +163,32 @@ function ipnResponse()
// params not use in pingback signature
unset($_GET['wc-api']);
unset($_GET['action']);
$_GET['sign_version'] = Paymentwall_Signature_Abstract::VERSION_THREE;

$pingback = new Paymentwall_Pingback($_GET, $_SERVER['REMOTE_ADDR']);

if ($pingback->validate()) {

// Get Order Info
$order = new WC_Order(isset($_GET['goodsid']) ? $_GET['goodsid'] : false);
$result = $this->handlePingback(
$order,
isset($_GET['type']) ? $_GET['type'] : false,
isset($_GET ['reason']) ? $_GET ['reason'] : false
);
if ($order = new WC_Order($pingback->getProductId())) {

if ($pingback->isDeliverable()) {

// Call Delivery Confirmation API
if ($this->settings['enable_delivery']) {
// Delivery Confirmation
$delivery = new Paymentwall_GenerericApiObject('delivery');
$response = $delivery->post($this->prepareDeliveryConfirmationData($order));
}

$order->add_order_note(__('Paymentwall payment completed', 'woocommerce'));
$order->payment_complete();

} elseif ($pingback->isCancelable()) {
$order->update_status('cancelled', __('Reason: ' . $pingback->getParameter('reason'), 'woocommerce'));
}

if ($result) {
die(DEFAULT_SUCCESS_PINGBACK_VALUE);
} else {
die('Paymentwall IPN Request Failure');
die('Order Invalid!');
}

} else {
Expand All @@ -263,21 +215,6 @@ function ajaxResponse()
die(json_encode($return));
}

function handlePingback($order, $type, $reason)
{
if ($order) {
// Check request chargeback
if ($type == REQUEST_CHARGE_BACK) {
$order->update_status('cancelled', __('Reason: ' . $reason, 'woocommerce'));
} else {
$order->add_order_note(__('Paymentwall payment completed', 'woocommerce'));
$order->payment_complete();
}
return true;
}

return false;
}

function handleAction()
{
Expand Down Expand Up @@ -305,38 +242,108 @@ function getTemplate($templateFileName, $data)
return false;
}

function prepareExtraPrarams($order)
function prepareUserProfileData($order)
{
return array(
'customer[city]' => $order->billing_city,
'customer[state]' => $order->billing_state,
'customer[address]' => $order->shipping_address_1,
'customer[country]' => $order->shipping_country,
'customer[zip]' => $order->billing_postcode,
'customer[username]' => $order->billing_email,
'customer[firstname]' => $order->billing_first_name,
'customer[lastname]' => $order->billing_last_name,
'email' => $order->billing_email,
);
}

function prepareDeliveryConfirmationData($order)
{
return array(
'customer' => array(
'birthday' => '', // Unavailable
'sex' => '', // Unavailable
'firstname' => $order->billing_first_name,
'lastname' => $order->billing_last_name,
'street1' => $order->billing_address_1,
'street2' => $order->billing_address_2,
'city' => $order->billing_city,
'state' => $order->billing_state,
'postcode' => $order->billing_postcode,
'country' => $order->billing_country
'payment_id' => $order->payment_method,
'type' => 'digital',
'status' => 'delivered',
'estimated_delivery_datetime' => date('Y/m/d H:i:s'),
'estimated_update_datetime' => date('Y/m/d H:i:s'),
'refundable' => 'yes',
'details' => 'Item will be delivered via email by ' . date('Y/m/d H:i:s'),
'shipping_address[email]' => $order->billing_email,
'shipping_address[firstname]' => $order->shipping_first_name,
'shipping_address[lastname]' => $order->shipping_last_name,
'shipping_address[country]' => $order->shipping_country,
'shipping_address[street]' => $order->shipping_address_1,
'shipping_address[state]' => $order->shipping_state,
'shipping_address[phone]' => '',
'shipping_address[zip]' => $order->shipping_postcode,
'shipping_address[city]' => $order->shipping_city,
'reason' => 'none',
'is_test' => $this->settings['test_mode'] ? 1 : 0,
'product_description' => '',
);
}

/*
* Display administrative fields under the Payment Gateways tab in the Settings page
*/
function init_form_fields()
{
$this->form_fields = array(
'enabled' => array(
'title' => __('Enable/Disable', 'woocommerce'),
'type' => 'checkbox',
'label' => __('Enable the Paymentwall Payment Solution', 'woocommerce'),
'default' => 'yes'
),
'shipping_address' => array(
'firstname' => $order->shipping_first_name,
'lastname' => $order->shipping_last_name,
'company' => $order->shipping_company,
'street1' => $order->shipping_address_1,
'street2' => $order->shipping_address_2,
'city' => $order->shipping_city,
'state' => $order->shipping_state,
'postcode' => $order->shipping_postcode,
'country' => $order->shipping_country
'title' => array(
'title' => __('Title', 'woocommerce'),
'type' => 'text',
'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'),
'default' => __('Paymentwall', 'woocommerce')
),
'carrier_type' => $order->get_shipping_method(),
'shipping_fee' => array(
'amount' => $order->get_total_shipping(),
'currency' => $order->get_order_currency()
'description' => array(
'title' => __('Description', 'woocommerce'),
'type' => 'text',
'description' => __('This controls the description which the user sees during checkout.', 'woocommerce'),
'default' => __("Pay via Paymentwall.", 'woocommerce')
),
'appkey' => array(
'title' => __('Project Key', 'woocommerce'),
'type' => 'text',
'description' => __('Your Paymentwall Project Key', 'woocommerce'),
'default' => ''
),
'secretkey' => array(
'title' => __('Secret Key', 'woocommerce'),
'type' => 'text',
'description' => __('Your Paymentwall Secret Key', 'woocommerce'),
'default' => ''
),
'widget' => array(
'title' => __('Widget Code', 'woocommerce'),
'type' => 'text',
'description' => __('Enter your preferred widget code', 'woocommerce'),
'default' => ''
),
'test_mode' => array(
'title' => __('Test Mode', 'woocommerce'),
'type' => 'select',
'description' => __('Enable test mode', 'woocommerce'),
'options' => array(
'0' => 'No',
'1' => 'Yes'
),
'default' => '1'
),
'enable_delivery' => array(
'title' => __('Enable Delivery Confirmation API', 'woocommerce'),
'type' => 'select',
'description' => '',
'options' => array(
'1' => 'Yes',
'0' => 'No'
),
'default' => '1'
)
);
}

}
} // End init_form_fields()
}

0 comments on commit 79b8419

Please sign in to comment.