• Resolved zetsubobilly

    (@zetsubobilly)


    Hi. I’m trying to implement a paypal checkout feature with Woocommerce. We do that by using the Woocommerce PayPal gateway for checkout. We want to have our default currency as BGN. The problem is PayPal doesn’t support Bulgarian lev so we have to find a way to change the currency to EUR on checkout. I found some code snippet that I used in functions.php of our child time.

    
    <?php
    // allow BGN for WooCommerce and PayPal
    add_filter( 'woocommerce_paypal_supported_currencies', 'add_bgn_paypal_valid_currency' );
        function add_bgn_paypal_valid_currency( $currencies ) {
         array_push ( $currencies , 'BGN' );
         return $currencies;
        }
    
    // Convert BGN to EUR for PayPal payments
    add_filter('woocommerce_paypal_args', 'convert_bgn_to_eur');
    function convert_bgn_to_eur($paypal_args){
    
    	
    	if ( $paypal_args['currency_code'] == 'BGN'){
    		$convert_rate = 1.955; //set the converting rate
    		$paypal_args['currency_code'] = 'EUR'; //change BGN to EUR
    		$i = 1;
    		
    		while (isset($paypal_args['amount_' . $i])) {
    			$paypal_args['amount_' . $i] = round( $paypal_args['amount_' . $i] / $convert_rate, 2);
    			++$i;
    		}
    
                    if (isset($paypal_args['tax_cart'])) {
                $paypal_args['tax_cart'] = round($paypal_args['tax_cart'] / $convert_rate, 2);
            }
    
            if (isset($paypal_args['shipping_1'])) {
                $paypal_args['shipping_1'] = round($paypal_args['shipping_1'] / $convert_rate, 2);
            }
    
            if ( $paypal_args['discount_amount_cart'] > 0 ) {
    $paypal_args['discount_amount_cart'] = round( $paypal_args['discount_amount_cart'] / $convert_rate, 2);
                    }
    		}
                    return $paypal_args;
    }
    

    The issue here is the woocommerce_paypal_args filter. I doubt that it’s working since it still returns an error when the user tries to make paypal purchase. Here is the response from PayPal:

    message: “[UNPROCESSABLE_ENTITY] The requested action could not be performed, semantically incorrect, or failed business validation. https://developer.paypal.com/docs/api/orders/v2/#error-CURRENCY_NOT_SUPPORTED&#8221;
    name: “UNPROCESSABLE_ENTITY”

    Now I’m sure the code called with the woocommerce_paypal_supported_currencies filter does work as it adds BGN as a currency code. Question is how to make the code called by the woocommerce_paypal_args filter actually work? I’ve tried debugging it but it doesn’t return anything. Is this filter working at all?

    Woocommerce version: 5.9.0

    • This topic was modified 3 years, 3 months ago by zetsubobilly.
    • This topic was modified 3 years, 3 months ago by zetsubobilly.
    • This topic was modified 3 years, 3 months ago by zetsubobilly.
    • This topic was modified 3 years, 3 months ago by zetsubobilly.
    • This topic was modified 3 years, 3 months ago by zetsubobilly.
    • This topic was modified 3 years, 3 months ago by zetsubobilly.
    • This topic was modified 3 years, 3 months ago by zetsubobilly.
    • This topic was modified 3 years, 3 months ago by zetsubobilly. Reason: final changes
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @zetsubobilly!

    Since this requires custom coding, I’m leaving this thread open for a bit to see if anyone can chime in to help you out.

    For additional assistance on this topic, we recommend contacting one of the customization experts listed on the WooCommerce Customizations Page.

    Also, if you visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack, you could find help from the community of open-source developers for WooCommerce that hangs in there.

    If you are using a PayPal plugin and need any help related to that, please contact us at WooCommerce.com > My Account > Support. You may need to create an account before you can access that page.
    ?
    We will be able to help you further there.

    Cheers!

    This thread has been inactive for a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Paypal currency BGN to EUR’ is closed to new replies.