从 braintree api 调用中为数据库赋值
assign value to database from braintree api call
我正在尝试将 braintree 创建的客户 ID 保存到我的数据库中。我可以看到 id 正在 braintree 上创建并在我的终端中回显但是当试图分配到我的数据库中的列时它似乎没有保存
I, [2016-06-22T23:30:13.267296 #8775] INFO -- : [Braintree] [22/Jun/2016 13:30:13 UTC] POST /merchants/xxxxx/customers 201
86502732
def create_braintree_customer
# self.access_token = SecureRandom::hex(9+rand(6)) if access_token.nil?
result = Braintree::Customer.create(
:first_name => self.first_name,
:last_name => self.last_name,
:email => self.email,
:phone => self.mobile
)
if result.success?
puts result.customer.id
self.customer_cim_id = result.customer.id
else
p result.errors
end
end
在 after_create 中,您的模型更改将不会再次保存。或者使用一些 before_create、before_save 和这样的回调或者做 update_attribute 或 update_column(如果你不想再次触发回调)。
update_column(:customer_cim_id, result.customer.id)
我正在尝试将 braintree 创建的客户 ID 保存到我的数据库中。我可以看到 id 正在 braintree 上创建并在我的终端中回显但是当试图分配到我的数据库中的列时它似乎没有保存
I, [2016-06-22T23:30:13.267296 #8775] INFO -- : [Braintree] [22/Jun/2016 13:30:13 UTC] POST /merchants/xxxxx/customers 201
86502732
def create_braintree_customer
# self.access_token = SecureRandom::hex(9+rand(6)) if access_token.nil?
result = Braintree::Customer.create(
:first_name => self.first_name,
:last_name => self.last_name,
:email => self.email,
:phone => self.mobile
)
if result.success?
puts result.customer.id
self.customer_cim_id = result.customer.id
else
p result.errors
end
end
在 after_create 中,您的模型更改将不会再次保存。或者使用一些 before_create、before_save 和这样的回调或者做 update_attribute 或 update_column(如果你不想再次触发回调)。
update_column(:customer_cim_id, result.customer.id)