commit f8c673dd6ae62fe61ea0c6522c882b1ceb7b6e61
parent 08941e08132d632dd4b25f338ad65e39d5370c84
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Mon, 22 Feb 2016 11:44:57 +0100
Addressing #4180
Diffstat:
5 files changed, 95 insertions(+), 54 deletions(-)
diff --git a/src/frontend_blog/essay_cc-form.html b/src/frontend_blog/essay_cc-form.html
@@ -8,6 +8,9 @@
<h1>Credit card payment</h1>
</header>
<section id="main">
+ <em>This page only <u>simulates</u> a credit card payment, in order to make
+ the blog demo more realistic. Therefore <u>no data</u> will be sent when
+ submitting the form</em>
<h1>Enter your details</h1>
<p>We need a few details before proceeding with credit card payment</p>
<form>
diff --git a/src/frontend_blog/essay_contract.php b/src/frontend_blog/essay_contract.php
@@ -21,7 +21,7 @@
include("./blog_lib.php");
$article = get($_GET['article']);
if (null == $article){
- echo "Please land here just to buy articles";
+ echo message_from_missing_param("article", "/");
die();
}
// send contract
@@ -35,7 +35,8 @@
$fulfillment_url = url_rel("essay_fulfillment.php")
. '×tamp=' . $now->getTimestamp()
. '&tid=' . $transaction_id;
- $contract_json = generate_contract($amount_value,
+
+/* $contract_json = generate_contract($amount_value,
$amount_fraction,
$MERCHANT_CURRENCY,
$transaction_id,
@@ -44,7 +45,18 @@
$article,
$teatax,
$now,
- $fulfillment_url);
+ $fulfillment_url);*/
+
+ $contract_json = _generate_contract(array("amount_value" => $amount_value,
+ "amount_fraction" => $amount_fraction,
+ "currency" => $MERCHANT_CURRENCY,
+ "transaction_id" => $transaction_id,
+ "description" => trim($teaser),
+ "product_id" => $article,
+ "correlation_id" => $article,
+ "taxes" => $teatax,
+ "now" => $now,
+ "fulfillment_url" => $fulfillment_url));
$resp = give_to_backend($_SERVER['HTTP_HOST'],
"backend/contract",
$contract_json);
diff --git a/src/frontend_blog/essay_fulfillment.php b/src/frontend_blog/essay_fulfillment.php
@@ -22,15 +22,16 @@
$article = get($_GET['article']);
if (null == $article){
http_response_code(400);
- echo "<p>Bad request (article missing)</p>";
+ echo message_from_missing_param("article", "/");
return;
}
session_start();
$payments = &pull($_SESSION, 'payments', array());
$my_payment = &pull($payments, $article, array());
$pay_url = url_rel("essay_pay.php");
- $offering_url = url_rel("essay_offer.php", true);
+ $offering_url = url_rel("essay_fulfillment.php", true);
$offering_url .= "?article=$article";
+ //FIXME ispayed not always defined; wrap around some check
if (false == $payments[$article]['ispayed'] || null === $my_payment){
$tid = get($_GET['tid']);
$timestamp = get($_GET['timestamp']);
@@ -44,6 +45,18 @@
// restore contract
$now = new DateTime();
$now->setTimestamp(intval($timestamp));
+
+ $contract_rec = _generate_contract(array("amount_value" => 0,
+ "amount_fraction" => 50000,
+ "currency" => $MERCHANT_CURRENCY,
+ "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,
@@ -53,7 +66,7 @@
$article,
array(),
$now,
- get_full_uri());
+ get_full_uri());*/
$resp = give_to_backend($_SERVER['HTTP_HOST'],
"backend/contract",
$contract_rec);
diff --git a/src/frontend_lib/merchants.php b/src/frontend_lib/merchants.php
@@ -8,54 +8,63 @@
*/
function _generate_contract($args){
include("../frontend_lib/config.php");
- $contract = array ('amount' => array ('value' => $args['amount_value'],
- 'fraction' => $args['amount_fraction'],
- 'currency' => $args['currency']),
- 'max_fee' => array ('value' => 3,
- 'fraction' => 01010,
- 'currency' => $args['currency']),
- 'transaction_id' => $args['transaction_id'],
- 'products' => array (
- array ('description' => $args['desc'],
- 'quantity' => 1,
- 'price' => array ('value' => $args['amount_value'],
- 'fraction' => $args['amount_fraction'],
- 'currency' => $args['currency']),
- 'product_id' => $args['p_id'],
- 'taxes' => $args['taxes'],
- 'delivery_date' => "Some Date Format",
- 'delivery_location' => 'LNAME1')),
- 'timestamp' => "/Date(" . $args['now']->getTimestamp() . ")/",
- 'expiry' => "/Date(" . $args['now']->add(new DateInterval('P2W'))->getTimestamp() . ")/",
- 'refund_deadline' => "/Date(" . $args['now']->add(new DateInterval($REFUND_DELTA))->getTimestamp() . ")/",
- 'repurchase_correlation_id' => $args['corr_id'],
- 'fulfillment_url' => $args['fulfillment_url'],
- 'merchant' => array ('address' => 'LNAME2',
- 'name' => 'Free Software Foundations (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)));
+ $contract = array ('amount' =>
+ array ('value' => $args['amount_value'],
+ 'fraction' => $args['amount_fraction'],
+ 'currency' => $args['currency']),
+ 'max_fee' =>
+ array ('value' => 3,
+ 'fraction' => 01010,
+ 'currency' => $args['currency']),
+ 'transaction_id' => $args['transaction_id'],
+ 'products' => array (
+ array ('description' => $args['description'],
+ 'quantity' => 1,
+ 'price' =>
+ array ('value' => $args['amount_value'],
+ 'fraction' => $args['amount_fraction'],
+ 'currency' => $args['currency']),
+ 'product_id' => $args['product_id'],
+ 'taxes' => $args['taxes'],
+ 'delivery_date' => "Some Date Format",
+ 'delivery_location' => 'LNAME1')),
+ 'timestamp' => "/Date(" . $args['now']->getTimestamp() . ")/",
+ 'expiry' =>
+ "/Date(" . $args['now']->add(new DateInterval('P2W'))->getTimestamp() . ")/",
+ 'refund_deadline' =>
+ "/Date(" . $args['now']->add(new DateInterval($REFUND_DELTA))->getTimestamp() . ")/",
+ 'repurchase_correlation_id' => $args['correlation_id'],
+ 'fulfillment_url' => $args['fulfillment_url'],
+ 'merchant' =>
+ array ('address' => 'LNAME2',
+ 'name' => 'Free Software Foundations (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;
}
diff --git a/src/frontend_lib/util.php b/src/frontend_lib/util.php
@@ -11,6 +11,10 @@ function &pull(&$arr, $idx, $default) {
return $arr[$idx];
}
+function message_from_missing_param($missing, $link, $link_name="home page"){
+ return "<p>Bad request, no $missing given. Return to <a href=\"$link\">$link_name</a></p>";
+}
+
function article_state_to_str($article_state){
if(null == $article_state || !isset($article_state))
return "undefined state";