Skip to content

Commit

Permalink
Add IPN for payments
Browse files Browse the repository at this point in the history
  • Loading branch information
AchoArnold committed May 21, 2022
1 parent 2af4689 commit b0cf540
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ module github.com/NdoleStudio/coinpayments-go

go 1.18

require (
github.com/davecgh/go-spew v1.1.1
github.com/stretchr/testify v1.7.1
)
require github.com/stretchr/testify v1.7.1

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
2 changes: 1 addition & 1 deletion internal/helpers/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ func MakeRequestCapturingTestServer(responseCode int, response []byte, request *
panic(err)
}
}))
}
}
9 changes: 5 additions & 4 deletions payment_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package coinpayments

import (
"context"
"github.com/NdoleStudio/coinpayments-go/internal/helpers"
"github.com/NdoleStudio/coinpayments-go/internal/stubs"
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"net/url"
"testing"

"github.com/NdoleStudio/coinpayments-go/internal/helpers"
"github.com/NdoleStudio/coinpayments-go/internal/stubs"
"github.com/stretchr/testify/assert"
)

func TestPaymentService_CreateTransaction_Request(t *testing.T) {
Expand Down Expand Up @@ -82,7 +83,7 @@ func TestPaymentService_CreateTransaction_Ok(t *testing.T) {
Amount: "1.00000000",
Address: "ZZZ",
DestTag: "YYY",
TxnID: "XXX",
TransactionID: "XXX",
ConfirmsNeeded: "10",
Timeout: 9000,
CheckoutURL: "https://www.coinpayments.net/index.php?cmd=checkout&id=XXX&key=ZZZ",
Expand Down
26 changes: 25 additions & 1 deletion payments.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
package coinpayments

// CreatePaymentResponse is the api response after creating a payment
type CreatePaymentResponse struct {
Error string `json:"error"`
Result CreatePaymentResult `json:"result"`
}

// CreatePaymentResult is the result of creating a payment
type CreatePaymentResult struct {
Amount string `json:"amount"`
Address string `json:"address"`
DestTag string `json:"dest_tag"`
TxnID string `json:"txn_id"`
TransactionID string `json:"txn_id"`
ConfirmsNeeded string `json:"confirms_needed"`
Timeout int `json:"timeout"`
CheckoutURL string `json:"checkout_url"`
StatusURL string `json:"status_url"`
QrcodeURL string `json:"qrcode_url"`
}

// CreatePaymentRequest are the parameters for creating a payment
type CreatePaymentRequest struct {
Amount string `json:"amount"`
OriginalCurrency string `json:"currency1"`
SendingCurrency string `json:"currency2"`
BuyerEmail string `json:"buyer_email"`
}

// PaymentIpnRequest is the response we expect back from the server when the command is "api"
type PaymentIpnRequest struct {
Status string `json:"status"`
StatusText string `json:"status_text"`
TxnID string `json:"txn_id"`
Currency1 string `json:"currency1"`
Currency2 string `json:"currency2"`
Amount1 string `json:"amount1"`
Amount2 string `json:"amount2"`
Fee string `json:"fee"`
BuyerName string `json:"buyer_name"`
Email string `json:"email"`
ItemName string `json:"item_name"`
ItemNumber string `json:"item_number"`
Invoice string `json:"invoice"`
Custom string `json:"custom"`
SendTX string `json:"send_tx"` // the tx id of the payment to the merchant. only included when 'status' >= 100 and the payment mode is set to ASAP or nightly or if the payment is paypal passthru
ReceivedAmount string `json:"received_amount"`
ReceivedConfirms string `json:"received_confirms"`
}

0 comments on commit b0cf540

Please sign in to comment.