BraintreeWebhookTesting

The Paid Memberships Pro Braintree WebhookTesting class.

Defined (1)

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

/includes/lib/Braintree/lib/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::TRANSACTION_SETTLED: 
  23. $subjectXml = self::_transactionSettledSampleXml($id); 
  24. break; 
  25. case WebhookNotification::TRANSACTION_SETTLEMENT_DECLINED: 
  26. $subjectXml = self::_transactionSettlementDeclinedSampleXml($id); 
  27. break; 
  28. case WebhookNotification::DISBURSEMENT_EXCEPTION: 
  29. $subjectXml = self::_disbursementExceptionSampleXml($id); 
  30. break; 
  31. case WebhookNotification::DISBURSEMENT: 
  32. $subjectXml = self::_disbursementSampleXml($id); 
  33. break; 
  34. case WebhookNotification::PARTNER_MERCHANT_CONNECTED: 
  35. $subjectXml = self::_partnerMerchantConnectedSampleXml($id); 
  36. break; 
  37. case WebhookNotification::PARTNER_MERCHANT_DISCONNECTED: 
  38. $subjectXml = self::_partnerMerchantDisconnectedSampleXml($id); 
  39. break; 
  40. case WebhookNotification::PARTNER_MERCHANT_DECLINED: 
  41. $subjectXml = self::_partnerMerchantDeclinedSampleXml($id); 
  42. break; 
  43. case WebhookNotification::DISPUTE_OPENED: 
  44. $subjectXml = self::_disputeOpenedSampleXml($id); 
  45. break; 
  46. case WebhookNotification::DISPUTE_LOST: 
  47. $subjectXml = self::_disputeLostSampleXml($id); 
  48. break; 
  49. case WebhookNotification::DISPUTE_WON: 
  50. $subjectXml = self::_disputeWonSampleXml($id); 
  51. break; 
  52. case WebhookNotification::SUBSCRIPTION_CHARGED_SUCCESSFULLY: 
  53. $subjectXml = self::_subscriptionChargedSuccessfullySampleXml($id); 
  54. break; 
  55. case WebhookNotification::CHECK: 
  56. $subjectXml = self::_checkSampleXml(); 
  57. break; 
  58. case WebhookNotification::ACCOUNT_UPDATER_DAILY_REPORT: 
  59. $subjectXml = self::_accountUpdaterDailyReportSampleXml($id); 
  60. break; 
  61. default: 
  62. $subjectXml = self::_subscriptionSampleXml($id); 
  63. break; 
  64. $timestamp = self::_timestamp(); 
  65. return " 
  66. <notification> 
  67. <timestamp type=\"datetime\">{$timestamp}</timestamp> 
  68. <kind>{$kind}</kind> 
  69. <subject>{$subjectXml}</subject> 
  70. </notification> 
  71. "; 
  72.  
  73. private static function _merchantAccountApprovedSampleXml($id) 
  74. return " 
  75. <merchant_account> 
  76. <id>{$id}</id> 
  77. <master_merchant_account> 
  78. <id>master_ma_for_{$id}</id> 
  79. <status>active</status> 
  80. </master_merchant_account> 
  81. <status>active</status> 
  82. </merchant_account> 
  83. "; 
  84.  
  85. private static function _merchantAccountDeclinedSampleXml($id) 
  86. return " 
  87. <api-error-response> 
  88. <message>Credit score is too low</message> 
  89. <errors> 
  90. <errors type=\"array\"/> 
  91. <merchant-account> 
  92. <errors type=\"array\"> 
  93. <error> 
  94. <code>82621</code> 
  95. <message>Credit score is too low</message> 
  96. <attribute type=\"symbol\">base</attribute> 
  97. </error> 
  98. </errors> 
  99. </merchant-account> 
  100. </errors> 
  101. <merchant-account> 
  102. <id>{$id}</id> 
  103. <status>suspended</status> 
  104. <master-merchant-account> 
  105. <id>master_ma_for_{$id}</id> 
  106. <status>suspended</status> 
  107. </master-merchant-account> 
  108. </merchant-account> 
  109. </api-error-response> 
  110. "; 
  111.  
  112. private static function _transactionDisbursedSampleXml($id) 
  113. return " 
  114. <transaction> 
  115. <id>${id}</id> 
  116. <amount>100</amount> 
  117. <disbursement-details> 
  118. <disbursement-date type=\"date\">2013-07-09</disbursement-date> 
  119. </disbursement-details> 
  120. </transaction> 
  121. "; 
  122.  
  123. private static function _transactionSettledSampleXml($id) 
  124. return " 
  125. <transaction> 
  126. <id>${id}</id> 
  127. <status>settled</status> 
  128. <type>sale</type> 
  129. <currency-iso-code>USD</currency-iso-code> 
  130. <amount>100.00</amount> 
  131. <merchant-account-id>ogaotkivejpfayqfeaimuktty</merchant-account-id> 
  132. <payment-instrument-type>us_bank_account</payment-instrument-type> 
  133. <us-bank-account> 
  134. <routing-number>123456789</routing-number> 
  135. <last-4>1234</last-4> 
  136. <account-type>checking</account-type> 
  137. <account-description>PayPal Checking - 1234</account-description> 
  138. <account-holder-name>Dan Schulman</account-holder-name> 
  139. </us-bank-account> 
  140. </transaction> 
  141. "; 
  142.  
  143. private static function _transactionSettlementDeclinedSampleXml($id) 
  144. return " 
  145. <transaction> 
  146. <id>${id}</id> 
  147. <status>settlement_declined</status> 
  148. <type>sale</type> 
  149. <currency-iso-code>USD</currency-iso-code> 
  150. <amount>100.00</amount> 
  151. <merchant-account-id>ogaotkivejpfayqfeaimuktty</merchant-account-id> 
  152. <payment-instrument-type>us_bank_account</payment-instrument-type> 
  153. <us-bank-account> 
  154. <routing-number>123456789</routing-number> 
  155. <last-4>1234</last-4> 
  156. <account-type>checking</account-type> 
  157. <account-description>PayPal Checking - 1234</account-description> 
  158. <account-holder-name>Dan Schulman</account-holder-name> 
  159. </us-bank-account> 
  160. </transaction> 
  161. "; 
  162.  
  163. private static function _disbursementExceptionSampleXml($id) 
  164. return " 
  165. <disbursement> 
  166. <id>${id}</id> 
  167. <transaction-ids type=\"array\"> 
  168. <item>asdfg</item> 
  169. <item>qwert</item> 
  170. </transaction-ids> 
  171. <success type=\"boolean\">false</success> 
  172. <retry type=\"boolean\">false</retry> 
  173. <merchant-account> 
  174. <id>merchant_account_token</id> 
  175. <currency-iso-code>USD</currency-iso-code> 
  176. <sub-merchant-account type=\"boolean\">false</sub-merchant-account> 
  177. <status>active</status> 
  178. </merchant-account> 
  179. <amount>100.00</amount> 
  180. <disbursement-date type=\"date\">2014-02-10</disbursement-date> 
  181. <exception-message>bank_rejected</exception-message> 
  182. <follow-up-action>update_funding_information</follow-up-action> 
  183. </disbursement> 
  184. "; 
  185.  
  186. private static function _disbursementSampleXml($id) 
  187. return " 
  188. <disbursement> 
  189. <id>${id}</id> 
  190. <transaction-ids type=\"array\"> 
  191. <item>asdfg</item> 
  192. <item>qwert</item> 
  193. </transaction-ids> 
  194. <success type=\"boolean\">true</success> 
  195. <retry type=\"boolean\">false</retry> 
  196. <merchant-account> 
  197. <id>merchant_account_token</id> 
  198. <currency-iso-code>USD</currency-iso-code> 
  199. <sub-merchant-account type=\"boolean\">false</sub-merchant-account> 
  200. <status>active</status> 
  201. </merchant-account> 
  202. <amount>100.00</amount> 
  203. <disbursement-date type=\"date\">2014-02-10</disbursement-date> 
  204. <exception-message nil=\"true\"/> 
  205. <follow-up-action nil=\"true\"/> 
  206. </disbursement> 
  207. "; 
  208.  
  209. private static function _disputeOpenedSampleXml($id) 
  210. return " 
  211. <dispute> 
  212. <amount>250.00</amount> 
  213. <currency-iso-code>USD</currency-iso-code> 
  214. <received-date type=\"date\">2014-03-01</received-date> 
  215. <reply-by-date type=\"date\">2014-03-21</reply-by-date> 
  216. <kind>chargeback</kind> 
  217. <status>open</status> 
  218. <reason>fraud</reason> 
  219. <id>${id}</id> 
  220. <transaction> 
  221. <id>${id}</id> 
  222. <amount>250.00</amount> 
  223. </transaction> 
  224. <date-opened type=\"date\">2014-03-21</date-opened> 
  225. </dispute> 
  226. "; 
  227.  
  228. private static function _disputeLostSampleXml($id) 
  229. return " 
  230. <dispute> 
  231. <amount>250.00</amount> 
  232. <currency-iso-code>USD</currency-iso-code> 
  233. <received-date type=\"date\">2014-03-01</received-date> 
  234. <reply-by-date type=\"date\">2014-03-21</reply-by-date> 
  235. <kind>chargeback</kind> 
  236. <status>lost</status> 
  237. <reason>fraud</reason> 
  238. <id>${id}</id> 
  239. <transaction> 
  240. <id>${id}</id> 
  241. <amount>250.00</amount> 
  242. <next_billing-date type=\"date\">2020-02-10</next_billing-date> 
  243. </transaction> 
  244. <date-opened type=\"date\">2014-03-21</date-opened> 
  245. </dispute> 
  246. "; 
  247.  
  248. private static function _disputeWonSampleXml($id) 
  249. return " 
  250. <dispute> 
  251. <amount>250.00</amount> 
  252. <currency-iso-code>USD</currency-iso-code> 
  253. <received-date type=\"date\">2014-03-01</received-date> 
  254. <reply-by-date type=\"date\">2014-03-21</reply-by-date> 
  255. <kind>chargeback</kind> 
  256. <status>won</status> 
  257. <reason>fraud</reason> 
  258. <id>${id}</id> 
  259. <transaction> 
  260. <id>${id}</id> 
  261. <amount>250.00</amount> 
  262. </transaction> 
  263. <date-opened type=\"date\">2014-03-21</date-opened> 
  264. <date-won type=\"date\">2014-03-22</date-won> 
  265. </dispute> 
  266. "; 
  267.  
  268. private static function _subscriptionSampleXml($id) 
  269. return " 
  270. <subscription> 
  271. <id>{$id}</id> 
  272. <transactions type=\"array\"> 
  273. </transactions> 
  274. <add_ons type=\"array\"> 
  275. </add_ons> 
  276. <discounts type=\"array\"> 
  277. </discounts> 
  278. </subscription> 
  279. "; 
  280.  
  281. private static function _subscriptionChargedSuccessfullySampleXml($id) 
  282. return " 
  283. <subscription> 
  284. <id>{$id}</id> 
  285. <billing-period-start-date type=\"date\">2016-03-21</billing-period-start-date> 
  286. <billing-period-end-date type=\"date\">2017-03-31</billing-period-end-date> 
  287. <transactions type=\"array\"> 
  288. <transaction> 
  289. <status>submitted_for_settlement</status> 
  290. <amount>49.99</amount> 
  291. </transaction> 
  292. </transactions> 
  293. <add_ons type=\"array\"> 
  294. </add_ons> 
  295. <discounts type=\"array\"> 
  296. </discounts> 
  297. </subscription> 
  298. "; 
  299.  
  300. private static function _checkSampleXml() 
  301. return " 
  302. <check type=\"boolean\">true</check> 
  303. "; 
  304.  
  305. private static function _partnerMerchantConnectedSampleXml($id) 
  306. return " 
  307. <partner-merchant> 
  308. <merchant-public-id>public_id</merchant-public-id> 
  309. <public-key>public_key</public-key> 
  310. <private-key>private_key</private-key> 
  311. <partner-merchant-id>abc123</partner-merchant-id> 
  312. <client-side-encryption-key>cse_key</client-side-encryption-key> 
  313. </partner-merchant> 
  314. "; 
  315.  
  316. private static function _partnerMerchantDisconnectedSampleXml($id) 
  317. return " 
  318. <partner-merchant> 
  319. <partner-merchant-id>abc123</partner-merchant-id> 
  320. </partner-merchant> 
  321. "; 
  322.  
  323. private static function _partnerMerchantDeclinedSampleXml($id) 
  324. return " 
  325. <partner-merchant> 
  326. <partner-merchant-id>abc123</partner-merchant-id> 
  327. </partner-merchant> 
  328. "; 
  329.  
  330. private static function _accountUpdaterDailyReportSampleXml($id) 
  331. return " 
  332. <account-updater-daily-report> 
  333. <report-date type=\"date\">2016-01-14</report-date> 
  334. <report-url>link-to-csv-report</report-url> 
  335. </account-updater-daily-report> 
  336. "; 
  337.  
  338. private static function _timestamp() 
  339. $originalZone = date_default_timezone_get(); 
  340. date_default_timezone_set('UTC'); 
  341. $timestamp = strftime('%Y-%m-%dT%TZ'); 
  342. date_default_timezone_set($originalZone); 
  343.  
  344. return $timestamp;