config = $gateway->config;
$this->config->assertHasAccessTokenOrKeys();
}
public function sampleNotification($kind, $id, $sourceMerchantId = null)
{
$xml = self::_sampleXml($kind, $id, $sourceMerchantId);
$payload = base64_encode($xml) . "\n";
$signature = $this->config->getPublicKey() . "|" . Digest::hexDigestSha1($this->config->getPrivateKey(), $payload);
return [
'bt_signature' => $signature,
'bt_payload' => $payload
];
}
private static function _sampleXml($kind, $id, $sourceMerchantId)
{
switch ($kind) {
case WebhookNotification::SUB_MERCHANT_ACCOUNT_APPROVED:
$subjectXml = self::_merchantAccountApprovedSampleXml($id);
break;
case WebhookNotification::SUB_MERCHANT_ACCOUNT_DECLINED:
$subjectXml = self::_merchantAccountDeclinedSampleXml($id);
break;
case WebhookNotification::TRANSACTION_DISBURSED:
$subjectXml = self::_transactionDisbursedSampleXml($id);
break;
case WebhookNotification::TRANSACTION_SETTLED:
$subjectXml = self::_transactionSettledSampleXml($id);
break;
case WebhookNotification::TRANSACTION_SETTLEMENT_DECLINED:
$subjectXml = self::_transactionSettlementDeclinedSampleXml($id);
break;
case WebhookNotification::DISBURSEMENT_EXCEPTION:
$subjectXml = self::_disbursementExceptionSampleXml($id);
break;
case WebhookNotification::DISBURSEMENT:
$subjectXml = self::_disbursementSampleXml($id);
break;
case WebhookNotification::PARTNER_MERCHANT_CONNECTED:
$subjectXml = self::_partnerMerchantConnectedSampleXml($id);
break;
case WebhookNotification::PARTNER_MERCHANT_DISCONNECTED:
$subjectXml = self::_partnerMerchantDisconnectedSampleXml($id);
break;
case WebhookNotification::PARTNER_MERCHANT_DECLINED:
$subjectXml = self::_partnerMerchantDeclinedSampleXml($id);
break;
case WebhookNotification::OAUTH_ACCESS_REVOKED:
$subjectXml = self::_oauthAccessRevocationSampleXml($id);
break;
case WebhookNotification::CONNECTED_MERCHANT_STATUS_TRANSITIONED:
$subjectXml = self::_connectedMerchantStatusTransitionedSampleXml($id);
break;
case WebhookNotification::CONNECTED_MERCHANT_PAYPAL_STATUS_CHANGED:
$subjectXml = self::_connectedMerchantPayPalStatusChangedSampleXml($id);
break;
case WebhookNotification::DISPUTE_OPENED:
$subjectXml = self::_disputeOpenedSampleXml($id);
break;
case WebhookNotification::DISPUTE_LOST:
$subjectXml = self::_disputeLostSampleXml($id);
break;
case WebhookNotification::DISPUTE_WON:
$subjectXml = self::_disputeWonSampleXml($id);
break;
case WebhookNotification::SUBSCRIPTION_CHARGED_SUCCESSFULLY:
$subjectXml = self::_subscriptionChargedSuccessfullySampleXml($id);
break;
case WebhookNotification::SUBSCRIPTION_CHARGED_UNSUCCESSFULLY:
$subjectXml = self::_subscriptionChargedUnsuccessfullySampleXml($id);
break;
case WebhookNotification::CHECK:
$subjectXml = self::_checkSampleXml();
break;
case WebhookNotification::ACCOUNT_UPDATER_DAILY_REPORT:
$subjectXml = self::_accountUpdaterDailyReportSampleXml($id);
break;
case WebhookNotification::IDEAL_PAYMENT_COMPLETE:
$subjectXml = self::_idealPaymentCompleteSampleXml($id);
break;
case WebhookNotification::IDEAL_PAYMENT_FAILED:
$subjectXml = self::_idealPaymentFailedSampleXml($id);
break;
case WebhookNotification::GRANTED_PAYMENT_INSTRUMENT_UPDATE:
$subjectXml = self::_grantedPaymentInstrumentUpdateSampleXml();
break;
default:
$subjectXml = self::_subscriptionSampleXml($id);
break;
}
$timestamp = self::_timestamp();
$sourceMerchantIdXml = '';
if (!is_null($sourceMerchantId)) {
$sourceMerchantIdXml = "{$sourceMerchantId}";
}
return "
{$timestamp}
{$kind}
{$sourceMerchantIdXml}
{$subjectXml}
";
}
private static function _merchantAccountApprovedSampleXml($id)
{
return "
{$id}
master_ma_for_{$id}
active
active
";
}
private static function _merchantAccountDeclinedSampleXml($id)
{
return "
Credit score is too low
82621
Credit score is too low
base
{$id}
suspended
master_ma_for_{$id}
suspended
";
}
private static function _transactionDisbursedSampleXml($id)
{
return "
${id}
100
2013-07-09
";
}
private static function _transactionSettledSampleXml($id)
{
return "
${id}
settled
sale
USD
100.00
ogaotkivejpfayqfeaimuktty
us_bank_account
123456789
1234
checking
Dan Schulman
";
}
private static function _transactionSettlementDeclinedSampleXml($id)
{
return "
${id}
settlement_declined
sale
USD
100.00
ogaotkivejpfayqfeaimuktty
us_bank_account
123456789
1234
checking
Dan Schulman
";
}
private static function _disbursementExceptionSampleXml($id)
{
return "
${id}
- asdfg
- qwert
false
false
merchant_account_token
USD
false
active
100.00
2014-02-10
bank_rejected
update_funding_information
";
}
private static function _disbursementSampleXml($id)
{
return "
${id}
- asdfg
- qwert
true
false
merchant_account_token
USD
false
active
100.00
2014-02-10
";
}
private static function _disputeOpenedSampleXml($id)
{
return "
250.00
250.0
245.00
USD
2014-03-01
2014-03-21
chargeback
open
fraud
${id}
${id}
250.00
2014-03-21
";
}
private static function _disputeLostSampleXml($id)
{
return "
250.00
250.0
245.00
USD
2014-03-01
2014-03-21
chargeback
lost
fraud
${id}
${id}
250.00
2020-02-10
2014-03-21
";
}
private static function _disputeWonSampleXml($id)
{
return "
250.00
250.0
245.00
USD
2014-03-01
2014-03-21
chargeback
won
fraud
${id}
${id}
250.00
2014-03-21
2014-03-22
";
}
private static function _subscriptionSampleXml($id)
{
return "
{$id}
";
}
private static function _subscriptionChargedSuccessfullySampleXml($id)
{
return "
{$id}
2016-03-21
2017-03-31
{$id}
submitted_for_settlement
49.99
";
}
private static function _subscriptionChargedUnsuccessfullySampleXml($id)
{
return "
{$id}
2016-03-21
2017-03-31
{$id}
failed
49.99
";
}
private static function _checkSampleXml()
{
return "
true
";
}
private static function _partnerMerchantConnectedSampleXml($id)
{
return "
public_id
public_key
private_key
abc123
cse_key
";
}
private static function _partnerMerchantDisconnectedSampleXml($id)
{
return "
abc123
";
}
private static function _partnerMerchantDeclinedSampleXml($id)
{
return "
abc123
";
}
private static function _oauthAccessRevocationSampleXml($id)
{
return "
{$id}
oauth_application_client_id
";
}
private static function _accountUpdaterDailyReportSampleXml($id)
{
return "
2016-01-14
link-to-csv-report
";
}
private static function _connectedMerchantStatusTransitionedSampleXml($id)
{
return "
{$id}
new_status
oauth_application_client_id
";
}
private static function _connectedMerchantPayPalStatusChangedSampleXml($id)
{
return "
{$id}
link
oauth_application_client_id
";
}
private static function _idealPaymentCompleteSampleXml($id)
{
return "
{$id}
COMPLETE
ABCISSUER
ORDERABC
EUR
10.00
2016-11-29T23:27:34.547Z
https://example.com
1234567890
";
}
private static function _idealPaymentFailedSampleXml($id)
{
return "
{$id}
FAILED
ABCISSUER
ORDERABC
EUR
10.00
2016-11-29T23:27:34.547Z
https://example.com
1234567890
";
}
private static function _grantedPaymentInstrumentUpdateSampleXml()
{
return "
vczo7jqrpwrsi2px
cf0i8wgarszuy6hc
ee257d98-de40-47e8-96b3-a6954ea7a9a4
false
false
abc123z
- expiration-month
- expiration-year
";
}
private static function _timestamp()
{
$originalZone = date_default_timezone_get();
date_default_timezone_set('UTC');
$timestamp = strftime('%Y-%m-%dT%TZ');
date_default_timezone_set($originalZone);
return $timestamp;
}
}
class_alias('Braintree\WebhookTestingGateway', 'Braintree_WebhookTestingGateway');