@@ -45,7 +45,7 @@ func (a *API) PaymentListForUser(w http.ResponseWriter, r *http.Request) error {
45
45
return notFoundError ("Couldn't find a record for " + userID )
46
46
}
47
47
48
- trans , httpErr := queryForTransactions (a .db , log , "user_id = ?" , userID )
48
+ trans , httpErr := queryForTransactions (a .DB ( r ) , log , "user_id = ?" , userID )
49
49
if httpErr != nil {
50
50
return httpErr
51
51
}
@@ -60,7 +60,7 @@ func (a *API) PaymentListForOrder(w http.ResponseWriter, r *http.Request) error
60
60
orderID := gcontext .GetOrderID (ctx )
61
61
claims := gcontext .GetClaims (ctx )
62
62
63
- order , httpErr := queryForOrder (a .db , orderID , log )
63
+ order , httpErr := queryForOrder (a .DB ( r ) , orderID , log )
64
64
if httpErr != nil {
65
65
return httpErr
66
66
}
@@ -138,7 +138,7 @@ func (a *API) PaymentCreate(w http.ResponseWriter, r *http.Request) error {
138
138
}
139
139
140
140
orderID := gcontext .GetOrderID (ctx )
141
- tx := a .db .Begin ()
141
+ tx := a .DB ( r ) .Begin ()
142
142
order := & models.Order {}
143
143
loader := tx .
144
144
Preload ("LineItems" ).
@@ -237,9 +237,10 @@ func (a *API) PaymentCreate(w http.ResponseWriter, r *http.Request) error {
237
237
func (a * API ) PaymentConfirm (w http.ResponseWriter , r * http.Request ) error {
238
238
ctx := r .Context ()
239
239
log := getLogEntry (r )
240
+ db := a .DB (r )
240
241
241
242
payID := chi .URLParam (r , "payment_id" )
242
- trans , httpErr := a . getTransaction (payID )
243
+ trans , httpErr := getTransaction (db , payID )
243
244
if httpErr != nil {
244
245
return httpErr
245
246
}
@@ -260,7 +261,7 @@ func (a *API) PaymentConfirm(w http.ResponseWriter, r *http.Request) error {
260
261
}
261
262
262
263
order := & models.Order {}
263
- if rsp := a . db .Find (order , "id = ?" , trans .OrderID ); rsp .Error != nil {
264
+ if rsp := db .Find (order , "id = ?" , trans .OrderID ); rsp .Error != nil {
264
265
if rsp .RecordNotFound () {
265
266
return notFoundError ("Order not found" )
266
267
}
@@ -286,7 +287,7 @@ func (a *API) PaymentConfirm(w http.ResponseWriter, r *http.Request) error {
286
287
return internalServerError ("Error on provider while trying to confirm: %v. Try again later." , err )
287
288
}
288
289
289
- tx := a . db .Begin ()
290
+ tx := db .Begin ()
290
291
291
292
if trans .InvoiceNumber == 0 {
292
293
invoiceNumber , err := models .NextInvoiceNumber (tx , order .InstanceID )
@@ -311,7 +312,7 @@ func (a *API) PaymentConfirm(w http.ResponseWriter, r *http.Request) error {
311
312
func (a * API ) PaymentList (w http.ResponseWriter , r * http.Request ) error {
312
313
log := getLogEntry (r )
313
314
instanceID := gcontext .GetInstanceID (r .Context ())
314
- query := a .db .Where ("instance_id = ?" , instanceID )
315
+ query := a .DB ( r ) .Where ("instance_id = ?" , instanceID )
315
316
316
317
query , err := parsePaymentQueryParams (query , r .URL .Query ())
317
318
if err != nil {
@@ -328,7 +329,7 @@ func (a *API) PaymentList(w http.ResponseWriter, r *http.Request) error {
328
329
// PaymentView returns information about a single payment. It is only available to admins.
329
330
func (a * API ) PaymentView (w http.ResponseWriter , r * http.Request ) error {
330
331
payID := chi .URLParam (r , "payment_id" )
331
- trans , httpErr := a . getTransaction ( payID )
332
+ trans , httpErr := getTransaction ( a . DB ( r ), payID )
332
333
if httpErr != nil {
333
334
return httpErr
334
335
}
@@ -339,6 +340,7 @@ func (a *API) PaymentView(w http.ResponseWriter, r *http.Request) error {
339
340
// refunds if desired. It is only available to admins.
340
341
func (a * API ) PaymentRefund (w http.ResponseWriter , r * http.Request ) error {
341
342
ctx := r .Context ()
343
+ db := a .DB (r )
342
344
config := gcontext .GetConfig (ctx )
343
345
params := PaymentParams {Currency : "USD" }
344
346
err := json .NewDecoder (r .Body ).Decode (& params )
@@ -347,7 +349,7 @@ func (a *API) PaymentRefund(w http.ResponseWriter, r *http.Request) error {
347
349
}
348
350
349
351
payID := chi .URLParam (r , "payment_id" )
350
- trans , httpErr := a . getTransaction (payID )
352
+ trans , httpErr := getTransaction (db , payID )
351
353
if httpErr != nil {
352
354
return httpErr
353
355
}
@@ -369,7 +371,7 @@ func (a *API) PaymentRefund(w http.ResponseWriter, r *http.Request) error {
369
371
}
370
372
371
373
log := getLogEntry (r )
372
- order , httpErr := queryForOrder (a . db , trans .OrderID , log )
374
+ order , httpErr := queryForOrder (db , trans .OrderID , log )
373
375
if httpErr != nil {
374
376
return httpErr
375
377
}
@@ -398,7 +400,7 @@ func (a *API) PaymentRefund(w http.ResponseWriter, r *http.Request) error {
398
400
Status : models .PendingState ,
399
401
}
400
402
401
- tx := a . db .Begin ()
403
+ tx := db .Begin ()
402
404
tx .Create (m )
403
405
provID := provider .Name ()
404
406
log .Debugf ("Starting refund to %s" , provID )
@@ -480,8 +482,8 @@ func (a *API) PreauthorizePayment(w http.ResponseWriter, r *http.Request) error
480
482
// ------------------------------------------------------------------------------------------------
481
483
// Helpers
482
484
// ------------------------------------------------------------------------------------------------
483
- func ( a * API ) getTransaction ( payID string ) (* models.Transaction , * HTTPError ) {
484
- trans , err := models .GetTransaction (a . db , payID )
485
+ func getTransaction ( db * gorm. DB , payID string ) (* models.Transaction , * HTTPError ) {
486
+ trans , err := models .GetTransaction (db , payID )
485
487
if err != nil {
486
488
return nil , internalServerError ("Error while querying for transactions" ).WithInternalError (err )
487
489
}
0 commit comments