-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistrations.go
More file actions
257 lines (193 loc) · 9.69 KB
/
registrations.go
File metadata and controls
257 lines (193 loc) · 9.69 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package snap
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/DoWithLogic/go-snap-bi/types"
)
// CardType represents the type of bank card in SNAP BI system.
type CardType string
const (
// Debit represents a debit card type.
Debit CardType = "D"
// Credit represents a credit card type.
Credit CardType = "C"
// ElectronicMoney represents an electronic money card type.
ElectronicMoney CardType = "UE"
)
// Flag represents a boolean-like flag with YES/NO values for SNAP BI APIs.
type Flag string
const (
// YES represents an affirmative/true value.
YES Flag = "YES"
// NO represents a negative/false value.
NO Flag = "NO"
)
// CardBindRequest represents the request structure for card binding operation.
// This is used to bind a customer's card to the merchant for future transactions.
type CardBindRequest struct {
Params
// PartnerReferenceNo is the unique reference number generated by the partner.
PartnerReferenceNo *string `json:"partnerReferenceNo,omitempty"`
// AccountName is the name of the account holder.
AccountName *string `json:"accountName,omitempty"`
// CardData contains encrypted card data for binding.
CardData string `json:"cardData"`
// BankAccountNo is the bank account number associated with the card.
BankAccountNo *string `json:"bankAccountNo,omitempty"`
// BankCardNo is the card number to be bound.
BankCardNo string `json:"bankCardNo"`
// BankCardType specifies the type of card (debit, credit, electronic money).
BankCardType *CardType `json:"bankCardType,omitempty"`
// DateOfBirth is the customer's date of birth in YYYY-MM-DD format.
DateOfBirth *string `json:"dateOfBirth,omitempty"`
// Email is the customer's email address.
Email *string `json:"email,omitempty"`
// ExpiredDateTime is the expiration datetime of the binding operation.
ExpiredDateTime *string `json:"expiredDatetime,omitempty"`
// ExpiryDate is the card expiration date in MMYY format.
ExpiryDate *string `json:"expiryDate,omitempty"`
// IdentificationNo is the customer's identification number.
IdentificationNo *string `json:"identificationNo,omitempty"`
// IdentificationType specifies the type of identification provided.
IdentificationType *types.IdentificationType `json:"identificationType,omitempty"`
// CustIDMerchant is the customer identifier in the merchant system.
CustIDMerchant string `json:"custIdMerchant"`
// IsBindAndPay indicates if this is a bind-and-pay operation.
IsBindAndPay *string `json:"isBindAndPay,omitempty"`
// MerchantID is the merchant identifier.
MerchantID *string `json:"merchantId,omitempty"`
// TerminalID is the terminal identifier.
TerminalID *string `json:"terminalId,omitempty"`
// JourneyID is the journey identifier for tracking the customer flow.
JourneyID *string `json:"journeyId,omitempty"`
// SubMerchantID is the sub-merchant identifier.
SubMerchantID *string `json:"subMerchantId,omitempty"`
// ExternalStoreID is the external store identifier.
ExternalStoreID *string `json:"externalStoreId,omitempty"`
// Limit is the transaction limit for the bound card.
Limit *float64 `json:"limit,omitempty"`
// MerchantLogoURL is the URL of the merchant's logo.
MerchantLogoURL *string `json:"merchantLogoUrl,omitempty"`
// PhoneNo is the customer's phone number.
PhoneNo *string `json:"phoneNo,omitempty"`
// SendOtpFlag indicates whether to send OTP for verification.
SendOtpFlag *Flag `json:"sendOtpFlag,omitempty"`
// Type specifies additional type information for the binding.
Type *string `json:"type,omitempty"`
// AdditionalInfo contains extra parameters for the request.
AdditionalInfo *types.AdditionalInfo `json:"additionalInfo,omitempty"`
}
// JSON marshals the CardBindRequest into JSON bytes.
// Note: This method ignores marshaling errors which should be handled by callers.
func (c CardBindRequest) JSON() []byte {
byteJSON, _ := json.Marshal(c)
return byteJSON
}
// CardBindResponse represents the response structure for card binding operation.
type CardBindResponse struct {
// ResponseCode contains the API response code.
ResponseCode string `json:"responseCode"`
// ResponseMessage contains the descriptive response message.
ResponseMessage string `json:"responseMessage"`
// ReferenceNo is the unique reference number generated by SNAP.
ReferenceNo *string `json:"referenceNo,omitempty"`
// PartnerReferenceNo is the partner's reference number from the request.
PartnerReferenceNo *string `json:"partnerReferenceNo,omitempty"`
// BankCardToken is the token representing the bound card for future transactions.
BankCardToken string `json:"bankCardToken"`
// ChargeToken is the token for charging the bound card (if applicable).
ChargeToken *string `json:"chargeToken,omitempty"`
// RandomString is a random string for security purposes.
RandomString *string `json:"randomString,omitempty"`
// TokenExpiryTime is the expiration time of the generated tokens.
TokenExpiryTime *string `json:"tokenExpiryTime,omitempty"`
// AdditionalInfo contains extra parameters from the response.
AdditionalInfo *types.AdditionalInfo `json:"additionalInfo,omitempty"`
}
// CardBindLimitRequest represents the request structure for setting card binding limits.
// This operation sets or updates transaction limits for a previously bound card.
type CardBindLimitRequest struct {
Params
// PartnerReferenceNo is the unique reference number generated by the partner.
PartnerReferenceNo string `json:"partnerReferenceNo"`
// BankAccountNo is the bank account number associated with the card.
BankAccountNo string `json:"bankAccountNo"`
// BankCardNo is the card number that was previously bound.
BankCardNo string `json:"bankCardNo"`
// Limit is the new transaction limit to set for the card.
Limit string `json:"limit"`
// BankCardToken is the token representing the bound card.
BankCardToken string `json:"bankCardToken"`
// Otp is the one-time password for authorization.
Otp string `json:"otp"`
// AdditionalInfo contains extra parameters for the request.
AdditionalInfo *types.AdditionalInfo `json:"additionalInfo,omitempty"`
}
// JSON marshals the CardBindLimitRequest into JSON bytes.
// Note: This method ignores marshaling errors which should be handled by callers.
func (c CardBindLimitRequest) JSON() []byte {
byteJSON, _ := json.Marshal(c)
return byteJSON
}
// CardBindLimitResponse represents the response structure for card binding limit operation.
type CardBindLimitResponse struct {
// ResponseCode contains the API response code.
ResponseCode string `json:"responseCode"`
// ResponseMessage contains the descriptive response message.
ResponseMessage string `json:"responseMessage"`
// ReferenceNo is the unique reference number generated by SNAP.
ReferenceNo string `json:"referenceNo"`
// PartnerReferenceNo is the partner's reference number from the request.
PartnerReferenceNo string `json:"partnerReferenceNo"`
// AdditionalInfo contains extra parameters from the response.
AdditionalInfo *types.AdditionalInfo `json:"additionalInfo,omitempty"`
}
// registration handles customer registration related operations including card binding.
type registration struct {
tm *tokenManager
}
// CardBind performs a card registration service to register a consumer's card data
// with Non-PJP Service Users, PJP AIns, or PJP PIAS. The consumer's card is issued
// by PJP AIS and serves as the consumer's funding source for transactions and/or
// accessing other services. This API can be provided by the PJP performing the card registration.
//
// For B2C business relationships, a verification process is required to ensure
// the accuracy of consumer data. This operation binds a customer's payment card
// to the merchant system for future transactions, enabling seamless payments
// without re-entering card details.
//
// Reference: https://apidevportal.aspi-indonesia.or.id/api-services/registrasi#/Registrasi/post_api_v1_0_registration_card_bind_limit
func (r *registration) CardBind(ctx context.Context, request CardBindRequest) (response CardBindResponse, err error) {
// Build transaction headers with authentication and signing
if err := r.tm.buildTransactionHeaders(ctx, http.MethodPost, types.RegistrationCardBind.String(), request.JSON(), &request.Params); err != nil {
return response, fmt.Errorf("failed to build transaction headers: %w", err)
}
// Execute the API call to bind the card
if err := r.tm.tp.CallWithContext(ctx, http.MethodPost, types.RegistrationCardBind, &request, &response); err != nil {
return response, fmt.Errorf("card bind API call failed: %w", err)
}
return response, nil
}
// CardBindLimit sets or updates transaction limits for a previously bound card.
// This API allows merchants to define spending limits and restrictions on registered
// consumer cards, providing additional security controls and risk management.
//
// The limit setting operation requires OTP (One-Time Password) verification to ensure
// that only authorized users can modify transaction limits, adding an extra layer of
// security for consumer protection.
//
// This service is typically used after successful card binding (CardBind) to configure
// the operational parameters of the bound card for subsequent transactions.
//
// Reference: https://apidevportal.aspi-indonesia.or.id/api-services/registrasi#/Registrasi/post_api_v1_0_registration_card_bind_limit
func (r *registration) CardBindLimit(ctx context.Context, request CardBindLimitRequest) (response CardBindLimitResponse, err error) {
if err := r.tm.buildTransactionHeaders(ctx, http.MethodPost, types.RegistrationCardBindLimit.String(), request.JSON(), &request.Params); err != nil {
return response, err
}
if err := r.tm.tp.CallWithContext(ctx, http.MethodPost, types.RegistrationCardBindLimit, &request, &response); err != nil {
return response, err
}
return response, nil
}