This is a POC stub for the Twilio Pay Connector. It is a simple web server that listens for incoming requests and responds with a JSON payload.
Card Number: 4111 1111 1111 1111
Expiry Date: 12/25
Billing Zip: 94105
CVV: 333
- Uses a Twilio-purchased telephone number to receive the call
- A TwiML Bin to handle the incoming call and forward the request to the connector
- The Twilio Generic Pay Connector (docs) to accept the card information and forward it to the payment gateway
- This repo, as a stub for the payment gateway (accessed on my local via ngrok)
- A Twilio serverless function to handle the callback from the Generic Pay Connector
Twilio Serverless Function:
exports.handler = function (context, event, callback) {
// Helper just to clean/filter the response
const getParams = (target, startsWithVal = 'PayConnector_') =>
Object.keys(target).reduce((acc, key) => {
if (key.startsWith(startsWithVal)) {
acc[key.replace(startsWithVal, '')] = target[key];
}
return acc;
}, {});
let twiml = new Twilio.twiml.VoiceResponse();
const myParams = getParams(event);
console.log('============== in /pay with params ===========');
console.log(myParams);
console.log('==================================');
switch (event.Result) {
case 'success':
const { charge_id } = event;
text = `Thank you for your payment. Your confirmation number is: ${event.PayConnector_confirmation_number}`;
break;
case 'payment-connector-error':
text = `The Payment Gateway is reporting the error: ${event.PaymentError}`;
console.log(decodeURIComponent(event.PaymentError));
break;
default:
text = 'The payment was not completed successfully';
}
twiml.say(text);
callback(null, twiml);
};