-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package pawapay | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/pariz/gountries" | ||
) | ||
|
||
// InitiateDeposit provides the functionality of initiating a deposit for the sender to confirm | ||
// See docs https://docs.pawapay.co.uk/#operation/createDesposit for more details | ||
func (s *Service) InitiateDeposit(timeProvider TimeProviderFunc, depositReq DepositRequest) (CreateDepositResponse, error) { | ||
|
||
query := gountries.New() | ||
se, err := query.FindCountryByCallingCode(depositReq.PhoneNumber.CountryCode) | ||
if err != nil { | ||
return CreateDepositResponse{}, err | ||
} | ||
countryCode := se.Alpha3 | ||
|
||
resource := "deposits" | ||
payload := s.newDepositRequest(timeProvider, depositReq.DepositId, depositReq.Amount, countryCode, | ||
depositReq.Correspondent, depositReq.Description, depositReq.PhoneNumber, depositReq.PreAuthCode) | ||
|
||
var response CreateDepositResponse | ||
annotation, err := s.makeRequest(http.MethodPost, resource, payload, &response) | ||
if err != nil { | ||
return CreateDepositResponse{}, err | ||
} | ||
response.Annotation = annotation | ||
|
||
return response, nil | ||
} | ||
|
||
// CreateBulkDeposit provides the functionality of creating a bulk deposit | ||
// See docs https://docs.pawapay.co.uk/#operation/createDeposits for more details | ||
func (s *Service) CreateBulkDeposit(timeProvider TimeProviderFunc, data []DepositRequest) (CreateBulkDepositResponse, error) { | ||
|
||
resource := "deposits/bulk" | ||
payload, err := s.newCreateBulkDepositRequest(timeProvider, data) | ||
if err != nil { | ||
return CreateBulkDepositResponse{}, err | ||
} | ||
|
||
var response []CreateDepositResponse | ||
annotation, err := s.makeRequest(http.MethodPost, resource, payload, &response) | ||
if err != nil { | ||
return CreateBulkDepositResponse{}, err | ||
} | ||
|
||
return CreateBulkDepositResponse{Result: response, Annotation: annotation}, nil | ||
} | ||
|
||
// GetDeposit provides the functionality of retrieving a deposit | ||
// See docs https://docs.pawapay.co.uk/#operation/getDeposit for more details | ||
func (s *Service) GetDeposit(depositId string) (Deposit, error) { | ||
|
||
resource := fmt.Sprintf("payouts/%s", depositId) | ||
var ( | ||
response []Deposit | ||
result Deposit | ||
) | ||
|
||
annotation, err := s.makeRequest(http.MethodGet, resource, nil, &response) | ||
if err != nil { | ||
return Deposit{}, err | ||
} | ||
if len(response) > 0 { | ||
result = response[0] | ||
} | ||
result.Annotation = annotation | ||
return result, nil | ||
} | ||
|
||
// ResendCallback 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) { | ||
|
||
resource := "deposits/resend-callback" | ||
payload := ResendCallbackRequest{DepositId: depositId} | ||
|
||
var response DepositStatusResponse | ||
annotation, err := s.makeRequest(http.MethodPost, resource, payload, &response) | ||
if err != nil { | ||
return DepositStatusResponse{}, err | ||
} | ||
response.Annotation = annotation | ||
|
||
return response, nil | ||
} |