WebhookNotification.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace Braintree;
  3. class WebhookNotification extends Base
  4. {
  5. const SUBSCRIPTION_CANCELED = 'subscription_canceled';
  6. const SUBSCRIPTION_CHARGED_SUCCESSFULLY = 'subscription_charged_successfully';
  7. const SUBSCRIPTION_CHARGED_UNSUCCESSFULLY = 'subscription_charged_unsuccessfully';
  8. const SUBSCRIPTION_EXPIRED = 'subscription_expired';
  9. const SUBSCRIPTION_TRIAL_ENDED = 'subscription_trial_ended';
  10. const SUBSCRIPTION_WENT_ACTIVE = 'subscription_went_active';
  11. const SUBSCRIPTION_WENT_PAST_DUE = 'subscription_went_past_due';
  12. const SUB_MERCHANT_ACCOUNT_APPROVED = 'sub_merchant_account_approved';
  13. const SUB_MERCHANT_ACCOUNT_DECLINED = 'sub_merchant_account_declined';
  14. const TRANSACTION_DISBURSED = 'transaction_disbursed';
  15. const TRANSACTION_SETTLED = 'transaction_settled';
  16. const TRANSACTION_SETTLEMENT_DECLINED = 'transaction_settlement_declined';
  17. const DISBURSEMENT_EXCEPTION = 'disbursement_exception';
  18. const DISBURSEMENT = 'disbursement';
  19. const DISPUTE_OPENED = 'dispute_opened';
  20. const DISPUTE_LOST = 'dispute_lost';
  21. const DISPUTE_WON = 'dispute_won';
  22. const PARTNER_MERCHANT_CONNECTED = 'partner_merchant_connected';
  23. const PARTNER_MERCHANT_DISCONNECTED = 'partner_merchant_disconnected';
  24. const PARTNER_MERCHANT_DECLINED = 'partner_merchant_declined';
  25. const OAUTH_ACCESS_REVOKED = 'oauth_access_revoked';
  26. const CHECK = 'check';
  27. const ACCOUNT_UPDATER_DAILY_REPORT = 'account_updater_daily_report';
  28. const CONNECTED_MERCHANT_STATUS_TRANSITIONED = 'connected_merchant_status_transitioned';
  29. const CONNECTED_MERCHANT_PAYPAL_STATUS_CHANGED = 'connected_merchant_paypal_status_changed';
  30. const IDEAL_PAYMENT_COMPLETE = 'ideal_payment_complete';
  31. const IDEAL_PAYMENT_FAILED = 'ideal_payment_failed';
  32. const GRANTED_PAYMENT_INSTRUMENT_UPDATE = 'granted_payment_instrument_update';
  33. public static function parse($signature, $payload) {
  34. return Configuration::gateway()->webhookNotification()->parse($signature, $payload);
  35. }
  36. public static function verify($challenge) {
  37. return Configuration::gateway()->webhookNotification()->verify($challenge);
  38. }
  39. public static function factory($attributes)
  40. {
  41. $instance = new self();
  42. $instance->_initialize($attributes);
  43. return $instance;
  44. }
  45. protected function _initialize($attributes)
  46. {
  47. $this->_attributes = $attributes;
  48. if (!isset($attributes['sourceMerchantId'])) {
  49. $this->_set('sourceMerchantId', null);
  50. }
  51. if (isset($attributes['subject']['apiErrorResponse'])) {
  52. $wrapperNode = $attributes['subject']['apiErrorResponse'];
  53. } else {
  54. $wrapperNode = $attributes['subject'];
  55. }
  56. if (isset($wrapperNode['subscription'])) {
  57. $this->_set('subscription', Subscription::factory($attributes['subject']['subscription']));
  58. }
  59. if (isset($wrapperNode['merchantAccount'])) {
  60. $this->_set('merchantAccount', MerchantAccount::factory($wrapperNode['merchantAccount']));
  61. }
  62. if (isset($wrapperNode['transaction'])) {
  63. $this->_set('transaction', Transaction::factory($wrapperNode['transaction']));
  64. }
  65. if (isset($wrapperNode['disbursement'])) {
  66. $this->_set('disbursement', Disbursement::factory($wrapperNode['disbursement']));
  67. }
  68. if (isset($wrapperNode['partnerMerchant'])) {
  69. $this->_set('partnerMerchant', PartnerMerchant::factory($wrapperNode['partnerMerchant']));
  70. }
  71. if (isset($wrapperNode['oauthApplicationRevocation'])) {
  72. $this->_set('oauthAccessRevocation', OAuthAccessRevocation::factory($wrapperNode['oauthApplicationRevocation']));
  73. }
  74. if (isset($wrapperNode['connectedMerchantStatusTransitioned'])) {
  75. $this->_set('connectedMerchantStatusTransitioned', ConnectedMerchantStatusTransitioned::factory($wrapperNode['connectedMerchantStatusTransitioned']));
  76. }
  77. if (isset($wrapperNode['connectedMerchantPaypalStatusChanged'])) {
  78. $this->_set('connectedMerchantPayPalStatusChanged', ConnectedMerchantPayPalStatusChanged::factory($wrapperNode['connectedMerchantPaypalStatusChanged']));
  79. }
  80. if (isset($wrapperNode['dispute'])) {
  81. $this->_set('dispute', Dispute::factory($wrapperNode['dispute']));
  82. }
  83. if (isset($wrapperNode['accountUpdaterDailyReport'])) {
  84. $this->_set('accountUpdaterDailyReport', AccountUpdaterDailyReport::factory($wrapperNode['accountUpdaterDailyReport']));
  85. }
  86. if (isset($wrapperNode['idealPayment'])) {
  87. $this->_set('idealPayment', IdealPayment::factory($wrapperNode['idealPayment']));
  88. }
  89. if (isset($wrapperNode['grantedPaymentInstrumentUpdate'])) {
  90. $this->_set('grantedPaymentInstrumentUpdate', GrantedPaymentInstrumentUpdate::factory($wrapperNode['grantedPaymentInstrumentUpdate']));
  91. }
  92. if (isset($wrapperNode['errors'])) {
  93. $this->_set('errors', new Error\ValidationErrorCollection($wrapperNode['errors']));
  94. $this->_set('message', $wrapperNode['message']);
  95. }
  96. }
  97. }
  98. class_alias('Braintree\WebhookNotification', 'Braintree_WebhookNotification');