INTRODUCTION
This Document contains the description of all and specifics functions from FasaPay XML API. XML API allows you to process sending and receiving payment automatically. Getting transaction information and history of performed transaction. These services are required for all web sites that wish to use FasaPay as one of the payment options and business that required to use automated transaction between FasaPay account.
WHO NEEDS THESE DOCUMENTS
This documents are needed for all developer working on programming interface to integrate FasaPay to their website. To be successful, developers will need experience in following:
- Preparation and sending requests to web server
- Receiving and analyzing information received from web server
- Working with HTTPS protocol
- Have knowledge of XML and know how to use HASH operations.
BASIC INFORMATION ABOUT XML API
XML API is a collection of commands, which are used as intermediaries between FasaPay and other web sites. Format and data structure of XML API was developed from standard XML-1.0
HOW IT WORKS
XML API are a system which receive and sending information request. This system will
process the request in accordance to the order then will combine the report data
and send it back to the sender's request.
Every request consists of specific command which then intepreted by API and then
ordered server to follow those instruction. After every instruction executed,
server will respons with the result of the instruction or with error message
which explain why the error occured.
Each request and response are arranged with specified format so that it will establish
specific data and can be read by XML API. Some request will result in more than one
command and or more than one response. Here some steps so that XML API can run smoothly.
- Gathering and preparing request data
- Creating correct XML format
- Creating HTTP GET or POST Request based on the prepared XML
- Sending HTTP GET or POST Request to FasaPay server through HTTPS protocol
- Wait for response from the server
- Analyzing and process the response data sent by the server FasaPay
PREPARATION
Before using XML API, you need following steps:
- You have to create API_KEY in FasaPay:
- Login to FasaPay
- in <<MEMBER AREA>> choose Account Access (API) > Account API from the menu
- Click Add API
- Enter API Name and API Secretword then Click Create API
- You will receive API_KEY, this API_KEY will be used to identify XML API request.
Secretword will be used as part of creating tokens for authentication process.
XML API OPERATIONS
XML API support the following operations :
- Transfer. Allow you to transfer fund from one account to another. With this command you may transfer any of the available currencies that FasaPay supports. This function also permits you to perform multiple (bulk) transfers.
- History. Allow you to receive history transaction of your FasaPay account. This command has many additional parameter to filter the response like date range, currencies, type of transaction, account target, etc.
- Detail. Allow you to receive detail information of specific transaction. You can include more than one of this command in single request.
- Balance. Allow you to check your FasaPay account balance.
- Account. Allow you to check specific FasaPay account, to indicate is it registered or not.
AUTHENTICATION
XML Document must contain authentication information from the user. This information used to identify user. Every request to XML-API server has to contain these informations.
-
API_KEY, you will receive your api_key after you create the API.
These api_key will be used to identify the user. - TOKEN, token is a HASH from api_secretword, api_key and UTC date.
CREATING AUTHENTICATION TOKEN
This is how you create a TOKEN
- Obtain by concatenation the following data
API_KEY:API_SECRETWORD:DATE UTC in YYYYMMDDHH
YYYY = 4 digit year
MM = 2 Digit Month
DD = 2 digit Day
HH = 2 digit hour
- Then HASH it using SHA256
example:
- api_key = 11123548cd3a5e5613325132112becf
- api_secretword = kata rahasia
- date = 20 July 2011, 15:30
Will create
11123548cd3a5e5613325132112becf:kata rahasia:2011072015And after hashed (this is your token)
e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b
REQUEST AND RESPONSE IDENTIFICATION
XML API need additional parameter of identification which permits to accurately match
each request with response. This insure the correct response is received to a spesific
request and prevents system from sending response to incorrect or misguided requests.
Id string plays a role of identification parameter. It need to be presents in a body
of XML request, set by program or website and be unique for account. Every response from
server will include obtained id parameter in the body response. Once response reveived,
user's end of API has to analyze and confirm that the response's id string of requests.
If id string are not matched - you have either received an incorrect response or there
was a malfunction within system. id parameter is also used to prevent accidental
duplicate payments via API.
Once transfer request is submited, server performs search for requests with identical
id submitted recently by this account via this API entry. If matches found, the request
will be aborted by server. and server will send following response to the user as an
indication of an error in the XML-API system.
<fasa_response id="1107210001" date_time="2011-08-01T14:15:00+07:00">
<errors id="tr-td-1" mode="transfer" code="40109">
<data>
<attribute>duplication_detected</attribute>
<message>DUPLICATION DATA DETECTED</message>
</data>
</errors>
</fasa_response>
DATA FORMATS
This table lists types and format of data utilized by FasaPay XML API
DATA TYPE |
FORMAT |
EXAMPLE |
---|---|---|
ID |
Line of text, up to 20 characters long (varchar(20)) |
id1234567890, 20110720, abcdefg |
API_KEY |
32 characters long |
1d719cf2f0888c8fbfe41933f884c955 |
TOKEN |
64 characters long |
e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b |
Amount |
Fraction with up to 4 digits in denominator, point (.) as a separator |
10000 |
Currency |
3 charaters long of currency format |
IDR, USD |
Date_time |
ISO 8601 Date Format |
2011-08-01T14:15:00+07:00 |
|
|
|
ERROR CODE
Primary Error Code
ERROR CODE | MESSAGE | DETAIL | FIX |
---|---|---|---|
40000 | NOT VALID XML REQUEST | The sended XML are not valid, broken or has wrong format | Recheck XML is there an unclosed XML tag, wrong spesial character, etc. |
40100 | UNAUTHORIZED | Authorisation failed. |
error in auth tag. like wrong api_key or wrong token |
40600 | NOT ACCEPTABLE TRANSFER | There is an error in the transfer operation |
there is an error in the transfer operation. like not enough balance, amount to much, invalid target account, etc. |
40700 | DETAIL REQUEST ERROR | There is an error in the detail operation | you have inputed invalid or nonexistence batch number. |
40800 | HISTORY REQUEST ERROR | There is an error in the history operation | check your code for invalid value. like invalid date format, invalid page value, etc. |
40900 | BALANCE REQUEST ERROR | There is an error in the balance operation | you have inputed invalid, nonexistence, or disabled currency code. |
41000 | ACCOUNT REQUEST ERROR | There is an error in the account operation | you have inputed invalid, nonexistence, or disabled FasaPay Account Number. |
Secondary Error Code
ERROR CODE | MESSAGE | DETAIL | FIX |
---|---|---|---|
40101 | WRONG API_KEY | API_KEY not found it the database |
Recheck your api_key and match it with the api_key that you create in your FasaPay account. |
40102 | WRONG API_SECRET | wrong API_SECRET | Recheck your api_secret and match it with the api_secret that you create in your FasaPay account. |
40103 | WRONG TOKEN | wrong TOKEN |
Recheck your token and hash. Make sure that you used SHA256 and using correct string. |
40104 | WRONG API_SECRETWORD | wrong API_SECRETWORD | Recheck your api_secret_word and match it with the api_secret that you create in your FasaPay account. |
40105 | UNAUTHORIZED IP | Your IP is listed in the black-list or not listed in the white-list. | Check your API Black/White List setting. |
40106 | UNAUTHORIZED TIME | You use the IP on the black listed time or not in the white-listed time. | Check your API Black/White List setting for the correct time of use. |
40107 | UNAUTHORIZED COMMAND | The Operation command is black-listed or not in the white list. | Check your API Black/White List setting. |
40108 | UNAUTHORIZED METHOD | The Method used to access API is black-listed or not in the white list. | Check your API Black/White List setting. |
40601 | INVALID OR NON EXISTENCE DESTINATION ACCOUNT | Target FasaPay account are not exists or incorrect | Recheck your <to></to> in <transfer> tag. and make sure it point to correct FasaPay Account |
40602 | NOT ENOUGH BALANCE | Balance are not enought to continue the operation | Increase your balance. like using TOPUP |
40603 | AMOUNT TO LARGE | The amount is larger than what permited by FasaPay | Decrease your transfer amount |
40604 | AMOUNT TO SMALL | The amount is smaller than what permited by FasaPay | Increase your transfer amount |
40605 | INVALID OR NON EXISTENCE SOURCE CURRENCY | The currency is either not actived or invalid value | Check the <currency> tag for invalid currency format. or check your account for disabled currency |
40701 | TRANSACTION NOT FOUND | The batch number inputed is not in FasaPay database | Make sure you inputed valid batch number |
40801 | WRONG OR INACTIVE CURRENCY | The currency is either not actived or invalid value | Check the <currency> tag for invalid currency format. or check your account for disabled currency |
40802 | INVALID DATE FORMAT (yyyy-mm-dd) | Invalid <start_date> Format | Check your <start_date> for invalid date format |
40803 | INVALID DATE FORMAT (yyyy-mm-dd) | Invalid <end_date> Format | Check your <end_date> for invalid date format |
40804 | INVALID TYPE VALUE | Invalid <type> value | Check your <type> for invalid value. make sure it one of the allowed value. |
40805 | INVALID ORDER_BY VALUE | Invalid <order_by> value | Check your <order_by> for invalid value. make sure it one of the allowed value. |
40806 | INVALID ORDER VALUE | Invalid <order> value | Check your <order> for invalid value. make sure it one of the allowed value. |
40807 | INVALID PAGE VALUE | Invalid <page> value | Check your <page> for invalid value. make sure it one of the allowed value. |
40808 | INVALID PAGE_SIZE VALUE | Invalid <page_size> value | Check your <page_size> for invalid value. make sure it one of the allowed value. |
40910 | REACH MAXIMUM ALLOWED BALANCE REQUEST BATCH COUNT | Have reached maximum allowed batch request count. | decrease the amount of batch request. |
40901 | WRONG OR INACTIVE CURRENCY | The currency is either not actived or invalid value | invalid currency format or check your account for disabled currency |
41010 | REACH MAXIMUM ALLOWED ACCOUNT REQUEST BATCH COUNT | Have reached maximum allowed batch request count. | decrease the amount of batch request. |
41001 | ACCOUNT NOT FOUND | Invalid Account number or the Requested account number is not yet registered or disabled by Admin |
XML API Operations
URL XML API
Every XML API Request are send to this URL:
https://api.fasapay.com/
or
https://www.fasapay.com/xml
General Request Structure
Here is basic template of XML Request.
Every operation has same structure.
Start with fasa_request tag, then auth block and followed by request block
<fasa_request id="idrequest">
<auth>
<api_key>API KEY</api_key>
<token>AUTHENTICATION TOKEN</token>
</auth>
<operation name> <!-- operation No.1 -->
... operation data ...
</operation name>
...
<operation name> <!-- operation No.N -->
... operation data ...
</operation name>
</fasa_request>
General Response Structure
Here is basic template of XML Response.
Start with fasa_response
<fasa_response id="idrequest">
<operation name> <!-- operation No.1 -->
... status operation data ...
</operation name>
...
<operation name> <!-- operation No.N -->
... status operation data ...
</operation name>
</fasa_response>
If error happen while an operation executed it will create error response with the following format.
<errors id="if-operation-has-id" mode="operation name" code="primary-error-code">
<data><!—error data No.1 -->
<code>secondary-error-code</code>
<attribute>affected attribute (attribute which has invalid data)</attribute>
<message>error-message</message>
</data>
....
<data>><!—error data No.N-->
<code>secondary-error-code</code>
<attribute>affected attribute (attribute which has invalid data)</attribute>
<message>error-message</message>
</data>
</errors>
Note that error only cancel the operation which the error happened, so if there were more
than one operation within one request it will only cancel the operation which the error
happened and still executing the other operation.
-
TRANSFER REQUEST
REQUEST URL :
https://api.fasapay.com/?req=requestbody
or
https://www.fasapay.com/xml?req=requestbody
Request transfer used if you want to transfer fund from one account to another.
Here are the required data for this operation
-
required to, is the FasaPay account target
format : FPnnnnn
example : FP123456 -
required amount, is the amount of the transfered fund. with point (.) as the decimal separator
format : float
example : 100000.10 -
required currency, is the currency used in the transfer
format : string (IDR | USD)
example : IDR -
optional fee_mode, is Fee Mode used in the transfer. default to FiR
format : string (FiR | FiS)
example : FiR -
optional note, is note of the transfer
format : string max 255 character
example : Refund Transaction A -
optional id, id transfer for marking the transfer
format : string max 50 character
example : TR1111 -
optional ref, Reference Code that can be used to track transaction
format : string max 50 character
example : ORDER12345
Here is the xml format of transfer request:
<transfer id="abc">
<to>TARGET ACCOUNT</to>
<amount>AMOUNT TO TRANSFER</amount>
<currency>CURRENCY USED</currency>
<fee_mode>FiS</fee_mode>
<note>TRANSFER NOTE</note>
</transfer>
EXAMPLE OF VALID TRANSFER REQUEST FORMAT
<fasa_request id="1234567">
<auth>
<api_key>11123548cd3a5e5613325132112becf</api_key>
<token>e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b</token>
</auth>
<transfer id="tid">
<to>FP89680</to>
<amount>1000.0</amount>
<currency>idr</currency>
<note>standart operation</note>
</transfer>
</fasa_request>
EXAMPLE OF VALID BATCH TRANSFER REQUEST FORMAT
<fasa_request id="1234567">
<auth><!-- authentication tag. required on every request -->
<api_key>11123548cd3a5e5613325132112becf</api_key>
<token>e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b</token>
</auth>
<transfer id="tid-1"> <!-- transfer tag dan ididentifier -->
<to>FP00001</to> <!-- akun tujuan-->
<amount>1000.0</amount> <!-- jumlah yang ditransfer -->
<currency>idr</currency> <!-- kurensi yang digunakan -->
<note>note note</note> <!-- catatan -->
</transfer>
<transfer id="tid-2">
<to>FP00002</to>
<amount>1000.0</amount>
<currency>idr</currency>
<note>no note</note>
</transfer>
<transfer id="tid-3">
<to>FP00003</to>
<amount>1000.0</amount>
<currency>idr</currency>
<note></note>
</transfer>
</fasa_request>
ERROR AND RESPONSE
FasaPay will response with <fasa_response> tag
EXAMPLE OF TRANSFER RESPONSE
<fasa_response id="1311059195" date_time="2011-07-19T14:06:35+07:00">
<transfer mode="transfer" code="203">
<batchnumber>TR2011071917277</batchnumber>
<date>2011-07-19</date>
<time>14:06:35</time>
<from>FP12049</from>
<to>FP89680</to>
<amount>1000.0</amount>
<fee>100</fee>
<total>1100.0</total>
<fee_mode>FiS</fee_mode>
<currency>IDR</currency>
<note>standart operation</note>
<status>FINISH</status>
<type>Keluar</type>
<balance>2815832.00</balance>
<method>xml_api</method>
</transfer>
</fasa_response>
EXAMPLE OF ERROR RESPONSE
<fasa_response id="1311059195" date_time="2011-07-19T14:06:35+07:00">
<errors id="tid3" mode="transfer" code="40600">
<data>
<code>40605</code>
<attribute>id_kurensi</attribute>
<message>Kurensi tidak boleh kosong.</message>
</data>
<data>
<code>40601</code>
<attribute>to</attribute>
<message>Tidak ada User dengan Nomor Akun FP89681</message>
</data>
<data>
<code>40602</code>
<attribute>jumlah</attribute>
<message>Jumlah melebihi batas yg diijinkan.</message>
</data>
</errors>
</fasa_response>
-
required to, is the FasaPay account target
-
HISTORY REQUEST
REQUEST URL :
https://api.fasapay.com/?req=requestbody
or
https://www.fasapay.com/xml?req=requestbody
History Request are used to get latest transaction history in your FasaPay account.
Request history does not need any parameter to get 10 lates transaction.
But it has following parameter to get specific transaction history :- optional start_date, for specify start date.
format : YYYY-mm-dd
example : 2011-03-01 - optional end_date, for specify end date.
format : YYYY-mm-dd
example : 2011-03-05 2011-03-30 - optional type, for specify transaction type.
format : string transfer|topup|redeem|exchange|receive
example : transfer - optional order_by, for specify order/sort by spesific parameters (sorting)
format : string date|amount|to|from|currency|bank
example : date - optional order, specify order type
format : string ASC|DESC
example : asc - optional page, for getting spesific page from history transaction which has more than one page
format : integer
example : 1 - optional page_size, for specify how much transaction per page
format : integer, max 20
example : 20
Here is the basic xml format for history request :
<history>
... parameters ...
</history>EXAMPLE OF VALID BASIC HISTORY REQUEST
<fasa_request id="1234567">
<auth><!-- authentication tag. required on every request -->
<api_key>11123548cd3a5e5613325132112becf</api_key>
<token>e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b</token>
</auth>
<history>
</history>
</fasa_request>EXAMPLE OF VALID HISTORY REQUEST WITH PARAMETERS
<fasa_request id="1234567">
<auth><!-- authentication tag. required on every request -->
<api_key>11123548cd3a5e5613325132112becf</api_key>
<token>e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b</token>
</auth>
<history>
<start_date>2011-07-01</start_date>
<end_date>2011-07-09</end_date>
<type>transfer</type>
<order_by>date</order_by>
<order>DESC</order>
<page>3</page>
<page_size>5</page_size>
</history>
</fasa_request>
EXAMPLE OF HISTORY RESPONSE
<fasa_response id="1312342474" date_time="2011-08-03T10:34:34+07:00">
<history>
<page>
<total_item>579</total_item>
<page_count>58</page_count>
<current_page>0</current_page>
</page>
<detail>
<batchnumber>TR2011072685119</batchnumber>
<datetime>2011-07-26 15:44:35</datetime>
<type>Keluar</type>
<to>FP10500</to>
<from>FP12049</from>
<amount>11160.000</amount>
<note>Pembayaran untuk pembelian Liberty Reserve</note>
<status>FINISH</status>
</detail>
<detail>
<batchnumber>TR2011072521135</batchnumber>
<datetime>2011-07-25 11:38:43</datetime>
<type>Keluar</type>
<to>FP89680</to>
<from>FP12049</from>
<amount>1000.000</amount>
<note>standart operation</note>
<status>FINISH</status>
</detail>
</history>
</fasa_response>
- optional start_date, for specify start date.
-
DETAIL REQUEST
REQUEST URL :https://api.fasapay.com/?req=requestbody
or
https://www.fasapay.com/xml?req=requestbody
Detail-Request is used to get the detailed transaction information.
Detail-Request only needs BATCHNUMBER of transactions that you want to see.Detail-Request can also use this parameter to search for specific transaction :
- ref, REF parameter used to search for spesific fp_merchant_ref string that was saved by FasaPay during Transaction using SCI
- note, NOTE Parameter used to search for spesific note string that was saved by FasaPay During Transaction.
Here is the basic xml format for detail request :
<detail>TR2012092712345</detail>
<detail><ref>BL12345</ref></detail>
<detail><note>Pembayaran</note></detail>
EXAMPLE OF VALID DETAIL REQUEST FORMAT
<fasa_request id="1234567">
<auth>
<api_key>11123548cd3a5e5613325132112becf</api_key>
<token>e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b</token>
</auth>
<detail>TR2012092712345</detail>
</fasa_request>
EXAMPLE OF VALID BATCH DETAIL REQUEST FORMAT
<fasa_request id="1234567">
<auth><!-- authentication tag. required on every request -->
<api_key>11123548cd3a5e5613325132112becf</api_key>
<token>e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b</token>
</auth>
<detail>TU2012092712345</detail>
<detail>TR2012100265432</detail>
<detail>TR2012092791234</detail>
<detail><ref>BL12345</ref></detail>
<detail><note>Pembayaran</note></detail>
</fasa_request>
ERROR AND RESPONSE
FasaPay will response with <fasa_response> tag
EXAMPLE OF DETAIL RESPONSE
<fasa_response id="1234567" date_time="2013-01-01T10:58:43+07:00">
<detail mode="detail" code="210">
<batchnumber>TR2012092791234</batchnumber>
<date>2012-10-20</date>
<time>10:09:36</time>
<from>FP00001</from>
<to>FP00002</to>
<amount>1000.000</amount>
<total>1100</total>
<currency>IDR</currency>
<note>Payment for something</note>
<status>FINISH</status>
<fee>100.000</fee>
<type>Transfer Out</type>
<method>api_xml</method>
<fee_mod>FiS</fee_mod>
</detail>
</fasa_response>
EXAMPLE OF ERROR RESPONSE
<fasa_response id="1234567" date_time="2013-01-01T10:58:43+07:00"> <errors mode="detail" code="40701"> <data> <message>TRANSACTION NOT FOUND</message> <detail>BATCHNUMBER TR2012100291308 NOT FOUND</detail> </data> </errors> </fasa_response>
-
BALANCE REQUEST
REQUEST URL :
https://api.fasapay.com/?req=requestbody
or
https://www.fasapay.com/xml?req=requestbody
Balance Request is used to get the amount of balance in your account.
Balance request only needs currency code of currency that you want to see. (IDR, USD)
Here is the basic xml format for balance request :
<balance>IDR</balance>
EXAMPLE OF VALID BALANCE REQUEST FORMAT
<fasa_request id="1234567">
<auth>
<api_key>11123548cd3a5e5613325132112becf</api_key>
<token>e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b</token>
</auth>
<balance>IDR</balance>
</fasa_request>
EXAMPLE OF VALID BATCH BALANCE REQUEST FORMAT
<fasa_request id="1234567">
<auth><!-- authentication tag. required on every request -->
<api_key>11123548cd3a5e5613325132112becf</api_key>
<token>e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b</token>
</auth>
<balance>IDR</balance>
<balance>USD</balance> </fasa_request>
ERROR AND RESPONSE
FasaPay will response with <fasa_response> tag
EXAMPLE OF BALANCE RESPONSE
<fasa_response id="1234567" date_time="2013-01-01T10:58:43+07:00">
<balance>
<IDR>19092587.45</IDR>
<USD>3987.31</USD>
</balance>
</fasa_response>
EXAMPLE OF ERROR RESPONSE
<fasa_response id="1234567" date_time="2013-01-01T10:58:43+07:00">
<errors mode="balance" code="40901">
<data>
<message>WRONG OR INACTIVE CURRENCY</message>
<detail>WRONG OR INACTIVE CURRENCY CHY</detail>
</data>
</errors>
</fasa_response> -
ACCOUNT REQUEST
REQUEST URL :
https://api.fasapay.com/?req=requestbody
or
https://www.fasapay.com/xml?req=requestbody
Account request is used to get the information of certain FasaPay user by their account number.
Account request only needs account number of FasaPay account that you want to see.
Here is the basic xml format for account request :
<account>FP00001</account>
EXAMPLE OF VALID ACCOUNT REQUEST FORMAT
<fasa_request id="1234567">
<auth>
<api_key>11123548cd3a5e5613325132112becf</api_key>
<token>e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b</token>
</auth>
<account>FP00001</account>
</fasa_request>
EXAMPLE OF VALID BATCH ACCOUNT REQUEST FORMAT
<fasa_request id="1234567">
<auth><!-- authentication tag. required on every request -->
<api_key>11123548cd3a5e5613325132112becf</api_key>
<token>e910361e42dafdfd100b19701c2ef403858cab640fd699afc67b78c7603ddb1b</token>
</auth>
<account>FP00001</account>
<account>FP00002</account> </fasa_request>
ERROR AND RESPONSE
FasaPay will response with <fasa_response> tag
EXAMPLE OF ACCOUNT RESPONSE
<fasa_response id="1234567" date_time="2013-01-01T10:58:43+07:00">
<account>
<fullname>Budiman</fullname>
<account>FP00001</account>
<status>Store</status>
</account>
<account>
<fullname>Ani Permata</fullname>
<account>FP00002</account>
<status>Standard</status>
</account>
</fasa_response>
EXAMPLE OF ERROR RESPONSE
<fasa_response id="1234567" date_time="2013-01-01T10:58:43+07:00">
<errors mode="account" code="41001">
<data>
<message>ACCOUNT NOT FOUND</message> <detail>FP ACCOUNT FP12345 NOT FOUND</detail>
</data>
</errors>
</fasa_response>
XML API PHP Function Snippet
CREATE TOKEN
This function are used to create token
/** * For creating token used to authenticate xml api request * * @param string $api_key 32 character of api_key * @param string $api_secretword secret word used to created xml api * @return string sha256 hashed token **/ function createToken($api_key, $api_secretword){ $str = $api_key.":".$api_secretword.":".gmdate("YmdH"); return hash('sha256',$str); }
BUILD AUTH
This function are used to create auth tag
/** * for building xml auth xml tag * * @param string $api_key 32 character of api_key * @param string $token token which has created using createToken function * @return string auth xml tag **/ function buildAuth($api_key, $token){ $str = '<auth> <api_key>'.$api_key.'</api_key> <token>'.$token.'</token> </auth>'; return $str; }
BUILD TRANSFER
This function are used to create transfer request xml tag
/** * for building xml transfer tag * * @param string $id transfer identification string * @param string $to destination FasaPay account (FP12345) * @param float $amount amount of money to transfer * @param string $currency 3 character of currency used (IDR|USD|JPY) * @param string $note transfer note * @return string xml formated transfer request **/ function buildTransfer($id, $to, $amount, $currency="IDR", $note=""){ $str = '<transfer id="'.$id.'"> <to>'.$to.'</to> <amount>'.$amount.'</amount> <currency>'.$currency.'</currency> <note>'.$note.'</note> </transfer> '; return $str; }
BUILD XML
This function are used to create xml request document
/** * for building xml request document * * @param string $id request identification string * @param string $auth xml formated auth tag (created with buildAuth) * @param string/array $request xml formated request body (created with buildTransfer,buildHistory,buildDetail,etc) * @return string xml formated request xml document **/ public function buildXml($id, $auth, $request){ $str = ''; $str .= $auth; if(is_array($request)){ foreach($request as $value){ $str .= $value; } } else { $str .= $request; } $str .= ' '; return $str; }
GET RESPONSE
This function are used to send request xml using CURL to FasaPay XML API Server. This function will return the response from FasaPay XML API Server.
/**
* sending request xml through curl and returning xml response from xml api
* @param string $xml xml request created using buildXml (or manualy)
* @return string xml formated fasa response
**/
function getResponse($xml)
{
$url = "https://www.fasapay.com/xml/";
$handler = curl_init($url);
curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handler, 115, 1);
// Sending request through post
curl_setopt($handler, CURLOPT_POST, true);
curl_setopt($handler, CURLOPT_POSTFIELDS, 'req='.urlencode($xml));
// Some optimization :)
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($handler);
curl_close($handler);
return $content;
}