~singpolyma/jmp-pay

56244eb81f77789d966b2342f195042c528be8e3 — Stephen Paul Weber 1 year, 11 months ago e76129e
Save bidirectional association for customer_id in redis
1 files changed, 20 insertions(+), 7 deletions(-)

M config.ru
M config.ru => config.ru +20 -7
@@ 31,16 31,25 @@ class CreditCardGateway
	end

	def customer_id
		customer_id = REDIS.get(redis_key)
		customer_id = REDIS.get(redis_key_jid)
		return customer_id if check_customer_id(customer_id)

		cresult = @gateway.customer.create
		raise "Braintree customer create failed" unless cresult.success?
		result = @gateway.customer.create
		raise "Braintree customer create failed" unless result.success?
		@customer_id = result.customer.id
		save_customer_id!
	end

	def save_customer_id!
		unless REDIS.set(redis_key_jid, @customer_id) == "OK"
			raise "Saving new jid,customer to redis failed"
		end

		result = REDIS.set(redis_key, cresult.customer.id)
		raise "Saving new customer to redis failed" unless result == "OK"
		unless REDIS.set(redis_key_customer_id, @jid) == "OK"
			raise "Saving new customer,jid to redis failed"
		end

		cresult.customer.id
		@customer_id
	end

	def client_token


@@ 59,9 68,13 @@ class CreditCardGateway

protected

	def redis_key
	def redis_key_jid
		"jmp_customer_id-#{@jid}"
	end

	def redis_key_customer_id
		"jmp_customer_jid-#{@customer_id}"
	end
end

class JmpPay < Roda