diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml deleted file mode 100644 index 3b1a2fa8..00000000 --- a/.github/workflows/security.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: SecurityChecks -on: - pull_request: {} - push: - branches: ["master"] - schedule: - - cron: '30 20 * * *' -jobs: - semgrep: - name: Scan - runs-on: [ubuntu-latest] # nosemgrep : semgrep.dev/s/swati31196:github_provided_runner - steps: - - uses: actions/checkout@v2 - - uses: returntocorp/semgrep-action@v1 - with: - publishToken: ${{ secrets.SEMGREP_APP_TOKEN }} - publishDeployment: 339 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - workflow_status: - runs-on: [ ubuntu-latest ] # nosemgrep : semgrep.dev/s/swati31196:github_provided_runner - name: Update Status Check - needs: [ semgrep ] - if: always() - env: - githubCommit: ${{ github.event.pull_request.head.sha }} - steps: - - name: Set github commit id - run: | - if [ "${{ github.event_name }}" = "push" ] || [ "${{ github.event_name }}" = "schedule" ]; then - echo "githubCommit=${{ github.sha }}" >> $GITHUB_ENV - fi - exit 0 - - name: Failed - id: failed - if: (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && github.ref != 'refs/heads/master' - run: | - echo 'Failing the workflow for github security status check.' - curl -X POST -H "Content-Type: application/json" -H "Authorization: token ${{ github.token }}" \ - -d '{ "state" : "failure" , "context" : "github/security-status-check" , "description" : "github/security-status-check", "target_url" : "https://github.com/${{ github.repository }}" }' \ - https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.githubCommit }} - exit 1 - - name: Success - if: steps.failed.conclusion == 'skipped' || github.ref != 'refs/heads/master' - run: | - echo 'Status check has passed!' - curl -X POST -H "Content-Type: application/json" -H "Authorization: token ${{ github.token }}" \ - -d '{ "state" : "success" , "context" : "github/security-status-check" , "description" : "github/security-status-check", "target_url" : "https://github.com/${{ github.repository }}" }' \ - https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.githubCommit }} - exit 0 \ No newline at end of file diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 62209693..dc923b6e 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -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 diff --git a/checkout-block.php b/checkout-block.php new file mode 100644 index 00000000..94d239df --- /dev/null +++ b/checkout-block.php @@ -0,0 +1,45 @@ +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'], + ]; + } +} diff --git a/checkout_block.js b/checkout_block.js new file mode 100644 index 00000000..2054aec2 --- /dev/null +++ b/checkout_block.js @@ -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 ); + \ No newline at end of file diff --git a/includes/api/cart.php b/includes/api/cart.php index c3c70d33..e09986d8 100644 --- a/includes/api/cart.php +++ b/includes/api/cart.php @@ -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) { @@ -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); } @@ -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 */ @@ -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"; @@ -146,7 +175,7 @@ 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'; } @@ -154,7 +183,7 @@ function getCartLineItem() }else{ if($product->get_type() == 'pw-gift-card' || $product->get_type() == 'gift-card'){ - $type = 'gift_card'; + $type = 'gift_card'; } } } @@ -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; } @@ -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; diff --git a/includes/cron/one-click-checkout/one-cc-address-sync.php b/includes/cron/one-click-checkout/one-cc-address-sync.php index 74ebb9ad..babc3fae 100644 --- a/includes/cron/one-click-checkout/one-cc-address-sync.php +++ b/includes/cron/one-click-checkout/one-cc-address-sync.php @@ -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"); } diff --git a/includes/razorpay-affordability-widget.php b/includes/razorpay-affordability-widget.php index e4e5deb2..2f8cbd94 100644 --- a/includes/razorpay-affordability-widget.php +++ b/includes/razorpay-affordability-widget.php @@ -5,9 +5,9 @@ function addAffordabilityWidgetHTML() { $current_user = wp_get_current_user(); - if ((isAffordabilityWidgetTestModeEnabled() === false) or + if ((isAffordabilityWidgetTestModeEnabled() === false) or (isAffordabilityWidgetTestModeEnabled() and - ($current_user->has_cap('administrator') or + ($current_user->has_cap('administrator') or preg_match('/@razorpay.com$/i', $current_user->user_email)))) { echo '
@@ -17,7 +17,7 @@ function addAffordabilityWidgetHTML() + +