Skip to content

Commit

Permalink
test all refund functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
Uchencho committed Sep 24, 2023
1 parent 395d49c commit a288a27
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 24 deletions.
91 changes: 68 additions & 23 deletions default.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (t Payout) IsNotFound() bool {
type ResendCallbackRequest struct {
PayoutId string `json:"payoutId,omitempty"`
DepositId string `json:"depositId,omitempty"`
RefundId string `json:"refundId,omitempty"`
}

type PayoutStatusResponse struct {
Expand Down Expand Up @@ -174,11 +175,72 @@ type CreateDepositResponse struct {
Annotation APIAnnotation
}

type InitiateRefundResponse struct {
RefundId string `json:"depositId"`
Status string `json:"status"`
Created string `json:"created"`
Annotation APIAnnotation
}

type Deposit struct {
DepositId string `json:"depositId"`
Status string `json:"status"`
RequestedAmount string `json:"requestedAmount"`
DepositedAmount string `json:"depositedAmount"`
Currency string `json:"currency"`
Country string `json:"country"`
Payer Payer `json:"payer"`
Correspondent string `json:"correspondent"`
StatementDescription string `json:"statementDescription"`
CustomerTimestamp string `json:"customerTimestamp"`
Created string `json:"created"`
RespondedByPayer string `json:"respondedByPayer"`
CorrespondentIds map[string]interface{} `json:"correspondentIds"`
SuspiciousActivity map[string]interface{} `json:"suspiciousActivityReport"`
FailureReason FailureReason `json:"failureReason"`
Annotation APIAnnotation
}

type DepositStatusResponse struct {
DepositId string `json:"depositId"`
Status string `json:"status"`
Annotation APIAnnotation
}

type RefundRequest struct {
RefundId string `json:"refundId"`
DepositId string `json:"depositId"`
Amount string `json:"amount"`
}

type CreateBulkDepositResponse struct {
Result []CreateDepositResponse
Annotation APIAnnotation
}

type Refund struct {
RefundId string `json:"refundId"`
Status string `json:"status"`
Amount string `json:"amount"`
Currency string `json:"currency"`
Country string `json:"country"`
Recipient Recipient `json:"recipient"`
Correspondent string `json:"correspondent"`
StatementDescription string `json:"statementDescription"`
CustomerTimestamp string `json:"customerTimestamp"`
Created string `json:"created"`
ReceivedByRecipient string `json:"receivedByRecipient"`
CorrespondentIds map[string]interface{} `json:"correspondentIds"`
FailureReason FailureReason `json:"failureReason"`
Annotation APIAnnotation
}

type RefundStatusResponse struct {
RefundId string `json:"refundId"`
Status string `json:"status"`
Annotation APIAnnotation
}

// TimeProviderFunc represents a provider of time
type TimeProviderFunc func() time.Time

Expand Down Expand Up @@ -327,29 +389,12 @@ func (s *Service) newCreateBulkDepositRequest(timeProvider TimeProviderFunc, req
return requests, nil
}

type Deposit struct {
DepositId string `json:"depositId"`
Status string `json:"status"`
RequestedAmount string `json:"requestedAmount"`
DepositedAmount string `json:"depositedAmount"`
Currency string `json:"currency"`
Country string `json:"country"`
Payer Payer `json:"recipient"`
Correspondent string `json:"correspondent"`
StatementDescription string `json:"statementDescription"`
CustomerTimestamp string `json:"customerTimestamp"`
Created string `json:"created"`
RespondedByPayer string `json:"respondedByPayer"`
CorrespondentIds map[string]interface{} `json:"correspondentIds"`
SuspiciousActivity map[string]interface{} `json:"suspiciousActivityReport"`
FailureReason FailureReason `json:"failureReason"`
Annotation APIAnnotation
}

type DepositStatusResponse struct {
DepositId string `json:"depositId"`
Status string `json:"status"`
Annotation APIAnnotation
func (s Service) newRefundRequest(refundId, depositId string, amount Amount) RefundRequest {
return RefundRequest{
RefundId: refundId,
DepositId: depositId,
Amount: amount.Value,
}
}

func GetAllCorrespondents() ([]MomoMapping, error) {
Expand Down
2 changes: 1 addition & 1 deletion deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *Service) GetDeposit(depositId string) (Deposit, error) {
return result, nil
}

// ResendCallback provides the functionality of resending a callback (webhook) for a deposit
// ResendDepositCallback provides the functionality of resending a callback (webhook) for a deposit
// See docs https://docs.pawapay.co.uk/#operation/depositsResendCallback for more details
func (s *Service) ResendDepositCallback(depositId string) (DepositStatusResponse, error) {

Expand Down
61 changes: 61 additions & 0 deletions refund.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package pawapay

import (
"fmt"
"net/http"
)

// RequestRefund provides the functionality of requesting a refund for an initiated deposit
// See docs https://docs.pawapay.co.uk/#operation/depositWebhook for more details
func (s *Service) RequestRefund(refundId, depositId string, amount Amount) (InitiateRefundResponse, error) {

resource := "refunds"
payload := s.newRefundRequest(refundId, depositId, amount)

var response InitiateRefundResponse
annotation, err := s.makeRequest(http.MethodPost, resource, payload, &response)
if err != nil {
return InitiateRefundResponse{}, err
}
response.Annotation = annotation

return response, nil
}

// GetRefund provides the functionality of retrieving an initiated refund
// See docs https://docs.pawapay.co.uk/#operation/getRefund for more details
func (s *Service) GetRefund(refundId string) (Refund, error) {

resource := fmt.Sprintf("refunds/%s", refundId)
var (
response []Refund
result Refund
)

annotation, err := s.makeRequest(http.MethodGet, resource, nil, &response)
if err != nil {
return Refund{}, err
}
if len(response) > 0 {
result = response[0]
}
result.Annotation = annotation
return result, nil
}

// ResendRefundCallback provides the functionality of resending a callback (webhook)
// See docs https://docs.pawapay.co.uk/#operation/refundsResendCallback for more details
func (s *Service) ResendRefundCallback(refundId string) (RefundStatusResponse, error) {

resource := "refunds/resend-callback"
payload := ResendCallbackRequest{RefundId: refundId}

var response RefundStatusResponse
annotation, err := s.makeRequest(http.MethodPost, resource, payload, &response)
if err != nil {
return RefundStatusResponse{}, err
}
response.Annotation = annotation

return response, nil
}

0 comments on commit a288a27

Please sign in to comment.