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_settlement
49.99
XML
end
def _subscription_charged_unsuccessfully(id)
<<-XML
#{id}
#{id}
failed
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_reviewed_sample_xml(id)
<<-XML
my_id
decision
hey@girl.com
i reviewed this
2017-06-16T20:44:41Z
XML
end
def _transaction_settled_sample_xml(id)
<<-XML
#{id}
settled
sale
USD
100.00
ogaotkivejpfayqfeaimuktty
us_bank_account
123456789
1234
checking
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
Dan 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.00
USD
2014-03-01
2014-03-21
chargeback
under_review
fraud
#{id}
#{id}
100.00
2014-03-21
XML
end
def _old_dispute_opened_sample_xml(id)
<<-XML
100.00
USD
2014-03-01
2014-03-21
chargeback
open
fraud
#{id}
#{id}
100.00
2014-03-21
XML
end
def _old_dispute_lost_sample_xml(id)
<<-XML
100.00
USD
2014-03-01
2014-03-21
chargeback
lost
fraud
#{id}
#{id}
100.00
2014-03-21
XML
end
def _old_dispute_won_sample_xml(id)
<<-XML
100.00
USD
2014-03-01
2014-03-21
chargeback
won
fraud
#{id}
#{id}
100.00
2014-03-21
2014-03-22
XML
end
def _old_dispute_accepted_sample_xml(id)
<<-XML
100.00
USD
2014-03-01
2014-03-21
chargeback
accepted
fraud
#{id}
#{id}
100.00
2014-03-21
XML
end
def _old_dispute_auto_accepted_sample_xml(id)
<<-XML
100.00
USD
2014-03-01
2014-03-21
chargeback
auto_accepted
fraud
#{id}
#{id}
100.00
2014-03-21
XML
end
def _old_dispute_disputed_sample_xml(id)
<<-XML
100.00
USD
2014-03-01
2014-03-21
chargeback
disputed
fraud
#{id}
#{id}
100.00
2014-03-21
XML
end
def _old_dispute_expired_sample_xml(id)
<<-XML
100.00
USD
2014-03-01
2014-03-21
chargeback
expired
fraud
#{id}
#{id}
100.00
2014-03-21
XML
end
def _new_dispute_under_review_sample_xml(id)
<<-XML
#{id}
100.00
100.00
95.00
CASE-12345
2017-06-16T20:44:41Z
USD
chargeback
ytnlulaloidoqwvzxjrdqputg
fraud
2016-02-15
REF-9876
2016-02-22
under_review
2017-06-16T20:44:41Z
9qde5qgp
under_review
2017-06-16T20:44:41Z
#{id}
100.00
2017-06-21T20:44:41Z
Visa
2014-03-21
XML
end
def _new_dispute_opened_sample_xml(id)
<<-XML
#{id}
100.00
100.00
95.00
CASE-12345
2017-06-16T20:44:41Z
USD
chargeback
ytnlulaloidoqwvzxjrdqputg
fraud
2016-02-15
REF-9876
2016-02-22
open
2017-06-16T20:44:41Z
9qde5qgp
open
2017-06-16T20:44:41Z
#{id}
100.00
2017-06-21T20:44:41Z
Visa
2014-03-21
XML
end
def _new_dispute_lost_sample_xml(id)
<<-XML
#{id}
100.00
100.00
95.00
CASE-12345
2017-06-16T20:44:41Z
USD
chargeback
ytnlulaloidoqwvzxjrdqputg
fraud
2016-02-15
REF-9876
2016-02-22
lost
2017-06-21T20:44:41Z
9qde5qgp
open
2017-06-16T20:44:41Z
lost
2017-06-25T20:50:55Z
rxtngk9j5j93tsrq
2017-06-21T20:44:42Z
s3.amazonaws.com/foo.jpg
88cfb8dd
text evidence
2017-06-21T20:44:42Z
#{id}
100.00
2017-06-21T20:44:41Z
Visa
2014-03-21
XML
end
def _new_dispute_won_sample_xml(id)
<<-XML
#{id}
100.00
100.00
95.00
CASE-12345
2017-06-16T20:44:41Z
USD
chargeback
ytnlulaloidoqwvzxjrdqputg
fraud
2016-02-15
REF-9876
2016-02-22
won
2017-06-21T20:44:41Z
9qde5qgp
open
2017-06-16T20:44:41Z
won
2017-06-25T20:50:55Z
rxtngk9j5j93tsrq
2017-06-21T20:44:42Z
s3.amazonaws.com/foo.jpg
88cfb8dd
text evidence
2017-06-21T20:44:42Z
#{id}
100.00
2017-06-21T20:44:41Z
Visa
2014-03-21
2014-03-22
XML
end
def _new_dispute_accepted_sample_xml(id)
<<-XML
#{id}
100.00
100.00
95.00
CASE-12345
2017-06-16T20:44:41Z
USD
chargeback
ytnlulaloidoqwvzxjrdqputg
fraud
2016-02-15
REF-9876
2016-02-22
accepted
2017-06-16T20:44:41Z
9qde5qgp
open
2017-06-16T20:44:41Z
accepted
2017-06-25T20:50:55Z
#{id}
100.00
2017-06-21T20:44:41Z
Visa
2014-03-21
XML
end
def _new_dispute_auto_accepted_sample_xml(id)
<<-XML
#{id}
100.00
100.00
95.00
CASE-12345
2017-06-16T20:44:41Z
USD
chargeback
ytnlulaloidoqwvzxjrdqputg
fraud
2016-02-15
REF-9876
2016-02-22
auto_accepted
2017-06-16T20:44:41Z
9qde5qgp
open
2017-06-16T20:44:41Z
auto_accepted
2017-06-25T20:50:55Z
#{id}
100.00
2017-06-21T20:44:41Z
Visa
2014-03-21
XML
end
def _new_dispute_disputed_sample_xml(id)
<<-XML
#{id}
100.00
100.00
95.00
CASE-12345
2017-06-16T20:44:41Z
USD
chargeback
ytnlulaloidoqwvzxjrdqputg
fraud
2016-02-15
REF-9876
2016-02-22
disputed
2017-06-21T20:44:41Z
9qde5qgp
open
2017-06-16T20:44:41Z
disputed
2017-06-25T20:50:55Z
rxtngk9j5j93tsrq
2017-06-21T20:44:42Z
s3.amazonaws.com/foo.jpg
88cfb8dd
text evidence
2017-06-21T20:44:42Z
#{id}
100.00
2017-06-21T20:44:41Z
Visa
2014-03-21
XML
end
def _new_dispute_expired_sample_xml(id)
<<-XML
#{id}
100.00
100.00
95.00
CASE-12345
2017-06-16T20:44:41Z
USD
chargeback
ytnlulaloidoqwvzxjrdqputg
fraud
2016-02-15
REF-9876
2016-02-22
expired
2017-06-16T20:44:41Z
9qde5qgp
open
2017-06-16T20:44:41Z
expired
2017-06-25T20:50:55Z
#{id}
100.00
2017-06-21T20:44:41Z
Visa
2014-03-21
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
def _auth_status_transitioned_sample_xml(id)
<<-XML
#{id}
new_status
oauth_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
vczo7jqrpwrsi2px
cf0i8wgarszuy6hc
ee257d98-de40-47e8-96b3-a6954ea7a9a4
false
false
abc123z
- expiration-month
- expiration-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-id
2019-01-01T12:00:00Z
a-customer-id
true
name@email.com
cGF5bWVudG1ldGhvZF9jaDZieXNz
https://assets.braintreegateway.com/payment_method_logo/paypal.png?environment=test
#{id}
2019-01-02T12:00:00Z
a-payer-id
2019-01-02T12:00:00Z
XML
end
def _local_payment_completed_sample_xml(id)
<<-XML
PAY-XYZ123
ABCPAYER
ee257d98-de40-47e8-96b3-a6954ea7a9a4
#{id}
authorized
49.99
order4567
XML
end
def _local_payment_expired_sample_xml
<<-XML
PAY-XYZ123
cG5b=
XML
end
def _local_payment_funded_sample_xml(id)
<<-XML
PAY-XYZ123
cG5b=
#{id}
settled
49.99
order4567
XML
end
def _local_payment_reversed_sample_xml
<<-XML
PAY-XYZ123
cG5b=
XML
end
def _payment_method_customer_data_updated_sample_xml(id)
<<-XML
TOKEN-12345
#{_venmo_account_xml(id)}
2022-01-01T21:28:37Z
- username
venmo_username
John
Doe
1231231234
john.doe@paypal.com
XML
end
def _venmo_account_xml(id)
<<-XML
2018-10-11T21:28:37Z
2018-10-11T21:28:37Z
true
https://assets.braintreegateway.com/payment_method_logo/venmo.png?environment=test
#{id}
Venmo Account: venmojoe
venmojoe
456
venmo_customer_id
cGF5bWVudG1ldGhvZF92ZW5tb2FjY291bnQ
XML
end
def _refund_failed_sample_xml(id)
<<-XML
#{id}
100
1234560000001234
123
MasterCard
processor_declined
1
XML
end
end
end