-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathofferObject.js
More file actions
99 lines (74 loc) · 1.89 KB
/
offerObject.js
File metadata and controls
99 lines (74 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var fs = require('fs');
var path = require('path');
var jws = require('jws');
const {google} = require('googleapis');
var baseUrl = "";
exports.generateJWT = function(url) {
baseUrl = url;
var payload = getUncodedJWT(creatObject());
var key = require("./privatekey.json");
console.log(JSON.stringify(payload));
var signature = jws.sign({
header: { alg: 'RS256' },
payload: payload,
privateKey: key.private_key
});
console.log(signature);
return signature;
};
function creatObject() {
// var gpPath = __dirname + "/gpaySettings.json";
var settings = require("./gpaySettings.json"); //JSON.parse(fs.readFileSync(gpPath, "utf8"));
var issuerid = settings.issuerId;
var offer = {};
offer.classId = issuerid + "." + settings.offerClass;
offer.id = issuerid + "." + settings.offerObject;
offer.version = "1";
offer.state = "active";
offer.barcode = createBarcode(settings.barcode);
return offer;
}
function createBarcode(code) {
var barcode = {};
barcode.type = "upcA";
barcode.value = code;
barcode.label = "User Id";
barcode.alternateText = "12345";
return barcode;
}
//function createImage() {
// var imageData = [{
// mainImage :{
// kind : "walletobjects#image",
// sourceUri : {
// kind : "walletobjects#uri",
// uri : "",
// description : ""
// }
// }
// }];
//}
function getUncodedJWT(offer) {
var adate = new Date();
var seconds = Math.ceil(adate.getTime() / 1000);
var uJWT = {};
uJWT.iss = "usps-offer-poc@usps-offer-poc.iam.gserviceaccount.com";
uJWT.aud = "google";
uJWT.typ = "savetoandroidpay";
uJWT.iat = seconds;
uJWT.origins = [
"http://" + baseUrl,
"https://" + baseUrl,
"http://localhost:8080/",
"https://localhost:8080/"
];
uJWT.payload = {
offerObjects:[offer],
offerClasses: [],
loyaltyObjects: [],
giftCardClasses: [],
loyaltyClasses: [],
giftCardObjects: []
};
return uJWT;
}