diff --git a/lib/fat_zebra.rb b/lib/fat_zebra.rb index a4a4041..33d7311 100644 --- a/lib/fat_zebra.rb +++ b/lib/fat_zebra.rb @@ -42,7 +42,8 @@ require 'fat_zebra/web_hook' require 'fat_zebra/batch' -# Utilities/Mastercard +# Utilities +require 'fat_zebra/utilities/apple_pay/domain' require 'fat_zebra/utilities/mastercard/click_to_pay/registration' # Paypal API Resources diff --git a/lib/fat_zebra/utilities/apple_pay/domain.rb b/lib/fat_zebra/utilities/apple_pay/domain.rb new file mode 100644 index 0000000..f68cea1 --- /dev/null +++ b/lib/fat_zebra/utilities/apple_pay/domain.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module FatZebra + module Utilities + module ApplePay + class Domain < APIResource + + ENDPOINT_URL = '/v1.0/utilities/apple_pay/domains' + + class << self + + ## + # Register an Apple Pay (web) domain + # + # @return [FatZebra::Utilities::ApplePay::Domains] response + def register!(domain, params = {}) + response = request(:post, path(domain), params) + initialize_from(response) + end + + ## + # Check registration status of an Apple Pay (web) domain + # + # @return [FatZebra::Utilities::ApplePay::Domains] response + def find!(domain) + response = request(:get, path(domain)) + initialize_from(response) + end + + ## + # Delete an Apple Pay (web) domain + # + # @return [FatZebra::Utilities::ApplePay::Domains] response + def delete!(domain) + response = request(:delete, path(domain)) + initialize_from(response) + end + + private + + def path(domain) + "#{ENDPOINT_URL}/#{domain}" + end + end + end + end + end +end diff --git a/spec/cassettes/FatZebra_Utilities_ApplePay_Domain/_delete_/deletes_the_domain.yml b/spec/cassettes/FatZebra_Utilities_ApplePay_Domain/_delete_/deletes_the_domain.yml new file mode 100644 index 0000000..85bead3 --- /dev/null +++ b/spec/cassettes/FatZebra_Utilities_ApplePay_Domain/_delete_/deletes_the_domain.yml @@ -0,0 +1,52 @@ +--- +http_interactions: +- request: + method: delete + uri: https://gateway.sandbox.fatzebra.com.au/v1.0/utilities/apple_pay/domains/www.example99.com + body: + encoding: UTF-8 + string: '{"test":true}' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + Authorization: + - Basic VEVTVDpURVNU + response: + status: + code: 202 + message: Accepted + headers: + Date: + - Mon, 04 Mar 2024 01:10:33 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Status: + - 202 Accepted + Cache-Control: + - no-store + Vary: + - Accept + Pragma: + - no-cache + X-Request-Id: + - 3f319fea5d6aa95004cab8f5 + X-Runtime: + - '0.033681' + X-Backend: + - gateway + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + body: + encoding: UTF-8 + string: '{"successful":true,"response":{},"errors":[],"test":true}' + http_version: + recorded_at: Mon, 04 Mar 2024 01:10:33 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/cassettes/FatZebra_Utilities_ApplePay_Domain/_find_/fetches_the_domain.yml b/spec/cassettes/FatZebra_Utilities_ApplePay_Domain/_find_/fetches_the_domain.yml new file mode 100644 index 0000000..e6a2546 --- /dev/null +++ b/spec/cassettes/FatZebra_Utilities_ApplePay_Domain/_find_/fetches_the_domain.yml @@ -0,0 +1,86 @@ +--- +http_interactions: +- request: + method: get + uri: https://gateway.sandbox.fatzebra.com.au/v1.0/utilities/apple_pay/domains/www.example.com?test=true + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - application/json + User-Agent: + - Ruby + Host: + - gateway.sandbox.fatzebra.com.au + Authorization: + - Basic VEVTVDpURVNU + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 04 Mar 2024 01:10:33 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Status: + - 200 OK + Cache-Control: + - no-store + Vary: + - Accept + Pragma: + - no-cache + X-Request-Id: + - 5347a0df5e2ebe022d005a3a + X-Runtime: + - '0.030516' + X-Backend: + - gateway + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + Content-Security-Policy-Report-Only: + - 'child-src ''self'' blob: *.cardinalcommerce.com fatzebra.statuspage.io; connect-src + ''self'' *.mastercard.com *.forter.com *.pmnts-staging.io *.rollbar.com *.nr-data.net + *.cardinalcommerce.com fatzebra.statuspage.io *.googleapis.com *.google-analytics.com; + default-src ''self'' ''unsafe-eval'' ''unsafe-inline'' *.forter.com *.nr-data.net + blob: *.pmnts-sandbox.io *.rollbar.com fatzebra.statuspage.io *.iovation.com + data: *.googleapis.com *.gstatic.com *.newrelic.com *.bootstrapcdn.com www.google.com + pay.google.com *.google-analytics.com *.gravatar.com; font-src ''self'' cdnjs.cloudflare.com + data: *.gstatic.com *.bootstrapcdn.com *.aexp-static.com; form-action ''self'' + *.cardinalcommerce.com; frame-ancestors ''self''; frame-src ''self'' fatzebra.statuspage.io + *.americanexpress.com www.google.com pay.google.com *.masterpass.com *.visa.com + *.mastercard.com; img-src ''self'' *.visa.com data: *.googleapis.com *.gstatic.com + masterpass.com *.masterpass.com *.americanexpress.com *.google-analytics.com + *.gravatar.com; script-src ''self'' ''unsafe-eval'' ''unsafe-inline'' *.forter.com + *.nr-data.net *.pmnts-sandbox.io *.pmnts-staging.io *.rollbar.com fatzebra.statuspage.io + cdnjs.cloudflare.com *.iovation.com *.jquery.com *.newrelic.com *.googleapis.com + *.cardinalcommerce.com *.bootstrapcdn.com wasm-eval *.google-analytics.com + *.googletagmanager.com; script-src-attr ''unsafe-inline''; script-src-elem + ''self'' ''unsafe-inline'' *.forter.com *.nr-data.net *.pmnts-sandbox.io *.rollbar.com + fatzebra.statuspage.io *.iovation.com *.jquery.com cdnjs.cloudflare.com *.pmnts-staging.io + *.aexp-static.com *.newrelic.com *.googleapis.com *.americanexpress.com www.google.com + pay.google.com *.visa.com *.masterpass.com *.mastercard.com *.google-analytics.com + *.gstatic.com *.bootstrapcdn.com; style-src ''self'' ''unsafe-eval'' ''unsafe-inline'' + *.bootstrapcdn.com *.googleapis.com; style-src-attr ''unsafe-inline''; style-src-elem + ''unsafe-inline'' ''self'' *.googleapis.com cdnjs.cloudflare.com *.bootstrapcdn.com; + worker-src blob:; report-uri https://fatzebra.report-uri.com/r/d/csp/wizard' + Nel: + - '{"report_to":"default","max_age":31536000,"include_subdomains":true}' + Report-To: + - '{"group":"default","max_age":31536000,"endpoints":[{"url":"https://fatzebra.report-uri.com/a/d/g"}],"include_subdomains":true}' + body: + encoding: UTF-8 + string: '{"successful":true,"response":{"status":"Active","domain":"www.example.com","created_at":"2023-04-14T15:15:45+10:00","updated_at":"2023-04-14T05:15:47+00:00"},"errors":[],"test":true}' + http_version: + recorded_at: Mon, 04 Mar 2024 01:10:32 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/cassettes/FatZebra_Utilities_ApplePay_Domain/_register_/creates_the_domain.yml b/spec/cassettes/FatZebra_Utilities_ApplePay_Domain/_register_/creates_the_domain.yml new file mode 100644 index 0000000..9f6ee2c --- /dev/null +++ b/spec/cassettes/FatZebra_Utilities_ApplePay_Domain/_register_/creates_the_domain.yml @@ -0,0 +1,84 @@ +--- +http_interactions: +- request: + method: post + uri: https://gateway.sandbox.fatzebra.com.au/v1.0/utilities/apple_pay/domains/www.example99.com + body: + encoding: UTF-8 + string: '{"async":false,"test":true}' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - application/json + User-Agent: + - Ruby + Authorization: + - Basic VEVTVDpURVNU + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 04 Mar 2024 01:10:32 GMT + Content-Type: + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Status: + - 200 OK + Cache-Control: + - no-store + Vary: + - Accept + Pragma: + - no-cache + X-Request-Id: + - 298c3b404da4ccb5139e44ce + X-Runtime: + - '3.097708' + X-Backend: + - gateway + Strict-Transport-Security: + - max-age=31536000; includeSubDomains + Content-Security-Policy-Report-Only: + - 'child-src ''self'' blob: *.cardinalcommerce.com fatzebra.statuspage.io; connect-src + ''self'' *.mastercard.com *.forter.com *.pmnts-staging.io *.rollbar.com *.nr-data.net + *.cardinalcommerce.com fatzebra.statuspage.io *.googleapis.com *.google-analytics.com; + default-src ''self'' ''unsafe-eval'' ''unsafe-inline'' *.forter.com *.nr-data.net + blob: *.pmnts-sandbox.io *.rollbar.com fatzebra.statuspage.io *.iovation.com + data: *.googleapis.com *.gstatic.com *.newrelic.com *.bootstrapcdn.com www.google.com + pay.google.com *.google-analytics.com *.gravatar.com; font-src ''self'' cdnjs.cloudflare.com + data: *.gstatic.com *.bootstrapcdn.com *.aexp-static.com; form-action ''self'' + *.cardinalcommerce.com; frame-ancestors ''self''; frame-src ''self'' fatzebra.statuspage.io + *.americanexpress.com www.google.com pay.google.com *.masterpass.com *.visa.com + *.mastercard.com; img-src ''self'' *.visa.com data: *.googleapis.com *.gstatic.com + masterpass.com *.masterpass.com *.americanexpress.com *.google-analytics.com + *.gravatar.com; script-src ''self'' ''unsafe-eval'' ''unsafe-inline'' *.forter.com + *.nr-data.net *.pmnts-sandbox.io *.pmnts-staging.io *.rollbar.com fatzebra.statuspage.io + cdnjs.cloudflare.com *.iovation.com *.jquery.com *.newrelic.com *.googleapis.com + *.cardinalcommerce.com *.bootstrapcdn.com wasm-eval *.google-analytics.com + *.googletagmanager.com; script-src-attr ''unsafe-inline''; script-src-elem + ''self'' ''unsafe-inline'' *.forter.com *.nr-data.net *.pmnts-sandbox.io *.rollbar.com + fatzebra.statuspage.io *.iovation.com *.jquery.com cdnjs.cloudflare.com *.pmnts-staging.io + *.aexp-static.com *.newrelic.com *.googleapis.com *.americanexpress.com www.google.com + pay.google.com *.visa.com *.masterpass.com *.mastercard.com *.google-analytics.com + *.gstatic.com *.bootstrapcdn.com; style-src ''self'' ''unsafe-eval'' ''unsafe-inline'' + *.bootstrapcdn.com *.googleapis.com; style-src-attr ''unsafe-inline''; style-src-elem + ''unsafe-inline'' ''self'' *.googleapis.com cdnjs.cloudflare.com *.bootstrapcdn.com; + worker-src blob:; report-uri https://fatzebra.report-uri.com/r/d/csp/wizard' + Nel: + - '{"report_to":"default","max_age":31536000,"include_subdomains":true}' + Report-To: + - '{"group":"default","max_age":31536000,"endpoints":[{"url":"https://fatzebra.report-uri.com/a/d/g"}],"include_subdomains":true}' + body: + encoding: UTF-8 + string: '{"successful":true,"response":{"status":"Active","domain":"www.example99.com","created_at":"2024-03-04T12:10:29+11:00","updated_at":"2024-03-04T01:10:31+00:00"},"errors":[],"test":true}' + http_version: + recorded_at: Mon, 04 Mar 2024 01:10:32 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/lib/fat_zebra/utilities/apple_pay/domain_spec.rb b/spec/lib/fat_zebra/utilities/apple_pay/domain_spec.rb new file mode 100644 index 0000000..f8020d2 --- /dev/null +++ b/spec/lib/fat_zebra/utilities/apple_pay/domain_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe FatZebra::Utilities::ApplePay::Domain do + + describe '.register!', :vcr do + subject(:create) { FatZebra::Utilities::ApplePay::Domain.register!(domain, valid_payload) } + + let!(:domain) { "www.example99.com" } + let!(:valid_payload) {{ + async: false + }} + + it "creates the domain" do + expect(create).to be_accepted + expect(create.domain).to eq(domain) + expect(create.status).to eq("Active") + end + end + + describe '.find!', :vcr do + subject(:find) { FatZebra::Utilities::ApplePay::Domain.find!(domain) } + let!(:domain) { "www.example.com" } + + it "fetches the domain" do + expect(find).to be_accepted + expect(find.domain).to eq(domain) + expect(find.status).to eq("Active") + end + end + + describe '.delete!', :vcr do + subject(:delete) { FatZebra::Utilities::ApplePay::Domain.delete!(domain) } + let!(:domain) { "www.example99.com" } + + it "deletes the domain" do + expect(delete).to be_accepted + end + end +end