Skip to content

Commit

Permalink
fix(qris): ensure payment fee category and fee are both present
Browse files Browse the repository at this point in the history
  • Loading branch information
fyvri committed Dec 18, 2024
1 parent 609375b commit b41c6fb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
9 changes: 3 additions & 6 deletions api/routes/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ func Setup(env *bootstrap.Env, ginEngine *gin.Engine) {
map[string]any{
"1_Name": "Parse QRIS",
"2_Method": "POST",
"3_Path": "/parse",
"3_Target": "/parse",
"4_Body": map[string]any{
"qr_string": "000201010211y0ur4w3soMEQr15STriN6",
},
"5_Code_Snippet": `curl --location 'https://api.qris.membasuh.com/parse' --header 'Content-Type: application/json' --data '{"qr_string": "000201010211y0ur4w3soMEQr15STriN6"}'`,
},
map[string]any{
"1_Name": "Convert QRIS into a Dynamic Version",
"2_Method": "POST",
"3_Path": "/convert",
"3_Target": "/convert",
"4_Body": map[string]any{
"qr_string": "000201010211y0ur4w3soMEQr15STriN6",
"merchant_city": "Kota Yogyakarta",
Expand All @@ -46,16 +45,14 @@ func Setup(env *bootstrap.Env, ginEngine *gin.Engine) {
"payment_fee_category": "FIXED",
"payment_fee": 666,
},
"5_Code_Snippet": `curl --location 'https://api.qris.membasuh.com/convert' --header 'Content-Type: application/json' --data '{ "qr_string": "000201010211y0ur4w3soMEQr15STriN6", "merchant_city": "Kota Yogyakarta", "merchant_postal_code": "55000", "payment_amount": 1337, "payment_fee_category": "FIXED", "payment_fee": 666 }'`,
},
map[string]any{
"1_Name": "Validate QRIS",
"2_Method": "POST",
"3_Path": "/is-valid",
"3_Target": "/is-valid",
"4_Body": map[string]any{
"qr_string": "000201010211y0ur4w3soMEQr15STriN6",
},
"5_Code_Snippet": `curl --location 'https://api.qris.membasuh.com/is-valid' --header 'Content-Type: application/json' --data '{"qr_string": "000201010211y0ur4w3soMEQr15STriN6"}'`,
},
},
},
Expand Down
11 changes: 11 additions & 0 deletions internal/usecases/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func (uc *Field) IsValid(qris *entities.QRIS, errs *[]string) {
}
}

uc.IsValidPaymentFee(qris, errs)

isValidField(errs, qris.MerchantCategoryCode.Tag, "Merchant category tag is missing")
isValidField(errs, qris.CurrencyCode.Tag, "Currency code tag is missing")
isValidField(errs, qris.CountryCode.Tag, "Country code tag is missing")
Expand All @@ -126,3 +128,12 @@ func (uc *Field) IsValid(qris *entities.QRIS, errs *[]string) {
isValidField(errs, qris.MerchantPostalCode.Tag, "Merchant postal code tag is missing")
isValidField(errs, qris.CRCCode.Tag, "CRC code tag is missing")
}

func (uc *Field) IsValidPaymentFee(qris *entities.QRIS, errs *[]string) {
if qris.PaymentFeeCategory.Tag == "" && qris.PaymentFee.Tag != "" {
*errs = append(*errs, "Payment fee category tag is missing")
}
if qris.PaymentFeeCategory.Tag != "" && qris.PaymentFee.Tag == "" {
*errs = append(*errs, "Payment fee tag is missing")
}
}
48 changes: 48 additions & 0 deletions internal/usecases/field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,54 @@ func TestFieldIsValid(t *testing.T) {
"Switching tag is missing",
},
},
{
name: "Error: Payment Fee Category Tag Is Missing",
fields: Field{},
args: args{
qris: &entities.QRIS{
Version: testQRIS.Version,
Category: testQRIS.Category,
Acquirer: testQRIS.Acquirer,
Switching: testQRIS.Switching,
MerchantCategoryCode: testQRIS.MerchantCategoryCode,
CurrencyCode: testQRIS.CurrencyCode,
PaymentFeeCategory: entities.Data{},
PaymentFee: testQRIS.PaymentFee,
CountryCode: testQRIS.CountryCode,
MerchantName: testQRIS.MerchantName,
MerchantCity: testQRIS.MerchantCity,
MerchantPostalCode: testQRIS.MerchantPostalCode,
CRCCode: testQRIS.CRCCode,
},
},
want: &[]string{
"Payment fee category tag is missing",
},
},
{
name: "Error: Payment Fee Tag Is Missing",
fields: Field{},
args: args{
qris: &entities.QRIS{
Version: testQRIS.Version,
Category: testQRIS.Category,
Acquirer: testQRIS.Acquirer,
Switching: testQRIS.Switching,
MerchantCategoryCode: testQRIS.MerchantCategoryCode,
CurrencyCode: testQRIS.CurrencyCode,
PaymentFeeCategory: testQRIS.PaymentFeeCategory,
PaymentFee: entities.Data{},
CountryCode: testQRIS.CountryCode,
MerchantName: testQRIS.MerchantName,
MerchantCity: testQRIS.MerchantCity,
MerchantPostalCode: testQRIS.MerchantPostalCode,
CRCCode: testQRIS.CRCCode,
},
},
want: &[]string{
"Payment fee tag is missing",
},
},
{
name: "Error: CRC Code Tag Is Missing",
fields: Field{},
Expand Down
5 changes: 3 additions & 2 deletions internal/usecases/qris.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func (uc *QRIS) Modify(qris *entities.QRIS, merchantCityValue string, merchantPo
Data: uc.qrisTags.PaymentAmountTag + fmt.Sprintf("%02d", len(content)) + content,
}, content)

qris.PaymentFeeCategory = entities.Data{}
qris.PaymentFee = entities.Data{}
if qris.Acquirer.Tag == uc.qrisTags.AcquirerTag {
if merchantCityValue != "" {
qris.MerchantCity = *uc.dataUsecase.ModifyContent(&qris.MerchantCity, merchantCityValue)
Expand All @@ -98,8 +100,7 @@ func (uc *QRIS) Modify(qris *entities.QRIS, merchantCityValue string, merchantPo
qris.MerchantPostalCode = *uc.dataUsecase.ModifyContent(&qris.MerchantPostalCode, merchantPostalCodeValue)
}

qris.PaymentFee = entities.Data{}
if paymentFeeValue > 0 && paymentFeeCategoryValue != "" {
if paymentFeeCategoryValue != "" && paymentFeeValue > 0 {
paymentFeeCategoryTag := ""
paymentFeeCategoryContent := ""
paymentFeeCategoryContentLength := ""
Expand Down
File renamed without changes.

0 comments on commit b41c6fb

Please sign in to comment.