Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2007
    Location
    Bronx, New York, United States
    Posts
    521
    Plugin Contributions
    3

    Default Better way to format currencies

    This is in regards to the FraudLabsPro contribution.

    Currently, the plugin pulls the raw number from the Orders table to fill in the "amount" field of the API call to FraudLabsPro server for processing. I've changed it from just pulling the value to the following:

    Code:
    $check_status = $db->Execute('select * FROM ' . TABLE_ORDERS . ' o LEFT JOIN ' . TABLE_CURRENCIES . ' c ON o.currency = c.code WHERE o.orders_id = ' . (int) $oID);
    
    
    ...
    
    $response = fetch('https://api.fraudlabspro.com/v2/order/screen', [
    'amount'          => round($check_status->fields['order_total'], $check_status->fields['decimal_places']), 
    ];
    So far this does the job, but I feel there might be a better way to format and round the numerical portion of the currency. (The 'amount' field according to the API of Fraudlabspro only accepts numerical data. So I can't pull from, say, the orders_total table and present the ['text'] portion of that table.)

    I tried to read through the ZenCart functions but couldn't figure out a better/easier way that reinventing the wheel per se.

    Any advice would be appreciated.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,587
    Plugin Contributions
    88

    Default Re: Better way to format currencies

    Quote Originally Posted by retched View Post
    This is in regards to the FraudLabsPro contribution.

    Currently, the plugin pulls the raw number from the Orders table to fill in the "amount" field of the API call to FraudLabsPro server for processing. I've changed it from just pulling the value to the following:

    Code:
    $check_status = $db->Execute('select * FROM ' . TABLE_ORDERS . ' o LEFT JOIN ' . TABLE_CURRENCIES . ' c ON o.currency = c.code WHERE o.orders_id = ' . (int) $oID);
    
    
    ...
    
    $response = fetch('https://api.fraudlabspro.com/v2/order/screen', [
    'amount'          => round($check_status->fields['order_total'], $check_status->fields['decimal_places']), 
    ];
    So far this does the job, but I feel there might be a better way to format and round the numerical portion of the currency. (The 'amount' field according to the API of Fraudlabspro only accepts numerical data. So I can't pull from, say, the orders_total table and present the ['text'] portion of that table.)

    I tried to read through the ZenCart functions but couldn't figure out a better/easier way that reinventing the wheel per se.

    Any advice would be appreciated.
    While not in the 'official' Zen Cart docs/functions, here's how I 'feed' currency values to PayPal (adapted for your usage):
    Code:
        'amount' => number_format((float)$check_status->fields['order_total'], (int)$check_status->fields['decimal_places'], '.', ''),

 

 

Similar Threads

  1. Better Way to do Downloads?
    By susb8383 in forum General Questions
    Replies: 2
    Last Post: 9 Apr 2011, 02:04 PM
  2. My currencies update is way out!
    By BREZ in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 7
    Last Post: 28 Nov 2008, 04:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR