Skip to content

Commit

Permalink
Merge pull request #1 from google-pay/niccorder/misc-fixes
Browse files Browse the repository at this point in the history
[Fixes] Fixes to match the codelab originally created
  • Loading branch information
niccorder authored Jan 13, 2023
2 parents d6a7aa3 + 866d4c4 commit 273a1db
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ class CheckoutActivity : AppCompatActivity() {
// TODO: Set an on-click listener on the "Add to Google Wallet" button
addToGoogleWalletButton = layout.addToGoogleWalletButton.root
addToGoogleWalletButton.setOnClickListener {
walletClient.savePasses(newObjectJson, this, addToGoogleWalletRequestCode)
walletClient.savePasses(
TODO("Token goes here"),
this,
addToGoogleWalletRequestCode
)
}
}

Expand Down Expand Up @@ -99,27 +103,4 @@ class CheckoutActivity : AppCompatActivity() {
}
}
}

// TODO: Create the pass object definition
private val issuerEmail = "SERVICE_ACCOUNT_EMAIL"
private val issuerId = "ISSUER_ID"
private val objectId = "codelab_object"

private val newObjectJson = """
{
"iss": "$issuerEmail",
"aud": "google",
"typ": "savetowallet",
"origins": [
"https://www.example.com"
],
"payload": {
"genericObjects": [
{
"id": "$issuerId.$objectId"
}
]
}
}
"""
}
43 changes: 13 additions & 30 deletions backend/generic_pass.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { GoogleAuth } = require('google-auth-library');
const jwt = require('jsonwebtoken');

// TODO: Define issuer ID
let issuerId = 'ISSUER_ID';
Expand Down Expand Up @@ -30,7 +31,7 @@ let genericObject = {
'cardTitle': {
'defaultValue': {
'language': 'en-US',
'value': 'Google I/O \'22 [DEMO ONLY]'
'value': 'Google I/O \'22'
}
},
'subheader': {
Expand Down Expand Up @@ -68,33 +69,15 @@ let genericObject = {
]
}

// Check if the object exists already
httpClient.request({
url: `${baseUrl}/genericObject/${objectId}`,
method: 'GET',
}).then(response => {
console.log('Object already exists');
console.log(response);

console.log('Object ID');
console.log(response.data.id);
}).catch(err => {
if (err.response && err.response.status === 404) {
// Object does not exist
// Create it now
httpClient.request({
url: `${baseUrl}/genericObject`,
method: 'POST',
data: genericObject,
}).then(response => {
console.log('Object insert response');
console.log(response);
const claims = {
iss: credentials.client_email, // `client_email` in service account file.
aud: 'google',
origins: ['http://localhost:3000'],
typ: 'savetowallet',
payload: {
genericObjects: [genericObject],
},
};

console.log('Object ID');
console.log(response.data.id);
});
} else {
// Something else went wrong
console.log(err);
}
});
const token = jwt.sign(claims, credentials.private_key, {algorithm: 'RS256'});
console.log(token)
101 changes: 100 additions & 1 deletion backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"google-auth-library": ">=5.9.2"
"google-auth-library": ">=5.9.2",
"jsonwebtoken": ">=8.5.1"
}
}

0 comments on commit 273a1db

Please sign in to comment.