function getAmount($price) { $taxamo = new Taxamo(new APIClient($privTocken, 'https://api.taxamo.com')); $transaction_line2 = new Input_transaction_line(); $transaction_line2->amount = $price; $transaction_line2->custom_id = 'line2'; $transaction_line2->product_type = 'e-service'; $transaction = new Input_transaction(); $transaction->currency_code = 'GBP'; // whose currency code ? our or the customers ? //propagate customer's IP address when calling API server-side $transaction->buyer_ip = "92.234.73.59"; $transaction->buyer_credit_card_prefix = "454638489"; // echo '>>>>>>>>'.$_SERVER['REMOTE_ADDR']; $transaction->billing_country_code = 'GB'; $transaction->force_country_code = 'GB'; $transaction->transaction_lines = array($transaction_line2); $resp = $taxamo->calculateTax(array('transaction' => $transaction)); $_SESSION['billing_country_code'] = $resp->transaction->billing_country_code; print_r($resp->transaction); return $resp->transaction; }
public static function record_transaction($transaction) { global $psts; $token = $psts->get_setting('taxamo_private_token'); if ($token && isset($transaction->billing_country_code) && ProSites_Helper_Geolocation::is_EU($transaction->billing_country_code)) { $taxamo = new Taxamo(new APIClient($token, 'https://api.taxamo.com')); // Convert to Taxamo types (because of Swagger lib) $t = new Input_transaction(); // Add easy items (and avoid custom ones) $t_types = array_keys(get_object_vars($t)); foreach ($transaction as $key => $value) { if (!is_object($value) && in_array($key, $t_types)) { $t->{$key} = $value; } } // Convert line items $lines = array(); foreach ($transaction->transaction_lines as $line) { $l = new Input_transaction_line(); foreach ($line as $key => $value) { if (!is_object($value)) { $l->{$key} = $value; } } $lines[] = $l; } $t->transaction_lines = $lines; // //// Evidence $t->evidence = new Evidence(); foreach ($transaction->evidence as $ek => $ev) { $t->evidence->{$ek} = new Evidence_schema(); foreach ($ev as $k => $v) { $t->evidence->{$ek}->{$k} = $v; } } $resp = $taxamo->createTransaction(array('transaction' => $t)); if (isset($resp) && isset($resp->transaction) && isset($resp->transaction->key)) { $taxamo->confirmTransaction($resp->transaction->key, null); } } }