如何使用 Nodejs 将通行证保存到 Google Pay?

问题描述

我想将 google pay API 用于具有 firebase 云功能的通行证,但不幸的是,nodejs 在 google-pay/passes-rest-samples 中被严重遗漏,并且在 client libraries 中不受支持。

我能够在 PHP 示例中测试 API - 即我的服务帐户已启动并链接到我的商家帐户,但我想知道如何在 nodejs 中使用该 API:

1- 如何在请求调用中获取访问令牌并保存传递?

尝试了以下操作,但我总是收到 401 状态代码:

a) 使用 google-auth-library-nodejs

    // Create a new JWT client using the key file downloaded from the Google Developer Console
      const auth = new google.auth.GoogleAuth({
          keyFile: path.join(__dirname,'serviceAccount.json'),scopes: 'https://www.googleapis.com/auth/wallet_object.issuer',});
      const client = await auth.getClient();
      const accessToken = (await client.getAccessToken()).token;

      const result = (await axios.post(`https://walletobjects.googleapis.com/walletobjects/v1/loyaltyClass?strict=true`,payload,{ headers: { Authorization: `Bearer ${accessToken}` } })
    ).data;
     

b) 使用 jsonwebtoken

 const token = jwt.sign({ payload,typ: JWT_TYPE },credentialJson.private_key,{
            algorithm: 'RS256',audience: AUDIENCE,issuer: SERVICE_ACCOUNT_EMAIL_ADDRESS,});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)