Unable to save property when redirected from external site then redirect to thank you page

Hi,

I’ve created a gov.uk pay widget which sends the user to a gov pay website then returns once completed. I then run get_template_data to check if the payment succeeded. If it does succeed I want to complete the form I read cs.save requires a field path reference and the record id. If I don’t go to an external page this actually updates the ‘_form completed’ field but if I get there from an external page I get:
Unable to save property PRO0001097FEFFC1. It belongs to object OBJ0000056FEFFC1, however expected object is . (Widget: Gov.UK Pay)

here’s the code:

data_to_save[cs.ref(‘field_case_form_completed’)] = true;
data_to_save[’:id’] = record_id;
mats.save(base_object_id, data_to_save);
cs.redirect(cs.ref(‘page_thank_you’));

After this I then want to redirect to the thank you page but get the error:
Problem with the webpage - The hash doesn’t match.

,What is wrong with my references?

Thanks
Robin

edit: I think it might actually be saving the form completed field but still throwing up the error