Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

satellite/console: payments api #3297

Merged
merged 17 commits into from Oct 17, 2019
Merged

satellite/console: payments api #3297

merged 17 commits into from Oct 17, 2019

Conversation

crawter
Copy link
Contributor

@crawter crawter commented Oct 16, 2019

What:

  1. Minor fixes for payment service
  2. satellite/console/service extended with payments functionality
  3. satellite/console/server routes partially changed
  4. satellite/console/ - api for setting account up, get balance and add credit card implemented
    Why:

Please describe the tests:

  • Test 1:
  • Test 2:

Please describe the performance impact:

Code Review Checklist (to be filled out by reviewer)

  • Does the PR describe what changes are being made?
  • Does the PR describe why the changes are being made?
  • Does the code follow our style guide?
  • Does the code follow our testing guide?
  • Is the PR appropriately sized? (If it could be broken into smaller PRs it should be)
  • Does the new code have enough tests? (every PR should have tests or justification otherwise. Bug-fix PRs especially)
  • Does the new code have enough documentation that answers "how do I use it?" and "what does it do?"? (both source documentation and higher level, diagrams?)
  • Does any documentation need updating?
  • Do the database access patterns make sense?

@cla-bot cla-bot bot added the cla-signed label Oct 16, 2019
@crawter crawter self-assigned this Oct 16, 2019
@crawter crawter changed the title api implemented, server partially refactored, console service extended satellite/console - payments api Oct 16, 2019
@crawter crawter marked this pull request as ready for review October 16, 2019 16:33
@crawter crawter requested a review from a team October 16, 2019 16:33
@ghost ghost requested review from cam-a and zeebo and removed request for a team October 16, 2019 16:33
@crawter crawter requested review from ifraixedes, rikysya, egonelbre and a team October 16, 2019 16:34
@ghost ghost removed their request for review October 16, 2019 16:34
@crawter crawter added Request Code Review Code review requested Reviewer Can Merge If all checks have passed, non-owner can merge PR Sprint Release Goal Sprint Release Goal labels Oct 16, 2019
@ifraixedes ifraixedes removed their request for review October 16, 2019 17:00

err = json.NewEncoder(w).Encode(balanceResponse)
if err != nil {
p.serveJSONError(w, http.StatusInternalServerError, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the json NewEncoder already started writing something, it will double write the header.

egonelbre
egonelbre previously approved these changes Oct 17, 2019
mux.Handle("/api/v0/token", http.HandlerFunc(server.tokenHandler))
paymentController := consoleapi.NewPayments(logger, service)
paymentsRouter := router.PathPrefix("/api/v0/payments").Subrouter()
paymentsRouter.Handle("/cards", http.HandlerFunc(paymentController.AddCreditCard)).Methods(http.MethodPost)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, just noticed this... mux.Router has HandleFunc, so you don't have to cast everything to HandlerFunc

satellite/api.go Outdated
@@ -363,11 +364,16 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB, pointerDB metai
if consoleConfig.AuthTokenSecret == "" {
return nil, errs.New("Auth token secret required")
}

paymentsConfig := stripecoinpayments.Config{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to create config here?

var err error
defer mon.Task()(&ctx)(&err)

balance, err := p.service.Payments().AccountBalance(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing authorization

return
}

err = p.service.Payments().AddCreditCard(ctx, requestBody.Token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing authorization

@@ -592,11 +592,15 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, pointerDB metainfo
return nil, errs.New("Auth token secret required")
}

paymentsConfig := stripecoinpayments.Config{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we create config here

var err error
defer mon.Task()(&ctx)(&err)

err = p.service.Payments().SetupAccount(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing authorization

@rikysya rikysya changed the title satellite/console - payments api satellite/console: payments api Oct 17, 2019
@crawter crawter requested a review from rikysya October 17, 2019 12:57

// authorize checks request for authorization token, validates it and updates context with auth data.
func (p *Payments) authorize(ctx context.Context, r *http.Request) (context.Context, error) {
tokenCookie, err := r.Cookie("_tokenKey")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api doesn't use coockie auth

}

auth, err := p.service.Authorize(auth.WithAPIKey(ctx, []byte(tokenCookie.Value)))
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err add error to context

@crawter crawter requested a review from rikysya October 17, 2019 13:24
satellite/api.go Outdated
@@ -363,11 +364,16 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB, pointerDB metai
if consoleConfig.AuthTokenSecret == "" {
return nil, errs.New("Auth token secret required")
}

paymentsConfig := config.Payments
payments := stripecoinpayments.NewService(paymentsConfig, peer.DB.Customers())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use config.Payments directly

@@ -49,11 +50,15 @@ func TestGrapqhlMutation(t *testing.T) {

log := zaptest.NewLogger(t)

paymentsConfig := stripecoinpayments.Config{}
payments := stripecoinpayments.NewService(paymentsConfig, db.Customers())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use config.Payments directly


passwordCost int
}

// PaymentsService separates all payment related functionality
type PaymentsService struct {
service *Service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smth with console would make more sense

@crawter crawter requested a review from rikysya October 17, 2019 14:27
@crawter crawter requested a review from Qweder93 October 17, 2019 14:33
@crawter crawter merged commit 26cc625 into storj:master Oct 17, 2019
@crawter crawter deleted the yb/satellite-console-card-api branch October 17, 2019 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed Request Code Review Code review requested Reviewer Can Merge If all checks have passed, non-owner can merge PR Sprint Release Goal Sprint Release Goal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants