From d5ebd6cac98b44cf88eae9b26820bb744cf92c19 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 2 Mar 2016 14:36:24 +0100 Subject: refactor --- copylib/merchants.php | 72 +------------------------------ examples/blog/essay_contract.php | 37 ++++++---------- examples/blog/essay_fulfillment.php | 37 ++++++---------- examples/shop/generate_taler_contract.php | 26 +++++------ 4 files changed, 43 insertions(+), 129 deletions(-) diff --git a/copylib/merchants.php b/copylib/merchants.php index 1ae763c9..4f3c229a 100644 --- a/copylib/merchants.php +++ b/copylib/merchants.php @@ -6,7 +6,7 @@ * Taler-style amount (so it has the usual * triple). Moreover, `teatax` should be a *list* of taxes */ -function _generate_contract($args){ +function generate_contract($args){ $contract = array ('amount' => array ('value' => $args['amount_value'], 'fraction' => $args['amount_fraction'], @@ -68,76 +68,6 @@ function _generate_contract($args){ return $json; } -/** - * Return a contract proposition to forward to the backend - * Note that `teatax` is an associative array representing a - * Taler-style amount (so it has the usual - * triple). Moreover, `teatax` should be a *list* of taxes - */ -function generate_contract($amount_value, - $amount_fraction, - $currency, - $transaction_id, - $desc, - $p_id, - $corr_id, - $taxes, - $now, - $fulfillment_url){ - include("../frontend_lib/config.php"); - $contract = array ('amount' => array ('value' => $amount_value, - 'fraction' => $amount_fraction, - 'currency' => $currency), - 'max_fee' => array ('value' => 3, - 'fraction' => 01010, - 'currency' => $currency), - 'transaction_id' => $transaction_id, - 'products' => array ( - array ('description' => $desc, - 'quantity' => 1, - 'price' => array ('value' => $amount_value, - 'fraction' => $amount_fraction, - 'currency' => $currency), - 'product_id' => $p_id, - 'taxes' => $taxes, - 'delivery_date' => "Some Date Format", - 'delivery_location' => 'LNAME1')), - 'timestamp' => "/Date(" . $now->getTimestamp() . ")/", - 'expiry' => "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/", - 'refund_deadline' => "/Date(" . $now->add(new DateInterval($REFUND_DELTA))->getTimestamp() . ")/", - 'repurchase_correlation_id' => $corr_id, - 'fulfillment_url' => $fulfillment_url, - 'merchant' => array ('address' => 'LNAME2', - 'name' => 'Free Software Foundation (demo)', - 'jurisdiction' => 'LNAME3'), - - 'locations' => array ('LNAME1' => array ('country' => 'Test Country', - 'city' => 'Test City', - 'state' => 'Test State', - 'region' => 'Test Region', - 'province' => 'Test Province', - 'ZIP code' => 4908, - 'street' => 'test street', - 'street number' => 20), - 'LNAME2' => array ('country' => 'Test Country', - 'city' => 'Test City', - 'state' => 'Test State', - 'region' => 'Test Region', - 'province' => 'Test Province', - 'ZIP code' => 4908, - 'street' => 'test street', - 'street number' => 20), - 'LNAME3' => array ('country' => 'Test Country', - 'city' => 'Test City', - 'state' => 'Test State', - 'region' => 'Test Region', - 'province' => 'Test Province', - 'ZIP code' => 4908))); - $json = json_encode (array ('contract' => $contract), JSON_PRETTY_PRINT); - return $json; -} - - /** * Feed `$json` to the backend and return the "(pecl) http response object" diff --git a/examples/blog/essay_contract.php b/examples/blog/essay_contract.php index 23fb9fe6..6482a3b4 100644 --- a/examples/blog/essay_contract.php +++ b/examples/blog/essay_contract.php @@ -36,29 +36,20 @@ . '×tamp=' . $now->getTimestamp() . '&tid=' . $transaction_id; -/* $contract_json = generate_contract($amount_value, - $amount_fraction, - $MERCHANT_CURRENCY, - $transaction_id, - trim($teaser), - $article, - $article, - $teatax, - $now, - $fulfillment_url);*/ - - $contract_json = _generate_contract(array("amount_value" => $amount_value, - "amount_fraction" => $amount_fraction, - "currency" => $MERCHANT_CURRENCY, - "refund_delta" => $REFUND_DELTA, - "transaction_id" => $transaction_id, - "description" => trim($teaser), - "merchant_name" => "Free Software Foundation (demo)", - "product_id" => $article, - "correlation_id" => $article, - "taxes" => $teatax, - "now" => $now, - "fulfillment_url" => $fulfillment_url)); + $contract_json = generate_contract(array( + "amount_value" => $amount_value, + "amount_fraction" => $amount_fraction, + "currency" => $MERCHANT_CURRENCY, + "refund_delta" => $REFUND_DELTA, + "transaction_id" => $transaction_id, + "description" => trim($teaser), + "merchant_name" => "Free Software Foundation (demo)", + "product_id" => $article, + "correlation_id" => $article, + "taxes" => $teatax, + "now" => $now, + "fulfillment_url" => $fulfillment_url) + ); $resp = give_to_backend("backend/contract", $contract_json); $status_code = $resp->getResponseCode(); diff --git a/examples/blog/essay_fulfillment.php b/examples/blog/essay_fulfillment.php index 9bb73643..088735d9 100644 --- a/examples/blog/essay_fulfillment.php +++ b/examples/blog/essay_fulfillment.php @@ -52,29 +52,20 @@ $now = new DateTime(); $now->setTimestamp(intval($timestamp)); - $contract_rec = _generate_contract(array("amount_value" => 0, - "amount_fraction" => 50000, - "currency" => $MERCHANT_CURRENCY, - "refund_delta" => $REFUND_DELTA, - "merchant_name" => "Free Software Foundation (demo)", - "transaction_id" => intval($tid), - "description" => trim(get_title($article)), - "product_id" => $article, - "correlation_id" => $article, - "taxes" => array(), - "now" => $now, - "fulfillment_url" => get_full_uri())); - /* - $contract_rec = generate_contract(0, - 50000, - $MERCHANT_CURRENCY, - intval($tid), - trim(get_title($article)), - $article, - $article, - array(), - $now, - get_full_uri());*/ + $contract_rec = generate_contract(array( + "amount_value" => 0, + "amount_fraction" => 50000, + "currency" => $MERCHANT_CURRENCY, + "refund_delta" => $REFUND_DELTA, + "merchant_name" => "Free Software Foundation (demo)", + "transaction_id" => intval($tid), + "description" => trim(get_title($article)), + "product_id" => $article, + "correlation_id" => $article, + "taxes" => array(), + "now" => $now, + "fulfillment_url" => get_full_uri()) + ); $resp = give_to_backend("backend/contract", $contract_rec); if ($resp->getResponseCode() != 200){ diff --git a/examples/shop/generate_taler_contract.php b/examples/shop/generate_taler_contract.php index fd241d41..213632b3 100644 --- a/examples/shop/generate_taler_contract.php +++ b/examples/shop/generate_taler_contract.php @@ -55,18 +55,20 @@ $fulfillment_url = url_rel("fulfillment.php") . '&tid=' . $transaction_id; - $contract = _generate_contract(array("amount_value" => $amount_value, - "amount_fraction" => $amount_fraction, - "currency" => $currency, - "refund_delta" => 'P3M', - "transaction_id" => $transaction_id, - "description" => $desc, - "product_id" => $p_id, - "correlation_id" => "", - "merchant_name" => "Kudos Inc.", - "taxes" => array(), - "now" => $now, - "fulfillment_url" => $fulfillment_url)); +$contract = generate_contract(array( + "amount_value" => $amount_value, + "amount_fraction" => $amount_fraction, + "currency" => $currency, + "refund_delta" => 'P3M', + "transaction_id" => $transaction_id, + "description" => $desc, + "product_id" => $p_id, + "correlation_id" => "", + "merchant_name" => "Kudos Inc.", + "taxes" => array(), + "now" => $now, + "fulfillment_url" => $fulfillment_url) +); // pack the JSON for the contract -- cgit v1.2.3