PHP code help

Discussion in 'PHP' started by shmizla, Aug 25, 2011.

  1. #1
    Hi,

    I need prices on my webpages be in Croatian kuna HRK (I have to show them in national currency by the law). I know that this is not PayPal supported currency. I had this problem already solved in on other sites (with Virtuemart). I put in payment gateway script to divide total sum with 7,4 (HRK-EUR ratio) to get amount in Euros and to send default currency euro to PayPal websites.

    Now, I want to do the same thing on other site (Wordpress) where I have php string: <input type="hidden" name="a3" value="'.$data['price']['total'].'">';

    I tried many possibilities to put divide with 7,4 but I can't do it right. I am not that good in PHP.

    I need help, please.
    Thank you.
     
    shmizla, Aug 25, 2011 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    You'll need to show more of your code:

    
    <?php
    
    $hrk = 7.47; //division rate for the Croatian Kuna
    
    $price = 1.00; // example 1euro
    
    $hrk_price = $price / $hrk; //Euro devided by Croatian Kuna
    
    echo number_format($hrk_price, 2, '.', ''); // 0.13 for 2 decimals  
    
    ?>
    
    PHP:
     
    MyVodaFone, Aug 25, 2011 IP
  3. shmizla

    shmizla Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    tnx.

    this is full code for paypal gateway:


    function gateway_paypal($data=""){

    global $wpdb;

    $gatewaycode = "";

    $gatewaycode .= '<form method="post" action="https://www.paypal.com/cgi-bin/webscr" name="checkout_paypal">';

    if($_POST['rec'] == 1){

    $gatewaycode .= '<input type="hidden" name="cmd" value="_xclick-subscriptions">
    <input type="hidden" name="a3" value="'.$data['price']['total'].'">';

    if(!isset($_POST['rec_days'])){
    $gatewaycode .= '<input type="hidden" name="p3" value="1">
    <input type="hidden" name="t3" value="M">
    <input type="hidden" name="src" value="1">
    <input type="hidden" name="sra" value="1">';
    }else{

    if($_POST['rec_days'] < 8){

    $gatewaycode .= '<input type="hidden" name="a3" value="'.$data['price']['total'].'">
    <input type="hidden" name="p3" value="'.$_POST['rec_days'].'">
    <input type="hidden" name="t3" value="D">
    <input type="hidden" name="src" value="1">
    <input type="hidden" name="sra" value="1">';

    }elseif($_POST['rec_days'] < 30){

    $numweeks = $_POST['rec_days']/7;
    $gatewaycode .= '<input type="hidden" name="a3" value="'.$data['price']['total'].'">
    <input type="hidden" name="p3" value="'.$numweeks.'">
    <input type="hidden" name="t3" value="W">
    <input type="hidden" name="src" value="1">
    <input type="hidden" name="sra" value="1">';

    }elseif($_POST['rec_days'] < 370){

    $nummonths = $_POST['rec_days']/30;
    $gatewaycode .= '<input type="hidden" name="a3" value="'.$data['price']['total'].'">
    <input type="hidden" name="p3" value="'.$nummonths.'">
    <input type="hidden" name="t3" value="M">
    <input type="hidden" name="src" value="1">
    <input type="hidden" name="sra" value="1">';
    }
    }


    }else{
    $gatewaycode .= '<input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="amount" value="'.$data['price']['total'].'">';
    }

    $gatewaycode .= '
    <input type="hidden" name="return" value="'.get_option('paypal_return').'?order_id='.$data['orderid'].'">
    <input type="hidden" name="cancel_return" value="'.get_option('paypal_cancel').'">
    <input type="hidden" name="notify_url" value="'.get_option('paypal_notify').'">
    <input type="hidden" name="item_name" value="'.strip_tags($data['description']).'">
    <input type="hidden" name="item_number" value="'.$data['orderid'].'">
    <input type="hidden" name="business" value="'.get_option('paypal_email').'">
    <input type="hidden" name="currency_code" value="'.get_option('paypal_currency').'">
    <input type="hidden" name="custom" value="'.$data['orderid'].'">
    <p class="CheckoutBtn"><a href="javascript:document.checkout_paypal.submit();">'.SPEC($GLOBALS['_LANG']['_checkout']) .'</a></p>

    </form>';

    return $gatewaycode;

    }
    It is WP couponpress gateway for paypal.
    I will also need to give default currency code - EURO to be sent to PayPAl.
     
    shmizla, Aug 25, 2011 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    All that code is the php file creating the html. You do the conversion in the php code that sends the price to the gateway - that's somewhere else in the code.
     
    Rukbat, Aug 25, 2011 IP
  5. shmizla

    shmizla Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    tnx, but I only need to value="'.$data['price']['total'].'" divide with 7,4
     
    shmizla, Aug 25, 2011 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    $price = round($data['price']['total'] / 7.4, 2);

    (Note - . not , for the decimal separator.)

    You can round it to as many digits as you need, but I think Euros go to 2 digits.
     
    Rukbat, Aug 25, 2011 IP
  7. stefke25

    stefke25 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    is anyone solve this problem??
    I need help about that code. I've the same problem like shmizla, but i dont know hot to figure it out.
    Tnx
     
    stefke25, Oct 25, 2012 IP