Skip to content

Commit

Permalink
Merged latest master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ChetanGN committed Jul 29, 2024
2 parents 1498ef3 + ba0b5e8 commit 7bc181f
Show file tree
Hide file tree
Showing 18 changed files with 552 additions and 255 deletions.
51 changes: 0 additions & 51 deletions .github/workflows/security.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
env:
MYSQL_ROOT_PASSWORD: root
# Ensure docker waits for mariadb to start
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand Down
45 changes: 45 additions & 0 deletions checkout-block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;

final class WC_Razorpay_Blocks extends AbstractPaymentMethodType
{
protected $name = 'razorpay';

public function initialize()
{
$this->settings = get_option('woocommerce_razorpay_settings', []);
}

public function get_payment_method_script_handles()
{
wp_register_script(
'razorpay-blocks-integration',
plugin_dir_url(__FILE__) . 'checkout_block.js',
[
'wc-blocks-registry',
'wc-settings',
'wp-element',
'wp-html-entities',
'wp-i18n',
],
null,
true
);

if (function_exists('wp_set_script_translations'))
{
wp_set_script_translations('razorpay-blocks-integration');
}

return ['razorpay-blocks-integration'];
}

public function get_payment_method_data()
{
return [
'title' => 'Pay by Razorpay',
'description' => $this->settings['description'],
];
}
}
18 changes: 18 additions & 0 deletions checkout_block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const settings = window.wc.wcSettings.getSetting('razorpay_data', {});
const label = window.wp.htmlEntities.decodeEntities(settings.title) || window.wp.i18n.__('Razorpay for woocommerce', 'razorpay');
const Content = () => {
return window.wp.htmlEntities.decodeEntities(settings.description || '');
};
const Block_Gateway = {
name: 'razorpay',
label: label,
content: Object(window.wp.element.createElement)(Content, null ),
edit: Object(window.wp.element.createElement)(Content, null ),
canMakePayment: () => true,
ariaLabel: label,
supports: {
features: settings.supports,
},
};
window.wc.wcBlocksRegistry.registerPaymentMethod( Block_Gateway );

43 changes: 36 additions & 7 deletions includes/api/cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// Fetch cart data on cart and mini cart page

use Automattic\WooCommerce\Utilities\OrderUtil;
use Automattic\WooCommerce\Utilities\OrderUtil;

function fetchCartData(WP_REST_Request $request)
{
Expand Down Expand Up @@ -39,6 +39,10 @@ function fetchCartData(WP_REST_Request $request)

$response = cartResponse($couponCode);

$response['user'] = getCartUserObject();

$response['plugins'] = getPluginsDetails();

return new WP_REST_Response($response, 200);
}

Expand Down Expand Up @@ -90,9 +94,34 @@ function createCartData(WP_REST_Request $request)

$response = cartResponse($couponCode);

$response['user'] = getCartUserObject();

$response['plugins'] = getPluginsDetails();

return new WP_REST_Response($response, 200);
}

function getCartUserObject(): array {
$user = [
"logged_in" => false,
];
if (is_user_logged_in()) {
$current_user = wp_get_current_user();
$user['logged_in'] = true;
$user['email'] = $current_user->user_email;
}
return $user;
}

function getPluginsDetails(): array {
$pluginData = [];
if (is_plugin_active('woo-wallet/woo-wallet.php'))
{
$pluginData['terra-wallet'] = ['active' => true];
}
return $pluginData;
}

/**
* Create the cart object for the line items exist in order
*/
Expand Down Expand Up @@ -134,8 +163,8 @@ function getCartLineItem()
$cart = WC()->cart->get_cart();
$i = 0;

foreach($cart as $item_id => $item) {
$product = wc_get_product( $item['product_id']);
foreach($cart as $item_id => $item) {
$product = wc_get_product( $item['product_id']);
$price = round($item['line_subtotal']*100) + round($item['line_subtotal_tax']*100);

$type = "e-commerce";
Expand All @@ -146,15 +175,15 @@ function getCartLineItem()
if($product->is_type('variation')){
$parentProductId = $product->get_parent_id();
$parentProduct = wc_get_product($parentProductId);

if($parentProduct->get_type() == 'pw-gift-card' || $parentProduct->get_type() == 'gift-card'){
$type = 'gift_card';
}

}else{

if($product->get_type() == 'pw-gift-card' || $product->get_type() == 'gift-card'){
$type = 'gift_card';
$type = 'gift_card';
}
}
}
Expand All @@ -172,7 +201,7 @@ function getCartLineItem()
$data[$i]['variant_id'] = $item['variation_id'];
$data[$i]['offer_price'] = (empty($productDetails['sale_price'])=== false) ? (int) $productDetails['sale_price']*100 : $price/$item['quantity'];
$i++;
}
}

return $data;
}
Expand Down Expand Up @@ -220,7 +249,7 @@ function cartResponse($couponCode){

$response['enable_ga_analytics'] = get_option('woocommerce_razorpay_settings')['enable_1cc_ga_analytics'] === 'yes' ? true : false;
$response['enable_fb_analytics'] = get_option('woocommerce_razorpay_settings')['enable_1cc_fb_analytics'] === 'yes' ? true : false;

$response += ['redirect' => true, 'one_click_checkout' => true, 'mandatory_login' => false, 'key' => get_option('woocommerce_razorpay_settings')['key_id'], 'name' => html_entity_decode(get_bloginfo('name'), ENT_QUOTES), 'currency' => 'INR'];

return $response;
Expand Down
2 changes: 1 addition & 1 deletion includes/cron/one-click-checkout/one-cc-address-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ function createOneCCAddressSyncCron()
rzpLogInfo("createOneCCAddressSyncCron:426 - Adding option: ONE_CC_ADDRESS_SYNC_CRON_HOOK");
add_option(
Constants::ONE_CC_ADDRESS_SYNC_CRON_HOOK,
$data,
$data
);
rzpLogInfo("createOneCCAddressSyncCron:432 - Successfully Added option: ONE_CC_ADDRESS_SYNC_CRON_HOOK");
}
Expand Down
Loading

0 comments on commit 7bc181f

Please sign in to comment.