neero.*transactionIntentService.CashIn   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nop 2
dl 0
loc 17
rs 9.85
c 0
b 0
f 0
1
package neero
2
3
import (
4
	"context"
5
	"encoding/json"
6
	"net/http"
7
)
8
9
// transactionIntentService is the API client for the `/payment-gateway/api/v1/transaction-intents` endpoint
10
type transactionIntentService service
11
12
// CashIn creates a transaction in which the destination is a Merchant Account you own.
13
//
14
// API Docs: https://app.theneo.io/neero/neero-payment-gateway/transaction-intents-1/create-cash-in-payment-intent
15
func (service *transactionIntentService) CashIn(ctx context.Context, payload *TransactionIntentCreateRequest) (*TransactionIntentTransaction, *Response, error) {
16
	request, err := service.client.newRequest(ctx, http.MethodPost, "/payment-gateway/api/v1/transaction-intents/cash-in", payload)
17
	if err != nil {
18
		return nil, nil, err
19
	}
20
21
	response, err := service.client.do(request)
22
	if err != nil {
23
		return nil, response, err
24
	}
25
26
	transaction := new(TransactionIntentTransaction)
27
	if err = json.Unmarshal(*response.Body, transaction); err != nil {
28
		return nil, response, err
29
	}
30
31
	return transaction, response, nil
32
}
33
34
// CashOut creates a transaction in which the source is your Merchant Account and the destination can be a wallet, bank account, credit card
35
//
36
// API Docs: https://app.theneo.io/neero/neero-payment-gateway/transaction-intents-1/create-cash-out-payment-intent
37
func (service *transactionIntentService) CashOut(ctx context.Context, payload *TransactionIntentCreateRequest) (*TransactionIntentTransaction, *Response, error) {
38
	request, err := service.client.newRequest(ctx, http.MethodPost, "/payment-gateway/api/v1/transaction-intents/cash-out", payload)
39
	if err != nil {
40
		return nil, nil, err
41
	}
42
43
	response, err := service.client.do(request)
44
	if err != nil {
45
		return nil, response, err
46
	}
47
48
	transaction := new(TransactionIntentTransaction)
49
	if err = json.Unmarshal(*response.Body, transaction); err != nil {
50
		return nil, response, err
51
	}
52
53
	return transaction, response, nil
54
}
55
56
// Get a transaction intent by ID
57
//
58
// API Docs: https://app.theneo.io/neero/neero-payment-gateway/transaction-intents-1/find-transaction-intent-by-id
59
func (service *transactionIntentService) Get(ctx context.Context, transactionIntentID string) (*TransactionIntentTransaction, *Response, error) {
60
	request, err := service.client.newRequest(ctx, http.MethodGet, "/payment-gateway/api/v1/transaction-intents/"+transactionIntentID, nil)
61
	if err != nil {
62
		return nil, nil, err
63
	}
64
65
	response, err := service.client.do(request)
66
	if err != nil {
67
		return nil, response, err
68
	}
69
70
	balance := new(TransactionIntentTransaction)
71
	if err = json.Unmarshal(*response.Body, balance); err != nil {
72
		return nil, response, err
73
	}
74
75
	return balance, response, nil
76
}
77