@@ 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