I am a bit confused as to how I am meant to hook up my Lambda functions via API Gateway to Braintree's Webhooks. I know webhooks invoke my lambda functions via api gateway via and endpoint URL but I am unsure how to set up my lambda function to handle this properly and use the values that webhooks will pass as parameters when invoking the function. I have the following right now:
package com.amazonaws.lambda.submerchantapproved;
import java.util.HashMap;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.DynamodbEvent;
import com.braintreegateway.BraintreeGateway;
import com.braintreegateway.Environment;
import com.braintreegateway.WebhookNotification;
import com.braintreegateway.WebhookNotification.Kind;
public class SubmerchantApproved implements RequestHandler<Object, String> {
public String handleRequest(Object request, Context context) {
BraintreeGateway gateway = new BraintreeGateway(
Environment.SANDBOX,
"MyValue",
"MyValue",
"MyValue"
);
WebhookNotification webhookNotification = gateway.webhookNotification().parse(
request.queryParams("bt_signature"),
request.queryParams("bt_payload")
);
String woofer = "";
return woofer;
}
}
This is not working or correct though. How exactly am I meant to get these bt_signature and by_payload values into my lambda function?? The webhooks pass the data in via a http-POST request which is relevant.
Well, your Object request
is exactly where those request parameters should be.
There are two main scenarios for Java Lambdas:
bt_signature
and by_payload
. Again, a great template/example is available from AWS: http://docs.aws.amazon.com/lambda/latest/dg/java-handler-io-type-pojo.html