将 Mpesa API 与 google 表单集成

Integrate Mpesa API with google forms

我想将 Mpesa API 集成到 google 表单中。 用户使用表格支付,让我们说注册费

我认为这可以通过使用 Apps 脚本创建 google 表单来实现。

Forms Service

This service allows scripts to create, access, and modify Google Forms.

这是使用 Apps 脚本创建 google 表单的示例代码。

// Create a new form, then add a checkbox question, a multiple choice question,
// a page break, then a date question and a grid of questions.
var form = FormApp.create('New Form');
var item = form.addCheckboxItem();
item.setTitle('What condiments would you like on your hot dog?');
item.setChoices([
        item.createChoice('Ketchup'),
        item.createChoice('Mustard'),
        item.createChoice('Relish')
    ]);
form.addMultipleChoiceItem()
    .setTitle('Do you prefer cats or dogs?')
    .setChoiceValues(['Cats','Dogs'])
    .showOtherOption(true);
form.addPageBreakItem()
    .setTitle('Getting to know you');
form.addDateItem()
    .setTitle('When were you born?');
form.addGridItem()
    .setTitle('Rate your interests')
    .setRows(['Cars', 'Computers', 'Celebrities'])
    .setColumns(['Boring', 'So-so', 'Interesting']);
Logger.log('Published URL: ' + form.getPublishedUrl());
Logger.log('Editor URL: ' + form.getEditUrl());

然后你可以在Apps脚本中集成第三方API。

External APIs

Google Apps Script can interact with APIs from all over the web. This guide shows how to work with different types of APIs in your scripts.

Dozens of Google APIs are available in Apps Script, either as built-in services or advanced services. If you want to use a Google (or non-Google) API that isn't available as an Apps Script service, you can connect to the API's public HTTP interface through the URL Fetch service.

The following example makes a request to the YouTube API and returns a feed of videos that match the query skateboarding dog.

var url = 'https://gdata.youtube.com/feeds/api/videos?'
    + 'q=skateboarding+dog'
    + '&start-index=21'
    + '&max-results=10'
    + '&v=2';
var response = UrlFetchApp.fetch(url);
Logger.log(response);

同样,以下示例将视频上传到 YouTube。还使用 UrlFetchApp.fetch()

var payload = 'XXXXX'; // Replace with raw video data.
var headers = {
    'GData-Version': '2',
    'Slug': 'dog-skateboarding.mpeg'
    // Add any other required parameters for the YouTube API.
};
var url = 'https://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
var options = {
    'method': 'post',
    'headers': headers,
    'payload': payload
};
var response = UrlFetchApp.fetch(url, options);

请在此处查看我对与您类似问题的回答:

探索使用定制的 Mpesa api 开发 android 应用程序的可能性,以帮助您在线存储 Mpesa 消息并优化该信息以用于 Google 表单

您现在使用 M-Pesa RESTful API 可通过 Safaricom 访问 developer portal. The documentation 有主要编程语言的示例代码 - Python、JavaScript/NodeJS、Java, Ruby.

您现在可以使用 Google Apps 脚本使用 M-Pesa RESTful API,就像使用任何其他 RESTful API 一样。