Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
collections request api
Browse files Browse the repository at this point in the history
  • Loading branch information
taylordowns2000 committed Jun 17, 2016
1 parent 8993277 commit 06f57f8
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 8 deletions.
38 changes: 30 additions & 8 deletions README.md
Expand Up @@ -12,16 +12,38 @@ Documentation
```js
createPayment(fields(
field("phonenumber", "+256773712831"),
field("first_name", "+256773712831"),
field("last_name", "+256773712831"),
field("first_name", "Gideon"),
field("last_name", "Zelalem"),
field("amount", 100.2),
field("currency", "UGX"),
field("currency", "USD"),
field("account", 1),
field("description", "+256773712831"),
field("payment_type", "+256773712831"),
field("callback_url", "+256773712831"),
field("metadata.id", 1234),
field("metadata.name", "Lucy")
field("description", "Long-term contract for Arseal"),
field("payment_type", "money"),
field("callback_url", "https://my.website/payments/callback")
))
```

## Collection Requests API

#### `createCollectionRequest(...)`
```js
createCollectionRequest(fields(
field("instructions", "Send me some money, please!"),
field("phonenumber", "+256773712831"),
field("amount", 5.0),
field("currency", "USD")
))
```

## Contacts API

#### `createContact(...)`
```js
createContact(fields(
field("first_name", "Granit"),
field("last_name", "Xhaka"),
field("phone_number", "+256773712831"),
field("email", "granit@arsenal.com")
))
```

Expand Down
33 changes: 33 additions & 0 deletions lib/Adaptor.js
Expand Up @@ -10,6 +10,7 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
exports.execute = execute;
exports.createPayment = createPayment;
exports.createContact = createContact;
exports.createCollectionRequest = createCollectionRequest;

var _languageCommon = require('language-common');

Expand Down Expand Up @@ -154,3 +155,35 @@ function createContact(data) {
});
};
}

/**
* Create a collection request
* @example
* execute(
* createCollectionRequest(data)
* )(state)
* @constructor
* @param {object} data - Payload data for the collection request
* @returns {Operation}
*/
function createCollectionRequest(data) {

return function (state) {
var body = (0, _languageCommon.expandReferences)(data)(state);

var _state$configuration3 = state.configuration;
var apiUrl = _state$configuration3.apiUrl;
var apiToken = _state$configuration3.apiToken;


var url = (0, _url.resolve)(apiUrl + '/', 'collectionrequests');

console.log("Posting collection request:");
console.log(body);

return (0, _Client.post)({ apiToken: apiToken, body: body, url: url }).then(function (result) {
console.log("Success:", result);
return _extends({}, state, { references: [result].concat(_toConsumableArray(state.references)) });
});
};
}
30 changes: 30 additions & 0 deletions src/Adaptor.js
Expand Up @@ -90,6 +90,36 @@ export function createContact(data) {
}
}

/**
* Create a collection request
* @example
* execute(
* createCollectionRequest(data)
* )(state)
* @constructor
* @param {object} data - Payload data for the collection request
* @returns {Operation}
*/
export function createCollectionRequest(data) {

return state => {
const body = expandReferences(data)(state);

const { apiUrl, apiToken } = state.configuration;

const url = resolveUrl(apiUrl + '/', 'collectionrequests')

console.log("Posting collection request:");
console.log(body)

return post({ apiToken, body, url })
.then((result) => {
console.log("Success:", result);
return { ...state, references: [ result, ...state.references ] }
})

}
}

export {
field, fields, sourceValue,
Expand Down

0 comments on commit 06f57f8

Please sign in to comment.