diff options
author | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-11-14 15:53:15 +0100 |
---|---|---|
committer | Marcello Stanisci <marcello.stanisci@inria.fr> | 2016-11-14 15:53:15 +0100 |
commit | cdf6c12262f37b0e44d6d2e693804f3749f73795 (patch) | |
tree | 7daa0295f9b99d1937f2714d2fda07c1d8367ec2 /doc/examples/generate_contract.php | |
parent | 7b20ec17a7f5e0f3166f9daff2357e1fd5349005 (diff) | |
parent | ad9764cb7ac78fcb32ee9de222cd8794e9d63737 (diff) | |
download | merchant-cdf6c12262f37b0e44d6d2e693804f3749f73795.tar.gz merchant-cdf6c12262f37b0e44d6d2e693804f3749f73795.tar.bz2 merchant-cdf6c12262f37b0e44d6d2e693804f3749f73795.zip |
Merge branch 'master' of ssh://taler.net/merchant
Diffstat (limited to 'doc/examples/generate_contract.php')
-rw-r--r-- | doc/examples/generate_contract.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/doc/examples/generate_contract.php b/doc/examples/generate_contract.php new file mode 100644 index 00000000..de9770f5 --- /dev/null +++ b/doc/examples/generate_contract.php @@ -0,0 +1,76 @@ +function make_contract($transaction_id, $now) @{ + $contract = + array ( + 'amount' => array ( + 'value' => 1, + 'fraction' => 0, + 'currency' => "KUDOS"), + 'max_fee' => array ( + 'value' => 0, + 'fraction' => 50000, + 'currency' => "KUDOS"), + 'transaction_id' => $transaction_id, + 'products' => array ( + array ( + 'description' => "Donation to charity program", + 'quantity' => 1, + 'price' => array ( + 'value' => 1, + 'fraction' => 0, + 'currency' => "KUDOS"), + 'product_id' => 0, + 'taxes' => array(), // No taxes for donations + 'delivery_date' => "/Date(" . $now->getTimestamp() . ")/", + 'delivery_location' => 'LNAME1')), + 'timestamp' => "/Date(" . $now->getTimestamp() . ")/", + 'expiry' => + "/Date(" . $now->add(new DateInterval('P2W'))->getTimestamp() . ")/", + 'refund_deadline' => + "/Date(" . $now->add(new DateInterval('P3M'))->getTimestamp() . ")/", + 'repurchase_correlation_id' => '', + 'fulfillment_url' => + "https://shop.com/fulfillment?" + . "transaction_id=$transaction_id×tamp=$now", + 'merchant' => array ( + 'address' => 'LNAME1', + 'name' => "Charity donations shop", + 'jurisdiction' => 'LNAME2'), + 'locations' => array ( + 'LNAME1' => + array ( + 'country' => 'Shop Country', + 'city' => 'Shop City', + 'state' => 'Shop State', + 'region' => 'Shop Region', + 'province' => 'Shop Province', + 'ZIP code' => 4908, + 'street' => 'Shop street', + 'street number' => 20), + 'LNAME2' => array ( + 'country' => 'Legal Country', + 'city' => Legal City', + 'state' => 'Legal State', + 'region' => 'Legal Region', + 'province' => 'Legal Province', + 'ZIP code' => 4908))); +@} + + +/* this variable is the JSON of a contract proposal, + see https://api.taler.net/api-merchant.html#post--contract + the second parameter is the transaction id */ +$transaction_id = rand(1,90000); // simplified, do not do this! +$proposal = make_contract($transaction_id, new DateTime('now')); + +# Here the frontend POSTs the proposal to the backend +$response = post_to_backend("/contract", $proposal); + +if (200 != $response->getResponseCode()) @{ + echo json_encode(array( + 'error' => "internal error", + 'hint' => "failed to generate contract", + 'detail' => $resp->body->toString() + ), JSON_PRETTY_PRINT); + return; +@} +echo $response->body; |