summaryrefslogtreecommitdiff
path: root/c2ec/bank-integration.go
diff options
context:
space:
mode:
Diffstat (limited to 'c2ec/bank-integration.go')
-rw-r--r--c2ec/bank-integration.go76
1 files changed, 38 insertions, 38 deletions
diff --git a/c2ec/bank-integration.go b/c2ec/bank-integration.go
index 89f9c26..d4d72f0 100644
--- a/c2ec/bank-integration.go
+++ b/c2ec/bank-integration.go
@@ -3,6 +3,7 @@ package main
import (
"bytes"
"context"
+ "encoding/base64"
"fmt"
http "net/http"
"strconv"
@@ -16,7 +17,7 @@ const WOPID_PARAMETER = "wopid"
const BANK_INTEGRATION_CONFIG_PATTERN = BANK_INTEGRATION_CONFIG_ENDPOINT
const WITHDRAWAL_OPERATION_PATTERN = WITHDRAWAL_OPERATION
const WITHDRAWAL_OPERATION_BY_WOPID_PATTERN = WITHDRAWAL_OPERATION + "/{" + WOPID_PARAMETER + "}"
-const WITHDRAWAL_OPERATION_PAYMENT_PATTERN = WITHDRAWAL_OPERATION_BY_WOPID_PATTERN + "/payment"
+const WITHDRAWAL_OPERATION_PAYMENT_PATTERN = WITHDRAWAL_OPERATION_BY_WOPID_PATTERN + "/confirm"
const WITHDRAWAL_OPERATION_ABORTION_PATTERN = WITHDRAWAL_OPERATION_BY_WOPID_PATTERN + "/abort"
const DEFAULT_LONG_POLL_MS = 1000
@@ -39,11 +40,11 @@ type BankIntegrationConfig struct {
Implementation string `json:"implementation"`
Currency string `json:"currency"`
CurrencySpecification CurrencySpecification `json:"currency_specification"`
+ // TODO: maybe add exchanges payto uri for transfers etc.?
}
type C2ECWithdrawRegistration struct {
ReservePubKey EddsaPublicKey `json:"reserve_pub_key"`
- TerminalId uint64 `json:"terminal_id"`
}
type C2ECWithdrawalStatus struct {
@@ -56,8 +57,9 @@ type C2ECWithdrawalStatus struct {
type C2ECPaymentNotification struct {
ProviderTransactionId string `json:"provider_transaction_id"`
+ TerminalId int `json:"terminal_id"`
Amount Amount `json:"amount"`
- Fees Amount `json:"fees"`
+ Fees Amount `json:"card_fees"`
}
func bankIntegrationConfig(res http.ResponseWriter, req *http.Request) {
@@ -98,27 +100,24 @@ func handleWithdrawalRegistration(res http.ResponseWriter, req *http.Request) {
// read and validate the wopid path parameter
wopid := req.PathValue(WOPID_PARAMETER)
- wopid, err = ParseWopid(wopid)
+ wpd, err := ParseWopid(wopid)
if err != nil {
LogWarn("bank-integration-api", "wopid "+wopid+" not valid")
- if wopid == "" {
- err := WriteProblem(res, HTTP_BAD_REQUEST, &RFC9457Problem{
- TypeUri: TALER_URI_PROBLEM_PREFIX + "/C2EC_INVALID_PATH_PARAMETER",
- Title: "invalid request path parameter",
- Detail: "the withdrawal status request path parameter 'wopid' is malformed",
- Instance: req.RequestURI,
- })
- if err != nil {
- res.WriteHeader(HTTP_INTERNAL_SERVER_ERROR)
- }
- return
+ err := WriteProblem(res, HTTP_BAD_REQUEST, &RFC9457Problem{
+ TypeUri: TALER_URI_PROBLEM_PREFIX + "/C2EC_INVALID_PATH_PARAMETER",
+ Title: "invalid request path parameter",
+ Detail: "the withdrawal status request path parameter 'wopid' is malformed",
+ Instance: req.RequestURI,
+ })
+ if err != nil {
+ res.WriteHeader(HTTP_INTERNAL_SERVER_ERROR)
}
+ return
}
err = DB.RegisterWithdrawal(
- WithdrawalIdentifier(wopid),
+ wpd,
registration.ReservePubKey,
- registration.TerminalId,
)
if err != nil {
@@ -135,7 +134,7 @@ func handleWithdrawalRegistration(res http.ResponseWriter, req *http.Request) {
return
}
- res.WriteHeader(HTTP_NO_CONTENT)
+ writeWithdrawalOrError(wpd, res, req.RequestURI)
}
// Get status of withdrawal associated with the given WOPID
@@ -167,21 +166,19 @@ func handleWithdrawalStatus(res http.ResponseWriter, req *http.Request) {
// read and validate the wopid path parameter
wopid := req.PathValue(WOPID_PARAMETER)
- wopid, err := ParseWopid(wopid)
+ wpd, err := ParseWopid(wopid)
if err != nil {
LogWarn("bank-integration-api", "wopid "+wopid+" not valid")
- if wopid == "" {
- err := WriteProblem(res, HTTP_BAD_REQUEST, &RFC9457Problem{
- TypeUri: TALER_URI_PROBLEM_PREFIX + "/C2EC_INVALID_PATH_PARAMETER",
- Title: "invalid request path parameter",
- Detail: "the withdrawal status request path parameter 'wopid' is malformed",
- Instance: req.RequestURI,
- })
- if err != nil {
- res.WriteHeader(HTTP_INTERNAL_SERVER_ERROR)
- }
- return
+ err := WriteProblem(res, HTTP_BAD_REQUEST, &RFC9457Problem{
+ TypeUri: TALER_URI_PROBLEM_PREFIX + "/C2EC_INVALID_PATH_PARAMETER",
+ Title: "invalid request path parameter",
+ Detail: "the withdrawal status request path parameter 'wopid' is malformed",
+ Instance: req.RequestURI,
+ })
+ if err != nil {
+ res.WriteHeader(HTTP_INTERNAL_SERVER_ERROR)
}
+ return
}
if shouldStartLongPoll {
@@ -195,7 +192,7 @@ func handleWithdrawalStatus(res http.ResponseWriter, req *http.Request) {
statusChannel := make(chan WithdrawalOperationStatus)
errChan := make(chan error)
- go DB.ListenForWithdrawalStatusChange(timeoutCtx, WithdrawalIdentifier(wopid), statusChannel, errChan)
+ go DB.ListenForWithdrawalStatusChange(timeoutCtx, WithdrawalIdentifier(base64.StdEncoding.EncodeToString(wpd)), statusChannel, errChan)
for {
select {
case <-timeoutCtx.Done():
@@ -221,19 +218,19 @@ func handleWithdrawalStatus(res http.ResponseWriter, req *http.Request) {
}
return
case <-statusChannel:
- getWithdrawalOrWriteError(wopid, res, req.RequestURI)
+ writeWithdrawalOrError(wpd, res, req.RequestURI)
return
}
}
}
- getWithdrawalOrWriteError(wopid, res, req.RequestURI)
+ writeWithdrawalOrError(wpd, res, req.RequestURI)
}
func handlePaymentNotification(res http.ResponseWriter, req *http.Request) {
wopid := req.PathValue(WOPID_PARAMETER)
- wopid, err := ParseWopid(wopid)
+ wpd, err := ParseWopid(wopid)
if err != nil {
LogWarn("bank-integration-api", "wopid "+wopid+" not valid")
if wopid == "" {
@@ -266,11 +263,14 @@ func handlePaymentNotification(res http.ResponseWriter, req *http.Request) {
return
}
+ LogInfo("bank-integration-api", "received payment notification")
+
err = DB.NotifyPayment(
- WithdrawalIdentifier(wopid),
+ wpd,
paymentNotification.ProviderTransactionId,
+ paymentNotification.TerminalId,
paymentNotification.Amount,
- paymentNotification.Amount,
+ paymentNotification.Fees,
)
if err != nil {
err := WriteProblem(res, HTTP_BAD_REQUEST, &RFC9457Problem{
@@ -296,7 +296,7 @@ func handleWithdrawalAbort(res http.ResponseWriter, req *http.Request) {
// Tries to load a WithdrawalOperationStatus from the database. If no
// entry could been found, it will write the correct error to the response.
-func getWithdrawalOrWriteError(wopid string, res http.ResponseWriter, reqUri string) {
+func writeWithdrawalOrError(wopid []byte, res http.ResponseWriter, reqUri string) {
// read the withdrawal from the database
withdrawal, err := DB.GetWithdrawalByWopid(wopid)
if err != nil {
@@ -318,7 +318,7 @@ func getWithdrawalOrWriteError(wopid string, res http.ResponseWriter, reqUri str
err := WriteProblem(res, HTTP_NOT_FOUND, &RFC9457Problem{
TypeUri: TALER_URI_PROBLEM_PREFIX + "/C2EC_WITHDRAWAL_NOT_FOUND",
Title: "Not Found",
- Detail: "No withdrawal with wopid=" + wopid + " could been found.",
+ Detail: "No withdrawal with wopid=" + talerBase32Encode(wopid) + " could been found.",
Instance: reqUri,
})
if err != nil {