/* This macro will be parsed as PHP code (see http://www.php.net) The calculateshipping function is called every time a shipping calculation request is made by Shopify. The function must return an array of available shipping options, otherwise no shipping options will be returned to your customers. */ function calculateshipping($DATA) { /* do not edit above this line */ $_RATES = array(); $_STAMPS_USER = 'YOUR STAMPS.COM USERNAME'; $_STAMPS_PASS = 'YOUR STAMPS.COM PASSWORD'; $s = new StampsAPI($_STAMPS_USER,$_STAMPS_PASS); $s->setOrigin(null,$DATA['origin']['postal_code'],null); $s->setDestination($DATA['destination']['province'],$DATA['destination']['postal_code'],$DATA['destination']['country']); $packages = array( array('weight'=>10, 'length'=>8, 'width'=>5.25, 'height'=>3.125), //lb and inches ); $r = $s->getRate($packages); if ($r) { foreach ($r as $_r) { $_RATES[] = array( "service_name" => $_r['name'].($_r['businessdays']!=''?" ({$_r['businessdays']} Business days)":''), "service_code" => $_r['code'], "total_price" => $_r['amount']*100, //in cents "currency" => "USD", ); } } return $_RATES; /* do not edit below this line */ }