Skip to content

Commit 3dedc7e

Browse files
committed
Updated to version 1.2.7
1 parent 9615b4f commit 3dedc7e

27 files changed

+3666
-895
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ Anyone can use our plugin, but businesses listed in our **[Prohibited Business L
6969

7070
## 📜 Changelog
7171

72+
### V1.2.7
73+
74+
- Updated: Tested up to WordPress 6.9 & WooCommerce 10.3.6
75+
- New: New providers including UPI/IMPS for India (INR), Interac for Canada (CAD), Binance, Moonpay and more
76+
- New: Added Hosted checkout with multiple providers on one page, automatic customer location detection for higher conversions and page customization option
77+
- New: Added Custom payment provider option
78+
- Improved: Checkout on your own domain
79+
- Improved: Updated minimum amount for some providers
80+
- Fixed: USD bug for some providers
81+
7282
### V1.2.6
7383

7484
- Updated: Tested up to WooCommerce 10.2.2
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
<?php
2+
if (!defined('ABSPATH')) {
3+
exit;
4+
}
5+
6+
add_action('plugins_loaded', 'init_shieldclimbgateway_banxa_gateway');
7+
8+
function init_shieldclimbgateway_banxa_gateway() {
9+
if (!class_exists('WC_Payment_Gateway')) {
10+
return;
11+
}
12+
13+
class shieldclimb_Instant_Payment_Gateway_Banxa extends WC_Payment_Gateway {
14+
15+
protected $icon_url;
16+
protected $banxacom_wallet_address;
17+
protected $banxacom_custom_domain;
18+
19+
public function __construct() {
20+
$this->id = 'shieldclimb-banxa';
21+
$this->icon = sanitize_url($this->get_option('icon_url'));
22+
$this->method_title = esc_html__('ShieldClimb – banxa.com | Min USD20 | Auto Hide If Below Min', 'shieldclimb-high-risk-card-payment-gateway'); // Escaping title
23+
$this->method_description = esc_html__('High Risk Business Card Payment Gateway with Chargeback Protection and Instant USDC POLYGON Wallet Payouts using banxa.com infrastructure', 'shieldclimb-high-risk-card-payment-gateway'); // Escaping description
24+
$this->has_fields = false;
25+
26+
$this->init_form_fields();
27+
$this->init_settings();
28+
29+
$this->title = sanitize_text_field($this->get_option('title'));
30+
$this->description = sanitize_text_field($this->get_option('description'));
31+
32+
// Use the configured settings for redirect and icon URLs
33+
$this->banxacom_custom_domain = rtrim(str_replace(['https://','http://'], '', sanitize_text_field($this->get_option('banxacom_custom_domain'))), '/');
34+
$this->banxacom_wallet_address = sanitize_text_field($this->get_option('banxacom_wallet_address'));
35+
$this->icon_url = sanitize_url($this->get_option('icon_url'));
36+
37+
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
38+
}
39+
40+
public function init_form_fields() {
41+
$this->form_fields = array(
42+
'enabled' => array(
43+
'title' => esc_html__('Enable/Disable', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping title
44+
'type' => 'checkbox',
45+
'label' => esc_html__('Enable banxa.com payment gateway', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping label
46+
'default' => 'no',
47+
),
48+
'title' => array(
49+
'title' => esc_html__('Title', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping title
50+
'type' => 'text',
51+
'description' => esc_html__('Payment method title that users will see during checkout.', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping description
52+
'default' => esc_html__('Pay with Banxa (Credit Card)', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping default value
53+
'desc_tip' => true,
54+
),
55+
'description' => array(
56+
'title' => esc_html__('Description', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping title
57+
'type' => 'textarea',
58+
'description' => esc_html__('Payment method description that users will see during checkout.', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping description
59+
'default' => esc_html__('Credit Card Crypto On-Ramp (via Banxa)', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping default value
60+
'desc_tip' => true,
61+
),
62+
'banxacom_custom_domain' => array(
63+
'title' => esc_html__('Custom Domain', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping title
64+
'type' => 'text',
65+
'description' => esc_html__('Follow the custom domain guide to use your own domain name for the checkout pages and links.', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping description
66+
'default' => esc_html__('payment.shieldclimb.com', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping default value
67+
'desc_tip' => true,
68+
),
69+
'banxacom_wallet_address' => array(
70+
'title' => esc_html__('Wallet Address', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping title
71+
'type' => 'text',
72+
'description' => esc_html__('Insert your USDC (Polygon) wallet address to receive instant payouts. Payouts maybe sent in ETH or USDC or USDT (Polygon or BEP-20) or POL native token. Same wallet should work to receive all. Make sure you use a self-custodial wallet to receive payouts.', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping description
73+
'desc_tip' => true,
74+
),
75+
'icon_url' => array(
76+
'title' => esc_html__('Icon URL', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping title
77+
'type' => 'url',
78+
'description' => esc_html__('Enter the URL of the icon image for the payment method.', 'shieldclimb-high-risk-card-payment-gateway'), // Escaping description
79+
'desc_tip' => true,
80+
),
81+
);
82+
}
83+
// Add this method to validate the wallet address in wp-admin
84+
public function process_admin_options() {
85+
if (!isset($_POST['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'])), 'woocommerce-settings')) {
86+
WC_Admin_Settings::add_error(__('Nonce verification failed. Please try again.', 'shieldclimb-high-risk-card-payment-gateway'));
87+
return false;
88+
}
89+
$banxacom_admin_wallet_address = isset($_POST[$this->plugin_id . $this->id . '_banxacom_wallet_address']) ? sanitize_text_field( wp_unslash( $_POST[$this->plugin_id . $this->id . '_banxacom_wallet_address'])) : '';
90+
91+
// Check if wallet address starts with "0x"
92+
if (substr($banxacom_admin_wallet_address, 0, 2) !== '0x') {
93+
WC_Admin_Settings::add_error(__('Invalid Wallet Address: Please insert your USDC Polygon wallet address.', 'shieldclimb-high-risk-card-payment-gateway'));
94+
return false;
95+
}
96+
97+
// Check if wallet address matches the USDC contract address
98+
if (strtolower($banxacom_admin_wallet_address) === '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359') {
99+
WC_Admin_Settings::add_error(__('Invalid Wallet Address: Please insert your USDC Polygon wallet address.', 'shieldclimb-high-risk-card-payment-gateway'));
100+
return false;
101+
}
102+
103+
// Proceed with the default processing if validations pass
104+
return parent::process_admin_options();
105+
}
106+
public function process_payment($order_id) {
107+
$order = wc_get_order($order_id);
108+
$shieldclimbgateway_banxacom_currency = get_woocommerce_currency();
109+
$shieldclimbgateway_banxacom_total = $order->get_total();
110+
$shieldclimbgateway_banxacom_nonce = wp_create_nonce( 'shieldclimbgateway_banxacom_nonce_' . $order_id );
111+
$shieldclimbgateway_banxacom_callback = add_query_arg(array('order_id' => $order_id, 'nonce' => $shieldclimbgateway_banxacom_nonce,), rest_url('shieldclimbgateway/v1/shieldclimbgateway-banxacom/'));
112+
$shieldclimbgateway_banxacom_email = urlencode(sanitize_email($order->get_billing_email()));
113+
$shieldclimbgateway_banxacom_final_total = $shieldclimbgateway_banxacom_total;
114+
115+
if ($shieldclimbgateway_banxacom_currency === 'USD') {
116+
$shieldclimbgateway_banxacom_minimumcheck = $shieldclimbgateway_banxacom_total;
117+
} else {
118+
119+
$shieldclimbgateway_banxacom_minimumcheck_response = wp_remote_get('https://api.shieldclimb.com/control/convert.php?value=' . $shieldclimbgateway_banxacom_total . '&from=' . strtolower($shieldclimbgateway_banxacom_currency), array('timeout' => 30));
120+
121+
if (is_wp_error($shieldclimbgateway_banxacom_minimumcheck_response)) {
122+
// Handle error
123+
shieldclimbgateway_add_notice(__('Payment error:', 'shieldclimb-high-risk-card-payment-gateway') . __('Payment could not be processed due to failed currency conversion process, please try again', 'shieldclimb-high-risk-card-payment-gateway'), 'error');
124+
return null;
125+
} else {
126+
127+
$shieldclimbgateway_banxacom_minimumcheck_body = wp_remote_retrieve_body($shieldclimbgateway_banxacom_minimumcheck_response);
128+
$shieldclimbgateway_banxacom_minimum_conversion_resp = json_decode($shieldclimbgateway_banxacom_minimumcheck_body, true);
129+
130+
if ($shieldclimbgateway_banxacom_minimum_conversion_resp && isset($shieldclimbgateway_banxacom_minimum_conversion_resp['value_coin'])) {
131+
// Escape output
132+
$shieldclimbgateway_banxacom_minimum_conversion_total = sanitize_text_field($shieldclimbgateway_banxacom_minimum_conversion_resp['value_coin']);
133+
$shieldclimbgateway_banxacom_minimumcheck = (float)$shieldclimbgateway_banxacom_minimum_conversion_total;
134+
} else {
135+
shieldclimbgateway_add_notice(__('Payment error:', 'shieldclimb-high-risk-card-payment-gateway') . __('Payment could not be processed, please try again (unsupported store currency)', 'shieldclimb-high-risk-card-payment-gateway'), 'error');
136+
return null;
137+
}
138+
}
139+
}
140+
141+
if ($shieldclimbgateway_banxacom_minimumcheck < 20) {
142+
shieldclimbgateway_add_notice(__('Payment error:', 'shieldclimb-high-risk-card-payment-gateway') . __('Order total for this payment provider must be $20 USD or more.', 'shieldclimb-high-risk-card-payment-gateway'), 'error');
143+
return null;
144+
}
145+
146+
$shieldclimbgateway_banxacom_gen_wallet = wp_remote_get('https://api.shieldclimb.com/control/wallet.php?address=' . $this->banxacom_wallet_address .'&callback=' . urlencode($shieldclimbgateway_banxacom_callback), array('timeout' => 30));
147+
148+
if (is_wp_error($shieldclimbgateway_banxacom_gen_wallet)) {
149+
// Handle error
150+
shieldclimbgateway_add_notice(__('Wallet error:', 'shieldclimb-high-risk-card-payment-gateway') . __('Payment could not be processed due to incorrect payout wallet settings, please contact website admin', 'shieldclimb-high-risk-card-payment-gateway'), 'error');
151+
return null;
152+
} else {
153+
$shieldclimbgateway_banxacom_wallet_body = wp_remote_retrieve_body($shieldclimbgateway_banxacom_gen_wallet);
154+
$shieldclimbgateway_banxacom_wallet_decbody = json_decode($shieldclimbgateway_banxacom_wallet_body, true);
155+
156+
// Check if decoding was successful
157+
if ($shieldclimbgateway_banxacom_wallet_decbody && isset($shieldclimbgateway_banxacom_wallet_decbody['address_in'])) {
158+
// Store the address_in as a variable
159+
$shieldclimbgateway_banxacom_gen_addressIn = wp_kses_post($shieldclimbgateway_banxacom_wallet_decbody['address_in']);
160+
$shieldclimbgateway_banxacom_gen_polygon_addressIn = sanitize_text_field($shieldclimbgateway_banxacom_wallet_decbody['polygon_address_in']);
161+
$shieldclimbgateway_banxacom_gen_callback = sanitize_url($shieldclimbgateway_banxacom_wallet_decbody['callback_url']);
162+
// Save $banxacomresponse in order meta data
163+
$order->add_meta_data('shieldclimb_banxacom_tracking_address', $shieldclimbgateway_banxacom_gen_addressIn, true);
164+
$order->add_meta_data('shieldclimb_banxacom_polygon_temporary_order_wallet_address', $shieldclimbgateway_banxacom_gen_polygon_addressIn, true);
165+
$order->add_meta_data('shieldclimb_banxacom_callback', $shieldclimbgateway_banxacom_gen_callback, true);
166+
$order->add_meta_data('shieldclimb_banxacom_converted_amount', $shieldclimbgateway_banxacom_final_total, true);
167+
$order->add_meta_data('shieldclimb_banxacom_nonce', $shieldclimbgateway_banxacom_nonce, true);
168+
$order->save();
169+
} else {
170+
shieldclimbgateway_add_notice(__('Payment error:', 'shieldclimb-high-risk-card-payment-gateway') . __('Payment could not be processed, please try again (wallet address error)', 'shieldclimb-high-risk-card-payment-gateway'), 'error');
171+
172+
return null;
173+
}
174+
}
175+
176+
// Check if the Checkout page is using Checkout Blocks
177+
if (shieldclimbgateway_is_checkout_block()) {
178+
global $woocommerce;
179+
$woocommerce->cart->empty_cart();
180+
}
181+
182+
// Redirect to payment page
183+
return array(
184+
'result' => 'success',
185+
'redirect' => 'https://' . $this->banxacom_custom_domain . '/process-payment.php?address=' . $shieldclimbgateway_banxacom_gen_addressIn . '&amount=' . (float)$shieldclimbgateway_banxacom_final_total . '&provider=banxa&email=' . $shieldclimbgateway_banxacom_email . '&currency=' . $shieldclimbgateway_banxacom_currency,
186+
);
187+
}
188+
189+
public function shieldclimb_instant_payment_gateway_get_icon_url() {
190+
return !empty($this->icon_url) ? esc_url($this->icon_url) : '';
191+
}
192+
}
193+
194+
function shieldclimbgateway_add_instant_payment_gateway_banxa($gateways) {
195+
$gateways[] = 'shieldclimb_Instant_Payment_Gateway_Banxa';
196+
return $gateways;
197+
}
198+
add_filter('woocommerce_payment_gateways', 'shieldclimbgateway_add_instant_payment_gateway_banxa');
199+
}
200+
201+
// Add custom endpoint for changing order status
202+
function shieldclimbgateway_banxacom_change_order_status_rest_endpoint() {
203+
// Register custom route
204+
register_rest_route( 'shieldclimbgateway/v1', '/shieldclimbgateway-banxacom/', array(
205+
'methods' => 'GET',
206+
'callback' => 'shieldclimbgateway_banxacom_change_order_status_callback',
207+
'permission_callback' => '__return_true',
208+
));
209+
}
210+
add_action( 'rest_api_init', 'shieldclimbgateway_banxacom_change_order_status_rest_endpoint' );
211+
212+
// Callback function to change order status
213+
function shieldclimbgateway_banxacom_change_order_status_callback( $request ) {
214+
$order_id = absint($request->get_param( 'order_id' ));
215+
$shieldclimbgateway_banxacomgetnonce = sanitize_text_field($request->get_param( 'nonce' ));
216+
$shieldclimbgateway_banxacompaid_txid_out = sanitize_text_field($request->get_param('txid_out'));
217+
218+
// Check if order ID parameter exists
219+
if ( empty( $order_id ) ) {
220+
return new WP_Error( 'missing_order_id', __( 'Order ID parameter is missing.', 'shieldclimb-high-risk-card-payment-gateway' ), array( 'status' => 400 ) );
221+
}
222+
223+
// Get order object
224+
$order = wc_get_order( $order_id );
225+
226+
// Check if order exists
227+
if ( ! $order ) {
228+
return new WP_Error( 'invalid_order', __( 'Invalid order ID.', 'shieldclimb-high-risk-card-payment-gateway' ), array( 'status' => 404 ) );
229+
}
230+
231+
// Verify nonce
232+
if ( empty( $shieldclimbgateway_banxacomgetnonce ) || $order->get_meta('shieldclimb_banxacom_nonce', true) !== $shieldclimbgateway_banxacomgetnonce ) {
233+
return new WP_Error( 'invalid_nonce', __( 'Invalid nonce.', 'shieldclimb-high-risk-card-payment-gateway' ), array( 'status' => 403 ) );
234+
}
235+
236+
// Check if the order is pending and payment method is 'shieldclimb-banxa'
237+
if ( $order && $order->get_status() !== 'processing' && $order->get_status() !== 'completed' && 'shieldclimb-banxa' === $order->get_payment_method() ) {
238+
// Change order status to processing
239+
$order->payment_complete();
240+
/* translators: 1: Transaction ID */
241+
$order->add_order_note( sprintf(__('Payment completed by the provider TXID: %1$s', 'shieldclimb-high-risk-card-payment-gateway'), $shieldclimbgateway_banxacompaid_txid_out) );
242+
// Return success response
243+
return array( 'message' => 'Order marked as paid and status changed.' );
244+
} else {
245+
// Return error response if conditions are not met
246+
return new WP_Error( 'order_not_eligible', __( 'Order is not eligible for status change.', 'shieldclimb-high-risk-card-payment-gateway' ), array( 'status' => 400 ) );
247+
}
248+
}
249+
?>

0 commit comments

Comments
 (0)