Skip to content

Commit

Permalink
Fix account holder payment context source
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko committed Aug 2, 2024
1 parent cbc519c commit eeba3fb
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
5 changes: 3 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,12 @@ type (
AccountHolder struct {
Type AccountHolderType `json:"type,omitempty"`
Title string `json:"title,omitempty"`
FullName string `json:"full_name,omitempty"`
FirstName string `json:"first_name,omitempty"`
MiddleName string `json:"middle_name,omitempty"`
LastName string `json:"last_name,omitempty"`
Email string `json:"email,omitempty"`
Gender string `json:"gender,omitempty"`
CompanyName string `json:"company_name,omitempty"`
TaxId string `json:"tax_id,omitempty"`
DateOfBirth string `json:"date_of_birth,omitempty"`
Expand All @@ -193,8 +196,6 @@ type (
BillingAddress *Address `json:"billing_address,omitempty"`
Phone *Phone `json:"phone,omitempty"`
Identification *AccountHolderIdentification `json:"identification,omitempty"`
Email string `json:"email,omitempty"`
Gender string `json:"gender,omitempty"`
}
)

Expand Down
3 changes: 2 additions & 1 deletion payments/nas/sources/contexts/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type (
}

requestPaymentContextsPayPalSource struct {
Type payments.SourceType `json:"type,omitempty"`
Type payments.SourceType `json:"type,omitempty"`
AccountHolder *common.AccountHolder `json:"account_holder,omitempty"`
}
)

Expand Down
41 changes: 41 additions & 0 deletions test/deserializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,44 @@ func TestControlsUnmarshallJson(t *testing.T) {
})
}
}

func TestPaymentContextUnmarshallJson(t *testing.T) {
paypalResponse, _ := ioutil.ReadFile("resources/payment_context_paypal_details_response.json")

cases := []struct {
name string
json []byte
checker func(*bytes.Buffer, error)
}{
{
name: "when deserializing payment_context_paypal_details_response type must be PayPal",
json: paypalResponse,
checker: func(serialized *bytes.Buffer, err error) {
assert.Nil(t, err)
assert.NotNil(t, serialized)

var deserialized map[string]interface{}
unmErr := json.Unmarshal(serialized.Bytes(), &deserialized)

assert.Nil(t, unmErr)
assert.NotNil(t, deserialized["payment_request"])
paymentRequest := deserialized["payment_request"].(map[string]interface{})
source := paymentRequest["source"].(map[string]interface{})

assert.Equal(t, "paypal", source["type"])
assert.Contains(t, source, "type")
assert.Contains(t, source, "account_holder")

accountHolder := source["account_holder"].(map[string]interface{})
assert.Contains(t, accountHolder, "full_name")
assert.Equal(t, "Andrey Young", accountHolder["full_name"])
},
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
tc.checker(bytes.NewBuffer(tc.json), nil)
})
}
}
50 changes: 50 additions & 0 deletions test/resources/payment_context_paypal_details_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"partner_metadata": {
"customer_id": "EWR4HCRWOEIW4",
"order_id": "NF89G5J9E5G905E90"
},
"payment_request": {
"amount": 2500,
"authorization_type": "Final",
"capture": true,
"currency": "GBP",
"failure_url": "https://url/payment-failed",
"items": [
{
"discount_amount": 0,
"name": "£25.00 Voucher",
"quantity": 1,
"tax_amount": 0,
"total_amount": 2500,
"unit_price": 2500
}
],
"payment_type": "Regular",
"processing": {
"shipping_amount": 0,
"user_action": "PAY_NOW"
},
"processing_channel_id": "pc_strugfrty47ellyymdfg6fzhc4i",
"reference": "543454",
"shipping": {
"address": {
"address_line1": "Main Address",
"address_line2": "Flor 1",
"city": "London",
"country": "GB",
"state": "State",
"zip": "ZIP"
},
"first_name": "Andrey Young"
},
"source": {
"account_holder": {
"email": "[email protected]",
"full_name": "Andrey Young"
},
"type": "paypal"
},
"success_url": "https://url/payment-successful"
},
"status": "Created"
}

0 comments on commit eeba3fb

Please sign in to comment.