Errors
8 years ago
api
2 months ago
cron
2 years ago
support
5 months ago
debug.php
4 years ago
plugin-instrumentation.php
3 months ago
razorpay-affordability-widget.php
4 weeks ago
razorpay-route-actions.php
2 years ago
razorpay-route.php
4 weeks ago
razorpay-webhook.php
5 months ago
state-map.php
4 years ago
utils.php
3 years ago
utils.php
118 lines
| 1 | <?php |
| 2 | /** |
| 3 | * controls visibility of 1cc buttons |
| 4 | * checks test mode, metrics collection config |
| 5 | * NOTE: we add additional check to see if the config field exists as it may cause issues |
| 6 | * during plugin updates |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * payment plugins are loaded even if they are disabled which triggers the 1cc button flow |
| 11 | * we need to check if the plugin is disabled |
| 12 | */ |
| 13 | function isRazorpayPluginEnabled() |
| 14 | { |
| 15 | return ( |
| 16 | empty(get_option('woocommerce_razorpay_settings')['enabled']) === false |
| 17 | && 'yes' == get_option('woocommerce_razorpay_settings')['enabled'] |
| 18 | ); |
| 19 | } |
| 20 | |
| 21 | function isTestModeEnabled() |
| 22 | { |
| 23 | return ( |
| 24 | empty(get_option('woocommerce_razorpay_settings')['enable_1cc_test_mode']) === false |
| 25 | && 'yes' == get_option('woocommerce_razorpay_settings')['enable_1cc_test_mode'] |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | function is1ccEnabled() |
| 30 | { |
| 31 | return ( |
| 32 | empty(get_option('woocommerce_razorpay_settings')['enable_1cc']) === false |
| 33 | && 'yes' == get_option('woocommerce_razorpay_settings')['enable_1cc'] |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | function isProductSupported() |
| 38 | { |
| 39 | |
| 40 | } |
| 41 | |
| 42 | function isCartSupported() |
| 43 | { |
| 44 | |
| 45 | } |
| 46 | |
| 47 | function isDebugModeEnabled() |
| 48 | { |
| 49 | return ( |
| 50 | empty(get_option('woocommerce_razorpay_settings')['enable_1cc_debug_mode']) === false |
| 51 | && 'yes' == get_option('woocommerce_razorpay_settings')['enable_1cc_debug_mode'] |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | function isPdpCheckoutEnabled() |
| 56 | { |
| 57 | return ( |
| 58 | empty(get_option('woocommerce_razorpay_settings')['enable_1cc_pdp_checkout']) === false |
| 59 | && 'yes' == get_option('woocommerce_razorpay_settings')['enable_1cc_pdp_checkout'] |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | function isMiniCartCheckoutEnabled() |
| 64 | { |
| 65 | return ( |
| 66 | empty(get_option('woocommerce_razorpay_settings')['enable_1cc_mini_cart_checkout']) === false |
| 67 | && 'yes' == get_option('woocommerce_razorpay_settings')['enable_1cc_mini_cart_checkout'] |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | function isMandatoryAccCreationEnabled() |
| 72 | { |
| 73 | return ( |
| 74 | empty(get_option('woocommerce_razorpay_settings')['1cc_account_creation']) === false |
| 75 | && 'yes' == get_option('woocommerce_razorpay_settings')['1cc_account_creation'] |
| 76 | ); |
| 77 | } |
| 78 | function validateInput($route, $param) |
| 79 | { |
| 80 | $failure_reason = null; |
| 81 | |
| 82 | switch ($route) { |
| 83 | case 'list': |
| 84 | if (empty(sanitize_text_field($param['amount'])) === true) { |
| 85 | $failure_reason = 'Field amount is required.'; |
| 86 | } |
| 87 | break; |
| 88 | |
| 89 | case 'apply': |
| 90 | if (empty(sanitize_text_field($param['code'])) === true) { |
| 91 | $failure_reason = 'Field code is required.'; |
| 92 | |
| 93 | } elseif (empty(sanitize_text_field($param['order_id'])) === true) { |
| 94 | |
| 95 | $failure_reason = 'Field order id is required.'; |
| 96 | |
| 97 | } |
| 98 | break; |
| 99 | |
| 100 | case 'shipping': |
| 101 | if (empty(sanitize_text_field($param['order_id'])) === true) { |
| 102 | $failure_reason = 'Field order id is required.'; |
| 103 | |
| 104 | } elseif (empty($param['addresses']) === true) { |
| 105 | |
| 106 | $failure_reason = 'Field addresses is required.'; |
| 107 | |
| 108 | } |
| 109 | break; |
| 110 | |
| 111 | default: |
| 112 | |
| 113 | break; |
| 114 | } |
| 115 | |
| 116 | return $failure_reason; |
| 117 | } |
| 118 |