API upgrade, bug fixes and pounds
-
The Public API Version 1 will be taken offline on November 30th, 2018, and version 2 works completely different. I needed to have my values represented in pounds rather than usd, therefore i have modified the code. and fixed a few bugs!
plugins/woo-altcoin-payment-gateway/lib/core/frontend/functions/CsWapgCoinCal.php
<?php namespace WooGateWayCoreLib\frontend\functions; /** * Frontend Functions * * @package WAPG Admin * @since 1.0.0 * @author CodeSolz <customer-service@codesolz.com> */ if ( ! defined( 'CS_WAPG_VERSION' ) ) { exit; } class CsWapgCoinCal { /** * Get Coin Price * * @param type $coinName */ public static function calcualteCoinPrice(){ check_ajax_referer(SECURE_AUTH_SALT, 'code'); $coin_info = sanitize_text_field($_POST['coin_info']); if( empty($coin_info) ){ echo json_encode(array('response' => false, 'msg' => 'Something Went Wrong! Please try again.')); }else{ $coinFullName = sanitize_text_field($_POST['coin_name']); $coin_info = explode( '__', $coin_info); $coinId = trim($coin_info[0]); // from about here // use Version 2 of the api $getCoinsIds = file_get_contents("https://api.coinmarketcap.com/v2/listings/"); if( $getCoinsIds ) { // decode the list of coins returned $getCoinsIs = json_decode($getCoinsIds ); // look for the coin i have selected bu going through the list foreach($getCoinsIs->data as $row) { // is it my coin if($row->website_slug==$coinId) { // yup so get the id of the coin (number index on coinmarketcap.com) $coinId = $row->id; // exit loop break; } } } // here we fixed a bug as it was an (int) rather than a (float) which was rounding // down the prices to an int therefore $1.99 would become $1.00 $cartTotal = (float)sanitize_text_field($_POST['cart_total']); // now access the version 2 api and convert the value to GBP, you could // use other FIAT currencies https://coinmarketcap.com/api/ $getMarketPrice = file_get_contents("https://api.coinmarketcap.com/v2/ticker/".$coinId."?convert=GBP"); if( $getMarketPrice ){ // decode the json $getMarketPrice = json_decode($getMarketPrice); // now extract the price for the coin in GBP $coinPrice = $getMarketPrice->data->quotes->GBP->price; // to about here $totalCoin = round( ((1/$coinPrice) * $cartTotal), 8); echo json_encode( array( 'response' => true, 'cartTotal' => $cartTotal, 'totalCoin' => $totalCoin, 'coinPrice' => $coinPrice, 'coinFullName' =>$coinFullName, 'coinAddress' => $coin_info[1] )); }else{ echo json_encode(array('response' => false, 'msg' => sprintf( __( '%s API couldn\'t reach! Please try again or contact customer support. %s', CS_WAPG_TEXTDOMAIN ), '<div class="woocommerce-error">', '</div>' ) ) ); } } exit; } }plugins/woo-altcoin-payment-gateway/lib/core/frontend/scripts/CsWapgScript.php
Also I fixed some bugs in CsWapgScript.php the You Pay box was not sitting right on the page, so i added some css to fix it style=”float:left;width:100%;” on the “You have to pay:” <H3> tag and id=”order_review” div.
There are also a couple of places where the dollar sign is hard coded so some small HTML changes, it would be good if it used the Woo commerce symbol we selected!
It would also be good if the conversion currency was an option in the control panel!
The topic ‘API upgrade, bug fixes and pounds’ is closed to new replies.