@@ -190,32 +190,44 @@ func (pl *PaymentListener) onPayment(payment horizon.PaymentResponse) (err error
190190 return
191191 }
192192
193- err = pl .process (payment )
194-
195- if err != nil {
196- pl .log .WithFields (logrus.Fields {"err" : err }).Error ("Payment processed with errors" )
197- dbPayment .Status = err .Error ()
193+ process , status := pl .shouldProcessPayment (payment )
194+ if ! process {
195+ dbPayment .Status = status
196+ pl .log .Info (status )
198197 } else {
199- pl .log .Info ("Payment successfully processed" )
200- dbPayment .Status = "Success"
198+ err = pl .process (payment )
199+
200+ if err != nil {
201+ pl .log .WithFields (logrus.Fields {"err" : err }).Error ("Payment processed with errors" )
202+ dbPayment .Status = err .Error ()
203+ } else {
204+ pl .log .Info ("Payment successfully processed" )
205+ dbPayment .Status = "Success"
206+ }
201207 }
202208
203209 return pl .entityManager .Persist (dbPayment )
204210}
205211
206- func (pl * PaymentListener ) process (payment horizon.PaymentResponse ) error {
212+ // shouldProcessPayment returns false and text status if payment should not be processed
213+ // (ex. asset is different than allowed assets).
214+ func (pl * PaymentListener ) shouldProcessPayment (payment horizon.PaymentResponse ) (bool , string ) {
207215 if payment .Type != "payment" && payment .Type != "path_payment" {
208- return errors . New ( "Not a payment operation" )
216+ return false , "Not a payment operation"
209217 }
210218
211219 if payment .To != pl .config .Accounts .ReceivingAccountID {
212- return errors . New ( "Operation sent not received" )
220+ return false , "Operation sent not received"
213221 }
214222
215223 if ! pl .isAssetAllowed (payment .AssetType , payment .AssetCode , payment .AssetIssuer ) {
216- return errors . New ( "Asset not allowed" )
224+ return false , "Asset not allowed"
217225 }
218226
227+ return true , ""
228+ }
229+
230+ func (pl * PaymentListener ) process (payment horizon.PaymentResponse ) error {
219231 err := pl .horizon .LoadMemo (& payment )
220232 if err != nil {
221233 return errors .Wrap (err , "Unable to load transaction memo" )
0 commit comments