Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: razorpay/razorpay-woocommerce
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.3.0
Choose a base ref
...
head repository: razorpay/razorpay-woocommerce
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.3.1
Choose a head ref
  • 6 commits
  • 2 files changed
  • 4 contributors

Commits on Nov 17, 2016

  1. Copy the full SHA
    a6e5904 View commit details

Commits on Dec 23, 2016

  1. [session] Improves session handling

    - Namespaces the session that holds razorpay payment ID by the
      WC-order-id
    - Also, do not recreate the order ID every time.
    Nemo committed Dec 23, 2016
    Copy the full SHA
    8056795 View commit details
  2. [session] Verifies value in sesssion against Razorpay API

    mayankamencherla authored and Nemo committed Dec 23, 2016
    Copy the full SHA
    6273ae5 View commit details
  3. Merge pull request #24 from razorpay/session-fix

    [session] Improves session handling
    captn3m0 authored Dec 23, 2016
    Copy the full SHA
    d55e189 View commit details
  4. [release] Version Bump

    Nemo committed Dec 23, 2016
    Copy the full SHA
    ac4bfd2 View commit details

Commits on Dec 26, 2016

  1. Copy the full SHA
    bfe51b4 View commit details
Showing with 105 additions and 57 deletions.
  1. +95 −34 razorpay-payments.php
  2. +10 −23 readme.txt
129 changes: 95 additions & 34 deletions razorpay-payments.php
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
Plugin Name: WooCommerce Razorpay Payments
Plugin URI: https://razorpay.com
Description: Razorpay Payment Gateway Integration for WooCommerce
Version: 1.3.0
Version: 1.3.1
Author: Razorpay
Author URI: https://razorpay.com
*/
@@ -23,6 +23,7 @@ class WC_Razorpay extends WC_Payment_Gateway
{
const BASE_URL = 'https://api.razorpay.com/';
const API_VERSION = 'v1';
// This one stores the WooCommerce Order Id
const SESSION_KEY = 'razorpay_wc_order_id';

public function __construct()
@@ -133,53 +134,112 @@ function receipt_page($order)
echo $this->generate_razorpay_form($order);
}

protected function getSessionKey($orderId)
{
return "razorpay_order_id.$orderId";
}

/**
* Generate razorpay button link
**/
public function generate_razorpay_form($order_id)
public function generate_razorpay_form($orderId)
{
global $woocommerce;
$order = new WC_Order($order_id);
$order = new WC_Order($orderId);

$redirect_url = get_site_url() . '/?wc-api=' . get_class($this);
$productinfo = "Order $order_id";
$productinfo = "Order $orderId";
$api = new Api($this->key_id, $this->key_secret);

$sessionKey = $this->getSessionKey($orderId);

try
{
$api = new Api($this->key_id, $this->key_secret);
// Calls the helper function to create order data
$data = $this->get_order_creation_data($order_id);

$razorpay_order = $api->order->create($data);

$woocommerce->session->set('razorpay_order_id', $razorpay_order['id']);
$razorpay_args = array(
'key' => $this->key_id,
'name' => get_bloginfo('name'),
'amount' => $order->order_total * 100,
'currency' => get_woocommerce_currency(),
'description' => $productinfo,
'prefill' => array(
'name' => $order->billing_first_name." ".$order->billing_last_name,
'email' => $order->billing_email,
'contact' => $order->billing_phone
),
'notes' => array(
'woocommerce_order_id' => $order_id
),
'order_id' => $razorpay_order['id']
);
$json = json_encode($razorpay_args);
$html = $this->generate_order_form($redirect_url, $json);
return $html;
$razorpayOrderId = $woocommerce->session->get($sessionKey);

// If we don't have an Order
// or the if the order is present in session but doesn't match what we have saved
if (($razorpayOrderId === null) or
(($razorpayOrderId and ($this->verifyOrderAmount($razorpayOrderId, $orderId)) === false)))
{
$razorpayOrderId = $this->createRazorpayOrderId(
$orderId, $sessionKey);
}
}
catch (Exception $e)
{
echo "RAZORPAY ERROR: Api could not be reached";
}

$razorpay_args = array(
'key' => $this->key_id,
'name' => get_bloginfo('name'),
'amount' => $order->order_total*100,
'currency' => get_woocommerce_currency(),
'description' => $productinfo,
'prefill' => array(
'name' => $order->billing_first_name." ".$order->billing_last_name,
'email' => $order->billing_email,
'contact' => $order->billing_phone
),
'notes' => array(
'woocommerce_order_id' => $orderId
),
'order_id' => $razorpayOrderId
);

$json = json_encode($razorpay_args);

$html = $this->generate_order_form($redirect_url,$json,$orderId);

return $html;
}

protected function createRazorpayOrderId($orderId, $sessionKey)
{
// Calls the helper function to create order data
global $woocommerce;

$api = new Api($this->key_id, $this->key_secret);

$data = $this->get_order_creation_data($orderId);
$razorpay_order = $api->order->create($data);

$razorpayOrderId = $razorpay_order['id'];

$woocommerce->session->set($sessionKey, $razorpayOrderId);

return $razorpayOrderId;
}

protected function verifyOrderAmount($razorpayOrderId, $orderId)
{
$order = new WC_Order($orderId);

$api = new Api($this->key_id, $this->key_secret);

$razorpayOrder = $api->order->fetch($razorpayOrderId);

$razorpayOrderArgs = array(
'id' => $razorpayOrderId,
'amount' => (int) $order->order_total*100,
'currency' => get_woocommerce_currency(),
'receipt' => (string) $orderId,
);

$orderKeys = array_keys($razorpayOrderArgs);

foreach ($orderKeys as $key)
{
if ($razorpayOrderArgs[$key] !== $razorpayOrder[$key])
{
return false;
}
}

return true;
}

/**
* Creates order data
**/
function get_order_creation_data($order_id)
{
$order = new WC_Order($order_id);
@@ -335,7 +395,8 @@ function check_razorpay_response()

else
{
$razorpay_order_id = $woocommerce->session->get('razorpay_order_id');
$sessionKey = $this->getSessionKey($order_id);
$razorpay_order_id = $woocommerce->session->get($sessionKey);
$razorpay_signature = $_POST['razorpay_signature'];

$signature = hash_hmac('sha256', $razorpay_order_id . '|' . $razorpay_payment_id, $key_secret);
33 changes: 10 additions & 23 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ Contributors: razorpay
Tags: razorpay, payments, india, woocommerce, ecommerce
Requires at least: 3.9.2
Tested up to: 4.7
Stable tag: 1.3.0
Stable tag: 1.3.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

@@ -17,28 +17,15 @@ This is compatible with both 2.4 and 2.5 series of WooCommerce.

== Installation ==

1. Download the plugin from [github releases](https://github.com/razorpay/razorpay-woocommerce/archive/1.2.11.zip)
2. Ensure you have latest version of WooCommerce plugin installed
3. Unzip and upload contents of the plugin to your /wp-content/plugins/ directory
4. Activate the plugin through the 'Plugins' menu in WordPress

If you have downloaded the plugin from GitHub or elsewhere, make sure
that the directory is named `woo-razorpay`.

This is how your directory structure should look like:

```
wordpress/
wp-content/
plugins/
woo-razorpay/
ca-bundle.crt
images/
LICENSE
razorpay-payments.php
readme.txt
woocommerce/
```
1. Install the plugin from the [Wordpress Plugin Directory](https://wordpress.org/plugins/woo-razorpay/).
2. To use this plugin correctly, you need to be able to make network requests. Please make sure that you have the php-curl extension installed.

== Dependencies ==

1. Wordpress v3.9.2 and later
2. Woocommerce v2.4 and later
3. PHP v5.6.0 and later
4. php-curl

== Configuration ==