Module: ZipMoney::WebHook
- Defined in:
- lib/zipMoney/webhook.rb
Constant Summary collapse
- EVENT_AUTH_SUCCESS =
"authorise_succeeded"
- EVENT_AUTH_FAIL =
"authorise_failed"
- EVENT_AUTH_REVIEW =
"authorise_under_review"
- EVENT_AUTH_DECLINED =
"authorise_declined"
- EVENT_CANCEL_SUCCESS =
"cancel_succeeded"
- EVENT_CANCEL_FAIL =
"cancel_failed"
- EVENT_CAPTURE_SUCCESS =
"capture_succeeded"
- EVENT_CAPTURE_FAIL =
"capture_failed"
- EVENT_REFUND_SUCCESS =
"refund_succeeded"
- EVENT_REFUND_FAIL =
"refund_failed"
- EVENT_ORDER_CANCELLED =
"order_cancelled"
- EVENT_CHARGE_SUCCESS =
"charge_succeeded"
- EVENT_CHARGE_FAIL =
"charge_failed"
- EVENT_CONFIG_UPDATE =
"configuration_updated"
- TYPE_SUBSCRIPTION_CONFIRMATION =
"SubscriptionConfirmation"
- TYPE_NOTIFICATION =
"Notification"
Instance Attribute Summary collapse
-
#merchant_id ⇒ Object
Returns the value of attribute merchant_id.
-
#merchant_key ⇒ Object
Returns the value of attribute merchant_key.
Class Method Summary collapse
-
.process(request, &block) ⇒ Object
Process the webhook.
-
.process_notifications(request, &block) ⇒ Object
Process the webhook notifications.
-
.subscribe(url) ⇒ Object
Subscribes for the webhook notifications by calling the subscription url.
Instance Attribute Details
#merchant_id ⇒ Object
Returns the value of attribute merchant_id.
3 4 5 |
# File 'lib/zipMoney/webhook.rb', line 3 def merchant_id @merchant_id end |
#merchant_key ⇒ Object
Returns the value of attribute merchant_key.
3 4 5 |
# File 'lib/zipMoney/webhook.rb', line 3 def merchant_key @merchant_key end |
Class Method Details
.process(request, &block) ⇒ Object
Process the webhook
27 28 29 30 31 32 33 34 35 |
# File 'lib/zipMoney/webhook.rb', line 27 def self.process(request,&block) raise WebHookRequestError, "Payload emtpy" if request.nil? request = Util.json_parse(request) if request["Type"] == TYPE_SUBSCRIPTION_CONFIRMATION subscribe(request["SubscribeURL"]) elsif request["Type"] == TYPE_NOTIFICATION process_notifications(request, &block) end end |
.process_notifications(request, &block) ⇒ Object
Process the webhook notifications
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zipMoney/webhook.rb', line 41 def self.process_notifications(request, &block) raise ArgumentError, "Invalid params provided" if request["Message"].nil? = Util.json_parse(request["Message"]) Configuration.credentials_valid(["response"]["merchant_id"], ["response"]["merchant_key"]) raise ArgumentError, "Response empty" if ["response"].nil? if (block.arity > 0) block.call(['type'], ["response"]) end end |
.subscribe(url) ⇒ Object
Subscribes for the webhook notifications by calling the subscription url
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/zipMoney/webhook.rb', line 56 def self.subscribe(url) raise WebHookError, "Url emtpy" if url.nil? begin response = RestClient.get(url) rescue raise WebHookError, "Unable to reach the subscription url #{url}" if response.nil? end response.code == 200 || response.code == 201 end |