Skip to content

Commit 26518f1

Browse files
authored
Merge pull request #152 from khrystynaklochko/main
Gift card generation app POC
2 parents 8e18955 + 0556b76 commit 26518f1

File tree

206 files changed

+59279
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+59279
-0
lines changed

7-defi-devpost/coupon/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

7-defi-devpost/coupon/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "coupon"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v0.8.0" }
8+
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v0.8.0" }
9+
10+
[dev-dependencies]
11+
transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v0.8.0" }
12+
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v0.8.0" }
13+
scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v0.8.0" }
14+
15+
[profile.release]
16+
opt-level = 's' # Optimize for size.
17+
lto = true # Enable Link Time Optimization.
18+
codegen-units = 1 # Reduce number of codegen units to increase optimizations.
19+
panic = 'abort' # Abort on panic.
20+
strip = "debuginfo" # Strip debug info.
21+
overflow-checks = true # Panic in the case of an overflow.
22+
23+
[lib]
24+
crate-type = ["cdylib", "lib"]
25+
26+
[workspace]
27+
# Set the package crate as its own empty workspace, to hide it from any potential ancestor workspace
28+
# Remove this [workspace] section if you intend the package to be part of a Cargo workspace

7-defi-devpost/coupon/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Coupon javascript app POC
2+
This is a blueprint application POC for potential use of Wallet SDK to create cupons for integration with e-commerce.
3+
I had troubles with registering an app and using npm package and happy to create js package if an idea kicks in!
4+
5+
For time being use js sample server to check a concept.
6+
- UI app is under `coupon-ui ` folder.
7+
- Server app is under `coupon-js ` folder.
8+
Instructions are inside README of each folder.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## POC server app for generating gift code coupons
2+
This app is generating encrypted gift code based on user id, amount and address to send to.
3+
Codes are encrypted with btoa and this can be later improved for a security reasons.
4+
Generated reference code can be shared and later executed as a payment transaction with Radix network and transaction will require further approvement.
5+
6+
### Start a server
7+
8+
Vanilla Node.js app
9+
10+
```npm install```
11+
12+
```node server```
13+
14+
15+
### API endpoint
16+
```POST /giftcode```
17+
18+
```json body: { "giftcode" : { "amount" : "40", id: "id", "to_address": "to_address" } }```
19+
20+
#### Expectations
21+
22+
if you trigger a request from your local:\
23+
\
24+
```http://127.0.0.1:3002/giftcode```\
25+
with a body:\
26+
```{ "giftcode" : { "amount" : "40", "id": "id", "to_address": "to_address" } }```\
27+
you should expect a response with a payment link inside:\
28+
\
29+
[
30+
{
31+
"message": "Successfully generated a code from URL",
32+
"giftcode": "dG9fYWRkcmVzczQwaWQ="
33+
}
34+
]
35+
36+
### API endpoint
37+
POC concept which will require further development for security and integration reasons.
38+
39+
```POST /redeemcode```
40+
41+
```json body: { "redeemcode" : { "giftcode" : "dG9fYWRkcmVzczQwaWQ=" } }```
42+
43+
#### Expectations
44+
45+
if you trigger a request from your local:\
46+
\
47+
```http://127.0.0.1:3002/redeem/code```\
48+
with a body:\
49+
```{ "redeemcode" : { "giftcode" : "dG9fYWRkcmVzczQwaWQ=" } }```\
50+
you should expect a response with a payment link inside:\
51+
\
52+
[
53+
{
54+
"message": "Successfully decoded payment details",
55+
"paymentDetails" : { "amount" : "40", "id": "id", "to_address": "to_address" }
56+
}
57+
]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
const giftCardObject = require('./couponUtil.js');
2+
3+
//Method to return giftcode
4+
exports.generate= function(req, res) {
5+
let body = '';
6+
7+
req.on('data', function (chunk) {
8+
body += chunk.toString();
9+
});
10+
11+
req.on('end', function () {
12+
console.log(body);
13+
let amount = JSON.parse(body).giftcode.amount
14+
let id = JSON.parse(body).giftcode.id
15+
let to_address = JSON.parse(body).giftcode.to_address
16+
17+
console.log('Amount', amount);
18+
console.log('Id', id);
19+
console.log('To address', to_address);
20+
21+
res.statusCode = 201;
22+
res.setHeader('content-Type', 'Application/json');
23+
giftCardObject.generate(to_address, id, amount).then((giftcode) => {
24+
console.log(giftcode);
25+
let response =
26+
{ "status": 200,
27+
"message": "Successfully generated a code from URL",
28+
"giftcode": giftcode
29+
}
30+
res.end(JSON.stringify(response));
31+
});
32+
33+
});
34+
35+
}
36+
37+
// Method to decode coupon
38+
exports.decode= function(req, res) {
39+
let body = '';
40+
41+
req.on('data', function (chunk) {
42+
body += chunk.toString();
43+
});
44+
45+
req.on('end', function () {
46+
console.log(body);
47+
let giftcode = JSON.parse(body).redeemcode.giftcode
48+
49+
console.log('Gift Code', giftcode);
50+
51+
res.statusCode = 201;
52+
res.setHeader('content-Type', 'Application/json');
53+
giftCardObject.decode(giftcode).then((decodeResponse) => {
54+
console.log(giftcode);
55+
let response =
56+
{ "status": 200,
57+
"message": "Successfully decoded payment details",
58+
"paymentDetails": decodeResponse
59+
}
60+
res.end(JSON.stringify(response))
61+
});
62+
63+
});
64+
65+
}
66+
67+
// Method to catch wrong requests
68+
exports.invalid = function(req, res) {
69+
var response = [
70+
{
71+
"message": "Gift code can not be generated"
72+
},
73+
availableEndpoints
74+
]
75+
res.statusCode = 404;
76+
res.setHeader('content-Type', 'Application/json');
77+
res.end(JSON.stringify(response))
78+
}
79+
80+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
3+
generate: function(to_address, id, amount) {
4+
return new Promise(function (resolve) {
5+
let reference = btoa(to_address+"$"+amount+"$"+id);
6+
resolve(reference);
7+
}).catch(err => {
8+
console.log('Error: ', err.message);
9+
reject();
10+
});;
11+
},
12+
13+
decode: function(giftcode) {
14+
return new Promise(function (resolve) {
15+
let reference = atob(giftcode);
16+
console.log('Reference', reference)
17+
let array = reference.split(/(\d+)/)
18+
let response = [
19+
{ "to_address": array[0],
20+
"amount": array[1],
21+
"id": array[2]
22+
},
23+
]
24+
resolve(response);
25+
}).catch(err => {
26+
console.log('Error: ', err.message);
27+
reject();
28+
});;
29+
},
30+
}
31+

7-defi-devpost/coupon/coupon-js-server/node_modules/.package-lock.json

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

7-defi-devpost/coupon/coupon-js-server/node_modules/asynckit/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)