|
|
@ -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,41 +275,47 @@ 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) |
|
|
|
// Wait 5 seconds for payment gateway to load
|
|
|
|
time.Sleep(time.Second * 5) |
|
|
|
|
|
|
|
for _, currPage := range browser.MustPages() { |
|
|
|
currPage.MustWaitLoad() |
|
|
|
for _, currPage := range browser.MustPages() { |
|
|
|
currPage.MustWaitLoad() |
|
|
|
|
|
|
|
var currTitle string |
|
|
|
err := rod.Try(func() { |
|
|
|
currTitle = currPage.Timeout(100 * time.Millisecond).MustElement("title").MustText() |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
currTitle = "" |
|
|
|
} |
|
|
|
var currTitle string |
|
|
|
err := rod.Try(func() { |
|
|
|
currTitle = currPage.Timeout(100 * time.Millisecond).MustElement("title").MustText() |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
currTitle = "" |
|
|
|
} |
|
|
|
|
|
|
|
if strings.Contains(currTitle, "Payment Acceptance") { |
|
|
|
page = currPage |
|
|
|
if strings.Contains(currTitle, "Payment Acceptance") { |
|
|
|
page = currPage |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Exits if context cancelled
|
|
|
|
select { |
|
|
|
case <-timerCtx.Done(): |
|
|
|
browser.MustClose() |
|
|
|
return false |
|
|
|
default: |
|
|
|
} |
|
|
|
// Exits if context cancelled
|
|
|
|
select { |
|
|
|
case <-timerCtx.Done(): |
|
|
|
browser.MustClose() |
|
|
|
return false |
|
|
|
default: |
|
|
|
} |
|
|
|
|
|
|
|
expiryMonth := strings.Split(creditCardExpiry, "/")[0] |
|
|
|
expiryYear := strings.Split(creditCardExpiry, "/")[1] |
|
|
|
expiryMonth := strings.Split(creditCardExpiry, "/")[0] |
|
|
|
expiryYear := strings.Split(creditCardExpiry, "/")[1] |
|
|
|
|
|
|
|
page = makePayment(page, creditCardType, creditCard, expiryMonth, expiryYear, creditCardCVV) |
|
|
|
log.Println("Payment made.") |
|
|
|
page = makePayment(page, creditCardType, creditCard, expiryMonth, expiryYear, creditCardCVV) |
|
|
|
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() |
|
|
|