Feat(booking): New payment mode - KTMWallet
All checks were successful
ktm-booking-bot/ktm-booking-bot/pipeline/head This commit looks good
All checks were successful
ktm-booking-bot/ktm-booking-bot/pipeline/head This commit looks good
This commit is contained in:
@@ -583,7 +583,7 @@ const docTemplate = `{
|
||||
},
|
||||
"ktmTrainCreditCardType": {
|
||||
"type": "string",
|
||||
"example": "Visa|Mastercard"
|
||||
"example": "Visa|Mastercard|KTMWallet"
|
||||
},
|
||||
"ktmTrainPassword": {
|
||||
"type": "string",
|
||||
|
||||
@@ -575,7 +575,7 @@
|
||||
},
|
||||
"ktmTrainCreditCardType": {
|
||||
"type": "string",
|
||||
"example": "Visa|Mastercard"
|
||||
"example": "Visa|Mastercard|KTMWallet"
|
||||
},
|
||||
"ktmTrainPassword": {
|
||||
"type": "string",
|
||||
|
||||
@@ -106,7 +106,7 @@ definitions:
|
||||
example: 01/2022
|
||||
type: string
|
||||
ktmTrainCreditCardType:
|
||||
example: Visa|Mastercard
|
||||
example: Visa|Mastercard|KTMWallet
|
||||
type: string
|
||||
ktmTrainPassword:
|
||||
example: password
|
||||
|
||||
@@ -77,7 +77,7 @@ func (env *Env) BackgroundJobRunner() {
|
||||
} else { // if there's job to do
|
||||
// Create next run where it's not the past (either from old NextRun or now())
|
||||
timeNow := time.Now()
|
||||
startTime := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 10, 0, 0, timeNow.Location())
|
||||
startTime := time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 22, 34, 0, 0, timeNow.Location())
|
||||
endTime := startTime.Add(10 * time.Minute)
|
||||
|
||||
if timeNow.After(startTime) && timeNow.Before(endTime) {
|
||||
@@ -105,7 +105,7 @@ func (env *Env) BackgroundJobRunner() {
|
||||
success := env.startBooking(&jobToDo, username, password, creditCardType, creditCard, creditCardCVV, creditCardExpiry)
|
||||
if success {
|
||||
jobToDo.Status = "success"
|
||||
env.DB.Save(jobToDo)
|
||||
env.DB.Save(&jobToDo)
|
||||
fmt.Println("Successfully made a booking.")
|
||||
} else {
|
||||
// Sleep for 10 minutes before setting status to pending
|
||||
@@ -275,8 +275,9 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre
|
||||
default:
|
||||
}
|
||||
|
||||
page = choosePayment(page)
|
||||
log.Println("Payment method chosen.")
|
||||
if strings.ToUpper(creditCardType) == "VISA" || strings.ToUpper(creditCardType) == "MASTERCARD" {
|
||||
page = choosePaymentCreditCard(page)
|
||||
log.Println("Credit card payment method chosen.")
|
||||
|
||||
// Wait 5 seconds for payment gateway to load
|
||||
time.Sleep(time.Second * 5)
|
||||
@@ -309,7 +310,12 @@ func (env *Env) startBooking(job *Booking, username string, password string, cre
|
||||
expiryYear := strings.Split(creditCardExpiry, "/")[1]
|
||||
|
||||
page = makePayment(page, creditCardType, creditCard, expiryMonth, expiryYear, creditCardCVV)
|
||||
log.Println("Payment made.")
|
||||
log.Println("Credit card payment made.")
|
||||
} else if strings.ToUpper(creditCardType) == "KTMWALLET" {
|
||||
page = choosePaymentKTMWallet(page)
|
||||
log.Println("KTM wallet payment method chosen.")
|
||||
log.Println("KTM wallet payment made.")
|
||||
}
|
||||
|
||||
// // Start debug screenshots
|
||||
// debugScreenshotCtx, cancelDebugScreenshot := context.WithCancel(context.Background())
|
||||
@@ -499,7 +505,15 @@ func fillPassengerDetails(page *rod.Page, name string, gender string, passport s
|
||||
return page
|
||||
}
|
||||
|
||||
func choosePayment(page *rod.Page) *rod.Page {
|
||||
func choosePaymentKTMWallet(page *rod.Page) *rod.Page {
|
||||
creditCardButton := page.MustElement(".btn-ktmb-ewallet")
|
||||
creditCardButton.Eval(`this.click()`)
|
||||
page.MustWaitLoad()
|
||||
|
||||
return page
|
||||
}
|
||||
|
||||
func choosePaymentCreditCard(page *rod.Page) *rod.Page {
|
||||
creditCardButton := page.MustElement(".btn-public-bank")
|
||||
creditCardButton.Eval(`this.click()`)
|
||||
page.MustWaitLoad()
|
||||
|
||||
@@ -24,7 +24,7 @@ type Profile struct {
|
||||
type ProfileRequest struct {
|
||||
KtmTrainUsername string `json:"ktmTrainUsername" swaggertype:"string" example:"user@gmail.com"`
|
||||
KtmTrainPassword string `json:"ktmTrainPassword" swaggertype:"string" example:"password"`
|
||||
KtmTrainCreditCardType string `json:"ktmTrainCreditCardType" swaggertype:"string" example:"Visa|Mastercard"`
|
||||
KtmTrainCreditCardType string `json:"ktmTrainCreditCardType" swaggertype:"string" example:"Visa|Mastercard|KTMWallet"`
|
||||
KtmTrainCreditCard string `json:"ktmTrainCreditCard" swaggertype:"string" example:"1234123412341234"`
|
||||
KtmTrainCreditCardExpiry string `json:"ktmTrainCreditCardExpiry" swaggertype:"string" example:"01/2022"`
|
||||
KtmTrainCreditCardCVV string `json:"ktmTrainCreditCardCVV" swaggertype:"string" example:"123"`
|
||||
|
||||
Reference in New Issue
Block a user