-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreditcard.go
86 lines (71 loc) · 2.77 KB
/
creditcard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package mundipagg
// NewCardByToken Link a customer to the card using the card token
func (m mundipagg) NewCardByToken(customerID string, cardToken string, indepotencyKey string) (*Response, error) {
creditCardLink := BASEURL + customerID + CARDENDPOINT
card := NewCreditCardToken(cardToken)
resp, err := MakePostRequest(card, m.BasicSecretAuthKey, indepotencyKey, creditCardLink)
if err != nil {
return nil, err
}
return resp, nil
}
// CreditCard Struct that holds a CreditCard object
type CreditCard struct {
Installments int32 `json:"installments,omitempty"`
// StatementDescriptor description that appears on the credit card bill -> Max 22 characters
StatementDescriptor string `json:"statement_descriptor,omitempty"`
// OperationType if the transactions needs to be captuured
OperationType string `json:"Operation_type,omitempty"`
// Credit cards choose one
CardCredit *CreditCard `json:"credit_card,omitempty"`
CardID string `json:"card_id,omitempty"`
// CardToken Mundipagg card token
CardToken string `json:"card_token,omitempty"`
// Recurrence define if this payment repeats or not (default not)
Recurrence bool `json:"recurrence,omitempty"`
// Metadata Extra information about the payment
Metadata *interface{} // TODO ------------------------------------------
// Only for private label cards
ExtendedLimitEnabled bool `json:"extended_limit_enabled,omitempty"`
// Code for the super limit
ExtendedLimitCode string `json:"extended_limit_code,omitempty"`
// Code for the type of store
MerchantCategoryCode int32 `json:"merchant_id,omitempty"`
// Authentication
Authentication *interface{} // TODO ----------------------
// AutoRecovery from a offline fail
AutoRecovery bool `json:"auto_recovery,omitempty"`
// Payload for google pay, apple pay and samsung pay
Payload *interface{} `json:"payload,omitempty"` // TODO ---------------
}
/* OperationTypes
1 - auth_and_capture (default)
2 - auth_only
3 - pre_auth
*/
func (c CreditCard) OperationTypes(operationType int) string {
operation := map[int]string{
1: "auth_and_capture",
2: "auth_only",
3: "pre_auth",
}
return operation[operationType]
}
// CreditCardToken Struct that holds a CreditCard Token object
type CreditCardToken struct {
// Token CreditCard Token generated by Mundipagg
Token string `json:"token,omitempty"`
// Options Extra options like
Options *CreditCardOptions `json:"options,omitempty"`
}
// CreditCardOptions Extra options for credit card like Zero Dollar Payment
type CreditCardOptions struct {
// VerifyCard Make a Zero Dollar Payment to verify if a card is valid
VerifyCard bool `json:"verify_card,omitempty"`
}
// NewCreditCardToken return a new CreditCardToken object
func NewCreditCardToken(token string) *CreditCardToken {
return &CreditCardToken{
Token: token,
}
}