Postage function with paypal

I’m very close to set my e-commerce website project online, but I have an issue with a postage function. I’m using a plugin originally created by texnixe here : Commerce Plugin - interest?, wich was upgraded by starckio in Cartkit : Shopping cart with PayPal!.
So, the template/controller and functions are exactly the same and everything works fine locally. But when I put the website on servor, the $postage variable doesn’t return any value to the paypal page.

The example given by texnite has the same issue : https://kylebean.co.uk/shop. When you click “add to cart”, and then “pay with paypal”, the postage doesn’t appear in the form.

This is here the cart.php plugin

<?php
function get_cart() {
    s::start();
    $cart = s::get('cart', array());
    return $cart;
}
 
function cart_logic($cart) {

    if (isset($_REQUEST['action'])) {
      $action = $_REQUEST['action'];
      $id = $_REQUEST['id'];
      switch ($action) {
          case 'add':
              if (isset($cart[$id])) {
                  $cart[$id]++;
              } else {
                  $cart[$id] = 1;
              }
              break;
          case 'remove':
              if (isset($cart[$id])) {
                  $cart[$id]--;
              } else {
                  $cart[$id] = 1;
              }
              break;
          case 'update':
              if (isset($_REQUEST['quantity'])) {
                  $quantity = intval($_REQUEST['quantity']);
                  if ($quantity < 1) {
                      unset($cart[$id]);
                  } else {
                      $cart[$id] = $quantity;                
                  }
              }
              break;
          case 'delete':
              if (isset($cart[$id])) {
                  unset($cart[$id]);
              }
              break;
      }
      s::set('cart', $cart);
    }
    
//    if (count($cart) == 0) {
//    	go(url('products'));        
//    }
    
    return $cart;
}

function cart_count($cart) {
    $count = 0;
    foreach ($cart as $id => $quantity) {
        $count += $quantity;
    }
    return $count;
}

function cart_postage($total) {
	    $postage;
	    switch ($total) {
	        case ($total < 10):
	            $postage = 2.5;
	            break;
	        case ($total < 30):
	            $postage = 3.5;
	            break;
	        case ($total < 75):
	            $postage = 5.5;
	            break;
	        case ($total < 150):
	            $postage = 8;
	            break;
	        default:
	            $postage = 10;
	    }
	    return $postage;
	}

I installed the kit locally and - at least in the PayPal sandbox - postage is included, but there seems to be something wrong with the total because of how tax is calculated.

Yes, I had noticed this error and that’s why I don’t use the latest version. But if you disable the ‘TVA’ function in the site settings, the problem is resolved. But … it means that I have to upgrade my version of Cartkit to the new one, and it’s still a lot of work.

Any idea why this does not work on the basic version, like on the site https://kylebean.co.uk/shop ?

I mean, if it’s working locally and not on servor, does that definitely means that it is a servor settings issue ?

On the kylebean site it seems to work correctly as well?

37

Hu ?? Weird, for me the postage doesn’t appear. Tested on chrome and firefox

I think it only appears once you log in to Paypal

Nope, I logged to Paypal and same thing. Do you see the postage with and without logging ? Or just with ?
I don’t like to see other things than the others, but it is maybe a good news…

This is my project : (…). Can you please test to add the book into cart and see if paypal is taking account the postage ?

I only see the postage when I log in or after Paypal has set a cookie. If I remove all Paypal data, I get to see this:

On your site, postage is not added.

Ok, thanks a lot for your screenshots and the test. I conclude that I have to set the new Cartkit version without TVA option and see if it’s working. I suspect that the paypal send button interferes with the send button of the uniform form for check payment, but that’s another story…

You could just change TVA calculation in the plugin.

function cart_vat($ttc, $vat) {
	$ht = $ttc * ($vat/100);
	return $ht;
}

But I’m not sure what that function is supposed to do. It says it calculated the tax but then returns a wrong price without tax, but from the text in the cart table I assume it is supposed to calculate the amount of VAT included in the final price. But then the tax should not be added (quite confusing, but maybe I don’t understand enough French)

Thanks. I don’t have any need of taxes, I’ll simply remove it from the plugin. I was just trying to display the postage onto the paypal paiement. I’m trying now to upgrade my Cartkit version, and I hope all will be fine.

In fact, the author assumes to have created a plugin still in development. BTW it’s a very smart plugin, but still confused as you say.

You can just set Tax to false in site.txt, I think, no need to fiddle with the plugin code in that case.

1 Like

This is what I intend to do :slight_smile:

I have created an issue on GitHub regarding the calculation stuff: https://github.com/starckio/Cartkit/issues/9

You’re on top form !!!

Oops, I’m re-openning this thread because after multiple tests, I see now that the problem come from languages. If I pay by paypal in English, the postage is set, but in French, it’s not.

I absolutely don’t know where to begin to solve that. I show you my config.php but I don’t know if it is related to…

// Settings
c::set('license', 'put your license key here');
c::set('panel.language', 'fr');
c::set('debug',true);
c::set('cache.ignore', array('cart',));
c::set('email.service', 'mail');

// Sitemap plugin
c::set('sitemap.images.license', 'http://creativecommons.org/licenses/by-nc-nd/4.0/');
c::set('sitemap.include.images', true);
c::set('sitemap.include.invisible', false);
c::set('sitemap.ignored.pages', ['informations']);
c::set('sitemap.ignored.templates', ['contact', 'projets']);
c::set('sitemap.frequency', true);
c::set('sitemap.priority', true);

// Languages
c::set('languages', array(
  array(
    'code'    => 'fr',
    'name'    => 'French',
    'locale'  => 'fr_FR',  
    'default' => true,
    'url'     => '/',
    'locale'  => array(
      LC_COLLATE  => 'fr_FR.utf8',
      LC_MONETARY => 'fr_FR.utf8',
      LC_NUMERIC  => 'fr_FR.utf8',
      LC_TIME     => 'fr_FR.utf8',
      LC_MESSAGES => 'fr_FR.utf8',
      LC_CTYPE    => 'fr_FR.utf8'
    )
  ),
  array(
    'code'    => 'en',
    'name'    => 'English',
    'locale'  => 'en_US',
    'url'     => '/en',
    'locale'  => array(
      LC_COLLATE  => 'en_US.utf8',
      LC_MONETARY => 'en_US.utf8',
      LC_NUMERIC  => 'en_US.utf8',
      LC_TIME     => 'en_US.utf8',
      LC_MESSAGES => 'en_US.utf8',
      LC_CTYPE    => 'en_US.utf8'
    )
  )
));

/*
---------------------------------------
User roles
--------------------------------------

*/

c::set('roles', array(
  array(
    'id'      => 'client',
    'name'    => 'Client',
    'default' => true,
    'panel'   => false
  ),
  array(
    'id'      => 'admin',
    'name'    => 'Admin',
    'panel'   => true
  )
));


/*

---------------------------------------
Routes
--------------------------------------

*/

c::set('routes', array(
  array(
    'pattern' => 'logout',
    'action'  => function() {
      if($user = site()->user()) $user->logout();
      go('login');
    }
  )
));

Even if I remove c::set('cache.ignore', array('cart',));, it doesn’t change.

You can try it by yourself : (…)

OK so…I replaced

array(
    'code'    => 'fr',
    'name'    => 'French',
    'locale'  => 'fr_FR',  
    'default' => true,
    'url'     => '/',
    'locale'  => array(
      LC_COLLATE  => 'fr_FR.utf8',
      LC_MONETARY => 'fr_FR.utf8',
      LC_NUMERIC  => 'fr_FR.utf8',
      LC_TIME     => 'fr_FR.utf8',
      LC_MESSAGES => 'fr_FR.utf8',
      LC_CTYPE    => 'fr_FR.utf8'
    )
  ),

by

array(
    'code'    => 'fr',
    'name'    => 'French',
    'locale'  => 'fr_FR',  
    'default' => true,
    'url'     => '/',
    'locale'  => array(
      LC_COLLATE  => 'en_US.utf8',
      LC_MONETARY => 'en_US.utf8',
      LC_NUMERIC  => 'en_US.utf8',
      LC_TIME     => 'en_US.utf8',
      LC_MESSAGES => 'en_US.utf8',
      LC_CTYPE    => 'en_US.utf8'
    )
  ),

It’s a bit tricky, but it’s working. I’m loosing X,XX to X.XX wich is typographically incorrect in French.

I don’t think you have to set all values to en, but just the numeric (doesn’t help typographically, I know, but at least it would preserve the other values). But I think Paypal should actually accept local values as well, probably just a matter of finding out how to do that.

I just wonder why it works for the product price but not the postage, where’s the difference?

Thanks for the clarification, but as I am lazy this question will not prevent me from sleeping :slight_smile: