{"_id":"56e1b819150ed52d0062c65e","parentDoc":null,"user":"56cdfe00e538330b0021ab76","project":"558b53f749dc4f0d00517de0","category":{"_id":"55909cb433090f0d004d25d9","__v":4,"pages":["55909cb533090f0d004d25de","55909cb533090f0d004d25df","55909cb533090f0d004d25e0","55936ccc47f40b170036087f","55936d259755e117000fbdf5","559372059755e117000fbe08"],"project":"558b53f749dc4f0d00517de0","version":"55909cb433090f0d004d25d8","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-06-25T01:06:00.994Z","from_sync":false,"order":0,"slug":"getting-started","title":"Getting Started"},"__v":59,"version":{"_id":"55909cb433090f0d004d25d8","project":"558b53f749dc4f0d00517de0","forked_from":"558b53f749dc4f0d00517de3","__v":8,"createdAt":"2015-06-29T01:17:40.214Z","releaseDate":"2015-06-29T01:17:40.214Z","categories":["55909cb433090f0d004d25d9","55909cb433090f0d004d25da","55909cb433090f0d004d25db","55909cb433090f0d004d25dc","56c72c00197f9f1700c811db","56c72df5b3625c0d00422c9e","56e1b646150ed52d0062c652","56e9fe9779708c0e002b6026","57312dc94245100e001743f4","57646a570742400e00c04701","5894c96f4d9c7e27002e42ba"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-03-10T18:08:25.946Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"This a start-to-finish guide on how to quickly get up to speed using the Wyre MassPay API. \n\n**What is MassPay?\n**\nMassPay is utilized by companies that are looking to transfer balances between local currencies. So when you're looking to transfer funds into a customer's bank account, MassPay is what you'll want to use! Note: \n\n**Contents:\n**\n1. [Setting up a Wyre Account](http://masspay.sendwyre.com/v2/docs/tutorial#1-setting-up-a-wyre-account)\n2. [Making API Requests](http://masspay.sendwyre.com/v2/docs/tutorial#2-making-api-requests)\n3. [Constructing your first Transfer Creation request](http://masspay.sendwyre.com/v2/docs/tutorial#constructing-your-first-transfer)\n4. [Example Transfers](http://masspay.sendwyre.com/v2/docs/tutorial#example-transfers)\n5. [Code Examples](http://masspay.sendwyre.com/v2/docs/tutorial#code-examples)\n6. [Links, Resources, and Contacts](http://masspay.sendwyre.com/v2/docs/tutorial#links-resources-and-contacts)\n[block:api-header]\n{\n  \"type\": \"link\",\n  \"title\": \"1. Setting up a Wyre Account\"\n}\n[/block]\nFirst, [create an account](https://dash.sendwyre.com/register) if you haven't already done so. Be sure to verify the email and phone attached to the account.\n\nTo get started transferring funds you'll need the following:\n\n- API Key\n- SECRET Key\n- ACCOUNT ID\n\nThese can be found in your [account settings](https://www.sendwyre.com/wallet/settings#!/api) once you have logged in.\n\nOnce you have generated an API key, here's what you'll see:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/7116657-signup.png\",\n        \"signup.png\",\n        615,\n        290,\n        \"#767677\"\n      ],\n      \"border\": false,\n      \"caption\": \"\"\n    }\n  ]\n}\n[/block]\nThe last piece is your AccountID. This can be found by clicking on the \"details\" of the key that you just generated. \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/cf94636-Wyre_account_number.png\",\n        \"Wyre account number.png\",\n        641,\n        247,\n        \"#7c7b7c\"\n      ]\n    }\n  ]\n}\n[/block]\n**Note** \nDon't include the \"account:\" when making your requests. \nThis - **account:pm9ddj8jr8rrq53fsk9v4bfhunieu72t**\nBecomes this for your requests - **pm9ddj8jr8rrq53fsk9v4bfhunieu72t**\n\n[block:api-header]\n{\n  \"type\": \"link\",\n  \"title\": \"2. Making API Requests\"\n}\n[/block]\nThe base Wyre API URL is at https://api.sendwyre.com/v2/. All responses are in JSON. \n\nWyre utilizes the following HTTP Headers as security measures:\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"X-Api-Key\",\n    \"1-0\": \"X-Api-Signature\",\n    \"h-0\": \"Header Field\",\n    \"h-1\": \"Description\",\n    \"0-1\": \"Your Wyre API key\",\n    \"1-1\": \"[HMAC](https://en.wikipedia.org/wiki/Hash-based_message_authentication_code) calculated with the secret key.\"\n  },\n  \"cols\": 2,\n  \"rows\": 2\n}\n[/block]\nCalculate your API Signature HMAC as follows (code examples at bottom of page):\n\n1. Construct your Request URL and add a *timestamp* URL parameter in milliseconds. For example, to get your account details, the Request URL is [https://api.sendwyre.com/v2/account?timestamp=1426252182534](https://api.sendwyre.com/v2/account?timestamp=1426252182534).\n2.  Concatenate the Request URL with the body of the HTTP request into a UTF-8 String. Use an empty string for the HTTP body in GET requests.\n3.  Compute the signature using HMAC using the SHA-256 algorithm and your API Secret Key.\n\nHere are Wyre's MassPay API endpoints. Click on the name links for full documentation:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Name\",\n    \"h-1\": \"API Endpoint\",\n    \"h-2\": \"HTTP Method\",\n    \"1-0\": \"[Live Exchange Rates](http://masspay.sendwyre.com/docs/checking-live-exchange-rates)\",\n    \"2-0\": \"[Create Transfer](http://masspay.sendwyre.com/docs/creating-a-transfer-and-getting-a-quote)\",\n    \"3-0\": \"[Confirm Transfer](http://masspay.sendwyre.com/docs/confirming-a-quote)\",\n    \"h-3\": \"Description\",\n    \"0-1\": \"[https://api.sendwyre.com/v2/account](https://api.sendwyre.com/v2/account)\",\n    \"1-1\": \"[https://api.sendwyre.com/v2/rates](https://api.sendwyre.com/v2/rates)\",\n    \"2-1\": \"[https://api.sendwyre.com/v2/transfers](https://api.sendwyre.com/v2/transfers)\",\n    \"0-0\": \"[Account Details](http://masspay.sendwyre.com/docs/getting-your-account-and-checking-balances)\",\n    \"4-0\": \"[Transfer Status](http://masspay.sendwyre.com/docs/getting-transfer-status-updates)\",\n    \"0-2\": \"GET\",\n    \"1-2\": \"GET\",\n    \"2-2\": \"POST\",\n    \"3-2\": \"POST\",\n    \"4-2\": \"GET\",\n    \"3-1\": \"[https://api.sendwyre.com/v2/transfer/:transferId/confirm](https://api.sendwyre.com/v2/:transferId/confirm)\",\n    \"4-1\": \"[https://api.sendwyre.com/v2/transfer/:transferId](https://api.sendwyre.com/v2/:transferId)\",\n    \"0-3\": \"Account details including contact info, balances in all currencies, KYC authorizations, and payment methods.\",\n    \"1-3\": \"A list of exchange rates for all currency pair combinations that Wyre currently supports.\",\n    \"2-3\": \"Creates a transfer between two currencies. The destination can be an email address, wallet address, or bank account. autoConfirm may be used but is not recommended.\",\n    \"3-3\": \"The transfer will normally only execute after you review the details and confirm at this endpoint within 30 seconds.\",\n    \"4-3\": \"If you don't use a callbackUrl when created the transfer, you can poll this endpoint until the order is filled. Different possible statuses are[ here](http://masspay.sendwyre.com/docs/transfer-statuses).\"\n  },\n  \"cols\": 4,\n  \"rows\": 5\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"link\",\n  \"title\": \"Constructing your first Transfer\"\n}\n[/block]\nA Transfer request is a JSON POST request that may contain up to [7 fields](http://masspay.sendwyre.com/docs/creating-a-transfer-and-getting-a-quote):\n\n- `sourceAmount` - only include either `sourceAmount` or `destAmount`, not both. `sourceAmount` is the amount removed from your main account in order to send funds to the destination. In this case you specify the amount removed from your account, and the destAmount will be determined depending on the fees and exchange rate.\n- `sourceCurrency` - an [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3#Current_codes) currency code that will be deducted from your account.\n- `dest` - a destination for the funds. This can be an email address, phone number, blockchain address, or bank account. \n- `destAmount` - only include either `sourceAmount` or `destAmount`, not both. `destAmount` is the exact amount that will be deposited into the `dest`. If `destAmount` is specified in the Transfer creation request the `sourceAmount` will be calculated from the `destAmount`, the exchange rate any fees on the Transfer\n- `destCurrency` - an [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3#Current_codes) currency code that matches the `dest` type. The `destCurrency` can be the same or different from the `sourceCurrency`. If they are different, an exchange will automatically occur.\n- `message` - An optional log message to include with the transfer\n- `callbackUrl` - An optional url that Wyre will POST a status callback to (see [Callbacks](doc:callbacks))\n- `autoConfirm` - An optional parameter to automatically confirm the transfer order. Not recommended.\n\nHere is an example transfer creation request to convert BRL to USD and send it to our lead developer's bank account:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"dest\\\": {\\n    \\\"paymentMethodType\\\":\\\"INTERNATIONAL_TRANSFER\\\",\\n    \\\"country\\\": \\\"US\\\",\\n    \\\"currency\\\": \\\"USD\\\",\\n    \\\"firstNameOnAccount\\\": \\\"Sam\\\",\\n    \\\"lastNameOnAccount\\\":\\\"Schlachter\\\",\\n    \\\"accountNumber\\\": \\\"1234dinosaur\\\",\\n    \\\"routingNumber\\\": \\\"0000000000\\\",\\n    \\\"accountType\\\": \\\"savings\\\",\\n    \\\"bankName\\\": \\\"Bank of 'murrrica\\\",\\n    \\\"bankStreet\\\": \\\"112 Brannan St\\\",\\n    \\\"bankCity\\\": \\\"San Francisco\\\",\\n    \\\"bankPostal\\\": \\\"94108\\\",\\n    \\\"accountHolderPhoneNumber\\\": \\\"+14102239203\\\",\\n    \\\"beneficiaryType\\\": \\\"INDIVIDUAL\\\",\\n    \\\"priority\\\":\\\"HIGH\\\"\\n  },\\n  \\\"sourceCurrency\\\": \\\"BRL\\\",\\n  \\\"destCurrency\\\": \\\"USD\\\",\\n  \\\"destAmount\\\": 10,\\n  \\\"message\\\":\\\"Here's your $10!\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nThe response will resemble [this](http://masspay.sendwyre.com/docs/creating-a-transfer-and-getting-a-quote#section-reviewing-your-transfer). The most important part of the response is the `id` field. This is what we'll use to confirm the transfer and poll its status. \n\nIf the transfer response is of the amount and at the rate we wanted, we must confirm the order by posting to the [Confirm Transfer](http://masspay.sendwyre.com/docs/confirming-a-quote) endpoint (or by using `autoConfirm` in the original request). \n\nThe last step is to poll the `status` of the order from the [Transfer Status ](http://masspay.sendwyre.com/docs/getting-transfer-status-updates) endpoint until the transfer object reaches an end state- either `COMPLETED`, `EXPIRED`, or `FAILED`. Alternatively, you can pass in a URL to the `callbackUrl` field to the original transfer creation request, which will cause wyre to  send an HTTP POST transfer status response to the URL. \n\nBelow are examples of transfers involving bank accounts.\n[block:api-header]\n{\n  \"type\": \"link\",\n  \"title\": \"Example Transfers\"\n}\n[/block]\n**USA πŸ‡ΊπŸ‡Έ β†’ πŸ‡§πŸ‡· BRAZIL**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"dest\\\": {\\n    \\\"paymentMethodType\\\":\\\"INTERNATIONAL_TRANSFER\\\",\\n    \\\"country\\\": \\\"BR\\\",\\n    \\\"currency\\\": \\\"BRL\\\",\\n    \\\"firstNameOnAccount\\\": \\\"Robert\\\",\\n    \\\"lastNameOnAccount\\\": \\\"Baratheon\\\",\\n    \\\"accountNumber\\\": \\\"1234dinosaur\\\",\\n    \\\"bankName\\\": \\\"Mordor Credit Union\\\",\\n    \\\"cpfCnpj\\\": \\\"943759353\\\",\\n    \\\"accountType\\\": \\\"poupanca\\\",\\n    \\\"branchCode\\\": \\\"Artichoke\\\",\\n    \\\"accountHolderEmail\\\": \\\"banana:::at:::phone.com\\\",\\n    \\\"accountHolderPhoneNumber\\\": \\\"+14102239203\\\",\\n    \\\"swift\\\": \\\"DEUTUS00000\\\",\\n    \\\"beneficiaryType\\\": \\\"INDIVIDUAL\\\",\\n        \\\"priority\\\":\\\"HIGH\\\"\\n  },\\n  \\\"sourceCurrency\\\": \\\"USD\\\",\\n  \\\"destCurrency\\\": \\\"BRL\\\",\\n  \\\"destAmount\\\": 10,\\n  \\\"message\\\":\\\"A Lannister always pays his debts \\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n**BRAZIL πŸ‡§πŸ‡· β†’ πŸ‡ΊπŸ‡Έ USA**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"dest\\\": {\\n    \\\"paymentMethodType\\\":\\\"INTERNATIONAL_TRANSFER\\\",\\n    \\\"country\\\": \\\"US\\\",\\n    \\\"currency\\\": \\\"USD\\\",\\n    \\\"beneficiaryType\\\": \\\"INDIVIDUAL\\\",\\n    \\\"beneficiaryAddress\\\": \\\"112 Brannan St\\\",\\n    \\\"beneficiaryAddress2\\\": \\\"\\\", //Optional\\n    \\\"beneficiaryCity\\\": \\\"San Francisco\\\",\\n    \\\"beneficiaryState\\\": \\\"CA\\\",\\n    \\\"beneficiaryPostal\\\": \\\"94108\\\",\\n    \\\"beneficiaryPhoneNumber\\\": \\\"+14102239203\\\",\\n    \\\"beneficiaryDobDay\\\": \\\"15\\\",\\n    \\\"beneficiaryDobMonth\\\":\\\"12\\\",\\n    \\\"beneficiaryDobYear\\\":\\\"1989\\\",\\n    \\\"paymentType\\\" : \\\"LOCAL_BANK_WIRE\\\", // LOCAL_BANK_WIRE or ACH\\n    \\\"firstNameOnAccount\\\": \\\"Billy-Bob\\\",\\n    \\\"lastNameOnAccount\\\":\\\"Jones\\\",\\n    \\\"accountNumber\\\": \\\"0000000000000\\\",\\n    \\\"routingNumber\\\": \\\"0000000000\\\",\\n    \\\"accountType\\\": \\\"CHECKING\\\", //CHECKING or SAVINGS\\n    \\\"bankName\\\": \\\"Bank of America\\\"\\n  },\\n  \\\"sourceCurrency\\\": \\\"BRL\\\",\\n  \\\"destCurrency\\\": \\\"USD\\\",\\n  \\\"destAmount\\\": 10,\\n  \\\"message\\\":\\\"USD Personal example\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n**USA πŸ‡ΊπŸ‡Έ β†’ πŸ‡¨πŸ‡³ CHINA**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"dest\\\": {\\n    \\\"paymentMethodType\\\":\\\"INTERNATIONAL_TRANSFER\\\",\\n    \\\"country\\\": \\\"CN\\\",\\n    \\\"currency\\\": \\\"CNY\\\",\\n    \\\"nameOnAccount\\\": \\\"成龍\\\",\\n    \\\"accountNumber\\\": \\\"1234dinosaur\\\",\\n    \\\"bankName\\\": \\\"ζ‹›ε•†ι“Άθ‘Œ\\\",\\n    \\\"accountType\\\": \\\"金卑\\\",\\n    \\\"branchCode\\\": \\\"ε…‰εŽθ·―ζ”―θ‘Œ\\\",\\n    \\\"accountHolderEmail\\\": \\\"[email protected]\\\",\\n    \\\"accountHolderPhoneNumber\\\": \\\"+14102239203\\\",\\n    \\\"swift\\\": \\\"DEUTUS00000\\\",\\n    \\\"beneficiaryType\\\": \\\"INDIVIDUAL\\\",\\n    \\\"priority\\\":\\\"HIGH\\\"\\n  },\\n  \\\"sourceCurrency\\\": \\\"USD\\\",\\n  \\\"destCurrency\\\": \\\"CNY\\\",\\n  \\\"destAmount\\\": 10,\\n  \\\"message\\\":\\\"\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n**CHINA πŸ‡¨πŸ‡³ β†’ πŸ‡ΊπŸ‡Έ USA**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"dest\\\": {\\n    \\\"paymentMethodType\\\":\\\"INTERNATIONAL_TRANSFER\\\",\\n    \\\"country\\\": \\\"US\\\",\\n    \\\"currency\\\": \\\"USD\\\",\\n    \\\"beneficiaryType\\\": \\\"INDIVIDUAL\\\",\\n    \\\"beneficiaryAddress\\\": \\\"112 Brannan St\\\",\\n    \\\"beneficiaryAddress2\\\": \\\"\\\", //Optional\\n    \\\"beneficiaryCity\\\": \\\"San Francisco\\\",\\n    \\\"beneficiaryState\\\": \\\"CA\\\",\\n    \\\"beneficiaryPostal\\\": \\\"94108\\\",\\n    \\\"beneficiaryPhoneNumber\\\": \\\"+14102239203\\\",\\n    \\\"beneficiaryDobDay\\\": \\\"15\\\",\\n    \\\"beneficiaryDobMonth\\\":\\\"12\\\",\\n    \\\"beneficiaryDobYear\\\":\\\"1989\\\",\\n    \\\"paymentType\\\" : \\\"LOCAL_BANK_WIRE\\\", // LOCAL_BANK_WIRE or ACH\\n    \\\"firstNameOnAccount\\\": \\\"Billy-Bob\\\",\\n    \\\"lastNameOnAccount\\\":\\\"Jones\\\",\\n    \\\"accountNumber\\\": \\\"0000000000000\\\",\\n    \\\"routingNumber\\\": \\\"0000000000\\\",\\n    \\\"accountType\\\": \\\"CHECKING\\\", //CHECKING or SAVINGS\\n    \\\"bankName\\\": \\\"Bank of America\\\"\\n  },\\n  \\\"sourceCurrency\\\": \\\"CNY\\\",\\n  \\\"destCurrency\\\": \\\"USD\\\",\\n  \\\"destAmount\\\": 10,\\n  \\\"message\\\":\\\"USD Personal example\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"link\",\n  \"title\": \"Code Examples\"\n}\n[/block]\nYou can simply put your API Key, API Secret Key, and Account ID into these scripts, alter the example transfer request objects, and get started right away making MassPay transfers!\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#dependencies:\\n#python3\\n#pip3 install requests\\n\\nimport json\\nimport hmac\\nimport time\\nfrom requests import request\\n\\nclass MassPay_API(object):\\n    def __init__(self, account_id, api_version, api_key, api_secret):\\n        self.account_id = account_id\\n        self.api_url = 'https://api.sendwyre.com/{}'.format(api_version)\\n        self.api_version = api_version\\n        self.api_key = api_key\\n        self.api_secret = api_secret\\n\\n    #authentication decorator. May raise ValueError if no json content is returned\\n    def authenticate_request(func):\\n        def wrap(self, *args, **kwargs):\\n            url, method, body = func(self, *args, **kwargs)\\n            params = {}\\n            timestamp = int(time.time() * 1000)\\n            url += '?timestamp={}'.format(timestamp)\\n            bodyJson = json.dumps(body) if body != '' else ''\\n            headers = {}\\n            headers['Content-Type'] = 'application/json'\\n            headers['X-Api-Version'] = self.api_version\\n            headers['X-Api-Key'] = self.api_key\\n            headers['X-Api-Signature'] = hmac.new(self.api_secret.encode('utf-8'), (url + bodyJson).encode('utf-8'), 'SHA256').hexdigest()\\n            print(headers['X-Api-Signature'])\\n            resp = request(method=method, url=url, params=params, data=(json.dumps(body) if body != '' else None), json=None, headers=headers)\\n            if resp.text is not None: #wyre will always try to give an err body\\n                return resp.status_code, resp.json()\\n            return 404, {}\\n        return wrap\\n\\n    @authenticate_request\\n    def retrieve_exchange_rates(self):\\n        url = self.api_url + '/rates'\\n        method = 'GET'\\n        body = ''\\n        return url, method, body\\n\\n    @authenticate_request\\n    def retrieve_account(self):\\n        url = self.api_url + '/account'\\n        method = 'GET'\\n        body = ''\\n        return url, method, body\\n\\n    @authenticate_request\\n    def create_transfer(self, sourceAmount, sourceCurrency, destAmount, destCurrency, destination, message, autoConfirm):\\n        url = self.api_url + '/transfers'\\n        method = 'POST'\\n        #ONLY use either sourceAmount or destAmount, see documentation\\n        body = {'sourceCurrency':sourceCurrency,\\n                'dest':destination, #email, wallet, or bank transfer dict\\n                'destCurrency':destCurrency,\\n                'message':message}\\n        if sourceAmount:\\n            body[\\\"sourceAmount\\\"] = sourceAmount\\n        elif destAmount:\\n            body[\\\"destAmount\\\"] = destAmount\\n        if autoConfirm:\\n            body['autoConfirm'] = True\\n        return url, method, body \\n\\n    @authenticate_request\\n    def confirm_transfer(self, transfer_id):\\n        url = self.api_url + '/transfer/{}/confirm'.format(transfer_id)\\n        method = 'POST'\\n        body = ''\\n        return url, method, body  \\n\\n    @authenticate_request\\n    def status_transfer(self, transfer_id):\\n        url = self.api_url + '/transfer/{}'.format(transfer_id)\\n        method = 'GET'\\n        body = ''\\n        return url, method, body  \\n\\n#USAGE Example\\naccount_id = \\\"YOUR_ACCOUNT_ID_HERE\\\" #optional\\napi_key = \\\"YOUR_API_KEY_HERE\\\"\\nsecret_key = \\\"YOUR_SECRET_KEY_HERE\\\"\\napi_version = \\\"2\\\"\\n\\n#create wyre MassPay API object\\nwyre = MassPay_API(account_id, api_version, api_key, secret_key)\\n\\n#get account info\\nhttp_code, account = wyre.retrieve_account()\\nprint(account)\\n\\n#get exchange rate info\\nhttp_code, rate_result = wyre.retrieve_exchange_rates()\\nprint(rate_result)\\n\\n#BTC to CNY rate\\nbtc_cny = rate_result.get(\\\"BTCCNY\\\")\\n\\n#amount of source (withdrawal) BTC we want to sent to Euro\\namount = 50\\n\\n#calculate destination (deposit) amount in CNY\\nfinal_amount = amount * btc_cny\\n\\n#example bank transfer dictionary that we will pass in as the destination\\nbank_transfer =   {\\n                \\\"paymentMethodType\\\":\\\"INTERNATIONAL_TRANSFER\\\",\\n                \\\"country\\\": \\\"CN\\\",\\n                \\\"currency\\\": \\\"CNY\\\",\\n                \\\"nameOnAccount\\\": \\\"成龍\\\",\\n                \\\"accountNumber\\\": \\\"1234dinosaur\\\",\\n                \\\"bankName\\\": \\\"ζ‹›ε•†ι“Άθ‘Œ\\\",\\n                \\\"accountType\\\": \\\"金卑\\\",\\n                \\\"branchCode\\\": \\\"ε…‰εŽθ·―ζ”―θ‘Œ\\\",\\n                \\\"accountHolderEmail\\\": \\\"[email protected]\\\",\\n                \\\"accountHolderPhoneNumber\\\": \\\"+14102239203\\\",\\n                \\\"swift\\\": \\\"DEUTUS00000\\\",\\n                \\\"beneficiaryType\\\": \\\"INDIVIDUAL\\\",\\n                \\\"priority\\\":\\\"HIGH\\\"\\n                }\\n\\n#send transfer and print result\\nhttp_code, transfer_result = wyre.create_transfer(\\n                                amount, \\n                                \\\"BTC\\\", \\n                                None, #final_amount\\n                                \\\"CNY\\\", \\n                                bank_transfer, #may also be an email or SRN\\n                                \\\"sending wyre developers pizza money\\\",\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\tFalse)\\nprint(transfer_result)\\ntx_id = transfer_result['id'] #grab our transfer id\\n\\n#confirm transfer\\nhttp_code, confirmation = wyre.confirm_transfer(tx_id)\\nprint(confirmation)\\n\\n#check status\\nhttp_code, status = wyre.status_transfer(tx_id)\\nprint(status)\",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"require 'uri'\\nrequire 'net/http'\\nrequire 'digest/hmac'\\nrequire 'json'\\n\\nclass WyreApi\\n  ACCOUNT_ID = 'ue5hsnusf8gene87asdf4es23bt9d7ak'\\n  API_KEY = '9idihi38o18mrm1234ipa1k9ooiifgts'\\n  SEC_KEY = '5e3kcoogptge6s5fh2qwertyb6g368dm'\\n  API_URL = 'https://api.sendwyre.com'\\n\\n  def create_transfer options\\n    api_post '/transfers', options\\n  end\\n\\n  private\\n\\n  def api_post path, post_data = {}\\n    params = {\\n      'timestamp' => (Time.now.to_i * 1000).to_s\\n    }\\n\\n    url = API_URL + path + '?' + URI.encode_www_form(params)\\n\\n    headers = {\\n      'X-Api-Key' => API_KEY,\\n      'X-Api-Signature' => calc_auth_sig_hash(url + post_data.to_json.to_s),\\n      'X-Api-Version' => '2'\\n    }\\n\\n    uri = URI API_URL\\n    Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|\\n      http.request_post(url, post_data.to_json.to_s, headers) do |res|\\n        response = JSON.parse res.body\\n        raise response['message'] if res.code != '200'\\n        return response\\n      end\\n    end\\n  end\\n\\n  def calc_auth_sig_hash url_body\\n    return Digest::HMAC.hexdigest url_body, SEC_KEY, Digest::SHA256\\n  end\\nend\\n\\napi = WyreApi.new\\napi.create_transfer({'sourceAmount'=>50,'sourceCurrency'=>'USD','dest'=>'[email protected]', 'destCurrency'=>'EUR', 'message'=>'buy sam pizza')\",\n      \"language\": \"ruby\"\n    },\n    {\n      \"code\": \"import javax.crypto.Mac;\\nimport javax.crypto.spec.SecretKeySpec;\\nimport java.io.BufferedReader;\\nimport java.io.DataOutputStream;\\nimport java.io.InputStream;\\nimport java.io.InputStreamReader;\\nimport java.lang.Integer;\\nimport java.lang.String;\\nimport java.lang.StringBuffer;\\nimport java.net.HttpURLConnection;\\nimport java.net.URL;\\n\\npublic class Main {\\n\\tpublic static void main(String[] args) {\\n\\t\\tString apiKey = \\\"fll36l3t35udalcqlh4ng6bm4qpbgher\\\";\\n\\t\\tString secretKey = \\\"tr3epinbk3maist0n3ijk18bm6dikrq6\\\";\\n\\n    //retrieve account details and balance\\n\\t\\tString url = \\\"https://api.sendwyre.com/account\\\";\\n\\t\\tString method = \\\"GET\\\";\\n\\t\\tString data = \\\"\\\";\\n\\n\\t\\tString result = executewyreRequest(url, \\\"\\\", method, apiKey, secretKey);\\n\\t\\tSystem.out.println(result);\\n\\n    //example transfer\\n\\t\\turl = \\\"https://api.sendwyre.com/transfers\\\";\\n\\t\\tmethod = \\\"POST\\\";\\n\\t\\tdata = \\\"{\\\" +\\n\\t\\t\\t\\t\\\"  \\\\\\\"dest\\\\\\\": \\\\\\\"[email protected]\\\\\\\",\\\" +\\n\\t\\t\\t\\t\\\"  \\\\\\\"destCurrency\\\\\\\": \\\\\\\"BTC\\\\\\\",\\\" +\\n\\t\\t\\t\\t\\\"  \\\\\\\"sourceCurrency\\\\\\\" : \\\\\\\"USD\\\\\\\",\\\" +\\n\\t\\t\\t\\t\\\"  \\\\\\\"sourceAmount\\\\\\\" : \\\\\\\"50\\\\\\\",\\\" +\\n\\t\\t\\t\\t\\\"  \\\\\\\"message\\\\\\\": \\\\\\\"$50 worth of bitcoin! Food please!\\\\\\\"\\\" +\\n\\t\\t\\t\\t\\\"}\\\";\\n\\t\\tresult = excutewyreRequest(url, data, method, apiKey, secretKey);\\n\\n\\t\\tSystem.out.println(result);\\n\\t}\\n\\n\\tpublic static String excutewyreRequest(String targetURL, String requestBody, String method, String apiKey, String secretKey) {\\n\\t\\tURL url;\\n\\t\\tHttpURLConnection connection = null;\\n\\t\\ttry {\\n\\n\\t\\t\\ttargetURL += ((targetURL.indexOf(\\\"?\\\")>0)?\\\"&\\\":\\\"?\\\") + \\\"timestamp=\\\" + System.currentTimeMillis();\\n\\n\\t\\t\\t//Create connection\\n\\t\\t\\turl = new URL(targetURL);\\n\\t\\t\\tconnection = (HttpURLConnection)url.openConnection();\\n\\t\\t\\tconnection.setRequestMethod(method);\\n\\t\\t\\tSystem.out.println(connection.getRequestMethod());\\n\\n\\t\\t\\tconnection.setRequestProperty(\\\"Content-Type\\\", \\\"application/json\\\");\\n\\t\\t\\tconnection.setRequestProperty(\\\"Content-Length\\\", Integer.toString(requestBody.getBytes().length));\\n\\n\\t\\t\\t//Specify API v2\\n\\t\\t\\tconnection.setRequestProperty(\\\"X-Api-Version\\\",\\\"2\\\");\\n\\n\\t\\t\\t// Provide API key and signature\\n\\t\\t\\tconnection.setRequestProperty(\\\"X-Api-Key\\\", apiKey);\\n\\t\\t\\tconnection.setRequestProperty(\\\"X-Api-Signature\\\",computeSignature(secretKey,targetURL,requestBody));\\n\\n\\t\\t\\t//Send request\\n\\t\\t\\tif(method.equals(\\\"POST\\\")) {\\n\\t\\t\\t\\tconnection.setDoOutput(true);\\n\\t\\t\\t\\tconnection.setRequestMethod(method);\\n\\n\\t\\t\\t\\tDataOutputStream wr = new DataOutputStream(\\n\\t\\t\\t\\t\\t\\tconnection.getOutputStream());\\n\\n\\t\\t\\t\\twr.writeBytes(requestBody);\\n\\t\\t\\t\\twr.flush();\\n\\t\\t\\t\\twr.close();\\n\\t\\t\\t}\\n\\n\\t\\t\\t//Get Response\\n      InputStream is = null;\\n    \\tif (connection.getResponseCode() >= 400) {\\n      \\tis = connection.getErrorStream();\\n    \\t}  \\n    \\telse {\\n      \\tis = connection.getInputStream();\\n    \\t}\\n\\t\\t\\tBufferedReader rd = new BufferedReader(new InputStreamReader(is));\\n\\t\\t\\tString line;\\n\\t\\t\\tStringBuffer response = new StringBuffer();\\n\\t\\t\\twhile((line = rd.readLine()) != null) {\\n\\t\\t\\t\\tresponse.append(line);\\n\\t\\t\\t\\tresponse.append('\\\\r');\\n\\t\\t\\t}\\n\\t\\t\\trd.close();\\n\\t\\t\\treturn response.toString();\\n\\n\\t\\t} catch (Exception e) {\\n\\n\\t\\t\\te.printStackTrace();\\n\\t\\t\\treturn null;\\n\\n\\t\\t} finally {\\n\\n\\t\\t\\tif(connection != null) {\\n\\t\\t\\t\\tconnection.disconnect();\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n\\n\\tpublic static String computeSignature(String secretKey, String url, String reqData) {\\n\\n\\t\\tString data = url + reqData;\\n\\n\\t\\tSystem.out.println(data);\\n\\n\\t\\ttry {\\n\\t\\t\\tMac sha256Hmac = Mac.getInstance(\\\"HmacSHA256\\\");\\n\\t\\t\\tSecretKeySpec key = new SecretKeySpec(secretKey.getBytes(), \\\"HmacSHA256\\\");\\n\\t\\t\\tsha256Hmac.init(key);\\n\\n\\t\\t\\tbyte[] macData = sha256Hmac.doFinal(data.getBytes());\\n\\n\\t\\t\\tString result = \\\"\\\";\\n\\t\\t\\tfor (final byte element : macData){\\n\\t\\t\\t\\tresult += Integer.toString((element & 0xff) + 0x100, 16).substring(1);\\n\\t\\t\\t}\\n\\t\\t\\treturn result;\\n\\n\\t\\t} catch (Exception e) {\\n\\t\\t\\te.printStackTrace();\\n\\t\\t\\treturn \\\"\\\";\\n\\t\\t}\\n\\t}\\n}\",\n      \"language\": \"java\"\n    },\n    {\n      \"code\": \"using System;\\nusing System.IO;\\nusing System.Net;\\nusing System.Security.Cryptography;\\nusing System.Text;\\n\\nnamespace test\\n{\\n\\tclass MainClass\\n\\t{\\n\\t\\tpublic static void Main(string[] args)\\n\\t\\t{\\n\\t\\t\\twyreApi wyreApi = new wyreApi();\\n\\n\\t\\t\\tstring balance = wyreApi.getAccount();\\n\\t\\t\\tConsole.WriteLine(balance);\\n\\n\\t\\t\\tstring transferData = \\\"{\\\" +\\n\\t\\t\\t\\t\\\"\\\\\\\"sourceCurrency\\\\\\\": \\\\\\\"USD\\\\\\\",\\\" +\\n\\t\\t\\t\\t\\\"\\\\\\\"dest\\\\\\\": \\\\\\\"[email protected]\\\\\\\",\\\" +\\n\\t\\t\\t\\t\\\"\\\\\\\"sourceAmount\\\\\\\": \\\\\\\"0.01\\\\\\\",\\\" +\\n\\t\\t\\t\\t\\\"\\\\\\\"destCurrency\\\\\\\": \\\\\\\"BTC\\\\\\\"\\\" +\\n\\t\\t\\t\\t\\\"}\\\";\\n\\t\\t\\tstring authResponse = wyreApi.transfer(transferData);\\n\\t\\t\\tConsole.WriteLine(authResponse);\\n\\t\\t}\\n\\t}\\n\\n\\tpublic class wyreApi {\\n\\t\\tprivate const string domain = \\\"https://api.sendwyre.com\\\";\\n\\t\\tprivate const string apiKey = \\\"xxxxxx\\\";\\n\\t\\tprivate const string secKey = \\\"xxxxxx\\\";\\n\\n\\t\\tpublic string getAccount() \\n\\t\\t{\\n\\t\\t\\treturn MakeGetReq(\\\"/account\\\");\\n\\t\\t}\\n\\n\\t\\tpublic string transfer(string jsonString)\\n\\t\\t{\\n\\t\\t\\treturn MakePostReq(\\\"/transfers\\\", jsonString);\\n\\t\\t}\\n\\n\\t\\tprivate string MakeGetReq(string apiRoute)\\n\\t\\t{\\n\\t\\t\\tWebRequest req = AssembleWebRequest(apiRoute);\\n\\t\\t\\treq.Method = \\\"GET\\\";\\n\\t\\t\\tWebResponse response = req.GetResponse();\\n\\t\\t\\tstring responseString = ParseWebResponse(response);\\n\\t\\t\\treturn responseString;\\n\\t\\t}\\n\\n\\t\\tprivate string MakePostReq(string apiRoute, string jsonData)\\n\\t\\t{\\n\\t\\t\\tWebRequest req = AssembleWebRequest(apiRoute, jsonData);\\n\\t\\t\\treq.Method = \\\"POST\\\";\\n\\t\\t\\tWriteJsonToRequest(req, jsonData);\\n\\n\\n\\t\\t\\tWebResponse response = req.GetResponse();\\n\\t\\t\\tstring responseString = ParseWebResponse(response);\\n\\t\\t\\treturn responseString;\\n\\t\\t}\\n\\n\\t\\tprivate WebRequest AssembleWebRequest(string apiRoute, string jsonData = \\\"\\\")\\n\\t\\t{\\n\\t\\t\\tstring url = domain + apiRoute + (apiRoute.Contains(\\\"?\\\")?\\\"&\\\":\\\"?\\\") + \\\"timestamp=\\\"+DateTime.Now.Ticks; \\n\\t\\t\\tWebRequest request = WebRequest.Create(url);\\n\\t\\t\\tstring authSig = CalcAuthSigHash(secKey, url + jsonData);\\n\\n\\t\\t\\trequest.ContentType = \\\"application/json\\\";\\n\\t\\t\\trequest.Headers[\\\"X-Api-Key\\\"] = apiKey;\\n\\t\\t\\trequest.Headers[\\\"X-Api-Signature\\\"] = authSig;\\n\\t\\t\\trequest.Headers[\\\"X-Api-Version\\\"] = \\\"2\\\";\\n\\t\\t\\treturn request;\\n\\t\\t}\\n\\n\\t\\tprivate void WriteJsonToRequest(WebRequest req, string jsonData)\\n\\t\\t{\\n\\t\\t\\tvar streamWriter = new StreamWriter(req.GetRequestStream ());\\n\\t\\t\\tstreamWriter.Write(jsonData);\\n\\t\\t\\tstreamWriter.Close();\\n\\t\\t}\\n\\n\\t\\tprivate byte[] GetBytes(string str)\\n\\t\\t{\\n\\t\\t\\treturn Encoding.UTF8.GetBytes(str);\\n\\t\\t}\\n\\n\\t\\tprivate string GetString(byte[] bytes)\\n\\t\\t{\\n\\t\\t\\treturn BitConverter.ToString(bytes);\\n\\t\\t}\\n\\n\\t\\tprivate string CalcAuthSigHash(string key, string value)\\n\\t\\t{\\n\\t\\t\\tHMACSHA256 hmac = new HMACSHA256(GetBytes(key));\\n\\t\\t\\tstring hash = GetString(hmac.ComputeHash(GetBytes(value)));\\n\\t\\t\\thash = hash.Replace(\\\"-\\\", \\\"\\\");\\n\\t\\t\\treturn hash;\\n\\t\\t}\\n\\n\\t\\tprivate string ParseWebResponse(WebResponse response)\\n\\t\\t{\\n\\t\\t\\tStreamReader streamReader = new StreamReader(response.GetResponseStream());\\n\\t\\t\\tstring result = streamReader.ReadToEnd();\\n\\t\\t\\tstreamReader.Close();\\n\\t\\t\\treturn result;\\n\\t\\t}\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    },\n    {\n      \"code\": \"<?php\\n    function make_authenticated_request($endpoint, $method, $body) {\\n        $url = 'https://api.sendwyre.com';\\n        $api_key = \\\"bh405n7stsuo5ut30iftrsl71b4iqjnv\\\";\\n        $secret_key = \\\"a19cvrchgja82urvn47kirrlrrb7stgg\\\";\\n\\n        $timestamp = floor(microtime(true)*1000);\\n        $request_url = $url . $endpoint;\\n\\n        if(strpos($request_url,\\\"?\\\"))\\n            $request_url .= '&timestamp=' . $timestamp;\\n        else\\n            $request_url .= '?timestamp=' . $timestamp;\\n\\n        if(!empty($body))\\n            $body = json_encode($body, JSON_FORCE_OBJECT);\\n        else\\n            $body = '';\\n\\n        $headers = array(\\n            \\\"Content-Type: application/json\\\",\\n            \\\"X-Api-Key: \\\". $api_key,\\n            \\\"X-Api-Signature: \\\". calc_auth_sig_hash($secret_key, $request_url . $body),\\n            \\\"X-Api-Version: 2\\\"\\n        );\\n        $curl = curl_init();\\n\\n        if($method==\\\"POST\\\"){\\n          $options = array(\\n            CURLOPT_URL             => $request_url,\\n            CURLOPT_POST            =>  true,\\n            CURLOPT_POSTFIELDS      => $body,\\n            CURLOPT_RETURNTRANSFER  => true);\\n        }else {\\n          $options = array(\\n            CURLOPT_URL             => $request_url,\\n            CURLOPT_RETURNTRANSFER  => true);\\n        }\\n        curl_setopt_array($curl, $options);\\n        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);\\n        $result = curl_exec($curl);\\n        curl_close($curl);\\n        var_dump($result);\\n        return json_decode($result, true);\\n    }\\n\\n    function calc_auth_sig_hash($seckey, $val) {\\n        $hash = hash_hmac('sha256', $val, $seckey);\\n        return $hash;\\n    }\\n\\n    echo make_authenticated_request(\\\"/account\\\", \\\"GET\\\", array());\\n\\t\\t$transfer = array(\\n      \\\"sourceCurrency\\\"=>\\\"USD\\\",\\n      \\\"dest\\\"=>\\\"[email protected]\\\",\\n      \\\"destAmount\\\"=> 55.05,\\n      \\\"destCurrency\\\"=>\\\"EUR\\\",\\n      \\\"message\\\"=> \\\"buy sam pizza\\\"\\n      );\\n\\t\\techo make_authenticated_request(\\\"/transfers\\\", \\\"POST\\\", $transfer);\\n?>\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"link\",\n  \"title\": \"Links, Resources, and Contacts\"\n}\n[/block]\n## **Links**\n\n[Wyre Main Site](https://www.sendwyre.com/)\n\n[Wyre Sign Up](https://www.sendwyre.com/wallet/sign-up)\n\n[MassPay Developer Hub](http://masspay.sendwyre.com/)\n\n[Wallet Developer Hub](http://wallets.docs.sendwyre.com/)\n\n[Merchant Developer Hub](http://docs.sendwyre.com/)\n\n## **Resources**\n\n[Github](https://github.com/wyre)\n\n[Blockchain Tech Introduction](https://bitcoin.org/en/how-it-works)\n\n[Company Information](https://angel.co/sendwyre)\n\n## **Contact**\n\n*[email protected]*\n*415-374-7356*\n1550 Bryant St, Ste 750\nSan Francisco, CA 94107\n\nOR\n\n*Use our Intercom support located on the lower right of the frontpage*","excerpt":"","slug":"tutorial","type":"basic","title":"Tutorial πŸ‡ΊπŸ‡Έ"}

Tutorial πŸ‡ΊπŸ‡Έ


This a start-to-finish guide on how to quickly get up to speed using the Wyre MassPay API. **What is MassPay? ** MassPay is utilized by companies that are looking to transfer balances between local currencies. So when you're looking to transfer funds into a customer's bank account, MassPay is what you'll want to use! Note: **Contents: ** 1. [Setting up a Wyre Account](http://masspay.sendwyre.com/v2/docs/tutorial#1-setting-up-a-wyre-account) 2. [Making API Requests](http://masspay.sendwyre.com/v2/docs/tutorial#2-making-api-requests) 3. [Constructing your first Transfer Creation request](http://masspay.sendwyre.com/v2/docs/tutorial#constructing-your-first-transfer) 4. [Example Transfers](http://masspay.sendwyre.com/v2/docs/tutorial#example-transfers) 5. [Code Examples](http://masspay.sendwyre.com/v2/docs/tutorial#code-examples) 6. [Links, Resources, and Contacts](http://masspay.sendwyre.com/v2/docs/tutorial#links-resources-and-contacts) [block:api-header] { "type": "link", "title": "1. Setting up a Wyre Account" } [/block] First, [create an account](https://dash.sendwyre.com/register) if you haven't already done so. Be sure to verify the email and phone attached to the account. To get started transferring funds you'll need the following: - API Key - SECRET Key - ACCOUNT ID These can be found in your [account settings](https://www.sendwyre.com/wallet/settings#!/api) once you have logged in. Once you have generated an API key, here's what you'll see: [block:image] { "images": [ { "image": [ "https://files.readme.io/7116657-signup.png", "signup.png", 615, 290, "#767677" ], "border": false, "caption": "" } ] } [/block] The last piece is your AccountID. This can be found by clicking on the "details" of the key that you just generated. [block:image] { "images": [ { "image": [ "https://files.readme.io/cf94636-Wyre_account_number.png", "Wyre account number.png", 641, 247, "#7c7b7c" ] } ] } [/block] **Note** Don't include the "account:" when making your requests. This - **account:pm9ddj8jr8rrq53fsk9v4bfhunieu72t** Becomes this for your requests - **pm9ddj8jr8rrq53fsk9v4bfhunieu72t** [block:api-header] { "type": "link", "title": "2. Making API Requests" } [/block] The base Wyre API URL is at https://api.sendwyre.com/v2/. All responses are in JSON. Wyre utilizes the following HTTP Headers as security measures: [block:parameters] { "data": { "0-0": "X-Api-Key", "1-0": "X-Api-Signature", "h-0": "Header Field", "h-1": "Description", "0-1": "Your Wyre API key", "1-1": "[HMAC](https://en.wikipedia.org/wiki/Hash-based_message_authentication_code) calculated with the secret key." }, "cols": 2, "rows": 2 } [/block] Calculate your API Signature HMAC as follows (code examples at bottom of page): 1. Construct your Request URL and add a *timestamp* URL parameter in milliseconds. For example, to get your account details, the Request URL is [https://api.sendwyre.com/v2/account?timestamp=1426252182534](https://api.sendwyre.com/v2/account?timestamp=1426252182534). 2. Concatenate the Request URL with the body of the HTTP request into a UTF-8 String. Use an empty string for the HTTP body in GET requests. 3. Compute the signature using HMAC using the SHA-256 algorithm and your API Secret Key. Here are Wyre's MassPay API endpoints. Click on the name links for full documentation: [block:parameters] { "data": { "h-0": "Name", "h-1": "API Endpoint", "h-2": "HTTP Method", "1-0": "[Live Exchange Rates](http://masspay.sendwyre.com/docs/checking-live-exchange-rates)", "2-0": "[Create Transfer](http://masspay.sendwyre.com/docs/creating-a-transfer-and-getting-a-quote)", "3-0": "[Confirm Transfer](http://masspay.sendwyre.com/docs/confirming-a-quote)", "h-3": "Description", "0-1": "[https://api.sendwyre.com/v2/account](https://api.sendwyre.com/v2/account)", "1-1": "[https://api.sendwyre.com/v2/rates](https://api.sendwyre.com/v2/rates)", "2-1": "[https://api.sendwyre.com/v2/transfers](https://api.sendwyre.com/v2/transfers)", "0-0": "[Account Details](http://masspay.sendwyre.com/docs/getting-your-account-and-checking-balances)", "4-0": "[Transfer Status](http://masspay.sendwyre.com/docs/getting-transfer-status-updates)", "0-2": "GET", "1-2": "GET", "2-2": "POST", "3-2": "POST", "4-2": "GET", "3-1": "[https://api.sendwyre.com/v2/transfer/:transferId/confirm](https://api.sendwyre.com/v2/:transferId/confirm)", "4-1": "[https://api.sendwyre.com/v2/transfer/:transferId](https://api.sendwyre.com/v2/:transferId)", "0-3": "Account details including contact info, balances in all currencies, KYC authorizations, and payment methods.", "1-3": "A list of exchange rates for all currency pair combinations that Wyre currently supports.", "2-3": "Creates a transfer between two currencies. The destination can be an email address, wallet address, or bank account. autoConfirm may be used but is not recommended.", "3-3": "The transfer will normally only execute after you review the details and confirm at this endpoint within 30 seconds.", "4-3": "If you don't use a callbackUrl when created the transfer, you can poll this endpoint until the order is filled. Different possible statuses are[ here](http://masspay.sendwyre.com/docs/transfer-statuses)." }, "cols": 4, "rows": 5 } [/block] [block:api-header] { "type": "link", "title": "Constructing your first Transfer" } [/block] A Transfer request is a JSON POST request that may contain up to [7 fields](http://masspay.sendwyre.com/docs/creating-a-transfer-and-getting-a-quote): - `sourceAmount` - only include either `sourceAmount` or `destAmount`, not both. `sourceAmount` is the amount removed from your main account in order to send funds to the destination. In this case you specify the amount removed from your account, and the destAmount will be determined depending on the fees and exchange rate. - `sourceCurrency` - an [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3#Current_codes) currency code that will be deducted from your account. - `dest` - a destination for the funds. This can be an email address, phone number, blockchain address, or bank account. - `destAmount` - only include either `sourceAmount` or `destAmount`, not both. `destAmount` is the exact amount that will be deposited into the `dest`. If `destAmount` is specified in the Transfer creation request the `sourceAmount` will be calculated from the `destAmount`, the exchange rate any fees on the Transfer - `destCurrency` - an [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3#Current_codes) currency code that matches the `dest` type. The `destCurrency` can be the same or different from the `sourceCurrency`. If they are different, an exchange will automatically occur. - `message` - An optional log message to include with the transfer - `callbackUrl` - An optional url that Wyre will POST a status callback to (see [Callbacks](doc:callbacks)) - `autoConfirm` - An optional parameter to automatically confirm the transfer order. Not recommended. Here is an example transfer creation request to convert BRL to USD and send it to our lead developer's bank account: [block:code] { "codes": [ { "code": "{\n \"dest\": {\n \"paymentMethodType\":\"INTERNATIONAL_TRANSFER\",\n \"country\": \"US\",\n \"currency\": \"USD\",\n \"firstNameOnAccount\": \"Sam\",\n \"lastNameOnAccount\":\"Schlachter\",\n \"accountNumber\": \"1234dinosaur\",\n \"routingNumber\": \"0000000000\",\n \"accountType\": \"savings\",\n \"bankName\": \"Bank of 'murrrica\",\n \"bankStreet\": \"112 Brannan St\",\n \"bankCity\": \"San Francisco\",\n \"bankPostal\": \"94108\",\n \"accountHolderPhoneNumber\": \"+14102239203\",\n \"beneficiaryType\": \"INDIVIDUAL\",\n \"priority\":\"HIGH\"\n },\n \"sourceCurrency\": \"BRL\",\n \"destCurrency\": \"USD\",\n \"destAmount\": 10,\n \"message\":\"Here's your $10!\"\n}", "language": "json" } ] } [/block] The response will resemble [this](http://masspay.sendwyre.com/docs/creating-a-transfer-and-getting-a-quote#section-reviewing-your-transfer). The most important part of the response is the `id` field. This is what we'll use to confirm the transfer and poll its status. If the transfer response is of the amount and at the rate we wanted, we must confirm the order by posting to the [Confirm Transfer](http://masspay.sendwyre.com/docs/confirming-a-quote) endpoint (or by using `autoConfirm` in the original request). The last step is to poll the `status` of the order from the [Transfer Status ](http://masspay.sendwyre.com/docs/getting-transfer-status-updates) endpoint until the transfer object reaches an end state- either `COMPLETED`, `EXPIRED`, or `FAILED`. Alternatively, you can pass in a URL to the `callbackUrl` field to the original transfer creation request, which will cause wyre to send an HTTP POST transfer status response to the URL. Below are examples of transfers involving bank accounts. [block:api-header] { "type": "link", "title": "Example Transfers" } [/block] **USA πŸ‡ΊπŸ‡Έ β†’ πŸ‡§πŸ‡· BRAZIL** [block:code] { "codes": [ { "code": "{\n \"dest\": {\n \"paymentMethodType\":\"INTERNATIONAL_TRANSFER\",\n \"country\": \"BR\",\n \"currency\": \"BRL\",\n \"firstNameOnAccount\": \"Robert\",\n \"lastNameOnAccount\": \"Baratheon\",\n \"accountNumber\": \"1234dinosaur\",\n \"bankName\": \"Mordor Credit Union\",\n \"cpfCnpj\": \"943759353\",\n \"accountType\": \"poupanca\",\n \"branchCode\": \"Artichoke\",\n \"accountHolderEmail\": \"[email protected]\",\n \"accountHolderPhoneNumber\": \"+14102239203\",\n \"swift\": \"DEUTUS00000\",\n \"beneficiaryType\": \"INDIVIDUAL\",\n \"priority\":\"HIGH\"\n },\n \"sourceCurrency\": \"USD\",\n \"destCurrency\": \"BRL\",\n \"destAmount\": 10,\n \"message\":\"A Lannister always pays his debts \"\n}", "language": "json" } ] } [/block] **BRAZIL πŸ‡§πŸ‡· β†’ πŸ‡ΊπŸ‡Έ USA** [block:code] { "codes": [ { "code": "{\n \"dest\": {\n \"paymentMethodType\":\"INTERNATIONAL_TRANSFER\",\n \"country\": \"US\",\n \"currency\": \"USD\",\n \"beneficiaryType\": \"INDIVIDUAL\",\n \"beneficiaryAddress\": \"112 Brannan St\",\n \"beneficiaryAddress2\": \"\", //Optional\n \"beneficiaryCity\": \"San Francisco\",\n \"beneficiaryState\": \"CA\",\n \"beneficiaryPostal\": \"94108\",\n \"beneficiaryPhoneNumber\": \"+14102239203\",\n \"beneficiaryDobDay\": \"15\",\n \"beneficiaryDobMonth\":\"12\",\n \"beneficiaryDobYear\":\"1989\",\n \"paymentType\" : \"LOCAL_BANK_WIRE\", // LOCAL_BANK_WIRE or ACH\n \"firstNameOnAccount\": \"Billy-Bob\",\n \"lastNameOnAccount\":\"Jones\",\n \"accountNumber\": \"0000000000000\",\n \"routingNumber\": \"0000000000\",\n \"accountType\": \"CHECKING\", //CHECKING or SAVINGS\n \"bankName\": \"Bank of America\"\n },\n \"sourceCurrency\": \"BRL\",\n \"destCurrency\": \"USD\",\n \"destAmount\": 10,\n \"message\":\"USD Personal example\"\n}", "language": "json" } ] } [/block] **USA πŸ‡ΊπŸ‡Έ β†’ πŸ‡¨πŸ‡³ CHINA** [block:code] { "codes": [ { "code": "{\n \"dest\": {\n \"paymentMethodType\":\"INTERNATIONAL_TRANSFER\",\n \"country\": \"CN\",\n \"currency\": \"CNY\",\n \"nameOnAccount\": \"成龍\",\n \"accountNumber\": \"1234dinosaur\",\n \"bankName\": \"ζ‹›ε•†ι“Άθ‘Œ\",\n \"accountType\": \"金卑\",\n \"branchCode\": \"ε…‰εŽθ·―ζ”―θ‘Œ\",\n \"accountHolderEmail\": \"[email protected]\",\n \"accountHolderPhoneNumber\": \"+14102239203\",\n \"swift\": \"DEUTUS00000\",\n \"beneficiaryType\": \"INDIVIDUAL\",\n \"priority\":\"HIGH\"\n },\n \"sourceCurrency\": \"USD\",\n \"destCurrency\": \"CNY\",\n \"destAmount\": 10,\n \"message\":\"\"\n}", "language": "json" } ] } [/block] **CHINA πŸ‡¨πŸ‡³ β†’ πŸ‡ΊπŸ‡Έ USA** [block:code] { "codes": [ { "code": "{\n \"dest\": {\n \"paymentMethodType\":\"INTERNATIONAL_TRANSFER\",\n \"country\": \"US\",\n \"currency\": \"USD\",\n \"beneficiaryType\": \"INDIVIDUAL\",\n \"beneficiaryAddress\": \"112 Brannan St\",\n \"beneficiaryAddress2\": \"\", //Optional\n \"beneficiaryCity\": \"San Francisco\",\n \"beneficiaryState\": \"CA\",\n \"beneficiaryPostal\": \"94108\",\n \"beneficiaryPhoneNumber\": \"+14102239203\",\n \"beneficiaryDobDay\": \"15\",\n \"beneficiaryDobMonth\":\"12\",\n \"beneficiaryDobYear\":\"1989\",\n \"paymentType\" : \"LOCAL_BANK_WIRE\", // LOCAL_BANK_WIRE or ACH\n \"firstNameOnAccount\": \"Billy-Bob\",\n \"lastNameOnAccount\":\"Jones\",\n \"accountNumber\": \"0000000000000\",\n \"routingNumber\": \"0000000000\",\n \"accountType\": \"CHECKING\", //CHECKING or SAVINGS\n \"bankName\": \"Bank of America\"\n },\n \"sourceCurrency\": \"CNY\",\n \"destCurrency\": \"USD\",\n \"destAmount\": 10,\n \"message\":\"USD Personal example\"\n}", "language": "json" } ] } [/block] [block:api-header] { "type": "link", "title": "Code Examples" } [/block] You can simply put your API Key, API Secret Key, and Account ID into these scripts, alter the example transfer request objects, and get started right away making MassPay transfers! [block:code] { "codes": [ { "code": "#dependencies:\n#python3\n#pip3 install requests\n\nimport json\nimport hmac\nimport time\nfrom requests import request\n\nclass MassPay_API(object):\n def __init__(self, account_id, api_version, api_key, api_secret):\n self.account_id = account_id\n self.api_url = 'https://api.sendwyre.com/{}'.format(api_version)\n self.api_version = api_version\n self.api_key = api_key\n self.api_secret = api_secret\n\n #authentication decorator. May raise ValueError if no json content is returned\n def authenticate_request(func):\n def wrap(self, *args, **kwargs):\n url, method, body = func(self, *args, **kwargs)\n params = {}\n timestamp = int(time.time() * 1000)\n url += '?timestamp={}'.format(timestamp)\n bodyJson = json.dumps(body) if body != '' else ''\n headers = {}\n headers['Content-Type'] = 'application/json'\n headers['X-Api-Version'] = self.api_version\n headers['X-Api-Key'] = self.api_key\n headers['X-Api-Signature'] = hmac.new(self.api_secret.encode('utf-8'), (url + bodyJson).encode('utf-8'), 'SHA256').hexdigest()\n print(headers['X-Api-Signature'])\n resp = request(method=method, url=url, params=params, data=(json.dumps(body) if body != '' else None), json=None, headers=headers)\n if resp.text is not None: #wyre will always try to give an err body\n return resp.status_code, resp.json()\n return 404, {}\n return wrap\n\n @authenticate_request\n def retrieve_exchange_rates(self):\n url = self.api_url + '/rates'\n method = 'GET'\n body = ''\n return url, method, body\n\n @authenticate_request\n def retrieve_account(self):\n url = self.api_url + '/account'\n method = 'GET'\n body = ''\n return url, method, body\n\n @authenticate_request\n def create_transfer(self, sourceAmount, sourceCurrency, destAmount, destCurrency, destination, message, autoConfirm):\n url = self.api_url + '/transfers'\n method = 'POST'\n #ONLY use either sourceAmount or destAmount, see documentation\n body = {'sourceCurrency':sourceCurrency,\n 'dest':destination, #email, wallet, or bank transfer dict\n 'destCurrency':destCurrency,\n 'message':message}\n if sourceAmount:\n body[\"sourceAmount\"] = sourceAmount\n elif destAmount:\n body[\"destAmount\"] = destAmount\n if autoConfirm:\n body['autoConfirm'] = True\n return url, method, body \n\n @authenticate_request\n def confirm_transfer(self, transfer_id):\n url = self.api_url + '/transfer/{}/confirm'.format(transfer_id)\n method = 'POST'\n body = ''\n return url, method, body \n\n @authenticate_request\n def status_transfer(self, transfer_id):\n url = self.api_url + '/transfer/{}'.format(transfer_id)\n method = 'GET'\n body = ''\n return url, method, body \n\n#USAGE Example\naccount_id = \"YOUR_ACCOUNT_ID_HERE\" #optional\napi_key = \"YOUR_API_KEY_HERE\"\nsecret_key = \"YOUR_SECRET_KEY_HERE\"\napi_version = \"2\"\n\n#create wyre MassPay API object\nwyre = MassPay_API(account_id, api_version, api_key, secret_key)\n\n#get account info\nhttp_code, account = wyre.retrieve_account()\nprint(account)\n\n#get exchange rate info\nhttp_code, rate_result = wyre.retrieve_exchange_rates()\nprint(rate_result)\n\n#BTC to CNY rate\nbtc_cny = rate_result.get(\"BTCCNY\")\n\n#amount of source (withdrawal) BTC we want to sent to Euro\namount = 50\n\n#calculate destination (deposit) amount in CNY\nfinal_amount = amount * btc_cny\n\n#example bank transfer dictionary that we will pass in as the destination\nbank_transfer = {\n \"paymentMethodType\":\"INTERNATIONAL_TRANSFER\",\n \"country\": \"CN\",\n \"currency\": \"CNY\",\n \"nameOnAccount\": \"成龍\",\n \"accountNumber\": \"1234dinosaur\",\n \"bankName\": \"ζ‹›ε•†ι“Άθ‘Œ\",\n \"accountType\": \"金卑\",\n \"branchCode\": \"ε…‰εŽθ·―ζ”―θ‘Œ\",\n \"accountHolderEmail\": \"[email protected]\",\n \"accountHolderPhoneNumber\": \"+14102239203\",\n \"swift\": \"DEUTUS00000\",\n \"beneficiaryType\": \"INDIVIDUAL\",\n \"priority\":\"HIGH\"\n }\n\n#send transfer and print result\nhttp_code, transfer_result = wyre.create_transfer(\n amount, \n \"BTC\", \n None, #final_amount\n \"CNY\", \n bank_transfer, #may also be an email or SRN\n \"sending wyre developers pizza money\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFalse)\nprint(transfer_result)\ntx_id = transfer_result['id'] #grab our transfer id\n\n#confirm transfer\nhttp_code, confirmation = wyre.confirm_transfer(tx_id)\nprint(confirmation)\n\n#check status\nhttp_code, status = wyre.status_transfer(tx_id)\nprint(status)", "language": "python" }, { "code": "require 'uri'\nrequire 'net/http'\nrequire 'digest/hmac'\nrequire 'json'\n\nclass WyreApi\n ACCOUNT_ID = 'ue5hsnusf8gene87asdf4es23bt9d7ak'\n API_KEY = '9idihi38o18mrm1234ipa1k9ooiifgts'\n SEC_KEY = '5e3kcoogptge6s5fh2qwertyb6g368dm'\n API_URL = 'https://api.sendwyre.com'\n\n def create_transfer options\n api_post '/transfers', options\n end\n\n private\n\n def api_post path, post_data = {}\n params = {\n 'timestamp' => (Time.now.to_i * 1000).to_s\n }\n\n url = API_URL + path + '?' + URI.encode_www_form(params)\n\n headers = {\n 'X-Api-Key' => API_KEY,\n 'X-Api-Signature' => calc_auth_sig_hash(url + post_data.to_json.to_s),\n 'X-Api-Version' => '2'\n }\n\n uri = URI API_URL\n Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|\n http.request_post(url, post_data.to_json.to_s, headers) do |res|\n response = JSON.parse res.body\n raise response['message'] if res.code != '200'\n return response\n end\n end\n end\n\n def calc_auth_sig_hash url_body\n return Digest::HMAC.hexdigest url_body, SEC_KEY, Digest::SHA256\n end\nend\n\napi = WyreApi.new\napi.create_transfer({'sourceAmount'=>50,'sourceCurrency'=>'USD','dest'=>'[email protected]', 'destCurrency'=>'EUR', 'message'=>'buy sam pizza')", "language": "ruby" }, { "code": "import javax.crypto.Mac;\nimport javax.crypto.spec.SecretKeySpec;\nimport java.io.BufferedReader;\nimport java.io.DataOutputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.lang.Integer;\nimport java.lang.String;\nimport java.lang.StringBuffer;\nimport java.net.HttpURLConnection;\nimport java.net.URL;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tString apiKey = \"fll36l3t35udalcqlh4ng6bm4qpbgher\";\n\t\tString secretKey = \"tr3epinbk3maist0n3ijk18bm6dikrq6\";\n\n //retrieve account details and balance\n\t\tString url = \"https://api.sendwyre.com/account\";\n\t\tString method = \"GET\";\n\t\tString data = \"\";\n\n\t\tString result = executewyreRequest(url, \"\", method, apiKey, secretKey);\n\t\tSystem.out.println(result);\n\n //example transfer\n\t\turl = \"https://api.sendwyre.com/transfers\";\n\t\tmethod = \"POST\";\n\t\tdata = \"{\" +\n\t\t\t\t\" \\\"dest\\\": \\\"[email protected]\\\",\" +\n\t\t\t\t\" \\\"destCurrency\\\": \\\"BTC\\\",\" +\n\t\t\t\t\" \\\"sourceCurrency\\\" : \\\"USD\\\",\" +\n\t\t\t\t\" \\\"sourceAmount\\\" : \\\"50\\\",\" +\n\t\t\t\t\" \\\"message\\\": \\\"$50 worth of bitcoin! Food please!\\\"\" +\n\t\t\t\t\"}\";\n\t\tresult = excutewyreRequest(url, data, method, apiKey, secretKey);\n\n\t\tSystem.out.println(result);\n\t}\n\n\tpublic static String excutewyreRequest(String targetURL, String requestBody, String method, String apiKey, String secretKey) {\n\t\tURL url;\n\t\tHttpURLConnection connection = null;\n\t\ttry {\n\n\t\t\ttargetURL += ((targetURL.indexOf(\"?\")>0)?\"&\":\"?\") + \"timestamp=\" + System.currentTimeMillis();\n\n\t\t\t//Create connection\n\t\t\turl = new URL(targetURL);\n\t\t\tconnection = (HttpURLConnection)url.openConnection();\n\t\t\tconnection.setRequestMethod(method);\n\t\t\tSystem.out.println(connection.getRequestMethod());\n\n\t\t\tconnection.setRequestProperty(\"Content-Type\", \"application/json\");\n\t\t\tconnection.setRequestProperty(\"Content-Length\", Integer.toString(requestBody.getBytes().length));\n\n\t\t\t//Specify API v2\n\t\t\tconnection.setRequestProperty(\"X-Api-Version\",\"2\");\n\n\t\t\t// Provide API key and signature\n\t\t\tconnection.setRequestProperty(\"X-Api-Key\", apiKey);\n\t\t\tconnection.setRequestProperty(\"X-Api-Signature\",computeSignature(secretKey,targetURL,requestBody));\n\n\t\t\t//Send request\n\t\t\tif(method.equals(\"POST\")) {\n\t\t\t\tconnection.setDoOutput(true);\n\t\t\t\tconnection.setRequestMethod(method);\n\n\t\t\t\tDataOutputStream wr = new DataOutputStream(\n\t\t\t\t\t\tconnection.getOutputStream());\n\n\t\t\t\twr.writeBytes(requestBody);\n\t\t\t\twr.flush();\n\t\t\t\twr.close();\n\t\t\t}\n\n\t\t\t//Get Response\n InputStream is = null;\n \tif (connection.getResponseCode() >= 400) {\n \tis = connection.getErrorStream();\n \t} \n \telse {\n \tis = connection.getInputStream();\n \t}\n\t\t\tBufferedReader rd = new BufferedReader(new InputStreamReader(is));\n\t\t\tString line;\n\t\t\tStringBuffer response = new StringBuffer();\n\t\t\twhile((line = rd.readLine()) != null) {\n\t\t\t\tresponse.append(line);\n\t\t\t\tresponse.append('\\r');\n\t\t\t}\n\t\t\trd.close();\n\t\t\treturn response.toString();\n\n\t\t} catch (Exception e) {\n\n\t\t\te.printStackTrace();\n\t\t\treturn null;\n\n\t\t} finally {\n\n\t\t\tif(connection != null) {\n\t\t\t\tconnection.disconnect();\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static String computeSignature(String secretKey, String url, String reqData) {\n\n\t\tString data = url + reqData;\n\n\t\tSystem.out.println(data);\n\n\t\ttry {\n\t\t\tMac sha256Hmac = Mac.getInstance(\"HmacSHA256\");\n\t\t\tSecretKeySpec key = new SecretKeySpec(secretKey.getBytes(), \"HmacSHA256\");\n\t\t\tsha256Hmac.init(key);\n\n\t\t\tbyte[] macData = sha256Hmac.doFinal(data.getBytes());\n\n\t\t\tString result = \"\";\n\t\t\tfor (final byte element : macData){\n\t\t\t\tresult += Integer.toString((element & 0xff) + 0x100, 16).substring(1);\n\t\t\t}\n\t\t\treturn result;\n\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\treturn \"\";\n\t\t}\n\t}\n}", "language": "java" }, { "code": "using System;\nusing System.IO;\nusing System.Net;\nusing System.Security.Cryptography;\nusing System.Text;\n\nnamespace test\n{\n\tclass MainClass\n\t{\n\t\tpublic static void Main(string[] args)\n\t\t{\n\t\t\twyreApi wyreApi = new wyreApi();\n\n\t\t\tstring balance = wyreApi.getAccount();\n\t\t\tConsole.WriteLine(balance);\n\n\t\t\tstring transferData = \"{\" +\n\t\t\t\t\"\\\"sourceCurrency\\\": \\\"USD\\\",\" +\n\t\t\t\t\"\\\"dest\\\": \\\"[email protected]\\\",\" +\n\t\t\t\t\"\\\"sourceAmount\\\": \\\"0.01\\\",\" +\n\t\t\t\t\"\\\"destCurrency\\\": \\\"BTC\\\"\" +\n\t\t\t\t\"}\";\n\t\t\tstring authResponse = wyreApi.transfer(transferData);\n\t\t\tConsole.WriteLine(authResponse);\n\t\t}\n\t}\n\n\tpublic class wyreApi {\n\t\tprivate const string domain = \"https://api.sendwyre.com\";\n\t\tprivate const string apiKey = \"xxxxxx\";\n\t\tprivate const string secKey = \"xxxxxx\";\n\n\t\tpublic string getAccount() \n\t\t{\n\t\t\treturn MakeGetReq(\"/account\");\n\t\t}\n\n\t\tpublic string transfer(string jsonString)\n\t\t{\n\t\t\treturn MakePostReq(\"/transfers\", jsonString);\n\t\t}\n\n\t\tprivate string MakeGetReq(string apiRoute)\n\t\t{\n\t\t\tWebRequest req = AssembleWebRequest(apiRoute);\n\t\t\treq.Method = \"GET\";\n\t\t\tWebResponse response = req.GetResponse();\n\t\t\tstring responseString = ParseWebResponse(response);\n\t\t\treturn responseString;\n\t\t}\n\n\t\tprivate string MakePostReq(string apiRoute, string jsonData)\n\t\t{\n\t\t\tWebRequest req = AssembleWebRequest(apiRoute, jsonData);\n\t\t\treq.Method = \"POST\";\n\t\t\tWriteJsonToRequest(req, jsonData);\n\n\n\t\t\tWebResponse response = req.GetResponse();\n\t\t\tstring responseString = ParseWebResponse(response);\n\t\t\treturn responseString;\n\t\t}\n\n\t\tprivate WebRequest AssembleWebRequest(string apiRoute, string jsonData = \"\")\n\t\t{\n\t\t\tstring url = domain + apiRoute + (apiRoute.Contains(\"?\")?\"&\":\"?\") + \"timestamp=\"+DateTime.Now.Ticks; \n\t\t\tWebRequest request = WebRequest.Create(url);\n\t\t\tstring authSig = CalcAuthSigHash(secKey, url + jsonData);\n\n\t\t\trequest.ContentType = \"application/json\";\n\t\t\trequest.Headers[\"X-Api-Key\"] = apiKey;\n\t\t\trequest.Headers[\"X-Api-Signature\"] = authSig;\n\t\t\trequest.Headers[\"X-Api-Version\"] = \"2\";\n\t\t\treturn request;\n\t\t}\n\n\t\tprivate void WriteJsonToRequest(WebRequest req, string jsonData)\n\t\t{\n\t\t\tvar streamWriter = new StreamWriter(req.GetRequestStream ());\n\t\t\tstreamWriter.Write(jsonData);\n\t\t\tstreamWriter.Close();\n\t\t}\n\n\t\tprivate byte[] GetBytes(string str)\n\t\t{\n\t\t\treturn Encoding.UTF8.GetBytes(str);\n\t\t}\n\n\t\tprivate string GetString(byte[] bytes)\n\t\t{\n\t\t\treturn BitConverter.ToString(bytes);\n\t\t}\n\n\t\tprivate string CalcAuthSigHash(string key, string value)\n\t\t{\n\t\t\tHMACSHA256 hmac = new HMACSHA256(GetBytes(key));\n\t\t\tstring hash = GetString(hmac.ComputeHash(GetBytes(value)));\n\t\t\thash = hash.Replace(\"-\", \"\");\n\t\t\treturn hash;\n\t\t}\n\n\t\tprivate string ParseWebResponse(WebResponse response)\n\t\t{\n\t\t\tStreamReader streamReader = new StreamReader(response.GetResponseStream());\n\t\t\tstring result = streamReader.ReadToEnd();\n\t\t\tstreamReader.Close();\n\t\t\treturn result;\n\t\t}\n\t}\n}", "language": "csharp" }, { "code": "<?php\n function make_authenticated_request($endpoint, $method, $body) {\n $url = 'https://api.sendwyre.com';\n $api_key = \"bh405n7stsuo5ut30iftrsl71b4iqjnv\";\n $secret_key = \"a19cvrchgja82urvn47kirrlrrb7stgg\";\n\n $timestamp = floor(microtime(true)*1000);\n $request_url = $url . $endpoint;\n\n if(strpos($request_url,\"?\"))\n $request_url .= '&timestamp=' . $timestamp;\n else\n $request_url .= '?timestamp=' . $timestamp;\n\n if(!empty($body))\n $body = json_encode($body, JSON_FORCE_OBJECT);\n else\n $body = '';\n\n $headers = array(\n \"Content-Type: application/json\",\n \"X-Api-Key: \". $api_key,\n \"X-Api-Signature: \". calc_auth_sig_hash($secret_key, $request_url . $body),\n \"X-Api-Version: 2\"\n );\n $curl = curl_init();\n\n if($method==\"POST\"){\n $options = array(\n CURLOPT_URL => $request_url,\n CURLOPT_POST => true,\n CURLOPT_POSTFIELDS => $body,\n CURLOPT_RETURNTRANSFER => true);\n }else {\n $options = array(\n CURLOPT_URL => $request_url,\n CURLOPT_RETURNTRANSFER => true);\n }\n curl_setopt_array($curl, $options);\n curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);\n $result = curl_exec($curl);\n curl_close($curl);\n var_dump($result);\n return json_decode($result, true);\n }\n\n function calc_auth_sig_hash($seckey, $val) {\n $hash = hash_hmac('sha256', $val, $seckey);\n return $hash;\n }\n\n echo make_authenticated_request(\"/account\", \"GET\", array());\n\t\t$transfer = array(\n \"sourceCurrency\"=>\"USD\",\n \"dest\"=>\"[email protected]\",\n \"destAmount\"=> 55.05,\n \"destCurrency\"=>\"EUR\",\n \"message\"=> \"buy sam pizza\"\n );\n\t\techo make_authenticated_request(\"/transfers\", \"POST\", $transfer);\n?>", "language": "php" } ] } [/block] [block:api-header] { "type": "link", "title": "Links, Resources, and Contacts" } [/block] ## **Links** [Wyre Main Site](https://www.sendwyre.com/) [Wyre Sign Up](https://www.sendwyre.com/wallet/sign-up) [MassPay Developer Hub](http://masspay.sendwyre.com/) [Wallet Developer Hub](http://wallets.docs.sendwyre.com/) [Merchant Developer Hub](http://docs.sendwyre.com/) ## **Resources** [Github](https://github.com/wyre) [Blockchain Tech Introduction](https://bitcoin.org/en/how-it-works) [Company Information](https://angel.co/sendwyre) ## **Contact** *[email protected]* *415-374-7356* 1550 Bryant St, Ste 750 San Francisco, CA 94107 OR *Use our Intercom support located on the lower right of the frontpage*