BraintreeWebhookTesting

The PayPal for WooCommerce Braintree WebhookTesting class.

Defined (1)

The class is defined in the following location(s).

/classes/lib/Braintree/Braintree/WebhookTesting.php  
  1. class WebhookTesting 
  2. public static function sampleNotification($kind, $id) 
  3. $payload = base64_encode(self::_sampleXml($kind, $id)) . "\n"; 
  4. $signature = Configuration::publicKey() . "|" . Digest::hexDigestSha1(Configuration::privateKey(), $payload); 
  5.  
  6. return [ 
  7. 'bt_signature' => $signature,  
  8. 'bt_payload' => $payload 
  9. ]; 
  10.  
  11. private static function _sampleXml($kind, $id) 
  12. switch ($kind) { 
  13. case WebhookNotification::SUB_MERCHANT_ACCOUNT_APPROVED: 
  14. $subjectXml = self::_merchantAccountApprovedSampleXml($id); 
  15. break; 
  16. case WebhookNotification::SUB_MERCHANT_ACCOUNT_DECLINED: 
  17. $subjectXml = self::_merchantAccountDeclinedSampleXml($id); 
  18. break; 
  19. case WebhookNotification::TRANSACTION_DISBURSED: 
  20. $subjectXml = self::_transactionDisbursedSampleXml($id); 
  21. break; 
  22. case WebhookNotification::DISBURSEMENT_EXCEPTION: 
  23. $subjectXml = self::_disbursementExceptionSampleXml($id); 
  24. break; 
  25. case WebhookNotification::DISBURSEMENT: 
  26. $subjectXml = self::_disbursementSampleXml($id); 
  27. break; 
  28. case WebhookNotification::PARTNER_MERCHANT_CONNECTED: 
  29. $subjectXml = self::_partnerMerchantConnectedSampleXml($id); 
  30. break; 
  31. case WebhookNotification::PARTNER_MERCHANT_DISCONNECTED: 
  32. $subjectXml = self::_partnerMerchantDisconnectedSampleXml($id); 
  33. break; 
  34. case WebhookNotification::PARTNER_MERCHANT_DECLINED: 
  35. $subjectXml = self::_partnerMerchantDeclinedSampleXml($id); 
  36. break; 
  37. case WebhookNotification::DISPUTE_OPENED: 
  38. $subjectXml = self::_disputeOpenedSampleXml($id); 
  39. break; 
  40. case WebhookNotification::DISPUTE_LOST: 
  41. $subjectXml = self::_disputeLostSampleXml($id); 
  42. break; 
  43. case WebhookNotification::DISPUTE_WON: 
  44. $subjectXml = self::_disputeWonSampleXml($id); 
  45. break; 
  46. case WebhookNotification::SUBSCRIPTION_CHARGED_SUCCESSFULLY: 
  47. $subjectXml = self::_subscriptionChargedSuccessfullySampleXml($id); 
  48. break; 
  49. case WebhookNotification::CHECK: 
  50. $subjectXml = self::_checkSampleXml(); 
  51. break; 
  52. default: 
  53. $subjectXml = self::_subscriptionSampleXml($id); 
  54. break; 
  55. $timestamp = self::_timestamp(); 
  56. return " 
  57. <notification> 
  58. <timestamp type=\"datetime\">{$timestamp}</timestamp> 
  59. <kind>{$kind}</kind> 
  60. <subject>{$subjectXml}</subject> 
  61. </notification> 
  62. "; 
  63.  
  64. private static function _merchantAccountApprovedSampleXml($id) 
  65. return " 
  66. <merchant_account> 
  67. <id>{$id}</id> 
  68. <master_merchant_account> 
  69. <id>master_ma_for_{$id}</id> 
  70. <status>active</status> 
  71. </master_merchant_account> 
  72. <status>active</status> 
  73. </merchant_account> 
  74. "; 
  75.  
  76. private static function _merchantAccountDeclinedSampleXml($id) 
  77. return " 
  78. <api-error-response> 
  79. <message>Credit score is too low</message> 
  80. <errors> 
  81. <errors type=\"array\"/> 
  82. <merchant-account> 
  83. <errors type=\"array\"> 
  84. <error> 
  85. <code>82621</code> 
  86. <message>Credit score is too low</message> 
  87. <attribute type=\"symbol\">base</attribute> 
  88. </error> 
  89. </errors> 
  90. </merchant-account> 
  91. </errors> 
  92. <merchant-account> 
  93. <id>{$id}</id> 
  94. <status>suspended</status> 
  95. <master-merchant-account> 
  96. <id>master_ma_for_{$id}</id> 
  97. <status>suspended</status> 
  98. </master-merchant-account> 
  99. </merchant-account> 
  100. </api-error-response> 
  101. "; 
  102.  
  103. private static function _transactionDisbursedSampleXml($id) 
  104. return " 
  105. <transaction> 
  106. <id>${id}</id> 
  107. <amount>100</amount> 
  108. <disbursement-details> 
  109. <disbursement-date type=\"date\">2013-07-09</disbursement-date> 
  110. </disbursement-details> 
  111. </transaction> 
  112. "; 
  113.  
  114. private static function _disbursementExceptionSampleXml($id) 
  115. return " 
  116. <disbursement> 
  117. <id>${id}</id> 
  118. <transaction-ids type=\"array\"> 
  119. <item>asdfg</item> 
  120. <item>qwert</item> 
  121. </transaction-ids> 
  122. <success type=\"boolean\">false</success> 
  123. <retry type=\"boolean\">false</retry> 
  124. <merchant-account> 
  125. <id>merchant_account_token</id> 
  126. <currency-iso-code>USD</currency-iso-code> 
  127. <sub-merchant-account type=\"boolean\">false</sub-merchant-account> 
  128. <status>active</status> 
  129. </merchant-account> 
  130. <amount>100.00</amount> 
  131. <disbursement-date type=\"date\">2014-02-10</disbursement-date> 
  132. <exception-message>bank_rejected</exception-message> 
  133. <follow-up-action>update_funding_information</follow-up-action> 
  134. </disbursement> 
  135. "; 
  136.  
  137. private static function _disbursementSampleXml($id) 
  138. return " 
  139. <disbursement> 
  140. <id>${id}</id> 
  141. <transaction-ids type=\"array\"> 
  142. <item>asdfg</item> 
  143. <item>qwert</item> 
  144. </transaction-ids> 
  145. <success type=\"boolean\">true</success> 
  146. <retry type=\"boolean\">false</retry> 
  147. <merchant-account> 
  148. <id>merchant_account_token</id> 
  149. <currency-iso-code>USD</currency-iso-code> 
  150. <sub-merchant-account type=\"boolean\">false</sub-merchant-account> 
  151. <status>active</status> 
  152. </merchant-account> 
  153. <amount>100.00</amount> 
  154. <disbursement-date type=\"date\">2014-02-10</disbursement-date> 
  155. <exception-message nil=\"true\"/> 
  156. <follow-up-action nil=\"true\"/> 
  157. </disbursement> 
  158. "; 
  159.  
  160. private static function _disputeOpenedSampleXml($id) 
  161. return " 
  162. <dispute> 
  163. <amount>250.00</amount> 
  164. <currency-iso-code>USD</currency-iso-code> 
  165. <received-date type=\"date\">2014-03-01</received-date> 
  166. <reply-by-date type=\"date\">2014-03-21</reply-by-date> 
  167. <kind>chargeback</kind> 
  168. <status>open</status> 
  169. <reason>fraud</reason> 
  170. <id>${id}</id> 
  171. <transaction> 
  172. <id>${id}</id> 
  173. <amount>250.00</amount> 
  174. </transaction> 
  175. <date-opened type=\"date\">2014-03-21</date-opened> 
  176. </dispute> 
  177. "; 
  178.  
  179. private static function _disputeLostSampleXml($id) 
  180. return " 
  181. <dispute> 
  182. <amount>250.00</amount> 
  183. <currency-iso-code>USD</currency-iso-code> 
  184. <received-date type=\"date\">2014-03-01</received-date> 
  185. <reply-by-date type=\"date\">2014-03-21</reply-by-date> 
  186. <kind>chargeback</kind> 
  187. <status>lost</status> 
  188. <reason>fraud</reason> 
  189. <id>${id}</id> 
  190. <transaction> 
  191. <id>${id}</id> 
  192. <amount>250.00</amount> 
  193. </transaction> 
  194. <date-opened type=\"date\">2014-03-21</date-opened> 
  195. </dispute> 
  196. "; 
  197.  
  198. private static function _disputeWonSampleXml($id) 
  199. return " 
  200. <dispute> 
  201. <amount>250.00</amount> 
  202. <currency-iso-code>USD</currency-iso-code> 
  203. <received-date type=\"date\">2014-03-01</received-date> 
  204. <reply-by-date type=\"date\">2014-03-21</reply-by-date> 
  205. <kind>chargeback</kind> 
  206. <status>won</status> 
  207. <reason>fraud</reason> 
  208. <id>${id}</id> 
  209. <transaction> 
  210. <id>${id}</id> 
  211. <amount>250.00</amount> 
  212. </transaction> 
  213. <date-opened type=\"date\">2014-03-21</date-opened> 
  214. <date-won type=\"date\">2014-03-22</date-won> 
  215. </dispute> 
  216. "; 
  217.  
  218. private static function _subscriptionSampleXml($id) 
  219. return " 
  220. <subscription> 
  221. <id>{$id}</id> 
  222. <transactions type=\"array\"> 
  223. </transactions> 
  224. <add_ons type=\"array\"> 
  225. </add_ons> 
  226. <discounts type=\"array\"> 
  227. </discounts> 
  228. </subscription> 
  229. "; 
  230.  
  231. private static function _subscriptionChargedSuccessfullySampleXml($id) 
  232. return " 
  233. <subscription> 
  234. <id>{$id}</id> 
  235. <transactions type=\"array\"> 
  236. <transaction> 
  237. <status>submitted_for_settlement</status> 
  238. <amount>49.99</amount> 
  239. </transaction> 
  240. </transactions> 
  241. <add_ons type=\"array\"> 
  242. </add_ons> 
  243. <discounts type=\"array\"> 
  244. </discounts> 
  245. </subscription> 
  246. "; 
  247.  
  248. private static function _checkSampleXml() 
  249. return " 
  250. <check type=\"boolean\">true</check> 
  251. "; 
  252.  
  253. private static function _partnerMerchantConnectedSampleXml($id) 
  254. return " 
  255. <partner-merchant> 
  256. <merchant-public-id>public_id</merchant-public-id> 
  257. <public-key>public_key</public-key> 
  258. <private-key>private_key</private-key> 
  259. <partner-merchant-id>abc123</partner-merchant-id> 
  260. <client-side-encryption-key>cse_key</client-side-encryption-key> 
  261. </partner-merchant> 
  262. "; 
  263.  
  264. private static function _partnerMerchantDisconnectedSampleXml($id) 
  265. return " 
  266. <partner-merchant> 
  267. <partner-merchant-id>abc123</partner-merchant-id> 
  268. </partner-merchant> 
  269. "; 
  270.  
  271. private static function _partnerMerchantDeclinedSampleXml($id) 
  272. return " 
  273. <partner-merchant> 
  274. <partner-merchant-id>abc123</partner-merchant-id> 
  275. </partner-merchant> 
  276. "; 
  277.  
  278. private static function _timestamp() 
  279. $originalZone = date_default_timezone_get(); 
  280. date_default_timezone_set('UTC'); 
  281. $timestamp = strftime('%Y-%m-%dT%TZ'); 
  282. date_default_timezone_set($originalZone); 
  283.  
  284. return $timestamp;