Help Needed with Amazon Pay Integration for Alexa

amazon-alexa

#21

Great! Just for future reference. Where was the problem?

After you’ve sent the setup directive, you will receive a custom request called Connections.Response. Jovo automatically maps that request to the ON_PURCHASE() intent.

That request will contain a payload object, which should have an attribute called billingAgreementId that you need to be able to send the charge directive, which, as the name says, is used to charge the customer.

Here’s a sample payload object from the official docs:

{
    "billingAgreementDetails":{ 
        "billingAgreementId":"C01-0000002-0000003",
        "creationTimestamp":"2018-03-24T00:31:57.352Z",
        "destination":{ 
            "addressLine1":"1234 Main Street",
            "city":"CUPERTINO",
            "countryCode":"US",
            "name":"Jane Doe",
            "phone":"1111122222",
            "postalCode":"90000",
            "stateOrRegion":"CA"
        },
        "billingAddress":{ 
            "addressLine1":"1234 Main Street",
            "city":"Seattle",
            "countryCode":"US",
            "name":"Jane Doe",
            "phone":"1111122222",
            "postalCode":"98104",
            "stateOrRegion":"WA" 
        },
        "checkoutLanguage":"en_US",
        "billingAgreementStatus":"OPEN",
        "releaseEnvironment":"SANDBOX"
    } 
}

I’ve never tested it myself, but I don’t see any reason why you shouldn’t be able to.

Thanks!


#22

Hi Kaan, thanks for your help. There wasn’t a problem as such, just me misunderstanding. I realised the card I was sending appeared in the user’s Alexa app. Using the card, I can now get read/write access permissions from the user for their lists and also Amazon Pay.

I was reading the docs myself last night. Thanks for confirming this. I will now attempt to send the charge directive using the billingAgreementId I get from the response. Here goes…


#23

Hi Jan/Kaan,

I’ve sent the setupDirective, and I can confirm that the response is coming back to the ON_PURCHASE() intent. There are two issues I need help with now:

Firstly, I’m having great difficulty in logging the request object:

const request = this.$request.toJSON(); // access the request object

I’ve not worked with Node.js in a project before, and normally I use console.log to check things. I set up the ON_PURCHASE() intent like this:

ON_PURCHASE() {
        const request = this.$request.toJSON(); // access the request object
   
        console.log(request);

    }

Do you know how I can see the log inside Lambda? I’ve looked at the CloudWatch logs when I do a test in the Alexa Developer Console and the logs are working but there’s no sign of my console.log(request) output.

In a very hacky attempt, I applied JSON.stringify to the request, then I used this.tell('Here is the request: ' + requestStringified + ' .'). It was pretty funny when Alexa started reading back the JSON! But obviously, this is not the right way to do things. There’s an 8000 character limit on the speech anyway so I couldn’t retrieve all the JSON even if I wanted to format it in a text editor for reading.

I need to read/check the details of the request.payload object. Once I’ve checked that, I can work on sending the charge directive.

Which leads me to my next question:

After reading the Amazon docs, there seems to be no reference to a particular product in the requests or responses. It seems as though this process is just setting up the ability to charge the customer a certain amount. It doesn’t say how the fulfillment is done.

Do you know how I can add an item to the customer’s basket from the Amazon store?

Many thanks,
Simon


#24

Update:

I’m getting the console.log to show up in the CloudWatch logs now. Turns out you need to add the following permissions in your IAM Permissions Policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "iam:CreateRole",
        "iam:GetRole",
        "iam:AttachRolePolicy",
        "iam:PassRole",
        "lambda:AddPermission",
        "lambda:CreateFunction",
        "lambda:GetFunction",
        "lambda:UpdateFunctionCode",
        "lambda:ListFunctions",
        "logs:FilterLogEvents",
        "logs:getLogEvents",
        "logs:describeLogStreams"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "arn:aws:logs:*:*:*"
    }
  ]
}

#25

Okay guys, I can see you are busy. If you could let me know when you can get back in touch that would be great. I’ve managed to get the transaction working with the setup and charge directives.

If we can’t add products to our user’s basket with Jovo I’m not sure what we will do next…


#26

Hi @simon.revill, we’re doing our best, but please keep in mind that this is free community support, which sometimes takes time when other things come up. After all, we need to pay the bills as well :slight_smile:

Have you consulted the Amazon Pay support? We’re no Amazon Pay experts, we just built the integration with their API, anything beyond that is difficult for us to debug.

This is great, so everything works beside putting something into the Amazon basket? Does the “charge later” functionality maybe work for something like this?


#27

Thanks Jan. I appreciate your efforts with helping me.
I will get in touch with Amazon Pay support and let you know what I find out.

Cheers