Feat(booking-job): Loop detect payment merchant
All checks were successful
ktm-booking-bot/ktm-booking-bot/pipeline/head This commit looks good

This commit is contained in:
2022-10-28 00:51:00 +08:00
parent a6b2ffa1e8
commit 8be27ce214

View File

@@ -322,29 +322,37 @@ func chooseAndMakePayment(timerCtx context.Context, creditCardType, creditCard,
log.Println("Waiting for payment gateway to load.") log.Println("Waiting for payment gateway to load.")
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
for _, currPage := range browser.MustPages() { foundPage := false
currPage.MustWaitLoad()
var currTitle string for !foundPage {
err := rod.Try(func() { for _, currPage := range browser.MustPages() {
currTitle = currPage.Timeout(100 * time.Millisecond).MustElement("title").MustText() currPage.MustWaitLoad()
})
if err != nil { var currTitle string
currTitle = "" err := rod.Try(func() {
currTitle = currPage.Timeout(100 * time.Millisecond).MustElement("title").MustText()
})
if err != nil {
currTitle = ""
}
if strings.Contains(currTitle, "Payment Acceptance") {
log.Println("Page found.")
foundPage = true
page = currPage
}
} }
if strings.Contains(currTitle, "Payment Acceptance") { // Exits if context cancelled
page = currPage select {
case <-timerCtx.Done():
browser.MustClose()
cancelRefresh()
return false
default:
} }
}
// Exits if context cancelled time.Sleep(time.Second * 1)
select {
case <-timerCtx.Done():
browser.MustClose()
cancelRefresh()
return false
default:
} }
expiryMonth := strings.Split(creditCardExpiry, "/")[0] expiryMonth := strings.Split(creditCardExpiry, "/")[0]