module Braintree class WebhookTestingGateway # :nodoc: def initialize(gateway) @gateway = gateway @config = gateway.config @config.assert_has_access_token_or_keys end def sample_notification(kind, id) payload = Base64.encode64(_sample_xml(kind, id)) signature_string = "#{@config.public_key}|#{Braintree::Digest.hexdigest(@config.private_key, payload)}" return {:bt_signature => signature_string, :bt_payload => payload} end def _sample_xml(kind, data) <<-XML #{Time.now.utc.iso8601} #{kind} #{_subject_sample_xml(kind, data)} XML end def _subject_sample_xml(kind, id) case kind when Braintree::WebhookNotification::Kind::Check _check when Braintree::WebhookNotification::Kind::DisputeOpened _dispute_opened_sample_xml(id) when Braintree::WebhookNotification::Kind::DisputeLost _dispute_lost_sample_xml(id) when Braintree::WebhookNotification::Kind::DisputeWon _dispute_won_sample_xml(id) when Braintree::WebhookNotification::Kind::PartnerMerchantConnected _partner_merchant_connected_sample_xml(id) when Braintree::WebhookNotification::Kind::PartnerMerchantDisconnected _partner_merchant_disconnected_sample_xml(id) when Braintree::WebhookNotification::Kind::PartnerMerchantDeclined _partner_merchant_declined_sample_xml(id) when Braintree::WebhookNotification::Kind::SubMerchantAccountApproved _merchant_account_approved_sample_xml(id) when Braintree::WebhookNotification::Kind::SubMerchantAccountDeclined _merchant_account_declined_sample_xml(id) when Braintree::WebhookNotification::Kind::TransactionDisbursed _transaction_disbursed_sample_xml(id) when Braintree::WebhookNotification::Kind::TransactionSettled _transaction_settled_sample_xml(id) when Braintree::WebhookNotification::Kind::TransactionSettlementDeclined _transaction_settlement_declined_sample_xml(id) when Braintree::WebhookNotification::Kind::DisbursementException _disbursement_exception_sample_xml(id) when Braintree::WebhookNotification::Kind::Disbursement _disbursement_sample_xml(id) when Braintree::WebhookNotification::Kind::SubscriptionChargedSuccessfully _subscription_charged_successfully(id) when Braintree::WebhookNotification::Kind::AccountUpdaterDailyReport _account_updater_daily_report_sample_xml(id) else _subscription_sample_xml(id) end end def _check <<-XML true XML end def _subscription_charged_successfully(id) <<-XML #{id} submitted_for_settlement 49.99 XML end def _subscription_sample_xml(id) <<-XML #{id} XML end def _partner_merchant_connected_sample_xml(data) <<-XML public_id public_key private_key abc123 cse_key XML end def _partner_merchant_disconnected_sample_xml(data) <<-XML abc123 XML end def _partner_merchant_declined_sample_xml(data) <<-XML abc123 XML end def _merchant_account_approved_sample_xml(id) <<-XML #{id} master_ma_for_#{id} active active XML end def _merchant_account_declined_sample_xml(id) <<-XML Credit score is too low 82621 Credit score is too low base #{id} suspended master_ma_for_#{id} suspended XML end def _transaction_disbursed_sample_xml(id) <<-XML #{id} 100 2013-07-09 XML end def _transaction_settled_sample_xml(id) <<-XML #{id} settled sale USD 100.00 ogaotkivejpfayqfeaimuktty us_bank_account 123456789 1234 checking PayPal Checking - 1234 Dan Schulman XML end def _transaction_settlement_declined_sample_xml(id) <<-XML #{id} settlement_declined sale USD 100.00 ogaotkivejpfayqfeaimuktty us_bank_account 123456789 1234 checking PayPal Checking - 1234 Dan Schulman XML end def _dispute_opened_sample_xml(id) <<-XML 250.00 USD 2014-03-01 2014-03-21 chargeback open fraud #{id} #{id} 250.00 2014-03-21 XML end def _dispute_lost_sample_xml(id) <<-XML 250.00 USD 2014-03-01 2014-03-21 chargeback lost fraud #{id} #{id} 250.00 2014-03-21 XML end def _dispute_won_sample_xml(id) <<-XML 250.00 USD 2014-03-01 2014-03-21 chargeback won fraud #{id} #{id} 250.00 2014-03-21 2014-03-22 XML end def _disbursement_exception_sample_xml(id) <<-XML #{id} afv56j kj8hjk false false merchant_account_token USD false active 100.00 2014-02-10 bank_rejected update_funding_information XML end def _disbursement_sample_xml(id) <<-XML #{id} afv56j kj8hjk true false merchant_account_token USD false active 100.00 2014-02-10 XML end def _account_updater_daily_report_sample_xml(id) <<-XML 2016-01-14 link-to-csv-report XML end end end