{"_id":"56ecf98c7f94882900591955","user":"544fc065698ab40800b4f888","version":{"_id":"56326e9cdf556c0d00cd08ca","project":"544fc17e698ab40800b4f891","__v":2,"createdAt":"2015-10-29T19:08:12.724Z","releaseDate":"2015-10-29T19:08:12.724Z","categories":["56326e9ddf556c0d00cd08cb","56326e9ddf556c0d00cd08cc","56326e9ddf556c0d00cd08cd","56326e9ddf556c0d00cd08ce","56326e9ddf556c0d00cd08cf","56326e9ddf556c0d00cd08d0","56326e9ddf556c0d00cd08d1","56326e9ddf556c0d00cd08d2","56326e9ddf556c0d00cd08d3","56326e9ddf556c0d00cd08d4","56d942ac337fd11300d6a251"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"collector","version_clean":"2.1.0","version":"2.1"},"parentDoc":null,"category":{"_id":"56326e9ddf556c0d00cd08cd","pages":["56326e9edf556c0d00cd08da","56326e9edf556c0d00cd08db","56326e9edf556c0d00cd08dc","56326e9edf556c0d00cd08dd","56326e9edf556c0d00cd08de","56326e9edf556c0d00cd08df","5632e61862c48a0d00334ddc","5637210ec75f5d0d00ec5d4a","563750380704070d00f06c4b","56ecf98c7f94882900591955"],"version":"56326e9cdf556c0d00cd08ca","__v":5,"project":"544fc17e698ab40800b4f891","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-01T09:13:02.297Z","from_sync":false,"order":2,"slug":"tutorials","title":"Tutorials"},"project":"544fc17e698ab40800b4f891","__v":4,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-03-19T07:02:36.558Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":9,"body":"## Overview\n\nThe Coins Payment Requests API allows coins users to request for payments from anyone who has at least one of the following:\n\n* Coins account\n* Phone number\n* Email\n\n### A typical payment request flow will look like this:\n\n1. The requester creates a [payment request](doc:payment-requests) which would be sent to a chosen contact (coins account, phone number, email).\n2. The payer receives a notification through the channel chosen by the requester (coins account, phone number, email). \n3. The payer visits the payment link in the notification and chooses one of the currently available payment options.\n4. The payer completes payment through their chosen payment option.\n5. The requester receives their payment.\n\n## Using the Payment Requests API\n\n*Before proceeding, you may want to follow the the instructions for [Creating your API keys](doc:creating-your-api-keys) and [Choosing an Authentication method](doc:choosing-an-authentication-method). We recommend using [HMAC](doc:hmac) authentication, unless you would like to create a payment request in behalf of another coins user.*\n\n### 1. Creating a payment request:\n\nA payment request requires the following to be present in the payload:\n\n* payer_contact_info - The contact to send a payment request to. It can be a phone number or an email address. If the target payer is a registered coins user, `payer_contact_info` may also be that user's Facebook ID.\n* receiving_account - Account ID of the wallet to receive funds. To retrieve a wallet's account ID, please use the [accounts](http://api.coins.asia/v2.1/docs/crypto-accounts) endpoint.\n* amount - The requested amount to be paid for by the payer.\n* message - An arbitrary message that will be attached to the payment request.\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST \\\\\\n\\t-H \\\"Authorization: Bearer YOUR_TOKEN\\\" \\\\\\n  -H \\\"Content-Type: application/json;charset=UTF-8\\\" \\\\\\n  -H \\\"Accept: application/json\\\" \\\\\\n  -d '{\\\"payer_contact_info\\\": \\\"example:::at:::example.com\\\",\\\"receiving_account\\\": \\\"5411c4604c9b45b8b74837c84daa0f4c\\\",\\\"amount\\\": 20,\\\"message\\\": \\\"Thanks for all the fish!\\\"}' \\\\\\n\\t\\\"https://coins.ph/api/v3/payment-requests/\\\"\",\n      \"language\": \"curl\"\n    },\n    {\n      \"code\": \"import json\\nimport requests\\n\\nurl = \\\"https://coins.ph/api/v3/payment-requests/\\\"\\n\\nTOKEN = 'YOUR TOKEN'\\nheaders = {\\n    'Authorization': 'Bearer {}'.format(TOKEN),\\n    'Content-Type': 'application/json;charset=UTF-8',\\n    'Accept': 'application/json'\\n}\\nbody = json.dumps({\\n    'payer_contact_info': 'example@example.com',\\n    'receiving_account': '5411c4604c9b45b8b74837c84daa0f4c',\\n    'amount': 20,\\n    'message': 'Thanks for all the fish!'\\n})\\n\\nrequests.post(url, headers=headers, data=body)\\nprint(response.text)\",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"require 'uri'\\nrequire 'json'\\nrequire 'net/http'\\n\\nurl = URI('https://coins.ph/api/v3/payment-requests/')\\n\\nhttp = Net::HTTP.new(url.host, url.port)\\nhttp.use_ssl = true\\n\\nrequest = Net::HTTP::Post.new(url.request_uri)\\nrequest[\\\"content-type\\\"] = 'application/json'\\nrequest[\\\"authorization\\\"] = 'Bearer YOUR_BEARER_TOKEN'\\nrequest.body = JSON.dump({\\n  payer_contact_info: 'example@example.com',\\n  receiving_account: '5411c4604c9b45b8b74837c84daa0f4c',\\n  amount: 20,\\n  message: 'Thanks for all the fish!'\\n})\\n\\nresponse = http.request(request)\\nputs response.read_body\",\n      \"language\": \"ruby\"\n    }\n  ]\n}\n[/block]\nHere's an example response:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"payment-request\\\": {\\n        \\\"id\\\": \\\"5edc263fac7f4f61b87632cb5710050f\\\",\\n        \\\"invoice\\\": \\\"5713e3ab76e74e6b85194deaf0f14cel\\\",\\n        \\\"payer_contact_info\\\": \\\"example@example.com\\\",\\n        \\\"payer_contact_info_type\\\": \\\"email\\\",\\n        \\\"payer_email\\\": \\\"example@example.com\\\",\\n        \\\"amount\\\": \\\"20.00000000\\\",\\n        \\\"currency\\\": \\\"PHP\\\",\\n        \\\"message\\\": \\\"Thanks for all the fish!\\\",\\n        \\\"message_scope\\\": \\\"private\\\",\\n        \\\"status\\\": \\\"pending\\\",\\n        \\\"receiving_account\\\": \\\"5411c4604c9b45b8b74837c84daa0f4c\\\",\\n        \\\"payment_url\\\": \\\"https://coins.ph/payment/request/5edc263fac7f4f61b87632cb5710050f\\\",\\n        \\\"created_at\\\": \\\"2016-03-04T07:12:00.352338Z\\\",\\n        \\\"updated_at\\\": \\\"2016-03-04T07:12:00.474500Z\\\",\\n        \\\"expires_at\\\":\\\"2017-03-04T07:11:59.942484Z\\\"\\n    }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n### 2. Payer receives the payment request\n\nOnce the payment request is created, the payer will receive a notification through the contact information provided in the payment request. Once the payer clicks the link in the notification, they will be presented with a list of payment options:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/lc6HTnfRSSiopJwZYqD9_Screen_Shot_2016-03-13_at_2_37_52_PM.jpg\",\n        \"Screen_Shot_2016-03-13_at_2_37_52_PM.jpg\",\n        \"906\",\n        \"1800\",\n        \"#2f90d0\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nOnce the payer completes the payment, funds will be credited to the requester's provided receiving account. \n\n## More Information\n\nThe payment requests API is explained in more detail in their appropriate endpoint docs:\n\n* [GET](doc:payment-requests-1) \n* [POST](doc:payment-requests)","excerpt":"This document how to request payment from anyone","slug":"request-payments-api-tutorial","type":"basic","title":"Request payments from anyone"}

Request payments from anyone

This document how to request payment from anyone

## Overview The Coins Payment Requests API allows coins users to request for payments from anyone who has at least one of the following: * Coins account * Phone number * Email ### A typical payment request flow will look like this: 1. The requester creates a [payment request](doc:payment-requests) which would be sent to a chosen contact (coins account, phone number, email). 2. The payer receives a notification through the channel chosen by the requester (coins account, phone number, email). 3. The payer visits the payment link in the notification and chooses one of the currently available payment options. 4. The payer completes payment through their chosen payment option. 5. The requester receives their payment. ## Using the Payment Requests API *Before proceeding, you may want to follow the the instructions for [Creating your API keys](doc:creating-your-api-keys) and [Choosing an Authentication method](doc:choosing-an-authentication-method). We recommend using [HMAC](doc:hmac) authentication, unless you would like to create a payment request in behalf of another coins user.* ### 1. Creating a payment request: A payment request requires the following to be present in the payload: * payer_contact_info - The contact to send a payment request to. It can be a phone number or an email address. If the target payer is a registered coins user, `payer_contact_info` may also be that user's Facebook ID. * receiving_account - Account ID of the wallet to receive funds. To retrieve a wallet's account ID, please use the [accounts](http://api.coins.asia/v2.1/docs/crypto-accounts) endpoint. * amount - The requested amount to be paid for by the payer. * message - An arbitrary message that will be attached to the payment request. [block:code] { "codes": [ { "code": "curl -X POST \\\n\t-H \"Authorization: Bearer YOUR_TOKEN\" \\\n -H \"Content-Type: application/json;charset=UTF-8\" \\\n -H \"Accept: application/json\" \\\n -d '{\"payer_contact_info\": \"example@example.com\",\"receiving_account\": \"5411c4604c9b45b8b74837c84daa0f4c\",\"amount\": 20,\"message\": \"Thanks for all the fish!\"}' \\\n\t\"https://coins.ph/api/v3/payment-requests/\"", "language": "curl" }, { "code": "import json\nimport requests\n\nurl = \"https://coins.ph/api/v3/payment-requests/\"\n\nTOKEN = 'YOUR TOKEN'\nheaders = {\n 'Authorization': 'Bearer {}'.format(TOKEN),\n 'Content-Type': 'application/json;charset=UTF-8',\n 'Accept': 'application/json'\n}\nbody = json.dumps({\n 'payer_contact_info': 'example@example.com',\n 'receiving_account': '5411c4604c9b45b8b74837c84daa0f4c',\n 'amount': 20,\n 'message': 'Thanks for all the fish!'\n})\n\nrequests.post(url, headers=headers, data=body)\nprint(response.text)", "language": "python" }, { "code": "require 'uri'\nrequire 'json'\nrequire 'net/http'\n\nurl = URI('https://coins.ph/api/v3/payment-requests/')\n\nhttp = Net::HTTP.new(url.host, url.port)\nhttp.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url.request_uri)\nrequest[\"content-type\"] = 'application/json'\nrequest[\"authorization\"] = 'Bearer YOUR_BEARER_TOKEN'\nrequest.body = JSON.dump({\n payer_contact_info: 'example@example.com',\n receiving_account: '5411c4604c9b45b8b74837c84daa0f4c',\n amount: 20,\n message: 'Thanks for all the fish!'\n})\n\nresponse = http.request(request)\nputs response.read_body", "language": "ruby" } ] } [/block] Here's an example response: [block:code] { "codes": [ { "code": "{\n \"payment-request\": {\n \"id\": \"5edc263fac7f4f61b87632cb5710050f\",\n \"invoice\": \"5713e3ab76e74e6b85194deaf0f14cel\",\n \"payer_contact_info\": \"example@example.com\",\n \"payer_contact_info_type\": \"email\",\n \"payer_email\": \"example@example.com\",\n \"amount\": \"20.00000000\",\n \"currency\": \"PHP\",\n \"message\": \"Thanks for all the fish!\",\n \"message_scope\": \"private\",\n \"status\": \"pending\",\n \"receiving_account\": \"5411c4604c9b45b8b74837c84daa0f4c\",\n \"payment_url\": \"https://coins.ph/payment/request/5edc263fac7f4f61b87632cb5710050f\",\n \"created_at\": \"2016-03-04T07:12:00.352338Z\",\n \"updated_at\": \"2016-03-04T07:12:00.474500Z\",\n \"expires_at\":\"2017-03-04T07:11:59.942484Z\"\n }\n}", "language": "json" } ] } [/block] ### 2. Payer receives the payment request Once the payment request is created, the payer will receive a notification through the contact information provided in the payment request. Once the payer clicks the link in the notification, they will be presented with a list of payment options: [block:image] { "images": [ { "image": [ "https://files.readme.io/lc6HTnfRSSiopJwZYqD9_Screen_Shot_2016-03-13_at_2_37_52_PM.jpg", "Screen_Shot_2016-03-13_at_2_37_52_PM.jpg", "906", "1800", "#2f90d0", "" ] } ] } [/block] Once the payer completes the payment, funds will be credited to the requester's provided receiving account. ## More Information The payment requests API is explained in more detail in their appropriate endpoint docs: * [GET](doc:payment-requests-1) * [POST](doc:payment-requests)