public function process_payment( $order_id ) { $order = wc_get_order( $order_id ); $requestId = 'Ecomart' . uniqid(); // Payment API request $payment_payload = array( 'msisdn' => $order->get_billing_phone(), 'merchantNumber'=> $this->merchant_id, 'merchCode' => $this->merchant_id, 'amount' => $order->get_total(), 'requestId' => $requestId, 'vendor_code' => $this->vendor_code, 'api_key' => $this->api_key, 'checksum' => 'string', // replace if needed 'callbackurl' => $this->callback_url, ); $logger = wc_get_logger(); $logger->info( 'Sending Ecocash Payment Request: ' . json_encode( $payment_payload ), [ 'source' => 'ecocash' ] ); $payment_response = wp_remote_post( 'https://etlapp.etl.co.ls/prodpinfulpaymerchant/payment/', array( 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => json_encode( $payment_payload ), 'method' => 'POST', 'data_format' => 'body' )); if ( is_wp_error( $payment_response ) ) { wc_add_notice( 'Payment gateway error: ' . $payment_response->get_error_message(), 'error' ); return; } $payment_result = json_decode( wp_remote_retrieve_body( $payment_response ), true ); $logger->info( 'Ecocash Payment Response: ' . json_encode( $payment_result ), [ 'source' => 'ecocash' ] ); // If payment was accepted by gateway, then check transaction status if ( isset( $payment_result['responseCode'] ) && $payment_result['responseCode'] == '200' ) { sleep(5); // wait a few seconds before checking status $status_payload = array( 'transactionId' => $requestId, 'vendor_code' => $this->vendor_code, 'api_key' => $this->api_key, 'checksum' => 'string', // replace if needed ); $status_response = wp_remote_post( 'https://etlapp.etl.co.ls/prodpinfulpaymerchant/transactionstatus/', array( 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => json_encode( $status_payload ), 'method' => 'POST', 'data_format' => 'body' )); if ( is_wp_error( $status_response ) ) { wc_add_notice( 'Transaction status check failed: ' . $status_response->get_error_message(), 'error' ); return; } $status_result = json_decode( wp_remote_retrieve_body( $status_response ), true ); $logger->info( 'Ecocash Transaction Status Response: ' . json_encode( $status_result ), [ 'source' => 'ecocash' ] ); if ( isset( $status_result['txnstatus'] ) && $status_result['txnstatus'] == '200' ) { $order->payment_complete(); $order->add_order_note( 'Ecocash payment successful. Txn ID: ' . $requestId ); return array( 'result' => 'success', 'redirect' => $this->get_return_url( $order ), ); } else { $order->update_status( 'failed', 'Ecocash transaction failed or was not successful.' ); wc_add_notice( 'Transaction failed or was not confirmed.', 'error' ); return; } } else { wc_add_notice( 'Payment was not accepted. Please try again.', 'error' ); return; } }
Shop – ecomart
Welcome to ecomart Online Store
Blog
Contact Us
My account
Sign In
/
Register
Home
Shop
Pages
Become a Vendor
Wishlist
Cart
Checkout
My account
About Us
Compare
Contact Us
FAQs
Vendor
Store List
Dashboard
Account
Call us:
Help Line
0
Wishlist
Compare
Cart
0
All Categories
Uncategorized
Electronics
Technologies
Service
Econet
Track Order
Daily Deals
Home
>
Shop
Filters
Sort By :
Default sorting
Sort by popularity
Sort by average rating
Sort by latest
Sort by price: low to high
Sort by price: high to low
Show 9
Show 12
Show 24
Show 36
Add to cart
Quick View
Protected: Fibre
Rated
0
out of 5
0 reviews
R
1.00
Add to cart
Quick View
Front-end web development
Rated
0
out of 5
0 reviews
R
400.00
3% off
Add to cart
Quick View
Hisense Smart phone U601s Pro
Rated
0
out of 5
0 reviews
R
775.00
R
800.00
12% off
Add to cart
Quick View
Snug Qi Wireless Charging Power Bank
Rated
0
out of 5
0 reviews
R
880.00
R
1,000.00
8% off
Add to cart
Quick View
Ubiquiti Unifi Dual Band AC Lite AP
Rated
0
out of 5
0 reviews
R
2,020.00
R
2,200.00