Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion actions/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func Content(event event.Event) *chargebee.Result {
if err1 != nil {
panic(err1)
}

// Parse and populate custom fields
chargebee.PrepareResultCF(event.Content, content)

return content
}

Expand All @@ -37,4 +41,4 @@ func Deserialize(jsonObj string) *event.Event {
panic(errors.New("API version [" + strings.ToUpper(string(apiVersion)) + "] in responce does not match with client library API version [" + strings.ToUpper(envVersion) + "]"))
}
return event
}
}
4 changes: 4 additions & 0 deletions tests/event_deserialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ func TestDeserialize(t *testing.T) {
assert.NotNil(t, content.Card)
assert.NotNil(t, content.Invoice)
assert.NotNil(t, content.Transaction)

// Check that custom fields are here
assert.Equal(t, content.Subscription.CustomField["cf_subscription_comment"], "test_value_subscription")
assert.Equal(t, content.Customer.CustomField["cf_customer_comment"], "test_value_customer")
}
6 changes: 4 additions & 2 deletions tests/sample_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func eventData() string {
"created_at": 1339951248,
"email": "rr@chargebee.com",
"id": "8avPlNabxST86",
"object": "customer"
"object": "customer",
"cf_customer_comment": "test_value_customer"
},
"invoice": {
"amount": 900,
Expand Down Expand Up @@ -83,7 +84,8 @@ func eventData() string {
"object": "subscription",
"plan_id": "no_trial",
"plan_quantity": 1,
"status": "active"
"status": "active",
"cf_subscription_comment": "test_value_subscription"
},
"transaction": {
"amount": 900,
Expand Down
6 changes: 3 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func parseArray(anArray []interface{}, serParams map[string]interface{}, prefix
k := prefix + "[" + mk + "]" + "[" + strconv.Itoa(i) + "]"
serParams[k] = mv
}
default:
default:
k := prefix + "[" + strconv.Itoa(i) + "]"
serParams[k] = value
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func camelCase(str string) string {
func customFieldExtraction(v interface{}, resJSON []byte) {
switch v.(type) {
case *Result:
prepareResultCF(resJSON, v)
PrepareResultCF(resJSON, v)

case *ResultList:
prepareResultListCF(resJSON, v)
Expand All @@ -183,7 +183,7 @@ func customMapping(val interface{}) map[string]interface{} {
return custom
}

func prepareResultCF(resbody []byte, v interface{}) {
func PrepareResultCF(resbody []byte, v interface{}) {
data := json.NewDecoder(strings.NewReader(string(resbody)))
data.UseNumber()
var m map[string]interface{}
Expand Down