Changeset 2298 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-dashboard.php
- Timestamp:
- 01/15/2016 06:07:53 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments-network/includes/payment-requests-dashboard.php
r2273 r2298 489 489 } 490 490 } 491 492 /**493 * Currency Conversion494 *495 * @param string $from What currency are we selling.496 * @param string $to What currency are we buying.497 * @param float $amount How much we're selling.498 *499 * @return float Converted amount.500 */501 public static function convert_currency( $from, $to, $amount ) {502 global $wpdb;503 504 $from = strtolower( $from );505 $to = strtolower( $to );506 $cache_key = md5( sprintf( 'wcp-exchange-rate-%s:%s', $from, $to ) );507 508 $rate = 0;509 if ( false === ( $rate = get_transient( $cache_key ) ) ) {510 $url = 'https://query.yahooapis.com/v1/public/yql';511 $url = add_query_arg( 'format', 'json', $url );512 $url = add_query_arg( 'env', rawurlencode( 'store://datatables.org/alltableswithkeys' ), $url );513 $url = add_query_arg( 'q', rawurlencode( $wpdb->prepare( 'select * from yahoo.finance.xchange where pair = %s', $from . $to ) ), $url );514 515 $request = wp_remote_get( esc_url_raw( $url ) );516 $body = json_decode( wp_remote_retrieve_body( $request ), true );517 518 if ( ! empty( $body['query']['results']['rate']['Ask'] ) ) {519 $rate = floatval( $body['query']['results']['rate']['Ask'] );520 }521 522 set_transient( $cache_key, $rate, 24 * HOUR_IN_SECONDS );523 }524 525 if ( $rate < 0.0000000001 )526 return 0;527 528 return $amount * $rate;529 }530 491 }
Note: See TracChangeset
for help on using the changeset viewer.