module Braintree
class WebhookTestingGateway
def initialize(gateway)
@gateway = gateway
@config = gateway.config
@config.assert_has_access_token_or_keys
end
def sample_notification(kind, id, source_merchant_id=nil)
payload = Base64.encode64(_sample_xml(kind, id, source_merchant_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, source_merchant_id=nil)
unless source_merchant_id.nil?
source_merchant_xml = "#{source_merchant_id}"
end
<<-XML
#{Time.now.utc.iso8601}#{kind}
#{source_merchant_xml}
#{_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::DisputeAccepted
_dispute_accepted_sample_xml(id)
when Braintree::WebhookNotification::Kind::DisputeAutoAccepted
_dispute_auto_accepted_sample_xml(id)
when Braintree::WebhookNotification::Kind::DisputeDisputed
_dispute_disputed_sample_xml(id)
when Braintree::WebhookNotification::Kind::DisputeExpired
_dispute_expired_sample_xml(id)
when Braintree::WebhookNotification::Kind::DisputeLost
_dispute_lost_sample_xml(id)
when Braintree::WebhookNotification::Kind::DisputeOpened
_dispute_opened_sample_xml(id)
when Braintree::WebhookNotification::Kind::DisputeUnderReview
_dispute_under_review_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::OAuthAccessRevoked
_oauth_access_revoked_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::TransactionReviewed
_transaction_reviewed_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::SubscriptionBillingSkipped
_subscription_billing_skipped(id)
when Braintree::WebhookNotification::Kind::SubscriptionChargedSuccessfully
_subscription_charged_successfully(id)
when Braintree::WebhookNotification::Kind::SubscriptionChargedUnsuccessfully
_subscription_charged_unsuccessfully(id)
when Braintree::WebhookNotification::Kind::AccountUpdaterDailyReport
_account_updater_daily_report_sample_xml(id)
when Braintree::WebhookNotification::Kind::ConnectedMerchantStatusTransitioned
_auth_status_transitioned_sample_xml(id)
when Braintree::WebhookNotification::Kind::ConnectedMerchantPayPalStatusChanged
_auth_paypal_status_changed_sample_xml(id)
when Braintree::WebhookNotification::Kind::GrantorUpdatedGrantedPaymentMethod
_granted_payment_instrument_update_sample_xml(id)
when Braintree::WebhookNotification::Kind::RecipientUpdatedGrantedPaymentMethod
_granted_payment_instrument_update_sample_xml(id)
when Braintree::WebhookNotification::Kind::GrantedPaymentMethodRevoked
_granted_payment_method_revoked_xml(id)
when Braintree::WebhookNotification::Kind::PaymentMethodRevokedByCustomer
_payment_method_revoked_by_customer_sample_xml(id)
when Braintree::WebhookNotification::Kind::LocalPaymentCompleted
_local_payment_completed_sample_xml(id)
when Braintree::WebhookNotification::Kind::LocalPaymentExpired
_local_payment_expired_sample_xml
when Braintree::WebhookNotification::Kind::LocalPaymentFunded
_local_payment_funded_sample_xml(id)
when Braintree::WebhookNotification::Kind::LocalPaymentReversed
_local_payment_reversed_sample_xml
when Braintree::WebhookNotification::Kind::PaymentMethodCustomerDataUpdated
_payment_method_customer_data_updated_sample_xml(id)
when Braintree::WebhookNotification::Kind::RefundFailed
_refund_failed_sample_xml(id)
else
_subscription_sample_xml(id)
end
end
def _check
<<-XML
true
XML
end
def _subscription_billing_skipped(id)
<<-XML
#{id}
XML
end
def _subscription_charged_successfully(id)
<<-XML
#{id}#{id}submitted_for_settlement49.99
XML
end
def _subscription_charged_unsuccessfully(id)
<<-XML
#{id}#{id}failed49.99
XML
end
def _subscription_sample_xml(id)
<<-XML
#{id}
XML
end
def _partner_merchant_connected_sample_xml(data)
<<-XML
public_idpublic_keyprivate_keyabc123cse_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}activeactive
XML
end
def _merchant_account_declined_sample_xml(id)
<<-XML
Credit score is too low82621Credit score is too lowbase#{id}suspendedmaster_ma_for_#{id}suspended
XML
end
def _transaction_disbursed_sample_xml(id)
<<-XML
#{id}1002013-07-09
XML
end
def _transaction_reviewed_sample_xml(id)
<<-XML
my_iddecisionhey@girl.comi reviewed this2017-06-16T20:44:41Z
XML
end
def _transaction_settled_sample_xml(id)
<<-XML
#{id}settledsaleUSD100.00ogaotkivejpfayqfeaimukttyus_bank_account1234567891234checkingDan Schulman
XML
end
def _transaction_settlement_declined_sample_xml(id)
<<-XML
#{id}settlement_declinedsaleUSD100.00ogaotkivejpfayqfeaimukttyus_bank_account1234567891234checkingDan Schulman
XML
end
def _dispute_under_review_sample_xml(id)
if id == "legacy_dispute_id"
_old_dispute_under_review_sample_xml(id)
else
_new_dispute_under_review_sample_xml(id)
end
end
def _dispute_opened_sample_xml(id)
if id == "legacy_dispute_id"
_old_dispute_opened_sample_xml(id)
else
_new_dispute_opened_sample_xml(id)
end
end
def _dispute_lost_sample_xml(id)
if id == "legacy_dispute_id"
_old_dispute_lost_sample_xml(id)
else
_new_dispute_lost_sample_xml(id)
end
end
def _dispute_won_sample_xml(id)
if id == "legacy_dispute_id"
_old_dispute_won_sample_xml(id)
else
_new_dispute_won_sample_xml(id)
end
end
def _dispute_accepted_sample_xml(id)
if id == "legacy_dispute_id"
_old_dispute_accepted_sample_xml(id)
else
_new_dispute_accepted_sample_xml(id)
end
end
def _dispute_auto_accepted_sample_xml(id)
if id == "legacy_dispute_id"
_old_dispute_auto_accepted_sample_xml(id)
else
_new_dispute_auto_accepted_sample_xml(id)
end
end
def _dispute_disputed_sample_xml(id)
if id == "legacy_dispute_id"
_old_dispute_disputed_sample_xml(id)
else
_new_dispute_disputed_sample_xml(id)
end
end
def _dispute_expired_sample_xml(id)
if id == "legacy_dispute_id"
_old_dispute_expired_sample_xml(id)
else
_new_dispute_expired_sample_xml(id)
end
end
def _old_dispute_under_review_sample_xml(id)
<<-XML
100.00USD2014-03-012014-03-21chargebackunder_reviewfraud#{id}#{id}100.002014-03-21
XML
end
def _old_dispute_opened_sample_xml(id)
<<-XML
100.00USD2014-03-012014-03-21chargebackopenfraud#{id}#{id}100.002014-03-21
XML
end
def _old_dispute_lost_sample_xml(id)
<<-XML
100.00USD2014-03-012014-03-21chargebacklostfraud#{id}#{id}100.002014-03-21
XML
end
def _old_dispute_won_sample_xml(id)
<<-XML
100.00USD2014-03-012014-03-21chargebackwonfraud#{id}#{id}100.002014-03-212014-03-22
XML
end
def _old_dispute_accepted_sample_xml(id)
<<-XML
100.00USD2014-03-012014-03-21chargebackacceptedfraud#{id}#{id}100.002014-03-21
XML
end
def _old_dispute_auto_accepted_sample_xml(id)
<<-XML
100.00USD2014-03-012014-03-21chargebackauto_acceptedfraud#{id}#{id}100.002014-03-21
XML
end
def _old_dispute_disputed_sample_xml(id)
<<-XML
100.00USD2014-03-012014-03-21chargebackdisputedfraud#{id}#{id}100.002014-03-21
XML
end
def _old_dispute_expired_sample_xml(id)
<<-XML
100.00USD2014-03-012014-03-21chargebackexpiredfraud#{id}#{id}100.002014-03-21
XML
end
def _new_dispute_under_review_sample_xml(id)
<<-XML
#{id}100.00100.0095.00CASE-123452017-06-16T20:44:41ZUSDchargebackytnlulaloidoqwvzxjrdqputgfraud2016-02-15REF-98762016-02-22under_review2017-06-16T20:44:41Z9qde5qgpunder_review2017-06-16T20:44:41Z#{id}100.002017-06-21T20:44:41ZVisa2014-03-21
XML
end
def _new_dispute_opened_sample_xml(id)
<<-XML
#{id}100.00100.0095.00CASE-123452017-06-16T20:44:41ZUSDchargebackytnlulaloidoqwvzxjrdqputgfraud2016-02-15REF-98762016-02-22open2017-06-16T20:44:41Z9qde5qgpopen2017-06-16T20:44:41Z#{id}100.002017-06-21T20:44:41ZVisa2014-03-21
XML
end
def _new_dispute_lost_sample_xml(id)
<<-XML
#{id}100.00100.0095.00CASE-123452017-06-16T20:44:41ZUSDchargebackytnlulaloidoqwvzxjrdqputgfraud2016-02-15REF-98762016-02-22lost2017-06-21T20:44:41Z9qde5qgpopen2017-06-16T20:44:41Zlost2017-06-25T20:50:55Zrxtngk9j5j93tsrq2017-06-21T20:44:42Zs3.amazonaws.com/foo.jpg88cfb8ddtext evidence2017-06-21T20:44:42Z#{id}100.002017-06-21T20:44:41ZVisa2014-03-21
XML
end
def _new_dispute_won_sample_xml(id)
<<-XML
#{id}100.00100.0095.00CASE-123452017-06-16T20:44:41ZUSDchargebackytnlulaloidoqwvzxjrdqputgfraud2016-02-15REF-98762016-02-22won2017-06-21T20:44:41Z9qde5qgpopen2017-06-16T20:44:41Zwon2017-06-25T20:50:55Zrxtngk9j5j93tsrq2017-06-21T20:44:42Zs3.amazonaws.com/foo.jpg88cfb8ddtext evidence2017-06-21T20:44:42Z#{id}100.002017-06-21T20:44:41ZVisa2014-03-212014-03-22
XML
end
def _new_dispute_accepted_sample_xml(id)
<<-XML
#{id}100.00100.0095.00CASE-123452017-06-16T20:44:41ZUSDchargebackytnlulaloidoqwvzxjrdqputgfraud2016-02-15REF-98762016-02-22accepted2017-06-16T20:44:41Z9qde5qgpopen2017-06-16T20:44:41Zaccepted2017-06-25T20:50:55Z#{id}100.002017-06-21T20:44:41ZVisa2014-03-21
XML
end
def _new_dispute_auto_accepted_sample_xml(id)
<<-XML
#{id}100.00100.0095.00CASE-123452017-06-16T20:44:41ZUSDchargebackytnlulaloidoqwvzxjrdqputgfraud2016-02-15REF-98762016-02-22auto_accepted2017-06-16T20:44:41Z9qde5qgpopen2017-06-16T20:44:41Zauto_accepted2017-06-25T20:50:55Z#{id}100.002017-06-21T20:44:41ZVisa2014-03-21
XML
end
def _new_dispute_disputed_sample_xml(id)
<<-XML
#{id}100.00100.0095.00CASE-123452017-06-16T20:44:41ZUSDchargebackytnlulaloidoqwvzxjrdqputgfraud2016-02-15REF-98762016-02-22disputed2017-06-21T20:44:41Z9qde5qgpopen2017-06-16T20:44:41Zdisputed2017-06-25T20:50:55Zrxtngk9j5j93tsrq2017-06-21T20:44:42Zs3.amazonaws.com/foo.jpg88cfb8ddtext evidence2017-06-21T20:44:42Z#{id}100.002017-06-21T20:44:41ZVisa2014-03-21
XML
end
def _new_dispute_expired_sample_xml(id)
<<-XML
#{id}100.00100.0095.00CASE-123452017-06-16T20:44:41ZUSDchargebackytnlulaloidoqwvzxjrdqputgfraud2016-02-15REF-98762016-02-22expired2017-06-16T20:44:41Z9qde5qgpopen2017-06-16T20:44:41Zexpired2017-06-25T20:50:55Z#{id}100.002017-06-21T20:44:41ZVisa2014-03-21
XML
end
def _disbursement_exception_sample_xml(id)
<<-XML
#{id}afv56jkj8hjkfalsefalsemerchant_account_tokenUSDfalseactive100.002014-02-10bank_rejectedupdate_funding_information
XML
end
def _disbursement_sample_xml(id)
<<-XML
#{id}afv56jkj8hjktruefalsemerchant_account_tokenUSDfalseactive100.002014-02-10
XML
end
def _account_updater_daily_report_sample_xml(id)
<<-XML
2016-01-14link-to-csv-report
XML
end
def _auth_status_transitioned_sample_xml(id)
<<-XML
#{id}new_statusoauth_application_client_id
XML
end
def _auth_paypal_status_changed_sample_xml(id)
<<-XML
oauth_application_client_id#{id}link
XML
end
def _oauth_access_revoked_sample_xml(id)
<<-XML
#{id}oauth_application_client_id
XML
end
def _granted_payment_instrument_update_sample_xml(id)
<<-XML
vczo7jqrpwrsi2pxcf0i8wgarszuy6hcee257d98-de40-47e8-96b3-a6954ea7a9a4falsefalseabc123zexpiration-monthexpiration-year
XML
end
def _granted_payment_method_revoked_xml(id)
_venmo_account_xml(id)
end
def _payment_method_revoked_by_customer_sample_xml(id)
<<-XML
a-billing-agreement-id2019-01-01T12:00:00Za-customer-idtruename@email.comcGF5bWVudG1ldGhvZF9jaDZieXNzhttps://assets.braintreegateway.com/payment_method_logo/paypal.png?environment=test#{id}2019-01-02T12:00:00Za-payer-id2019-01-02T12:00:00Z
XML
end
def _local_payment_completed_sample_xml(id)
if id == "blik_one_click_id"
_blik_one_click_local_payment_completed_sample_xml(id)
else
_default_local_payment_completed_sample_xml(id)
end
end
def _default_local_payment_completed_sample_xml(id)
<<-XML
BIC1234ABCPAYERPAYERNAMEPAY-XYZ123ee257d98-de40-47e8-96b3-a6954ea7a9a4#{id}authorized49.99order4567
XML
end
def _blik_one_click_local_payment_completed_sample_xml(id)
<<-XML
BICalias-key-11234ABCPAYERPAYERNAMEPAY-XYZ123ee257d98-de40-47e8-96b3-a6954ea7a9a4#{id}authorized49.99order4567
XML
end
def _local_payment_expired_sample_xml
<<-XML
PAY-XYZ123cG5b=
XML
end
def _local_payment_funded_sample_xml(id)
<<-XML
PAY-XYZ123cG5b=#{id}settled49.99order4567
XML
end
def _local_payment_reversed_sample_xml
<<-XML
PAY-XYZ123cG5b=
XML
end
def _payment_method_customer_data_updated_sample_xml(id)
<<-XML
TOKEN-12345
#{_venmo_account_xml(id)}
2022-01-01T21:28:37Zusernamevenmo_usernameJohnDoe1231231234john.doe@paypal.com
XML
end
def _venmo_account_xml(id)
<<-XML
2018-10-11T21:28:37Z2018-10-11T21:28:37Ztruehttps://assets.braintreegateway.com/payment_method_logo/venmo.png?environment=test#{id}Venmo Account: venmojoevenmojoe456venmo_customer_idcGF5bWVudG1ldGhvZF92ZW5tb2FjY291bnQ
XML
end
def _refund_failed_sample_xml(id)
<<-XML
#{id}1001234560000001234123MasterCardprocessor_declined1
XML
end
end
end