Class: Service
- Inherits:
-
Object
- Object
- Service
- Defined in:
- lib/compropago_sdk/service.rb
Instance Method Summary collapse
-
#create_webhook(url) ⇒ Webhook
FUNCTION: creatre webhook.
-
#delete_webhook(webhook_id) ⇒ Object
FUNCTION: delete webhook.
-
#get_auth ⇒ Hash
FUNCTION: get auth params.
-
#initialize(client) ⇒ Service
constructor
FUNCTION: constructor.
-
#list_providers(limit = 0, currency = 'MXN') ⇒ Object
FUNCTION: list providers by limit and currency.
-
#list_webhooks ⇒ ListWebhooks
FUNCTION: get list registered webhooks.
-
#place_order(order) ⇒ NewOrderInfo
FUNCTION: place order.
-
#send_sms_instructions(number, order_id) ⇒ SmsInfo
FUNCTION: send sms of an order.
-
#update_webhook(webhook_id, new_url) ⇒ Webhook
FUNCTION: update registered webhook.
-
#verify_order(order_id) ⇒ CpOrderInfo
FUNCTION: veridy order by unique_id.
Constructor Details
#initialize(client) ⇒ Service
FUNCTION: constructor
3 4 5 |
# File 'lib/compropago_sdk/service.rb', line 3 def initialize(client) @client = client end |
Instance Method Details
#create_webhook(url) ⇒ Webhook
FUNCTION: creatre webhook
82 83 84 85 86 87 88 |
# File 'lib/compropago_sdk/service.rb', line 82 def create_webhook(url) params = {url: url} response = EasyRequest::post(@client.deploy_uri+'webhooks/stores/', params, get_auth()) Factory::get_instance_of 'Webhook', response end |
#delete_webhook(webhook_id) ⇒ Object
FUNCTION: delete webhook
105 106 107 108 109 |
# File 'lib/compropago_sdk/service.rb', line 105 def delete_webhook(webhook_id) response = EasyRequest::delete(@client.deploy_uri+'webhooks/stores/'+webhook_id, nil, get_auth()) Factory::get_instance_of 'Webhook', response end |
#get_auth ⇒ Hash
FUNCTION: get auth params
9 10 11 |
# File 'lib/compropago_sdk/service.rb', line 9 def get_auth { :user => @client.get_user, :pass => @client.get_pass } end |
#list_providers(limit = 0, currency = 'MXN') ⇒ Object
FUNCTION: list providers by limit and currency
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/compropago_sdk/service.rb', line 16 def list_providers(limit=0, currency='MXN') uri = @client.deploy_uri+'providers/' if limit > 0 uri = uri+'?order_total='+limit.to_s end if limit > 0 && !currency.nil? && currency != 'MXN' uri = uri+'¤cy='+currency end response = EasyRequest::get(uri, get_auth()) Factory::get_instance_of 'ListProviders', response end |
#list_webhooks ⇒ ListWebhooks
FUNCTION: get list registered webhooks
113 114 115 116 117 |
# File 'lib/compropago_sdk/service.rb', line 113 def list_webhooks response = EasyRequest::get(@client.deploy_uri+'webhooks/stores/', get_auth()) Factory::get_instance_of 'ListWebhooks', response end |
#place_order(order) ⇒ NewOrderInfo
FUNCTION: place order
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/compropago_sdk/service.rb', line 43 def place_order(order) unless order.is_a?(PlaceOrderInfo) raise 'Order object is not valid' end params = { order_id: order.order_id, order_name: order.order_name, order_price: order.order_price, customer_name: order.customer_name, customer_email: order.customer_email, payment_type: order.payment_type, currency: order.currency, expiration_time: order.expiration_time, image_url: order.image_url, app_client_name: order.app_client_name, app_client_version: order.app_client_version, } response = EasyRequest::post(@client.deploy_uri+'charges/', params, get_auth()) Factory::get_instance_of 'NewOrderInfo', response end |
#send_sms_instructions(number, order_id) ⇒ SmsInfo
FUNCTION: send sms of an order
71 72 73 74 75 76 77 |
# File 'lib/compropago_sdk/service.rb', line 71 def send_sms_instructions(number, order_id) params = {customer_phone: number} response = EasyRequest::post(@client.deploy_uri+'charges/'+order_id+'/sms/', params, get_auth()) Factory::get_instance_of 'SmsInfo', response end |
#update_webhook(webhook_id, new_url) ⇒ Webhook
FUNCTION: update registered webhook
94 95 96 97 98 99 100 |
# File 'lib/compropago_sdk/service.rb', line 94 def update_webhook(webhook_id, new_url) params = {url: new_url} response = EasyRequest::put(@client.deploy_uri+'webhooks/stores/'+webhook_id+'/', params, get_auth()) Factory::get_instance_of 'Webhook', response end |
#verify_order(order_id) ⇒ CpOrderInfo
FUNCTION: veridy order by unique_id
34 35 36 37 38 |
# File 'lib/compropago_sdk/service.rb', line 34 def verify_order(order_id) response = EasyRequest::get( @client.deploy_uri+'charges/'+order_id+'/', get_auth()) Factory::get_instance_of 'CpOrderInfo', response end |