README ¶
WsCreditBalance: Credit Balance Method
Credit Balance (WsCreditBalance) is a service method to retrieve credit balance information from Sriwijaya Air Web Service (SOAP) v.111 [1].
In this example you will learn about using Credit Balance Method (WsCreditBalance) with Go (using sjwsdk111 package).
The following are the sections available in this guide.
What you’ll build
Let’s make a real world simple application for retrieving credit balance information using Sriwijaya Air Web Services Endpoint. Following diagram demonstrates the credit balance use case.
Prerequisites
go get github.com/ClientSDK/sriwijaya-ws-client-go/sjwsdk111
- A Text Editor or an IDE
Sriwijaya Air Agent requirements
- Sriwijaya Air Agent Credential Account (Agent Application)
- Sriwijaya Air Web Service Access (IP Whitelist) ( Production, Development )
- WSDL File ( Production, Development )
Implementation
If you want to skip the basics, you can download the git repo and directly move to the "Build and Running" section by skipping "Implementation" section.
Example structure
Go is a complete programming language that supports custom project structures. Let's use the following package structure for this example.
sjwsv111
├── by-features
│ ├── 01.WsCreditBalance
│ │ ├── README.md
│ │ ├── build_and_run.sh
│ │ └── main.go
└── wsdl
└── wsp-wsdl.eticketv111.wsdl
-
Create the above directories in your local machine and also create empty
main.go
andbuild_and_run.sh
files. -
Download Sriwijaya Air Web Service WSDL and saved to
wsp-wsdl.eticketv111.wsdl
.
Developing the application
Let's make a simple application for retrieving credit balance information using sjwsdk111
package.
package main
import (
"crypto/tls"
"encoding/xml"
"fmt"
"net/http"
"net/url"
"github.com/ClientSDK/sriwijaya-ws-client-go/sjwsdk111"
)
func makeHTTPClient() *http.Client {
// Access via proxy if needed
proxyURL, _ := url.Parse("http://proxy-ip-address:proxy-port")
//proxyURL, _ := url.Parse("http://proxy-user:proxy-password@proxy-ip-address:proxy-port")
// Initite transport with proxy and skip TLS (if needed)
tr := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
// Initiate transport without proxy and skip TLS (if needed)
// tr := &http.Transport{
// TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
// }
httpClient := &http.Client{Transport: tr}
return httpClient
}
func main() {
// Initiate http client
httpClient := makeHTTPClient()
// Initiate NewSoapSJClient version 111
sjClient, err := sjwsdk111.NewSoapSJClient(httpClient, "../../wsdl/wsp-wsdl.eticketv111.wsdl", "file")
if err != nil {
fmt.Println(err)
}
// call Sriwijaya web service operation
callWsCreditBalance(sjClient)
}
// callWsCreditBalance is a function to call WsCreditBalance method
func callWsCreditBalance(s *sjwsdk111.SoapSJClient) {
params := []byte(
`
<Username xsi:type="xsd:string">SRIWIJAWA_AGENT_USERNAME</Username>
<Password xsi:type="xsd:string">SRIWIJAWA_AGENT_PASSWORD</Password>
`)
wsResp, errC := s.CallWsCreditBalance(params, false)
if errC != nil {
fmt.Println(errC)
return
}
// Access response variable
// fmt.Println()
// fmt.Println("ReturnData-WsCreditBalance:")
// fmt.Printf("%#v\n", wsResp.Return)
// Marshal response variable to XML
myXML, _ := xml.MarshalIndent(wsResp, " ", " ")
fmt.Println(string(myXML))
}
echo "Clean..."
rm ./WsCreditBalance
echo "Build..."
go build -o WsCreditBalance main.go
echo "Build Done."
echo "Run..."
./WsCreditBalance > WsCreditBalance-Result.xml
echo "Done."
Build and Running
You can build and running by execute the "build_and_run.sh" bash files.
$ sh build_and_run.sh
After the application is running, you will get the xml response in WsCreditBalance-Result.xml
files.
Sample Response
<WsCreditBalanceResponse>
<return>
<Username>SRIWIJAWA_AGENT_USERNAME</Username>
<CreditBalance>20188102</CreditBalance>
<ErrorCode>CR_BALANCE0000</ErrorCode>
<ErrorMessage>Success.</ErrorMessage>
</return>
</WsCreditBalanceResponse>