Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Add JavaScript code example #35

Merged
merged 2 commits into from
Mar 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 39 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# CH-Payments
Welcome to CH Payments, a simple paymentprovider wrapper for stuff you want CH to get money for.
Payments makes it easy to create products, and implement it in your own website.
No hassle with keys, accounts and webhooks, just a single call to initiate a payment.
No hassle with keys, accounts and webhooks, just a single call to initiate a payment.

Below you can find some ready-to-use code examples for your website.

The administration panel (for now) is only available for board members.
The administration panel (for now) is only available for board members.
They can create products to generate the keys required.

# Code examples
No idea how to code, but still want to sell tickets on your CH site?
Use one of these code examples to get going.
No idea how to code, but still want to sell tickets on your CH site?
Use one of these code examples to get going.

#### Python 3.5
```python
Expand All @@ -31,23 +31,53 @@ print(response.json())
```

#### JavaScript
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a note that fetch is not supported everywhere yet?

[Code example required](https://github.com/WISVCH/payments/issues/6)

The full workflow is as follows.

```js
async function main() {
const productsRequest = await fetch('http://localhost:9000/api/products/SYMPOSIUM/2016');
const products = await productsRequest.json();

const orderRequest = await fetch('http://localhost:9000/api/orders', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({
name: 'Thomas Ticket',
email: '[email protected]',
returnUrl: 'https://www.ch.tudelft.nl/payments/ordercompleted',
productKeys: products.map(p => p.key)
})
});
const order = await orderRequest.json();
console.log(`You should redirect the user to url ${order.url}`);

// After that you can obtain the order status with:
const statusRequest = await fetch(`http://localhost:9000/api/orders/${order.publicReference}`);
const status = await statusRequest.json();
console.log(`The order status is right now ${status.status}`);
}

main();
```

(You can copy-paste this snippet into the Dev console of your browser to try it out. It requires Chrome 55+.

#### PHP
[Code example required](https://github.com/WISVCH/payments/issues/6)

# HootHub
This project currently is quite minimal, and offers lots of opportunities for great features built by you!
Check out the issue page for HootHub issues, and start earning Uilenballen.
Check out the issue page for HootHub issues, and start earning Uilenballen.

First, pick an issue and self-assign it. Make your changes in a new branch, with the following naming convention:

- Fixing a bug? > "fix-description_of_bug"
- Implementing a new feature? > "feature-description_of_feature"

Once you're satisfied with your changes, create a pull request and give it the label "Ready for review".
You can assign someone in specific or wait for someone to pick it up.
Make sure to include tests and documentation.
Once you're satisfied with your changes, create a pull request and give it the label "Ready for review".
You can assign someone in specific or wait for someone to pick it up.
Make sure to include tests and documentation.
If Travis isn't happy, we're not happy.

# Running
Expand Down