module Braintree
class WebhookTestingGateway # :nodoc:
def initialize(gateway)
@gateway = gateway
@config = gateway.config
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 signature_string, 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::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::DisbursementException
_disbursement_exception_sample_xml(id)
when Braintree::WebhookNotification::Kind::Disbursement
_disbursement_sample_xml(id)
else
_subscription_sample_xml(id)
end
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 _dispute_opened_sample_xml(id)
<<-XML
250.00
USD
2014-03-01
2014-03-21
open
fraud
#{id}
#{id}
250.00
XML
end
def _dispute_lost_sample_xml(id)
<<-XML
250.00
USD
2014-03-01
2014-03-21
lost
fraud
#{id}
#{id}
250.00
XML
end
def _dispute_won_sample_xml(id)
<<-XML
250.00
USD
2014-03-01
2014-03-21
won
fraud
#{id}
#{id}
250.00
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
end
end