diff --git a/actions/event/event.go b/actions/event/event.go index 42096b36..6b90fc43 100644 --- a/actions/event/event.go +++ b/actions/event/event.go @@ -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 } @@ -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 -} \ No newline at end of file +} diff --git a/tests/event_deserialize_test.go b/tests/event_deserialize_test.go index 140e2a64..3cacb8e4 100644 --- a/tests/event_deserialize_test.go +++ b/tests/event_deserialize_test.go @@ -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") } diff --git a/tests/sample_data.go b/tests/sample_data.go index 8ff3b6f7..86e5a962 100644 --- a/tests/sample_data.go +++ b/tests/sample_data.go @@ -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, @@ -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, diff --git a/util.go b/util.go index f73b83fb..ebdd8f7a 100644 --- a/util.go +++ b/util.go @@ -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 } @@ -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) @@ -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{}