Skip to content

Commit 866d4c4

Browse files
committed
Fixes to match the codelab originally created
1 parent d6a7aa3 commit 866d4c4

File tree

4 files changed

+120
-56
lines changed

4 files changed

+120
-56
lines changed

android_complete/app/src/main/java/com/google/android/gms/samples/wallet/activity/CheckoutActivity.kt

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ class CheckoutActivity : AppCompatActivity() {
5858
// TODO: Set an on-click listener on the "Add to Google Wallet" button
5959
addToGoogleWalletButton = layout.addToGoogleWalletButton.root
6060
addToGoogleWalletButton.setOnClickListener {
61-
walletClient.savePasses(newObjectJson, this, addToGoogleWalletRequestCode)
61+
walletClient.savePasses(
62+
TODO("Token goes here"),
63+
this,
64+
addToGoogleWalletRequestCode
65+
)
6266
}
6367
}
6468

@@ -99,27 +103,4 @@ class CheckoutActivity : AppCompatActivity() {
99103
}
100104
}
101105
}
102-
103-
// TODO: Create the pass object definition
104-
private val issuerEmail = "SERVICE_ACCOUNT_EMAIL"
105-
private val issuerId = "ISSUER_ID"
106-
private val objectId = "codelab_object"
107-
108-
private val newObjectJson = """
109-
{
110-
"iss": "$issuerEmail",
111-
"aud": "google",
112-
"typ": "savetowallet",
113-
"origins": [
114-
"https://www.example.com"
115-
],
116-
"payload": {
117-
"genericObjects": [
118-
{
119-
"id": "$issuerId.$objectId"
120-
}
121-
]
122-
}
123-
}
124-
"""
125106
}

backend/generic_pass.js

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { GoogleAuth } = require('google-auth-library');
2+
const jwt = require('jsonwebtoken');
23

34
// TODO: Define issuer ID
45
let issuerId = 'ISSUER_ID';
@@ -30,7 +31,7 @@ let genericObject = {
3031
'cardTitle': {
3132
'defaultValue': {
3233
'language': 'en-US',
33-
'value': 'Google I/O \'22 [DEMO ONLY]'
34+
'value': 'Google I/O \'22'
3435
}
3536
},
3637
'subheader': {
@@ -68,33 +69,15 @@ let genericObject = {
6869
]
6970
}
7071

71-
// Check if the object exists already
72-
httpClient.request({
73-
url: `${baseUrl}/genericObject/${objectId}`,
74-
method: 'GET',
75-
}).then(response => {
76-
console.log('Object already exists');
77-
console.log(response);
78-
79-
console.log('Object ID');
80-
console.log(response.data.id);
81-
}).catch(err => {
82-
if (err.response && err.response.status === 404) {
83-
// Object does not exist
84-
// Create it now
85-
httpClient.request({
86-
url: `${baseUrl}/genericObject`,
87-
method: 'POST',
88-
data: genericObject,
89-
}).then(response => {
90-
console.log('Object insert response');
91-
console.log(response);
72+
const claims = {
73+
iss: credentials.client_email, // `client_email` in service account file.
74+
aud: 'google',
75+
origins: ['http://localhost:3000'],
76+
typ: 'savetowallet',
77+
payload: {
78+
genericObjects: [genericObject],
79+
},
80+
};
9281

93-
console.log('Object ID');
94-
console.log(response.data.id);
95-
});
96-
} else {
97-
// Something else went wrong
98-
console.log(err);
99-
}
100-
});
82+
const token = jwt.sign(claims, credentials.private_key, {algorithm: 'RS256'});
83+
console.log(token)

backend/package-lock.json

Lines changed: 100 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"dependencies": {
3-
"google-auth-library": ">=5.9.2"
3+
"google-auth-library": ">=5.9.2",
4+
"jsonwebtoken": ">=8.5.1"
45
}
56
}

0 commit comments

Comments
 (0)