Skip to content

Commit

Permalink
[Eko] - setPayement request
Browse files Browse the repository at this point in the history
  • Loading branch information
Eko Aprianto committed Dec 14, 2019
1 parent 149bb56 commit 457aa34
Show file tree
Hide file tree
Showing 11 changed files with 428 additions and 22 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# ddd-go
# DDD go
Domain Driven Design written in Go


# How to run
1. copy file at presentation/config/config.json.sample and rename to rename to config.json
2. move to presentation directory
3. run command `go run main.go`
9 changes: 7 additions & 2 deletions application/flight_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func BookInfo(request domain.BookInfoRequest) (int, domain.BookInfoResponse, dom
}
}

func SetPayment() {

func SetPayment(request domain.SetPaymentRequest) (int, domain.SetPaymentResponse, domain.ErrorResponse) {
valid, response := request.Validate()
if !valid {
return http.StatusBadRequest, domain.SetPaymentResponse{}, response
} else {
return http.StatusOK, infrastructure.SjSetPayment(request), domain.ErrorResponse{}
}
}
51 changes: 51 additions & 0 deletions domain/payment.go
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
package domain

import "strings"

type SetPaymentRequest struct {
Payment Payment `json:"payment"`
FFInfo FFInfo `json:"FFInfo"`
}
type SetPaymentResponse struct {
BaseResponse
Data SetPaymentData `json:"data" xml:"data"`
}
type Payment struct {
PaymentMethod string `json:"paymentMethod"`
PaymentCardName string `json:"paymentCardName"`
PaymentTenor string `json:"paymentTenor"`
PaymentEmail string `json:"paymentEmail"`
PaymentContact PaymentContact `json:"paymentContact"`
}
type PaymentContact struct {
Email string `json:"email"`
Phone string `json:"phone"`
}
type FFInfo struct {
FFType string `json:"FFType"`
FFNumber string `json:"FFNumber"`
FFPassword string `json:"FFPassword"`
FFPoint string `json:"FFPoint"`
}

func (data SetPaymentRequest) Validate() (bool, ErrorResponse) {
valid := true
var message string
var messages []ErrorMessage
if (len(strings.TrimSpace(data.Payment.PaymentMethod)) == 0) {
valid = false
messages = append(messages, ErrorMessage{"", "paymentMethod is required!"})
message = "Some field are required"
}
response := ErrorResponse{BaseResponse{false, "", message}, messages}
return valid, response
}

type SetPaymentData struct {
PaymentCode string `json:"paymentCode"`
PaymentMethod string `json:"paymentMethod"`
PaymentMethodDescription string `json:"paymentMethodDescription"`
PaymentAmount float64 `json:"paymentAmount"`
FFDetail string `json:"FFDetail"`
SpecialRequest string `json:"specialRequest"`
BNIWOW string `json:"BNIWOW"`
}
14 changes: 14 additions & 0 deletions domain/sj_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,17 @@ type SjBookInfoResponse struct {
ERRORCODE string `json:"ERROR_CODE"`
ERRORMESSAGE string `json:"ERROR_MESSAGE"`
}

type SjSetPaymentResponse struct {
Data []struct {
PaymentCode string `json:"PAYMENT_CODE"`
PaymentMethod string `json:"PAYMENT_METHOD"`
PaymentMethodDescription string `json:"PAYMENT_METHOD_DESCRIPTION"`
Amount float64 `json:"AMOUNT"`
FFDetail string `json:"FF_DETAIL"`
SpecialRequest string `json:"SPECIAL_REQUEST"`
BNIWOW string `json:"BNIWOW"`
} `json:"DATA"`
ErrorCode string `json:"ERROR_CODE" xml""ERROR_CODE"`
ErrorMessage string `json:"ERROR_MESSAGE" xml"ERROR_MESSAGE"`
}
31 changes: 27 additions & 4 deletions infrastructure/sj_client_mob.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package infrastructure

import (
"encoding/json"
"ddd-go/domain"
"encoding/json"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -40,9 +40,34 @@ func SjSplSearch(searchRequest domain.SearchRequest) (domain.SearchResponse, err
func SjSplBook() {

}
func SjSplSetPayment() {
func SjSplSetPayment(setPaymentRequest domain.SetPaymentRequest) (domain.SetPaymentResponse, error) {
path := SjBookInfoPath()
payload := MapSjSetPaymentRequest(setPaymentRequest, path)

var response []byte = nil
var err error = nil
if SjUseMock() {
response, err = SetPaymentMock(), nil
} else {
response, err = SendRequest(path, "POST", payload)
}

var responseSpl domain.SjSetPaymentResponse
errParse := json.Unmarshal(response, &responseSpl)
if (errParse != nil) {
fmt.Println("Parse failed with error: ", errParse)
}
setPaymentData := domain.SetPaymentData{}
var setPaymentResponse domain.SetPaymentResponse
if err != nil {
setPaymentResponse = domain.SetPaymentResponse{domain.BaseResponse{false, "", "Internal Server Error"}, domain.SetPaymentData{}}
} else {
setPaymentData = MapSjSetPaymentResponse(responseSpl)
setPaymentResponse = domain.SetPaymentResponse{BaseResponse: domain.BaseResponse{true, "OK", ""}, Data: setPaymentData}
}
return setPaymentResponse, err
}

func SjSplBookInfo(bookInfoRequest domain.BookInfoRequest) (domain.BookInfoResponse, error) {
path := SjBookInfoPath()
payload := MapSjBookInfoRequest(bookInfoRequest, path)
Expand All @@ -66,10 +91,8 @@ func SjSplBookInfo(bookInfoRequest domain.BookInfoRequest) (domain.BookInfoRespo
bookInfoResponse = domain.BookInfoResponse{domain.BaseResponse{false, "", "Internal Server Error"}, domain.BookInfoData{}}
} else {
bookInfoData = MapSjBookInfoResponse(responseSpl)
//searchResponse = domain.SearchResponse{domain.BaseResponse{true, "OK", ""}, searchResponseData}
bookInfoResponse = domain.BookInfoResponse{BaseResponse: domain.BaseResponse{true, "OK", ""}, Data: bookInfoData}
}
//return responseSpl, err
return bookInfoResponse, err
//LZYHFE
}
Expand Down
27 changes: 27 additions & 0 deletions infrastructure/sj_domain_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,30 @@ func MapSjBookInfoResponse(responseSpl domain.SjBookInfoResponse) domain.BookInf
bookInfoData.ItineraryDetails.AdditionalInformation = responseSpl.DATA.YourItineraryDetails.AdditionalInformation
return bookInfoData
}

func MapSjSetPaymentRequest(setPaymentRequest domain.SetPaymentRequest, path string) *strings.Reader {
payload := strings.NewReader(
"BookingCode=" + setPaymentRequest.Payment.PaymentMethod +
"&DEVICE_ID=" + SjConfigGetDeviceId() +
"&SUBSCRIBE_ID=" + SjConfigGetSubscribeId() +
"&USERNAME=" + SjConfigGetUserName() +
"&PASSWORD=" + SjConfigGetPassword() +
"&OS=" + SjConfigGetOs() +
"&APPS_NAME=" + SjConfigGetAppsName() +
"&APPS_VERSION=" + SjConfigGetAppsVersion() +
"&API_URL=" + SjConfigGetAPibaseUrl() + path +
"&USER_LOGIN=")
return payload
}

func MapSjSetPaymentResponse(responseSpl domain.SjSetPaymentResponse) domain.SetPaymentData {
setPaymentData := domain.SetPaymentData{}
setPaymentData.PaymentCode = responseSpl.Data[0].PaymentCode
setPaymentData.PaymentMethod = responseSpl.Data[0].PaymentMethod
setPaymentData.PaymentMethodDescription = responseSpl.Data[0].PaymentMethodDescription
setPaymentData.PaymentAmount = responseSpl.Data[0].Amount
setPaymentData.FFDetail = responseSpl.Data[0].FFDetail
setPaymentData.SpecialRequest = responseSpl.Data[0].SpecialRequest
setPaymentData.BNIWOW = responseSpl.Data[0].BNIWOW
return setPaymentData
}
13 changes: 7 additions & 6 deletions infrastructure/sj_flight_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"ddd-go/domain"
)

func SjSearch(searchRequest domain.SearchRequest) domain.SearchResponse {
searchResponse, _ := SjSplSearch(searchRequest)
func SjSearch(req domain.SearchRequest) domain.SearchResponse {
searchResponse, _ := SjSplSearch(req)
return searchResponse
}

func SjBook() {

}
func SjBookInfo(bookInfoRequest domain.BookInfoRequest) domain.BookInfoResponse {
response, _ := SjSplBookInfo(bookInfoRequest)
func SjBookInfo(req domain.BookInfoRequest) domain.BookInfoResponse {
response, _ := SjSplBookInfo(req)
return response
}
func SjSetPayment() {

func SjSetPayment(req domain.SetPaymentRequest) domain.SetPaymentResponse {
response, _ := SjSplSetPayment(req)
return response
}
Loading

0 comments on commit 457aa34

Please sign in to comment.