How to use getMessage method of validation Package

Best Gauge code snippet using validation.getMessage

constraints_common.go

Source:constraints_common.go Github

copy

Full Screen

...175 if str, ok := v.(string); ok {176 if p, ok := presetsRegistry.get(c.Preset); ok {177 if !p.Check(str) {178 vcx.CeaseFurtherIf(c.Stop)179 return false, c.getMessage(vcx, p.GetMessage())180 }181 } else {182 vcx.CeaseFurtherIf(c.Stop)183 return false, vcx.TranslateFormat(fmtMsgUnknownPresetPattern, c.Preset)184 }185 }186 return true, ""187}188func (c *StringPresetPattern) getMessage(tcx I18nContext, msg string) string {189 if c.Message != "" {190 return obtainI18nContext(tcx).TranslateMessage(c.Message)191 } else if msg != "" {192 return obtainI18nContext(tcx).TranslateMessage(msg)193 }194 // still an empty message...195 return obtainI18nContext(tcx).TranslateMessage(msgValidPattern)196}197// GetMessage implements the Constraint.GetMessage198func (c *StringPresetPattern) GetMessage(tcx I18nContext) string {199 if c.Message != "" {200 return obtainI18nContext(tcx).TranslateMessage(c.Message)201 } else if p, ok := presetsRegistry.get(c.Preset); ok {202 if msg := p.GetMessage(); msg != "" {...

Full Screen

Full Screen

pay_zen.go

Source:pay_zen.go Github

copy

Full Screen

...27}28/* pay operations */29func (this *PayZen) PaymentCreate(payment *api.Payment) (*api.PaymentResult, error) {30 if !this.onValid(payment) {31 return nil, errors.New(this.getMessage("PayZen.ValidationError"))32 }33 if payment.Card.Scheme == SchemeBoleto && payment.Account.Mode == PayZenModeProduction {34 switch payment.BoletoOnline {35 case api.BoletoOnline, api.BoletoOnlineItauIb, api.BoletoOnlineItauBoleto, api.BoletoOnlineBradescoBoleto:36 return this.PaymentCreateBoletoOnline(payment)37 }38 }39 this.ToolBox = NewPayZenToolBox(payment.Account)40 this.ToolBox.Debug = this.Debug41 return this.ToolBox.CreatePayment(payment)42}43func (this *PayZen) PaymentCreateBoletoOnline(payment *api.Payment) (*api.PaymentResult, error) {44 if !this.onValid(payment) {45 return nil, errors.New(this.getMessage("PayZen.ValidationError"))46 }47 this.ToolBox = NewPayZenToolBox(payment.Account)48 this.ToolBox.Debug = this.Debug49 return this.ToolBox.CreatePaymentBoletoOnline(payment)50}51func (this *PayZen) PaymentUpdate(payment *api.Payment) (*api.PaymentResult, error) {52 valid := this.onValidOther(payment, func (validator *validation.Validation) {53 if len(payment.TransactionUuid) == 0 {54 validator.SetError("TransactionUuid", this.getMessage("Pagarme.rquired"))55 }56 if payment.Amount <= 0 {57 validator.SetError("Amount", this.getMessage("Pagarme.rquired"))58 }59 })60 if !valid {61 return nil, errors.New(this.getMessage("PayZen.ValidationError"))62 }63 this.ToolBox = NewPayZenToolBox(payment.Account)64 this.ToolBox.Debug = this.Debug65 return this.ToolBox.UpdatePayment(payment)66}67// Para cancelar: Initial, Authorised,68func (this *PayZen) PaymentCancel(paymentFind *api.PaymentFind) (*api.PaymentResult, error) {69 valid := this.onValidOther(paymentFind, func (validator *validation.Validation) {70 if len(paymentFind.TransactionUuid) == 0 {71 validator.SetError("TransactionUuid", this.getMessage("Pagarme.rquired"))72 }73 })74 if !valid {75 return nil, errors.New(this.getMessage("PayZen.ValidationError"))76 }77 this.ToolBox = NewPayZenToolBox(paymentFind.Account)78 this.ToolBox.Debug = this.Debug79 return this.ToolBox.CancelPayment(paymentFind.TransactionUuid)80}81func (this *PayZen) PaymentCapture(capturePayment *api.PaymentCapture) (*api.PaymentResult, error) {82 if !this.onValidOther(capturePayment, nil) {83 return nil, errors.New(this.getMessage("PayZen.ValidationError"))84 }85 this.ToolBox = NewPayZenToolBox(capturePayment.Account)86 this.ToolBox.Debug = this.Debug87 return this.ToolBox.CapturePayment(capturePayment)88}89func (this *PayZen) PaymentValidate(paymentFind *api.PaymentFind) (*api.PaymentResult, error) {90 valid := this.onValidOther(paymentFind, func (validator *validation.Validation) {91 if len(paymentFind.TransactionUuid) == 0 {92 validator.SetError("TransactionUuid", this.getMessage("Pagarme.rquired"))93 }94 })95 if !valid {96 return nil, errors.New(this.getMessage("PayZen.ValidationError"))97 }98 this.ToolBox = NewPayZenToolBox(paymentFind.Account)99 this.ToolBox.Debug = this.Debug100 return this.ToolBox.ValidatePayment(paymentFind.TransactionUuid)101}102func (this *PayZen) PaymentDuplicate(payment *api.Payment) (*api.PaymentResult, error) {103 valid := this.onValidOther(payment, func (validator *validation.Validation) {104 if len(payment.TransactionUuid) == 0 {105 validator.SetError("TransactionUuid", this.getMessage("Pagarme.rquired"))106 }107 if len(payment.OrderId) == 0 {108 validator.SetError("OrderId", this.getMessage("Pagarme.rquired"))109 }110 if payment.Amount <= 0 {111 validator.SetError("Amount", this.getMessage("Pagarme.rquired"))112 }113 })114 if !valid {115 return nil, errors.New(this.getMessage("PayZen.ValidationError"))116 }117 this.ToolBox = NewPayZenToolBox(payment.Account)118 this.ToolBox.Debug = this.Debug119 return this.ToolBox.DuplicatePayment(payment)120}121func (this *PayZen) PaymentRefund(payment *api.Payment) (*api.PaymentResult, error) {122 valid := this.onValidOther(payment, func (validator *validation.Validation) {123 if len(payment.TransactionUuid) == 0 {124 validator.SetError("TransactionUuid", this.getMessage("Pagarme.rquired"))125 }126 if payment.Amount <= 0 {127 validator.SetError("Amount", this.getMessage("Pagarme.rquired"))128 }129 })130 if !valid {131 return nil, errors.New(this.getMessage("PayZen.ValidationError"))132 }133 this.ToolBox = NewPayZenToolBox(payment.Account)134 this.ToolBox.Debug = this.Debug135 return this.ToolBox.RefundPayment(payment)136}137/* token operations */138func (this *PayZen) PaymentTokenCreate(payment *api.Payment) (*api.PaymentResult, error) {139 payment.TokenOperation = true140 if !this.onValid(payment) {141 return nil, errors.New(this.getMessage("PayZen.ValidationError"))142 }143 this.ToolBox = NewPayZenToolBox(payment.Account)144 this.ToolBox.Debug = this.Debug145 return this.ToolBox.CreatePaymentToken(payment)146}147func (this *PayZen) PaymentTokenUpdate(payment *api.Payment) (*api.PaymentResult, error) {148 payment.TokenOperation = true149 if !this.onValid(payment) {150 return nil, errors.New(this.getMessage("PayZen.ValidationError"))151 }152 valid := this.onValidOther(payment, func (validator *validation.Validation) {153 if len(payment.Card.Token) == 0 {154 validator.SetError("Token", this.getMessage("Pagarme.rquired"))155 return156 }157 })158 if !valid {159 return nil, errors.New(this.getMessage("PayZen.ValidationError"))160 }161 this.ToolBox = NewPayZenToolBox(payment.Account)162 this.ToolBox.Debug = this.Debug163 return this.ToolBox.UpdatePaymentToken(payment)164}165func (this *PayZen) PaymentTokenCancel(paymentToken *api.PaymentToken) (*api.PaymentResult, error) {166 if !this.onValidOther(paymentToken, nil) {167 return nil, errors.New(this.getMessage("PayZen.ValidationError"))168 }169 this.ToolBox = NewPayZenToolBox(paymentToken.Account)170 this.ToolBox.Debug = this.Debug171 return this.ToolBox.CancelPaymentToken(paymentToken.Token)172}173func (this *PayZen) PaymentTokenReactive(paymentToken *api.PaymentToken) (*api.PaymentResult, error) {174 if !this.onValidOther(paymentToken, nil) {175 return nil, errors.New(this.getMessage("PayZen.ValidationError"))176 }177 this.ToolBox = NewPayZenToolBox(paymentToken.Account)178 this.ToolBox.Debug = this.Debug179 return this.ToolBox.ReactivePaymentToken(paymentToken.Token)180}181func (this *PayZen) PaymentTokenGetDetails(paymentToken *api.PaymentToken) (*api.PaymentResult, error) {182 if !this.onValidOther(paymentToken, nil) {183 return nil, errors.New(this.getMessage("PayZen.ValidationError"))184 }185 this.ToolBox = NewPayZenToolBox(paymentToken.Account)186 this.ToolBox.Debug = this.Debug187 return this.ToolBox.GetDetailsPaymentToken(paymentToken.Token)188}189/* find payment operations */190/*191 Com esse método é possível buscar todos os pagamentos relacionados a uma recorrência. As transações retornam no atributo Transactions do resultado192*/193func (this *PayZen) PaymentFind(paymentFind *api.PaymentFind) (*api.PaymentResult, error) {194 valid := this.onValidOther(paymentFind, func (validator *validation.Validation) {195 if len(paymentFind.OrderId) == 0 {196 validator.SetError("OrderId", this.getMessage("Pagarme.rquired"))197 return198 }199 })200 if !valid {201 return nil, errors.New(this.getMessage("PayZen.ValidationError"))202 }203 this.ToolBox = NewPayZenToolBox(paymentFind.Account)204 this.ToolBox.Debug = this.Debug205 return this.ToolBox.FindPayment(paymentFind.OrderId)206}207func (this *PayZen) PaymentGetDetails(paymentFind *api.PaymentFind) (*api.PaymentResult, error) {208 valid := this.onValidOther(paymentFind, func (validator *validation.Validation) {209 if len(paymentFind.TransactionUuid) == 0 {210 validator.SetError("TransactionUuid", this.getMessage("Pagarme.rquired"))211 return212 }213 })214 if !valid {215 return nil, errors.New(this.getMessage("PayZen.ValidationError"))216 }217 this.ToolBox = NewPayZenToolBox(paymentFind.Account)218 this.ToolBox.Debug = this.Debug219 return this.ToolBox.GetPaymentDetails(paymentFind.TransactionUuid)220}221func (this *PayZen) PaymentGetDetailsWithNsu(paymentFind *api.PaymentFind) (*api.PaymentResult, error) {222 valid := this.onValidOther(paymentFind, func (validator *validation.Validation) {223 if len(paymentFind.TransactionUuid) == 0 {224 validator.SetError("TransactionUuid", this.getMessage("Pagarme.rquired"))225 return226 }227 })228 if !valid {229 return nil, errors.New(this.getMessage("PayZen.ValidationError"))230 }231 this.ToolBox = NewPayZenToolBox(paymentFind.Account)232 this.ToolBox.Debug = this.Debug233 return this.ToolBox.GetPaymentDetailsWithNsu(paymentFind.TransactionUuid)234}235func (this *PayZen) PaymentCreateSubscription(subscription *api.Subscription) (*api.PaymentResult, error) {236 if !this.onValidSubscription(subscription) {237 return nil, errors.New(this.getMessage("PayZen.ValidationError"))238 }239 this.ToolBox = NewPayZenToolBox(subscription.Account)240 this.ToolBox.Debug = this.Debug241 return this.ToolBox.CreateSubscription(subscription)242}243func (this *PayZen) PaymentGetDetailsSubscription(paymentFind *api.PaymentFind) (*api.PaymentResult, error) {244 valid := this.onValidOther(paymentFind, func (validator *validation.Validation) {245 if len(paymentFind.SubscriptionId) == 0 {246 validator.SetError("SubscriptionId", this.getMessage("Pagarme.rquired"))247 return248 }249 if len(paymentFind.Token) == 0 {250 validator.SetError("Token", this.getMessage("Pagarme.rquired"))251 return252 }253 })254 if !valid {255 return nil, errors.New(this.getMessage("PayZen.ValidationError"))256 }257 this.ToolBox = NewPayZenToolBox(paymentFind.Account)258 this.ToolBox.Debug = this.Debug259 return this.ToolBox.GetSubscriptionDetails(paymentFind.SubscriptionId, paymentFind.Token)260}261func (this *PayZen) PaymentCancelSubscription(paymentFind *api.PaymentFind) (*api.PaymentResult, error) {262 valid := this.onValidOther(paymentFind, func (validator *validation.Validation) {263 if len(paymentFind.SubscriptionId) == 0 {264 validator.SetError("SubscriptionId", this.getMessage("Pagarme.rquired"))265 return266 }267 if len(paymentFind.Token) == 0 {268 validator.SetError("Token", this.getMessage("Pagarme.rquired"))269 return270 }271 })272 if !valid {273 return nil, errors.New(this.getMessage("PayZen.ValidationError"))274 }275 this.ToolBox = NewPayZenToolBox(paymentFind.Account)276 this.ToolBox.Debug = this.Debug277 return this.ToolBox.CancelSubscription(paymentFind.SubscriptionId, paymentFind.Token)278}279func (this *PayZen) PaymentUpdateSubscription(subscription *api.Subscription) (*api.PaymentResult, error) {280 if !this.onValidSubscription(subscription) {281 return nil, errors.New(this.getMessage("PayZen.ValidationError"))282 }283 valid := this.onValidOther(subscription, func (validator *validation.Validation) {284 if len(subscription.SubscriptionId) == 0 {285 validator.SetError("SubscriptionId", this.getMessage("Pagarme.rquired"))286 return287 }288 if len(subscription.Token) == 0 {289 validator.SetError("Token", this.getMessage("Pagarme.rquired"))290 return291 }292 })293 if !valid {294 return nil, errors.New(this.getMessage("PayZen.ValidationError"))295 }296 this.ToolBox = NewPayZenToolBox(subscription.Account)297 this.ToolBox.Debug = this.Debug298 return this.ToolBox.UpdateSubscription(subscription)299}300func (this *PayZen) CanCancelPayment(status api.TransactionStatus) bool {301 switch status {302 case api.Initial:303 case api.Authorised:304 case api.AuthorisedToValidate:305 case api.WaitingAuthorisation:306 case api.WaitingAuthorisationToValidate:307 return true308 }309 return false310}311func (this *PayZen) CanUpdatePayment(status api.TransactionStatus) bool {312 switch status {313 case api.Initial:314 case api.Authorised:315 case api.AuthorisedToValidate:316 case api.WaitingAuthorisation:317 case api.WaitingAuthorisationToValidate:318 return true319 }320 return false321}322func (this *PayZen) CanDuplicatePayment(status api.TransactionStatus) bool {323 switch status {324 case api.Captured:325 return true326 }327 return false328}329func (this *PayZen) onValidOther(object interface{}, action func (*validation.Validation)) bool {330 this.EntityValidatorResult, _ = this.EntityValidator.IsValid(object, action)331 if this.EntityValidatorResult.HasError {332 this.onValidationErrors()333 return false334 }335 return true336}337func (this *PayZen) onValidSubscription(subscription *api.Subscription) bool {338 this.EntityValidatorResult, _ = this.EntityValidator.IsValid(subscription, func (validator *validation.Validation) {339 if len(subscription.Rule) == 0 {340 if subscription.EffectDate.IsZero() {341 validator.SetError("EffectDate", this.getMessage("Pagarme.rquired"))342 }343 if subscription.InitialAmountNumber > 0 && subscription.InitialAmount == 0.0 {344 validator.SetError("InitialAmount", this.getMessage("Pagarme.rquired"))345 }346 if subscription.InitialAmountNumber == 0 && subscription.InitialAmount > 0.0 {347 validator.SetError("InitialAmountNumber", this.getMessage("Pagarme.rquired"))348 }349 if subscription.Amount <= 0 {350 validator.SetError("Amount", this.getMessage("Pagarme.rquired"))351 }352 }353 })354 if this.EntityValidatorResult.HasError {355 this.onValidationErrors()356 return false357 }358 return true359}360func (this *PayZen) onValid(payment *api.Payment) bool {361 this.EntityValidatorResult, _ = this.EntityValidator.IsValid(payment, func (validator *validation.Validation) {362 if !payment.TokenOperation {363 if len(strings.TrimSpace(payment.OrderId)) == 0 {364 validator.SetError(this.getMessage("Pagarme.OrderId"), this.getMessage("Pagarme.rquired"))365 }366 if payment.Installments <= 0 {367 validator.SetError(this.getMessage("Pagarme.Installments"), this.getMessage("Pagarme.rquired"))368 }369 if payment.Amount <= 0 {370 validator.SetError(this.getMessage("Pagarme.Amount"), this.getMessage("Pagarme.rquired"))371 }372 if payment.Card == nil {373 validator.SetError(this.getMessage("Pagarme.Card"), this.getMessage("Pagarme.rquired"))374 }375 if payment.Customer == nil {376 validator.SetError(this.getMessage("Pagarme.Customer"), this.getMessage("Pagarme.rquired"))377 } else {378 379 if payment.Card.Scheme == SchemeBoleto {380 if len(strings.TrimSpace(payment.Customer.IdentityCode)) == 0 {381 validator.SetError(this.getMessage("Pagarme.IdentityCode"), this.getMessage("Pagarme.rquired"))382 }383 }384 }385 }386 if payment.Card.Scheme == SchemeBoleto {387 switch payment.BoletoOnline {388 case api.BoletoOnline:389 validator.SetError(this.getMessage("Pagarme.BoletoOnline"), fmt.Sprintf("Boleto On-Line %v não implementado", payment.BoletoOnline))390 break391 case api.BoletoOnlineItauIb:392 validator.SetError(this.getMessage("Pagarme.BoletoOnline"), fmt.Sprintf("Boleto On-Line %v não implementado", payment.BoletoOnline))393 break394 case api.BoletoOnlineItauBoleto:395 if _, err := strconv.Atoi(payment.VadsTransId); err != nil {396 validator.SetError(this.getMessage("Pagarme.VadsTransId"), "vads_trans_id deve ser um valor númerico de 6 digitos que não pode repetir no mesmo dia.")397 } 398 break399 case api.BoletoOnlineBradescoBoleto:400 if _, err := strconv.Atoi(payment.VadsTransId); err != nil {401 validator.SetError(this.getMessage("Pagarme.VadsTransId"), "vads_trans_id deve ser um valor númerico de 6 digitos que não pode repetir no mesmo dia.")402 } 403 //validator.SetError(this.getMessage("Pagarme.BoletoOnline"), fmt.Sprintf("Boleto On-Line %v não implementado", payment.BoletoOnline))404 break405 406 } 407 }408 })409 if this.EntityValidatorResult.HasError {410 this.onValidationErrors()411 return false412 }413 this.EntityValidatorResult, _ = this.EntityValidator.IsValid(payment.Card, func (validator *validation.Validation) {414 if len(strings.TrimSpace(payment.Card.Token)) == 0 && payment.Card.Scheme != SchemeBoleto {415 if len(strings.TrimSpace(payment.Card.Number)) == 0 {416 validator.SetError(this.getMessage("Pagarme.Number"), this.getMessage("Pagarme.rquired"))417 }418 if len(strings.TrimSpace(payment.Card.Scheme)) == 0 {419 validator.SetError(this.getMessage("Pagarme.Scheme"), this.getMessage("Pagarme.rquired"))420 }421 if len(strings.TrimSpace(payment.Card.ExpiryMonth)) == 0 {422 validator.SetError(this.getMessage("Pagarme.ExpiryMonth"), this.getMessage("Pagarme.rquired"))423 }424 if len(strings.TrimSpace(payment.Card.ExpiryYear)) == 0 {425 validator.SetError(this.getMessage("Pagarme.ExpiryYear"), this.getMessage("Pagarme.rquired"))426 }427 /*428 if len(strings.TrimSpace(payment.Card.Number)) == 0 {429 validator.SetError("Number", this.getMessage("Pagarme.rquired"))430 }*/431 if len(strings.TrimSpace(payment.Card.CardSecurityCode)) == 0 {432 validator.SetError(this.getMessage("Pagarme.CardSecurityCode"), this.getMessage("Pagarme.rquired"))433 }434 if len(strings.TrimSpace(payment.Card.CardHolderName)) == 0 {435 validator.SetError(this.getMessage("Pagarme.CardHolderName"), this.getMessage("Pagarme.rquired"))436 }437 }438 })439 if this.EntityValidatorResult.HasError {440 this.onValidationErrors()441 return false442 }443 this.EntityValidatorResult, _ = this.EntityValidator.IsValid(payment.Customer, func (validator *validation.Validation) {444 })445 if this.EntityValidatorResult.HasError {446 this.onValidationErrors()447 return false448 }449 return true450}451func (this *PayZen) onValidationErrors(){452 this.HasValidationError = true453 data := make(map[interface{}]interface{})454 this.EntityValidator.CopyErrorsToView(this.EntityValidatorResult, data)455 this.ValidationErrors = data["errors"].(map[string]string)456}457func (this *PayZen) getMessage(key string, args ...interface{}) string{458 return i18n.Tr(this.Lang, key, args)459}...

Full Screen

Full Screen

payzen.go

Source:payzen.go Github

copy

Full Screen

...50}51func (this *PayZen) SetDebug() { this.Debug = true }52func (this *PayZen) PaymentCreate(payment *Payment) (*PayZenResult, error) { 53 if !this.onValidPayment(payment) {54 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 55 }56 result := new(PaymentResponse)57 info, err := this.request(payment, "PCI/Charge/CreatePayment", result)58 result.Response = info["Response"]59 result.Request = info["Request"] 60 return NewPayZenResultWithResponse(result), err61}62func (this *PayZen) PaymentCancelOrRefund(transactionUuid string, amount float64) (*PayZenResult, error) { 63 64 if len(transactionUuid) == 0 {65 this.SetValidationError("transactionUuid", "is required")66 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 67 }68 if amount <= 0 {69 this.SetValidationError("amount", "is required")70 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 71 }72 result := new(TransationResponse)73 data := make(map[string]interface{})74 data["uuid"] = transactionUuid75 data["amount"] = ConvertAmount(amount)76 data["currency"] = payzen.Currency77 info, err := this.request(data, "Transaction/CancelOrRefund", result)78 result.Response = info["Response"]79 result.Request = info["Request"] 80 return NewPayZenResultWithTransaction(result), err81}82func (this *PayZen) PaymentCapture(transactionUuid string) (*PayZenResult, error) { 83 84 if len(transactionUuid) == 0 {85 this.SetValidationError("transactionUuid", "is required")86 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 87 }88 result := new(TransationResponse)89 data := make(map[string][]string)90 data["uuids"] = []string{transactionUuid,}91 info, err := this.request(data, "Transaction/Capture", result)92 result.Response = info["Response"]93 result.Request = info["Request"] 94 return NewPayZenResultWithTransaction(result), err95}96func (this *PayZen) TokenCreate(payment *Payment) (*PayZenResult, error) { 97 if !this.onValidPaymentWithCreateToken(payment) {98 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 99 }100 result := new(PaymentResponse)101 info, err := this.request(payment, "PCI/Charge/CreateToken", result)102 result.Response = info["Response"]103 result.Request = info["Request"] 104 return NewPayZenResultWithResponse(result), err105}106func (this *PayZen) TokenUpdate(payment *Payment) (*PayZenResult, error) { 107 if !this.onValidPaymentWithUpdateToken(payment) {108 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 109 }110 result := new(PaymentResponse)111 info, err := this.request(payment, "Token/Update", result)112 result.Response = info["Response"]113 result.Request = info["Request"] 114 return NewPayZenResultWithResponse(result), err115}116func (this *PayZen) TokenGet(paymentMethodToken string) (*PayZenResult, error) { 117 if len(paymentMethodToken) == 0 {118 this.SetValidationError("paymentMethodToken", "is required")119 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 120 }121 result := new(PaymentResponse)122 data := make(map[string]string)123 data["paymentMethodToken"] = paymentMethodToken124 info, err := this.request(data, "Token/Get", result)125 result.Response = info["Response"]126 result.Request = info["Request"] 127 return NewPayZenResultWithResponse(result), err128}129func (this *PayZen) TokenCancel(paymentMethodToken string) (*PayZenResult, error) { 130 if len(paymentMethodToken) == 0 {131 this.SetValidationError("paymentMethodToken", "is required")132 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 133 }134 result := new(PaymentResponse)135 data := make(map[string]string)136 data["paymentMethodToken"] = paymentMethodToken137 info, err := this.request(data, "Token/Cancel", result)138 result.Response = info["Response"]139 result.Request = info["Request"] 140 return NewPayZenResultWithResponse(result), err141}142func (this *PayZen) SubscriptionCreate(subscription *Subscription) (*PayZenResult, error) { 143 error := subscription.BuildRule()144 if len(error) > 0 {145 this.SetValidationError("Rrule", error)146 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 147 }148 if !this.onValidSubscription(subscription) {149 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 150 } 151 result := new(PaymentResponse)152 info, err := this.request(subscription, "Charge/CreateSubscription", result)153 result.Response = info["Response"]154 result.Request = info["Request"] 155 return NewPayZenResultWithResponse(result), err156}157func (this *PayZen) SubscriptionUpdate(subscription *Subscription) (*PayZenResult, error) { 158 if len(subscription.SubscriptionId) == 0 {159 this.SetValidationError("SubscriptionId", "is required")160 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 161 }162 error := subscription.BuildRule()163 if len(error) > 0 {164 this.SetValidationError("Rrule", error)165 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 166 }167 if !this.onValidSubscription(subscription) {168 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 169 } 170 result := new(PaymentResponse)171 info, err := this.request(subscription, "Subscription/Update", result)172 result.Response = info["Response"]173 result.Request = info["Request"] 174 return NewPayZenResultWithResponse(result), err175}176func (this *PayZen) SubscriptionGet(subscriptionId string, paymentMethodToken string) (*PayZenResult, error) { 177 if len(subscriptionId) == 0 {178 this.SetValidationError("subscriptionId", "is required")179 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 180 }181 if len(paymentMethodToken) == 0 {182 this.SetValidationError("paymentMethodToken", "is required")183 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 184 }185 result := new(PaymentResponse)186 data := make(map[string]string)187 data["subscriptionId"] = subscriptionId188 data["paymentMethodToken"] = paymentMethodToken189 info, err := this.request(data, "Subscription/Get", result)190 result.Response = info["Response"]191 result.Request = info["Request"]192 return NewPayZenResultWithResponse(result), err193}194func (this *PayZen) SubscriptionCancel(subscriptionId string, paymentMethodToken string) (*PayZenResult, error) { 195 if len(subscriptionId) == 0 {196 this.SetValidationError("subscriptionId", "is required")197 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 198 }199 if len(paymentMethodToken) == 0 {200 this.SetValidationError("paymentMethodToken", "is required")201 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 202 }203 result := new(PaymentResponse)204 data := make(map[string]string)205 data["subscriptionId"] = subscriptionId206 data["paymentMethodToken"] = paymentMethodToken207 info, err := this.request(data, "Subscription/Cancel", result)208 result.Response = info["Response"]209 result.Request = info["Request"]210 return NewPayZenResultWithResponse(result), err211}212func (this *PayZen) TransactionGet(transactionUuid string) (*PayZenResult, error) { 213 if len(transactionUuid) == 0 {214 this.SetValidationError("transactionUuid", "is required")215 return nil, errors.New(this.getMessage("PayZen.ValidationError")) 216 }217 result := new(TransationResponse)218 data := make(map[string]string)219 data["uuid"] = transactionUuid220 info, err := this.request(data, "Transaction/Get", result)221 result.Response = info["Response"]222 result.Request = info["Request"]223 return NewPayZenResultWithTransaction(result), err224}225func (this *PayZen) request(requestData interface{}, action string, result interface{}) (map[string]string, error) {226 //result := new(PaymentResponse)227 //result.RequestObject = soap228 info := make(map[string]string)229 jsonContent, err := json.MarshalIndent(requestData, " ", " ")230 if err != nil {231 fmt.Println("** request: error MarshalIndent: %v", err)232 return info, errors.New(fmt.Sprintf("request - MarshalIndent: %v", err.Error()))233 }234 data := bytes.NewBuffer(jsonContent)235 info["Request"] = string(data.Bytes())236 url := fmt.Sprintf("%v/%v", ApiUrl, action)237 if this.Debug {238 fmt.Println("**********************************************")239 fmt.Println(" ----------------- JSON REQUEST --------------")240 fmt.Println("URL: %v", url)241 fmt.Println("%v", string(data.Bytes()))242 fmt.Println("**********************************************")243 }244 client := new(http.Client)245 req, err := http.NewRequest("POST", url, data)246 if err != nil {247 return info, errors.New(fmt.Sprintf("http.NewRequest: %v", err.Error()))248 }249 req.Header.Add("Content-Type", "application/json")250 req.Header.Add("Authorization", this.Authentication.CreateBasicAuth(this.Mode))251 resp, err := client.Do(req)252 if err != nil {253 return info, errors.New(fmt.Sprintf("client.Do: %v", err.Error()))254 }255 response, err := ioutil.ReadAll(resp.Body)256 if err != nil {257 return info, errors.New(fmt.Sprintf("ioutil.ReadAll: %v", err.Error())) 258 }259 fmt.Println("***********************************")260 fmt.Println("***** PAYZEN START RESPONSE ******") 261 fmt.Println("***** STATUS CODE: %v", resp.StatusCode)262 if this.Debug && resp.StatusCode != 200 {263 fmt.Println("***** RESPONSE: %v", string(response)) 264 }265 fmt.Println("***** PAYZEN END RESPONSE *********")266 fmt.Println("***********************************")267 info["Response"] = string(response)268 switch resp.StatusCode {269 case 200:270 if this.Debug {271 jsonResult := make(map[string]json.RawMessage)272 json.Unmarshal(response, &jsonResult)273 jsonContent, _ := json.MarshalIndent(jsonResult, " ", " ")274 fmt.Println("***********************************************")275 fmt.Println(" ----------------- JSON RESPONSE --------------")276 fmt.Println(string(jsonContent))277 fmt.Println("***********************************************")278 }279 err := json.Unmarshal(response, result)280 if err != nil { 281 return info, errors.New(fmt.Sprintf("request - Unmarshal Response: %v", err.Error()))282 }283 return info, nil284 default:285 return info, errors.New(fmt.Sprintf("PayZen API error - Code %v, Status: %v", resp.StatusCode, resp.Status))286 }287}288func (this *PayZen) onValidSubscription(subscription *Subscription) bool {289 290 this.EntityValidatorResult, _ = this.EntityValidator.Valid(subscription, func (validator *validation.Validation) {291 if len(strings.TrimSpace(subscription.PaymentMethodToken)) == 0 {292 validator.SetError(this.getMessage("PaymentMethodToken"), this.getMessage("PayZen.rquired"))293 } 294 })295 296 if this.EntityValidatorResult.HasError {297 this.onValidationErrors()298 return false299 }300 return true 301}302func (this *PayZen) onValidPayment(payment *Payment) bool {303 return this.validPayment(payment, false, false, false)304}305func (this *PayZen) onValidPaymentWithCreateToken(payment *Payment) bool {306 return this.validPayment(payment, false, true, false)307}308func (this *PayZen) onValidPaymentWithUpdateToken(payment *Payment) bool {309 return this.validPayment(payment, false, true, true)310}311func (this *PayZen) validPayment(payment *Payment, checkPaymentId bool, tokenOperation bool, tokenUpdate bool) bool {312 items := []interface{}{313 payment,314 payment.Customer,315 payment.Customer.BillingDetails,316 payment.Device,317 }318 if payment.Card != nil && len(strings.TrimSpace(payment.Card.PaymentMethodToken)) == 0 && len(strings.TrimSpace(payment.PaymentMethodToken)) == 0 {319 items = append(items, payment.Card)320 }321 this.EntityValidatorResult, _ = this.EntityValidator.ValidMult(items, func (validator *validation.Validation) {322 if checkPaymentId {323 if len(strings.TrimSpace(payment.PaymentOrderId)) == 0 {324 validator.SetError(this.getMessage("PayZen.PaymentOrderId"), this.getMessage("PayZen.rquired"))325 } 326 }327 if !tokenOperation {328 if len(strings.TrimSpace(payment.OrderId)) == 0 {329 validator.SetError(this.getMessage("PayZen.OrderId"), this.getMessage("PayZen.rquired"))330 }331 if payment.Card == nil && !checkPaymentId {332 validator.SetError(this.getMessage("PayZen.Card"), this.getMessage("PayZen.rquired"))333 }334 335 if payment.Card != nil {336 if payment.Card.InstallmentNumber <= 0 {337 validator.SetError(this.getMessage("PayZen.Installments"), this.getMessage("PayZen.rquired"))338 }339 }340 if payment.Amount <= 0 {341 validator.SetError(this.getMessage("PayZen.Amount"), this.getMessage("PayZen.rquired"))342 }343 if payment.Customer == nil && !checkPaymentId {344 validator.SetError(this.getMessage("PayZen.Customer"), this.getMessage("PayZen.rquired"))345 } 346 if payment.Customer != nil { 347 if len(strings.TrimSpace(payment.Customer.BillingDetails.IdentityCode)) == 0 {348 validator.SetError(this.getMessage("PayZen.IdentityCode"), this.getMessage("PayZen.rquired"))349 }350 }351 }352 if tokenUpdate {353 if len(strings.TrimSpace(payment.PaymentMethodToken)) == 0 && len(strings.TrimSpace(payment.Card.PaymentMethodToken)) == 0 {354 validator.SetError(this.getMessage("PaymentMethodToken"), this.getMessage("PayZen.rquired"))355 } 356 } 357 })358 if this.EntityValidatorResult.HasError {359 this.onValidationErrors()360 return false361 }362 return true363}364func (this *PayZen) onValidationErrors(){365 this.HasValidationError = true366 data := make(map[interface{}]interface{})367 this.EntityValidator.CopyErrorsToView(this.EntityValidatorResult, data)368 fmt.Println("DATA ERRORS = %v", data)369 this.ValidationErrors = data["errors"].(map[string]string)370}371func (this *PayZen) getMessage(key string, args ...interface{}) string{372 return i18n.Tr(this.Lang, key, args)373}374func (this *PayZen) SetValidationError(key string, value string){375 this.HasValidationError = true376 if this.ValidationErrors == nil {377 this.ValidationErrors = make(map[string]string)378 }379 this.ValidationErrors[key]= value380}...

Full Screen

Full Screen

getMessage

Using AI Code Generation

copy

Full Screen

1func main() {2 fmt.Println(validation.GetMessage())3}4func main() {5 fmt.Println(validation.GetMessage())6}7func main() {8 fmt.Println(validation.GetMessage())9}10func main() {11 fmt.Println(validation.GetMessage())12}13func main() {14 fmt.Println(validation.GetMessage())15}16func main() {17 fmt.Println(validation.GetMessage())18}19func main() {20 fmt.Println(validation.GetMessage())21}22func main() {23 fmt.Println(validation.GetMessage())24}25func main() {26 fmt.Println(validation.GetMessage())27}28func main() {29 fmt.Println(validation.GetMessage())30}31func main() {32 fmt.Println(validation.GetMessage())33}34func main() {35 fmt.Println(validation.GetMessage())36}37func main() {38 fmt.Println(validation.GetMessage())39}40func main() {41 fmt.Println(validation.GetMessage())42}43func main() {44 fmt.Println(validation.GetMessage())45}46func main() {47 fmt.Println(validation.GetMessage())48}49func main() {50 fmt.Println(validation.GetMessage())51}52func main() {53 fmt.Println(validation.GetMessage())54}

Full Screen

Full Screen

getMessage

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 validate := validator.New()4 err := validate.Var("abc", "required,email")5 if err != nil {6 fmt.Println(err.(validator.ValidationErrors)[0].Namespace())7 fmt.Println(err.(validator.ValidationErrors)[0].Field())8 fmt.Println(err.(validator.ValidationErrors)[0].StructNamespace())9 fmt.Println(err.(validator.ValidationErrors)[0].StructField())10 fmt.Println(err.(validator.ValidationErrors)[0].Tag())11 fmt.Println(err.(validator.ValidationErrors)[0].ActualTag())12 fmt.Println(err.(validator.ValidationErrors)[0].Kind())13 fmt.Println(err.(validator.ValidationErrors)[0].Type())14 fmt.Println(err.(validator.ValidationErrors)[0].Value())15 fmt.Println(err.(validator.ValidationErrors)[0].Param())16 }17}18Namespace()19Field()20StructNamespace()21StructField()22Tag()23ActualTag()24Kind()25Type()26Value()27Param()

Full Screen

Full Screen

getMessage

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World!")4 fmt.Println(validation.getMessage(1))5}6import (7func getMessage(val int) string {8 return fmt.Sprintf("The value is: %d", val)9}10import (11func TestGetMessage(t *testing.T) {12 if getMessage(1) != "The value is: 1" {13 t.Error("Expected: 'The value is: 1', Actual: ", getMessage(1))14 }15}16import (17func TestGetMessage(t *testing.T) {18 if getMessage(1) != "The value is: 1" {19 t.Error("Expected: 'The value is: 1', Actual: ", getMessage(1))20 }21}22import (23func TestGetMessage(t *testing.T) {24 if getMessage(1) != "The value is: 1" {25 t.Error("Expected: 'The value is: 1', Actual: ", getMessage(1))26 }27}28import (29func TestGetMessage(t *testing.T) {30 if getMessage(1) != "The value is: 1" {31 t.Error("Expected: 'The value is: 1', Actual: ", getMessage(1))32 }33}34import (35func TestGetMessage(t *testing.T) {36 if getMessage(1) != "The value is: 1" {37 t.Error("Expected: 'The value is: 1', Actual: ", getMessage(1))38 }39}40import (41func TestGetMessage(t *testing.T) {42 if getMessage(1) != "The value is: 1" {43 t.Error("Expected: 'The value is: 1', Actual: ", getMessage(1))44 }45}46import (47func TestGetMessage(t *testing.T) {48 if getMessage(1) != "

Full Screen

Full Screen

getMessage

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 validate := validator.New()4 validate.RegisterValidation("checkname", checkName)5 validate.RegisterTranslation("checkname", trans, func(ut ut.Translator) error {6 return ut.Add("checkname", "{0} is not valid", true)7 }, func(ut ut.Translator, fe validator.FieldError) string {8 t, _ := ut.T("checkname", fe.Field())9 })10 type User struct {11 }12 user := User{Name: "sachin"}13 err := validate.Struct(user)14 if err != nil {15 for _, err := range err.(validator.ValidationErrors) {16 fmt.Println(err.Translate(trans))17 }18 }19}20import (21func checkName(fl validator.FieldLevel) bool {22 name := fl.Field().String()23 if strings.Contains(name, " ") {24 }25}26import (27func init() {28 en := en.New()29 uni := ut.New(en, en)30 trans, _ = uni.GetTranslator("en")31}32How to validate a struct using validate.Struct() in Golang?33How to validate a struct using validate.StructExcept() in Golang?34How to validate a struct using validate.Var() in Golang?

Full Screen

Full Screen

getMessage

Using AI Code Generation

copy

Full Screen

1func main() {2 m = validation.Message{}3 m.GetMessage()4}5func main() {6 m = validation.Message{}7 m.GetMessage()8}

Full Screen

Full Screen

getMessage

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(validation.GetMessage())4}5import (6func main() {7 fmt.Println(v.Validate())8}9import (10func main() {11 fmt.Println(v.ValidateWithMessage())12}13import (14func main() {15 fmt.Println(v.ValidateWithMessageAndReturn())16}17import (18func main() {19 fmt.Println(v.ValidateWithMessageAndReturn())20}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful