diff --git a/.travis.yml b/.travis.yml index 7c9f958..279ffdb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: ruby rvm: - - 2.1.0 -before_install: gem install bundler -v 1.10.6 + - 2.6.6 +before_install: gem install bundler -v 1.17.2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c8ae10..870b0fb 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.0.0 + +- Added: API Pix endpoints + # 0.0.15 - Added: new endpoint (one step) diff --git a/README.md b/README.md index 44b09df..f477c40 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ $ gem install gerencianet ``` ## Tested with ``` -ruby 2.1.0 +ruby 2.6.6 ``` ## Basic usage @@ -37,9 +37,9 @@ ruby 2.1.0 require "gerencianet" options = { - client_id: "client_id", - client_secret: "client_secret", - sandbox: true + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + sandbox: CREDENTIALS::SANDBOX } gerencianet = Gerencianet.new(options) diff --git a/examples/certs/developmentCertificate.pem b/examples/certs/developmentCertificate.pem new file mode 100755 index 0000000..e69de29 diff --git a/examples/certs/productionCertificate.pem b/examples/certs/productionCertificate.pem new file mode 100755 index 0000000..e69de29 diff --git a/examples/credentials.rb b/examples/credentials.rb index 8f10506..be866f1 100644 --- a/examples/credentials.rb +++ b/examples/credentials.rb @@ -1,5 +1,7 @@ # example module CREDENTIALS - CLIENT_ID = "" - CLIENT_SECRET = "" + CLIENT_ID = "Client_Id" + CLIENT_SECRET = "Client_Secret" + PIX_CERT = "../../certs/developmentCertificate.pem" + SANDBOX = true end diff --git a/examples/cancel_carnet.rb b/examples/default/carnet/cancel_carnet.rb old mode 100644 new mode 100755 similarity index 77% rename from examples/cancel_carnet.rb rename to examples/default/carnet/cancel_carnet.rb index 0267f30..2b2884a --- a/examples/cancel_carnet.rb +++ b/examples/default/carnet/cancel_carnet.rb @@ -1,10 +1,10 @@ require "gerencianet" -require_relative "./credentials" +require_relative "../../credentials" options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/cancel_parcel.rb b/examples/default/carnet/cancel_parcel.rb similarity index 89% rename from examples/cancel_parcel.rb rename to examples/default/carnet/cancel_parcel.rb index 7425547..ab1a64d 100644 --- a/examples/cancel_parcel.rb +++ b/examples/default/carnet/cancel_parcel.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/create_carnet.rb b/examples/default/carnet/create_carnet.rb similarity index 91% rename from examples/create_carnet.rb rename to examples/default/carnet/create_carnet.rb index 99a762a..84722af 100644 --- a/examples/create_carnet.rb +++ b/examples/default/carnet/create_carnet.rb @@ -5,7 +5,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } tomorrow = Date.today + 1 @@ -20,7 +20,7 @@ customer: { name: "Gorbadoc Oldbuck", email: "oldbuck@gerencianet.com.br", - cpf: "04267484171", + cpf: "94271564656", birth: "1977-01-15", phone_number: "5144916523" }, diff --git a/examples/create_carnet_history.rb b/examples/default/carnet/create_carnet_history.rb similarity index 91% rename from examples/create_carnet_history.rb rename to examples/default/carnet/create_carnet_history.rb index 37028cf..cef2576 100644 --- a/examples/create_carnet_history.rb +++ b/examples/default/carnet/create_carnet_history.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/detail_carnet.rb b/examples/default/carnet/detail_carnet.rb similarity index 89% rename from examples/detail_carnet.rb rename to examples/default/carnet/detail_carnet.rb index f54c347..ebff0da 100644 --- a/examples/detail_carnet.rb +++ b/examples/default/carnet/detail_carnet.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/resend_carnet.rb b/examples/default/carnet/resend_carnet.rb similarity index 91% rename from examples/resend_carnet.rb rename to examples/default/carnet/resend_carnet.rb index 713aba4..c3e7bfa 100644 --- a/examples/resend_carnet.rb +++ b/examples/default/carnet/resend_carnet.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/resend_parcel.rb b/examples/default/carnet/resend_parcel.rb similarity index 91% rename from examples/resend_parcel.rb rename to examples/default/carnet/resend_parcel.rb index ba5db4d..39d8f75 100644 --- a/examples/resend_parcel.rb +++ b/examples/default/carnet/resend_parcel.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/settle_carnet_parcel.rb b/examples/default/carnet/settle_carnet_parcel.rb similarity index 85% rename from examples/settle_carnet_parcel.rb rename to examples/default/carnet/settle_carnet_parcel.rb index 0edea3c..44e6bed 100644 --- a/examples/settle_carnet_parcel.rb +++ b/examples/default/carnet/settle_carnet_parcel.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/update_carnet_metadata.rb b/examples/default/carnet/update_carnet_metadata.rb similarity index 91% rename from examples/update_carnet_metadata.rb rename to examples/default/carnet/update_carnet_metadata.rb index 5ff155b..b97269f 100644 --- a/examples/update_carnet_metadata.rb +++ b/examples/default/carnet/update_carnet_metadata.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/update_parcel.rb b/examples/default/carnet/update_parcel.rb similarity index 91% rename from examples/update_parcel.rb rename to examples/default/carnet/update_parcel.rb index d6903a8..92c573e 100644 --- a/examples/update_parcel.rb +++ b/examples/default/carnet/update_parcel.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/all_in_one.rb b/examples/default/charge/all_in_one.rb similarity index 94% rename from examples/all_in_one.rb rename to examples/default/charge/all_in_one.rb index 5ea6808..ed4bf24 100644 --- a/examples/all_in_one.rb +++ b/examples/default/charge/all_in_one.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } charge = { @@ -38,7 +38,7 @@ customer: { name: "Gorbadoc Oldbuck", email: "oldbuck@gerencianet.com.br", - cpf: "04267484171", + cpf: "94271564656", birth: "1977-01-15", phone_number: "5144916523" } diff --git a/examples/cancel_charge.rb b/examples/default/charge/cancel_charge.rb similarity index 89% rename from examples/cancel_charge.rb rename to examples/default/charge/cancel_charge.rb index c919fa9..8287591 100644 --- a/examples/cancel_charge.rb +++ b/examples/default/charge/cancel_charge.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/charge_link.rb b/examples/default/charge/charge_link.rb similarity index 93% rename from examples/charge_link.rb rename to examples/default/charge/charge_link.rb index 6b30b6e..cd5fbad 100644 --- a/examples/charge_link.rb +++ b/examples/default/charge/charge_link.rb @@ -5,7 +5,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } expireAt = Date.today + 3 diff --git a/examples/create_billet_payment.rb b/examples/default/charge/create_billet_payment.rb similarity index 90% rename from examples/create_billet_payment.rb rename to examples/default/charge/create_billet_payment.rb index a27e73c..a4c179a 100644 --- a/examples/create_billet_payment.rb +++ b/examples/default/charge/create_billet_payment.rb @@ -5,7 +5,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } tomorrow = Date.today + 1 @@ -21,7 +21,7 @@ customer: { name: "Gorbadoc Oldbuck", email: "oldbuck@gerencianet.com.br", - cpf: "04267484171", + cpf: "94271564656", birth: "1977-01-15", phone_number: "5144916523" } diff --git a/examples/create_card_payment.rb b/examples/default/charge/create_card_payment.rb similarity index 92% rename from examples/create_card_payment.rb rename to examples/default/charge/create_card_payment.rb index 7387074..36fb589 100644 --- a/examples/create_card_payment.rb +++ b/examples/default/charge/create_card_payment.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } body = { @@ -23,7 +23,7 @@ customer: { name: "Gorbadoc Oldbuck", email: "oldbuck@gerencianet.com.br", - cpf: "04267484171", + cpf: "94271564656", birth: "1977-01-15", phone_number: "5144916523" } diff --git a/examples/create_charge.rb b/examples/default/charge/create_charge.rb similarity index 92% rename from examples/create_charge.rb rename to examples/default/charge/create_charge.rb index 7aff078..d2e0ab5 100755 --- a/examples/create_charge.rb +++ b/examples/default/charge/create_charge.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } body = { diff --git a/examples/create_charge_balance_sheet.rb b/examples/default/charge/create_charge_balance_sheet.rb similarity index 93% rename from examples/create_charge_balance_sheet.rb rename to examples/default/charge/create_charge_balance_sheet.rb index 5acdbe8..8ed5537 100755 --- a/examples/create_charge_balance_sheet.rb +++ b/examples/default/charge/create_charge_balance_sheet.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/create_charge_history.rb b/examples/default/charge/create_charge_history.rb similarity index 91% rename from examples/create_charge_history.rb rename to examples/default/charge/create_charge_history.rb index 8866612..c279395 100644 --- a/examples/create_charge_history.rb +++ b/examples/default/charge/create_charge_history.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/create_charge_onestep.rb b/examples/default/charge/create_charge_onestep.rb similarity index 91% rename from examples/create_charge_onestep.rb rename to examples/default/charge/create_charge_onestep.rb index a809cc8..7b25785 100755 --- a/examples/create_charge_onestep.rb +++ b/examples/default/charge/create_charge_onestep.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } body = { @@ -23,7 +23,7 @@ customer: { name: "Gorbadoc Oldbuck", email: "oldbuck@gerencianet.com.br", - cpf: "04267484171", + cpf: "94271564656", birth: "1977-01-15", phone_number: "5144916523" } diff --git a/examples/create_charge_onestep_creditcard.rb b/examples/default/charge/create_charge_onestep_creditcard.rb similarity index 96% rename from examples/create_charge_onestep_creditcard.rb rename to examples/default/charge/create_charge_onestep_creditcard.rb index d156aa9..36cefc6 100755 --- a/examples/create_charge_onestep_creditcard.rb +++ b/examples/default/charge/create_charge_onestep_creditcard.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } body = { diff --git a/examples/detail_charge.rb b/examples/default/charge/detail_charge.rb similarity index 89% rename from examples/detail_charge.rb rename to examples/default/charge/detail_charge.rb index c5739c0..f12a5f3 100644 --- a/examples/detail_charge.rb +++ b/examples/default/charge/detail_charge.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/resend_billet.rb b/examples/default/charge/resend_billet.rb similarity index 91% rename from examples/resend_billet.rb rename to examples/default/charge/resend_billet.rb index 36dde91..3f902a9 100644 --- a/examples/resend_billet.rb +++ b/examples/default/charge/resend_billet.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/settle_charge.rb b/examples/default/charge/settle_charge.rb similarity index 85% rename from examples/settle_charge.rb rename to examples/default/charge/settle_charge.rb index 373df86..5730699 100644 --- a/examples/settle_charge.rb +++ b/examples/default/charge/settle_charge.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/update_billet.rb b/examples/default/charge/update_billet.rb similarity index 90% rename from examples/update_billet.rb rename to examples/default/charge/update_billet.rb index a9492df..0f9e4ef 100644 --- a/examples/update_billet.rb +++ b/examples/default/charge/update_billet.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/update_charge_link.rb b/examples/default/charge/update_charge_link.rb similarity index 93% rename from examples/update_charge_link.rb rename to examples/default/charge/update_charge_link.rb index 9a04625..94ebbea 100644 --- a/examples/update_charge_link.rb +++ b/examples/default/charge/update_charge_link.rb @@ -5,7 +5,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } expireAt = Date.today + 3 diff --git a/examples/update_charge_metadata.rb b/examples/default/charge/update_charge_metadata.rb similarity index 91% rename from examples/update_charge_metadata.rb rename to examples/default/charge/update_charge_metadata.rb index e9724c3..3ece3ef 100644 --- a/examples/update_charge_metadata.rb +++ b/examples/default/charge/update_charge_metadata.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/create_charge_onestep_billet_marketplace.rb b/examples/default/marketplace/create_charge_onestep_billet_marketplace.rb similarity index 89% rename from examples/create_charge_onestep_billet_marketplace.rb rename to examples/default/marketplace/create_charge_onestep_billet_marketplace.rb index 0c1e3f5..0de31bd 100755 --- a/examples/create_charge_onestep_billet_marketplace.rb +++ b/examples/default/marketplace/create_charge_onestep_billet_marketplace.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } body = { @@ -32,7 +32,7 @@ customer: { name: "Gorbadoc Oldbuck", email: "oldbuck@gerencianet.com.br", - cpf: "04267484171", + cpf: "94271564656", birth: "1977-01-15", phone_number: "5144916523" } diff --git a/examples/create_charge_onestep_creditcard_marketplace.rb b/examples/default/marketplace/create_charge_onestep_creditcard_marketplace.rb similarity index 93% rename from examples/create_charge_onestep_creditcard_marketplace.rb rename to examples/default/marketplace/create_charge_onestep_creditcard_marketplace.rb index 219d81d..2178107 100755 --- a/examples/create_charge_onestep_creditcard_marketplace.rb +++ b/examples/default/marketplace/create_charge_onestep_creditcard_marketplace.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } body = { diff --git a/examples/get_notification.rb b/examples/default/notification/get_notification.rb similarity index 90% rename from examples/get_notification.rb rename to examples/default/notification/get_notification.rb index 73ef5eb..b5b4ab2 100644 --- a/examples/get_notification.rb +++ b/examples/default/notification/get_notification.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/get_installments.rb b/examples/default/others/get_installments.rb similarity index 89% rename from examples/get_installments.rb rename to examples/default/others/get_installments.rb index d9c62ac..4176c5a 100644 --- a/examples/get_installments.rb +++ b/examples/default/others/get_installments.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/cancel_subscription.rb b/examples/default/subscriptions/cancel_subscription.rb similarity index 89% rename from examples/cancel_subscription.rb rename to examples/default/subscriptions/cancel_subscription.rb index fd2849f..0ef2bdd 100644 --- a/examples/cancel_subscription.rb +++ b/examples/default/subscriptions/cancel_subscription.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/create_plan.rb b/examples/default/subscriptions/create_plan.rb similarity index 90% rename from examples/create_plan.rb rename to examples/default/subscriptions/create_plan.rb index d3a618d..1924261 100644 --- a/examples/create_plan.rb +++ b/examples/default/subscriptions/create_plan.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } body = { diff --git a/examples/create_subscription.rb b/examples/default/subscriptions/create_subscription.rb similarity index 94% rename from examples/create_subscription.rb rename to examples/default/subscriptions/create_subscription.rb index 84cf647..f868e52 100644 --- a/examples/create_subscription.rb +++ b/examples/default/subscriptions/create_subscription.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } plan = { diff --git a/examples/create_subscription_history.rb b/examples/default/subscriptions/create_subscription_history.rb similarity index 91% rename from examples/create_subscription_history.rb rename to examples/default/subscriptions/create_subscription_history.rb index 269609b..d709c51 100644 --- a/examples/create_subscription_history.rb +++ b/examples/default/subscriptions/create_subscription_history.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/create_subscription_payment.rb b/examples/default/subscriptions/create_subscription_payment.rb similarity index 92% rename from examples/create_subscription_payment.rb rename to examples/default/subscriptions/create_subscription_payment.rb index 0c0198d..5017173 100644 --- a/examples/create_subscription_payment.rb +++ b/examples/default/subscriptions/create_subscription_payment.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { @@ -26,7 +26,7 @@ customer: { name: "Gorbadoc Oldbuck", email: "oldbuck@gerencianet.com.br", - cpf: "04267484171", + cpf: "94271564656", birth: "1977-01-15", phone_number: "5144916523" } diff --git a/examples/delete_plan.rb b/examples/default/subscriptions/delete_plan.rb similarity index 89% rename from examples/delete_plan.rb rename to examples/default/subscriptions/delete_plan.rb index 4af35e2..1f64b07 100644 --- a/examples/delete_plan.rb +++ b/examples/default/subscriptions/delete_plan.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/detail_subscription.rb b/examples/default/subscriptions/detail_subscription.rb similarity index 89% rename from examples/detail_subscription.rb rename to examples/default/subscriptions/detail_subscription.rb index b09a7b4..ef294bb 100644 --- a/examples/detail_subscription.rb +++ b/examples/default/subscriptions/detail_subscription.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/get_plans.rb b/examples/default/subscriptions/get_plans.rb similarity index 90% rename from examples/get_plans.rb rename to examples/default/subscriptions/get_plans.rb index 4d5797f..db3fb7f 100644 --- a/examples/get_plans.rb +++ b/examples/default/subscriptions/get_plans.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/update_plan.rb b/examples/default/subscriptions/update_plan.rb similarity index 90% rename from examples/update_plan.rb rename to examples/default/subscriptions/update_plan.rb index a0fd934..e307131 100644 --- a/examples/update_plan.rb +++ b/examples/default/subscriptions/update_plan.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/update_subscription_metadata.rb b/examples/default/subscriptions/update_subscription_metadata.rb similarity index 92% rename from examples/update_subscription_metadata.rb rename to examples/default/subscriptions/update_subscription_metadata.rb index 97aece1..429469c 100644 --- a/examples/update_subscription_metadata.rb +++ b/examples/default/subscriptions/update_subscription_metadata.rb @@ -4,7 +4,7 @@ options = { client_id: CREDENTIALS::CLIENT_ID, client_secret: CREDENTIALS::CLIENT_SECRET, - sandbox: true + sandbox: CREDENTIALS::SANDBOX } params = { diff --git a/examples/gn/account/pix_detail_balance.rb b/examples/gn/account/pix_detail_balance.rb new file mode 100755 index 0000000..40dd06f --- /dev/null +++ b/examples/gn/account/pix_detail_balance.rb @@ -0,0 +1,16 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_detail_balance() \ No newline at end of file diff --git a/examples/gn/account/pix_detail_settings.rb b/examples/gn/account/pix_detail_settings.rb new file mode 100755 index 0000000..6042896 --- /dev/null +++ b/examples/gn/account/pix_detail_settings.rb @@ -0,0 +1,17 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_detail_settings() + diff --git a/examples/gn/account/pix_update_settings.rb b/examples/gn/account/pix_update_settings.rb new file mode 100755 index 0000000..bc1b0a5 --- /dev/null +++ b/examples/gn/account/pix_update_settings.rb @@ -0,0 +1,33 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +body = { + pix: { + receberSemChave: true, + chaves: { + "sua_chave": { + recebimento: { + txidObrigatorio: true, + qrCodeEstatico: { + recusarTodos: false + } + } + } + } + } +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_update_settings(body: body) + diff --git a/examples/gn/key/pix_create_evp.rb b/examples/gn/key/pix_create_evp.rb new file mode 100755 index 0000000..b1e07dd --- /dev/null +++ b/examples/gn/key/pix_create_evp.rb @@ -0,0 +1,17 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_create_evp() + diff --git a/examples/gn/key/pix_delete_evp.rb b/examples/gn/key/pix_delete_evp.rb new file mode 100755 index 0000000..f318b4a --- /dev/null +++ b/examples/gn/key/pix_delete_evp.rb @@ -0,0 +1,20 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + chave: " " +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_delete_evp(params: params) diff --git a/examples/gn/key/pix_list_evp.rb b/examples/gn/key/pix_list_evp.rb new file mode 100755 index 0000000..bfe8a76 --- /dev/null +++ b/examples/gn/key/pix_list_evp.rb @@ -0,0 +1,16 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_list_evp() diff --git a/examples/pix/charge/pix_create_charge.rb b/examples/pix/charge/pix_create_charge.rb new file mode 100755 index 0000000..5a29e97 --- /dev/null +++ b/examples/pix/charge/pix_create_charge.rb @@ -0,0 +1,35 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + txid: " " +} + +body = { + calendario: { + expiracao: 3600 + }, + devedor: { + cpf: "12345678909", + nome: "Francisco da Silva" + }, + valor: { + original: "0.01" + }, + chave: "sua_chave", + solicitacaoPagador: "Cobrança dos serviços prestados." +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_create_charge(params: params, body: body) diff --git a/examples/pix/charge/pix_create_immediate_charge.rb b/examples/pix/charge/pix_create_immediate_charge.rb new file mode 100755 index 0000000..ffca950 --- /dev/null +++ b/examples/pix/charge/pix_create_immediate_charge.rb @@ -0,0 +1,31 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +body = { + calendario: { + expiracao: 3600 + }, + devedor: { + cpf: "12345678909", + nome: "Francisco da Silva" + }, + valor: { + original: "0.01" + }, + chave: "sua_chave", + solicitacaoPagador: "Cobrança dos serviços prestados." +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_create_immediate_charge(body: body) diff --git a/examples/pix/charge/pix_detail_charge.rb b/examples/pix/charge/pix_detail_charge.rb new file mode 100755 index 0000000..39b577a --- /dev/null +++ b/examples/pix/charge/pix_detail_charge.rb @@ -0,0 +1,21 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + txid: " " +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_detail_charge(params: params) + diff --git a/examples/pix/charge/pix_list_charges.rb b/examples/pix/charge/pix_list_charges.rb new file mode 100755 index 0000000..7240104 --- /dev/null +++ b/examples/pix/charge/pix_list_charges.rb @@ -0,0 +1,21 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + inicio: "2020-10-22T16:01:35Z", + fim: "2021-04-23T16:01:35Z" +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_list_charges(params: params) diff --git a/examples/pix/charge/pix_update_charge.rb b/examples/pix/charge/pix_update_charge.rb new file mode 100755 index 0000000..fc79e6a --- /dev/null +++ b/examples/pix/charge/pix_update_charge.rb @@ -0,0 +1,26 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + txid: " " +} + +body = { + valor: { + original: "5.00" + } +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_update_charge(params: params, body: body) diff --git a/examples/pix/location/pix_create_location.rb b/examples/pix/location/pix_create_location.rb new file mode 100755 index 0000000..ba94abf --- /dev/null +++ b/examples/pix/location/pix_create_location.rb @@ -0,0 +1,20 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +body = { + tipoCob: "cob" +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_create_location(body: body) diff --git a/examples/pix/location/pix_detail_location.rb b/examples/pix/location/pix_detail_location.rb new file mode 100755 index 0000000..e0c2451 --- /dev/null +++ b/examples/pix/location/pix_detail_location.rb @@ -0,0 +1,20 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + id: " " +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_detail_location(params: params) diff --git a/examples/pix/location/pix_generate_qrcode.rb b/examples/pix/location/pix_generate_qrcode.rb new file mode 100755 index 0000000..3e226e0 --- /dev/null +++ b/examples/pix/location/pix_generate_qrcode.rb @@ -0,0 +1,26 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + id: " " +} + +gerencianet = Gerencianet.new(options) +response = gerencianet.pix_generate_qrcode(params: params) +puts response['qrcode'] + +data = response['imagemQrcode'] +image_data = Base64.decode64(data['data:image/png;base64,'.length .. -1]) +new_file=File.new("./../../../imgQrcode/qrCodeImage.png", 'wb') #salva a imagem do qrcode na pasta imgQrcode no diretório raiz +new_file.write(image_data) \ No newline at end of file diff --git a/examples/pix/location/pix_list_location.rb b/examples/pix/location/pix_list_location.rb new file mode 100755 index 0000000..f5e17f6 --- /dev/null +++ b/examples/pix/location/pix_list_location.rb @@ -0,0 +1,21 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + inicio: "2020-10-22T16:01:35Z", + fim: "2021-04-23T16:01:35Z" +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_list_location(params: params) diff --git a/examples/pix/location/pix_unset_txid.rb b/examples/pix/location/pix_unset_txid.rb new file mode 100755 index 0000000..c837f28 --- /dev/null +++ b/examples/pix/location/pix_unset_txid.rb @@ -0,0 +1,21 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + id: " " +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_unset_txid(params: params) + diff --git a/examples/pix/pix/pix_detail.rb b/examples/pix/pix/pix_detail.rb new file mode 100755 index 0000000..d98a323 --- /dev/null +++ b/examples/pix/pix/pix_detail.rb @@ -0,0 +1,20 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + e2eId: " " +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_detail(params: params) diff --git a/examples/pix/pix/pix_detail_devolution.rb b/examples/pix/pix/pix_detail_devolution.rb new file mode 100755 index 0000000..290bbd5 --- /dev/null +++ b/examples/pix/pix/pix_detail_devolution.rb @@ -0,0 +1,22 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + e2eId: " ", + id: " " +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_detail_devolution(params: params) + diff --git a/examples/pix/pix/pix_devolution.rb b/examples/pix/pix/pix_devolution.rb new file mode 100755 index 0000000..23466d3 --- /dev/null +++ b/examples/pix/pix/pix_devolution.rb @@ -0,0 +1,27 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + e2eId: " ", + id: " " +} + +body = { + valor: "0.01" +} + + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_devolution(params: params, body: body) + diff --git a/examples/pix/pix/pix_list_received.rb b/examples/pix/pix/pix_list_received.rb new file mode 100755 index 0000000..fc574e6 --- /dev/null +++ b/examples/pix/pix/pix_list_received.rb @@ -0,0 +1,21 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + inicio: "2020-10-22T16:01:35Z", + fim: "2021-04-23T16:01:35Z" +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_list_received(params: params) diff --git a/examples/pix/pix/pix_send.rb b/examples/pix/pix/pix_send.rb new file mode 100755 index 0000000..5fafa46 --- /dev/null +++ b/examples/pix/pix/pix_send.rb @@ -0,0 +1,27 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +body = { + valor: "0.01", + pagador: { + chave: "sua_chave" + }, + favorecido: { + chave: "chave_favorecido" + } +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_send(body: body) + diff --git a/examples/pix/webhooks/pix_config_webhook.rb b/examples/pix/webhooks/pix_config_webhook.rb new file mode 100755 index 0000000..3f33b87 --- /dev/null +++ b/examples/pix/webhooks/pix_config_webhook.rb @@ -0,0 +1,28 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +#verificar o mtls + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX, + "x-skip-mtls-checking": "true" +} + + +params = { + chave: "sua_chave" +} + +body = { + webhookUrl: "https://exemplo-pix/webhook" +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_config_webhook(params: params, body: body) diff --git a/examples/pix/webhooks/pix_delete_webhook.rb b/examples/pix/webhooks/pix_delete_webhook.rb new file mode 100755 index 0000000..852fe9f --- /dev/null +++ b/examples/pix/webhooks/pix_delete_webhook.rb @@ -0,0 +1,22 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + chave: "sua_chave" +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_delete_webhook(params: params) + diff --git a/examples/pix/webhooks/pix_detail_webhook.rb b/examples/pix/webhooks/pix_detail_webhook.rb new file mode 100755 index 0000000..f710182 --- /dev/null +++ b/examples/pix/webhooks/pix_detail_webhook.rb @@ -0,0 +1,21 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + chave: "sua_chave" +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_detail_webhook(params: params) + diff --git a/examples/pix/webhooks/pix_list_webhook.rb b/examples/pix/webhooks/pix_list_webhook.rb new file mode 100755 index 0000000..a5e861c --- /dev/null +++ b/examples/pix/webhooks/pix_list_webhook.rb @@ -0,0 +1,22 @@ +require "gerencianet" +require_relative "../../credentials" + +require "uri" +require "net/http" +require "openssl" + +options = { + client_id: CREDENTIALS::CLIENT_ID, + client_secret: CREDENTIALS::CLIENT_SECRET, + pix_cert: CREDENTIALS::PIX_CERT, + sandbox: CREDENTIALS::SANDBOX +} + +params = { + inicio: "2020-10-22T16:01:35Z", + fim: "2021-06-25T16:01:35Z" +} + +gerencianet = Gerencianet.new(options) +puts gerencianet.pix_list_webhook(params: params) + diff --git a/lib/gerencianet/constants.rb b/lib/gerencianet/constants.rb index ea1cee8..d7c4292 100755 --- a/lib/gerencianet/constants.rb +++ b/lib/gerencianet/constants.rb @@ -2,159 +2,273 @@ module Gerencianet # Endpoints signatures module Constants URL = { - production: "https://api.gerencianet.com.br/v1", - sandbox: "https://sandbox.gerencianet.com.br/v1" + DEFAULT: { + production: "https://api.gerencianet.com.br/v1", + sandbox: "https://sandbox.gerencianet.com.br/v1" + }, + PIX: { + production: "https://api-pix.gerencianet.com.br", + sandbox: "https://api-pix-h.gerencianet.com.br" + } } ENDPOINTS = { - authorize: { - route: "/authorize", - method: "post" - }, - create_charge: { - route: "/charge", - method: "post" - }, - detail_charge: { - route: "/charge/:id", - method: "get" - }, - update_charge_metadata: { - route: "/charge/:id/metadata", - method: "put" - }, - update_billet: { - route: "/charge/:id/billet", - method: "put" - }, - pay_charge: { - route: "/charge/:id/pay", - method: "post" - }, - cancel_charge: { - route: "/charge/:id/cancel", - method: "put" - }, - create_carnet: { - route: "/carnet", - method: "post" - }, - detail_carnet: { - route: "/carnet/:id", - method: "get" - }, - update_parcel: { - route: "/carnet/:id/parcel/:parcel", - method: "put" - }, - update_carnet_metadata: { - route: "/carnet/:id/metadata", - method: "put" - }, - get_notification: { - route: "/notification/:token", - method: "get" - }, - get_plans: { - route: "/plans", - method: "get" - }, - create_plan: { - route: "/plan", - method: "post" - }, - delete_plan: { - route: "/plan/:id", - method: "delete" - }, - create_subscription: { - route: "/plan/:id/subscription", - method: "post" - }, - detail_subscription: { - route: "/subscription/:id", - method: "get" - }, - pay_subscription: { - route: "/subscription/:id/pay", - method: "post" - }, - cancel_subscription: { - route: "/subscription/:id/cancel", - method: "put" - }, - update_subscription_metadata: { - route: "/subscription/:id/metadata", - method: "put" - }, - get_installments: { - route: "/installments", - method: "get" - }, - resend_billet: { - route: "/charge/:id/billet/resend", - method: "post" - }, - create_charge_history: { - route: "/charge/:id/history", - method: "post" - }, - resend_carnet: { - route: "/carnet/:id/resend", - method: "post" - }, - resend_parcel: { - route: "/carnet/:id/parcel/:parcel/resend", - method: "post" - }, - create_carnet_history: { - route: "/carnet/:id/history", - method: "post" - }, - cancel_carnet: { - route: "/carnet/:id/cancel", - method: "put" - }, - cancel_parcel: { - route: "/carnet/:id/parcel/:parcel/cancel", - method: "put" - }, - link_charge: { - route: "/charge/:id/link", - method: "post" - }, - charge_link: { - route: "/charge/:id/link", - method: "post" - }, - update_charge_link: { - route: "/charge/:id/link", - method: "put" - }, - update_plan: { - route: "/plan/:id", - method: "put" - }, - create_subscription_history: { - route: "/subscription/:id/history", - method: "post" - }, - create_charge_balance_sheet: { - route: "/charge/:id/balance-sheet", - method: "post" - }, - create_charge_onestep: { - route: "/charge/one-step", - method: "post" - }, - settleCharge: { - route: '/charge/:id/settle', - method: 'put' - }, - settleCarnetParcel: { - route: '/carnet/:id/parcel/:parcel/settle', - method: 'put' - } + DEFAULT: { + authorize: { + route: "/authorize", + method: "post" + }, + create_charge: { + route: "/charge", + method: "post" + }, + detail_charge: { + route: "/charge/:id", + method: "get" + }, + update_charge_metadata: { + route: "/charge/:id/metadata", + method: "put" + }, + update_billet: { + route: "/charge/:id/billet", + method: "put" + }, + pay_charge: { + route: "/charge/:id/pay", + method: "post" + }, + cancel_charge: { + route: "/charge/:id/cancel", + method: "put" + }, + create_carnet: { + route: "/carnet", + method: "post" + }, + detail_carnet: { + route: "/carnet/:id", + method: "get" + }, + update_parcel: { + route: "/carnet/:id/parcel/:parcel", + method: "put" + }, + update_carnet_metadata: { + route: "/carnet/:id/metadata", + method: "put" + }, + get_notification: { + route: "/notification/:token", + method: "get" + }, + get_plans: { + route: "/plans", + method: "get" + }, + create_plan: { + route: "/plan", + method: "post" + }, + delete_plan: { + route: "/plan/:id", + method: "delete" + }, + create_subscription: { + route: "/plan/:id/subscription", + method: "post" + }, + detail_subscription: { + route: "/subscription/:id", + method: "get" + }, + pay_subscription: { + route: "/subscription/:id/pay", + method: "post" + }, + cancel_subscription: { + route: "/subscription/:id/cancel", + method: "put" + }, + update_subscription_metadata: { + route: "/subscription/:id/metadata", + method: "put" + }, + get_installments: { + route: "/installments", + method: "get" + }, + resend_billet: { + route: "/charge/:id/billet/resend", + method: "post" + }, + create_charge_history: { + route: "/charge/:id/history", + method: "post" + }, + resend_carnet: { + route: "/carnet/:id/resend", + method: "post" + }, + resend_parcel: { + route: "/carnet/:id/parcel/:parcel/resend", + method: "post" + }, + create_carnet_history: { + route: "/carnet/:id/history", + method: "post" + }, + cancel_carnet: { + route: "/carnet/:id/cancel", + method: "put" + }, + cancel_parcel: { + route: "/carnet/:id/parcel/:parcel/cancel", + method: "put" + }, + link_charge: { + route: "/charge/:id/link", + method: "post" + }, + charge_link: { + route: "/charge/:id/link", + method: "post" + }, + update_charge_link: { + route: "/charge/:id/link", + method: "put" + }, + update_plan: { + route: "/plan/:id", + method: "put" + }, + create_subscription_history: { + route: "/subscription/:id/history", + method: "post" + }, + create_charge_balance_sheet: { + route: "/charge/:id/balance-sheet", + method: "post" + }, + create_charge_onestep: { + route: "/charge/one-step", + method: "post" + }, + settle_charge: { + route: "/charge/:id/settle", + method: "put" + }, + settle_carnet_parcel: { + route: "/carnet/:id/parcel/:parcel/settle", + method: "put" + } + }, + PIX: { + authorize: { + route: "/oauth/token", + method: "post" + }, + pix_config_webhook: { + route: "/v2/webhook/:chave", + method: "put" + }, + pix_detail_webhook: { + route: "/v2/webhook/:chave", + method: "get" + }, + pix_list_webhook: { + route: "/v2/webhook", + method: "get" + }, + pix_delete_webhook: { + route: "/v2/webhook/:chave", + method: "delete" + }, + pix_create_charge: { + route: "/v2/cob/:txid", + method: "put" + }, + pix_create_immediate_charge: { + route: "/v2/cob", + method: "post" + }, + pix_detail_charge: { + route: "/v2/cob/:txid", + method: "get" + }, + pix_update_charge: { + route: "/v2/cob/:txid", + method: "patch" + }, + pix_list_charges: { + route: "/v2/cob", + method: "get" + }, + pix_generate_qrcode: { + route: "/v2/loc/:id/qrcode", + method: "get" + }, + pix_devolution: { + route: "/v2/pix/:e2eId/devolucao/:id", + method: "put" + }, + pix_detail_devolution: { + route: "/v2/pix/:e2eId/devolucao/:id", + method: "get" + }, + pix_send: { + route: "/v2/pix", + method: "post" + }, + pix_detail: { + route: "/v2/pix/:e2eId", + method: "get" + }, + pix_list_received: { + route: "/v2/pix", + method: "get" + }, + pix_create_location: { + route: "/v2/loc", + method: "post" + }, + pix_list_location: { + route: "/v2/loc", + method: "get" + }, + pix_detail_location: { + route: "/v2/loc/:id", + method: "get" + }, + pix_unset_txid: { + route: "/v2/loc/:id/txid", + method: "delete" + }, + pix_create_evp: { + route: "/v2/gn/evp", + method: "post" + }, + pix_list_evp: { + route: "/v2/gn/evp", + method: "get" + }, + pix_delete_evp: { + route: "/v2/gn/evp/:chave", + method: "delete" + }, + pix_detail_balance: { + route: "/v2/gn/saldo", + method: "get" + }, + pix_update_settings: { + route: "/v2/gn/config", + method: "put" + }, + pix_detail_settings: { + route: "/v2/gn/config", + method: "get" + } + } } end end diff --git a/lib/gerencianet/endpoints.rb b/lib/gerencianet/endpoints.rb index 5e7d1cb..976ceea 100755 --- a/lib/gerencianet/endpoints.rb +++ b/lib/gerencianet/endpoints.rb @@ -22,29 +22,39 @@ def initialize(options) @base_url = current_base_url create_methods + end private def create_methods - @endpoints.each do |key, settings| - self.class.send(:define_method, key) do |args = {}| - create(args[:params], args[:body], settings) + if (@options.has_key?(:pix_cert)) + @endpoints[:PIX].each do |key, settings| + self.class.send(:define_method, key) do |args = {}| + create(args[:params], args[:body], settings) + end + end + else + @endpoints[:DEFAULT].each do |key, settings| + self.class.send(:define_method, key) do |args = {}| + create(args[:params], args[:body], settings) + end end end end def create(params, body, settings) authenticate unless @token - response = make_request(params, body, settings) - if response.status.to_s == STATUS::UNAUTHORIZED authenticate response = make_request(params, body, settings) end - - respond(response) + if response.to_s.empty? + puts response.status.to_s + else + respond(response) + end end def make_request(params, body, settings) @@ -58,26 +68,64 @@ def make_request(params, body, settings) headers['partner-token'] = @options[:partner_token] end - HTTP + if @options[:"x-skip-mtls-checking"] + headers["x-skip-mtls-checking"] = @options[:"x-skip-mtls-checking"] + end + + if (@options.has_key?(:pix_cert)) + + HTTP .headers(headers) .auth("Bearer #{@token['access_token']}") .method(settings[:method]) - .call(url, json: body) + .call(url, json: body, ssl_context: OpenSSL::SSL::SSLContext.new.tap do |ctx| + ctx.set_params( + cert: OpenSSL::X509::Certificate.new(File.read(@options[:pix_cert])), + key: OpenSSL::PKey::RSA.new(File.read(@options[:pix_cert])) + ) + end) + + else + HTTP + .headers(headers) + .auth("Bearer #{@token['access_token']}") + .method(settings[:method]) + .call(url, json: body) + end + end def authenticate - url = get_url({}, @endpoints[:authorize][:route]) + if (@options.has_key?(:pix_cert)) + url = get_url({}, @endpoints[:PIX][:authorize][:route]) + else + url = get_url({}, @endpoints[:DEFAULT][:authorize][:route]) + end headers = { "accept" => "application/json", - "api-sdk" => "ruby-#{Gerencianet::VERSION}" + "api-sdk" => "ruby-#{Gerencianet::VERSION}" } - - response = - HTTP - .headers(headers) - .basic_auth(auth_headers) - .post(url, json: auth_body) - + + if (@options.has_key?(:pix_cert)) + + response = + HTTP + .headers(headers) + .basic_auth(auth_headers) + .post(url, json: auth_body, ssl_context: OpenSSL::SSL::SSLContext.new.tap do |ctx| + ctx.set_params( + cert: OpenSSL::X509::Certificate.new(File.read(@options[:pix_cert])), + key: OpenSSL::PKey::RSA.new(File.read(@options[:pix_cert])) + ) + end) + else + response = + HTTP + .headers(headers) + .basic_auth(auth_headers) + .post(url, json: auth_body) + end + if response.status.to_s == STATUS::UNAUTHORIZED fail "unable to authenticate" else @@ -90,6 +138,7 @@ def auth_headers user: @options[:client_id], pass: @options[:client_secret] } + end def auth_body @@ -116,7 +165,7 @@ def remove_placeholders(params, route) def full_url(params, route) mapped = map_params(params) - + if !mapped.empty? "#{@base_url}#{route}?#{mapped}" else @@ -131,7 +180,11 @@ def map_params(params) end def current_base_url - @options[:sandbox] ? @urls[:sandbox] : @urls[:production] + if (@options.has_key?(:pix_cert)) + @options[:sandbox] ? @urls[:PIX][:sandbox] : @urls[:PIX][:production] + else + @options[:sandbox] ? @urls[:DEFAULT][:sandbox] : @urls[:DEFAULT][:production] + end end def respond(response) diff --git a/lib/gerencianet/version.rb b/lib/gerencianet/version.rb index cb14590..05426bc 100755 --- a/lib/gerencianet/version.rb +++ b/lib/gerencianet/version.rb @@ -1,4 +1,4 @@ # :nodoc: module Gerencianet - VERSION = "0.0.15" + VERSION = "1.0.0" end