Skip to content

Commit

Permalink
chore: add payment option patch and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsaporiti committed Jan 9, 2025
1 parent d57d129 commit d1b25ce
Show file tree
Hide file tree
Showing 8 changed files with 476 additions and 36 deletions.
42 changes: 42 additions & 0 deletions api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,7 @@ paths:
'500':
$ref: '#/components/responses/500'


/v2/identities/{identifier}/payment/options/{id}:
get:
summary: Get Payment Option
Expand Down Expand Up @@ -1950,6 +1951,36 @@ paths:
'500':
$ref: '#/components/responses/500'

patch:
summary: Update Payment Option
operationId: UpdatePaymentOption
description: Update payment option for the provided identity.
security:
- basicAuth: [ ]
tags:
- Payment
parameters:
- $ref: '#/components/parameters/pathIdentifier'
- $ref: '#/components/parameters/id'
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UpdatePaymentOptionRequest'
responses:
'200':
description: Schema information
content:
application/json:
schema:
$ref: '#/components/schemas/GenericMessage'
'400':
$ref: '#/components/responses/400'
'404':
$ref: '#/components/responses/404'
'500':
$ref: '#/components/responses/500'

/v2/identities/{identifier}/payment/verify/{nonce}:
post:
Expand Down Expand Up @@ -2816,6 +2847,17 @@ components:
paymentOptions:
$ref: '#/components/schemas/PaymentOptionConfig'

UpdatePaymentOptionRequest:
type: object
properties:
name:
type: string
description:
type: string
paymentOptions:
$ref: '#/components/schemas/PaymentOptionConfig'


CreatePaymentRequest:
type: object
required:
Expand Down
145 changes: 145 additions & 0 deletions internal/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions internal/api/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,34 @@ func (s *Server) VerifyPayment(ctx context.Context, request VerifyPaymentRequest
return toVerifyPaymentResponse(status)
}

// UpdatePaymentOption - updates a payment option
func (s *Server) UpdatePaymentOption(ctx context.Context, request UpdatePaymentOptionRequestObject) (UpdatePaymentOptionResponseObject, error) {
issuerDID, err := w3c.ParseDID(request.Identifier)
if err != nil {
log.Error(ctx, "parsing issuer did", "err", err, "did", request.Identifier)
return UpdatePaymentOption400JSONResponse{N400JSONResponse{Message: "invalid issuer did"}}, nil
}

var payOptConf *domain.PaymentOptionConfig
if request.Body.PaymentOptions != nil {
payOptConf, err = newPaymentOptionConfig(*request.Body.PaymentOptions)
if err != nil {
log.Error(ctx, "creating payment option config", "err", err)
return UpdatePaymentOption400JSONResponse{N400JSONResponse{Message: fmt.Sprintf("invalid config: %s", err)}}, nil
}
}

err = s.paymentService.UpdatePaymentOption(ctx, issuerDID, request.Id, request.Body.Name, request.Body.Description, payOptConf)
if err != nil {
log.Error(ctx, "updating payment option", "err", err, "issuer", issuerDID, "request", request.Body)
if errors.Is(err, repositories.ErrPaymentOptionDoesNotExists) {
return UpdatePaymentOption400JSONResponse{N400JSONResponse{Message: "payment option not found"}}, nil
}
return UpdatePaymentOption500JSONResponse{N500JSONResponse{Message: fmt.Sprintf("can't update payment-option: <%s>", err.Error())}}, nil
}
return UpdatePaymentOption200JSONResponse{}, nil
}

func newPaymentOptionConfig(config PaymentOptionConfig) (*domain.PaymentOptionConfig, error) {
const base10 = 10
cfg := &domain.PaymentOptionConfig{
Expand Down
Loading

0 comments on commit d1b25ce

Please sign in to comment.