WP eCommerce - Version 3.13.0

Version Description

[2017-10-25] =

  • New: Now including PayPal's Braintree payment gateway by default.
  • Fix: Various PHP notices related to custom taxonomies have been resolved.
  • Fix: Edge cases where shipping methods could be disabled, caused by poorly written Shipwire code, have been resolved.
  • Fix: Custom instructions in 3.0 Manual Gateway are now included in the receipt page and emails.
Download this release

Release Info

Developer JustinSainton
Plugin Icon 128x128 WP eCommerce
Version 3.13.0
Comparing to
See all releases

Code changes from version 3.12.4 to 3.13.0

Files changed (216) hide show
  1. readme.txt +9 -2
  2. wp-shopping-cart.php +1 -1
  3. wpsc-admin/includes/settings-tabs/shipping.php +4 -1
  4. wpsc-admin/js/settings-page.js +1 -1
  5. wpsc-components/merchant-core-v2/helpers/gateways.php +1 -1
  6. wpsc-components/merchant-core-v3/classes/payment-gateway.php +1 -1
  7. wpsc-components/merchant-core-v3/gateways/braintree-credit-cards.php +561 -0
  8. wpsc-components/merchant-core-v3/gateways/braintree-paypal.php +291 -0
  9. wpsc-components/merchant-core-v3/gateways/manual.php +23 -1
  10. wpsc-components/merchant-core-v3/libraries/pp-braintree/assets/css/style.css +85 -0
  11. wpsc-components/merchant-core-v3/libraries/pp-braintree/assets/images/PP_logo_h_200x51.png +0 -0
  12. wpsc-components/merchant-core-v3/libraries/pp-braintree/assets/js/admin.js +4 -0
  13. wpsc-components/merchant-core-v3/libraries/pp-braintree/assets/js/frontend.js +407 -0
  14. wpsc-components/merchant-core-v3/libraries/pp-braintree/pp-braintree.php +739 -0
  15. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/ACKNOWLEDGEMENTS.md +6 -0
  16. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/CHANGELOG.md +475 -0
  17. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/LICENSE +22 -0
  18. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/README.md +91 -0
  19. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/Rakefile +81 -0
  20. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/ci.sh +11 -0
  21. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/composer.json +36 -0
  22. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/images/cards.png +0 -0
  23. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/images/connect-braintree.png +0 -0
  24. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/images/connect-braintree@2x.png +0 -0
  25. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/images/connect-braintree@3x.png +0 -0
  26. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree.php +23 -0
  27. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AccountUpdaterDailyReport.php +44 -0
  28. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AchMandate.php +57 -0
  29. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AddOn.php +29 -0
  30. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AddOnGateway.php +53 -0
  31. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Address.php +150 -0
  32. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AddressGateway.php +314 -0
  33. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AmexExpressCheckoutCard.php +79 -0
  34. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AndroidPayCard.php +89 -0
  35. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ApplePayCard.php +99 -0
  36. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Base.php +75 -0
  37. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ClientToken.php +49 -0
  38. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ClientTokenGateway.php +129 -0
  39. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CoinbaseAccount.php +110 -0
  40. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Collection.php +161 -0
  41. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Configuration.php +602 -0
  42. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ConnectedMerchantPayPalStatusChanged.php +36 -0
  43. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ConnectedMerchantStatusTransitioned.php +36 -0
  44. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CredentialsParser.php +147 -0
  45. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CreditCard.php +316 -0
  46. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CreditCardGateway.php +486 -0
  47. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CreditCardVerification.php +43 -0
  48. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CreditCardVerificationGateway.php +74 -0
  49. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CreditCardVerificationSearch.php +56 -0
  50. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Customer.php +424 -0
  51. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CustomerGateway.php +637 -0
  52. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CustomerSearch.php +34 -0
  53. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Descriptor.php +7 -0
  54. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Digest.php +60 -0
  55. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Disbursement.php +52 -0
  56. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/DisbursementDetails.php +24 -0
  57. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Discount.php +21 -0
  58. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/DiscountGateway.php +31 -0
  59. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Dispute.php +81 -0
  60. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Dispute/TransactionDetails.php +25 -0
  61. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/EqualityNode.php +12 -0
  62. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Error/Codes.php +533 -0
  63. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Error/ErrorCollection.php +123 -0
  64. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Error/Validation.php +60 -0
  65. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Error/ValidationErrorCollection.php +131 -0
  66. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/EuropeBankAccount.php +67 -0
  67. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception.php +13 -0
  68. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Authentication.php +17 -0
  69. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Authorization.php +19 -0
  70. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Configuration.php +17 -0
  71. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Connection.php +17 -0
  72. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/DownForMaintenance.php +16 -0
  73. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/ForgedQueryString.php +20 -0
  74. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/InvalidChallenge.php +9 -0
  75. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/InvalidSignature.php +9 -0
  76. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/NotFound.php +16 -0
  77. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/SSLCaFileNotFound.php +16 -0
  78. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/SSLCertificate.php +16 -0
  79. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/ServerError.php +16 -0
  80. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/TestOperationPerformedInProduction.php +15 -0
  81. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Timeout.php +16 -0
  82. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/TooManyRequests.php +16 -0
  83. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Unexpected.php +17 -0
  84. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/UpgradeRequired.php +16 -0
  85. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/ValidationsFailed.php +16 -0
  86. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/FacilitatorDetails.php +30 -0
  87. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Gateway.php +224 -0
  88. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Http.php +202 -0
  89. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/IbanBankAccount.php +57 -0
  90. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/IdealPayment.php +92 -0
  91. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/IdealPaymentGateway.php +104 -0
  92. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Instance.php +74 -0
  93. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/IsNode.php +24 -0
  94. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/KeyValueNode.php +23 -0
  95. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MasterpassCard.php +141 -0
  96. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Merchant.php +36 -0
  97. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccount.php +64 -0
  98. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccount/AddressDetails.php +10 -0
  99. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccount/BusinessDetails.php +23 -0
  100. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccount/FundingDetails.php +10 -0
  101. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccount/IndividualDetails.php +23 -0
  102. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccountGateway.php +182 -0
  103. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantGateway.php +42 -0
  104. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Modification.php +22 -0
  105. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MultipleValueNode.php +41 -0
  106. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MultipleValueOrTextNode.php +47 -0
  107. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/OAuthCredentials.php +34 -0
  108. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/OAuthGateway.php +122 -0
  109. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/OAuthResult.php +34 -0
  110. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaginatedCollection.php +110 -0
  111. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaginatedResult.php +32 -0
  112. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PartialMatchNode.php +18 -0
  113. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PartnerMerchant.php +41 -0
  114. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PayPalAccount.php +109 -0
  115. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PayPalAccountGateway.php +178 -0
  116. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaymentInstrumentType.php +17 -0
  117. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaymentMethod.php +44 -0
  118. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaymentMethodGateway.php +350 -0
  119. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaymentMethodNonce.php +52 -0
  120. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaymentMethodNonceGateway.php +64 -0
  121. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Plan.php +51 -0
  122. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PlanGateway.php +34 -0
  123. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/RangeNode.php +40 -0
  124. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ResourceCollection.php +156 -0
  125. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Result/CreditCardVerification.php +100 -0
  126. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Result/Error.php +123 -0
  127. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Result/Successful.php +92 -0
  128. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/RiskData.php +30 -0
  129. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/SettlementBatchSummary.php +45 -0
  130. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/SettlementBatchSummaryGateway.php +106 -0
  131. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/SignatureService.php +24 -0
  132. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Subscription.php +140 -0
  133. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Subscription/StatusDetails.php +24 -0
  134. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/SubscriptionGateway.php +214 -0
  135. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/SubscriptionSearch.php +72 -0
  136. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/CreditCardNumbers.php +75 -0
  137. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/MerchantAccount.php +21 -0
  138. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/Nonces.php +76 -0
  139. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/Transaction.php +62 -0
  140. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/TransactionAmounts.php +18 -0
  141. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/VenmoSdk.php +30 -0
  142. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TestingGateway.php +52 -0
  143. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TextNode.php +12 -0
  144. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ThreeDSecureInfo.php +30 -0
  145. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction.php +596 -0
  146. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/AddressDetails.php +27 -0
  147. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/AmexExpressCheckoutCardDetails.php +43 -0
  148. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/AndroidPayCardDetails.php +47 -0
  149. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/ApplePayCardDetails.php +39 -0
  150. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/CoinbaseDetails.php +38 -0
  151. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/CreditCardDetails.php +38 -0
  152. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/CustomerDetails.php +25 -0
  153. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/EuropeBankAccountDetails.php +24 -0
  154. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/IdealPaymentDetails.php +23 -0
  155. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/MasterpassCardDetails.php +51 -0
  156. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/PayPalDetails.php +41 -0
  157. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/StatusDetails.php +21 -0
  158. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/SubscriptionDetails.php +19 -0
  159. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/UsBankAccountDetails.php +40 -0
  160. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/VenmoAccountDetails.php +38 -0
  161. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/VisaCheckoutCardDetails.php +52 -0
  162. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TransactionGateway.php +532 -0
  163. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TransactionSearch.php +130 -0
  164. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TransparentRedirect.php +100 -0
  165. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TransparentRedirectGateway.php +289 -0
  166. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/UnknownPaymentMethod.php +69 -0
  167. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/UsBankAccount.php +95 -0
  168. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/UsBankAccountGateway.php +106 -0
  169. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Util.php +414 -0
  170. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/VenmoAccount.php +74 -0
  171. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Version.php +34 -0
  172. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/VisaCheckoutCard.php +154 -0
  173. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/WebhookNotification.php +98 -0
  174. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/WebhookNotificationGateway.php +69 -0
  175. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/WebhookTesting.php +417 -0
  176. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Xml.php +39 -0
  177. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Xml/Generator.php +149 -0
  178. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Xml/Parser.php +140 -0
  179. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/autoload.php +21 -0
  180. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/ssl/api_braintreegateway_com.ca.crt +191 -0
  181. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/phpunit.xml.dist +24 -0
  182. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/Braintree/CreditCardDefaults.php +8 -0
  183. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/Braintree/CreditCardNumbers/CardTypeIndicators.php +15 -0
  184. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/Braintree/OAuthTestHelper.php +35 -0
  185. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/Helper.php +260 -0
  186. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/SanityTest.php +20 -0
  187. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/Setup.php +32 -0
  188. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/AddOnsTest.php +88 -0
  189. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/AddressTest.php +311 -0
  190. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/ClientTokenTest.php +189 -0
  191. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/CreditCardTest.php +1325 -0
  192. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/CreditCardVerificationAdvancedSearchTest.php +259 -0
  193. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/CreditCardVerificationTest.php +56 -0
  194. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/CustomerAdvancedSearchTest.php +199 -0
  195. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/CustomerTest.php +1592 -0
  196. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/DisbursementTest.php +39 -0
  197. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/DiscountTest.php +88 -0
  198. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/Error/ErrorCollectionTest.php +96 -0
  199. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/Error/ValidationErrorCollectionTest.php +75 -0
  200. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/EuropeBankAccountTest.php +54 -0
  201. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/HttpClientApi.php +130 -0
  202. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/HttpTest.php +148 -0
  203. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/IdealPaymentTest.php +93 -0
  204. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/MasterpassCardTest.php +128 -0
  205. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/MerchantAccountTest.php +631 -0
  206. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/MerchantTest.php +257 -0
  207. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/MultipleValueNodeTest.php +94 -0
  208. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/OAuthTest.php +324 -0
  209. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/PayPalAccountTest.php +309 -0
  210. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/PaymentMethodNonceTest.php +79 -0
  211. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/PaymentMethodTest.php +1668 -0
  212. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/PlanTest.php +132 -0
  213. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/Result/ErrorTest.php +33 -0
  214. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/SettlementBatchSummaryTest.php +95 -0
  215. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/SubscriptionHelper.php +86 -0
  216. wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/SubscriptionSearchTest.php +460 -0
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: JustinSainton
3
  Donate link: https://wpecommerce.org
4
  Tags: e-commerce, digital downloads, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax
5
  Requires at least: 4.5
6
- Tested up to: 4.8.2
7
- Stable tag: 3.12.4
8
 
9
  WP eCommerce is a free, powerful plugin that empowers you to sell anything online, quickly and easily.
10
 
@@ -36,6 +36,13 @@ After upgrading from earlier versions look for link "Update Store". This will up
36
 
37
  == Changelog ==
38
 
 
 
 
 
 
 
 
39
  = 3.12.4 [2017-9-23] =
40
 
41
  * Fix: Disable Theme Engine V2 by default. (Not yet released)
3
  Donate link: https://wpecommerce.org
4
  Tags: e-commerce, digital downloads, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax
5
  Requires at least: 4.5
6
+ Tested up to: 4.9
7
+ Stable tag: 3.13.0
8
 
9
  WP eCommerce is a free, powerful plugin that empowers you to sell anything online, quickly and easily.
10
 
36
 
37
  == Changelog ==
38
 
39
+ = 3.13.0 [2017-10-25] =
40
+
41
+ * New: Now including PayPal's Braintree payment gateway by default.
42
+ * Fix: Various PHP notices related to custom taxonomies have been resolved.
43
+ * Fix: Edge cases where shipping methods could be disabled, caused by poorly written Shipwire code, have been resolved.
44
+ * Fix: Custom instructions in 3.0 Manual Gateway are now included in the receipt page and emails.
45
+
46
  = 3.12.4 [2017-9-23] =
47
 
48
  * Fix: Disable Theme Engine V2 by default. (Not yet released)
wp-shopping-cart.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WP eCommerce
4
  * Plugin URI: http://wpecommerce.org/
5
  * Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://wpecommerce.org" target="_blank">WPeCommerce.org</a> | <a href="https://wordpress.org/support/plugin/wp-e-commerce/" target="_blank">Support Forum</a> | <a href="http://docs.wpecommerce.org/" target="_blank">Documentation</a>
6
- * Version: 3.12.4
7
  * Author: WP eCommerce
8
  * Author URI: http://wpecommerce.org/
9
  * Text Domain: wp-e-commerce
3
  * Plugin Name: WP eCommerce
4
  * Plugin URI: http://wpecommerce.org/
5
  * Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://wpecommerce.org" target="_blank">WPeCommerce.org</a> | <a href="https://wordpress.org/support/plugin/wp-e-commerce/" target="_blank">Support Forum</a> | <a href="http://docs.wpecommerce.org/" target="_blank">Documentation</a>
6
+ * Version: 3.13.0
7
  * Author: WP eCommerce
8
  * Author URI: http://wpecommerce.org/
9
  * Text Domain: wp-e-commerce
wpsc-admin/includes/settings-tabs/shipping.php CHANGED
@@ -195,7 +195,10 @@ class WPSC_Settings_Tab_Shipping extends WPSC_Settings_Tab {
195
  </tr>
196
  <tr>
197
  <th><?php esc_html_e( 'Use Test Server?', 'wp-e-commerce' ); ?></th>
198
- <td><input type="checkbox" name='wpsc_options[shipwire_test_server]' value="0" <?php checked( '1', get_option( 'shipwire_test_server', '0' ) ); ?> /></td>
 
 
 
199
  </tr>
200
  <tr>
201
  <th><?php esc_html_e( 'Force Sync with Shipwire', 'wp-e-commerce' ); ?></th>
195
  </tr>
196
  <tr>
197
  <th><?php esc_html_e( 'Use Test Server?', 'wp-e-commerce' ); ?></th>
198
+ <td>
199
+ <input <?php checked( get_option( 'shipwire_test_server', '0' ) ); ?> type="radio" name="wpsc_options[shipwire_test_server]" value="1" /> <?php _e( 'Yes', 'wp-e-commerce' ); ?>
200
+ <input <?php checked( (bool) get_option( 'shipwire_test_server', '0' ), false ); ?> type="radio" name="wpsc_options[shipwire_test_server]" value="0" /> <?php _e( 'No', 'wp-e-commerce' ); ?>
201
+ </td>
202
  </tr>
203
  <tr>
204
  <th><?php esc_html_e( 'Force Sync with Shipwire', 'wp-e-commerce' ); ?></th>
wpsc-admin/js/settings-page.js CHANGED
@@ -990,7 +990,7 @@
990
  action : 'sync_shipwire_products',
991
  email : $('input[name="wpsc_options[shipwireemail]"]').val(),
992
  password : $('input[name="wpsc_options[shipwirepassword]"]').val(),
993
- server : $('input[name="wpsc_options[shipwire_test_server]"]').val(),
994
  nonce : WPSC_Settings_Page.shipping_module_settings_form_nonce
995
  },
996
  ajax_callback = function(response) {
990
  action : 'sync_shipwire_products',
991
  email : $('input[name="wpsc_options[shipwireemail]"]').val(),
992
  password : $('input[name="wpsc_options[shipwirepassword]"]').val(),
993
+ server : $('input[name="wpsc_options[shipwire_test_server]"]:checked').val(),
994
  nonce : WPSC_Settings_Page.shipping_module_settings_form_nonce
995
  },
996
  ajax_callback = function(response) {
wpsc-components/merchant-core-v2/helpers/gateways.php CHANGED
@@ -282,7 +282,7 @@ function _wpsc_action_merchant_v2_validate_payment_method( $valid, $controller )
282
  'cctype',
283
  );
284
 
285
- $selected_gateway = $_POST['wpsc_payment_method'];
286
  if (
287
  ! isset( $_POST['extra_form'] )
288
  || ! isset( $_POST['extra_form'][$selected_gateway] )
282
  'cctype',
283
  );
284
 
285
+ $selected_gateway = isset( $_POST['wpsc_payment_method'] ) && $_POST['wpsc_payment_method'] ? $_POST['wpsc_payment_method'] : '';
286
  if (
287
  ! isset( $_POST['extra_form'] )
288
  || ! isset( $_POST['extra_form'][$selected_gateway] )
wpsc-components/merchant-core-v3/classes/payment-gateway.php CHANGED
@@ -235,7 +235,7 @@ final class WPSC_Payment_Gateways {
235
  $classname = ucwords( str_replace( '-', ' ', $filename ) );
236
  $classname = 'WPSC_Payment_Gateway_' . str_replace( ' ', '_', $classname );
237
 
238
- if ( file_exists( $file ) ) {
239
  require_once $file;
240
  }
241
 
235
  $classname = ucwords( str_replace( '-', ' ', $filename ) );
236
  $classname = 'WPSC_Payment_Gateway_' . str_replace( ' ', '_', $classname );
237
 
238
+ if ( file_exists( $file ) && ! class_exists( $classname ) ) {
239
  require_once $file;
240
  }
241
 
wpsc-components/merchant-core-v3/gateways/braintree-credit-cards.php ADDED
@@ -0,0 +1,561 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class WPSC_Payment_Gateway_Braintree_Credit_Cards extends WPSC_Payment_Gateway {
3
+
4
+ public function __construct() {
5
+ require_once( WPSC_MERCHANT_V3_SDKS_PATH . '/pp-braintree/pp-braintree.php' );
6
+ parent::__construct();
7
+
8
+ $this->helpers = WPEC_Braintree_Helpers::get_instance();
9
+ $this->title = __( 'PayPal powered by Braintree - Cards', 'wp-e-commerce' );
10
+ $this->image = WPSC_URL . '/images/cc.gif';
11
+ $this->supports = array( 'default_credit_card_form', 'tokenization', 'tev1', 'auth-capture', 'refunds' );
12
+ $this->sandbox = $this->setting->get( 'sandbox' ) == '1' ? true : false;
13
+ $this->payment_capture = $this->setting->get( 'payment_capture' ) !== null ? $this->setting->get( 'payment_capture' ) : 'standard';
14
+ // Define user set variables
15
+ }
16
+
17
+ public function init() {
18
+ parent::init();
19
+
20
+ // Disable if not setup using BT Auth
21
+ if ( ! $this->helpers::is_gateway_setup( 'braintree-credit-cards' ) ) {
22
+ // Remove gateway if its not setup properly
23
+ add_filter( 'wpsc_get_active_gateways', array( $this, 'remove_gateways' ) );
24
+ add_filter( 'wpsc_payment_method_form_fields', array( $this, 'remove_gateways_v2' ), 999 );
25
+ }
26
+
27
+ // Tev1 fields
28
+ add_action( 'wpsc_tev1_default_credit_card_form_fields_braintree-credit-cards', array( $this, 'tev1_checkout_fields'), 10, 2 );
29
+ add_action( 'wpsc_tev1_default_credit_card_form_end_braintree-credit-cards', array( $this, 'tev1_checkout_fields_extra') );
30
+ // Tev2 fields
31
+ add_filter( 'wpsc_default_credit_card_form_fields_braintree-credit-cards', array( $this, 'tev2_checkout_fields' ), 10, 2 );
32
+ add_action( 'wpsc_default_credit_card_form_end_braintree-credit-cards', array( $this, 'tev2_checkout_fields_extra' ) );
33
+ }
34
+
35
+ public function tev2_checkout_fields( $fields, $name ) {
36
+ unset($fields['card-name-field']);
37
+
38
+ $fields['card-number-field'] = '<p class="wpsc-form-row wpsc-form-row-wide wpsc-cc-field">
39
+ <label for="' . esc_attr( $name ) . '-card-number" class="bt-hosted-fields--label">' . __( 'Card Number', 'wp-e-commerce' ) . ' <span class="required">*</span></label>
40
+ <div id="braintree-credit-cards-card-number" class="bt-hosted-field"></div>
41
+ </p>';
42
+ $fields['card-expiry-field'] = '<p class="wpsc-form-row-middle wpsc-cc-field">
43
+ <label for="' . esc_attr( $name ) . '-card-expiry" class="bt-hosted-fields--label">' . __( 'Expiration Date', 'wp-e-commerce' ) . ' <span class="required">*</span></label>
44
+ <div id="braintree-credit-cards-card-expiry" class="bt-hosted-field"></div>
45
+ </p>';
46
+ $fields['card-cvc-field'] = '<p class="wpsc-form-row-last wpsc-cc-field">
47
+ <label for="' . esc_attr( $name ) . '-card-cvc" class="bt-hosted-fields--label">' . __( 'Card Code', 'wp-e-commerce' ) . ' <span class="required">*</span></label>
48
+ <div id="braintree-credit-cards-card-cvc" class="bt-hosted-field"></div></td>
49
+ </p>';
50
+
51
+ return $fields;
52
+ }
53
+
54
+ public function tev2_checkout_fields_extra( $name ) {
55
+ echo '<div id="pp-btree-hosted-fields-modal" class="pp-btree-hosted-fields-modal-hidden" tabindex="-1">
56
+ <div class="pp-btree-hosted-fields-bt-mask"></div>
57
+ <div class="pp-btree-hosted-fields-bt-modal-frame">
58
+ <div class="pp-btree-hosted-fields-bt-modal-header">
59
+ <div class="header-text">Authentication</div>
60
+ </div>
61
+ <div class="pp-btree-hosted-fields-bt-modal-body"></div>
62
+ <div class="pp-btree-hosted-fields-bt-modal-footer"><a id="pp-btree-hosted-fields-text-close" href="#">Cancel</a></div>
63
+ </div>
64
+ </div>';
65
+ }
66
+
67
+ public function tev1_checkout_fields( $fields, $name ) {
68
+ unset( $fields['card-name-field'] );
69
+
70
+ $fields['card-number-field'] = '<tr><td class="wpsc-form-row wpsc-form-row-wide wpsc-cc-field">
71
+ <label for="' . esc_attr( $name ) . '-card-number" class="bt-hosted-fields--label">' . __( 'Card Number', 'wp-e-commerce' ) . ' <span class="required">*</span></label></td>
72
+ <td><div id="braintree-credit-cards-card-number" class="bt-hosted-field"></div></td>
73
+ </tr>';
74
+ $fields['card-expiry-field'] = '<tr><td class="wpsc-form-row-middle wpsc-cc-field">
75
+ <label for="' . esc_attr( $name ) . '-card-expiry" class="bt-hosted-fields--label">' . __( 'Expiration Date', 'wp-e-commerce' ) . ' <span class="required">*</span></label></td>
76
+ <td><div id="braintree-credit-cards-card-expiry" class="bt-hosted-field"></div></td>
77
+ </tr>';
78
+ $fields['card-cvc-field'] = '<tr><td class="wpsc-form-row-last wpsc-cc-field">
79
+ <label for="' . esc_attr( $name ) . '-card-cvc" class="bt-hosted-fields--label">' . __( 'Card Code', 'wp-e-commerce' ) . ' <span class="required">*</span></label></td>
80
+ <td><div id="braintree-credit-cards-card-cvc" class="bt-hosted-field"></div></td>
81
+ </tr>';
82
+
83
+ return $fields;
84
+ }
85
+
86
+ public function tev1_checkout_fields_extra( $name ) {
87
+ $output = '';
88
+
89
+ $output .= '
90
+ <div id="pp-btree-hosted-fields-modal" class="pp-btree-hosted-fields-modal-hidden" tabindex="-1">
91
+ <div class="pp-btree-hosted-fields-bt-mask"></div>
92
+ <div class="pp-btree-hosted-fields-bt-modal-frame">
93
+ <div class="pp-btree-hosted-fields-bt-modal-header">
94
+ <div class="header-text">Authentication</div>
95
+ </div>
96
+ <div class="pp-btree-hosted-fields-bt-modal-body"></div>
97
+ <div class="pp-btree-hosted-fields-bt-modal-footer"><a id="pp-btree-hosted-fields-text-close" href="#">Cancel</a></div>
98
+ </div>
99
+ </div>';
100
+
101
+ echo $output;
102
+ }
103
+
104
+ public function process() {
105
+ global $braintree_settings;
106
+
107
+ $order = $this->purchase_log;
108
+ $purchase_log = new WPSC_Purchase_Log( $order->get('sessionid'), 'sessionid' );
109
+
110
+ $payment_method_nonce = $_POST['pp_btree_method_nonce'];
111
+ $kount_fraud = isset( $_POST['pp_btree_card_kount'] ) ? strip_tags( trim ( $_POST['pp_btree_card_kount'] ) ) : '';
112
+
113
+ if ( $this->setting->get( 'settlement' ) == 'upfront' ) {
114
+ $submit_for_settlement = true;
115
+ } else {
116
+ $submit_for_settlement = false;
117
+ }
118
+
119
+ $order_status = $submit_for_settlement === true ? WPSC_Purchase_Log::ACCEPTED_PAYMENT : WPSC_Purchase_Log::ORDER_RECEIVED;
120
+
121
+ // Check 3DS transaction.
122
+ $threedcheck = true;
123
+ $braintree_threedee_secure = $this->setting->get('three_d_secure');
124
+ $force3ds = false;
125
+ if ( '1' == $braintree_threedee_secure ) {
126
+ $force3ds = true;
127
+ $threedcheck = $this->check_3ds_risk_transaction( $payment_method_nonce );
128
+ }
129
+
130
+ if ( ! $threedcheck ) {
131
+ // 3DS check failed so return;
132
+ $error = __( '3D Secure verification failed.', 'wp-e-commerce' );
133
+ $order->set( 'processed', WPSC_Purchase_Log::INCOMPLETE_SALE )->save();
134
+ $order->add_note( $error );
135
+ $this->helpers::set_payment_error_message( $error );
136
+ wp_safe_redirect( $this->get_shopping_cart_payment_url() );
137
+ }
138
+
139
+ $phone_field = $this->checkout_data->get('billingphone');
140
+
141
+ $country = new WPSC_Country( $this->checkout_data->get('shippingcountry') );
142
+ if ( $country->has_regions() ) {
143
+ $shipping_state = wpsc_get_state_by_id( wpsc_get_customer_meta( '_wpsc_cart.delivery_region' ), 'code' );
144
+ } else {
145
+ $shipping_state = $this->checkout_data->get('shippingstate');
146
+ }
147
+
148
+ $params = array(
149
+ 'amount' => $order->get('totalprice'),
150
+ 'channel' => 'WPec_Cart_PPpbBT',
151
+ 'orderId' => $order->get('id'),
152
+ 'paymentMethodNonce' => $payment_method_nonce,
153
+ 'customer' => array(
154
+ 'firstName' => $this->checkout_data->get('billingfirstname'),
155
+ 'lastName' => $this->checkout_data->get('billinglastname'),
156
+ 'phone' => isset( $phone_field ) ? $phone_field : '',
157
+ 'email' => $this->checkout_data->get('billingemail'),
158
+ ),
159
+ 'billing' => array(
160
+ 'firstName' => $this->checkout_data->get('billingfirstname'),
161
+ 'lastName' => $this->checkout_data->get('billinglastname'),
162
+ 'streetAddress' => $this->checkout_data->get('billingaddress'),
163
+ 'locality' => $this->checkout_data->get('billingcity'),
164
+ 'region' => wpsc_get_state_by_id( wpsc_get_customer_meta( '_wpsc_cart.billing_region' ), 'code' ),
165
+ 'postalCode' => $this->checkout_data->get('billingpostcode'),
166
+ 'countryCodeAlpha2' => $this->checkout_data->get('billingcountry'),
167
+ ),
168
+ 'shipping' => array(
169
+ 'firstName' => $this->checkout_data->get('shippingfirstname'),
170
+ 'lastName' => $this->checkout_data->get('shippinglastname'),
171
+ 'streetAddress' => $this->checkout_data->get('shippingaddress'),
172
+ 'locality' => $this->checkout_data->get('shippingcity'),
173
+ 'region' => $shipping_state,
174
+ 'postalCode' => $this->checkout_data->get('shippingpostcode'),
175
+ 'countryCodeAlpha2' => $this->checkout_data->get('shippingcountry'),
176
+ ),
177
+ 'options' => array(
178
+ 'submitForSettlement' => $submit_for_settlement,
179
+ 'threeDSecure' => array(
180
+ 'required' => $force3ds,
181
+ ),
182
+ ),
183
+ 'deviceData' => $kount_fraud,
184
+ );
185
+
186
+ if ( $this->helpers::bt_auth_is_connected() ) {
187
+ $acc_token = get_option( 'wpec_braintree_auth_access_token' );
188
+ $gateway = new Braintree_Gateway( array(
189
+ 'accessToken' => $acc_token,
190
+ ));
191
+ $result = $gateway->transaction()->sale( $params );
192
+ } else {
193
+ $this->helpers::setBraintreeConfiguration();
194
+ $result = Braintree_Transaction::sale( $params );
195
+ }
196
+
197
+ // In theory all error handling should be done on the client side...?
198
+ if ( $result->success ) {
199
+ // Payment complete
200
+ $order->set( 'processed', $order_status )->save();
201
+ $order->set( 'transactid', $result->transaction->id )->save();
202
+
203
+ if ( false === $submit_for_settlement ) {
204
+ // Order is authorized
205
+ $order->set( 'bt_order_status' , 'Open' )->save();
206
+ $order->add_note( __( 'Order opened. Capture the payment below.', 'wp-e-commerce' ) )->save();
207
+ }
208
+
209
+ $this->go_to_transaction_results();
210
+ } else {
211
+ if ( $result->transaction ) {
212
+ $order->set( 'processed', WPSC_Purchase_Log::INCOMPLETE_SALE )->save();
213
+ $error = $this->helpers::get_failure_status_info( $result, 'message' );
214
+ $this->helpers::set_payment_error_message( $error );
215
+ wp_safe_redirect( $this->get_shopping_cart_payment_url() );
216
+ } else {
217
+ $error = "Payment Error: " . $result->message;
218
+
219
+ $this->helpers::set_payment_error_message( $error );
220
+ wp_safe_redirect( $this->get_shopping_cart_payment_url() );
221
+ }
222
+ }
223
+ exit;
224
+ }
225
+
226
+ public function check_3ds_risk_transaction( $nonce ) {
227
+ $pp_3ds_risk = $this->setting->get( 'three_d_secure_risk' ) != false ? $this->setting->get( 'three_d_secure_risk' ) : 'standard' ;
228
+ $auth_3ds = false;
229
+
230
+ if ( $this->helpers::bt_auth_can_connect() && $this->helpers::bt_auth_is_connected() ) {
231
+ $acc_token = get_option( 'wpec_braintree_auth_access_token' );
232
+
233
+ $gateway = new Braintree_Gateway( array(
234
+ 'accessToken' => $acc_token,
235
+ ));
236
+
237
+ $auth_3ds = true;
238
+ }
239
+
240
+ try {
241
+ $paymentMethodNonce = $auth_3ds ? $gateway->PaymentMethodNonce()->find( $nonce ) : Braintree_PaymentMethodNonce::find( $nonce );
242
+ } catch (Braintree_Exception_NotFound $e) {
243
+ echo 'Caught exception: ', $e->getMessage(), "\n";
244
+ exit;
245
+ }
246
+
247
+ $info = $paymentMethodNonce->threeDSecureInfo;
248
+
249
+ if ( empty( $info ) ) {
250
+ return true;
251
+ }
252
+
253
+ // Level should be 'strict' or 'standard'
254
+ $level = $pp_3ds_risk;
255
+
256
+ $matrix = array(
257
+ 'standard' => array(
258
+ 'unsupported_card' => true,
259
+ 'lookup_error' => true,
260
+ 'lookup_enrolled' => true,
261
+ 'authenticate_successful_issuer_not_participating' => true,
262
+ 'authentication_unavailable' => true,
263
+ 'authenticate_signature_verification_failed' => false,
264
+ 'authenticate_successful' => true,
265
+ 'authenticate_attempt_successful' => true,
266
+ 'authenticate_failed' => false,
267
+ 'authenticate_unable_to_authenticate' => true,
268
+ 'authenticate_error' => true,
269
+ ),
270
+ 'strict' => array(
271
+ 'unsupported_card' => false,
272
+ 'lookup_error' => false,
273
+ 'lookup_enrolled' => true,
274
+ 'authenticate_successful_issuer_not_participating' => true,
275
+ 'authentication_unavailable' => false,
276
+ 'authenticate_signature_verification_failed' => false,
277
+ 'authenticate_successful' => true,
278
+ 'authenticate_attempt_successful' => true,
279
+ 'authenticate_failed' => false,
280
+ 'authenticate_unable_to_authenticate' => false,
281
+ 'authenticate_error' => false,
282
+ )
283
+ );
284
+
285
+ return apply_filters( 'wpec_braintree_3ds_pass_or_fail', $matrix[ $level ][ $info->status ], $level );
286
+ }
287
+
288
+ public function capture_payment( $log, $transaction_id ) {
289
+
290
+ if ( $log->get( 'gateway' ) == 'braintree-credit-cards' && $log->get( 'bt_order_status' ) == 'Open' ) {
291
+
292
+ $transaction_id = $log->get( 'transactid' );
293
+ $log->get( 'totalprice' );
294
+
295
+ if ( $this->helpers::bt_auth_can_connect() && $this->helpers::bt_auth_is_connected() ) {
296
+ $acc_token = get_option( 'wpec_braintree_auth_access_token' );
297
+
298
+ $gateway = new Braintree_Gateway( array(
299
+ 'accessToken' => $acc_token,
300
+ ));
301
+ $result = $gateway->transaction()->submitForSettlement( $transaction_id );
302
+ } else {
303
+ $this->helpers::setBraintreeConfiguration();
304
+ $result = Braintree_Transaction::submitForSettlement( $transaction_id );
305
+ }
306
+
307
+ if ( $result->success ) {
308
+ $log->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT )->save();
309
+ $log->set( 'bt_order_status' , 'Completed' )->save();
310
+
311
+ return true;
312
+ } else {
313
+ return false;
314
+ }
315
+ }
316
+ return false;
317
+ }
318
+
319
+ public function process_refund( $log, $amount = 0.00, $reason = '', $manual = false ) {
320
+ if ( $log->get( 'gateway' ) == 'braintree-credit-cards' ) {
321
+
322
+ // Check if its a void
323
+ if ( $log->get( 'bt_order_status' ) == 'Open' ) {
324
+ // Process a Void on the Authorization
325
+ $transaction_id = $log->get( 'transactid' );
326
+
327
+ if ( $this->helpers::bt_auth_can_connect() && $this->helpers::bt_auth_is_connected() ) {
328
+ $acc_token = get_option( 'wpec_braintree_auth_access_token' );
329
+
330
+ $gateway = new Braintree_Gateway( array(
331
+ 'accessToken' => $acc_token,
332
+ ));
333
+ $result = $gateway->transaction()->void( $transaction_id );
334
+ } else {
335
+ $this->helpers::setBraintreeConfiguration();
336
+ $result = Braintree_Transaction::void( $transaction_id );
337
+ }
338
+
339
+ if ( $result->success ) {
340
+ // Set a log meta entry, and save log before adding refund note.
341
+ $log->set( 'processed', WPSC_Purchase_Log::INCOMPLETE_SALE )->save();
342
+ $log->set( 'total_order_refunded' , $log->get( 'totalprice' ) )->save();
343
+ $log->add_note( __( 'Authorization voided.', 'wp-e-commerce' ) )->save();
344
+ $log->set( 'bt_order_status', 'Voided' )->save();
345
+
346
+ remove_action( 'wpsc_order_fully_refunded', 'wpsc_update_order_status_fully_refunded' );
347
+
348
+ return true;
349
+ } else {
350
+ return false;
351
+ }
352
+ }
353
+ // End Void code block
354
+
355
+ if ( 0.00 == $amount ) {
356
+ return new WP_Error( 'braintree_credit_cards_refund_error', __( 'Refund Error: You need to specify a refund amount.', 'wp-e-commerce' ) );
357
+ }
358
+
359
+ $log = wpsc_get_order( $log );
360
+
361
+ if ( ! $log->get( 'transactid' ) ) {
362
+ return new WP_Error( 'error', __( 'Refund Failed: No transaction ID', 'wp-e-commerce' ) );
363
+ }
364
+
365
+ $max_refund = $log->get( 'totalprice' ) - $log->get_total_refunded();
366
+
367
+ if ( $amount && $max_refund < $amount || 0 > $amount ) {
368
+ throw new Exception( __( 'Invalid refund amount', 'wp-e-commerce' ) );
369
+ }
370
+
371
+ if ( $manual ) {
372
+ $current_refund = $log->get_total_refunded();
373
+
374
+ // Set a log meta entry, and save log before adding refund note.
375
+ $log->set( 'total_order_refunded' , $amount + $current_refund )->save();
376
+ $log->set( 'bt_order_status', 'Refunded' )->save();
377
+
378
+ $log->add_refund_note(
379
+ sprintf( __( 'Refunded %s via Manual Refund', 'wp-e-commerce' ), wpsc_currency_display( $amount ) ),
380
+ $reason
381
+ );
382
+
383
+ return true;
384
+ }
385
+
386
+ $transaction_id = $log->get( 'transactid' );
387
+
388
+ if ( $this->helpers::bt_auth_can_connect() && $this->helpers::bt_auth_is_connected() ) {
389
+ $acc_token = get_option( 'wpec_braintree_auth_access_token' );
390
+
391
+ $gateway = new Braintree_Gateway( array(
392
+ 'accessToken' => $acc_token,
393
+ ));
394
+ $result = $gateway->transaction()->refund( $transaction_id );
395
+ } else {
396
+ $this->helpers::setBraintreeConfiguration();
397
+ $result = Braintree_Transaction::refund( $transaction_id );
398
+ }
399
+
400
+ if ( $result->success ) {
401
+
402
+ $current_refund = $log->get_total_refunded();
403
+
404
+ // Set a log meta entry, and save log before adding refund note.
405
+ $log->set( 'total_order_refunded' , $amount + $current_refund )->save();
406
+ $log->set( 'bt_order_status', 'Refunded' )->save();
407
+
408
+ return true;
409
+ } else {
410
+ return false;
411
+ }
412
+ }
413
+
414
+ return false;
415
+ }
416
+
417
+ public function manual_credentials( $hide = false ) {
418
+ $hidden = $hide ? ' style="display:none;"' : '';
419
+ ?>
420
+ <!-- Account Credentials -->
421
+ <tr id="bt-cc-manual-header">
422
+ <td colspan="2">
423
+ <h4><?php _e( 'Account Credentials', 'wp-e-commerce' ); ?></h4>
424
+ </td>
425
+ </tr>
426
+ <tr id="bt-cc-manual-public-key">
427
+ <td>
428
+ <label for="wpsc-worldpay-secure-net-id"><?php _e( 'Public Key', 'wp-e-commerce' ); ?></label>
429
+ </td>
430
+ <td>
431
+ <input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'public_key' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'public_key' ) ); ?>" id="wpsc-anet-api-id" />
432
+ </td>
433
+ </tr>
434
+ <tr id="bt-cc-manual-private-key">
435
+ <td>
436
+ <label for="wpsc-worldpay-secure-key"><?php _e( 'Private Key', 'wp-e-commerce' ); ?></label>
437
+ </td>
438
+ <td>
439
+ <input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'private_key' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'private_key' ) ); ?>" id="wpsc-anet-trans-key" />
440
+ </td>
441
+ </tr>
442
+ <tr id="bt-cc-manual-merchant-id">
443
+ <td>
444
+ <label for="wpsc-worldpay-secure-key"><?php _e( 'Merchant ID', 'wp-e-commerce' ); ?></label>
445
+ </td>
446
+ <td>
447
+ <input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'merchant_id' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'merchant_id' ) ); ?>" id="wpsc-anet-trans-key" />
448
+ </td>
449
+ </tr>
450
+ <tr id="bt-cc-manual-sandbox">
451
+ <td>
452
+ <label><?php _e( 'Sandbox Mode', 'wp-e-commerce' ); ?></label>
453
+ </td>
454
+ <td>
455
+ <label><input <?php checked( $this->setting->get( 'sandbox' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'sandbox' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wp-e-commerce' ); ?></label>&nbsp;&nbsp;&nbsp;
456
+ <label><input <?php checked( (bool) $this->setting->get( 'sandbox' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'sandbox' ) ); ?>" value="0" /> <?php _e( 'No', 'wp-e-commerce' ); ?></label>
457
+ </td>
458
+ </tr>
459
+ <?php
460
+ }
461
+
462
+
463
+ public function setup_form() {
464
+ if ( $this->helpers::bt_auth_can_connect() ) {
465
+ echo $this->helpers::show_connect_button();
466
+ } else {
467
+ $this->manual_credentials(true);
468
+ }
469
+ ?>
470
+ <tr>
471
+ <td colspan="2">
472
+ <h4><?php _e( 'Transaction Settings', 'wp-e-commerce' ); ?></h4>
473
+ </td>
474
+ </tr>
475
+ <tr>
476
+ <td>
477
+ <label for="wpsc-worldpay-secure-key"><?php _e( 'Settlement Type', 'wp-e-commerce' ); ?></label>
478
+ </td>
479
+ <td>
480
+ <select id="wpsc-worldpay-payment-capture" name="<?php echo esc_attr( $this->setting->get_field_name( 'settlement' ) ); ?>">
481
+ <option value='upfront' <?php selected( 'upfront', $this->setting->get( 'settlement' ) ); ?>><?php _e( 'Upfront Settlement', 'wp-e-commerce' )?></option>
482
+ <option value='deferred' <?php selected( 'deferred', $this->setting->get( 'settlement' ) ); ?>><?php _e( 'Deferred Settlement', 'wp-e-commerce' )?></option>
483
+ </select>
484
+ </td>
485
+ </tr>
486
+ <tr>
487
+ <td colspan="2">
488
+ <h4><?php _e( '3D Secure Settings', 'wp-e-commerce' ); ?></h4>
489
+ </td>
490
+ </tr>
491
+ <tr>
492
+ <td>
493
+ <label for="wpsc-worldpay-secure-key"><?php _e( '3D Secure Enabled', 'wp-e-commerce' ); ?></label>
494
+ </td>
495
+ <td>
496
+ <label><input <?php checked( $this->setting->get( 'three_d_secure' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'three_d_secure' ) ); ?>" value="1" disabled /> <?php _e( 'Yes', 'wp-e-commerce' ); ?></label>&nbsp;&nbsp;&nbsp;
497
+ <label><input <?php checked( (bool) $this->setting->get( 'three_d_secure' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'three_d_secure' ) ); ?>" value="0" disabled /> <?php _e( 'No', 'wp-e-commerce' ); ?></label>
498
+ <p class="description"><?php _e( 'You can change 3D Secure settings from within your Braintree account settings.', 'wpsc' ); ?></p>
499
+ </td>
500
+ </tr>
501
+ <tr>
502
+ <td>
503
+ <label for="wpsc-worldpay-secure-key"><?php _e( 'Allow only 3D Secure', 'wp-e-commerce' ); ?></label>
504
+ </td>
505
+ <td>
506
+ <label><input <?php checked( $this->setting->get( 'three_d_secure_only' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'three_d_secure_only' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wp-e-commerce' ); ?></label>&nbsp;&nbsp;&nbsp;
507
+ <label><input <?php checked( (bool) $this->setting->get( 'three_d_secure_only' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'three_d_secure_only' ) ); ?>" value="0" /> <?php _e( 'No', 'wp-e-commerce' ); ?></label>
508
+ <p class="description"><?php _e( 'Only transactions that pass 3D Secure verifications are allowed to be processed', 'wpsc' ); ?></p>
509
+ </td>
510
+ </tr>
511
+ <tr>
512
+ <td>
513
+ <label for="wpsc-worldpay-payment-capture"><?php _e( '3D Secure Risk Settings', 'wp-e-commerce' ); ?></label>
514
+ </td>
515
+ <td>
516
+ <select id="wpsc-worldpay-payment-capture" name="<?php echo esc_attr( $this->setting->get_field_name( 'three_d_secure_risk' ) ); ?>">
517
+ <option value='standard' <?php selected( 'standard', $this->setting->get( 'three_d_secure_risk' ) ); ?>><?php _e( 'Standard', 'wp-e-commerce' )?></option>
518
+ <option value='strict' <?php selected( 'strict', $this->setting->get( 'three_d_secure_risk' ) ); ?>><?php _e( 'Strict', 'wp-e-commerce' )?></option>
519
+ </select>
520
+ </td>
521
+ </tr>
522
+ <!-- Error Logging -->
523
+ <tr>
524
+ <td colspan="2">
525
+ <h4><?php _e( 'Error Logging', 'wp-e-commerce' ); ?></h4>
526
+ </td>
527
+ </tr>
528
+ <tr>
529
+ <td>
530
+ <label><?php _e( 'Enable Debugging', 'wp-e-commerce' ); ?></label>
531
+ </td>
532
+ <td>
533
+ <label><input <?php checked( $this->setting->get( 'debugging' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'debugging' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wp-e-commerce' ); ?></label>&nbsp;&nbsp;&nbsp;
534
+ <label><input <?php checked( (bool) $this->setting->get( 'debugging' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'debugging' ) ); ?>" value="0" /> <?php _e( 'No', 'wp-e-commerce' ); ?></label>
535
+ </td>
536
+ </tr>
537
+ <?php
538
+ }
539
+
540
+ public function get_image_url() {
541
+ return apply_filters( 'wpsc_braintree-credit-cards_logo', WPSC_URL . '/images/cc.gif' );
542
+ }
543
+
544
+ public function remove_gateways( $gateways ) {
545
+ foreach ( $gateways as $i => $gateway ) {
546
+ if ( 'braintree-credit-cards' == $gateway ) {
547
+ unset( $gateways[ $i ] );
548
+ }
549
+ }
550
+ return $gateways;
551
+ }
552
+
553
+ public function remove_gateways_v2( $fields ) {
554
+ foreach ( $fields as $i => $field ) {
555
+ if ( 'braintree-credit-cards' == $field['value'] ) {
556
+ unset( $fields[ $i ] );
557
+ }
558
+ }
559
+ return $fields;
560
+ }
561
+ }
wpsc-components/merchant-core-v3/gateways/braintree-paypal.php ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class WPSC_Payment_Gateway_Braintree_PayPal extends WPSC_Payment_Gateway {
3
+
4
+ public function __construct() {
5
+ require_once( WPSC_MERCHANT_V3_SDKS_PATH . '/pp-braintree/pp-braintree.php' );
6
+ parent::__construct();
7
+
8
+ $this->helpers = WPEC_Braintree_Helpers::get_instance();
9
+ $this->title = __( 'PayPal powered by Braintree - PayPal', 'wp-e-commerce' );
10
+ $this->supports = array( 'default_credit_card_form', 'tokenization', 'tev1' );
11
+ $this->sandbox = $this->setting->get( 'sandbox' ) == '1' ? true : false;
12
+ $this->but_size = $this->setting->get( 'but_size' ) !== null ? $this->setting->get( 'but_size' ) : $this->setting->set( 'but_size', 'responsive' );
13
+ $this->but_colour = $this->setting->get( 'but_colour' ) !== null ? $this->setting->get( 'but_colour' ) : $this->setting->set( 'but_colour', 'gold' );
14
+ $this->but_shape = $this->setting->get( 'but_shape' ) !== null ? $this->setting->get( 'but_shape' ) : $this->setting->set( 'but_shape', 'pill' );
15
+ }
16
+
17
+ public function init() {
18
+ parent::init();
19
+
20
+ // Disable if not setup using BT Auth
21
+ if ( ! $this->helpers::is_gateway_setup( 'braintree-paypal' ) ) {
22
+ // Remove gateway if its not setup properly
23
+ add_filter( 'wpsc_get_active_gateways', array( $this, 'remove_gateways' ) );
24
+ add_filter( 'wpsc_payment_method_form_fields', array( $this, 'remove_gateways_v2' ), 999 );
25
+ }
26
+
27
+ // Tev1 fields
28
+ add_filter( 'wpsc_tev1_default_credit_card_form_fields_braintree-paypal', array( $this, 'tev1_checkout_fields'), 10, 2 );
29
+ // Tev2 fields
30
+ add_filter( 'wpsc_default_credit_card_form_fields_braintree-paypal', array( $this, 'tev2_checkout_fields' ), 10, 2 );
31
+ }
32
+
33
+ public function tev2_checkout_fields( $fields, $name ) {
34
+ $fields = array();
35
+
36
+ $fields = array(
37
+ 'bt-pp-button' => '<p class="wpsc-form-row wpsc-form-row-wide wpsc-bt-pp-but-field">
38
+ <label for="' . esc_attr( $name ) . '-bt-pp-but">' . __( 'Click below to continue to PayPal', 'wp-e-commerce' ) . '</label>
39
+ <div id="pp_braintree_pp_button"></div>
40
+ </p>'
41
+ );
42
+
43
+ return $fields;
44
+ }
45
+
46
+ public function tev1_checkout_fields( $fields, $name ) {
47
+ $fields = array();
48
+
49
+ $fields = array(
50
+ 'bt-pp-button' => '<tr><td><p class="wpsc-form-row wpsc-form-row-wide wpsc-bt-pp-but-field">
51
+ <label for="' . esc_attr( $name ) . '-bt-pp-but">' . __( 'Click below to continue to PayPal', 'wp-e-commerce' ) . '</label></td></tr>
52
+ <tr><td><div id="pp_braintree_pp_button"></div></td></tr>'
53
+ );
54
+
55
+ return $fields;
56
+
57
+ }
58
+
59
+ /**
60
+ * submit method, sends the received data to the payment gateway
61
+ * @access public
62
+ */
63
+ public function process() {
64
+ global $braintree_settings;
65
+
66
+ WPEC_Braintree_Helpers::setBraintreeConfiguration('braintree-paypal');
67
+
68
+ $order = $this->purchase_log;
69
+ $payment_method_nonce = $_POST['pp_btree_method_nonce'];
70
+
71
+ $country = new WPSC_Country( $this->checkout_data->get('shippingcountry') );
72
+ if ( $country->has_regions() ) {
73
+ $shipping_state = wpsc_get_state_by_id( wpsc_get_customer_meta( '_wpsc_cart.delivery_region' ), 'code' );
74
+ } else {
75
+ $shipping_state = $this->checkout_data->get('shippingstate');
76
+ }
77
+
78
+ $phone_field = $this->checkout_data->get('billingphone');
79
+
80
+ $params = array(
81
+ 'amount' => $order->get('totalprice'),
82
+ 'channel' => 'WPec_Cart_PPpbBT',
83
+ 'orderId' => $order->get('id'),
84
+ 'paymentMethodNonce' => $payment_method_nonce,
85
+ 'customer' => array(
86
+ 'firstName' => $this->checkout_data->get('billingfirstname'),
87
+ 'lastName' => $this->checkout_data->get('billinglastname'),
88
+ 'phone' => isset( $phone_field ) ? $phone_field : '',
89
+ 'email' => $this->checkout_data->get('billingemail'),
90
+ ),
91
+ 'billing' => array(
92
+ 'firstName' => $this->checkout_data->get('billingfirstname'),
93
+ 'lastName' => $this->checkout_data->get('billinglastname'),
94
+ 'streetAddress' => $this->checkout_data->get('billingaddress'),
95
+ 'locality' => $this->checkout_data->get('billingcity'),
96
+ 'region' => wpsc_get_state_by_id( wpsc_get_customer_meta( '_wpsc_cart.billing_region' ), 'code' ),
97
+ 'postalCode' => $this->checkout_data->get('billingpostcode'),
98
+ 'countryCodeAlpha2' => $this->checkout_data->get('billingcountry'),
99
+ ),
100
+ 'shipping' => array(
101
+ 'firstName' => $this->checkout_data->get('shippingfirstname'),
102
+ 'lastName' => $this->checkout_data->get('shippinglastname'),
103
+ 'streetAddress' => $this->checkout_data->get('shippingaddress'),
104
+ 'locality' => $this->checkout_data->get('shippingcity'),
105
+ 'region' => $shipping_state,
106
+ 'postalCode' => $this->checkout_data->get('shippingpostcode'),
107
+ 'countryCodeAlpha2' => $this->checkout_data->get('shippingcountry'),
108
+ ),
109
+ 'options' => array(
110
+ 'submitForSettlement' => true,
111
+ ),
112
+ );
113
+
114
+ if ( $this->helpers::bt_auth_is_connected() ) {
115
+ $acc_token = get_option( 'wpec_braintree_auth_access_token' );
116
+ $gateway = new Braintree_Gateway( array(
117
+ 'accessToken' => $acc_token,
118
+ ));
119
+
120
+ $result = $gateway->transaction()->sale( $params );
121
+ } else {
122
+ $this->helpers::setBraintreeConfiguration('braintree-paypal');
123
+ $result = Braintree_Transaction::sale( $params );
124
+ }
125
+
126
+ // In theory all error handling should be done on the client side...?
127
+ if ( $result->success ) {
128
+ // Payment complete
129
+ $order->set( 'processed', WPSC_Purchase_Log::ACCEPTED_PAYMENT )->save();
130
+ $order->set( 'transactid', $result->transaction->id )->save();
131
+ $this->go_to_transaction_results();
132
+ } else {
133
+ if ( $result->transaction ) {
134
+ $order->set( 'processed', WPSC_Purchase_Log::INCOMPLETE_SALE )->save();
135
+ $error = $this->helpers::get_failure_status_info( $result, 'message' );
136
+ $this->helpers::set_payment_error_message( $error );
137
+ wp_safe_redirect( $this->get_shopping_cart_payment_url() );
138
+ } else {
139
+ $error = "Payment Error: " . $result->message;
140
+
141
+ $this->helpers::set_payment_error_message( $error );
142
+ wp_safe_redirect( $this->get_shopping_cart_payment_url() );
143
+ }
144
+ }
145
+ exit();
146
+ }
147
+
148
+ public function manual_credentials( $hide = false ) {
149
+ $hidden = $hide ? ' style="display:none;"' : '';
150
+ ?>
151
+ <!-- Account Credentials -->
152
+ <tr id="bt-pp-manual-header">
153
+ <td colspan="2">
154
+ <h4><?php _e( 'Account Credentials', 'wp-e-commerce' ); ?></h4>
155
+ </td>
156
+ </tr>
157
+ <tr id="bt-pp-manual-public-key">
158
+ <td>
159
+ <label for="wpsc-worldpay-secure-net-id"><?php _e( 'Public Key', 'wp-e-commerce' ); ?></label>
160
+ </td>
161
+ <td>
162
+ <input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'public_key' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'public_key' ) ); ?>" id="wpsc-anet-api-id" />
163
+ </td>
164
+ </tr>
165
+ <tr id="bt-pp-manual-private-key">
166
+ <td>
167
+ <label for="wpsc-worldpay-secure-key"><?php _e( 'Private Key', 'wp-e-commerce' ); ?></label>
168
+ </td>
169
+ <td>
170
+ <input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'private_key' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'private_key' ) ); ?>" id="wpsc-anet-trans-key" />
171
+ </td>
172
+ </tr>
173
+ <tr id="bt-pp-manual-merchant-id">
174
+ <td>
175
+ <label for="wpsc-worldpay-secure-key"><?php _e( 'Merchant ID', 'wp-e-commerce' ); ?></label>
176
+ </td>
177
+ <td>
178
+ <input type="text" name="<?php echo esc_attr( $this->setting->get_field_name( 'merchant_id' ) ); ?>" value="<?php echo esc_attr( $this->setting->get( 'merchant_id' ) ); ?>" id="wpsc-anet-trans-key" />
179
+ </td>
180
+ </tr>
181
+ <tr id="bt-pp-manual-sandbox">
182
+ <td>
183
+ <label><?php _e( 'Sandbox Mode', 'wp-e-commerce' ); ?></label>
184
+ </td>
185
+ <td>
186
+ <label><input <?php checked( $this->setting->get( 'sandbox' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'sandbox' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wp-e-commerce' ); ?></label>&nbsp;&nbsp;&nbsp;
187
+ <label><input <?php checked( (bool) $this->setting->get( 'sandbox' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'sandbox' ) ); ?>" value="0" /> <?php _e( 'No', 'wp-e-commerce' ); ?></label>
188
+ </td>
189
+ </tr>
190
+ <?php
191
+ }
192
+
193
+ /**
194
+ * Creates the Braintree PayPal configuration form in the admin section
195
+ * @return string
196
+ */
197
+ public function setup_form() {
198
+ if ( $this->helpers::bt_auth_can_connect() ) {
199
+ echo $this->helpers::show_connect_button();
200
+ } else {
201
+ $this->manual_credentials(true);
202
+ }
203
+ ?>
204
+ <tr>
205
+ <td colspan="2">
206
+ <h4><?php _e( 'Gateway Settings', 'wp-e-commerce' ); ?></h4>
207
+ </td>
208
+ </tr>
209
+ <tr>
210
+ <td>
211
+ <label for="wpsc-worldpay-secure-key"><?php _e( 'Button Size', 'wp-e-commerce' ); ?></label>
212
+ </td>
213
+ <td>
214
+ <select id="wpsc-worldpay-payment-capture" name="<?php echo esc_attr( $this->setting->get_field_name( 'but_size' ) ); ?>">
215
+ <option value='small' <?php selected( 'small', $this->setting->get( 'but_size' ) ); ?>><?php _e( 'Small', 'wp-e-commerce' )?></option>
216
+ <option value='medium' <?php selected( 'medium', $this->setting->get( 'but_size' ) ); ?>><?php _e( 'Medium', 'wp-e-commerce' )?></option>
217
+ <option value='responsive' <?php selected( 'responsive', $this->setting->get( 'but_size' ) ); ?>><?php _e( 'Responsive', 'wp-e-commerce' )?></option>
218
+ </select>
219
+ </td>
220
+ </tr>
221
+ <tr>
222
+ <td>
223
+ <label for="wpsc-worldpay-secure-key"><?php _e( 'Button Colour', 'wp-e-commerce' ); ?></label>
224
+ </td>
225
+ <td>
226
+ <select id="wpsc-worldpay-payment-capture" name="<?php echo esc_attr( $this->setting->get_field_name( 'but_colour' ) ); ?>">
227
+ <option value='gold' <?php selected( 'gold', $this->setting->get( 'but_colour' ) ); ?>><?php _e( 'Gold', 'wp-e-commerce' )?></option>
228
+ <option value='blue' <?php selected( 'blue', $this->setting->get( 'but_colour' ) ); ?>><?php _e( 'Blue', 'wp-e-commerce' )?></option>
229
+ <option value='silver' <?php selected( 'silver', $this->setting->get( 'but_colour' ) ); ?>><?php _e( 'Silver', 'wp-e-commerce' )?></option>
230
+ </select>
231
+ </td>
232
+ </tr>
233
+ <tr>
234
+ <td>
235
+ <label for="wpsc-worldpay-secure-key"><?php _e( 'Button Shape', 'wp-e-commerce' ); ?></label>
236
+ </td>
237
+ <td>
238
+ <select id="wpsc-worldpay-payment-capture" name="<?php echo esc_attr( $this->setting->get_field_name( 'but_shape' ) ); ?>">
239
+ <option value='pill' <?php selected( 'pill', $this->setting->get( 'but_shape' ) ); ?>><?php _e( 'Pill', 'wp-e-commerce' )?></option>
240
+ <option value='rect' <?php selected( 'rect', $this->setting->get( 'but_shape' ) ); ?>><?php _e( 'Rect', 'wp-e-commerce' )?></option>
241
+ </select>
242
+ </td>
243
+ </tr>
244
+ <!-- Error Logging -->
245
+ <tr>
246
+ <td colspan="2">
247
+ <h4><?php _e( 'Error Logging', 'wp-e-commerce' ); ?></h4>
248
+ </td>
249
+ </tr>
250
+ <tr>
251
+ <td>
252
+ <label><?php _e( 'Enable Debugging', 'wp-e-commerce' ); ?></label>
253
+ </td>
254
+ <td>
255
+ <label><input <?php checked( $this->setting->get( 'debugging' ) ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'debugging' ) ); ?>" value="1" /> <?php _e( 'Yes', 'wp-e-commerce' ); ?></label>&nbsp;&nbsp;&nbsp;
256
+ <label><input <?php checked( (bool) $this->setting->get( 'debugging' ), false ); ?> type="radio" name="<?php echo esc_attr( $this->setting->get_field_name( 'debugging' ) ); ?>" value="0" /> <?php _e( 'No', 'wp-e-commerce' ); ?></label>
257
+ </td>
258
+ </tr>
259
+ <?php
260
+ }
261
+
262
+ /**
263
+ * Returns the HTML of the logo of the payment gateway.
264
+ *
265
+ * @access public
266
+ * @return string
267
+ *
268
+ * @since 3.9.0
269
+ */
270
+ public function get_image_url() {
271
+ return apply_filters( 'wpsc_braintree-paypal_mark_html', 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/PP_logo_h_200x51.png' );
272
+ }
273
+
274
+ public function remove_gateways( $gateways ) {
275
+ foreach ( $gateways as $i => $gateway ) {
276
+ if ( 'braintree-paypal' == $gateway ) {
277
+ unset( $gateways[ $i ] );
278
+ }
279
+ }
280
+ return $gateways;
281
+ }
282
+
283
+ public function remove_gateways_v2( $fields ) {
284
+ foreach ( $fields as $i => $field ) {
285
+ if ( 'braintree-paypal' == $field['value'] ) {
286
+ unset( $fields[ $i ] );
287
+ }
288
+ }
289
+ return $fields;
290
+ }
291
+ }
wpsc-components/merchant-core-v3/gateways/manual.php CHANGED
@@ -11,7 +11,10 @@ class WPSC_Payment_Gateway_Manual extends WPSC_Payment_Gateway {
11
  $this->title = __( 'Manual Payment Gateway 3.0', 'wp-e-commerce' );
12
 
13
  parent::__construct();
14
- }
 
 
 
15
 
16
  /**
17
  * Displays the setup form
@@ -44,4 +47,23 @@ class WPSC_Payment_Gateway_Manual extends WPSC_Payment_Gateway {
44
  $this->purchase_log->set( 'processed', WPSC_PAYMENT_STATUS_RECEIVED )->save();
45
  $this->go_to_transaction_results();
46
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
11
  $this->title = __( 'Manual Payment Gateway 3.0', 'wp-e-commerce' );
12
 
13
  parent::__construct();
14
+
15
+ add_filter( 'wpsc_purchase_log_customer_notification_raw_message', array( $this, 'filter_message' ), 10, 2 );
16
+ add_filter( 'wpsc_purchase_log_customer_html_notification_raw_message', array( $this, 'filter_message' ), 10, 2 );
17
+ }
18
 
19
  /**
20
  * Displays the setup form
47
  $this->purchase_log->set( 'processed', WPSC_PAYMENT_STATUS_RECEIVED )->save();
48
  $this->go_to_transaction_results();
49
  }
50
+
51
+ /**
52
+ * Filter the customer notification emails
53
+ *
54
+ * @access public
55
+ * @since 4.0
56
+ * @uses WPSC_Payment_Gateway_Setting::get()
57
+ *
58
+ * @return array $message Modified message with extra instructions from gateway settings
59
+ */
60
+ public function filter_message( $message, $notification ) {
61
+ $purchase_log = $notification->get_purchase_log();
62
+
63
+ if ( $purchase_log->get('gateway') == 'manual' ) {
64
+ $message = $this->setting->get( 'payment_instructions' ) . "\r\n\r\n" . $message;
65
+ }
66
+
67
+ return $message;
68
+ }
69
  }
wpsc-components/merchant-core-v3/libraries/pp-braintree/assets/css/style.css ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pp-btree-hosted-fields-modal {
2
+ position: absolute;
3
+ top: 0;
4
+ left: 0;
5
+ display: flex;
6
+ align-items: center;
7
+ height: 100vh;
8
+ z-index: 100;
9
+ }
10
+ .pp-btree-hosted-fields-modal-hidden {
11
+ display: none !important;
12
+ }
13
+ .pp-btree-hosted-fields-bt-modal-frame {
14
+ height: 480px;
15
+ width: 440px;
16
+ margin: auto;
17
+ background-color: #eee;
18
+ z-index: 2;
19
+ border-radius: 6px;
20
+ }
21
+ .pp-btree-hosted-fields-bt-modal-body {
22
+ height: 400px;
23
+ margin: 0 20px;
24
+ background-color: white;
25
+ border: 1px solid lightgray;
26
+ }
27
+ .pp-btree-hosted-fields-bt-modal-header, .pp-btree-hosted-fields-bt-modal-footer {
28
+ height: 40px;
29
+ text-align: center;
30
+ line-height: 40px;
31
+ }
32
+ .pp-btree-hosted-fields-bt-mask {
33
+ position: fixed;
34
+ top: 0;
35
+ left: 0;
36
+ height: 100%;
37
+ width: 100%;
38
+ background-color: black;
39
+ opacity: 0.8;
40
+ }
41
+
42
+ /* Card fields styles */
43
+ .braintree-credit-cards tr,
44
+ .braintree-credit-cards td {
45
+ display: block;
46
+ width: 100% !important; //Necessary to override WPSC styling
47
+ }
48
+ .bt-hosted-field {
49
+ height: 50px;
50
+ box-sizing: border-box;
51
+ width: 100%;
52
+ padding: 12px;
53
+ display: inline-block;
54
+ box-shadow: none;
55
+ font-weight: 600;
56
+ font-size: 14px;
57
+ border-radius: 6px;
58
+ border: 1px solid #dddddd;
59
+ line-height: 20px;
60
+ background: #fcfcfc;
61
+ margin-bottom: 12px;
62
+ background: linear-gradient(to right, white 50%, #fcfcfc 50%);
63
+ background-size: 200% 100%;
64
+ background-position: right bottom;
65
+ transition: all 300ms ease-in-out;
66
+ }
67
+ .bt-hosted-fields--label {
68
+ font-family: courier, monospace;
69
+ text-transform: uppercase;
70
+ font-size: 17px;
71
+ display: block;
72
+ margin-bottom: 6px;
73
+ }
74
+ .braintree-hosted-fields-focused {
75
+ border: 1px solid #64d18a;
76
+ border-radius: 1px;
77
+ background-position: left bottom;
78
+ }
79
+
80
+ .braintree-hosted-fields-invalid {
81
+ border: 1px solid #ed574a;
82
+ }
83
+
84
+ .braintree-hosted-fields-valid {
85
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/assets/images/PP_logo_h_200x51.png ADDED
Binary file
wpsc-components/merchant-core-v3/libraries/pp-braintree/assets/js/admin.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ /*global jQuery*/
2
+ ( function($) {
3
+
4
+ } )( jQuery );
wpsc-components/merchant-core-v3/libraries/pp-braintree/assets/js/frontend.js ADDED
@@ -0,0 +1,407 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*global jQuery, wpec_ppbt */
2
+ ( function($) {
3
+ var clientToken = wpec_ppbt.ctoken;
4
+ var errmsg = '';
5
+ var components = {
6
+ client: null,
7
+ threeDSecure: null,
8
+ hostedFields: null,
9
+ paypalCheckout: null,
10
+ kount: null,
11
+ };
12
+
13
+ var gateway;
14
+ var my3DSContainer;
15
+ var modal = $('#pp-btree-hosted-fields-modal');
16
+ var closeFrame = $('#pp-btree-hosted-fields-text-close');
17
+ var bankFrame = $('.pp-btree-hosted-fields-bt-modal-body');
18
+ var cart_form = $( '#wpsc-checkout-form, .wpsc_checkout_forms' );
19
+ var submit_btn = $('.wpsc-checkout-form-button, .wpsc_buy_button');
20
+ var paypalButton = $('#pp_braintree_pp_button');
21
+
22
+ function create3DSecure( clientInstance ) {
23
+ // DO 3DS
24
+ if ( wpec_ppbt.t3ds == '1' ) {
25
+ braintree.threeDSecure.create({
26
+ client: clientInstance
27
+ }, function (threeDSecureErr, threeDSecureInstance) {
28
+ if (threeDSecureErr) {
29
+ // Handle error in 3D Secure component creation
30
+ console.error('error in 3D Secure component creation');
31
+ return;
32
+ }
33
+ components.threeDSecure = threeDSecureInstance;
34
+ });
35
+ }
36
+ }
37
+
38
+ function addFrame(err, iframe) {
39
+ // Set up your UI and add the iframe.
40
+ bankFrame.append(iframe);
41
+ modal.removeClass('pp-btree-hosted-fields-modal-hidden');
42
+ modal.focus();
43
+ }
44
+
45
+ function removeFrame() {
46
+ var iframe = $('.pp-btree-hosted-fields-bt-modal-body iframe');
47
+ modal.addClass('pp-btree-hosted-fields-modal-hidden');
48
+ $( iframe ).remove();
49
+ submit_btn.attr('disabled', false);
50
+ }
51
+
52
+ function createHostedFields( clientInstance ) {
53
+ braintree.hostedFields.create({
54
+ client: clientInstance,
55
+ styles: {
56
+ 'input': {
57
+ 'font-size': '14px',
58
+ 'font-family': 'helvetica, tahoma, calibri, sans-serif',
59
+ 'font-weight': 'lighter',
60
+ 'color': '#ccc'
61
+ },
62
+ ':focus': {
63
+ 'color': 'black'
64
+ },
65
+ '.valid': {
66
+ 'color': '#8bdda8'
67
+ }
68
+ },
69
+ fields: {
70
+ number: {
71
+ selector: '#braintree-credit-cards-card-number',
72
+ placeholder: '4111 1111 1111 1111'
73
+ },
74
+ cvv: {
75
+ selector: '#braintree-credit-cards-card-cvc',
76
+ placeholder: '123'
77
+ },
78
+ expirationDate: {
79
+ selector: '#braintree-credit-cards-card-expiry',
80
+ placeholder: 'MM/YYYY'
81
+ }
82
+ }
83
+ }, function (hostedFieldsErr, hostedFieldsInstance) {
84
+ if (hostedFieldsErr) {
85
+ console.error(hostedFieldsErr.code);
86
+ alert(hostedFieldsErr.code);
87
+ return;
88
+ }
89
+ components.hostedFields = hostedFieldsInstance;
90
+ submit_btn.attr('disabled', false);
91
+ cart_form.on( 'submit', function (event) {
92
+ if ( gateway !== 'braintree-credit-cards' ) { return; }
93
+ event.preventDefault();
94
+ components.hostedFields.tokenize(function (tokenizeErr, payload) {
95
+ if (tokenizeErr) {
96
+ switch (tokenizeErr.code) {
97
+ case 'HOSTED_FIELDS_FIELDS_EMPTY':
98
+ // occurs when none of the fields are filled in
99
+ errmsg = 'Please enter credit card details!';
100
+
101
+ break;
102
+ case 'HOSTED_FIELDS_FIELDS_INVALID':
103
+ // occurs when certain fields do not pass client side validation
104
+ errmsg = 'Some credit card fields are invalid: ' + tokenizeErr.details.invalidFieldKeys;
105
+ break;
106
+ case 'HOSTED_FIELDS_TOKENIZATION_FAIL_ON_DUPLICATE':
107
+ // occurs when:
108
+ // * the client token used for client authorization was generated
109
+ // with a customer ID and the fail on duplicate payment method
110
+ // option is set to true
111
+ // * the card being tokenized has previously been vaulted (with any customer)
112
+ // See: https://developers.braintreepayments.com/reference/request/client-token/generate/#options.fail_on_duplicate_payment_method
113
+ errmsg = 'This payment method already exists in your vault.';
114
+ break;
115
+ case 'HOSTED_FIELDS_TOKENIZATION_CVV_VERIFICATION_FAILED':
116
+ // occurs when:
117
+ // * the client token used for client authorization was generated
118
+ // with a customer ID and the verify card option is set to true
119
+ // and you have credit card verification turned on in the Braintree
120
+ // control panel
121
+ // * the cvv does not pass verfication (https://developers.braintreepayments.com/reference/general/testing/#avs-and-cvv/cid-responses)
122
+ // See: https://developers.braintreepayments.com/reference/request/client-token/generate/#options.verify_card
123
+ errmsg = 'CVV did not pass verification';
124
+ break;
125
+ case 'HOSTED_FIELDS_FAILED_TOKENIZATION':
126
+ // occurs for any other tokenization error on the server
127
+ errmsg = 'Tokenization failed server side. Is the card valid?';
128
+ break;
129
+ case 'HOSTED_FIELDS_TOKENIZATION_NETWORK_ERROR':
130
+ // occurs when the Braintree gateway cannot be contacted
131
+ errmsg = 'Network error occurred when tokenizing.';
132
+ break;
133
+ default:
134
+ errmsg = 'Something bad happened!' + tokenizeErr;
135
+ }
136
+
137
+ console.error(errmsg);
138
+ alert(errmsg);
139
+ location.reload();
140
+ return;
141
+ }
142
+
143
+ if ( components.threeDSecure ) {
144
+ components.threeDSecure.verifyCard({
145
+ amount: wpec_ppbt.cart_total,
146
+ nonce: payload.nonce,
147
+ addFrame: addFrame,
148
+ removeFrame: removeFrame
149
+ }, function (err, response) {
150
+ // Handle response
151
+ if (!err) {
152
+ var liabilityShifted = response.liabilityShifted; // true || false
153
+ var liabilityShiftPossible = response.liabilityShiftPossible; // true || false
154
+ if ( liabilityShifted ) {
155
+ // The 3D Secure payment was successful so proceed with this nonce
156
+ $('input[name="pp_btree_method_nonce"]').val( response.nonce );
157
+ cart_form[0].submit();
158
+ } else {
159
+ // The 3D Secure payment failed an initial check so check whether liability shift is possible
160
+ if (liabilityShiftPossible) {
161
+ // LiabilityShift is possible so proceed with this nonce
162
+ $('input[name="pp_btree_method_nonce"]').val( response.nonce );
163
+ cart_form[0].submit();
164
+ } else {
165
+ if ( wpec_ppbt.t3dsonly == '1' ) {
166
+ // Check whether the 3D Secure check has to be passed to proceeed. If so then show an error
167
+ console.error('There was a problem with your payment verification');
168
+ alert('There was a problem with your payment verification');
169
+ return;
170
+ } else {
171
+ // ...and if not just proceed with this nonce
172
+ $('input[name="pp_btree_method_nonce"]').val( response.nonce );
173
+ cart_form[0].submit();
174
+ }
175
+ }
176
+ }
177
+ // 3D Secure finished. Using response.nonce you may proceed with the transaction with the associated server side parameters below.
178
+ $('input[name="pp_btree_method_nonce"]').val( response.nonce );
179
+ cart_form[0].submit();
180
+ } else {
181
+ // Handle errors
182
+ console.log('verification error:', err);
183
+ alert( 'Sorry this card type isn`t supported, please use a different card or payment method' );
184
+ return;
185
+ }
186
+ });
187
+ } else {
188
+ // send the nonce to your server.
189
+ $('input[name="pp_btree_method_nonce"]').val( payload.nonce );
190
+ cart_form[0].submit();
191
+ }
192
+ });
193
+ });
194
+ });
195
+ };
196
+
197
+ function createPayPalCheckout( clientInstance ) {
198
+ braintree.paypalCheckout.create({
199
+ client: clientInstance
200
+ }, function (paypalErr, paypalCheckoutInstance) {
201
+ if (paypalErr) {
202
+ console.error('Error creating PayPal:', paypalErr);
203
+ alert(paypalErr.code);
204
+ return;
205
+ }
206
+ components.paypalCheckout = paypalCheckoutInstance;
207
+ paypalButton.attr('disabled', false);
208
+ // Set up PayPal with the checkout.js library
209
+ paypal.Button.render({
210
+ env: wpec_ppbt.sandbox,
211
+ style: {
212
+ label: 'pay',
213
+ size: wpec_ppbt.but_size,
214
+ shape: wpec_ppbt.but_shape,
215
+ color: wpec_ppbt.but_colour,
216
+ },
217
+ commit: true,
218
+ payment: function () {
219
+ var args = {
220
+ flow: 'checkout', // Required
221
+ intent: 'sale',
222
+ amount: wpec_ppbt.cart_total, // Required
223
+ currency: wpec_ppbt.currency, // Required
224
+ locale: 'en_US',
225
+ useraction: 'commit'
226
+ };
227
+
228
+ if ( wpec_ppbt.is_shipping ) {
229
+ args = $.extend( args, {
230
+ enableShippingAddress: true,
231
+ shippingAddressEditable: false,
232
+ shippingAddressOverride: {
233
+ recipientName: $( 'input[title="shippingfirstname"]' ).val() + $( 'input[title="shippinglastname"]' ).val(),
234
+ line1: $( 'textarea[title="shippingaddress"]' ).text(),
235
+ city: $( 'input[title="shippingcity"]' ).val(),
236
+ countryCode: $( 'select[data-wpsc-meta-key="shippingcountry"]' ).val(),
237
+ postalCode: $( 'input[title="shippingpostcode"]' ).val(),
238
+ state: replace_state_code( $( 'input[title="shippingstate"]' ).val() ),
239
+ }
240
+ } );
241
+ } else {
242
+ args.enableShippingAddress = false;
243
+ }
244
+
245
+ return components.paypalCheckout.createPayment( args );
246
+ },
247
+ onAuthorize: function (data, actions) {
248
+ return components.paypalCheckout.tokenizePayment(data)
249
+ .then(function (payload) {
250
+ // Submit `payload.nonce` to your server
251
+ paypalButton.attr('disabled', true);
252
+ $('input[name="pp_btree_method_nonce"]').val( payload.nonce );
253
+ cart_form[0].submit();
254
+ });
255
+ },
256
+ onCancel: function (data) {
257
+ console.log('checkout.js payment cancelled', JSON.stringify(data, 0, 2));
258
+ },
259
+ onError: function (err) {
260
+ msg = 'There\'s been a problem processing your payment, please check and retry. If you continue to have an issue please choose an alternative payment method';
261
+ console.error( msg );
262
+ alert( msg );
263
+ return;
264
+ }
265
+ }, document.getElementById( 'pp_braintree_pp_button' ) ).then(function () {
266
+ // The PayPal button will be rendered in an html element with the id
267
+ // `paypal-button`. This function will be called when the PayPal button
268
+ // is set up and ready to be used.
269
+ });
270
+ });
271
+ };
272
+
273
+ function replace_state_code( state ) {
274
+ var states = {
275
+ 'Alabama':'AL',
276
+ 'Alaska':'AK',
277
+ 'Arizona':'AZ',
278
+ 'Arkansas':'AR',
279
+ 'California':'CA',
280
+ 'Colorado':'CO',
281
+ 'Connecticut':'CT',
282
+ 'Delaware':'DE',
283
+ 'Florida':'FL',
284
+ 'Georgia':'GA',
285
+ 'Hawaii':'HI',
286
+ 'Idaho':'ID',
287
+ 'Illinois':'IL',
288
+ 'Indiana':'IN',
289
+ 'Iowa':'IA',
290
+ 'Kansas':'KS',
291
+ 'Kentucky':'KY',
292
+ 'Louisiana':'LA',
293
+ 'Maine':'ME',
294
+ 'Maryland':'MD',
295
+ 'Massachusetts':'MA',
296
+ 'Michigan':'MI',
297
+ 'Minnesota':'MN',
298
+ 'Mississippi':'MS',
299
+ 'Missouri':'MO',
300
+ 'Montana':'MT',
301
+ 'Nebraska':'NE',
302
+ 'Nevada':'NV',
303
+ 'New Hampshire':'NH',
304
+ 'New Jersey':'NJ',
305
+ 'New Mexico':'NM',
306
+ 'New York':'NY',
307
+ 'North Carolina':'NC',
308
+ 'North Dakota':'ND',
309
+ 'Ohio':'OH',
310
+ 'Oklahoma':'OK',
311
+ 'Oregon':'OR',
312
+ 'Pennsylvania':'PA',
313
+ 'Rhode Island':'RI',
314
+ 'South Carolina':'SC',
315
+ 'South Dakota':'SD',
316
+ 'Tennessee':'TN',
317
+ 'Texas':'TX',
318
+ 'Utah':'UT',
319
+ 'Vermont':'VT',
320
+ 'Virginia':'VA',
321
+ 'Washington':'WA',
322
+ 'West Virginia':'WV',
323
+ 'Wisconsin':'WI',
324
+ 'Wyoming':'WY'
325
+ };
326
+ return states[state];
327
+ }
328
+
329
+ function wpscCheckSubmitStatus( e ) {
330
+ var pp_button = $( '.wpsc-checkout-form-button, .wpsc_buy_button' );
331
+ gateway = $( 'input[name="custom_gateway"]:checked, input[name="custom_gateway"]:hidden, input[name="wpsc_payment_method"]:checked' ).val();
332
+
333
+ if ( gateway == 'braintree-paypal' ) {
334
+ if ( e && e.keyCode == 13 ) {
335
+ e.preventDefault();
336
+ return;
337
+ }
338
+
339
+ if ( pp_button.is(":visible") ) {
340
+ pp_button.hide();
341
+ return;
342
+ }
343
+ }
344
+
345
+ pp_button.show();
346
+ }
347
+
348
+ function wpscBootstrapBraintree() {
349
+ //Disable the regular purchase button if using PayPal
350
+ wpscCheckSubmitStatus();
351
+
352
+ if ( gateway !== 'braintree-credit-cards' && gateway !== 'braintree-paypal' ) {
353
+ return;
354
+ }
355
+
356
+ if ( components.client ) {
357
+ return;
358
+ }
359
+
360
+ braintree.client.create({
361
+ authorization: clientToken
362
+ }, function(err, clientInstance) {
363
+ if (err) {
364
+ console.error(err);
365
+ return;
366
+ }
367
+ components.client = clientInstance;
368
+
369
+ braintree.dataCollector.create({
370
+ client: clientInstance,
371
+ kount: true
372
+ }, function (err, dataCollectorInstance) {
373
+ if (err) {
374
+ console.log(err);
375
+ // Handle error in creation of data collector
376
+ return;
377
+ }
378
+ // At this point, you should access the dataCollectorInstance.deviceData value and provide it
379
+ // to your server, e.g. by injecting it into your form as a hidden input.
380
+ components.kount = dataCollectorInstance.deviceData;
381
+
382
+ $('#pp_btree_card_kount').val( components.kount );
383
+ });
384
+
385
+ if ( wpec_ppbt.is_cc_active ) {
386
+ create3DSecure( clientInstance );
387
+ createHostedFields(clientInstance);
388
+ }
389
+ if ( wpec_ppbt.is_pp_active ) {
390
+ createPayPalCheckout(clientInstance );
391
+ }
392
+ });
393
+
394
+
395
+ }
396
+
397
+ closeFrame.on( 'click', function () {
398
+ components.threeDSecure.cancelVerifyCard( removeFrame() );
399
+ });
400
+
401
+ $( document ).ready( wpscBootstrapBraintree );
402
+ $( document ).on( 'keypress', '.wpsc_checkout_forms', wpscCheckSubmitStatus );
403
+ $( document ).on( 'keypress', '#wpsc-checkout-form', wpscCheckSubmitStatus );
404
+ $( 'input[name=\"custom_gateway\"]' ).change( wpscBootstrapBraintree );
405
+ $( 'input[name=\"wpsc_payment_method\"]' ).change( wpscBootstrapBraintree );
406
+
407
+ } )( jQuery );
wpsc-components/merchant-core-v3/libraries/pp-braintree/pp-braintree.php ADDED
@@ -0,0 +1,739 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class WPEC_Braintree_Helpers {
3
+
4
+ private static $instance;
5
+
6
+ /** @var array the admin notices to add */
7
+ public static $notices = array();
8
+
9
+ public function __construct() {
10
+ }
11
+
12
+ public static function get_instance() {
13
+ if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPEC_Braintree_Helpers ) ) {
14
+ self::$instance = new WPEC_Braintree_Helpers;
15
+
16
+ self::deactivate_plugins();
17
+ self::includes();
18
+ self::add_actions();
19
+ self::add_filters();
20
+ }
21
+ return self::$instance;
22
+ }
23
+
24
+ public static function deactivate_plugins() {
25
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
26
+ if ( ! function_exists( 'deactivate_plugins' ) ) {
27
+ return;
28
+ }
29
+ if ( is_plugin_active( 'wpec-pp-braintree/pp-braintree.php' ) ) {
30
+ deactivate_plugins( 'wpec-pp-braintree/pp-braintree.php' );
31
+ }
32
+ }
33
+
34
+ public static function includes() {
35
+ require_once( WPSC_MERCHANT_V3_SDKS_PATH . '/pp-braintree/sdk/lib/Braintree.php' );
36
+ }
37
+
38
+ public static function add_actions() {
39
+ add_action( 'admin_notices', array( self::$instance, 'admin_notices' ), 15 );
40
+ add_action( 'admin_init', array( self::$instance, 'handle_auth_connect' ) );
41
+ add_action( 'admin_init', array( self::$instance, 'handle_auth_disconnect' ) );
42
+ add_action( 'wpsc_loaded', array( self::$instance, 'init' ), 2 );
43
+ add_action( 'admin_enqueue_scripts', array( self::$instance, 'admin_scripts' ) );
44
+ add_action( 'wp_enqueue_scripts' , array( self::$instance, 'pp_braintree_enqueue_js' ), 100 );
45
+ add_action( 'wpsc_submit_gateway_options', array( self::$instance, 'update_payment_gateway_settings' ), 90 );
46
+ }
47
+
48
+ public static function add_filters() {
49
+ add_filter( 'wpsc_gateway_checkout_form_wpsc_merchant_braintree_v_zero_pp', array( self::$instance, 'pp_braintree_pp_checkout_fields') );
50
+ add_filter( 'wpsc_gateway_name', array( self::$instance, 'tev1_custom_gateway_name'), 10, 2 );
51
+ }
52
+
53
+ public function init() {
54
+ // Add hidden field to hold token value Tev1
55
+ add_action( 'wpsc_inside_shopping_cart', array( $this, 'te_v1_insert_hidden_field' ) );
56
+ // Add hidden field to hold token value Tev2
57
+ add_filter( 'wpsc_get_checkout_payment_method_form_args', array( $this, 'te_v2_insert_hidden_field' ) );
58
+ //add_action( 'wpsc_default_credit_card_form_end', array( $this, 'te_v2_insert_hidden_field' ) );
59
+ }
60
+
61
+ public function tev1_custom_gateway_name( $name, $gateway ) {
62
+
63
+ if ( $gateway['internalname'] == 'braintree-credit-cards' ) {
64
+ $name = __( 'Cards', 'wp-e-commerce' );
65
+ }
66
+
67
+ if ( $gateway['internalname'] == 'braintree-paypal' ) {
68
+ $name = __( 'PayPal', 'wp-e-commerce' );
69
+ }
70
+ return $name;
71
+ }
72
+
73
+ public function te_v1_insert_hidden_field() {
74
+ echo '<input type="hidden" id="pp_btree_method_nonce" name="pp_btree_method_nonce" value="" />';
75
+ echo '<input type="hidden" id="pp_btree_card_kount" name="pp_btree_card_kount" value="" />';
76
+ }
77
+
78
+ public function te_v2_insert_hidden_field( $args ) {
79
+ if ( $args['id'] != 'wpsc-checkout-form' ) {
80
+ return;
81
+ }
82
+
83
+ array_push( $args['form_actions'], array( 'type' => 'hidden', 'name' => 'pp_btree_method_nonce', 'value' => '' ) );
84
+ array_push( $args['form_actions'], array( 'type' => 'hidden', 'name' => 'pp_btree_card_kount', 'value' => '' ) );
85
+
86
+ return $args;
87
+ }
88
+
89
+ public function admin_scripts( $hook ) {
90
+ if ( 'settings_page_wpsc-settings' !== $hook ) {
91
+ return;
92
+ }
93
+
94
+ wp_register_script( 'pp-bt-admin', WPSC_MERCHANT_V3_SDKS_URL . '/pp-braintree/assets/js/admin.js', array( 'jquery' ), WPSC_VERSION, true );
95
+ wp_enqueue_script( 'pp-bt-admin' );
96
+ }
97
+
98
+ public static function pp_braintree_enqueue_js() {
99
+ if ( ! self::is_gateway_active( 'braintree-credit-cards' ) && ! self::is_gateway_active( 'braintree-paypal' ) ) {
100
+ return;
101
+ }
102
+
103
+ if ( ! self::is_gateway_setup( 'braintree-credit-cards' ) && ! self::is_gateway_setup( 'braintree-paypal' ) ) {
104
+ return;
105
+ }
106
+
107
+ $is_cart = wpsc_is_theme_engine( '1.0' ) ? wpsc_is_checkout() : ( _wpsc_get_current_controller_method() == 'payment' );
108
+ if ( $is_cart ) {
109
+ //Get Cards Gateway settings
110
+ $bt_cc = new WPSC_Payment_Gateway_Setting( 'braintree-credit-cards' );
111
+ //Get PayPal Gateway settings
112
+ $bt_pp = new WPSC_Payment_Gateway_Setting( 'braintree-paypal' );
113
+
114
+ // Check if we are using Auth and connected
115
+ if ( self::bt_auth_can_connect() && self::bt_auth_is_connected() ) {
116
+ $acc_token = get_option( 'wpec_braintree_auth_access_token' );
117
+ $gateway = new Braintree_Gateway( array(
118
+ 'accessToken' => $acc_token
119
+ ));
120
+
121
+ $clientToken = $gateway->clientToken()->generate();
122
+ $pp_sandbox = self::get_auth_environment();
123
+ } else {
124
+ self::setBraintreeConfiguration();
125
+ $clientToken = Braintree_ClientToken::generate();
126
+
127
+ $bt_pp_sandbox = $bt_pp->get('sandbox');
128
+ $pp_sandbox = $bt_pp_sandbox == '1' ? 'sandbox' : 'production';
129
+ }
130
+
131
+ // Set PP Button styles
132
+ $pp_but_colour = $bt_pp->get('but_colour') != false ? $bt_pp->get('but_colour') : 'gold';
133
+ $pp_but_size = $bt_pp->get('but_size') != false ? $bt_pp->get('but_size') : 'responsive';
134
+ $pp_but_shape = $bt_pp->get('but_shape') != false ? $bt_pp->get('but_shape') : 'pill';
135
+
136
+ wp_register_script( 'pp-braintree', WPSC_MERCHANT_V3_SDKS_URL . '/pp-braintree/assets/js/frontend.js', array( 'jquery' ), null, true );
137
+ wp_localize_script( 'pp-braintree', 'wpec_ppbt', array(
138
+ 't3ds' => $bt_cc->get('three_d_secure'),
139
+ 't3dsonly' => $bt_cc->get('three_d_secure_only'),
140
+ 'ctoken' => $clientToken,
141
+ 'sandbox' => $pp_sandbox,
142
+ 'but_label' => 'pay',
143
+ 'but_colour' => $pp_but_colour,
144
+ 'but_size' => $pp_but_size,
145
+ 'but_shape' => $pp_but_shape,
146
+ 'cart_total' => wpsc_cart_total(false),
147
+ 'currency' => wpsc_get_currency_code(),
148
+ 'is_shipping' => wpsc_uses_shipping(),
149
+ 'is_cc_active' => self::is_gateway_active( 'braintree-credit-cards' ),
150
+ 'is_pp_active' => self::is_gateway_active( 'braintree-paypal' ),
151
+ )
152
+ );
153
+
154
+ wp_enqueue_style( 'pp-braintree-css', WPSC_MERCHANT_V3_SDKS_URL . '/pp-braintree/assets/css/style.css' );
155
+
156
+ wp_enqueue_script( 'pp-braintree' );
157
+ wp_enqueue_script( 'ppbtclient', 'https://js.braintreegateway.com/web/3.20.0/js/client.min.js', array(), null, true );
158
+ wp_enqueue_script( 'ppbthosted', 'https://js.braintreegateway.com/web/3.20.0/js/hosted-fields.min.js', array(), null, true );
159
+ wp_enqueue_script( 'ppbtppcheckout', 'https://js.braintreegateway.com/web/3.20.0/js/paypal-checkout.min.js', array(), null, true );
160
+ wp_enqueue_script( 'ppbtppapi', 'https://www.paypalobjects.com/api/checkout.js', array(), null, true );
161
+ wp_enqueue_script( 'ppbtthreeds', 'https://js.braintreegateway.com/web/3.20.0/js/three-d-secure.min.js', array(), null, true );
162
+ wp_enqueue_script( 'ppbtdata', 'https://js.braintreegateway.com/web/3.20.0/js/data-collector.min.js', array(), null, true );
163
+ }
164
+ }
165
+
166
+ public static function is_gateway_active( $gateway ) {
167
+ $selected_gateways = get_option( 'custom_gateway_options', array() );
168
+
169
+ return in_array( $gateway, $selected_gateways );
170
+ }
171
+
172
+ public static function is_gateway_setup( $gateway ) {
173
+ $settings = new WPSC_Payment_Gateway_Setting( $gateway );
174
+
175
+ if ( self::bt_auth_can_connect() ) {
176
+ if ( self::bt_auth_is_connected() && self::is_client_token( $gateway ) ) {
177
+ return true;
178
+ } else {
179
+ //Disconnect BT auth
180
+ delete_option( 'wpec_braintree_auth_access_token' );
181
+ delete_option( 'wpec_braintree_auth_environment' );
182
+ delete_option( 'wpec_braintree_auth_merchant_id' );
183
+ return false;
184
+ }
185
+ }
186
+
187
+ if ( $settings->get( 'public_key' ) && $settings->get( 'private_key' ) && $settings->get( 'merchant_id' ) ) {
188
+
189
+ if ( self::is_client_token( $gateway ) ) {
190
+ return true;
191
+ } else {
192
+ return false;
193
+ }
194
+ }
195
+
196
+ return false;
197
+ }
198
+
199
+ public static function show_connect_button() {
200
+ $output = '';
201
+ if ( self::bt_auth_can_connect() ) {
202
+ $connect_url = ! self::bt_auth_is_connected() ? self::wpec_bt_auth_get_connect_url() : self::wpec_bt_auth_get_disconnect_url();
203
+ $button_image_url = WPSC_MERCHANT_V3_SDKS_URL . '/pp-braintree/sdk/images/connect-braintree.png';
204
+ $output .= '<tr class="btpp-braintree-auth">
205
+ <td>Connect/Disconnect</td>';
206
+ if ( self::bt_auth_is_connected() ) {
207
+ $output .= "<td><a href='". esc_url( $connect_url ) . "' class='button-primary'>" . esc_html__( 'Disconnect from PayPal Powered by Braintree', 'wp-e-commerce' ) . "</a>
208
+ <p class='small description'>" . __( 'Merchant account: ', 'wp-e-commerce' ) . esc_attr( get_option( 'wpec_braintree_auth_merchant_id' ) ) ."</p></td>";
209
+ } else {
210
+ $output .= "<td><a href='" . esc_url( $connect_url ) . "' class='wpec-braintree-connect-button'><img src='" . esc_url( $button_image_url ) . "'/></a>
211
+ <p class='small description'><a href='". esc_url( 'https://www.braintreepayments.com/partners/learn-more' ) ."' target='_blank'>" . __( 'Learn More ', 'wp-e-commerce' ) ."</a></p></td>
212
+ <td></td>";
213
+ }
214
+ $output .= '</tr>';
215
+ }
216
+
217
+ return $output;
218
+ }
219
+
220
+ /**
221
+ * Gets the Braintree Auth disconnect URL.
222
+ *
223
+ * @since 1.0.0
224
+ * @return string
225
+ */
226
+ public static function wpec_bt_auth_get_disconnect_url() {
227
+
228
+ $url = add_query_arg( 'disconnect_paypal_braintree', 1, admin_url( esc_url_raw( 'options-general.php?page=wpsc-settings&tab=gateway' ) ) );
229
+
230
+ return wp_nonce_url( $url, 'disconnect_paypal_braintree', 'wpec_paypal_braintree_admin_nonce' );
231
+ }
232
+
233
+ /**
234
+ * Gets the Braintree Auth connect URL.
235
+ *
236
+ * @since 1.0.0
237
+ * @return string
238
+ */
239
+ public static function wpec_bt_auth_get_connect_url() {
240
+
241
+ $connect_url = 'https://wpecommerce.org/wp-json/wpec/v1/braintree';
242
+
243
+ $redirect_url = wp_nonce_url( admin_url( esc_url_raw( 'options-general.php?page=wpsc-settings&tab=gateway' ) ), 'connect_paypal_braintree', 'wpec_paypal_braintree_admin_nonce' );
244
+
245
+ $current_user = wp_get_current_user();
246
+
247
+ $environment = get_option( 'braintree_sandbox_mode' );
248
+ $environment = $environment == 'on' ? 'sandbox' : 'production' ;
249
+
250
+ // Note: We doubly urlencode the redirect url to avoid Braintree's server
251
+ // decoding it which would cause loss of query params on the final redirect
252
+ $query_args = array(
253
+ 'Auth' => 'WPeCBraintree',
254
+ 'user_email' => $current_user->user_email,
255
+ 'business_currency' => wpsc_get_currency_code(),
256
+ 'business_website' => get_bloginfo( 'url' ),
257
+ 'redirect' => base64_encode( $redirect_url ),
258
+ );
259
+
260
+ if ( ! empty( $current_user->user_firstname ) ) {
261
+ $query_args[ 'user_firstName' ] = $current_user->user_firstname;
262
+ }
263
+
264
+ if ( ! empty( $current_user->user_lastname ) ) {
265
+ $query_args[ 'user_lastName' ] = $current_user->user_lastname;
266
+ }
267
+
268
+ // Let's go ahead and assume the user and business are in the same region and country,
269
+ // because they probably are. If not, they can edit these anyways
270
+ $base_country = new WPSC_Country( wpsc_get_base_country() );
271
+ $region = new WPSC_Region( get_option( 'base_country' ), get_option( 'base_region' ) );
272
+
273
+ $location = in_array( $base_country->get_isocode(), array( 'US', 'UK', 'FR' ) ) ? $base_country->get_isocode() : 'US';
274
+
275
+ if ( ! empty( wpsc_get_base_country() ) ) {
276
+ $query_args['business_country'] = $query_args['user_country'] = wpsc_get_base_country();
277
+ }
278
+
279
+ if ( ! empty( $region->get_name() ) ) {
280
+ $query_args['business_region'] = $query_args['user_region'] = $region->get_code();
281
+ }
282
+
283
+ if ( $site_name = get_bloginfo( 'name' ) ) {
284
+ $query_args[ 'business_name' ] = $site_name;
285
+ }
286
+
287
+ if ( $site_description = get_bloginfo( 'description' ) ) {
288
+ $query_args[ 'business_description' ] = $site_description;
289
+ }
290
+
291
+ return add_query_arg( $query_args, $connect_url );
292
+ }
293
+
294
+ public static function bt_auth_can_connect() {
295
+ $base_country = new WPSC_Country( wpsc_get_base_country() );
296
+
297
+ return in_array( $base_country->get_isocode(), array( 'US', 'UK', 'FR', 'GB' ) );
298
+ }
299
+
300
+ public static function bt_auth_is_connected() {
301
+ $token = get_option( 'wpec_braintree_auth_access_token', '' );
302
+
303
+ return ! empty( $token );
304
+ }
305
+
306
+ /**
307
+ * Returns a list of merchant currencies
308
+ */
309
+ public static function getMerchantCurrencies() {
310
+ $merchant_currencies = array();
311
+ // These are all the currencies supported by Braintree. Some have been commented out as trying to
312
+ // load them all really slows down the display of the admin section for Braintree payments
313
+ /*
314
+ $merchant_currencies[] = array('currency'=>'AFN','currency_label'=>'Afghan Afghani');
315
+ $merchant_currencies[] = array('currency'=>'ALL','currency_label'=>'Albanian Lek');
316
+ $merchant_currencies[] = array('currency'=>'AMD','currency_label'=>'Armenian Dram');
317
+ $merchant_currencies[] = array('currency'=>'ANG','currency_label'=>'Netherlands Antillean Gulden');
318
+ $merchant_currencies[] = array('currency'=>'AOA','currency_label'=>'Angolan Kwanza');
319
+ $merchant_currencies[] = array('currency'=>'ARS','currency_label'=>'Argentine Peso');
320
+ */
321
+ $merchant_currencies[] = array('currency'=>'AUD','currency_label'=>'Australian Dollar');
322
+ /*
323
+ $merchant_currencies[] = array('currency'=>'AWG','currency_label'=>'Aruban Florin');
324
+ $merchant_currencies[] = array('currency'=>'AZN','currency_label'=>'Azerbaijani Manat');
325
+ $merchant_currencies[] = array('currency'=>'BAM','currency_label'=>'Bosnia and Herzegovina Convertible Mark');
326
+ $merchant_currencies[] = array('currency'=>'BBD','currency_label'=>'Barbadian Dollar');
327
+ $merchant_currencies[] = array('currency'=>'BDT','currency_label'=>'Bangladeshi Taka');
328
+ $merchant_currencies[] = array('currency'=>'BGN','currency_label'=>'Bulgarian Lev');
329
+ $merchant_currencies[] = array('currency'=>'BHD','currency_label'=>'Bahraini Dinar');
330
+ $merchant_currencies[] = array('currency'=>'BIF','currency_label'=>'Burundian Franc');
331
+ $merchant_currencies[] = array('currency'=>'BMD','currency_label'=>'Bermudian Dollar');
332
+ $merchant_currencies[] = array('currency'=>'BND','currency_label'=>'Brunei Dollar');
333
+ $merchant_currencies[] = array('currency'=>'BOB','currency_label'=>'Bolivian Boliviano');
334
+ $merchant_currencies[] = array('currency'=>'BRL','currency_label'=>'Brazilian Real');
335
+ $merchant_currencies[] = array('currency'=>'BSD','currency_label'=>'Bahamian Dollar');
336
+ $merchant_currencies[] = array('currency'=>'BTN','currency_label'=>'Bhutanese Ngultrum');
337
+ $merchant_currencies[] = array('currency'=>'BWP','currency_label'=>'Botswana Pula');
338
+ $merchant_currencies[] = array('currency'=>'BYR','currency_label'=>'Belarusian Ruble');
339
+ $merchant_currencies[] = array('currency'=>'BZD','currency_label'=>'Belize Dollar');
340
+ */
341
+ $merchant_currencies[] = array('currency'=>'CAD','currency_label'=>'Canadian Dollar');
342
+ //$merchant_currencies[] = array('currency'=>'CDF','currency_label'=>'Congolese Franc');
343
+ $merchant_currencies[] = array('currency'=>'CHF','currency_label'=>'Swiss Franc');
344
+ //$merchant_currencies[] = array('currency'=>'CLP','currency_label'=>'Chilean Peso');
345
+ $merchant_currencies[] = array('currency'=>'CNY','currency_label'=>'Chinese Renminbi Yuan');
346
+ /*
347
+ $merchant_currencies[] = array('currency'=>'COP','currency_label'=>'Colombian Peso');
348
+ $merchant_currencies[] = array('currency'=>'CRC','currency_label'=>'Costa Rican Col�n');
349
+ $merchant_currencies[] = array('currency'=>'CUC','currency_label'=>'Cuban Convertible Peso');
350
+ $merchant_currencies[] = array('currency'=>'CUP','currency_label'=>'Cuban Peso');
351
+ $merchant_currencies[] = array('currency'=>'CVE','currency_label'=>'Cape Verdean Escudo');
352
+ $merchant_currencies[] = array('currency'=>'CZK','currency_label'=>'Czech Koruna');
353
+ $merchant_currencies[] = array('currency'=>'DJF','currency_label'=>'Djiboutian Franc');
354
+ $merchant_currencies[] = array('currency'=>'DKK','currency_label'=>'Danish Krone');
355
+ $merchant_currencies[] = array('currency'=>'DOP','currency_label'=>'Dominican Peso');
356
+ $merchant_currencies[] = array('currency'=>'DZD','currency_label'=>'Algerian Dinar');
357
+ $merchant_currencies[] = array('currency'=>'EEK','currency_label'=>'Estonian Kroon');
358
+ $merchant_currencies[] = array('currency'=>'EGP','currency_label'=>'Egyptian Pound');
359
+ $merchant_currencies[] = array('currency'=>'ERN','currency_label'=>'Eritrean Nakfa');
360
+ $merchant_currencies[] = array('currency'=>'ETB','currency_label'=>'Ethiopian Birr');
361
+ */
362
+ $merchant_currencies[] = array('currency'=>'EUR','currency_label'=>'Euro');
363
+ //$merchant_currencies[] = array('currency'=>'FJD','currency_label'=>'Fijian Dollar');
364
+ //$merchant_currencies[] = array('currency'=>'FKP','currency_label'=>'Falkland Pound');
365
+ $merchant_currencies[] = array('currency'=>'GBP','currency_label'=>'British Pound');
366
+ /*
367
+ $merchant_currencies[] = array('currency'=>'GEL','currency_label'=>'Georgian Lari');
368
+ $merchant_currencies[] = array('currency'=>'GHS','currency_label'=>'Ghanaian Cedi');
369
+ $merchant_currencies[] = array('currency'=>'GIP','currency_label'=>'Gibraltar Pound');
370
+ $merchant_currencies[] = array('currency'=>'GMD','currency_label'=>'Gambian Dalasi');
371
+ $merchant_currencies[] = array('currency'=>'GNF','currency_label'=>'Guinean Franc');
372
+ $merchant_currencies[] = array('currency'=>'GTQ','currency_label'=>'Guatemalan Quetzal');
373
+ $merchant_currencies[] = array('currency'=>'GYD','currency_label'=>'Guyanese Dollar');
374
+ */
375
+ $merchant_currencies[] = array('currency'=>'HKD','currency_label'=>'Hong Kong Dollar');
376
+ /*
377
+ $merchant_currencies[] = array('currency'=>'HNL','currency_label'=>'Honduran Lempira');
378
+ $merchant_currencies[] = array('currency'=>'HRK','currency_label'=>'Croatian Kuna');
379
+ $merchant_currencies[] = array('currency'=>'HTG','currency_label'=>'Haitian Gourde');
380
+ $merchant_currencies[] = array('currency'=>'HUF','currency_label'=>'Hungarian Forint');
381
+ $merchant_currencies[] = array('currency'=>'IDR','currency_label'=>'Indonesian Rupiah');
382
+ $merchant_currencies[] = array('currency'=>'ILS','currency_label'=>'Israeli New Sheqel');
383
+ $merchant_currencies[] = array('currency'=>'INR','currency_label'=>'Indian Rupee');
384
+ $merchant_currencies[] = array('currency'=>'IQD','currency_label'=>'Iraqi Dinar');
385
+ $merchant_currencies[] = array('currency'=>'IRR','currency_label'=>'Iranian Rial');
386
+ $merchant_currencies[] = array('currency'=>'ISK','currency_label'=>'Icelandic Kr�na');
387
+ $merchant_currencies[] = array('currency'=>'JMD','currency_label'=>'Jamaican Dollar');
388
+ $merchant_currencies[] = array('currency'=>'JOD','currency_label'=>'Jordanian Dinar');
389
+ */
390
+ $merchant_currencies[] = array('currency'=>'JPY','currency_label'=>'Japanese Yen');
391
+ /*
392
+ $merchant_currencies[] = array('currency'=>'KES','currency_label'=>'Kenyan Shilling');
393
+ $merchant_currencies[] = array('currency'=>'KGS','currency_label'=>'Kyrgyzstani Som');
394
+ $merchant_currencies[] = array('currency'=>'KHR','currency_label'=>'Cambodian Riel');
395
+ $merchant_currencies[] = array('currency'=>'KMF','currency_label'=>'Comorian Franc');
396
+ $merchant_currencies[] = array('currency'=>'KPW','currency_label'=>'North Korean Won');
397
+ $merchant_currencies[] = array('currency'=>'KRW','currency_label'=>'South Korean Won');
398
+ $merchant_currencies[] = array('currency'=>'KWD','currency_label'=>'Kuwaiti Dinar');
399
+ $merchant_currencies[] = array('currency'=>'KYD','currency_label'=>'Cayman Islands Dollar');
400
+ $merchant_currencies[] = array('currency'=>'KZT','currency_label'=>'Kazakhstani Tenge');
401
+ $merchant_currencies[] = array('currency'=>'LAK','currency_label'=>'Lao Kip');
402
+ $merchant_currencies[] = array('currency'=>'LBP','currency_label'=>'Lebanese Lira');
403
+ $merchant_currencies[] = array('currency'=>'LKR','currency_label'=>'Sri Lankan Rupee');
404
+ $merchant_currencies[] = array('currency'=>'LRD','currency_label'=>'Liberian Dollar');
405
+ $merchant_currencies[] = array('currency'=>'LSL','currency_label'=>'Lesotho Loti');
406
+ $merchant_currencies[] = array('currency'=>'LTL','currency_label'=>'Lithuanian Litas');
407
+ $merchant_currencies[] = array('currency'=>'LVL','currency_label'=>'Latvian Lats');
408
+ $merchant_currencies[] = array('currency'=>'LYD','currency_label'=>'Libyan Dinar');
409
+ $merchant_currencies[] = array('currency'=>'MAD','currency_label'=>'Moroccan Dirham');
410
+ $merchant_currencies[] = array('currency'=>'MDL','currency_label'=>'Moldovan Leu');
411
+ $merchant_currencies[] = array('currency'=>'MGA','currency_label'=>'Malagasy Ariary');
412
+ $merchant_currencies[] = array('currency'=>'MKD','currency_label'=>'Macedonian Denar');
413
+ $merchant_currencies[] = array('currency'=>'MMK','currency_label'=>'Myanmar Kyat');
414
+ $merchant_currencies[] = array('currency'=>'MNT','currency_label'=>'Mongolian T�gr�g');
415
+ $merchant_currencies[] = array('currency'=>'MOP','currency_label'=>'Macanese Pataca');
416
+ $merchant_currencies[] = array('currency'=>'MRO','currency_label'=>'Mauritanian Ouguiya');
417
+ $merchant_currencies[] = array('currency'=>'MUR','currency_label'=>'Mauritian Rupee');
418
+ $merchant_currencies[] = array('currency'=>'MVR','currency_label'=>'Maldivian Rufiyaa');
419
+ $merchant_currencies[] = array('currency'=>'MWK','currency_label'=>'Malawian Kwacha');
420
+ $merchant_currencies[] = array('currency'=>'MXN','currency_label'=>'Mexican Peso');
421
+ $merchant_currencies[] = array('currency'=>'MYR','currency_label'=>'Malaysian Ringgit');
422
+ $merchant_currencies[] = array('currency'=>'MZN','currency_label'=>'Mozambican Metical');
423
+ $merchant_currencies[] = array('currency'=>'NAD','currency_label'=>'Namibian Dollar');
424
+ $merchant_currencies[] = array('currency'=>'NGN','currency_label'=>'Nigerian Naira');
425
+ $merchant_currencies[] = array('currency'=>'NIO','currency_label'=>'Nicaraguan C�rdoba');
426
+ $merchant_currencies[] = array('currency'=>'NOK','currency_label'=>'Norwegian Krone');
427
+ $merchant_currencies[] = array('currency'=>'NPR','currency_label'=>'Nepalese Rupee');
428
+ */
429
+ $merchant_currencies[] = array('currency'=>'NZD','currency_label'=>'New Zealand Dollar');
430
+ /*
431
+ $merchant_currencies[] = array('currency'=>'OMR','currency_label'=>'Omani Rial');
432
+ $merchant_currencies[] = array('currency'=>'PAB','currency_label'=>'Panamanian Balboa');
433
+ $merchant_currencies[] = array('currency'=>'PEN','currency_label'=>'Peruvian Nuevo Sol');
434
+ $merchant_currencies[] = array('currency'=>'PGK','currency_label'=>'Papua New Guinean Kina');
435
+ $merchant_currencies[] = array('currency'=>'PHP','currency_label'=>'Philippine Peso');
436
+ $merchant_currencies[] = array('currency'=>'PKR','currency_label'=>'Pakistani Rupee');
437
+ $merchant_currencies[] = array('currency'=>'PLN','currency_label'=>'Polish Zloty');
438
+ $merchant_currencies[] = array('currency'=>'PYG','currency_label'=>'Paraguayan Guaran�');
439
+ $merchant_currencies[] = array('currency'=>'QAR','currency_label'=>'Qatari Riyal');
440
+ $merchant_currencies[] = array('currency'=>'RON','currency_label'=>'Romanian Leu');
441
+ $merchant_currencies[] = array('currency'=>'RSD','currency_label'=>'Serbian Dinar');
442
+ $merchant_currencies[] = array('currency'=>'RUB','currency_label'=>'Russian Ruble');
443
+ $merchant_currencies[] = array('currency'=>'RWF','currency_label'=>'Rwandan Franc');
444
+ $merchant_currencies[] = array('currency'=>'SAR','currency_label'=>'Saudi Riyal');
445
+ $merchant_currencies[] = array('currency'=>'SBD','currency_label'=>'Solomon Islands Dollar');
446
+ $merchant_currencies[] = array('currency'=>'SCR','currency_label'=>'Seychellois Rupee');
447
+ $merchant_currencies[] = array('currency'=>'SDG','currency_label'=>'Sudanese Pound');
448
+ $merchant_currencies[] = array('currency'=>'SEK','currency_label'=>'Swedish Krona');
449
+ $merchant_currencies[] = array('currency'=>'SGD','currency_label'=>'Singapore Dollar');
450
+ $merchant_currencies[] = array('currency'=>'SHP','currency_label'=>'Saint Helenian Pound');
451
+ $merchant_currencies[] = array('currency'=>'SKK','currency_label'=>'Slovak Koruna');
452
+ $merchant_currencies[] = array('currency'=>'SLL','currency_label'=>'Sierra Leonean Leone');
453
+ $merchant_currencies[] = array('currency'=>'SOS','currency_label'=>'Somali Shilling');
454
+ $merchant_currencies[] = array('currency'=>'SRD','currency_label'=>'Surinamese Dollar');
455
+ $merchant_currencies[] = array('currency'=>'STD','currency_label'=>'S�o Tom� and Pr�ncipe Dobra');
456
+ $merchant_currencies[] = array('currency'=>'SVC','currency_label'=>'Salvadoran Col�n');
457
+ $merchant_currencies[] = array('currency'=>'SYP','currency_label'=>'Syrian Pound');
458
+ $merchant_currencies[] = array('currency'=>'SZL','currency_label'=>'Swazi Lilangeni');
459
+ $merchant_currencies[] = array('currency'=>'THB','currency_label'=>'Thai Baht');
460
+ $merchant_currencies[] = array('currency'=>'TJS','currency_label'=>'Tajikistani Somoni');
461
+ $merchant_currencies[] = array('currency'=>'TMM','currency_label'=>'Turkmenistani Manat');
462
+ $merchant_currencies[] = array('currency'=>'TMT','currency_label'=>'Turkmenistani Manat');
463
+ $merchant_currencies[] = array('currency'=>'TND','currency_label'=>'Tunisian Dinar');
464
+ $merchant_currencies[] = array('currency'=>'TOP','currency_label'=>'Tongan Pa?anga');
465
+ $merchant_currencies[] = array('currency'=>'TRY','currency_label'=>'Turkish New Lira');
466
+ $merchant_currencies[] = array('currency'=>'TTD','currency_label'=>'Trinidad and Tobago Dollar');
467
+ $merchant_currencies[] = array('currency'=>'TWD','currency_label'=>'New Taiwan Dollar');
468
+ $merchant_currencies[] = array('currency'=>'TZS','currency_label'=>'Tanzanian Shilling');
469
+ $merchant_currencies[] = array('currency'=>'UAH','currency_label'=>'Ukrainian Hryvnia');
470
+ $merchant_currencies[] = array('currency'=>'UGX','currency_label'=>'Ugandan Shilling');
471
+ */
472
+ $merchant_currencies[] = array('currency'=>'USD','currency_label'=>'United States Dollar');
473
+ /*
474
+ $merchant_currencies[] = array('currency'=>'UYU','currency_label'=>'Uruguayan Peso');
475
+ $merchant_currencies[] = array('currency'=>'UZS','currency_label'=>'Uzbekistani Som');
476
+ $merchant_currencies[] = array('currency'=>'VEF','currency_label'=>'Venezuelan Bol�var');
477
+ $merchant_currencies[] = array('currency'=>'VND','currency_label'=>'Vietnamese �?ng');
478
+ $merchant_currencies[] = array('currency'=>'VUV','currency_label'=>'Vanuatu Vatu');
479
+ $merchant_currencies[] = array('currency'=>'WST','currency_label'=>'Samoan Tala');
480
+ $merchant_currencies[] = array('currency'=>'XAF','currency_label'=>'Central African Cfa Franc');
481
+ $merchant_currencies[] = array('currency'=>'XCD','currency_label'=>'East Caribbean Dollar');
482
+ $merchant_currencies[] = array('currency'=>'XOF','currency_label'=>'West African Cfa Franc');
483
+ $merchant_currencies[] = array('currency'=>'XPF','currency_label'=>'Cfp Franc');
484
+ $merchant_currencies[] = array('currency'=>'YER','currency_label'=>'Yemeni Rial');
485
+ $merchant_currencies[] = array('currency'=>'ZAR','currency_label'=>'South African Rand');
486
+ $merchant_currencies[] = array('currency'=>'ZMK','currency_label'=>'Zambian Kwacha');
487
+ $merchant_currencies[] = array('currency'=>'ZWD','currency_label'=>'Zimbabwean Dollar');
488
+ */
489
+ return $merchant_currencies;
490
+ }
491
+ /**
492
+ * Setup the Braintree configuration
493
+ */
494
+ public static function setBraintreeConfiguration( $gateway = 'braintree-credit-cards' ) {
495
+ global $merchant_currency, $braintree_settings;
496
+
497
+ if ( $gateway == 'paypal' ) {
498
+ //Get PayPal Gateway settings
499
+ $settings = new WPSC_Payment_Gateway_Setting( 'braintree-paypal' );
500
+ } else {
501
+ $settings = new WPSC_Payment_Gateway_Setting( 'braintree-credit-cards' );
502
+ }
503
+
504
+ $sandbox = $settings->get('sandbox') == '1' ? 'sandbox' : 'production';
505
+
506
+ Braintree_Configuration::environment( $sandbox );
507
+ Braintree_Configuration::merchantId( $settings->get('merchant_id') );
508
+ Braintree_Configuration::publicKey( $settings->get('public_key') );
509
+ Braintree_Configuration::privateKey( $settings->get('private_key') );
510
+ }
511
+
512
+ /**
513
+ * Handles the Braintree Auth connection response.
514
+ *
515
+ * @since 1.0.0
516
+ */
517
+ public function handle_auth_connect() {
518
+ // TO DO some sort of validation that we are on the correct page ? settings/gateways
519
+ if ( isset( $_REQUEST['wpec_paypal_braintree_admin_nonce'] ) && isset( $_REQUEST['access_token'] ) ) {
520
+ $nonce = isset( $_REQUEST[ 'wpec_paypal_braintree_admin_nonce' ] ) ? trim( $_REQUEST[ 'wpec_paypal_braintree_admin_nonce' ] ) : false;
521
+ // if no nonce is present, then this probably wasn't a connection response
522
+ if ( ! $nonce ) {
523
+ return;
524
+ }
525
+ // verify the nonce
526
+ if ( ! wp_verify_nonce( $nonce, 'connect_paypal_braintree' ) ) {
527
+ wp_die( __( 'Invalid connection request', 'wp-e-commerce' ) );
528
+ }
529
+ $access_token = isset( $_REQUEST[ 'access_token' ] ) ? sanitize_text_field( base64_decode( $_REQUEST[ 'access_token' ] ) ) : false;
530
+ if ( $access_token ) {
531
+ update_option( 'wpec_braintree_auth_access_token', $access_token );
532
+ list( $token_key, $environment, $merchant_id, $raw_token ) = explode( '$', $access_token );
533
+ update_option( 'wpec_braintree_auth_environment', $environment );
534
+ update_option( 'wpec_braintree_auth_merchant_id', $merchant_id );
535
+ $connected = true;
536
+
537
+ // BT Authentication successful.
538
+ // Set 3D Secure setting here
539
+ self::is_client_token();
540
+
541
+ } else {
542
+ // Show an error message maybe ?
543
+ $connected = false;
544
+ }
545
+ wp_safe_redirect( add_query_arg( 'wpec_braintree_connected', $connected, admin_url( 'options-general.php?page=wpsc-settings&tab=gateway' ) ) );
546
+ exit;
547
+ }
548
+ }
549
+
550
+ /**
551
+ * Handles the Braintree Auth disconnect request
552
+ *
553
+ * @since 1.0.0
554
+ */
555
+ public function handle_auth_disconnect() {
556
+ // if this is not a disconnect request, bail
557
+ if ( ! isset( $_REQUEST[ 'disconnect_paypal_braintree' ] ) ) {
558
+ return;
559
+ }
560
+ $nonce = isset( $_REQUEST[ 'wpec_paypal_braintree_admin_nonce' ] ) ? trim( $_REQUEST[ 'wpec_paypal_braintree_admin_nonce' ] ) : false;
561
+ // if no nonce is present, then this probably wasn't a disconnect request
562
+ if ( ! $nonce ) {
563
+ return;
564
+ }
565
+ // verify the nonce
566
+ if ( ! wp_verify_nonce( $nonce, 'disconnect_paypal_braintree' ) ) {
567
+ wp_die( __( 'Invalid disconnect request', 'wp-e-commerce' ) );
568
+ }
569
+ delete_option( 'wpec_braintree_auth_access_token' );
570
+ delete_option( 'wpec_braintree_auth_environment' );
571
+ delete_option( 'wpec_braintree_auth_merchant_id' );
572
+ wp_safe_redirect( add_query_arg( 'wpec_braintree_disconnected', true, admin_url( 'options-general.php?page=wpsc-settings&tab=gateway' ) ) );
573
+ exit;
574
+ }
575
+
576
+ /**
577
+ * Validates the access token or api credentials
578
+ *
579
+ * Generates a client token to verify credentials
580
+ *
581
+ * @since 1.0.0
582
+ * @return string
583
+ */
584
+ public static function is_client_token( $gateway= '' ) {
585
+ $valid = true;
586
+
587
+ if ( self::bt_auth_is_connected() ) {
588
+ $acc_token = get_option( 'wpec_braintree_auth_access_token' );
589
+
590
+ try {
591
+ $gateway = new Braintree_Gateway( array( 'accessToken' => $acc_token ) );
592
+ $clientToken = $gateway->clientToken()->generate();
593
+ }
594
+ catch ( Exception $e ) {
595
+ $valid = false;;
596
+ }
597
+ } else {
598
+ try {
599
+ self::setBraintreeConfiguration( $gateway );
600
+ $clientToken = Braintree_ClientToken::generate();
601
+ }
602
+ catch ( Exception $e ) {
603
+ $valid = false;
604
+ }
605
+ }
606
+
607
+ if ( false === $valid ) {
608
+ return $valid;
609
+ }
610
+
611
+ if ( $clientToken ) {
612
+ $decoded = json_decode( base64_decode( $clientToken ) );
613
+ $three3ds = $decoded->threeDSecureEnabled;
614
+ $bt_cc = new WPSC_Payment_Gateway_Setting( 'braintree-credit-cards' );
615
+ if ( true == $three3ds ) {
616
+ $bt_cc->set('three_d_secure', '1');
617
+ } else {
618
+ $bt_cc->set('three_d_secure', '0');
619
+ }
620
+ }
621
+
622
+ return isset( $clientToken ) ? $clientToken : false;
623
+ }
624
+
625
+ public static function update_payment_gateway_settings() {
626
+ if ( isset( $_POST['user_defined_name'] ) && $_POST['user_defined_name'] ) {
627
+ $gateway = array_keys( $_POST['user_defined_name'] );
628
+ if ( ! empty( $gateway ) && $gateway[0] == 'braintree-credit-cards' || $gateway[0] == 'braintree-paypal') {
629
+ if ( $gateway[0] == 'braintree-credit-cards' ) {
630
+ $token = self::is_client_token( 'braintree-credit-cards' );
631
+ } else {
632
+ $token = self::is_client_token('braintree-paypal');
633
+ }
634
+
635
+ if ( ! $token ) {
636
+ // Show some error message
637
+ }
638
+ }
639
+ }
640
+ }
641
+
642
+ public static function set_payment_error_message( $error ) {
643
+ if ( wpsc_is_theme_engine( '1.0' ) ) {
644
+ $messages = wpsc_get_customer_meta( 'checkout_misc_error_messages' );
645
+ if ( ! is_array( $messages ) ) {
646
+ $messages = array();
647
+ }
648
+ $messages[] = $error;
649
+ wpsc_update_customer_meta( 'checkout_misc_error_messages', $messages );
650
+ } else {
651
+ WPSC_Message_Collection::get_instance()->add( $error, 'error', 'main', 'flash' );
652
+ }
653
+ }
654
+
655
+ /**
656
+ * Gets configured environment.
657
+ *
658
+ * If connected to Braintree Auth, the environment was explicitly set at
659
+ * the time of authentication.
660
+ *
661
+ * @since 1.0.0
662
+ * @return string
663
+ */
664
+ public static function get_auth_environment() {
665
+ $environment = false;
666
+
667
+ if ( self::bt_auth_is_connected() ) {
668
+ $environment = get_option( 'wpec_braintree_auth_environment', 'production' );
669
+ }
670
+
671
+ return $environment;
672
+ }
673
+
674
+ /**
675
+ * Get the failure status info for the given parameter, either code or message
676
+ * @since 1.0.0
677
+ * @param string $type status info type, either `code` or `message`
678
+ * @return string
679
+ */
680
+ public static function get_failure_status_info( $result, $type ) {
681
+
682
+ // see https://developers.braintreepayments.com/reference/response/transaction/php#unsuccessful-result
683
+ // As per recommendation show a generic response message
684
+ $transaction = $result->transaction;
685
+ switch ( $transaction->status ) {
686
+
687
+ // gateway rejections are due to CVV, AVS, fraud, etc
688
+ case 'gateway_rejected':
689
+
690
+ $status = array(
691
+ 'code' => $transaction->gatewayRejectionReason,
692
+ 'message' => 'There\'s been a problem processing your payment, please check and retry. If you continue to have an issue please choose an alternative payment method', //$result->message,
693
+ );
694
+ break;
695
+
696
+ // soft/hard decline directly from merchant processor
697
+ case 'processor_declined':
698
+
699
+ $status = array(
700
+ 'code' => $transaction->processorResponseCode,
701
+ 'message' => 'There\'s been a problem processing your payment, please check and retry. If you continue to have an issue please choose an alternative payment method', //$transaction->processorResponseText . ( ! empty( $transaction->additionalProcessorResponse ) ? ' (' . $transaction->additionalProcessorResponse . ')' : '' ),
702
+ );
703
+ break;
704
+
705
+ // only can occur when attempting to settle a previously authorized charge
706
+ case 'settlement_declined':
707
+
708
+ $status = array(
709
+ 'code' => $transaction->processorSettlementResponseCode,
710
+ 'message' => 'There\'s been a problem processing your payment, please check and retry. If you continue to have an issue please choose an alternative payment method', //$transaction->processorSettlementResponseText,
711
+ );
712
+ break;
713
+
714
+ // this path shouldn't execute, but for posterity
715
+ default:
716
+ $status = array(
717
+ 'code' => $transaction->status,
718
+ 'message' => isset( $result->message ) ? $result->message : '',
719
+ );
720
+ }
721
+
722
+ return isset( $status[ $type] ) ? $status[ $type ] : null;
723
+ }
724
+
725
+ public function admin_notices() {
726
+ if ( ! self::is_gateway_active( 'braintree-credit-cards' ) && ! self::is_gateway_active( 'braintree-paypal' ) ) {
727
+ return;
728
+ }
729
+
730
+ if ( self::is_gateway_setup( 'braintree-credit-cards' ) || self::is_gateway_setup( 'braintree-paypal' ) ) {
731
+ return;
732
+ }
733
+ ?>
734
+ <div class="error notice">
735
+ <p><?php _e( 'WP eCommerce PayPal powered by Braintree is active but not configured. Please check the Payment gateway settings page', 'wp-e-commerce' ); ?></p>
736
+ </div>
737
+ <?php
738
+ }
739
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/ACKNOWLEDGEMENTS.md ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ Acknowledgements
2
+ ----------------
3
+
4
+ The Braintree SDK uses code from the following libraries:
5
+
6
+ * [phpunit](https://github.com/sebastianbergmann/phpunit), BSD-3-Clause License
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/CHANGELOG.md ADDED
@@ -0,0 +1,475 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## 3.23.1
2
+ * Fix token generator return type - thanks @jjok!
3
+ * Improve error reporting for connection issues - thanks @montymxb!
4
+ * Add support for additional PayPal options when vaulting a PayPal Order
5
+
6
+ ## 3.23.0
7
+ * Add Visa Checkout support
8
+ * Add ConnectedMerchantStatusTransitioned and ConnectedMerchantPayPalStatusChanged Auth webhooks
9
+ * Add new properties to `CreditCardVerification` and `Customer`
10
+ * Add SDK support for skip AVS and skip CVV
11
+
12
+ ## 3.22.0
13
+ * Add option to disable Accept-Encoding: gzip header for Google App Engine
14
+ * Fix a bug where `merchantAccount->all` would attempt to fetch too many pages of merchant accounts
15
+
16
+ ## 3.21.1
17
+ * Add back in `options->three_d_secure` to transaction params that was accidentally removed in v3.14.0
18
+
19
+ ## 3.21.0
20
+ * Allow optional configuration of SSL version
21
+ * Replace `var_dump` with `print_r`. Thanks, @mnlg
22
+ * Add functionality to list all merchant accounts for a merchant with `merchantAccount->all`
23
+ * Stop sending account_description field from us bank accounts
24
+
25
+ ## 3.20.0
26
+ * Add option `skip_advanced_fraud_check` for transaction flows
27
+
28
+ ## 3.19.0
29
+ * Add multi-currency updates to merchants onboarded through Braintree Auth
30
+ * Raise an exception if fetching pages of results times out during a transaction search
31
+
32
+ ## 3.18.0
33
+ * Fix `UsBankAccount` support for `Customer`s
34
+ * Update `Grant` api to support options hash
35
+
36
+ ## 3.17.0
37
+ * Add 'UsBankAccount' payment method
38
+
39
+ ## 3.16.0
40
+ * Add authenticated proxy functionality
41
+ * Add constant for Venmo Account payment instrument type
42
+ * Add validation error for verifications with submerchants
43
+
44
+ ## 3.15.0
45
+ * Add 'default_payment_method' option for Customer
46
+
47
+ ## 3.14.0
48
+ **Note: This version introduced an unintentional breaking change where the `options->three_d_secure` transaction parameter was changed to `options->threeDSecure`. Starting in v3.21.1, both case conventions are supported for backwards compatibility.**
49
+
50
+ * Add OrderId to refund
51
+ * Add 3DS Pass thru support
52
+ * Expose IDs in resource collections
53
+ * Add leading slash to the namespace. Thanks, @bocharsky-bw
54
+ * Stop modifying DateTime parameters during XML generation. Thanks, @jodarove
55
+
56
+ ## 3.13.0
57
+ * Add method of revoking OAuth access tokens.
58
+
59
+ ## 3.12.0
60
+ * Add Transaction `update_details`
61
+ * Support for Too Many Requests response codes
62
+ * Add ability to count errors in ErrorCollection object. Thanks, @bocharsky-bw
63
+ * Improve Type Hinting
64
+
65
+ ## 3.11.0
66
+ * Remove final from classes. Thanks, @ibrahimlawal!
67
+ * Add currency to Transaction search
68
+
69
+ ## 3.10.0
70
+ * Add timeout attribute
71
+ * Add start-date and end-date to SUBSCRIPTION_CHARGED_SUCCESSFULLY test webhook response
72
+
73
+ ## 3.9.0
74
+ * Add AccountUpdaterDailyReport webhook parsing
75
+
76
+ ## 3.8.0
77
+ * Add payment method revoke
78
+ * Add support for options in `submit_for_settlement` transaction flows
79
+ * Add verification create API
80
+ * Update https certificate bundle
81
+
82
+ ## 3.7.0
83
+ * Add VenmoAccount
84
+ * Allow order_id and descriptor to be passed in for Transaction submit_for_settlement
85
+ * Add facilitator details onto transactions
86
+ * Add check webhook constant
87
+
88
+ ## 3.6.1
89
+ * Fix PSR-0 style namespacing when using Symfony
90
+
91
+ ## 3.6.0
92
+ * Add support for proxy servers
93
+ * Add PSR-4 namespacing support
94
+ * Add support for AMEX Express Checkout
95
+ * Add support for new fields in dispute webhooks (`dateWon`, `dateOpened`, `kind`)
96
+ * Add transaction data to sucessful subscription webhook
97
+
98
+ ## 3.5.0
99
+ * Add support for raw ApplePay params on Transaction create
100
+
101
+ ## 3.4.0
102
+ * Add sourceDescription method to Android Pay and Apple Pay payment methods
103
+ * Add new Android Pay test nonces
104
+ * Add billing agreement ID to PayPal Account
105
+ * Support amex rewards transactions
106
+
107
+ ## 3.3.0
108
+ * Add new test payment method nonces
109
+ * Allow passing description on PayPal transactions
110
+ * Add methods to change transaction settlement status in sandbox
111
+ * Fix issue where customer with an id of 0 could not be found
112
+ * Add Europe Bank Account functionality
113
+
114
+ ## 3.2.0
115
+ * Add additional search criteria
116
+
117
+ ## 3.1.0
118
+ * Add support for HHVM
119
+ * Validate that configuration is valid before verifying webhooks
120
+ * Make OAuth methods conform more to existing API
121
+ * Expose customer paymentMethods as an attribute
122
+
123
+ ## 3.0.1
124
+ * Add support for Android Pay
125
+
126
+ ## 3.0.0
127
+ * Deprecate PHP 5.2 and 5.3
128
+ * Validate webhook challenge payload
129
+ * Bugfix for calling `__toString()` on objects that contain a `\DateTime`
130
+
131
+ ## 2.40.0
132
+ * Add missing criteria to credit card verification search
133
+ * Bugfix for autoloading files with Composer
134
+
135
+ ## 2.39.0
136
+ * Add oauth functionality
137
+ * Add 3DS info to the server side
138
+
139
+ ## 2.38.0
140
+ * Update payment instrument types and test nonces
141
+ * Add missing valid params to PaymentMethodGateway
142
+
143
+ ## 2.37.0
144
+ * Add 3D Secure transaction fields
145
+ * Add ability to create nonce from vaulted payment methods
146
+
147
+ ## 2.36.0
148
+ * Surface Apple Pay payment instrument name in responses
149
+ * Support Coinbase payment instruments
150
+
151
+ ## 2.35.2
152
+ * Fix E_STRICT errors
153
+ * Expose subscription status details
154
+
155
+ ## 2.35.1
156
+ * Bugfix for auto loading files
157
+
158
+ ## 2.35.0
159
+ * Allow PayPal fields in transaction.options.paypal
160
+ * Add error code constants
161
+ * Internal refactoring
162
+
163
+ ## 2.34.0
164
+ * Add risk_data to Transaction and Verification with Kount decision and id
165
+ * Add verification_amount an option when creating a credit card
166
+ * Add TravelCruise industry type to Transaction
167
+ * Add room_rate to Lodging industry type
168
+ * Add CreditCard#verification as the latest verification on that credit card
169
+ * Add ApplePay support to all endpoints that may return ApplePayCard objects
170
+ * Add prefix to sample Webhook to simulate webhook query params
171
+
172
+ ## 2.33.0
173
+ * Allow descriptor to be passed in Funding Details options params for Merchant Account create and update.
174
+
175
+ ## 2.32.0
176
+ * Add additionalProcessorResponse to Transaction
177
+
178
+ ## 2.31.1
179
+ * Allow payee_email to be passed in options params for Transaction create
180
+
181
+ ## 2.31.0
182
+ * Added paypal specific fields to transaction calls
183
+ * Added SettlementPending, SettlementDeclined transaction statuses
184
+
185
+ ## 2.30.0
186
+ * Add descriptor url support
187
+
188
+ ## 2.29.0
189
+ * Allow credit card verification options to be passed outside of the nonce for PaymentMethod.create
190
+ * Allow billing_address parameters and billing_address_id to be passed outside of the nonce for PaymentMethod.create
191
+ * Add Subscriptions to paypal accounts
192
+ * Add PaymentMethod.update
193
+ * Add fail_on_duplicate_payment_method option to PaymentMethod.create
194
+
195
+ ## 2.28.0
196
+ * Adds support for v.zero SDKs.
197
+
198
+ ## 2.27.2
199
+
200
+ * Make webhook parsing more robust with newlines
201
+ * Add messages to InvalidSignature exceptions
202
+
203
+ ## 2.27.1
204
+
205
+ * Updated secureCompare to correctly compare strings in consistent time
206
+ * Add better error messages around webhook verification
207
+
208
+ ## 2.27.0
209
+
210
+ * Include Dispute information on Transaction
211
+ * Search for Transactions disputed on a certain date
212
+
213
+ ## 2.26.0
214
+
215
+ * Disbursement Webhooks
216
+
217
+ ## 2.25.1
218
+
219
+ * Fix factories on AddOn and Discount (thanks [stewe](https://github.com/stewe))
220
+ * Allow billingAddressId on transaction create
221
+
222
+ ## 2.25.0
223
+
224
+ * Merchant account find API
225
+
226
+ ## 2.24.0
227
+
228
+ * Merchant account update API
229
+ * Merchant account create API v2
230
+
231
+ ## 2.23.1
232
+
233
+ * Update configuration URLs
234
+
235
+ ## 2.23.0
236
+
237
+ * Official Partnership support
238
+
239
+ ## 2.22.2
240
+
241
+ * Add Partner Merchant Declined webhook
242
+ * use preg_callback_replace instead of preg_replace (thanks [jonthornton](https://github.com/jonthornton)!)
243
+
244
+ ## 2.22.1
245
+
246
+ * Adds missing test contstant to library namespace
247
+
248
+ ## 2.22.0
249
+
250
+ * Adds holdInEscrow method
251
+ * Add error codes for verification not supported error
252
+ * Add companyName and taxId to merchant account create
253
+ * Adds cancelRelease method
254
+ * Adds releaseFromEscrow functionality
255
+ * Adds phone to merchant account signature.
256
+ * Adds merchant account phone error code.
257
+ * Fix casing issues with Braintree\_Http and Braintree\_Util references (thanks [steven-hadfield](https://github.com/steven-hadfield)!)
258
+ * Fixed transaction initialization arguments to be optional (thanks [karolsojko](https://github.com/karolsojko)!)
259
+
260
+ ## 2.21.0
261
+
262
+ * Enable device data.
263
+
264
+ ## 2.20.0
265
+
266
+ * Fixed getting custom fields with valueForHtmlField. [Thanks to Miguel Manso for the fix.](https://github.com/mumia)
267
+ * Adds disbursement details to transactions.
268
+ * Adds image url to transactions.
269
+
270
+ ## 2.19.0
271
+
272
+ * Adds channel field to transactions.
273
+
274
+ ## 2.18.0
275
+
276
+ * Adds country of issuance and issuing bank bin database fields
277
+
278
+ ## 2.17.0
279
+
280
+ * Adds verification search
281
+
282
+ ## 2.16.0
283
+
284
+ * Additional card information, such as prepaid, debit, commercial, Durbin regulated, healthcare, and payroll, are returned on credit card responses
285
+ * Allows transactions to be specified as recurring
286
+
287
+ ## 2.15.0
288
+
289
+ * Adds prepaid field to credit cards (possible values include Yes, No, Unknown)
290
+
291
+ ## 2.14.1
292
+
293
+ * Adds composer support (thanks [till](https://github.com/till))
294
+ * Fixes erroneous version number
295
+ * Braintree_Plan::all() returns empty array if no plans exist
296
+
297
+ ## 2.14.0
298
+
299
+ * Adds webhook gateways for parsing, verifying, and testing notifications
300
+
301
+ ## 2.13.0
302
+
303
+ * Adds search for duplicate credit cards given a payment method token
304
+ * Adds flag to fail saving credit card to vault if card is duplicate
305
+
306
+ ## 2.12.5
307
+
308
+ * Exposes plan_id on transactions
309
+
310
+ ## 2.12.4
311
+
312
+ * Added error code for invalid purchase order number
313
+
314
+ ## 2.12.3
315
+
316
+ * Fixed problematic case in ResourceCollection when no results are returned from a search.
317
+
318
+ ## 2.12.2
319
+
320
+ * Fixed customer search, which returned customers when no customers matched search criteria
321
+
322
+ ## 2.12.1
323
+
324
+ * Added new error message for merchant accounts that do not support refunds
325
+
326
+ ## 2.12.0
327
+
328
+ * Added ability to retrieve all Plans, AddOns, and Discounts
329
+ * Added Transaction cloning
330
+
331
+ ## 2.11.0
332
+
333
+ * Added Braintree_SettlementBatchSummary
334
+
335
+ ## 2.10.1
336
+
337
+ * Wrap dependency requirement in a function, to prevent pollution of the global namespace
338
+
339
+ ## 2.10.0
340
+
341
+ * Added subscriptionDetails to Transaction
342
+ * Added flag to store in vault only when a transaction is successful
343
+ * Added new error code
344
+
345
+ ## 2.9.0
346
+
347
+ * Added a new transaction state, AUTHORIZATION_EXPIRED.
348
+ * Enabled searching by authorizationExpiredAt.
349
+
350
+ ## 2.8.0
351
+
352
+ * Added next_billing_date and transaction_id to subscription search
353
+ * Added address_country_name to customer search
354
+ * Added new error codes
355
+
356
+ ## 2.7.0
357
+
358
+ * Added Customer search
359
+ * Added dynamic descriptors to Subscriptions and Transactions
360
+ * Added level 2 fields to Transactions:
361
+ * tax_amount
362
+ * tax_exempt
363
+ * purchase_order_number
364
+
365
+ ## 2.6.1
366
+
367
+ * Added billingAddressId to allowed parameters for credit cards create and update
368
+ * Allow searching on subscriptions that are currently in a trial period using inTrialPeriod
369
+
370
+ ## 2.6.0
371
+
372
+ * Added ability to perform multiple partial refunds on Braintree_Transactions
373
+ * Allow passing expirationMonth and expirationYear separately when creating Braintree_Transactions
374
+ * Added revertSubscriptionOnProrationFailure flag to Braintree_Subscription update that specifies how a Subscription should react to a failed proration charge
375
+ * Deprecated Braintree_Subscription nextBillAmount in favor of nextBillingPeriodAmount
376
+ * Deprecated Braintree_Transaction refundId in favor of refundIds
377
+ * Added new fields to Braintree_Subscription:
378
+ * balance
379
+ * paidThroughDate
380
+ * nextBillingPeriodAmount
381
+
382
+ ## 2.5.0
383
+
384
+ * Added Braintree_AddOns/Braintree_Discounts
385
+ * Enhanced Braintree_Subscription search
386
+ * Enhanced Braintree_Transaction search
387
+ * Added constants for Braintree_Result_CreditCardVerification statuses
388
+ * Added EXPIRED and PENDING statuses to Braintree_Subscription
389
+ * Allowed prorateCharges to be specified on Braintree_Subscription update
390
+ * Added Braintree_AddOn/Braintree_Discount details to Braintree_Transactions that were created from a Braintree_Subscription
391
+ * Removed 13 digit Visa Sandbox Credit Card number and replaced it with a 16 digit Visa
392
+ * Added new fields to Braintree_Subscription:
393
+ * billingDayOfMonth
394
+ * daysPastDue
395
+ * firstBillingDate
396
+ * neverExpires
397
+ * numberOfBillingCycles
398
+
399
+ ## 2.4.0
400
+
401
+ * Added ability to specify country using countryName, countryCodeAlpha2, countryCodeAlpha3, or countryCodeNumeric (see [ISO_3166-1](http://en.wikipedia.org/wiki/ISO_3166-1))
402
+ * Added gatewayRejectionReason to Braintree_Transaction and Braintree_Verification
403
+ * Added unified message to result objects
404
+
405
+ ## 2.3.0
406
+
407
+ * Added unified Braintree_TransparentRedirect url and confirm methods and deprecated old methods
408
+ * Added functions to Braintree_CreditCard to allow searching on expiring and expired credit cards
409
+ * Allow card verification against a specified merchant account
410
+ * Added ability to update a customer, credit card, and billing address in one request
411
+ * Allow updating the paymentMethodToken on a subscription
412
+
413
+ ## 2.2.0
414
+
415
+ * Prevent race condition when pulling back collection results -- search results represent the state of the data at the time the query was run
416
+ * Rename ResourceCollection's approximate_size to maximum_size because items that no longer match the query will not be returned in the result set
417
+ * Correctly handle HTTP error 426 (Upgrade Required) -- the error code is returned when your client library version is no long compatible with the gateway
418
+ * Add the ability to specify merchant_account_id when verifying credit cards
419
+ * Add subscription_id to transactions created from subscriptions
420
+
421
+ ## 2.1.0
422
+
423
+ * Added transaction advanced search
424
+ * Added ability to partially refund transactions
425
+ * Added ability to manually retry past-due subscriptions
426
+ * Added new transaction error codes
427
+ * Allow merchant account to be specified when creating transactions
428
+ * Allow creating a transaction with a vault customer and new payment method
429
+ * Allow existing billing address to be updated when updating credit card
430
+ * Correctly handle xml with nil=true
431
+
432
+ ## 2.0.0
433
+
434
+ * Updated success? on transaction responses to return false on declined transactions
435
+ * Search results now include Enumerable and will automatically paginate data
436
+ * Added credit_card[cardholder_name] to allowed transaction params and CreditCardDetails (thanks [chrismcc](http://github.com/chrismcc))
437
+ * Fixed a bug with Customer::all
438
+ * Added constants for error codes
439
+
440
+ ## 1.2.1
441
+
442
+ * Added methods to get both shallow and deep errors from a Braintree_ValidationErrorCollection
443
+ * Added the ability to make a credit card the default card for a customer
444
+ * Added constants for transaction statuses
445
+ * Updated Quick Start in README.md to show a workflow with error checking
446
+
447
+ ## 1.2.0
448
+
449
+ * Added subscription search
450
+ * Provide access to associated subscriptions from CreditCard
451
+ * Switched from using Zend framework for HTTP requests to using curl extension
452
+ * Fixed a bug in Transparent Redirect when arg_separator.output is configured as &amp; instead of &
453
+ * Increased http request timeout
454
+ * Fixed a bug where ForgedQueryString exception was being raised instead of DownForMaintenance
455
+ * Updated SSL CA files
456
+
457
+ ## 1.1.1
458
+
459
+ * Added Braintree_Transaction::refund
460
+ * Added Braintree_Transaction::submitForSettlementNoValidate
461
+ * Fixed a bug in errors->onHtmlField when checking for errors on custom fields when there are none
462
+ * Added support for passing merchantAccountId for Transaction and Subscription
463
+
464
+ ## 1.1.0
465
+
466
+ * Added recurring billing support
467
+
468
+ ## 1.0.1
469
+
470
+ * Fixed bug with Braintree_Error_ErrorCollection.deepSize
471
+ * Added methods for accessing validation errors and params by html field name
472
+
473
+ ## 1.0.0
474
+
475
+ * Initial release
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/LICENSE ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2017 Braintree, a division of PayPal, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/README.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Braintree PHP library
2
+
3
+ The Braintree PHP library provides integration access to the Braintree Gateway.
4
+
5
+ ## Please Note
6
+ > **The Payment Card Industry (PCI) Council has [mandated](http://blog.pcisecuritystandards.org/migrating-from-ssl-and-early-tls) that early versions of TLS be retired from service. All organizations that handle credit card information are required to comply with this standard. As part of this obligation, Braintree is updating its services to require TLS 1.2 for all HTTPS connections. Braintree will also require HTTP/1.1 for all connections. Please see our [technical documentation](https://github.com/paypal/tls-update) for more information.**
7
+
8
+ ## Dependencies
9
+
10
+ PHP version >= 5.4.0 is required.
11
+
12
+ The following PHP extensions are required:
13
+
14
+ * curl
15
+ * dom
16
+ * hash
17
+ * openssl
18
+ * xmlwriter
19
+
20
+ ## Quick Start Example
21
+
22
+ ```php
23
+ <?php
24
+
25
+ require_once 'PATH_TO_BRAINTREE/lib/Braintree.php';
26
+
27
+ Braintree_Configuration::environment('sandbox');
28
+ Braintree_Configuration::merchantId('your_merchant_id');
29
+ Braintree_Configuration::publicKey('your_public_key');
30
+ Braintree_Configuration::privateKey('your_private_key');
31
+
32
+ $result = Braintree_Transaction::sale([
33
+ 'amount' => '1000.00',
34
+ 'paymentMethodNonce' => 'nonceFromTheClient',
35
+ 'options' => [ 'submitForSettlement' => true ]
36
+ ]);
37
+
38
+ if ($result->success) {
39
+ print_r("success!: " . $result->transaction->id);
40
+ } else if ($result->transaction) {
41
+ print_r("Error processing transaction:");
42
+ print_r("\n code: " . $result->transaction->processorResponseCode);
43
+ print_r("\n text: " . $result->transaction->processorResponseText);
44
+ } else {
45
+ print_r("Validation errors: \n");
46
+ print_r($result->errors->deepAll());
47
+ }
48
+ ```
49
+
50
+ Both PSR-0 and PSR-4 namespacing are supported. If you are using composer with `--classmap-authoritative` or
51
+ `--optimize-autoloader` enabled, you'll have to reference classes using PSR-4 namespacing:
52
+
53
+ ```php
54
+ Braintree\Configuration::environment('sandbox');
55
+ Braintree\Configuration::merchantId('your_merchant_id');
56
+ Braintree\Configuration::publicKey('your_public_key');
57
+ Braintree\Configuration::privateKey('your_private_key');
58
+ ```
59
+
60
+ ## HHVM Support
61
+
62
+ The Braintree PHP library will run on HHVM >= 3.4.2.
63
+
64
+ ## Google App Engine
65
+
66
+ If you use Google App Engine, you'll have to turn off accepting gzip responses.
67
+
68
+ ```php
69
+ Braintree\Configuration::acceptGzipEncoding(false);
70
+ ```
71
+
72
+ ## Legacy PHP Support
73
+
74
+ Version [2.40.0](https://github.com/braintree/braintree_php/releases/tag/2.40.0) is compatible with PHP 5.2 and 5.3. You can find it on our releases page.
75
+
76
+ ## Documentation
77
+
78
+ * [Official documentation](https://developers.braintreepayments.com/php/sdk/server/overview)
79
+
80
+ ## Testing
81
+
82
+ The unit specs can be run by anyone on any system, but the integration specs are meant to be run against a local development server of our gateway code. These integration specs are not meant for public consumption and will likely fail if run on your system. To run unit tests use rake: `rake test:unit`.
83
+
84
+ The benefit of the `rake` tasks is that testing covers default `hhvm` and `php` interpreters. However, if you want to run tests manually simply use the following command:
85
+ ```
86
+ phpunit tests/unit/
87
+ ```
88
+
89
+ ## License
90
+
91
+ See the LICENSE file.
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/Rakefile ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ task :default => :test
2
+ task :test => %w[test:unit test:integration]
3
+
4
+ namespace :test do
5
+ task :unit => %w[test:php:unit test:hhvm:unit]
6
+ task :integration => %w[test:php:integration test:hhvm:integration]
7
+
8
+ namespace :php do
9
+ desc "print PHP version"
10
+ task :version do
11
+ print_php_version("php")
12
+ end
13
+
14
+ desc "run unit tests under PHP"
15
+ task :unit => :version do
16
+ run_php_test_suite("php", "unit")
17
+ end
18
+
19
+ desc "run integration tests under PHP"
20
+ task :integration do
21
+ run_php_test_suite("php", "integration")
22
+ end
23
+ end
24
+
25
+ namespace :hhvm do
26
+ desc "print HHVM version"
27
+ task :version do
28
+ print_php_version("hhvm")
29
+ end
30
+
31
+ desc "run tests under HHVM"
32
+ task :test => [:unit, :integration]
33
+
34
+ desc "run unit tests under HHVM"
35
+ task :unit => :version do
36
+ run_php_test_suite("hhvm", "unit")
37
+ end
38
+
39
+ desc "run integration tests under HHVM"
40
+ task :integration do
41
+ run_php_test_suite("hhvm", "integration")
42
+ end
43
+ end
44
+
45
+ desc "run tests under PHP"
46
+ task :php => %w[php:unit php:integration]
47
+
48
+ desc "run tests under HHVM"
49
+ task :hhvm => %w[hhvm:unit hhvm:integration]
50
+
51
+ desc "run a single test file"
52
+ task :file, :file_path do |t, args|
53
+ run_php_test_file(args[:file_path])
54
+ end
55
+
56
+ desc "run single test (e.g. rake test:single[GatewayTest::testConfigGetsAssertedValid])"
57
+ task :single, :test_name do |t, args|
58
+ run_php_test(args[:test_name])
59
+ end
60
+ end
61
+
62
+ desc "update the copyright year"
63
+ task :copyright, :from_year, :to_year do |t, args|
64
+ sh "find tests lib -type f -name '*.php' -exec sed -i 's/#{args[:from_year]} Braintree/#{args[:to_year]} Braintree/g' {} +"
65
+ end
66
+
67
+ def print_php_version(interpreter)
68
+ sh "#{interpreter} --version"
69
+ end
70
+
71
+ def run_php_test_suite(interpreter, test_suite)
72
+ sh "#{interpreter} ./vendor/bin/phpunit --testsuite #{test_suite}"
73
+ end
74
+
75
+ def run_php_test_file(test_file)
76
+ sh "./vendor/bin/phpunit #{test_file}"
77
+ end
78
+
79
+ def run_php_test(test_name)
80
+ sh "./vendor/bin/phpunit --filter #{test_name}"
81
+ end
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/ci.sh ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ curl -sS https://getcomposer.org/installer | php -d suhosin.executor.include.whitelist=phar
4
+
5
+ php -d suhosin.executor.include.whitelist=phar ./composer.phar install
6
+
7
+ if [ "$1" == "hhvm" ]; then
8
+ rake test:hhvm --trace
9
+ else
10
+ rake test:php --trace
11
+ fi
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/composer.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "braintree/braintree_php",
3
+ "type": "library",
4
+ "description": "Braintree PHP Client Library",
5
+ "license": "MIT",
6
+ "authors": [
7
+ {
8
+ "name": "Braintree",
9
+ "homepage": "http://www.braintreepayments.com"
10
+ }
11
+ ],
12
+ "require": {
13
+ "php": ">=5.4.0",
14
+ "ext-curl": "*",
15
+ "ext-dom": "*",
16
+ "ext-hash": "*",
17
+ "ext-openssl": "*",
18
+ "ext-xmlwriter": "*"
19
+ },
20
+ "require-dev": {
21
+ "phpunit/phpunit": "3.7.*"
22
+ },
23
+ "autoload": {
24
+ "psr-0": {
25
+ "Braintree": "lib/"
26
+ },
27
+ "psr-4": {
28
+ "Braintree\\": "lib/Braintree"
29
+ }
30
+ },
31
+ "autoload-dev": {
32
+ "psr-4": {
33
+ "Test\\": "tests"
34
+ }
35
+ }
36
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/images/cards.png ADDED
Binary file
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/images/connect-braintree.png ADDED
Binary file
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/images/connect-braintree@2x.png ADDED
Binary file
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/images/connect-braintree@3x.png ADDED
Binary file
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Braintree PHP Library
4
+ * Creates class_aliases for old class names replaced by PSR-4 Namespaces
5
+ */
6
+
7
+ require_once(__DIR__ . DIRECTORY_SEPARATOR . 'autoload.php');
8
+
9
+ if (version_compare(PHP_VERSION, '5.4.0', '<')) {
10
+ throw new Braintree_Exception('PHP version >= 5.4.0 required');
11
+ }
12
+
13
+
14
+ function PPrequireDependencies() {
15
+ $requiredExtensions = ['xmlwriter', 'openssl', 'dom', 'hash', 'curl'];
16
+ foreach ($requiredExtensions AS $ext) {
17
+ if (!extension_loaded($ext)) {
18
+ throw new Braintree_Exception('The Braintree library requires the ' . $ext . ' extension.');
19
+ }
20
+ }
21
+ }
22
+
23
+ PPrequireDependencies();
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AccountUpdaterDailyReport.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Creates an instance of AccountUpdaterDailyReport
6
+ *
7
+ *
8
+ * @package Braintree
9
+ *
10
+ * @property-read string $reportUrl
11
+ * @property-read date $reportDate
12
+ * @property-read date $receivedDate
13
+ */
14
+ class AccountUpdaterDailyReport extends Base
15
+ {
16
+ protected $_attributes = [];
17
+
18
+ protected function _initialize($disputeAttribs)
19
+ {
20
+ $this->_attributes = $disputeAttribs;
21
+ }
22
+
23
+ public static function factory($attributes)
24
+ {
25
+ $instance = new self();
26
+ $instance->_initialize($attributes);
27
+ return $instance;
28
+ }
29
+
30
+ public function __toString()
31
+ {
32
+ $display = [
33
+ 'reportDate', 'reportUrl'
34
+ ];
35
+
36
+ $displayAttributes = [];
37
+ foreach ($display AS $attrib) {
38
+ $displayAttributes[$attrib] = $this->$attrib;
39
+ }
40
+ return __CLASS__ . '[' .
41
+ Util::attributesToString($displayAttributes) .']';
42
+ }
43
+ }
44
+ class_alias('Braintree\AccountUpdaterDailyReport', 'Braintree_AccountUpdaterDailyReport');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AchMandate.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree AchMandate module
6
+ * PHP Version 5
7
+ *
8
+ * @package Braintree
9
+ *
10
+ * @property-read string $text
11
+ * @property-read string $acceptedAt
12
+ */
13
+ class AchMandate extends Base
14
+ {
15
+ /**
16
+ * create a printable representation of the object as:
17
+ * ClassName[property=value, property=value]
18
+ * @ignore
19
+ * @return string
20
+ */
21
+ public function __toString()
22
+ {
23
+ return __CLASS__ . '[' .
24
+ Util::attributesToString($this->_attributes) . ']';
25
+ }
26
+
27
+ /**
28
+ * sets instance properties from an array of values
29
+ *
30
+ * @ignore
31
+ * @access protected
32
+ * @param array $achAttribs array of achMandate data
33
+ * @return void
34
+ */
35
+ protected function _initialize($achAttribs)
36
+ {
37
+ // set the attributes
38
+ $this->_attributes = $achAttribs;
39
+ $date = new \DateTime($this->acceptedAt);
40
+ $this->_set('acceptedAt', $date);
41
+ }
42
+
43
+ /**
44
+ * factory method: returns an instance of AchMandate
45
+ * to the requesting method, with populated properties
46
+ * @ignore
47
+ * @return AchMandate
48
+ */
49
+ public static function factory($attributes)
50
+ {
51
+ $instance = new self();
52
+ $instance->_initialize($attributes);
53
+ return $instance;
54
+
55
+ }
56
+ }
57
+ class_alias('Braintree\AchMandate', 'Braintree_Mandate');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AddOn.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class AddOn extends Modification
5
+ {
6
+ /**
7
+ *
8
+ * @param array $attributes
9
+ * @return AddOn
10
+ */
11
+ public static function factory($attributes)
12
+ {
13
+ $instance = new self();
14
+ $instance->_initialize($attributes);
15
+ return $instance;
16
+ }
17
+
18
+
19
+ /**
20
+ * static methods redirecting to gateway
21
+ *
22
+ * @return AddOn[]
23
+ */
24
+ public static function all()
25
+ {
26
+ return Configuration::gateway()->addOn()->all();
27
+ }
28
+ }
29
+ class_alias('Braintree\AddOn', 'Braintree_AddOn');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AddOnGateway.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class AddOnGateway
5
+ {
6
+ /**
7
+ *
8
+ * @var Gateway
9
+ */
10
+ private $_gateway;
11
+
12
+ /**
13
+ *
14
+ * @var Configuration
15
+ */
16
+ private $_config;
17
+
18
+ /**
19
+ *
20
+ * @var Http
21
+ */
22
+ private $_http;
23
+
24
+ /**
25
+ *
26
+ * @param Gateway $gateway
27
+ */
28
+ public function __construct($gateway)
29
+ {
30
+ $this->_gateway = $gateway;
31
+ $this->_config = $gateway->config;
32
+ $this->_config->assertHasAccessTokenOrKeys();
33
+ $this->_http = new Http($gateway->config);
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @return AddOn[]
39
+ */
40
+ public function all()
41
+ {
42
+ $path = $this->_config->merchantPath() . '/add_ons';
43
+ $response = $this->_http->get($path);
44
+
45
+ $addOns = ["addOn" => $response['addOns']];
46
+
47
+ return Util::extractAttributeAsArray(
48
+ $addOns,
49
+ 'addOn'
50
+ );
51
+ }
52
+ }
53
+ class_alias('Braintree\AddOnGateway', 'Braintree_AddOnGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Address.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree Address module
6
+ * PHP Version 5
7
+ * Creates and manages Braintree Addresses
8
+ *
9
+ * An Address belongs to a Customer. It can be associated to a
10
+ * CreditCard as the billing address. It can also be used
11
+ * as the shipping address when creating a Transaction.
12
+ *
13
+ * @package Braintree
14
+ *
15
+ * @property-read string $company
16
+ * @property-read string $countryName
17
+ * @property-read string $createdAt
18
+ * @property-read string $customerId
19
+ * @property-read string $extendedAddress
20
+ * @property-read string $firstName
21
+ * @property-read string $id
22
+ * @property-read string $lastName
23
+ * @property-read string $locality
24
+ * @property-read string $postalCode
25
+ * @property-read string $region
26
+ * @property-read string $streetAddress
27
+ * @property-read string $updatedAt
28
+ */
29
+ class Address extends Base
30
+ {
31
+ /**
32
+ * returns false if comparing object is not a Address,
33
+ * or is a Address with a different id
34
+ *
35
+ * @param object $other address to compare against
36
+ * @return boolean
37
+ */
38
+ public function isEqual($other)
39
+ {
40
+ return !($other instanceof self) ?
41
+ false :
42
+ ($this->id === $other->id && $this->customerId === $other->customerId);
43
+ }
44
+
45
+ /**
46
+ * create a printable representation of the object as:
47
+ * ClassName[property=value, property=value]
48
+ * @ignore
49
+ * @return string
50
+ */
51
+ public function __toString()
52
+ {
53
+ return __CLASS__ . '[' .
54
+ Util::attributesToString($this->_attributes) . ']';
55
+ }
56
+
57
+ /**
58
+ * sets instance properties from an array of values
59
+ *
60
+ * @ignore
61
+ * @access protected
62
+ * @param array $addressAttribs array of address data
63
+ * @return void
64
+ */
65
+ protected function _initialize($addressAttribs)
66
+ {
67
+ // set the attributes
68
+ $this->_attributes = $addressAttribs;
69
+ }
70
+
71
+ /**
72
+ * factory method: returns an instance of Address
73
+ * to the requesting method, with populated properties
74
+ * @ignore
75
+ * @return Address
76
+ */
77
+ public static function factory($attributes)
78
+ {
79
+ $instance = new self();
80
+ $instance->_initialize($attributes);
81
+ return $instance;
82
+
83
+ }
84
+
85
+
86
+ // static methods redirecting to gateway
87
+
88
+ /**
89
+ *
90
+ * @param array $attribs
91
+ * @return Address
92
+ */
93
+ public static function create($attribs)
94
+ {
95
+ return Configuration::gateway()->address()->create($attribs);
96
+ }
97
+
98
+ /**
99
+ *
100
+ * @param array $attribs
101
+ * @return Address
102
+ */
103
+ public static function createNoValidate($attribs)
104
+ {
105
+ return Configuration::gateway()->address()->createNoValidate($attribs);
106
+ }
107
+
108
+ /**
109
+ *
110
+ * @param Customer|int $customerOrId
111
+ * @param int $addressId
112
+ * @throws InvalidArgumentException
113
+ * @return Result\Successful
114
+ */
115
+ public static function delete($customerOrId = null, $addressId = null)
116
+ {
117
+ return Configuration::gateway()->address()->delete($customerOrId, $addressId);
118
+ }
119
+
120
+ /**
121
+ *
122
+ * @param Customer|int $customerOrId
123
+ * @param int $addressId
124
+ * @throws Exception\NotFound
125
+ * @return Address
126
+ */
127
+ public static function find($customerOrId, $addressId)
128
+ {
129
+ return Configuration::gateway()->address()->find($customerOrId, $addressId);
130
+ }
131
+
132
+ /**
133
+ *
134
+ * @param Customer|int $customerOrId
135
+ * @param int $addressId
136
+ * @param array $attributes
137
+ * @throws Exception\Unexpected
138
+ * @return Result\Successful|Result\Error
139
+ */
140
+ public static function update($customerOrId, $addressId, $attributes)
141
+ {
142
+ return Configuration::gateway()->address()->update($customerOrId, $addressId, $attributes);
143
+ }
144
+
145
+ public static function updateNoValidate($customerOrId, $addressId, $attributes)
146
+ {
147
+ return Configuration::gateway()->address()->updateNoValidate($customerOrId, $addressId, $attributes);
148
+ }
149
+ }
150
+ class_alias('Braintree\Address', 'Braintree_Address');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AddressGateway.php ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ /**
7
+ * Braintree AddressGateway module
8
+ * PHP Version 5
9
+ * Creates and manages Braintree Addresses
10
+ *
11
+ * An Address belongs to a Customer. It can be associated to a
12
+ * CreditCard as the billing address. It can also be used
13
+ * as the shipping address when creating a Transaction.
14
+ *
15
+ * @package Braintree
16
+ */
17
+ class AddressGateway
18
+ {
19
+ /**
20
+ *
21
+ * @var Gateway
22
+ */
23
+ private $_gateway;
24
+
25
+ /**
26
+ *
27
+ * @var Configuration
28
+ */
29
+ private $_config;
30
+
31
+ /**
32
+ *
33
+ * @var Http
34
+ */
35
+ private $_http;
36
+
37
+ /**
38
+ *
39
+ * @param Gateway $gateway
40
+ */
41
+ public function __construct($gateway)
42
+ {
43
+ $this->_gateway = $gateway;
44
+ $this->_config = $gateway->config;
45
+ $this->_config->assertHasAccessTokenOrKeys();
46
+ $this->_http = new Http($gateway->config);
47
+ }
48
+
49
+
50
+ /* public class methods */
51
+ /**
52
+ *
53
+ * @access public
54
+ * @param array $attribs
55
+ * @return Result\Successful|Result\Error
56
+ */
57
+ public function create($attribs)
58
+ {
59
+ Util::verifyKeys(self::createSignature(), $attribs);
60
+ $customerId = isset($attribs['customerId']) ?
61
+ $attribs['customerId'] :
62
+ null;
63
+
64
+ $this->_validateCustomerId($customerId);
65
+ unset($attribs['customerId']);
66
+ try {
67
+ return $this->_doCreate(
68
+ '/customers/' . $customerId . '/addresses',
69
+ ['address' => $attribs]
70
+ );
71
+ } catch (Exception\NotFound $e) {
72
+ throw new Exception\NotFound(
73
+ 'Customer ' . $customerId . ' not found.'
74
+ );
75
+ }
76
+ }
77
+
78
+ /**
79
+ * attempts the create operation assuming all data will validate
80
+ * returns a Address object instead of a Result
81
+ *
82
+ * @access public
83
+ * @param array $attribs
84
+ * @return self
85
+ * @throws Exception\ValidationError
86
+ */
87
+ public function createNoValidate($attribs)
88
+ {
89
+ $result = $this->create($attribs);
90
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
91
+
92
+ }
93
+
94
+ /**
95
+ * delete an address by id
96
+ *
97
+ * @param mixed $customerOrId
98
+ * @param string $addressId
99
+ */
100
+ public function delete($customerOrId = null, $addressId = null)
101
+ {
102
+ $this->_validateId($addressId);
103
+ $customerId = $this->_determineCustomerId($customerOrId);
104
+ $path = $this->_config->merchantPath() . '/customers/' . $customerId . '/addresses/' . $addressId;
105
+ $this->_http->delete($path);
106
+ return new Result\Successful();
107
+ }
108
+
109
+ /**
110
+ * find an address by id
111
+ *
112
+ * Finds the address with the given <b>addressId</b> that is associated
113
+ * to the given <b>customerOrId</b>.
114
+ * If the address cannot be found, a NotFound exception will be thrown.
115
+ *
116
+ *
117
+ * @access public
118
+ * @param mixed $customerOrId
119
+ * @param string $addressId
120
+ * @return Address
121
+ * @throws Exception\NotFound
122
+ */
123
+ public function find($customerOrId, $addressId)
124
+ {
125
+
126
+ $customerId = $this->_determineCustomerId($customerOrId);
127
+ $this->_validateId($addressId);
128
+
129
+ try {
130
+ $path = $this->_config->merchantPath() . '/customers/' . $customerId . '/addresses/' . $addressId;
131
+ $response = $this->_http->get($path);
132
+ return Address::factory($response['address']);
133
+ } catch (Exception\NotFound $e) {
134
+ throw new Exception\NotFound(
135
+ 'address for customer ' . $customerId .
136
+ ' with id ' . $addressId . ' not found.'
137
+ );
138
+ }
139
+
140
+ }
141
+
142
+ /**
143
+ * updates the address record
144
+ *
145
+ * if calling this method in context,
146
+ * customerOrId is the 2nd attribute, addressId 3rd.
147
+ * customerOrId & addressId are not sent in object context.
148
+ *
149
+ *
150
+ * @access public
151
+ * @param array $attributes
152
+ * @param mixed $customerOrId (only used in call)
153
+ * @param string $addressId (only used in call)
154
+ * @return Result\Successful|Result\Error
155
+ */
156
+ public function update($customerOrId, $addressId, $attributes)
157
+ {
158
+ $this->_validateId($addressId);
159
+ $customerId = $this->_determineCustomerId($customerOrId);
160
+ Util::verifyKeys(self::updateSignature(), $attributes);
161
+
162
+ $path = $this->_config->merchantPath() . '/customers/' . $customerId . '/addresses/' . $addressId;
163
+ $response = $this->_http->put($path, ['address' => $attributes]);
164
+
165
+ return $this->_verifyGatewayResponse($response);
166
+
167
+ }
168
+
169
+ /**
170
+ * update an address record, assuming validations will pass
171
+ *
172
+ * if calling this method in context,
173
+ * customerOrId is the 2nd attribute, addressId 3rd.
174
+ * customerOrId & addressId are not sent in object context.
175
+ *
176
+ * @access public
177
+ * @param array $transactionAttribs
178
+ * @param string $customerId
179
+ * @return Transaction
180
+ * @throws Exception\ValidationsFailed
181
+ * @see Address::update()
182
+ */
183
+ public function updateNoValidate($customerOrId, $addressId, $attributes)
184
+ {
185
+ $result = $this->update($customerOrId, $addressId, $attributes);
186
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
187
+ }
188
+
189
+ /**
190
+ * creates a full array signature of a valid create request
191
+ * @return array gateway create request format
192
+ */
193
+ public static function createSignature()
194
+ {
195
+ return [
196
+ 'company', 'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric',
197
+ 'countryName', 'customerId', 'extendedAddress', 'firstName',
198
+ 'lastName', 'locality', 'postalCode', 'region', 'streetAddress'
199
+ ];
200
+ }
201
+
202
+ /**
203
+ * creates a full array signature of a valid update request
204
+ * @return array gateway update request format
205
+ */
206
+ public static function updateSignature()
207
+ {
208
+ // TODO: remove customerId from update signature
209
+ return self::createSignature();
210
+
211
+ }
212
+
213
+ /**
214
+ * verifies that a valid address id is being used
215
+ * @ignore
216
+ * @param string $id address id
217
+ * @throws InvalidArgumentException
218
+ */
219
+ private function _validateId($id = null)
220
+ {
221
+ if (empty($id) || trim($id) == "") {
222
+ throw new InvalidArgumentException(
223
+ 'expected address id to be set'
224
+ );
225
+ }
226
+ if (!preg_match('/^[0-9A-Za-z_-]+$/', $id)) {
227
+ throw new InvalidArgumentException(
228
+ $id . ' is an invalid address id.'
229
+ );
230
+ }
231
+ }
232
+
233
+ /**
234
+ * verifies that a valid customer id is being used
235
+ * @ignore
236
+ * @param string $id customer id
237
+ * @throws InvalidArgumentException
238
+ */
239
+ private function _validateCustomerId($id = null)
240
+ {
241
+ if (empty($id) || trim($id) == "") {
242
+ throw new InvalidArgumentException(
243
+ 'expected customer id to be set'
244
+ );
245
+ }
246
+ if (!preg_match('/^[0-9A-Za-z_-]+$/', $id)) {
247
+ throw new InvalidArgumentException(
248
+ $id . ' is an invalid customer id.'
249
+ );
250
+ }
251
+
252
+ }
253
+
254
+ /**
255
+ * determines if a string id or Customer object was passed
256
+ * @ignore
257
+ * @param mixed $customerOrId
258
+ * @return string customerId
259
+ */
260
+ private function _determineCustomerId($customerOrId)
261
+ {
262
+ $customerId = ($customerOrId instanceof Customer) ? $customerOrId->id : $customerOrId;
263
+ $this->_validateCustomerId($customerId);
264
+ return $customerId;
265
+
266
+ }
267
+
268
+ /* private class methods */
269
+ /**
270
+ * sends the create request to the gateway
271
+ * @ignore
272
+ * @param string $subPath
273
+ * @param array $params
274
+ * @return Result\Successful|Result\Error
275
+ */
276
+ private function _doCreate($subPath, $params)
277
+ {
278
+ $fullPath = $this->_config->merchantPath() . $subPath;
279
+ $response = $this->_http->post($fullPath, $params);
280
+
281
+ return $this->_verifyGatewayResponse($response);
282
+ }
283
+
284
+ /**
285
+ * generic method for validating incoming gateway responses
286
+ *
287
+ * creates a new Address object and encapsulates
288
+ * it inside a Result\Successful object, or
289
+ * encapsulates an Errors object inside a Result\Error
290
+ * alternatively, throws an Unexpected exception if the response is invalid
291
+ *
292
+ * @ignore
293
+ * @param array $response gateway response values
294
+ * @return Result\Successful|Result\Error
295
+ * @throws Exception\Unexpected
296
+ */
297
+ private function _verifyGatewayResponse($response)
298
+ {
299
+ if (isset($response['address'])) {
300
+ // return a populated instance of Address
301
+ return new Result\Successful(
302
+ Address::factory($response['address'])
303
+ );
304
+ } else if (isset($response['apiErrorResponse'])) {
305
+ return new Result\Error($response['apiErrorResponse']);
306
+ } else {
307
+ throw new Exception\Unexpected(
308
+ "Expected address or apiErrorResponse"
309
+ );
310
+ }
311
+
312
+ }
313
+ }
314
+ class_alias('Braintree\AddressGateway', 'Braintree_AddressGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AmexExpressCheckoutCard.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree AmexExpressCheckoutCard module
6
+ * Creates and manages Braintree Amex Express Checkout cards
7
+ *
8
+ * <b>== More information ==</b>
9
+ *
10
+ * See {@link https://developers.braintreepayments.com/javascript+php}<br />
11
+ *
12
+ * @package Braintree
13
+ * @category Resources
14
+ *
15
+ * @property-read string $createdAt
16
+ * @property-read string $default
17
+ * @property-read string $updatedAt
18
+ * @property-read string $customerId
19
+ * @property-read string $cardType
20
+ * @property-read string $bin
21
+ * @property-read string $cardMemberExpiryDate
22
+ * @property-read string $cardMemberNumber
23
+ * @property-read string $sourceDescription
24
+ * @property-read string $token
25
+ * @property-read string $imageUrl
26
+ * @property-read string $expirationMonth
27
+ * @property-read string $expirationYear
28
+ */
29
+ class AmexExpressCheckoutCard extends Base
30
+ {
31
+ /* instance methods */
32
+ /**
33
+ * returns false if default is null or false
34
+ *
35
+ * @return boolean
36
+ */
37
+ public function isDefault()
38
+ {
39
+ return $this->default;
40
+ }
41
+
42
+ /**
43
+ * factory method: returns an instance of AmexExpressCheckoutCard
44
+ * to the requesting method, with populated properties
45
+ *
46
+ * @ignore
47
+ * @return AmexExpressCheckoutCard
48
+ */
49
+ public static function factory($attributes)
50
+ {
51
+
52
+ $instance = new self();
53
+ $instance->_initialize($attributes);
54
+ return $instance;
55
+ }
56
+
57
+ /**
58
+ * sets instance properties from an array of values
59
+ *
60
+ * @access protected
61
+ * @param array $amexExpressCheckoutCardAttribs array of Amex Express Checkout card properties
62
+ * @return void
63
+ */
64
+ protected function _initialize($amexExpressCheckoutCardAttribs)
65
+ {
66
+ // set the attributes
67
+ $this->_attributes = $amexExpressCheckoutCardAttribs;
68
+
69
+ $subscriptionArray = [];
70
+ if (isset($amexExpressCheckoutCardAttribs['subscriptions'])) {
71
+ foreach ($amexExpressCheckoutCardAttribs['subscriptions'] AS $subscription) {
72
+ $subscriptionArray[] = Subscription::factory($subscription);
73
+ }
74
+ }
75
+
76
+ $this->_set('subscriptions', $subscriptionArray);
77
+ }
78
+ }
79
+ class_alias('Braintree\AmexExpressCheckoutCard', 'Braintree_AmexExpressCheckoutCard');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/AndroidPayCard.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree AndroidPayCard module
6
+ * Creates and manages Braintree Android Pay cards
7
+ *
8
+ * <b>== More information ==</b>
9
+ *
10
+ * See {@link https://developers.braintreepayments.com/javascript+php}<br />
11
+ *
12
+ * @package Braintree
13
+ * @category Resources
14
+ *
15
+ * @property-read string $bin
16
+ * @property-read string $cardType
17
+ * @property-read string $createdAt
18
+ * @property-read string $customerId
19
+ * @property-read string $default
20
+ * @property-read string $expirationMonth
21
+ * @property-read string $expirationYear
22
+ * @property-read string $googleTransactionId
23
+ * @property-read string $imageUrl
24
+ * @property-read string $last4
25
+ * @property-read string $sourceCardLast4
26
+ * @property-read string $sourceCardType
27
+ * @property-read string $sourceDescription
28
+ * @property-read string $token
29
+ * @property-read string $updatedAt
30
+ * @property-read string $virtualCardLast4
31
+ * @property-read string $virtualCardType
32
+ */
33
+ class AndroidPayCard extends Base
34
+ {
35
+ /* instance methods */
36
+ /**
37
+ * returns false if default is null or false
38
+ *
39
+ * @return boolean
40
+ */
41
+ public function isDefault()
42
+ {
43
+ return $this->default;
44
+ }
45
+
46
+ /**
47
+ * factory method: returns an instance of AndroidPayCard
48
+ * to the requesting method, with populated properties
49
+ *
50
+ * @ignore
51
+ * @return AndroidPayCard
52
+ */
53
+ public static function factory($attributes)
54
+ {
55
+ $defaultAttributes = [
56
+ 'expirationMonth' => '',
57
+ 'expirationYear' => '',
58
+ 'last4' => $attributes['virtualCardLast4'],
59
+ 'cardType' => $attributes['virtualCardType'],
60
+ ];
61
+
62
+ $instance = new self();
63
+ $instance->_initialize(array_merge($defaultAttributes, $attributes));
64
+ return $instance;
65
+ }
66
+
67
+ /**
68
+ * sets instance properties from an array of values
69
+ *
70
+ * @access protected
71
+ * @param array $androidPayCardAttribs array of Android Pay card properties
72
+ * @return void
73
+ */
74
+ protected function _initialize($androidPayCardAttribs)
75
+ {
76
+ // set the attributes
77
+ $this->_attributes = $androidPayCardAttribs;
78
+
79
+ $subscriptionArray = [];
80
+ if (isset($androidPayCardAttribs['subscriptions'])) {
81
+ foreach ($androidPayCardAttribs['subscriptions'] AS $subscription) {
82
+ $subscriptionArray[] = Subscription::factory($subscription);
83
+ }
84
+ }
85
+
86
+ $this->_set('subscriptions', $subscriptionArray);
87
+ }
88
+ }
89
+ class_alias('Braintree\AndroidPayCard', 'Braintree_AndroidPayCard');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ApplePayCard.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree ApplePayCard module
6
+ * Creates and manages Braintree Apple Pay cards
7
+ *
8
+ * <b>== More information ==</b>
9
+ *
10
+ * See {@link https://developers.braintreepayments.com/javascript+php}<br />
11
+ *
12
+ * @package Braintree
13
+ * @category Resources
14
+ *
15
+ * @property-read string $cardType
16
+ * @property-read string $createdAt
17
+ * @property-read string $customerId
18
+ * @property-read string $expirationDate
19
+ * @property-read string $expirationMonth
20
+ * @property-read string $expirationYear
21
+ * @property-read string $imageUrl
22
+ * @property-read string $last4
23
+ * @property-read string $token
24
+ * @property-read string $paymentInstrumentName
25
+ * @property-read string $sourceDescription
26
+ * @property-read string $updatedAt
27
+ */
28
+ class ApplePayCard extends Base
29
+ {
30
+ // Card Type
31
+ const AMEX = 'Apple Pay - American Express';
32
+ const MASTER_CARD = 'Apple Pay - MasterCard';
33
+ const VISA = 'Apple Pay - Visa';
34
+
35
+ /* instance methods */
36
+ /**
37
+ * returns false if default is null or false
38
+ *
39
+ * @return boolean
40
+ */
41
+ public function isDefault()
42
+ {
43
+ return $this->default;
44
+ }
45
+
46
+ /**
47
+ * checks whether the card is expired based on the current date
48
+ *
49
+ * @return boolean
50
+ */
51
+ public function isExpired()
52
+ {
53
+ return $this->expired;
54
+ }
55
+
56
+ /**
57
+ * factory method: returns an instance of ApplePayCard
58
+ * to the requesting method, with populated properties
59
+ *
60
+ * @ignore
61
+ * @return ApplePayCard
62
+ */
63
+ public static function factory($attributes)
64
+ {
65
+ $defaultAttributes = [
66
+ 'expirationMonth' => '',
67
+ 'expirationYear' => '',
68
+ 'last4' => '',
69
+ ];
70
+
71
+ $instance = new self();
72
+ $instance->_initialize(array_merge($defaultAttributes, $attributes));
73
+ return $instance;
74
+ }
75
+
76
+ /**
77
+ * sets instance properties from an array of values
78
+ *
79
+ * @access protected
80
+ * @param array $applePayCardAttribs array of Apple Pay card properties
81
+ * @return void
82
+ */
83
+ protected function _initialize($applePayCardAttribs)
84
+ {
85
+ // set the attributes
86
+ $this->_attributes = $applePayCardAttribs;
87
+
88
+ $subscriptionArray = [];
89
+ if (isset($applePayCardAttribs['subscriptions'])) {
90
+ foreach ($applePayCardAttribs['subscriptions'] AS $subscription) {
91
+ $subscriptionArray[] = Subscription::factory($subscription);
92
+ }
93
+ }
94
+
95
+ $this->_set('subscriptions', $subscriptionArray);
96
+ $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
97
+ }
98
+ }
99
+ class_alias('Braintree\ApplePayCard', 'Braintree_ApplePayCard');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Base.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree PHP Library.
6
+ *
7
+ * Braintree base class and initialization
8
+ * Provides methods to child classes. This class cannot be instantiated.
9
+ *
10
+ * PHP version 5
11
+ */
12
+ abstract class Base
13
+ {
14
+ protected $_attributes = [];
15
+
16
+ /**
17
+ * @ignore
18
+ * don't permit an explicit call of the constructor!
19
+ * (like $t = new Transaction())
20
+ */
21
+ protected function __construct()
22
+ {
23
+ }
24
+
25
+ /**
26
+ * Disable cloning of objects
27
+ *
28
+ * @ignore
29
+ */
30
+ protected function __clone()
31
+ {
32
+ }
33
+
34
+ /**
35
+ * Accessor for instance properties stored in the private $_attributes property
36
+ *
37
+ * @ignore
38
+ * @param string $name
39
+ * @return mixed
40
+ */
41
+ public function __get($name)
42
+ {
43
+ if (array_key_exists($name, $this->_attributes)) {
44
+ return $this->_attributes[$name];
45
+ }
46
+ else {
47
+ trigger_error('Undefined property on ' . get_class($this) . ': ' . $name, E_USER_NOTICE);
48
+ return null;
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Checks for the existance of a property stored in the private $_attributes property
54
+ *
55
+ * @ignore
56
+ * @param string $name
57
+ * @return boolean
58
+ */
59
+ public function __isset($name)
60
+ {
61
+ return array_key_exists($name, $this->_attributes);
62
+ }
63
+
64
+ /**
65
+ * Mutator for instance properties stored in the private $_attributes property
66
+ *
67
+ * @ignore
68
+ * @param string $key
69
+ * @param mixed $value
70
+ */
71
+ public function _set($key, $value)
72
+ {
73
+ $this->_attributes[$key] = $value;
74
+ }
75
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ClientToken.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class ClientToken
5
+ {
6
+ const DEFAULT_VERSION = 2;
7
+
8
+
9
+ // static methods redirecting to gateway
10
+
11
+ /**
12
+ *
13
+ * @param array $params
14
+ * @return array
15
+ */
16
+ public static function generate($params=[])
17
+ {
18
+ return Configuration::gateway()->clientToken()->generate($params);
19
+ }
20
+
21
+ /**
22
+ *
23
+ * @param type $params
24
+ * @throws InvalidArgumentException
25
+ */
26
+ public static function conditionallyVerifyKeys($params)
27
+ {
28
+ return Configuration::gateway()->clientToken()->conditionallyVerifyKeys($params);
29
+ }
30
+
31
+ /**
32
+ *
33
+ * @return string client token retrieved from server
34
+ */
35
+ public static function generateWithCustomerIdSignature()
36
+ {
37
+ return Configuration::gateway()->clientToken()->generateWithCustomerIdSignature();
38
+ }
39
+
40
+ /**
41
+ *
42
+ * @return string client token retrieved from server
43
+ */
44
+ public static function generateWithoutCustomerIdSignature()
45
+ {
46
+ return Configuration::gateway()->clientToken()->generateWithoutCustomerIdSignature();
47
+ }
48
+ }
49
+ class_alias('Braintree\ClientToken', 'Braintree_ClientToken');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ClientTokenGateway.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ class ClientTokenGateway
7
+ {
8
+ /**
9
+ *
10
+ * @var Gateway
11
+ */
12
+ private $_gateway;
13
+
14
+ /**
15
+ *
16
+ * @var Configuration
17
+ */
18
+ private $_config;
19
+
20
+ /**
21
+ *
22
+ * @var Http
23
+ */
24
+ private $_http;
25
+
26
+ /**
27
+ *
28
+ * @param Gateway $gateway
29
+ */
30
+ public function __construct($gateway)
31
+ {
32
+ $this->_gateway = $gateway;
33
+ $this->_config = $gateway->config;
34
+ $this->_config->assertHasAccessTokenOrKeys();
35
+ $this->_http = new Http($gateway->config);
36
+ }
37
+
38
+ public function generate($params=[])
39
+ {
40
+ if (!array_key_exists("version", $params)) {
41
+ $params["version"] = ClientToken::DEFAULT_VERSION;
42
+ }
43
+
44
+ $this->conditionallyVerifyKeys($params);
45
+ $generateParams = ["client_token" => $params];
46
+
47
+ return $this->_doGenerate('/client_token', $generateParams);
48
+ }
49
+
50
+ /**
51
+ * sends the generate request to the gateway
52
+ *
53
+ * @ignore
54
+ * @param var $url
55
+ * @param array $params
56
+ * @return string
57
+ */
58
+ public function _doGenerate($subPath, $params)
59
+ {
60
+ $fullPath = $this->_config->merchantPath() . $subPath;
61
+ $response = $this->_http->post($fullPath, $params);
62
+
63
+ return $this->_verifyGatewayResponse($response);
64
+ }
65
+
66
+ /**
67
+ *
68
+ * @param array $params
69
+ * @throws InvalidArgumentException
70
+ */
71
+ public function conditionallyVerifyKeys($params)
72
+ {
73
+ if (array_key_exists("customerId", $params)) {
74
+ Util::verifyKeys($this->generateWithCustomerIdSignature(), $params);
75
+ } else {
76
+ Util::verifyKeys($this->generateWithoutCustomerIdSignature(), $params);
77
+ }
78
+ }
79
+
80
+ /**
81
+ *
82
+ * @return mixed[]
83
+ */
84
+ public function generateWithCustomerIdSignature()
85
+ {
86
+ return [
87
+ "version", "customerId", "proxyMerchantId",
88
+ ["options" => ["makeDefault", "verifyCard", "failOnDuplicatePaymentMethod"]],
89
+ "merchantAccountId", "sepaMandateType", "sepaMandateAcceptanceLocation"];
90
+ }
91
+
92
+ /**
93
+ *
94
+ * @return string[]
95
+ */
96
+ public function generateWithoutCustomerIdSignature()
97
+ {
98
+ return ["version", "proxyMerchantId", "merchantAccountId"];
99
+ }
100
+
101
+ /**
102
+ * generic method for validating incoming gateway responses
103
+ *
104
+ * If the request is successful, returns a client token string.
105
+ * Otherwise, throws an InvalidArgumentException with the error
106
+ * response from the Gateway or an HTTP status code exception.
107
+ *
108
+ * @ignore
109
+ * @param array $response gateway response values
110
+ * @return string client token
111
+ * @throws InvalidArgumentException | HTTP status code exception
112
+ */
113
+ private function _verifyGatewayResponse($response)
114
+ {
115
+ if (isset($response['clientToken'])) {
116
+ return $response['clientToken']['value'];
117
+ } elseif (isset($response['apiErrorResponse'])) {
118
+ throw new InvalidArgumentException(
119
+ $response['apiErrorResponse']['message']
120
+ );
121
+ } else {
122
+ throw new Exception\Unexpected(
123
+ "Expected clientToken or apiErrorResponse"
124
+ );
125
+ }
126
+ }
127
+
128
+ }
129
+ class_alias('Braintree\ClientTokenGateway', 'Braintree_ClientTokenGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CoinbaseAccount.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree CoinbaseAccount module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+
11
+ /**
12
+ * Manages Braintree CoinbaseAccounts
13
+ *
14
+ * <b>== More information ==</b>
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @category Resources
19
+ *
20
+ * @property-read string $customerId
21
+ * @property-read string $token
22
+ * @property-read string $userId
23
+ * @property-read string $userName
24
+ * @property-read string $userEmail
25
+ */
26
+ class CoinbaseAccount extends Base
27
+ {
28
+ /**
29
+ * factory method: returns an instance of CoinbaseAccount
30
+ * to the requesting method, with populated properties
31
+ *
32
+ * @ignore
33
+ * @return CoinbaseAccount
34
+ */
35
+ public static function factory($attributes)
36
+ {
37
+ $instance = new self();
38
+ $instance->_initialize($attributes);
39
+ return $instance;
40
+ }
41
+
42
+ /* instance methods */
43
+
44
+ /**
45
+ * returns false if default is null or false
46
+ *
47
+ * @return boolean
48
+ */
49
+ public function isDefault()
50
+ {
51
+ return $this->default;
52
+ }
53
+
54
+ /**
55
+ * sets instance properties from an array of values
56
+ *
57
+ * @access protected
58
+ * @param array $coinbaseAccountAttribs array of coinbaseAccount data
59
+ * @return void
60
+ */
61
+ protected function _initialize($coinbaseAccountAttribs)
62
+ {
63
+ // set the attributes
64
+ $this->_attributes = $coinbaseAccountAttribs;
65
+
66
+ $subscriptionArray = [];
67
+ if (isset($coinbaseAccountAttribs['subscriptions'])) {
68
+ foreach ($coinbaseAccountAttribs['subscriptions'] AS $subscription) {
69
+ $subscriptionArray[] = Subscription::factory($subscription);
70
+ }
71
+ }
72
+
73
+ $this->_set('subscriptions', $subscriptionArray);
74
+ }
75
+
76
+ /**
77
+ * create a printable representation of the object as:
78
+ * ClassName[property=value, property=value]
79
+ * @return string
80
+ */
81
+ public function __toString()
82
+ {
83
+ return __CLASS__ . '[' .
84
+ Util::attributesToString($this->_attributes) .']';
85
+ }
86
+
87
+
88
+ // static methods redirecting to gateway
89
+
90
+ public static function find($token)
91
+ {
92
+ return Configuration::gateway()->coinbaseAccount()->find($token);
93
+ }
94
+
95
+ public static function update($token, $attributes)
96
+ {
97
+ return Configuration::gateway()->coinbaseAccount()->update($token, $attributes);
98
+ }
99
+
100
+ public static function delete($token)
101
+ {
102
+ return Configuration::gateway()->coinbaseAccount()->delete($token);
103
+ }
104
+
105
+ public static function sale($token, $transactionAttribs)
106
+ {
107
+ return Configuration::gateway()->coinbaseAccount()->sale($token, $transactionAttribs);
108
+ }
109
+ }
110
+ class_alias('Braintree\CoinbaseAccount', 'Braintree_CoinbaseAccount');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Collection.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use Countable;
5
+ use IteratorAggregate;
6
+ use ArrayAccess;
7
+ use OutOfRangeException;
8
+ use ArrayIterator;
9
+
10
+ /**
11
+ * Braintree Generic collection
12
+ *
13
+ * PHP Version 5
14
+ *
15
+ * Based on Generic Collection class from:
16
+ * {@link http://codeutopia.net/code/library/CU/Collection.php}
17
+ *
18
+ * @package Braintree
19
+ * @subpackage Utility
20
+ */
21
+
22
+ class Collection implements Countable, IteratorAggregate, ArrayAccess
23
+ {
24
+ /**
25
+ *
26
+ * @var array collection storage
27
+ */
28
+ protected $_collection = [];
29
+
30
+ /**
31
+ * Add a value into the collection
32
+ * @param string $value
33
+ */
34
+ public function add($value)
35
+ {
36
+ $this->_collection[] = $value;
37
+ }
38
+
39
+ /**
40
+ * Set index's value
41
+ * @param integer $index
42
+ * @param mixed $value
43
+ * @throws OutOfRangeException
44
+ */
45
+ public function set($index, $value)
46
+ {
47
+ if($index >= $this->count())
48
+ throw new OutOfRangeException('Index out of range');
49
+
50
+ $this->_collection[$index] = $value;
51
+ }
52
+
53
+ /**
54
+ * Remove a value from the collection
55
+ * @param integer $index index to remove
56
+ * @throws OutOfRangeException if index is out of range
57
+ */
58
+ public function remove($index)
59
+ {
60
+ if($index >= $this->count())
61
+ throw new OutOfRangeException('Index out of range');
62
+
63
+ array_splice($this->_collection, $index, 1);
64
+ }
65
+
66
+ /**
67
+ * Return value at index
68
+ * @param integer $index
69
+ * @return mixed
70
+ * @throws OutOfRangeException
71
+ */
72
+ public function get($index)
73
+ {
74
+ if($index >= $this->count())
75
+ throw new OutOfRangeException('Index out of range');
76
+
77
+ return $this->_collection[$index];
78
+ }
79
+
80
+ /**
81
+ * Determine if index exists
82
+ * @param integer $index
83
+ * @return boolean
84
+ */
85
+ public function exists($index)
86
+ {
87
+ if($index >= $this->count())
88
+ return false;
89
+
90
+ return true;
91
+ }
92
+ /**
93
+ * Return count of items in collection
94
+ * Implements countable
95
+ * @return integer
96
+ */
97
+ public function count()
98
+ {
99
+ return count($this->_collection);
100
+ }
101
+
102
+
103
+ /**
104
+ * Return an iterator
105
+ * Implements IteratorAggregate
106
+ * @return ArrayIterator
107
+ */
108
+ public function getIterator()
109
+ {
110
+ return new ArrayIterator($this->_collection);
111
+ }
112
+
113
+ /**
114
+ * Set offset to value
115
+ * Implements ArrayAccess
116
+ * @see set
117
+ * @param integer $offset
118
+ * @param mixed $value
119
+ */
120
+ public function offsetSet($offset, $value)
121
+ {
122
+ $this->set($offset, $value);
123
+ }
124
+
125
+ /**
126
+ * Unset offset
127
+ * Implements ArrayAccess
128
+ * @see remove
129
+ * @param integer $offset
130
+ */
131
+ public function offsetUnset($offset)
132
+ {
133
+ $this->remove($offset);
134
+ }
135
+
136
+ /**
137
+ * get an offset's value
138
+ * Implements ArrayAccess
139
+ * @see get
140
+ * @param integer $offset
141
+ * @return mixed
142
+ */
143
+ public function offsetGet($offset)
144
+ {
145
+ return $this->get($offset);
146
+ }
147
+
148
+ /**
149
+ * Determine if offset exists
150
+ * Implements ArrayAccess
151
+ * @see exists
152
+ * @param integer $offset
153
+ * @return boolean
154
+ */
155
+ public function offsetExists($offset)
156
+ {
157
+ return $this->exists($offset);
158
+ }
159
+
160
+ }
161
+ class_alias('Braintree\Collection', 'Braintree_Collection');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Configuration.php ADDED
@@ -0,0 +1,602 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ *
6
+ * Configuration registry
7
+ *
8
+ * @package Braintree
9
+ * @subpackage Utility
10
+ */
11
+
12
+ class Configuration
13
+ {
14
+ public static $global;
15
+
16
+ private $_environment = null;
17
+ private $_merchantId = null;
18
+ private $_publicKey = null;
19
+ private $_privateKey = null;
20
+ private $_clientId = null;
21
+ private $_clientSecret = null;
22
+ private $_accessToken = null;
23
+ private $_proxyHost = null;
24
+ private $_proxyPort = null;
25
+ private $_proxyType = null;
26
+ private $_proxyUser = null;
27
+ private $_proxyPassword = null;
28
+ private $_timeout = 60;
29
+ private $_sslVersion = null;
30
+ private $_acceptGzipEncoding = true;
31
+
32
+ /**
33
+ * Braintree API version to use
34
+ * @access public
35
+ */
36
+ const API_VERSION = 4;
37
+
38
+ public function __construct($attribs = [])
39
+ {
40
+ foreach ($attribs as $kind => $value) {
41
+ if ($kind == 'environment') {
42
+ CredentialsParser::assertValidEnvironment($value);
43
+ $this->_environment = $value;
44
+ }
45
+ if ($kind == 'merchantId') {
46
+ $this->_merchantId = $value;
47
+ }
48
+ if ($kind == 'publicKey') {
49
+ $this->_publicKey = $value;
50
+ }
51
+ if ($kind == 'privateKey') {
52
+ $this->_privateKey = $value;
53
+ }
54
+ }
55
+
56
+ if (isset($attribs['clientId']) || isset($attribs['accessToken'])) {
57
+ if (isset($attribs['environment']) || isset($attribs['merchantId']) || isset($attribs['publicKey']) || isset($attribs['privateKey'])) {
58
+ throw new Exception\Configuration('Cannot mix OAuth credentials (clientId, clientSecret, accessToken) with key credentials (publicKey, privateKey, environment, merchantId).');
59
+ }
60
+ $parsedCredentials = new CredentialsParser($attribs);
61
+
62
+ $this->_environment = $parsedCredentials->getEnvironment();
63
+ $this->_merchantId = $parsedCredentials->getMerchantId();
64
+ $this->_clientId = $parsedCredentials->getClientId();
65
+ $this->_clientSecret = $parsedCredentials->getClientSecret();
66
+ $this->_accessToken = $parsedCredentials->getAccessToken();
67
+ }
68
+ }
69
+
70
+ /**
71
+ * resets configuration to default
72
+ * @access public
73
+ */
74
+ public static function reset()
75
+ {
76
+ self::$global = new Configuration();
77
+ }
78
+
79
+ public static function gateway()
80
+ {
81
+ return new Gateway(self::$global);
82
+ }
83
+
84
+ public static function environment($value=null)
85
+ {
86
+ if (empty($value)) {
87
+ return self::$global->getEnvironment();
88
+ }
89
+ CredentialsParser::assertValidEnvironment($value);
90
+ self::$global->setEnvironment($value);
91
+ }
92
+
93
+ public static function merchantId($value=null)
94
+ {
95
+ if (empty($value)) {
96
+ return self::$global->getMerchantId();
97
+ }
98
+ self::$global->setMerchantId($value);
99
+ }
100
+
101
+ public static function publicKey($value=null)
102
+ {
103
+ if (empty($value)) {
104
+ return self::$global->getPublicKey();
105
+ }
106
+ self::$global->setPublicKey($value);
107
+ }
108
+
109
+ public static function privateKey($value=null)
110
+ {
111
+ if (empty($value)) {
112
+ return self::$global->getPrivateKey();
113
+ }
114
+ self::$global->setPrivateKey($value);
115
+ }
116
+
117
+ /**
118
+ * Sets or gets the read timeout to use for making requests.
119
+ *
120
+ * @param integer $value If provided, sets the read timeout
121
+ * @return integer The read timeout used for connecting to Braintree
122
+ */
123
+ public static function timeout($value=null)
124
+ {
125
+ if (empty($value)) {
126
+ return self::$global->getTimeout();
127
+ }
128
+ self::$global->setTimeout($value);
129
+ }
130
+
131
+ /**
132
+ * Sets or gets the SSL version to use for making requests. See
133
+ * http://php.net/manual/en/function.curl-setopt.php for possible
134
+ * CURLOPT_SSLVERSION values.
135
+ *
136
+ * @param integer $value If provided, sets the SSL version
137
+ * @return integer The SSL version used for connecting to Braintree
138
+ */
139
+ public static function sslVersion($value=null)
140
+ {
141
+ if (empty($value)) {
142
+ return self::$global->getSslVersion();
143
+ }
144
+ self::$global->setSslVersion($value);
145
+ }
146
+
147
+ /**
148
+ * Sets or gets the proxy host to use for connecting to Braintree
149
+ *
150
+ * @param string $value If provided, sets the proxy host
151
+ * @return string The proxy host used for connecting to Braintree
152
+ */
153
+ public static function proxyHost($value = null)
154
+ {
155
+ if (empty($value)) {
156
+ return self::$global->getProxyHost();
157
+ }
158
+ self::$global->setProxyHost($value);
159
+ }
160
+
161
+ /**
162
+ * Sets or gets the port of the proxy to use for connecting to Braintree
163
+ *
164
+ * @param string $value If provided, sets the port of the proxy
165
+ * @return string The port of the proxy used for connecting to Braintree
166
+ */
167
+ public static function proxyPort($value = null)
168
+ {
169
+ if (empty($value)) {
170
+ return self::$global->getProxyPort();
171
+ }
172
+ self::$global->setProxyPort($value);
173
+ }
174
+
175
+ /**
176
+ * Sets or gets the proxy type to use for connecting to Braintree. This value
177
+ * can be any of the CURLOPT_PROXYTYPE options in PHP cURL.
178
+ *
179
+ * @param string $value If provided, sets the proxy type
180
+ * @return string The proxy type used for connecting to Braintree
181
+ */
182
+ public static function proxyType($value = null)
183
+ {
184
+ if (empty($value)) {
185
+ return self::$global->getProxyType();
186
+ }
187
+ self::$global->setProxyType($value);
188
+ }
189
+
190
+ /**
191
+ * Specifies whether or not a proxy is properly configured
192
+ *
193
+ * @return bool true if a proxy is configured properly, false if not
194
+ */
195
+ public static function isUsingProxy()
196
+ {
197
+ $proxyHost = self::$global->getProxyHost();
198
+ $proxyPort = self::$global->getProxyPort();
199
+ return !empty($proxyHost) && !empty($proxyPort);
200
+ }
201
+
202
+ public static function proxyUser($value = null)
203
+ {
204
+ if (empty($value)) {
205
+ return self::$global->getProxyUser();
206
+ }
207
+ self::$global->setProxyUser($value);
208
+ }
209
+
210
+ public static function proxyPassword($value = null)
211
+ {
212
+ if (empty($value)) {
213
+ return self::$global->getProxyPassword();
214
+ }
215
+ self::$global->setProxyPassword($value);
216
+ }
217
+
218
+ /**
219
+ * Specified whether or not a username and password have been provided for
220
+ * use with an authenticated proxy
221
+ *
222
+ * @return bool true if both proxyUser and proxyPassword are present
223
+ */
224
+ public static function isAuthenticatedProxy()
225
+ {
226
+ $proxyUser = self::$global->getProxyUser();
227
+ $proxyPwd = self::$global->getProxyPassword();
228
+ return !empty($proxyUser) && !empty($proxyPwd);
229
+ }
230
+
231
+ /**
232
+ * Specify if the HTTP client is able to decode gzipped responses.
233
+ *
234
+ * @param bool $value If true, will send an Accept-Encoding header with a gzip value. If false, will not send an Accept-Encoding header with a gzip value.
235
+ * @return bool true if an Accept-Encoding header with a gzip value will be sent, false if not
236
+ */
237
+ public static function acceptGzipEncoding($value = null)
238
+ {
239
+ if (is_null($value)) {
240
+ return self::$global->getAcceptGzipEncoding();
241
+ }
242
+ self::$global->setAcceptGzipEncoding($value);
243
+ }
244
+
245
+ public static function assertGlobalHasAccessTokenOrKeys()
246
+ {
247
+ self::$global->assertHasAccessTokenOrKeys();
248
+ }
249
+
250
+ public function assertHasAccessTokenOrKeys()
251
+ {
252
+ if (empty($this->_accessToken)) {
253
+ if (empty($this->_merchantId)) {
254
+ throw new Exception\Configuration('Braintree\\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\\Gateway).');
255
+ } else if (empty($this->_environment)) {
256
+ throw new Exception\Configuration('Braintree\\Configuration::environment needs to be set.');
257
+ } else if (empty($this->_publicKey)) {
258
+ throw new Exception\Configuration('Braintree\\Configuration::publicKey needs to be set.');
259
+ } else if (empty($this->_privateKey)) {
260
+ throw new Exception\Configuration('Braintree\\Configuration::privateKey needs to be set.');
261
+ }
262
+ }
263
+ }
264
+
265
+ public function assertHasClientCredentials()
266
+ {
267
+ $this->assertHasClientId();
268
+ $this->assertHasClientSecret();
269
+ }
270
+
271
+ public function assertHasClientId()
272
+ {
273
+ if (empty($this->_clientId)) {
274
+ throw new Exception\Configuration('clientId needs to be passed to Braintree\\Gateway.');
275
+ }
276
+ }
277
+
278
+ public function assertHasClientSecret()
279
+ {
280
+ if (empty($this->_clientSecret)) {
281
+ throw new Exception\Configuration('clientSecret needs to be passed to Braintree\\Gateway.');
282
+ }
283
+ }
284
+
285
+ public function getEnvironment()
286
+ {
287
+ return $this->_environment;
288
+ }
289
+
290
+ /**
291
+ * Do not use this method directly. Pass in the environment to the constructor.
292
+ */
293
+ public function setEnvironment($value)
294
+ {
295
+ $this->_environment = $value;
296
+ }
297
+
298
+ public function getMerchantId()
299
+ {
300
+ return $this->_merchantId;
301
+ }
302
+
303
+ /**
304
+ * Do not use this method directly. Pass in the merchantId to the constructor.
305
+ */
306
+ public function setMerchantId($value)
307
+ {
308
+ $this->_merchantId = $value;
309
+ }
310
+
311
+ public function getPublicKey()
312
+ {
313
+ return $this->_publicKey;
314
+ }
315
+
316
+ public function getClientId()
317
+ {
318
+ return $this->_clientId;
319
+ }
320
+
321
+ /**
322
+ * Do not use this method directly. Pass in the publicKey to the constructor.
323
+ */
324
+ public function setPublicKey($value)
325
+ {
326
+ $this->_publicKey = $value;
327
+ }
328
+
329
+ public function getPrivateKey()
330
+ {
331
+ return $this->_privateKey;
332
+ }
333
+
334
+ public function getClientSecret()
335
+ {
336
+ return $this->_clientSecret;
337
+ }
338
+
339
+ /**
340
+ * Do not use this method directly. Pass in the privateKey to the constructor.
341
+ */
342
+ public function setPrivateKey($value)
343
+ {
344
+ $this->_privateKey = $value;
345
+ }
346
+
347
+ private function setProxyHost($value)
348
+ {
349
+ $this->_proxyHost = $value;
350
+ }
351
+
352
+ public function getProxyHost()
353
+ {
354
+ return $this->_proxyHost;
355
+ }
356
+
357
+ private function setProxyPort($value)
358
+ {
359
+ $this->_proxyPort = $value;
360
+ }
361
+
362
+ public function getProxyPort()
363
+ {
364
+ return $this->_proxyPort;
365
+ }
366
+
367
+ private function setProxyType($value)
368
+ {
369
+ $this->_proxyType = $value;
370
+ }
371
+
372
+ public function getProxyType()
373
+ {
374
+ return $this->_proxyType;
375
+ }
376
+
377
+ private function setProxyUser($value)
378
+ {
379
+ $this->_proxyUser = $value;
380
+ }
381
+
382
+ public function getProxyUser()
383
+ {
384
+ return $this->_proxyUser;
385
+ }
386
+
387
+ private function setProxyPassword($value)
388
+ {
389
+ $this->_proxyPassword = $value;
390
+ }
391
+
392
+ public function getProxyPassword()
393
+ {
394
+ return $this->_proxyPassword;
395
+ }
396
+
397
+ private function setTimeout($value)
398
+ {
399
+ $this->_timeout = $value;
400
+ }
401
+
402
+ public function getTimeout()
403
+ {
404
+ return $this->_timeout;
405
+ }
406
+
407
+ private function setSslVersion($value)
408
+ {
409
+ $this->_sslVersion = $value;
410
+ }
411
+
412
+ private function getSslVersion()
413
+ {
414
+ return $this->_sslVersion;
415
+ }
416
+
417
+ private function getAcceptGzipEncoding()
418
+ {
419
+ return $this->_acceptGzipEncoding;
420
+ }
421
+
422
+ private function setAcceptGzipEncoding($value)
423
+ {
424
+ $this->_acceptGzipEncoding = $value;
425
+ }
426
+
427
+ public function getAccessToken()
428
+ {
429
+ return $this->_accessToken;
430
+ }
431
+
432
+ public function isAccessToken()
433
+ {
434
+ return !empty($this->_accessToken);
435
+ }
436
+
437
+ public function isClientCredentials()
438
+ {
439
+ return !empty($this->_clientId);
440
+ }
441
+ /**
442
+ * returns the base braintree gateway URL based on config values
443
+ *
444
+ * @access public
445
+ * @param none
446
+ * @return string braintree gateway URL
447
+ */
448
+ public function baseUrl()
449
+ {
450
+ return sprintf('%s://%s:%d', $this->protocol(), $this->serverName(), $this->portNumber());
451
+ }
452
+
453
+ /**
454
+ * sets the merchant path based on merchant ID
455
+ *
456
+ * @access protected
457
+ * @param none
458
+ * @return string merchant path uri
459
+ */
460
+ public function merchantPath()
461
+ {
462
+ return '/merchants/' . $this->_merchantId;
463
+ }
464
+
465
+ /**
466
+ * sets the physical path for the location of the CA certs
467
+ *
468
+ * @access public
469
+ * @param none
470
+ * @return string filepath
471
+ */
472
+ public function caFile($sslPath = NULL)
473
+ {
474
+ $sslPath = $sslPath ? $sslPath : DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR .
475
+ 'ssl' . DIRECTORY_SEPARATOR;
476
+ $caPath = __DIR__ . $sslPath . 'api_braintreegateway_com.ca.crt';
477
+
478
+ if (!file_exists($caPath))
479
+ {
480
+ throw new Exception\SSLCaFileNotFound();
481
+ }
482
+
483
+ return $caPath;
484
+ }
485
+
486
+ /**
487
+ * returns the port number depending on environment
488
+ *
489
+ * @access public
490
+ * @param none
491
+ * @return int portnumber
492
+ */
493
+ public function portNumber()
494
+ {
495
+ if ($this->sslOn()) {
496
+ return 443;
497
+ }
498
+ return getenv("GATEWAY_PORT") ? getenv("GATEWAY_PORT") : 3000;
499
+ }
500
+
501
+ /**
502
+ * returns http protocol depending on environment
503
+ *
504
+ * @access public
505
+ * @param none
506
+ * @return string http || https
507
+ */
508
+ public function protocol()
509
+ {
510
+ return $this->sslOn() ? 'https' : 'http';
511
+ }
512
+
513
+ /**
514
+ * returns gateway server name depending on environment
515
+ *
516
+ * @access public
517
+ * @param none
518
+ * @return string server domain name
519
+ */
520
+ public function serverName()
521
+ {
522
+ switch($this->_environment) {
523
+ case 'production':
524
+ $serverName = 'api.braintreegateway.com';
525
+ break;
526
+ case 'qa':
527
+ $serverName = 'gateway.qa.braintreepayments.com';
528
+ break;
529
+ case 'sandbox':
530
+ $serverName = 'api.sandbox.braintreegateway.com';
531
+ break;
532
+ case 'development':
533
+ case 'integration':
534
+ default:
535
+ $serverName = 'localhost';
536
+ break;
537
+ }
538
+
539
+ return $serverName;
540
+ }
541
+
542
+ public function authUrl()
543
+ {
544
+ switch($this->_environment) {
545
+ case 'production':
546
+ $serverName = 'https://auth.venmo.com';
547
+ break;
548
+ case 'qa':
549
+ $serverName = 'https://auth.qa.venmo.com';
550
+ break;
551
+ case 'sandbox':
552
+ $serverName = 'https://auth.sandbox.venmo.com';
553
+ break;
554
+ case 'development':
555
+ case 'integration':
556
+ default:
557
+ $serverName = 'http://auth.venmo.dev:9292';
558
+ break;
559
+ }
560
+
561
+ return $serverName;
562
+ }
563
+
564
+ /**
565
+ * returns boolean indicating SSL is on or off for this session,
566
+ * depending on environment
567
+ *
568
+ * @access public
569
+ * @param none
570
+ * @return boolean
571
+ */
572
+ public function sslOn()
573
+ {
574
+ switch($this->_environment) {
575
+ case 'integration':
576
+ case 'development':
577
+ $ssl = false;
578
+ break;
579
+ case 'production':
580
+ case 'qa':
581
+ case 'sandbox':
582
+ default:
583
+ $ssl = true;
584
+ break;
585
+ }
586
+
587
+ return $ssl;
588
+ }
589
+
590
+ /**
591
+ * log message to default logger
592
+ *
593
+ * @param string $message
594
+ *
595
+ */
596
+ public function logMessage($message)
597
+ {
598
+ error_log('[Braintree] ' . $message);
599
+ }
600
+ }
601
+ Configuration::reset();
602
+ class_alias('Braintree\Configuration', 'Braintree_Configuration');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ConnectedMerchantPayPalStatusChanged.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Connected Merchant PayPal Status Changed Payload
6
+ *
7
+ * @package Braintree
8
+ *
9
+ * @property-read string $merchantPublicId
10
+ * @property-read string $action
11
+ * @property-read string $oauthApplicationClientId
12
+ */
13
+ class ConnectedMerchantPayPalStatusChanged extends Base
14
+ {
15
+ protected $_attributes = [];
16
+
17
+ /**
18
+ * @ignore
19
+ */
20
+ public static function factory($attributes)
21
+ {
22
+ $instance = new self();
23
+ $instance->_initialize($attributes);
24
+
25
+ return $instance;
26
+ }
27
+
28
+ /**
29
+ * @ignore
30
+ */
31
+ protected function _initialize($attributes)
32
+ {
33
+ $this->_attributes = $attributes;
34
+ }
35
+ }
36
+ class_alias('Braintree\ConnectedMerchantPayPalStatusChanged', 'Braintree_ConnectedMerchantPayPalStatusChanged');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ConnectedMerchantStatusTransitioned.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Connected Merchant Status Transitioned Payload
6
+ *
7
+ * @package Braintree
8
+ *
9
+ * @property-read string $merchantPublicId
10
+ * @property-read string $status
11
+ * @property-read string $oauthApplicationClientId
12
+ */
13
+ class ConnectedMerchantStatusTransitioned extends Base
14
+ {
15
+ protected $_attributes = [];
16
+
17
+ /**
18
+ * @ignore
19
+ */
20
+ public static function factory($attributes)
21
+ {
22
+ $instance = new self();
23
+ $instance->_initialize($attributes);
24
+
25
+ return $instance;
26
+ }
27
+
28
+ /**
29
+ * @ignore
30
+ */
31
+ protected function _initialize($attributes)
32
+ {
33
+ $this->_attributes = $attributes;
34
+ }
35
+ }
36
+ class_alias('Braintree\ConnectedMerchantStatusTransitioned', 'Braintree_ConnectedMerchantStatusTransitioned');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CredentialsParser.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ *
6
+ * CredentialsParser registry
7
+ *
8
+ * @package Braintree
9
+ * @subpackage Utility
10
+ */
11
+
12
+ class CredentialsParser
13
+ {
14
+ private $_clientId;
15
+ private $_clientSecret;
16
+ private $_accessToken;
17
+ private $_environment;
18
+ private $_merchantId;
19
+
20
+ public function __construct($attribs)
21
+ {
22
+ foreach ($attribs as $kind => $value) {
23
+ if ($kind == 'clientId') {
24
+ $this->_clientId = $value;
25
+ }
26
+ if ($kind == 'clientSecret') {
27
+ $this->_clientSecret = $value;
28
+ }
29
+ if ($kind == 'accessToken') {
30
+ $this->_accessToken = $value;
31
+ }
32
+ }
33
+ $this->parse();
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @access protected
39
+ * @static
40
+ * @var array valid environments, used for validation
41
+ */
42
+ private static $_validEnvironments = [
43
+ 'development',
44
+ 'integration',
45
+ 'sandbox',
46
+ 'production',
47
+ 'qa',
48
+ ];
49
+
50
+
51
+ public function parse()
52
+ {
53
+ $environments = [];
54
+ if (!empty($this->_clientId)) {
55
+ $environments[] = ['clientId', $this->_parseClientCredential('clientId', $this->_clientId, 'client_id')];
56
+ }
57
+ if (!empty($this->_clientSecret)) {
58
+ $environments[] = ['clientSecret', $this->_parseClientCredential('clientSecret', $this->_clientSecret, 'client_secret')];
59
+ }
60
+ if (!empty($this->_accessToken)) {
61
+ $environments[] = ['accessToken', $this->_parseAccessToken()];
62
+ }
63
+
64
+ $checkEnv = $environments[0];
65
+ foreach ($environments as $env) {
66
+ if ($env[1] !== $checkEnv[1]) {
67
+ throw new Exception\Configuration(
68
+ 'Mismatched credential environments: ' . $checkEnv[0] . ' environment is ' . $checkEnv[1] .
69
+ ' and ' . $env[0] . ' environment is ' . $env[1]);
70
+ }
71
+ }
72
+
73
+ self::assertValidEnvironment($checkEnv[1]);
74
+ $this->_environment = $checkEnv[1];
75
+ }
76
+
77
+ public static function assertValidEnvironment($environment) {
78
+ if (!in_array($environment, self::$_validEnvironments)) {
79
+ throw new Exception\Configuration('"' .
80
+ $environment . '" is not a valid environment.');
81
+ }
82
+ }
83
+
84
+ private function _parseClientCredential($credentialType, $value, $expectedValuePrefix)
85
+ {
86
+ $explodedCredential = explode('$', $value);
87
+ if (sizeof($explodedCredential) != 3) {
88
+ throw new Exception\Configuration('Incorrect ' . $credentialType . ' format. Expected: type$environment$token');
89
+ }
90
+
91
+ $gotValuePrefix = $explodedCredential[0];
92
+ $environment = $explodedCredential[1];
93
+ $token = $explodedCredential[2];
94
+
95
+ if ($gotValuePrefix != $expectedValuePrefix) {
96
+ throw new Exception\Configuration('Value passed for ' . $credentialType . ' is not a ' . $credentialType);
97
+ }
98
+
99
+ return $environment;
100
+ }
101
+
102
+ private function _parseAccessToken()
103
+ {
104
+ $accessTokenExploded = explode('$', $this->_accessToken);
105
+ if (sizeof($accessTokenExploded) != 4) {
106
+ throw new Exception\Configuration('Incorrect accessToken syntax. Expected: type$environment$merchant_id$token');
107
+ }
108
+
109
+ $gotValuePrefix = $accessTokenExploded[0];
110
+ $environment = $accessTokenExploded[1];
111
+ $merchantId = $accessTokenExploded[2];
112
+ $token = $accessTokenExploded[3];
113
+
114
+ if ($gotValuePrefix != 'access_token') {
115
+ throw new Exception\Configuration('Value passed for accessToken is not an accessToken');
116
+ }
117
+
118
+ $this->_merchantId = $merchantId;
119
+ return $environment;
120
+ }
121
+
122
+ public function getClientId()
123
+ {
124
+ return $this->_clientId;
125
+ }
126
+
127
+ public function getClientSecret()
128
+ {
129
+ return $this->_clientSecret;
130
+ }
131
+
132
+ public function getAccessToken()
133
+ {
134
+ return $this->_accessToken;
135
+ }
136
+
137
+ public function getEnvironment()
138
+ {
139
+ return $this->_environment;
140
+ }
141
+
142
+ public function getMerchantId()
143
+ {
144
+ return $this->_merchantId;
145
+ }
146
+ }
147
+ class_alias('Braintree\CredentialsParser', 'Braintree_CredentialsParser');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CreditCard.php ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree CreditCard module
6
+ * Creates and manages Braintree CreditCards
7
+ *
8
+ * <b>== More information ==</b>
9
+ *
10
+ * For more detailed information on CreditCards, see {@link http://www.braintreepayments.com/gateway/credit-card-api http://www.braintreepaymentsolutions.com/gateway/credit-card-api}<br />
11
+ * For more detailed information on CreditCard verifications, see {@link http://www.braintreepayments.com/gateway/credit-card-verification-api http://www.braintreepaymentsolutions.com/gateway/credit-card-verification-api}
12
+ *
13
+ * @package Braintree
14
+ * @category Resources
15
+ *
16
+ * @property-read string $billingAddress
17
+ * @property-read string $bin
18
+ * @property-read string $cardType
19
+ * @property-read string $cardholderName
20
+ * @property-read string $createdAt
21
+ * @property-read string $customerId
22
+ * @property-read string $expirationDate
23
+ * @property-read string $expirationMonth
24
+ * @property-read string $expirationYear
25
+ * @property-read string $imageUrl
26
+ * @property-read string $last4
27
+ * @property-read string $maskedNumber
28
+ * @property-read string $token
29
+ * @property-read string $updatedAt
30
+ */
31
+ class CreditCard extends Base
32
+ {
33
+ // Card Type
34
+ const AMEX = 'American Express';
35
+ const CARTE_BLANCHE = 'Carte Blanche';
36
+ const CHINA_UNION_PAY = 'China UnionPay';
37
+ const DINERS_CLUB_INTERNATIONAL = 'Diners Club';
38
+ const DISCOVER = 'Discover';
39
+ const JCB = 'JCB';
40
+ const LASER = 'Laser';
41
+ const MAESTRO = 'Maestro';
42
+ const UK_MAESTRO = 'UK Maestro';
43
+ const MASTER_CARD = 'MasterCard';
44
+ const SOLO = 'Solo';
45
+ const SWITCH_TYPE = 'Switch';
46
+ const VISA = 'Visa';
47
+ const UNKNOWN = 'Unknown';
48
+
49
+ // Credit card origination location
50
+ const INTERNATIONAL = "international";
51
+ const US = "us";
52
+
53
+ const PREPAID_YES = 'Yes';
54
+ const PREPAID_NO = 'No';
55
+ const PREPAID_UNKNOWN = 'Unknown';
56
+
57
+ const PAYROLL_YES = 'Yes';
58
+ const PAYROLL_NO = 'No';
59
+ const PAYROLL_UNKNOWN = 'Unknown';
60
+
61
+ const HEALTHCARE_YES = 'Yes';
62
+ const HEALTHCARE_NO = 'No';
63
+ const HEALTHCARE_UNKNOWN = 'Unknown';
64
+
65
+ const DURBIN_REGULATED_YES = 'Yes';
66
+ const DURBIN_REGULATED_NO = 'No';
67
+ const DURBIN_REGULATED_UNKNOWN = 'Unknown';
68
+
69
+ const DEBIT_YES = 'Yes';
70
+ const DEBIT_NO = 'No';
71
+ const DEBIT_UNKNOWN = 'Unknown';
72
+
73
+ const COMMERCIAL_YES = 'Yes';
74
+ const COMMERCIAL_NO = 'No';
75
+ const COMMERCIAL_UNKNOWN = 'Unknown';
76
+
77
+ const COUNTRY_OF_ISSUANCE_UNKNOWN = "Unknown";
78
+ const ISSUING_BANK_UNKNOWN = "Unknown";
79
+ const PRODUCT_ID_UNKNOWN = "Unknown";
80
+
81
+ /* instance methods */
82
+ /**
83
+ * returns false if default is null or false
84
+ *
85
+ * @return boolean
86
+ */
87
+ public function isDefault()
88
+ {
89
+ return $this->default;
90
+ }
91
+
92
+ /**
93
+ * checks whether the card is expired based on the current date
94
+ *
95
+ * @return boolean
96
+ */
97
+ public function isExpired()
98
+ {
99
+ return $this->expired;
100
+ }
101
+
102
+ /**
103
+ * checks whether the card is associated with venmo sdk
104
+ *
105
+ * @return boolean
106
+ */
107
+ public function isVenmoSdk()
108
+ {
109
+ return $this->venmoSdk;
110
+ }
111
+
112
+ /**
113
+ * sets instance properties from an array of values
114
+ *
115
+ * @access protected
116
+ * @param array $creditCardAttribs array of creditcard data
117
+ * @return void
118
+ */
119
+ protected function _initialize($creditCardAttribs)
120
+ {
121
+ // set the attributes
122
+ $this->_attributes = $creditCardAttribs;
123
+
124
+ // map each address into its own object
125
+ $billingAddress = isset($creditCardAttribs['billingAddress']) ?
126
+ Address::factory($creditCardAttribs['billingAddress']) :
127
+ null;
128
+
129
+ $subscriptionArray = [];
130
+ if (isset($creditCardAttribs['subscriptions'])) {
131
+ foreach ($creditCardAttribs['subscriptions'] AS $subscription) {
132
+ $subscriptionArray[] = Subscription::factory($subscription);
133
+ }
134
+ }
135
+
136
+ $this->_set('subscriptions', $subscriptionArray);
137
+ $this->_set('billingAddress', $billingAddress);
138
+ $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
139
+ $this->_set('maskedNumber', $this->bin . '******' . $this->last4);
140
+
141
+ if(isset($creditCardAttribs['verifications']) && count($creditCardAttribs['verifications']) > 0) {
142
+ $verifications = $creditCardAttribs['verifications'];
143
+ usort($verifications, [$this, '_compareCreatedAtOnVerifications']);
144
+
145
+ $this->_set('verification', CreditCardVerification::factory($verifications[0]));
146
+ }
147
+ }
148
+
149
+ private function _compareCreatedAtOnVerifications($verificationAttrib1, $verificationAttrib2)
150
+ {
151
+ return ($verificationAttrib2['createdAt'] < $verificationAttrib1['createdAt']) ? -1 : 1;
152
+ }
153
+
154
+ /**
155
+ * returns false if comparing object is not a CreditCard,
156
+ * or is a CreditCard with a different id
157
+ *
158
+ * @param object $otherCreditCard customer to compare against
159
+ * @return boolean
160
+ */
161
+ public function isEqual($otherCreditCard)
162
+ {
163
+ return !($otherCreditCard instanceof self) ? false : $this->token === $otherCreditCard->token;
164
+ }
165
+
166
+ /**
167
+ * create a printable representation of the object as:
168
+ * ClassName[property=value, property=value]
169
+ * @return string
170
+ */
171
+ public function __toString()
172
+ {
173
+ return __CLASS__ . '[' .
174
+ Util::attributesToString($this->_attributes) .']';
175
+ }
176
+
177
+ /**
178
+ * factory method: returns an instance of CreditCard
179
+ * to the requesting method, with populated properties
180
+ *
181
+ * @ignore
182
+ * @return CreditCard
183
+ */
184
+ public static function factory($attributes)
185
+ {
186
+ $defaultAttributes = [
187
+ 'bin' => '',
188
+ 'expirationMonth' => '',
189
+ 'expirationYear' => '',
190
+ 'last4' => '',
191
+ ];
192
+
193
+ $instance = new self();
194
+ $instance->_initialize(array_merge($defaultAttributes, $attributes));
195
+ return $instance;
196
+ }
197
+
198
+
199
+ // static methods redirecting to gateway
200
+
201
+ public static function create($attribs)
202
+ {
203
+ return Configuration::gateway()->creditCard()->create($attribs);
204
+ }
205
+
206
+ public static function createNoValidate($attribs)
207
+ {
208
+ return Configuration::gateway()->creditCard()->createNoValidate($attribs);
209
+ }
210
+
211
+ public static function createFromTransparentRedirect($queryString)
212
+ {
213
+ return Configuration::gateway()->creditCard()->createFromTransparentRedirect($queryString);
214
+ }
215
+
216
+ public static function createCreditCardUrl()
217
+ {
218
+ return Configuration::gateway()->creditCard()->createCreditCardUrl();
219
+ }
220
+
221
+ public static function expired()
222
+ {
223
+ return Configuration::gateway()->creditCard()->expired();
224
+ }
225
+
226
+ public static function fetchExpired($ids)
227
+ {
228
+ return Configuration::gateway()->creditCard()->fetchExpired($ids);
229
+ }
230
+
231
+ public static function expiringBetween($startDate, $endDate)
232
+ {
233
+ return Configuration::gateway()->creditCard()->expiringBetween($startDate, $endDate);
234
+ }
235
+
236
+ public static function fetchExpiring($startDate, $endDate, $ids)
237
+ {
238
+ return Configuration::gateway()->creditCard()->fetchExpiring($startDate, $endDate, $ids);
239
+ }
240
+
241
+ public static function find($token)
242
+ {
243
+ return Configuration::gateway()->creditCard()->find($token);
244
+ }
245
+
246
+ public static function fromNonce($nonce)
247
+ {
248
+ return Configuration::gateway()->creditCard()->fromNonce($nonce);
249
+ }
250
+
251
+ public static function credit($token, $transactionAttribs)
252
+ {
253
+ return Configuration::gateway()->creditCard()->credit($token, $transactionAttribs);
254
+ }
255
+
256
+ public static function creditNoValidate($token, $transactionAttribs)
257
+ {
258
+ return Configuration::gateway()->creditCard()->creditNoValidate($token, $transactionAttribs);
259
+ }
260
+
261
+ public static function sale($token, $transactionAttribs)
262
+ {
263
+ return Configuration::gateway()->creditCard()->sale($token, $transactionAttribs);
264
+ }
265
+
266
+ public static function saleNoValidate($token, $transactionAttribs)
267
+ {
268
+ return Configuration::gateway()->creditCard()->saleNoValidate($token, $transactionAttribs);
269
+ }
270
+
271
+ public static function update($token, $attributes)
272
+ {
273
+ return Configuration::gateway()->creditCard()->update($token, $attributes);
274
+ }
275
+
276
+ public static function updateNoValidate($token, $attributes)
277
+ {
278
+ return Configuration::gateway()->creditCard()->updateNoValidate($token, $attributes);
279
+ }
280
+
281
+ public static function updateCreditCardUrl()
282
+ {
283
+ return Configuration::gateway()->creditCard()->updateCreditCardUrl();
284
+ }
285
+
286
+ public static function updateFromTransparentRedirect($queryString)
287
+ {
288
+ return Configuration::gateway()->creditCard()->updateFromTransparentRedirect($queryString);
289
+ }
290
+
291
+ public static function delete($token)
292
+ {
293
+ return Configuration::gateway()->creditCard()->delete($token);
294
+ }
295
+
296
+ /** @return array */
297
+ public static function allCardTypes()
298
+ {
299
+ return [
300
+ CreditCard::AMEX,
301
+ CreditCard::CARTE_BLANCHE,
302
+ CreditCard::CHINA_UNION_PAY,
303
+ CreditCard::DINERS_CLUB_INTERNATIONAL,
304
+ CreditCard::DISCOVER,
305
+ CreditCard::JCB,
306
+ CreditCard::LASER,
307
+ CreditCard::MAESTRO,
308
+ CreditCard::MASTER_CARD,
309
+ CreditCard::SOLO,
310
+ CreditCard::SWITCH_TYPE,
311
+ CreditCard::VISA,
312
+ CreditCard::UNKNOWN
313
+ ];
314
+ }
315
+ }
316
+ class_alias('Braintree\CreditCard', 'Braintree_CreditCard');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CreditCardGateway.php ADDED
@@ -0,0 +1,486 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ /**
7
+ * Braintree CreditCardGateway module
8
+ * Creates and manages Braintree CreditCards
9
+ *
10
+ * <b>== More information ==</b>
11
+ *
12
+ * For more detailed information on CreditCards, see {@link http://www.braintreepayments.com/gateway/credit-card-api http://www.braintreepaymentsolutions.com/gateway/credit-card-api}<br />
13
+ * For more detailed information on CreditCard verifications, see {@link http://www.braintreepayments.com/gateway/credit-card-verification-api http://www.braintreepaymentsolutions.com/gateway/credit-card-verification-api}
14
+ *
15
+ * @package Braintree
16
+ * @category Resources
17
+ */
18
+ class CreditCardGateway
19
+ {
20
+ private $_gateway;
21
+ private $_config;
22
+ private $_http;
23
+
24
+ public function __construct($gateway)
25
+ {
26
+ $this->_gateway = $gateway;
27
+ $this->_config = $gateway->config;
28
+ $this->_config->assertHasAccessTokenOrKeys();
29
+ $this->_http = new Http($gateway->config);
30
+ }
31
+
32
+ public function create($attribs)
33
+ {
34
+ Util::verifyKeys(self::createSignature(), $attribs);
35
+ return $this->_doCreate('/payment_methods', ['credit_card' => $attribs]);
36
+ }
37
+
38
+ /**
39
+ * attempts the create operation assuming all data will validate
40
+ * returns a CreditCard object instead of a Result
41
+ *
42
+ * @access public
43
+ * @param array $attribs
44
+ * @return CreditCard
45
+ * @throws Exception\ValidationError
46
+ */
47
+ public function createNoValidate($attribs)
48
+ {
49
+ $result = $this->create($attribs);
50
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
51
+ }
52
+ /**
53
+ * create a customer from a TransparentRedirect operation
54
+ *
55
+ * @deprecated since version 2.3.0
56
+ * @access public
57
+ * @param array $attribs
58
+ * @return Result\Successful|Result\Error
59
+ */
60
+ public function createFromTransparentRedirect($queryString)
61
+ {
62
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::confirm", E_USER_NOTICE);
63
+ $params = TransparentRedirect::parseAndValidateQueryString(
64
+ $queryString
65
+ );
66
+ return $this->_doCreate(
67
+ '/payment_methods/all/confirm_transparent_redirect_request',
68
+ ['id' => $params['id']]
69
+ );
70
+ }
71
+
72
+ /**
73
+ *
74
+ * @deprecated since version 2.3.0
75
+ * @access public
76
+ * @param none
77
+ * @return string
78
+ */
79
+ public function createCreditCardUrl()
80
+ {
81
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::url", E_USER_NOTICE);
82
+ return $this->_config->baseUrl() . $this->_config->merchantPath().
83
+ '/payment_methods/all/create_via_transparent_redirect_request';
84
+ }
85
+
86
+ /**
87
+ * returns a ResourceCollection of expired credit cards
88
+ * @return ResourceCollection
89
+ */
90
+ public function expired()
91
+ {
92
+ $path = $this->_config->merchantPath() . '/payment_methods/all/expired_ids';
93
+ $response = $this->_http->post($path);
94
+ $pager = [
95
+ 'object' => $this,
96
+ 'method' => 'fetchExpired',
97
+ 'methodArgs' => []
98
+ ];
99
+
100
+ return new ResourceCollection($response, $pager);
101
+ }
102
+
103
+ public function fetchExpired($ids)
104
+ {
105
+ $path = $this->_config->merchantPath() . "/payment_methods/all/expired";
106
+ $response = $this->_http->post($path, ['search' => ['ids' => $ids]]);
107
+
108
+ return Util::extractattributeasarray(
109
+ $response['paymentMethods'],
110
+ 'creditCard'
111
+ );
112
+ }
113
+ /**
114
+ * returns a ResourceCollection of credit cards expiring between start/end
115
+ *
116
+ * @return ResourceCollection
117
+ */
118
+ public function expiringBetween($startDate, $endDate)
119
+ {
120
+ $queryPath = $this->_config->merchantPath() . '/payment_methods/all/expiring_ids?start=' . date('mY', $startDate) . '&end=' . date('mY', $endDate);
121
+ $response = $this->_http->post($queryPath);
122
+ $pager = [
123
+ 'object' => $this,
124
+ 'method' => 'fetchExpiring',
125
+ 'methodArgs' => [$startDate, $endDate]
126
+ ];
127
+
128
+ return new ResourceCollection($response, $pager);
129
+ }
130
+
131
+ public function fetchExpiring($startDate, $endDate, $ids)
132
+ {
133
+ $queryPath = $this->_config->merchantPath() . '/payment_methods/all/expiring?start=' . date('mY', $startDate) . '&end=' . date('mY', $endDate);
134
+ $response = $this->_http->post($queryPath, ['search' => ['ids' => $ids]]);
135
+
136
+ return Util::extractAttributeAsArray(
137
+ $response['paymentMethods'],
138
+ 'creditCard'
139
+ );
140
+ }
141
+
142
+ /**
143
+ * find a creditcard by token
144
+ *
145
+ * @access public
146
+ * @param string $token credit card unique id
147
+ * @return CreditCard
148
+ * @throws Exception\NotFound
149
+ */
150
+ public function find($token)
151
+ {
152
+ $this->_validateId($token);
153
+ try {
154
+ $path = $this->_config->merchantPath() . '/payment_methods/credit_card/' . $token;
155
+ $response = $this->_http->get($path);
156
+ return CreditCard::factory($response['creditCard']);
157
+ } catch (Exception\NotFound $e) {
158
+ throw new Exception\NotFound(
159
+ 'credit card with token ' . $token . ' not found'
160
+ );
161
+ }
162
+
163
+ }
164
+
165
+ /**
166
+ * Convert a payment method nonce to a credit card
167
+ *
168
+ * @access public
169
+ * @param string $nonce payment method nonce
170
+ * @return CreditCard
171
+ * @throws Exception\NotFound
172
+ */
173
+ public function fromNonce($nonce)
174
+ {
175
+ $this->_validateId($nonce, "nonce");
176
+ try {
177
+ $path = $this->_config->merchantPath() . '/payment_methods/from_nonce/' . $nonce;
178
+ $response = $this->_http->get($path);
179
+ return CreditCard::factory($response['creditCard']);
180
+ } catch (Exception\NotFound $e) {
181
+ throw new Exception\NotFound(
182
+ 'credit card with nonce ' . $nonce . ' locked, consumed or not found'
183
+ );
184
+ }
185
+
186
+ }
187
+
188
+ /**
189
+ * create a credit on the card for the passed transaction
190
+ *
191
+ * @access public
192
+ * @param array $attribs
193
+ * @return Result\Successful|Result\Error
194
+ */
195
+ public function credit($token, $transactionAttribs)
196
+ {
197
+ $this->_validateId($token);
198
+ return Transaction::credit(
199
+ array_merge(
200
+ $transactionAttribs,
201
+ ['paymentMethodToken' => $token]
202
+ )
203
+ );
204
+ }
205
+
206
+ /**
207
+ * create a credit on this card, assuming validations will pass
208
+ *
209
+ * returns a Transaction object on success
210
+ *
211
+ * @access public
212
+ * @param array $attribs
213
+ * @return Transaction
214
+ * @throws Exception\ValidationError
215
+ */
216
+ public function creditNoValidate($token, $transactionAttribs)
217
+ {
218
+ $result = $this->credit($token, $transactionAttribs);
219
+ return Util::returnObjectOrThrowException('Braintree\Transaction', $result);
220
+ }
221
+
222
+ /**
223
+ * create a new sale for the current card
224
+ *
225
+ * @param string $token
226
+ * @param array $transactionAttribs
227
+ * @return Result\Successful|Result\Error
228
+ * @see Transaction::sale()
229
+ */
230
+ public function sale($token, $transactionAttribs)
231
+ {
232
+ $this->_validateId($token);
233
+ return Transaction::sale(
234
+ array_merge(
235
+ $transactionAttribs,
236
+ ['paymentMethodToken' => $token]
237
+ )
238
+ );
239
+ }
240
+
241
+ /**
242
+ * create a new sale using this card, assuming validations will pass
243
+ *
244
+ * returns a Transaction object on success
245
+ *
246
+ * @access public
247
+ * @param array $transactionAttribs
248
+ * @param string $token
249
+ * @return Transaction
250
+ * @throws Exception\ValidationsFailed
251
+ * @see Transaction::sale()
252
+ */
253
+ public function saleNoValidate($token, $transactionAttribs)
254
+ {
255
+ $result = $this->sale($token, $transactionAttribs);
256
+ return Util::returnObjectOrThrowException('Braintree\Transaction', $result);
257
+ }
258
+
259
+ /**
260
+ * updates the creditcard record
261
+ *
262
+ * if calling this method in context, $token
263
+ * is the 2nd attribute. $token is not sent in object context.
264
+ *
265
+ * @access public
266
+ * @param array $attributes
267
+ * @param string $token (optional)
268
+ * @return Result\Successful|Result\Error
269
+ */
270
+ public function update($token, $attributes)
271
+ {
272
+ Util::verifyKeys(self::updateSignature(), $attributes);
273
+ $this->_validateId($token);
274
+ return $this->_doUpdate('put', '/payment_methods/credit_card/' . $token, ['creditCard' => $attributes]);
275
+ }
276
+
277
+ /**
278
+ * update a creditcard record, assuming validations will pass
279
+ *
280
+ * if calling this method in context, $token
281
+ * is the 2nd attribute. $token is not sent in object context.
282
+ * returns a CreditCard object on success
283
+ *
284
+ * @access public
285
+ * @param array $attributes
286
+ * @param string $token
287
+ * @return CreditCard
288
+ * @throws Exception\ValidationsFailed
289
+ */
290
+ public function updateNoValidate($token, $attributes)
291
+ {
292
+ $result = $this->update($token, $attributes);
293
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
294
+ }
295
+ /**
296
+ *
297
+ * @access public
298
+ * @param none
299
+ * @return string
300
+ */
301
+ public function updateCreditCardUrl()
302
+ {
303
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::url", E_USER_NOTICE);
304
+ return $this->_config->baseUrl() . $this->_config->merchantPath() .
305
+ '/payment_methods/all/update_via_transparent_redirect_request';
306
+ }
307
+
308
+ /**
309
+ * update a customer from a TransparentRedirect operation
310
+ *
311
+ * @deprecated since version 2.3.0
312
+ * @access public
313
+ * @param array $attribs
314
+ * @return object
315
+ */
316
+ public function updateFromTransparentRedirect($queryString)
317
+ {
318
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::confirm", E_USER_NOTICE);
319
+ $params = TransparentRedirect::parseAndValidateQueryString(
320
+ $queryString
321
+ );
322
+ return $this->_doUpdate(
323
+ 'post',
324
+ '/payment_methods/all/confirm_transparent_redirect_request',
325
+ ['id' => $params['id']]
326
+ );
327
+ }
328
+
329
+ public function delete($token)
330
+ {
331
+ $this->_validateId($token);
332
+ $path = $this->_config->merchantPath() . '/payment_methods/credit_card/' . $token;
333
+ $this->_http->delete($path);
334
+ return new Result\Successful();
335
+ }
336
+
337
+ private static function baseOptions()
338
+ {
339
+ return ['makeDefault', 'verificationMerchantAccountId', 'verifyCard', 'verificationAmount', 'venmoSdkSession'];
340
+ }
341
+
342
+ private static function baseSignature($options)
343
+ {
344
+ return [
345
+ 'billingAddressId', 'cardholderName', 'cvv', 'number', 'deviceSessionId',
346
+ 'expirationDate', 'expirationMonth', 'expirationYear', 'token', 'venmoSdkPaymentMethodCode',
347
+ 'deviceData', 'fraudMerchantId', 'paymentMethodNonce',
348
+ ['options' => $options],
349
+ [
350
+ 'billingAddress' => self::billingAddressSignature()
351
+ ],
352
+ ];
353
+ }
354
+
355
+ public static function billingAddressSignature()
356
+ {
357
+ return [
358
+ 'firstName',
359
+ 'lastName',
360
+ 'company',
361
+ 'countryCodeAlpha2',
362
+ 'countryCodeAlpha3',
363
+ 'countryCodeNumeric',
364
+ 'countryName',
365
+ 'extendedAddress',
366
+ 'locality',
367
+ 'region',
368
+ 'postalCode',
369
+ 'streetAddress'
370
+ ];
371
+ }
372
+
373
+ public static function createSignature()
374
+ {
375
+ $options = self::baseOptions();
376
+ $options[] = "failOnDuplicatePaymentMethod";
377
+ $signature = self::baseSignature($options);
378
+ $signature[] = 'customerId';
379
+ return $signature;
380
+ }
381
+
382
+ public static function updateSignature()
383
+ {
384
+ $options = self::baseOptions();
385
+ $options[] = "failOnDuplicatePaymentMethod";
386
+ $signature = self::baseSignature($options);
387
+
388
+ $updateExistingBillingSignature = [
389
+ [
390
+ 'options' => [
391
+ 'updateExisting'
392
+ ]
393
+ ]
394
+ ];
395
+
396
+ foreach($signature AS $key => $value) {
397
+ if(is_array($value) and array_key_exists('billingAddress', $value)) {
398
+ $signature[$key]['billingAddress'] = array_merge_recursive($value['billingAddress'], $updateExistingBillingSignature);
399
+ }
400
+ }
401
+
402
+ return $signature;
403
+ }
404
+
405
+ /**
406
+ * sends the create request to the gateway
407
+ *
408
+ * @ignore
409
+ * @param string $subPath
410
+ * @param array $params
411
+ * @return mixed
412
+ */
413
+ public function _doCreate($subPath, $params)
414
+ {
415
+ $fullPath = $this->_config->merchantPath() . $subPath;
416
+ $response = $this->_http->post($fullPath, $params);
417
+
418
+ return $this->_verifyGatewayResponse($response);
419
+ }
420
+
421
+ /**
422
+ * verifies that a valid credit card identifier is being used
423
+ * @ignore
424
+ * @param string $identifier
425
+ * @param Optional $string $identifierType type of identifier supplied, default "token"
426
+ * @throws InvalidArgumentException
427
+ */
428
+ private function _validateId($identifier = null, $identifierType = "token")
429
+ {
430
+ if (empty($identifier)) {
431
+ throw new InvalidArgumentException(
432
+ 'expected credit card id to be set'
433
+ );
434
+ }
435
+ if (!preg_match('/^[0-9A-Za-z_-]+$/', $identifier)) {
436
+ throw new InvalidArgumentException(
437
+ $identifier . ' is an invalid credit card ' . $identifierType . '.'
438
+ );
439
+ }
440
+ }
441
+
442
+ /**
443
+ * sends the update request to the gateway
444
+ *
445
+ * @ignore
446
+ * @param string $url
447
+ * @param array $params
448
+ * @return mixed
449
+ */
450
+ private function _doUpdate($httpVerb, $subPath, $params)
451
+ {
452
+ $fullPath = $this->_config->merchantPath() . $subPath;
453
+ $response = $this->_http->$httpVerb($fullPath, $params);
454
+ return $this->_verifyGatewayResponse($response);
455
+ }
456
+
457
+ /**
458
+ * generic method for validating incoming gateway responses
459
+ *
460
+ * creates a new CreditCard object and encapsulates
461
+ * it inside a Result\Successful object, or
462
+ * encapsulates a Errors object inside a Result\Error
463
+ * alternatively, throws an Unexpected exception if the response is invalid
464
+ *
465
+ * @ignore
466
+ * @param array $response gateway response values
467
+ * @return Result\Successful|Result\Error
468
+ * @throws Exception\Unexpected
469
+ */
470
+ private function _verifyGatewayResponse($response)
471
+ {
472
+ if (isset($response['creditCard'])) {
473
+ // return a populated instance of Address
474
+ return new Result\Successful(
475
+ CreditCard::factory($response['creditCard'])
476
+ );
477
+ } elseif (isset($response['apiErrorResponse'])) {
478
+ return new Result\Error($response['apiErrorResponse']);
479
+ } else {
480
+ throw new Exception\Unexpected(
481
+ "Expected address or apiErrorResponse"
482
+ );
483
+ }
484
+ }
485
+ }
486
+ class_alias('Braintree\CreditCardGateway', 'Braintree_CreditCardGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CreditCardVerification.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class CreditCardVerification extends Result\CreditCardVerification
5
+ {
6
+ public static function factory($attributes)
7
+ {
8
+ $instance = new self($attributes);
9
+ return $instance;
10
+ }
11
+
12
+ // static methods redirecting to gateway
13
+ //
14
+ public static function create($attributes)
15
+ {
16
+ Util::verifyKeys(self::createSignature(), $attributes);
17
+ return Configuration::gateway()->creditCardVerification()->create($attributes);
18
+ }
19
+
20
+ public static function fetch($query, $ids)
21
+ {
22
+ return Configuration::gateway()->creditCardVerification()->fetch($query, $ids);
23
+ }
24
+
25
+ public static function search($query)
26
+ {
27
+ return Configuration::gateway()->creditCardVerification()->search($query);
28
+ }
29
+
30
+ public static function createSignature()
31
+ {
32
+ return [
33
+ ['options' => ['amount', 'merchantAccountId']],
34
+ ['creditCard' =>
35
+ [
36
+ 'cardholderName', 'cvv', 'number',
37
+ 'expirationDate', 'expirationMonth', 'expirationYear',
38
+ ['billingAddress' => CreditCardGateway::billingAddressSignature()]
39
+ ]
40
+ ]];
41
+ }
42
+ }
43
+ class_alias('Braintree\CreditCardVerification', 'Braintree_CreditCardVerification');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CreditCardVerificationGateway.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class CreditCardVerificationGateway
5
+ {
6
+ private $_gateway;
7
+ private $_config;
8
+ private $_http;
9
+
10
+ public function __construct($gateway)
11
+ {
12
+ $this->_gateway = $gateway;
13
+ $this->_config = $gateway->config;
14
+ $this->_config->assertHasAccessTokenOrKeys();
15
+ $this->_http = new Http($gateway->config);
16
+ }
17
+
18
+ public function create($attributes)
19
+ {
20
+ $response = $this->_http->post($this->_config->merchantPath() . "/verifications", ['verification' => $attributes]);
21
+ return $this->_verifyGatewayResponse($response);
22
+ }
23
+
24
+ private function _verifyGatewayResponse($response)
25
+ {
26
+
27
+ if(isset($response['verification'])){
28
+ return new Result\Successful(
29
+ CreditCardVerification::factory($response['verification'])
30
+ );
31
+ } else if (isset($response['apiErrorResponse'])) {
32
+ return new Result\Error($response['apiErrorResponse']);
33
+ } else {
34
+ throw new Exception\Unexpected(
35
+ "Expected transaction or apiErrorResponse"
36
+ );
37
+ }
38
+ }
39
+
40
+ public function fetch($query, $ids)
41
+ {
42
+ $criteria = [];
43
+ foreach ($query as $term) {
44
+ $criteria[$term->name] = $term->toparam();
45
+ }
46
+ $criteria["ids"] = CreditCardVerificationSearch::ids()->in($ids)->toparam();
47
+ $path = $this->_config->merchantPath() . '/verifications/advanced_search';
48
+ $response = $this->_http->post($path, ['search' => $criteria]);
49
+
50
+ return Util::extractattributeasarray(
51
+ $response['creditCardVerifications'],
52
+ 'verification'
53
+ );
54
+ }
55
+
56
+ public function search($query)
57
+ {
58
+ $criteria = [];
59
+ foreach ($query as $term) {
60
+ $criteria[$term->name] = $term->toparam();
61
+ }
62
+
63
+ $path = $this->_config->merchantPath() . '/verifications/advanced_search_ids';
64
+ $response = $this->_http->post($path, ['search' => $criteria]);
65
+ $pager = [
66
+ 'object' => $this,
67
+ 'method' => 'fetch',
68
+ 'methodArgs' => [$query]
69
+ ];
70
+
71
+ return new ResourceCollection($response, $pager);
72
+ }
73
+ }
74
+ class_alias('Braintree\CreditCardVerificationGateway', 'Braintree_CreditCardVerificationGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CreditCardVerificationSearch.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class CreditCardVerificationSearch
5
+ {
6
+ public static function id() {
7
+ return new TextNode('id');
8
+ }
9
+
10
+ public static function creditCardCardholderName() {
11
+ return new TextNode('credit_card_cardholder_name');
12
+ }
13
+
14
+ public static function billingAddressDetailsPostalCode() {
15
+ return new TextNode('billing_address_details_postal_code');
16
+ }
17
+
18
+ public static function customerEmail() {
19
+ return new TextNode('customer_email');
20
+ }
21
+
22
+ public static function customerId() {
23
+ return new TextNode('customer_id');
24
+ }
25
+
26
+ public static function paymentMethodToken(){
27
+ return new TextNode('payment_method_token');
28
+ }
29
+
30
+ public static function creditCardExpirationDate() {
31
+ return new EqualityNode('credit_card_expiration_date');
32
+ }
33
+
34
+ public static function creditCardNumber() {
35
+ return new PartialMatchNode('credit_card_number');
36
+ }
37
+
38
+ public static function ids() {
39
+ return new MultipleValueNode('ids');
40
+ }
41
+
42
+ public static function createdAt() {
43
+ return new RangeNode("created_at");
44
+ }
45
+
46
+ public static function creditCardCardType()
47
+ {
48
+ return new MultipleValueNode("credit_card_card_type", CreditCard::allCardTypes());
49
+ }
50
+
51
+ public static function status()
52
+ {
53
+ return new MultipleValueNode("status", Result\CreditCardVerification::allStatuses());
54
+ }
55
+ }
56
+ class_alias('Braintree\CreditCardVerificationSearch', 'Braintree_CreditCardVerificationSearch');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Customer.php ADDED
@@ -0,0 +1,424 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree Customer module
6
+ * Creates and manages Customers
7
+ *
8
+ * <b>== More information ==</b>
9
+ *
10
+ * For more detailed information on Customers, see {@link http://www.braintreepayments.com/gateway/customer-api http://www.braintreepaymentsolutions.com/gateway/customer-api}
11
+ *
12
+ * @package Braintree
13
+ * @category Resources
14
+ *
15
+ * @property-read array $addresses
16
+ * @property-read array $paymentMethods
17
+ * @property-read string $company
18
+ * @property-read string $createdAt
19
+ * @property-read array $creditCards
20
+ * @property-read array $paypalAccounts
21
+ * @property-read array $applePayCards
22
+ * @property-read array $androidPayCards
23
+ * @property-read array $amexExpressCheckoutCards
24
+ * @property-read array $venmoAccounts
25
+ * @property-read array $visaCheckoutCards
26
+ * @property-read array $masterpassCards
27
+ * @property-read array $coinbaseAccounts
28
+ * @property-read array $customFields custom fields passed with the request
29
+ * @property-read string $email
30
+ * @property-read string $fax
31
+ * @property-read string $firstName
32
+ * @property-read string $id
33
+ * @property-read string $lastName
34
+ * @property-read string $phone
35
+ * @property-read string $updatedAt
36
+ * @property-read string $website
37
+ */
38
+ class Customer extends Base
39
+ {
40
+ /**
41
+ *
42
+ * @return Customer[]
43
+ */
44
+ public static function all()
45
+ {
46
+ return Configuration::gateway()->customer()->all();
47
+ }
48
+
49
+ /**
50
+ *
51
+ * @param string $query
52
+ * @param int[] $ids
53
+ * @return Customer|Customer[]
54
+ */
55
+ public static function fetch($query, $ids)
56
+ {
57
+ return Configuration::gateway()->customer()->fetch($query, $ids);
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @param array $attribs
63
+ * @return Result\Successful|Result\Error
64
+ */
65
+ public static function create($attribs = [])
66
+ {
67
+ return Configuration::gateway()->customer()->create($attribs);
68
+ }
69
+
70
+ /**
71
+ *
72
+ * @param array $attribs
73
+ * @return Customer
74
+ */
75
+ public static function createNoValidate($attribs = [])
76
+ {
77
+ return Configuration::gateway()->customer()->createNoValidate($attribs);
78
+ }
79
+
80
+ /**
81
+ * @deprecated since version 2.3.0
82
+ * @param string $queryString
83
+ * @return Result\Successful
84
+ */
85
+ public static function createFromTransparentRedirect($queryString)
86
+ {
87
+ return Configuration::gateway()->customer()->createFromTransparentRedirect($queryString);
88
+ }
89
+
90
+ /**
91
+ * @deprecated since version 2.3.0
92
+ * @return string
93
+ */
94
+ public static function createCustomerUrl()
95
+ {
96
+ return Configuration::gateway()->customer()->createCustomerUrl();
97
+ }
98
+
99
+ /**
100
+ *
101
+ * @throws Exception\NotFound
102
+ * @param string $id customer id
103
+ * @return Customer
104
+ */
105
+ public static function find($id)
106
+ {
107
+ return Configuration::gateway()->customer()->find($id);
108
+ }
109
+
110
+ /**
111
+ *
112
+ * @param int $customerId
113
+ * @param array $transactionAttribs
114
+ * @return Result\Successful|Result\Error
115
+ */
116
+ public static function credit($customerId, $transactionAttribs)
117
+ {
118
+ return Configuration::gateway()->customer()->credit($customerId, $transactionAttribs);
119
+ }
120
+
121
+ /**
122
+ *
123
+ * @throws Exception\ValidationError
124
+ * @param type $customerId
125
+ * @param type $transactionAttribs
126
+ * @return Transaction
127
+ */
128
+ public static function creditNoValidate($customerId, $transactionAttribs)
129
+ {
130
+ return Configuration::gateway()->customer()->creditNoValidate($customerId, $transactionAttribs);
131
+ }
132
+
133
+ /**
134
+ *
135
+ * @throws Exception on invalid id or non-200 http response code
136
+ * @param int $customerId
137
+ * @return Result\Successful
138
+ */
139
+ public static function delete($customerId)
140
+ {
141
+ return Configuration::gateway()->customer()->delete($customerId);
142
+ }
143
+
144
+ /**
145
+ *
146
+ * @param int $customerId
147
+ * @param array $transactionAttribs
148
+ * @return Transaction
149
+ */
150
+ public static function sale($customerId, $transactionAttribs)
151
+ {
152
+ return Configuration::gateway()->customer()->sale($customerId, $transactionAttribs);
153
+ }
154
+
155
+ /**
156
+ *
157
+ * @param int $customerId
158
+ * @param array $transactionAttribs
159
+ * @return Transaction
160
+ */
161
+ public static function saleNoValidate($customerId, $transactionAttribs)
162
+ {
163
+ return Configuration::gateway()->customer()->saleNoValidate($customerId, $transactionAttribs);
164
+ }
165
+
166
+ /**
167
+ *
168
+ * @throws InvalidArgumentException
169
+ * @param string $query
170
+ * @return ResourceCollection
171
+ */
172
+ public static function search($query)
173
+ {
174
+ return Configuration::gateway()->customer()->search($query);
175
+ }
176
+
177
+ /**
178
+ *
179
+ * @throws Exception\Unexpected
180
+ * @param int $customerId
181
+ * @param array $attributes
182
+ * @return Result\Successful|Result\Error
183
+ */
184
+ public static function update($customerId, $attributes)
185
+ {
186
+ return Configuration::gateway()->customer()->update($customerId, $attributes);
187
+ }
188
+
189
+ /**
190
+ *
191
+ * @throws Exception\Unexpected
192
+ * @param int $customerId
193
+ * @param array $attributes
194
+ * @return CustomerGateway
195
+ */
196
+ public static function updateNoValidate($customerId, $attributes)
197
+ {
198
+ return Configuration::gateway()->customer()->updateNoValidate($customerId, $attributes);
199
+ }
200
+
201
+ /**
202
+ *
203
+ * @deprecated since version 2.3.0
204
+ * @return string
205
+ */
206
+ public static function updateCustomerUrl()
207
+ {
208
+ return Configuration::gateway()->customer()->updateCustomerUrl();
209
+ }
210
+
211
+ /**
212
+ *
213
+ * @deprecated since version 2.3.0
214
+ * @param string $queryString
215
+ * @return Result\Successful|Result\Error
216
+ */
217
+ public static function updateFromTransparentRedirect($queryString)
218
+ {
219
+ return Configuration::gateway()->customer()->updateFromTransparentRedirect($queryString);
220
+ }
221
+
222
+ /* instance methods */
223
+
224
+ /**
225
+ * sets instance properties from an array of values
226
+ *
227
+ * @ignore
228
+ * @access protected
229
+ * @param array $customerAttribs array of customer data
230
+ */
231
+ protected function _initialize($customerAttribs)
232
+ {
233
+ $this->_attributes = $customerAttribs;
234
+
235
+ $addressArray = [];
236
+ if (isset($customerAttribs['addresses'])) {
237
+
238
+ foreach ($customerAttribs['addresses'] AS $address) {
239
+ $addressArray[] = Address::factory($address);
240
+ }
241
+ }
242
+ $this->_set('addresses', $addressArray);
243
+
244
+ $creditCardArray = [];
245
+ if (isset($customerAttribs['creditCards'])) {
246
+ foreach ($customerAttribs['creditCards'] AS $creditCard) {
247
+ $creditCardArray[] = CreditCard::factory($creditCard);
248
+ }
249
+ }
250
+ $this->_set('creditCards', $creditCardArray);
251
+
252
+ $coinbaseAccountArray = [];
253
+ if (isset($customerAttribs['coinbaseAccounts'])) {
254
+ foreach ($customerAttribs['coinbaseAccounts'] AS $coinbaseAccount) {
255
+ $coinbaseAccountArray[] = CoinbaseAccount::factory($coinbaseAccount);
256
+ }
257
+ }
258
+ $this->_set('coinbaseAccounts', $coinbaseAccountArray);
259
+
260
+ $paypalAccountArray = [];
261
+ if (isset($customerAttribs['paypalAccounts'])) {
262
+ foreach ($customerAttribs['paypalAccounts'] AS $paypalAccount) {
263
+ $paypalAccountArray[] = PayPalAccount::factory($paypalAccount);
264
+ }
265
+ }
266
+ $this->_set('paypalAccounts', $paypalAccountArray);
267
+
268
+ $applePayCardArray = [];
269
+ if (isset($customerAttribs['applePayCards'])) {
270
+ foreach ($customerAttribs['applePayCards'] AS $applePayCard) {
271
+ $applePayCardArray[] = ApplePayCard::factory($applePayCard);
272
+ }
273
+ }
274
+ $this->_set('applePayCards', $applePayCardArray);
275
+
276
+ $androidPayCardArray = [];
277
+ if (isset($customerAttribs['androidPayCards'])) {
278
+ foreach ($customerAttribs['androidPayCards'] AS $androidPayCard) {
279
+ $androidPayCardArray[] = AndroidPayCard::factory($androidPayCard);
280
+ }
281
+ }
282
+ $this->_set('androidPayCards', $androidPayCardArray);
283
+
284
+ $amexExpressCheckoutCardArray = [];
285
+ if (isset($customerAttribs['amexExpressCheckoutCards'])) {
286
+ foreach ($customerAttribs['amexExpressCheckoutCards'] AS $amexExpressCheckoutCard) {
287
+ $amexExpressCheckoutCardArray[] = AmexExpressCheckoutCard::factory($amexExpressCheckoutCard);
288
+ }
289
+ }
290
+ $this->_set('amexExpressCheckoutCards', $amexExpressCheckoutCardArray);
291
+
292
+ $venmoAccountArray = array();
293
+ if (isset($customerAttribs['venmoAccounts'])) {
294
+ foreach ($customerAttribs['venmoAccounts'] AS $venmoAccount) {
295
+ $venmoAccountArray[] = VenmoAccount::factory($venmoAccount);
296
+ }
297
+ }
298
+ $this->_set('venmoAccounts', $venmoAccountArray);
299
+
300
+ $visaCheckoutCardArray = [];
301
+ if (isset($customerAttribs['visaCheckoutCards'])) {
302
+ foreach ($customerAttribs['visaCheckoutCards'] AS $visaCheckoutCard) {
303
+ $visaCheckoutCardArray[] = VisaCheckoutCard::factory($visaCheckoutCard);
304
+ }
305
+ }
306
+ $this->_set('visaCheckoutCards', $visaCheckoutCardArray);
307
+
308
+ $masterpassCardArray = [];
309
+ if (isset($customerAttribs['masterpassCards'])) {
310
+ foreach ($customerAttribs['masterpassCards'] AS $masterpassCard) {
311
+ $masterpassCardArray[] = MasterpassCard::factory($masterpassCard);
312
+ }
313
+ }
314
+ $this->_set('masterpassCards', $masterpassCardArray);
315
+
316
+ $usBankAccountArray = array();
317
+ if (isset($customerAttribs['usBankAccounts'])) {
318
+ foreach ($customerAttribs['usBankAccounts'] AS $usBankAccount) {
319
+ $usBankAccountArray[] = UsBankAccount::factory($usBankAccount);
320
+ }
321
+ }
322
+ $this->_set('usBankAccounts', $usBankAccountArray);
323
+
324
+ $this->_set('paymentMethods', array_merge(
325
+ $this->creditCards,
326
+ $this->paypalAccounts,
327
+ $this->applePayCards,
328
+ $this->coinbaseAccounts,
329
+ $this->androidPayCards,
330
+ $this->amexExpressCheckoutCards,
331
+ $this->venmoAccounts,
332
+ $this->visaCheckoutCards,
333
+ $this->masterpassCards,
334
+ $this->usBankAccounts
335
+ ));
336
+ }
337
+
338
+ /**
339
+ * returns a string representation of the customer
340
+ * @return string
341
+ */
342
+ public function __toString()
343
+ {
344
+ return __CLASS__ . '[' .
345
+ Util::attributesToString($this->_attributes) .']';
346
+ }
347
+
348
+ /**
349
+ * returns false if comparing object is not a Customer,
350
+ * or is a Customer with a different id
351
+ *
352
+ * @param object $otherCust customer to compare against
353
+ * @return boolean
354
+ */
355
+ public function isEqual($otherCust)
356
+ {
357
+ return !($otherCust instanceof Customer) ? false : $this->id === $otherCust->id;
358
+ }
359
+
360
+ /**
361
+ * returns an array containt all of the customer's payment methods
362
+ *
363
+ * @deprecated since version 3.1.0 - use the paymentMethods property directly
364
+ *
365
+ * @return array
366
+ */
367
+ public function paymentMethods()
368
+ {
369
+ return $this->paymentMethods;
370
+ }
371
+
372
+ /**
373
+ * returns the customer's default payment method
374
+ *
375
+ * @return CreditCard|PayPalAccount
376
+ */
377
+ public function defaultPaymentMethod()
378
+ {
379
+ $defaultPaymentMethods = array_filter($this->paymentMethods, 'Braintree\Customer::_defaultPaymentMethodFilter');
380
+ return current($defaultPaymentMethods);
381
+ }
382
+
383
+ public static function _defaultPaymentMethodFilter($paymentMethod)
384
+ {
385
+ return $paymentMethod->isDefault();
386
+ }
387
+
388
+ /* private class properties */
389
+
390
+ /**
391
+ * @access protected
392
+ * @var array registry of customer data
393
+ */
394
+ protected $_attributes = [
395
+ 'addresses' => '',
396
+ 'company' => '',
397
+ 'creditCards' => '',
398
+ 'email' => '',
399
+ 'fax' => '',
400
+ 'firstName' => '',
401
+ 'id' => '',
402
+ 'lastName' => '',
403
+ 'phone' => '',
404
+ 'createdAt' => '',
405
+ 'updatedAt' => '',
406
+ 'website' => '',
407
+ ];
408
+
409
+ /**
410
+ * factory method: returns an instance of Customer
411
+ * to the requesting method, with populated properties
412
+ *
413
+ * @ignore
414
+ * @param array $attributes
415
+ * @return Customer
416
+ */
417
+ public static function factory($attributes)
418
+ {
419
+ $instance = new Customer();
420
+ $instance->_initialize($attributes);
421
+ return $instance;
422
+ }
423
+ }
424
+ class_alias('Braintree\Customer', 'Braintree_Customer');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CustomerGateway.php ADDED
@@ -0,0 +1,637 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ /**
7
+ * Braintree CustomerGateway module
8
+ * Creates and manages Customers
9
+ *
10
+ * <b>== More information ==</b>
11
+ *
12
+ * For more detailed information on Customers, see {@link http://www.braintreepayments.com/gateway/customer-api http://www.braintreepaymentsolutions.com/gateway/customer-api}
13
+ *
14
+ * @package Braintree
15
+ * @category Resources
16
+ */
17
+ class CustomerGateway
18
+ {
19
+ private $_gateway;
20
+ private $_config;
21
+ private $_http;
22
+
23
+ public function __construct($gateway)
24
+ {
25
+ $this->_gateway = $gateway;
26
+ $this->_config = $gateway->config;
27
+ $this->_config->assertHasAccessTokenOrKeys();
28
+ $this->_http = new Http($gateway->config);
29
+ }
30
+
31
+ public function all()
32
+ {
33
+ $path = $this->_config->merchantPath() . '/customers/advanced_search_ids';
34
+ $response = $this->_http->post($path);
35
+ $pager = [
36
+ 'object' => $this,
37
+ 'method' => 'fetch',
38
+ 'methodArgs' => [[]]
39
+ ];
40
+
41
+ return new ResourceCollection($response, $pager);
42
+ }
43
+
44
+ public function fetch($query, $ids)
45
+ {
46
+ $criteria = [];
47
+ foreach ($query as $term) {
48
+ $criteria[$term->name] = $term->toparam();
49
+ }
50
+ $criteria["ids"] = CustomerSearch::ids()->in($ids)->toparam();
51
+ $path = $this->_config->merchantPath() . '/customers/advanced_search';
52
+ $response = $this->_http->post($path, ['search' => $criteria]);
53
+
54
+ return Util::extractattributeasarray(
55
+ $response['customers'],
56
+ 'customer'
57
+ );
58
+ }
59
+
60
+ /**
61
+ * Creates a customer using the given +attributes+. If <tt>:id</tt> is not passed,
62
+ * the gateway will generate it.
63
+ *
64
+ * <code>
65
+ * $result = Customer::create(array(
66
+ * 'first_name' => 'John',
67
+ * 'last_name' => 'Smith',
68
+ * 'company' => 'Smith Co.',
69
+ * 'email' => 'john@smith.com',
70
+ * 'website' => 'www.smithco.com',
71
+ * 'fax' => '419-555-1234',
72
+ * 'phone' => '614-555-1234'
73
+ * ));
74
+ * if($result->success) {
75
+ * echo 'Created customer ' . $result->customer->id;
76
+ * } else {
77
+ * echo 'Could not create customer, see result->errors';
78
+ * }
79
+ * </code>
80
+ *
81
+ * @access public
82
+ * @param array $attribs
83
+ * @return Braintree_Result_Successful|Braintree_Result_Error
84
+ */
85
+ public function create($attribs = [])
86
+ {
87
+ Util::verifyKeys(self::createSignature(), $attribs);
88
+ return $this->_doCreate('/customers', ['customer' => $attribs]);
89
+ }
90
+
91
+ /**
92
+ * attempts the create operation assuming all data will validate
93
+ * returns a Customer object instead of a Result
94
+ *
95
+ * @access public
96
+ * @param array $attribs
97
+ * @return Customer
98
+ * @throws Exception\ValidationError
99
+ */
100
+ public function createNoValidate($attribs = [])
101
+ {
102
+ $result = $this->create($attribs);
103
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
104
+ }
105
+ /**
106
+ * create a customer from a TransparentRedirect operation
107
+ *
108
+ * @deprecated since version 2.3.0
109
+ * @access public
110
+ * @param array $attribs
111
+ * @return Customer
112
+ */
113
+ public function createFromTransparentRedirect($queryString)
114
+ {
115
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::confirm", E_USER_NOTICE);
116
+ $params = TransparentRedirect::parseAndValidateQueryString(
117
+ $queryString
118
+ );
119
+ return $this->_doCreate(
120
+ '/customers/all/confirm_transparent_redirect_request',
121
+ ['id' => $params['id']]
122
+ );
123
+ }
124
+
125
+ /**
126
+ *
127
+ * @deprecated since version 2.3.0
128
+ * @access public
129
+ * @param none
130
+ * @return string
131
+ */
132
+ public function createCustomerUrl()
133
+ {
134
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::url", E_USER_NOTICE);
135
+ return $this->_config->baseUrl() . $this->_config->merchantPath() .
136
+ '/customers/all/create_via_transparent_redirect_request';
137
+ }
138
+
139
+
140
+ /**
141
+ * creates a full array signature of a valid create request
142
+ * @return array gateway create request format
143
+ */
144
+ public static function createSignature()
145
+ {
146
+ $creditCardSignature = CreditCardGateway::createSignature();
147
+ unset($creditCardSignature[array_search('customerId', $creditCardSignature)]);
148
+
149
+ $signature = [
150
+ 'id', 'company', 'email', 'fax', 'firstName',
151
+ 'lastName', 'phone', 'website', 'deviceData',
152
+ 'deviceSessionId', 'fraudMerchantId', 'paymentMethodNonce',
153
+ ['riskData' =>
154
+ ['customerBrowser', 'customerIp', 'customer_browser', 'customer_ip']
155
+ ],
156
+ ['creditCard' => $creditCardSignature],
157
+ ['customFields' => ['_anyKey_']],
158
+ ['options' => [
159
+ ['paypal' => [
160
+ 'payee_email',
161
+ 'order_id',
162
+ 'custom_field',
163
+ 'description',
164
+ 'amount',
165
+ ]]
166
+ ]],
167
+ ];
168
+ return $signature;
169
+ }
170
+
171
+ /**
172
+ * creates a full array signature of a valid update request
173
+ * @return array update request format
174
+ */
175
+ public static function updateSignature()
176
+ {
177
+ $creditCardSignature = CreditCardGateway::updateSignature();
178
+
179
+ foreach($creditCardSignature AS $key => $value) {
180
+ if(is_array($value) and array_key_exists('options', $value)) {
181
+ array_push($creditCardSignature[$key]['options'], 'updateExistingToken');
182
+ }
183
+ }
184
+
185
+ $signature = [
186
+ 'id', 'company', 'email', 'fax', 'firstName',
187
+ 'lastName', 'phone', 'website', 'deviceData',
188
+ 'deviceSessionId', 'fraudMerchantId', 'paymentMethodNonce', 'defaultPaymentMethodToken',
189
+ ['creditCard' => $creditCardSignature],
190
+ ['customFields' => ['_anyKey_']],
191
+ ['options' => [
192
+ ['paypal' => ['payee_email']],
193
+ ]],
194
+ ];
195
+ return $signature;
196
+ }
197
+
198
+
199
+ /**
200
+ * find a customer by id
201
+ *
202
+ * @access public
203
+ * @param string id customer Id
204
+ * @return Customer|boolean The customer object or false if the request fails.
205
+ * @throws Exception\NotFound
206
+ */
207
+ public function find($id)
208
+ {
209
+ $this->_validateId($id);
210
+ try {
211
+ $path = $this->_config->merchantPath() . '/customers/' . $id;
212
+ $response = $this->_http->get($path);
213
+ return Customer::factory($response['customer']);
214
+ } catch (Exception\NotFound $e) {
215
+ throw new Exception\NotFound(
216
+ 'customer with id ' . $id . ' not found'
217
+ );
218
+ }
219
+ }
220
+
221
+ /**
222
+ * credit a customer for the passed transaction
223
+ *
224
+ * @access public
225
+ * @param int $customerId
226
+ * @param array $transactionAttribs
227
+ * @return Result\Successful|Result\Error
228
+ */
229
+ public function credit($customerId, $transactionAttribs)
230
+ {
231
+ $this->_validateId($customerId);
232
+ return Transaction::credit(
233
+ array_merge($transactionAttribs,
234
+ ['customerId' => $customerId]
235
+ )
236
+ );
237
+ }
238
+
239
+ /**
240
+ * credit a customer, assuming validations will pass
241
+ *
242
+ * returns a Transaction object on success
243
+ *
244
+ * @access public
245
+ * @param int $customerId
246
+ * @param array $transactionAttribs
247
+ * @return Transaction
248
+ * @throws Exception\ValidationError
249
+ */
250
+ public function creditNoValidate($customerId, $transactionAttribs)
251
+ {
252
+ $result = $this->credit($customerId, $transactionAttribs);
253
+ return Util::returnObjectOrThrowException('Braintree\Transaction', $result);
254
+ }
255
+
256
+ /**
257
+ * delete a customer by id
258
+ *
259
+ * @param string $customerId
260
+ */
261
+ public function delete($customerId)
262
+ {
263
+ $this->_validateId($customerId);
264
+ $path = $this->_config->merchantPath() . '/customers/' . $customerId;
265
+ $this->_http->delete($path);
266
+ return new Result\Successful();
267
+ }
268
+
269
+ /**
270
+ * create a new sale for a customer
271
+ *
272
+ * @param string $customerId
273
+ * @param array $transactionAttribs
274
+ * @return Result\Successful|Result\Error
275
+ * @see Transaction::sale()
276
+ */
277
+ public function sale($customerId, $transactionAttribs)
278
+ {
279
+ $this->_validateId($customerId);
280
+ return Transaction::sale(
281
+ array_merge($transactionAttribs,
282
+ ['customerId' => $customerId]
283
+ )
284
+ );
285
+ }
286
+
287
+ /**
288
+ * create a new sale for a customer, assuming validations will pass
289
+ *
290
+ * returns a Transaction object on success
291
+ * @access public
292
+ * @param string $customerId
293
+ * @param array $transactionAttribs
294
+ * @return Transaction
295
+ * @throws Exception\ValidationsFailed
296
+ * @see Transaction::sale()
297
+ */
298
+ public function saleNoValidate($customerId, $transactionAttribs)
299
+ {
300
+ $result = $this->sale($customerId, $transactionAttribs);
301
+ return Util::returnObjectOrThrowException('Braintree\Transaction', $result);
302
+ }
303
+
304
+ /**
305
+ * Returns a ResourceCollection of customers matching the search query.
306
+ *
307
+ * If <b>query</b> is a string, the search will be a basic search.
308
+ * If <b>query</b> is a hash, the search will be an advanced search.
309
+ * For more detailed information and examples, see {@link http://www.braintreepayments.com/gateway/customer-api#searching http://www.braintreepaymentsolutions.com/gateway/customer-api}
310
+ *
311
+ * @param mixed $query search query
312
+ * @return ResourceCollection
313
+ * @throws InvalidArgumentException
314
+ */
315
+ public function search($query)
316
+ {
317
+ $criteria = [];
318
+ foreach ($query as $term) {
319
+ $result = $term->toparam();
320
+ if(is_null($result) || empty($result)) {
321
+ throw new InvalidArgumentException('Operator must be provided');
322
+ }
323
+
324
+ $criteria[$term->name] = $term->toparam();
325
+ }
326
+
327
+ $path = $this->_config->merchantPath() . '/customers/advanced_search_ids';
328
+ $response = $this->_http->post($path, ['search' => $criteria]);
329
+ $pager = [
330
+ 'object' => $this,
331
+ 'method' => 'fetch',
332
+ 'methodArgs' => [$query]
333
+ ];
334
+
335
+ return new ResourceCollection($response, $pager);
336
+ }
337
+
338
+ /**
339
+ * updates the customer record
340
+ *
341
+ * if calling this method in static context, customerId
342
+ * is the 2nd attribute. customerId is not sent in object context.
343
+ *
344
+ * @access public
345
+ * @param string $customerId (optional)
346
+ * @param array $attributes
347
+ * @return Result\Successful|Result\Error
348
+ */
349
+ public function update($customerId, $attributes)
350
+ {
351
+ Util::verifyKeys(self::updateSignature(), $attributes);
352
+ $this->_validateId($customerId);
353
+ return $this->_doUpdate(
354
+ 'put',
355
+ '/customers/' . $customerId,
356
+ ['customer' => $attributes]
357
+ );
358
+ }
359
+
360
+ /**
361
+ * update a customer record, assuming validations will pass
362
+ *
363
+ * if calling this method in static context, customerId
364
+ * is the 2nd attribute. customerId is not sent in object context.
365
+ * returns a Customer object on success
366
+ *
367
+ * @access public
368
+ * @param string $customerId
369
+ * @param array $attributes
370
+ * @return Customer
371
+ * @throws Exception\ValidationsFailed
372
+ */
373
+ public function updateNoValidate($customerId, $attributes)
374
+ {
375
+ $result = $this->update($customerId, $attributes);
376
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
377
+ }
378
+ /**
379
+ *
380
+ * @deprecated since version 2.3.0
381
+ * @access public
382
+ * @return string
383
+ */
384
+ public function updateCustomerUrl()
385
+ {
386
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::url", E_USER_NOTICE);
387
+ return $this->_config->baseUrl() . $this->_config->merchantPath() .
388
+ '/customers/all/update_via_transparent_redirect_request';
389
+ }
390
+
391
+ /**
392
+ * update a customer from a TransparentRedirect operation
393
+ *
394
+ * @deprecated since version 2.3.0
395
+ * @access public
396
+ * @param string $queryString
397
+ * @return object
398
+ */
399
+ public function updateFromTransparentRedirect($queryString)
400
+ {
401
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::confirm", E_USER_NOTICE);
402
+ $params = TransparentRedirect::parseAndValidateQueryString(
403
+ $queryString
404
+ );
405
+ return $this->_doUpdate(
406
+ 'post',
407
+ '/customers/all/confirm_transparent_redirect_request',
408
+ ['id' => $params['id']]
409
+ );
410
+ }
411
+
412
+ /* instance methods */
413
+
414
+ /**
415
+ * sets instance properties from an array of values
416
+ *
417
+ * @ignore
418
+ * @access protected
419
+ * @param array $customerAttribs array of customer data
420
+ * @return void
421
+ */
422
+ protected function _initialize($customerAttribs)
423
+ {
424
+ // set the attributes
425
+ $this->_attributes = $customerAttribs;
426
+
427
+ // map each address into its own object
428
+ $addressArray = [];
429
+ if (isset($customerAttribs['addresses'])) {
430
+
431
+ foreach ($customerAttribs['addresses'] AS $address) {
432
+ $addressArray[] = Address::factory($address);
433
+ }
434
+ }
435
+ $this->_set('addresses', $addressArray);
436
+
437
+ // map each creditCard into its own object
438
+ $creditCardArray = [];
439
+ if (isset($customerAttribs['creditCards'])) {
440
+ foreach ($customerAttribs['creditCards'] AS $creditCard) {
441
+ $creditCardArray[] = CreditCard::factory($creditCard);
442
+ }
443
+ }
444
+ $this->_set('creditCards', $creditCardArray);
445
+
446
+ // map each coinbaseAccount into its own object
447
+ $coinbaseAccountArray = [];
448
+ if (isset($customerAttribs['coinbaseAccounts'])) {
449
+ foreach ($customerAttribs['coinbaseAccounts'] AS $coinbaseAccount) {
450
+ $coinbaseAccountArray[] = CoinbaseAccount::factory($coinbaseAccount);
451
+ }
452
+ }
453
+ $this->_set('coinbaseAccounts', $coinbaseAccountArray);
454
+
455
+ // map each paypalAccount into its own object
456
+ $paypalAccountArray = [];
457
+ if (isset($customerAttribs['paypalAccounts'])) {
458
+ foreach ($customerAttribs['paypalAccounts'] AS $paypalAccount) {
459
+ $paypalAccountArray[] = PayPalAccount::factory($paypalAccount);
460
+ }
461
+ }
462
+ $this->_set('paypalAccounts', $paypalAccountArray);
463
+
464
+ // map each applePayCard into its own object
465
+ $applePayCardArray = [];
466
+ if (isset($customerAttribs['applePayCards'])) {
467
+ foreach ($customerAttribs['applePayCards'] AS $applePayCard) {
468
+ $applePayCardArray[] = ApplePayCard::factory($applePayCard);
469
+ }
470
+ }
471
+ $this->_set('applePayCards', $applePayCardArray);
472
+
473
+ // map each androidPayCard into its own object
474
+ $androidPayCardArray = [];
475
+ if (isset($customerAttribs['androidPayCards'])) {
476
+ foreach ($customerAttribs['androidPayCards'] AS $androidPayCard) {
477
+ $androidPayCardArray[] = AndroidPayCard::factory($androidPayCard);
478
+ }
479
+ }
480
+ $this->_set('androidPayCards', $androidPayCardArray);
481
+
482
+ $this->_set('paymentMethods', array_merge($this->creditCards, $this->paypalAccounts, $this->applePayCards, $this->coinbaseAccounts, $this->androidPayCards));
483
+ }
484
+
485
+ /**
486
+ * returns a string representation of the customer
487
+ * @return string
488
+ */
489
+ public function __toString()
490
+ {
491
+ return __CLASS__ . '[' .
492
+ Util::attributesToString($this->_attributes) .']';
493
+ }
494
+
495
+ /**
496
+ * returns false if comparing object is not a Customer,
497
+ * or is a Customer with a different id
498
+ *
499
+ * @param object $otherCust customer to compare against
500
+ * @return boolean
501
+ */
502
+ public function isEqual($otherCust)
503
+ {
504
+ return !($otherCust instanceof Customer) ? false : $this->id === $otherCust->id;
505
+ }
506
+
507
+ /**
508
+ * returns an array containt all of the customer's payment methods
509
+ *
510
+ * @return array
511
+ */
512
+ public function paymentMethods()
513
+ {
514
+ return $this->paymentMethods;
515
+ }
516
+
517
+ /**
518
+ * returns the customer's default payment method
519
+ *
520
+ * @return CreditCard|PayPalAccount|ApplePayCard|AndroidPayCard
521
+ */
522
+ public function defaultPaymentMethod()
523
+ {
524
+ $defaultPaymentMethods = array_filter($this->paymentMethods, 'Braintree\\Customer::_defaultPaymentMethodFilter');
525
+ return current($defaultPaymentMethods);
526
+ }
527
+
528
+ public static function _defaultPaymentMethodFilter($paymentMethod)
529
+ {
530
+ return $paymentMethod->isDefault();
531
+ }
532
+
533
+ /* private class properties */
534
+
535
+ /**
536
+ * @access protected
537
+ * @var array registry of customer data
538
+ */
539
+ protected $_attributes = [
540
+ 'addresses' => '',
541
+ 'company' => '',
542
+ 'creditCards' => '',
543
+ 'email' => '',
544
+ 'fax' => '',
545
+ 'firstName' => '',
546
+ 'id' => '',
547
+ 'lastName' => '',
548
+ 'phone' => '',
549
+ 'createdAt' => '',
550
+ 'updatedAt' => '',
551
+ 'website' => '',
552
+ ];
553
+
554
+ /**
555
+ * sends the create request to the gateway
556
+ *
557
+ * @ignore
558
+ * @param string $subPath
559
+ * @param array $params
560
+ * @return mixed
561
+ */
562
+ public function _doCreate($subPath, $params)
563
+ {
564
+ $fullPath = $this->_config->merchantPath() . $subPath;
565
+ $response = $this->_http->post($fullPath, $params);
566
+
567
+ return $this->_verifyGatewayResponse($response);
568
+ }
569
+
570
+ /**
571
+ * verifies that a valid customer id is being used
572
+ * @ignore
573
+ * @param string customer id
574
+ * @throws InvalidArgumentException
575
+ */
576
+ private function _validateId($id = null) {
577
+ if (is_null($id)) {
578
+ throw new InvalidArgumentException(
579
+ 'expected customer id to be set'
580
+ );
581
+ }
582
+ if (!preg_match('/^[0-9A-Za-z_-]+$/', $id)) {
583
+ throw new InvalidArgumentException(
584
+ $id . ' is an invalid customer id.'
585
+ );
586
+ }
587
+ }
588
+
589
+
590
+ /* private class methods */
591
+
592
+ /**
593
+ * sends the update request to the gateway
594
+ *
595
+ * @ignore
596
+ * @param string $subPath
597
+ * @param array $params
598
+ * @return mixed
599
+ */
600
+ private function _doUpdate($httpVerb, $subPath, $params)
601
+ {
602
+ $fullPath = $this->_config->merchantPath() . $subPath;
603
+ $response = $this->_http->$httpVerb($fullPath, $params);
604
+
605
+ return $this->_verifyGatewayResponse($response);
606
+ }
607
+
608
+ /**
609
+ * generic method for validating incoming gateway responses
610
+ *
611
+ * creates a new Customer object and encapsulates
612
+ * it inside a Result\Successful object, or
613
+ * encapsulates a Errors object inside a Result\Error
614
+ * alternatively, throws an Unexpected exception if the response is invalid.
615
+ *
616
+ * @ignore
617
+ * @param array $response gateway response values
618
+ * @return Result\Successful|Result\Error
619
+ * @throws Exception\Unexpected
620
+ */
621
+ private function _verifyGatewayResponse($response)
622
+ {
623
+ if (isset($response['customer'])) {
624
+ // return a populated instance of Customer
625
+ return new Result\Successful(
626
+ Customer::factory($response['customer'])
627
+ );
628
+ } else if (isset($response['apiErrorResponse'])) {
629
+ return new Result\Error($response['apiErrorResponse']);
630
+ } else {
631
+ throw new Exception\Unexpected(
632
+ "Expected customer or apiErrorResponse"
633
+ );
634
+ }
635
+ }
636
+ }
637
+ class_alias('Braintree\CustomerGateway', 'Braintree_CustomerGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/CustomerSearch.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class CustomerSearch
5
+ {
6
+ public static function addressCountryName() { return new TextNode('address_country_name'); }
7
+ public static function addressExtendedAddress() { return new TextNode('address_extended_address'); }
8
+ public static function addressFirstName() { return new TextNode('address_first_name'); }
9
+ public static function addressLastName() { return new TextNode('address_last_name'); }
10
+ public static function addressLocality() { return new TextNode('address_locality'); }
11
+ public static function addressPostalCode() { return new TextNode('address_postal_code'); }
12
+ public static function addressRegion() { return new TextNode('address_region'); }
13
+ public static function addressStreetAddress() { return new TextNode('address_street_address'); }
14
+ public static function cardholderName() { return new TextNode('cardholder_name'); }
15
+ public static function company() { return new TextNode('company'); }
16
+ public static function email() { return new TextNode('email'); }
17
+ public static function fax() { return new TextNode('fax'); }
18
+ public static function firstName() { return new TextNode('first_name'); }
19
+ public static function id() { return new TextNode('id'); }
20
+ public static function lastName() { return new TextNode('last_name'); }
21
+ public static function paymentMethodToken() { return new TextNode('payment_method_token'); }
22
+ public static function paymentMethodTokenWithDuplicates() { return new IsNode('payment_method_token_with_duplicates'); }
23
+ public static function paypalAccountEmail() { return new IsNode('paypal_account_email'); }
24
+ public static function phone() { return new TextNode('phone'); }
25
+ public static function website() { return new TextNode('website'); }
26
+
27
+ public static function creditCardExpirationDate() { return new EqualityNode('credit_card_expiration_date'); }
28
+ public static function creditCardNumber() { return new PartialMatchNode('credit_card_number'); }
29
+
30
+ public static function ids() { return new MultipleValueNode('ids'); }
31
+
32
+ public static function createdAt() { return new RangeNode("created_at"); }
33
+ }
34
+ class_alias('Braintree\CustomerSearch', 'Braintree_CustomerSearch');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Descriptor.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class Descriptor extends Instance
5
+ {
6
+ }
7
+ class_alias('Braintree\Descriptor', 'Braintree_Descriptor');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Digest.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Digest encryption module
6
+ * Digest creates an HMAC-SHA1 hash for encrypting messages
7
+ */
8
+ class Digest
9
+ {
10
+ public static function hexDigestSha1($key, $string)
11
+ {
12
+ if(function_exists('hash_hmac')) {
13
+ return self::_builtInHmacSha1($string, $key);
14
+ } else {
15
+ return self::_hmacSha1($string, $key);
16
+ }
17
+ }
18
+
19
+ public static function hexDigestSha256($key, $string)
20
+ {
21
+ return hash_hmac('sha256', $string, hash('sha256', $key, true));
22
+ }
23
+
24
+ public static function secureCompare($left, $right)
25
+ {
26
+ if (strlen($left) != strlen($right)) {
27
+ return false;
28
+ }
29
+
30
+ $leftBytes = unpack("C*", $left);
31
+ $rightBytes = unpack("C*", $right);
32
+
33
+ $result = 0;
34
+ for ($i = 1; $i <= count($leftBytes); $i++) {
35
+ $result = $result | ($leftBytes[$i] ^ $rightBytes[$i]);
36
+ }
37
+ return $result == 0;
38
+ }
39
+
40
+ public static function _builtInHmacSha1($message, $key)
41
+ {
42
+ return hash_hmac('sha1', $message, sha1($key, true));
43
+ }
44
+
45
+ public static function _hmacSha1($message, $key)
46
+ {
47
+ $pack = 'H40';
48
+ $keyDigest = sha1($key,true);
49
+ $innerPad = str_repeat(chr(0x36), 64);
50
+ $outerPad = str_repeat(chr(0x5C), 64);
51
+
52
+ for ($i = 0; $i < 20; $i++) {
53
+ $innerPad{$i} = $keyDigest{$i} ^ $innerPad{$i};
54
+ $outerPad{$i} = $keyDigest{$i} ^ $outerPad{$i};
55
+ }
56
+
57
+ return sha1($outerPad.pack($pack, sha1($innerPad.$message)));
58
+ }
59
+ }
60
+ class_alias('Braintree\Digest', 'Braintree_Digest');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Disbursement.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class Disbursement extends Base
5
+ {
6
+ private $_merchantAccount;
7
+
8
+ protected function _initialize($disbursementAttribs)
9
+ {
10
+ $this->_attributes = $disbursementAttribs;
11
+ $this->merchantAccountDetails = $disbursementAttribs['merchantAccount'];
12
+
13
+ if (isset($disbursementAttribs['merchantAccount'])) {
14
+ $this->_set('merchantAccount',
15
+ MerchantAccount::factory($disbursementAttribs['merchantAccount'])
16
+ );
17
+ }
18
+ }
19
+
20
+ public function transactions()
21
+ {
22
+ $collection = Transaction::search([
23
+ TransactionSearch::ids()->in($this->transactionIds),
24
+ ]);
25
+
26
+ return $collection;
27
+ }
28
+
29
+ public static function factory($attributes)
30
+ {
31
+ $instance = new self();
32
+ $instance->_initialize($attributes);
33
+ return $instance;
34
+ }
35
+
36
+ public function __toString()
37
+ {
38
+ $display = [
39
+ 'id', 'merchantAccountDetails', 'exceptionMessage', 'amount',
40
+ 'disbursementDate', 'followUpAction', 'retry', 'success',
41
+ 'transactionIds'
42
+ ];
43
+
44
+ $displayAttributes = [];
45
+ foreach ($display AS $attrib) {
46
+ $displayAttributes[$attrib] = $this->$attrib;
47
+ }
48
+ return __CLASS__ . '[' .
49
+ Util::attributesToString($displayAttributes) .']';
50
+ }
51
+ }
52
+ class_alias('Braintree\Disbursement', 'Braintree_Disbursement');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/DisbursementDetails.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Disbursement details from a transaction
6
+ * Creates an instance of DisbursementDetails as returned from a transaction
7
+ *
8
+ *
9
+ * @package Braintree
10
+ *
11
+ * @property-read string $settlementAmount
12
+ * @property-read string $settlementCurrencyIsoCode
13
+ * @property-read string $settlementCurrencyExchangeRate
14
+ * @property-read string $fundsHeld
15
+ * @property-read string $success
16
+ * @property-read string $disbursementDate
17
+ */
18
+ class DisbursementDetails extends Instance
19
+ {
20
+ public function isValid() {
21
+ return !is_null($this->disbursementDate);
22
+ }
23
+ }
24
+ class_alias('Braintree\DisbursementDetails', 'Braintree_DisbursementDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Discount.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class Discount extends Modification
5
+ {
6
+ public static function factory($attributes)
7
+ {
8
+ $instance = new self();
9
+ $instance->_initialize($attributes);
10
+ return $instance;
11
+ }
12
+
13
+
14
+ // static methods redirecting to gateway
15
+
16
+ public static function all()
17
+ {
18
+ return Configuration::gateway()->discount()->all();
19
+ }
20
+ }
21
+ class_alias('Braintree\Discount', 'Braintree_Discount');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/DiscountGateway.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class DiscountGateway
5
+ {
6
+ private $_gateway;
7
+ private $_config;
8
+ private $_http;
9
+
10
+ public function __construct($gateway)
11
+ {
12
+ $this->_gateway = $gateway;
13
+ $this->_config = $gateway->config;
14
+ $this->_config->assertHasAccessTokenOrKeys();
15
+ $this->_http = new Http($gateway->config);
16
+ }
17
+
18
+ public function all()
19
+ {
20
+ $path = $this->_config->merchantPath() . '/discounts';
21
+ $response = $this->_http->get($path);
22
+
23
+ $discounts = ["discount" => $response['discounts']];
24
+
25
+ return Util::extractAttributeAsArray(
26
+ $discounts,
27
+ 'discount'
28
+ );
29
+ }
30
+ }
31
+ class_alias('Braintree\DiscountGateway', 'Braintree_DiscountGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Dispute.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Creates an instance of Dispute as returned from a transaction
6
+ *
7
+ *
8
+ * @package Braintree
9
+ *
10
+ * @property-read string $amount
11
+ * @property-read string $currencyIsoCode
12
+ * @property-read date $receivedDate
13
+ * @property-read string $reason
14
+ * @property-read string $status
15
+ * @property-read string $disbursementDate
16
+ * @property-read object $transactionDetails
17
+ */
18
+ class Dispute extends Base
19
+ {
20
+ protected $_attributes = [];
21
+
22
+ /* Dispute Status */
23
+ const OPEN = 'open';
24
+ const WON = 'won';
25
+ const LOST = 'lost';
26
+
27
+ /* deprecated; for backwards compatibilty */
28
+ const Open = 'open';
29
+
30
+ /* Dispute Reason */
31
+ const CANCELLED_RECURRING_TRANSACTION = "cancelled_recurring_transaction";
32
+ const CREDIT_NOT_PROCESSED = "credit_not_processed";
33
+ const DUPLICATE = "duplicate";
34
+ const FRAUD = "fraud";
35
+ const GENERAL = "general";
36
+ const INVALID_ACCOUNT = "invalid_account";
37
+ const NOT_RECOGNIZED = "not_recognized";
38
+ const PRODUCT_NOT_RECEIVED = "product_not_received";
39
+ const PRODUCT_UNSATISFACTORY = "product_unsatisfactory";
40
+ const TRANSACTION_AMOUNT_DIFFERS = "transaction_amount_differs";
41
+ const RETRIEVAL = "retrieval";
42
+
43
+ /* Dispute Kind */
44
+ const CHARGEBACK = 'chargeback';
45
+ const PRE_ARBITRATION = 'pre_arbitration';
46
+ // RETRIEVAL for kind already defined under Dispute Reason
47
+
48
+ protected function _initialize($disputeAttribs)
49
+ {
50
+ $this->_attributes = $disputeAttribs;
51
+
52
+ if (isset($disputeAttribs['transaction'])) {
53
+ $this->_set('transactionDetails',
54
+ new Dispute\TransactionDetails($disputeAttribs['transaction'])
55
+ );
56
+ }
57
+ }
58
+
59
+ public static function factory($attributes)
60
+ {
61
+ $instance = new self();
62
+ $instance->_initialize($attributes);
63
+ return $instance;
64
+ }
65
+
66
+ public function __toString()
67
+ {
68
+ $display = [
69
+ 'amount', 'reason', 'status',
70
+ 'replyByDate', 'receivedDate', 'currencyIsoCode'
71
+ ];
72
+
73
+ $displayAttributes = [];
74
+ foreach ($display AS $attrib) {
75
+ $displayAttributes[$attrib] = $this->$attrib;
76
+ }
77
+ return __CLASS__ . '[' .
78
+ Util::attributesToString($displayAttributes) .']';
79
+ }
80
+ }
81
+ class_alias('Braintree\Dispute', 'Braintree_Dispute');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Dispute/TransactionDetails.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Dispute;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * Transaction details for a dispute
8
+ *
9
+ * @package Braintree
10
+ */
11
+
12
+ /**
13
+ * Creates an instance of DisbursementDetails as returned from a transaction
14
+ *
15
+ *
16
+ * @package Braintree
17
+ *
18
+ * @property-read string $amount
19
+ * @property-read string $id
20
+ */
21
+ class TransactionDetails extends Instance
22
+ {
23
+ }
24
+
25
+ class_alias('Braintree\Dispute\TransactionDetails', 'Braintree_Dispute_TransactionDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/EqualityNode.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class EqualityNode extends IsNode
5
+ {
6
+ function isNot($value)
7
+ {
8
+ $this->searchTerms['is_not'] = strval($value);
9
+ return $this;
10
+ }
11
+ }
12
+ class_alias('Braintree\EqualityNode', 'Braintree_EqualityNode');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Error/Codes.php ADDED
@@ -0,0 +1,533 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Error;
3
+
4
+ /**
5
+ *
6
+ * Validation Error codes and messages
7
+ *
8
+ * ErrorCodes class provides constants for validation errors.
9
+ * The constants should be used to check for a specific validation
10
+ * error in a ValidationErrorCollection.
11
+ * The error messages returned from the server may change;
12
+ * but the codes will remain the same.
13
+ *
14
+ * @package Braintree
15
+ * @subpackage Errors
16
+ * @category Validation
17
+ */
18
+ class Codes
19
+ {
20
+ const ADDRESS_CANNOT_BE_BLANK = '81801';
21
+ const ADDRESS_COMPANY_IS_INVALID = '91821';
22
+ const ADDRESS_COMPANY_IS_TOO_LONG = '81802';
23
+ const ADDRESS_COUNTRY_CODE_ALPHA2_IS_NOT_ACCEPTED = '91814';
24
+ const ADDRESS_COUNTRY_CODE_ALPHA3_IS_NOT_ACCEPTED = '91816';
25
+ const ADDRESS_COUNTRY_CODE_NUMERIC_IS_NOT_ACCEPTED = '91817';
26
+ const ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED = '91803';
27
+ const ADDRESS_EXTENDED_ADDRESS_IS_INVALID = '91823';
28
+ const ADDRESS_EXTENDED_ADDRESS_IS_TOO_LONG = '81804';
29
+ const ADDRESS_FIRST_NAME_IS_INVALID = '91819';
30
+ const ADDRESS_FIRST_NAME_IS_TOO_LONG = '81805';
31
+ const ADDRESS_INCONSISTENT_COUNTRY = '91815';
32
+ const ADDRESS_LAST_NAME_IS_INVALID = '91820';
33
+ const ADDRESS_LAST_NAME_IS_TOO_LONG = '81806';
34
+ const ADDRESS_LOCALITY_IS_INVALID = '91824';
35
+ const ADDRESS_LOCALITY_IS_TOO_LONG = '81807';
36
+ const ADDRESS_POSTAL_CODE_INVALID_CHARACTERS = '81813';
37
+ const ADDRESS_POSTAL_CODE_IS_INVALID = '91826';
38
+ const ADDRESS_POSTAL_CODE_IS_REQUIRED = '81808';
39
+ const ADDRESS_POSTAL_CODE_IS_TOO_LONG = '81809';
40
+ const ADDRESS_REGION_IS_INVALID = '91825';
41
+ const ADDRESS_REGION_IS_TOO_LONG = '81810';
42
+ const ADDRESS_STATE_IS_INVALID_FOR_SELLER_PROTECTION = '81827';
43
+ const ADDRESS_STREET_ADDRESS_IS_INVALID = '91822';
44
+ const ADDRESS_STREET_ADDRESS_IS_REQUIRED = '81811';
45
+ const ADDRESS_STREET_ADDRESS_IS_TOO_LONG = '81812';
46
+ const ADDRESS_TOO_MANY_ADDRESSES_PER_CUSTOMER = '91818';
47
+
48
+ const APPLE_PAY_CARDS_ARE_NOT_ACCEPTED = '83501';
49
+ const APPLE_PAY_CUSTOMER_ID_IS_REQUIRED_FOR_VAULTING = '83502';
50
+ const APPLE_PAY_TOKEN_IS_IN_USE = '93503';
51
+ const APPLE_PAY_PAYMENT_METHOD_NONCE_CONSUMED = '93504';
52
+ const APPLE_PAY_PAYMENT_METHOD_NONCE_UNKNOWN = '93505';
53
+ const APPLE_PAY_PAYMENT_METHOD_NONCE_UNLOCKED = '93506';
54
+ const APPLE_PAY_PAYMENT_METHOD_NONCE_CARD_TYPE_IS_NOT_ACCEPTED = '83518';
55
+ const APPLE_PAY_CANNOT_UPDATE_APPLE_PAY_CARD_USING_PAYMENT_METHOD_NONCE = '93507';
56
+ const APPLE_PAY_NUMBER_IS_REQUIRED = '93508';
57
+ const APPLE_PAY_EXPIRATION_MONTH_IS_REQUIRED = '93509';
58
+ const APPLE_PAY_EXPIRATION_YEAR_IS_REQUIRED = '93510';
59
+ const APPLE_PAY_CRYPTOGRAM_IS_REQUIRED = '93511';
60
+ const APPLE_PAY_DECRYPTION_FAILED = '83512';
61
+ const APPLE_PAY_DISABLED = '93513';
62
+ const APPLE_PAY_MERCHANT_NOT_CONFIGURED = '93514';
63
+ const APPLE_PAY_MERCHANT_KEYS_ALREADY_CONFIGURED = '93515';
64
+ const APPLE_PAY_MERCHANT_KEYS_NOT_CONFIGURED = '93516';
65
+ const APPLE_PAY_CERTIFICATE_INVALID = '93517';
66
+ const APPLE_PAY_CERTIFICATE_MISMATCH = '93519';
67
+ const APPLE_PAY_INVALID_TOKEN = '83520';
68
+ const APPLE_PAY_PRIVATE_KEY_MISMATCH = '93521';
69
+ const APPLE_PAY_KEY_MISMATCH_STORING_CERTIFICATE = '93522';
70
+
71
+ const AUTHORIZATION_FINGERPRINT_INVALID_CREATED_AT = '93204';
72
+ const AUTHORIZATION_FINGERPRINT_INVALID_FORMAT = '93202';
73
+ const AUTHORIZATION_FINGERPRINT_INVALID_PUBLIC_KEY = '93205';
74
+ const AUTHORIZATION_FINGERPRINT_INVALID_SIGNATURE = '93206';
75
+ const AUTHORIZATION_FINGERPRINT_MISSING_FINGERPRINT = '93201';
76
+ const AUTHORIZATION_FINGERPRINT_OPTIONS_NOT_ALLOWED_WITHOUT_CUSTOMER = '93207';
77
+ const AUTHORIZATION_FINGERPRINT_SIGNATURE_REVOKED = '93203';
78
+
79
+ const CLIENT_TOKEN_CUSTOMER_DOES_NOT_EXIST = '92804';
80
+ const CLIENT_TOKEN_FAIL_ON_DUPLICATE_PAYMENT_METHOD_REQUIRES_CUSTOMER_ID = '92803';
81
+ const CLIENT_TOKEN_MAKE_DEFAULT_REQUIRES_CUSTOMER_ID = '92801';
82
+ const CLIENT_TOKEN_PROXY_MERCHANT_DOES_NOT_EXIST = '92805';
83
+ const CLIENT_TOKEN_UNSUPPORTED_VERSION = '92806';
84
+ const CLIENT_TOKEN_VERIFY_CARD_REQUIRES_CUSTOMER_ID = '92802';
85
+ const CLIENT_TOKEN_MERCHANT_ACCOUNT_DOES_NOT_EXIST = '92807';
86
+
87
+ const CREDIT_CARD_BILLING_ADDRESS_CONFLICT = '91701';
88
+ const CREDIT_CARD_BILLING_ADDRESS_FORMAT_IS_INVALID = '91744';
89
+ const CREDIT_CARD_BILLING_ADDRESS_ID_IS_INVALID = '91702';
90
+ const CREDIT_CARD_CANNOT_UPDATE_CARD_USING_PAYMENT_METHOD_NONCE = '91735';
91
+ const CREDIT_CARD_CARDHOLDER_NAME_IS_TOO_LONG = '81723';
92
+ const CREDIT_CARD_CREDIT_CARD_TYPE_IS_NOT_ACCEPTED = '81703';
93
+ const CREDIT_CARD_CREDIT_CARD_TYPE_IS_NOT_ACCEPTED_BY_SUBSCRIPTION_MERCHANT_ACCOUNT = '81718';
94
+ const CREDIT_CARD_CUSTOMER_ID_IS_INVALID = '91705';
95
+ const CREDIT_CARD_CUSTOMER_ID_IS_REQUIRED = '91704';
96
+ const CREDIT_CARD_CVV_IS_INVALID = '81707';
97
+ const CREDIT_CARD_CVV_IS_REQUIRED = '81706';
98
+ const CREDIT_CARD_CVV_VERIFICATION_FAILED = '81736';
99
+ const CREDIT_CARD_DUPLICATE_CARD_EXISTS = '81724';
100
+ const CREDIT_CARD_EXPIRATION_DATE_CONFLICT = '91708';
101
+ const CREDIT_CARD_EXPIRATION_DATE_IS_INVALID = '81710';
102
+ const CREDIT_CARD_EXPIRATION_DATE_IS_REQUIRED = '81709';
103
+ const CREDIT_CARD_EXPIRATION_DATE_YEAR_IS_INVALID = '81711';
104
+ const CREDIT_CARD_EXPIRATION_MONTH_IS_INVALID = '81712';
105
+ const CREDIT_CARD_EXPIRATION_YEAR_IS_INVALID = '81713';
106
+ const CREDIT_CARD_INVALID_PARAMS_FOR_CREDIT_CARD_UPDATE = '91745';
107
+ const CREDIT_CARD_INVALID_VENMO_SDK_PAYMENT_METHOD_CODE = '91727';
108
+ const CREDIT_CARD_NUMBER_INVALID_LENGTH = '81716';
109
+ const CREDIT_CARD_NUMBER_IS_INVALID = '81715';
110
+ const CREDIT_CARD_NUMBER_IS_PROHIBITED = '81750';
111
+ const CREDIT_CARD_NUMBER_IS_REQUIRED = '81714';
112
+ const CREDIT_CARD_NUMBER_LENGTH_IS_INVALID = '81716';
113
+ const CREDIT_CARD_NUMBER_MUST_BE_TEST_NUMBER = '81717';
114
+ const CREDIT_CARD_OPTIONS_UPDATE_EXISTING_TOKEN_IS_INVALID = '91723';
115
+ const CREDIT_CARD_OPTIONS_UPDATE_EXISTING_TOKEN_NOT_ALLOWED = '91729';
116
+ const CREDIT_CARD_OPTIONS_VERIFICATION_AMOUNT_CANNOT_BE_NEGATIVE = '91739';
117
+ const CREDIT_CARD_OPTIONS_VERIFICATION_AMOUNT_FORMAT_IS_INVALID = '91740';
118
+ const CREDIT_CARD_OPTIONS_VERIFICATION_AMOUNT_IS_TOO_LARGE = '91752';
119
+ const CREDIT_CARD_OPTIONS_VERIFICATION_AMOUNT_NOT_SUPPORTED_BY_PROCESSOR = '91741';
120
+ const CREDIT_CARD_OPTIONS_VERIFICATION_MERCHANT_ACCOUNT_ID_IS_INVALID = '91728';
121
+ const CREDIT_CARD_OPTIONS_VERIFICATION_MERCHANT_ACCOUNT_IS_FORBIDDEN = '91743';
122
+ const CREDIT_CARD_OPTIONS_VERIFICATION_MERCHANT_ACCOUNT_IS_SUSPENDED = '91742';
123
+ const CREDIT_CARD_OPTIONS_VERIFICATION_MERCHANT_ACCOUNT_CANNOT_BE_SUB_MERCHANT_ACCOUNT = '91755';
124
+ const CREDIT_CARD_PAYMENT_METHOD_CONFLICT = '81725';
125
+ const CREDIT_CARD_PAYMENT_METHOD_IS_NOT_A_CREDIT_CARD = '91738';
126
+ const CREDIT_CARD_PAYMENT_METHOD_NONCE_CARD_TYPE_IS_NOT_ACCEPTED = '91734';
127
+ const CREDIT_CARD_PAYMENT_METHOD_NONCE_CONSUMED = '91731';
128
+ const CREDIT_CARD_PAYMENT_METHOD_NONCE_LOCKED = '91733';
129
+ const CREDIT_CARD_PAYMENT_METHOD_NONCE_UNKNOWN = '91732';
130
+ const CREDIT_CARD_POSTAL_CODE_VERIFICATION_FAILED = '81737';
131
+ const CREDIT_CARD_TOKEN_FORMAT_IS_INVALID = '91718';
132
+ const CREDIT_CARD_TOKEN_INVALID = '91718';
133
+ const CREDIT_CARD_TOKEN_IS_IN_USE = '91719';
134
+ const CREDIT_CARD_TOKEN_IS_NOT_ALLOWED = '91721';
135
+ const CREDIT_CARD_TOKEN_IS_REQUIRED = '91722';
136
+ const CREDIT_CARD_TOKEN_IS_TOO_LONG = '91720';
137
+ const CREDIT_CARD_VENMO_SDK_PAYMENT_METHOD_CODE_CARD_TYPE_IS_NOT_ACCEPTED = '91726';
138
+ const CREDIT_CARD_VERIFICATION_NOT_SUPPORTED_ON_THIS_MERCHANT_ACCOUNT = '91730';
139
+
140
+ const CUSTOMER_COMPANY_IS_TOO_LONG = '81601';
141
+ const CUSTOMER_CUSTOM_FIELD_IS_INVALID = '91602';
142
+ const CUSTOMER_CUSTOM_FIELD_IS_TOO_LONG = '81603';
143
+ const CUSTOMER_EMAIL_FORMAT_IS_INVALID = '81604';
144
+ const CUSTOMER_EMAIL_IS_INVALID = '81604';
145
+ const CUSTOMER_EMAIL_IS_REQUIRED = '81606';
146
+ const CUSTOMER_EMAIL_IS_TOO_LONG = '81605';
147
+ const CUSTOMER_FAX_IS_TOO_LONG = '81607';
148
+ const CUSTOMER_FIRST_NAME_IS_TOO_LONG = '81608';
149
+ const CUSTOMER_ID_IS_INVAILD = '91610'; //Deprecated
150
+ const CUSTOMER_ID_IS_INVALID = '91610';
151
+ const CUSTOMER_ID_IS_IN_USE = '91609';
152
+ const CUSTOMER_ID_IS_NOT_ALLOWED = '91611';
153
+ const CUSTOMER_ID_IS_REQUIRED = '91613';
154
+ const CUSTOMER_ID_IS_TOO_LONG = '91612';
155
+ const CUSTOMER_LAST_NAME_IS_TOO_LONG = '81613';
156
+ const CUSTOMER_PHONE_IS_TOO_LONG = '81614';
157
+ const CUSTOMER_VAULTED_PAYMENT_INSTRUMENT_NONCE_BELONGS_TO_DIFFERENT_CUSTOMER = '91617';
158
+ const CUSTOMER_WEBSITE_FORMAT_IS_INVALID = '81616';
159
+ const CUSTOMER_WEBSITE_IS_INVALID = '81616';
160
+ const CUSTOMER_WEBSITE_IS_TOO_LONG = '81615';
161
+
162
+ const DESCRIPTOR_NAME_FORMAT_IS_INVALID = '92201';
163
+ const DESCRIPTOR_PHONE_FORMAT_IS_INVALID = '92202';
164
+ const DESCRIPTOR_INTERNATIONAL_NAME_FORMAT_IS_INVALID = '92204';
165
+ const DESCRIPTOR_DYNAMIC_DESCRIPTORS_DISABLED = '92203';
166
+ const DESCRIPTOR_INTERNATIONAL_PHONE_FORMAT_IS_INVALID = '92205';
167
+ const DESCRIPTOR_URL_FORMAT_IS_INVALID = '92206';
168
+
169
+ const INDUSTRY_DATA_INDUSTRY_TYPE_IS_INVALID = '93401';
170
+ const INDUSTRY_DATA_LODGING_EMPTY_DATA = '93402';
171
+ const INDUSTRY_DATA_LODGING_FOLIO_NUMBER_IS_INVALID = '93403';
172
+ const INDUSTRY_DATA_LODGING_CHECK_IN_DATE_IS_INVALID = '93404';
173
+ const INDUSTRY_DATA_LODGING_CHECK_OUT_DATE_IS_INVALID = '93405';
174
+ const INDUSTRY_DATA_LODGING_CHECK_OUT_DATE_MUST_FOLLOW_CHECK_IN_DATE = '93406';
175
+ const INDUSTRY_DATA_LODGING_UNKNOWN_DATA_FIELD = '93407';
176
+ const INDUSTRY_DATA_TRAVEL_CRUISE_EMPTY_DATA = '93408';
177
+ const INDUSTRY_DATA_TRAVEL_CRUISE_UNKNOWN_DATA_FIELD = '93409';
178
+ const INDUSTRY_DATA_TRAVEL_CRUISE_TRAVEL_PACKAGE_IS_INVALID = '93410';
179
+ const INDUSTRY_DATA_TRAVEL_CRUISE_DEPARTURE_DATE_IS_INVALID = '93411';
180
+ const INDUSTRY_DATA_TRAVEL_CRUISE_LODGING_CHECK_IN_DATE_IS_INVALID = '93412';
181
+ const INDUSTRY_DATA_TRAVEL_CRUISE_LODGING_CHECK_OUT_DATE_IS_INVALID = '93413';
182
+
183
+ const MERCHANT_COUNTRY_CANNOT_BE_BLANK = '83603';
184
+ const MERCHANT_COUNTRY_CODE_ALPHA2_IS_INVALID = '93607';
185
+ const MERCHANT_COUNTRY_CODE_ALPHA2_IS_NOT_ACCEPTED = '93606';
186
+ const MERCHANT_COUNTRY_CODE_ALPHA3_IS_INVALID = '93605';
187
+ const MERCHANT_COUNTRY_CODE_ALPHA3_IS_NOT_ACCEPTED = '93604';
188
+ const MERCHANT_COUNTRY_CODE_NUMERIC_IS_INVALID = '93609';
189
+ const MERCHANT_COUNTRY_CODE_NUMERIC_IS_NOT_ACCEPTED = '93608';
190
+ const MERCHANT_COUNTRY_NAME_IS_INVALID = '93611';
191
+ const MERCHANT_COUNTRY_NAME_IS_NOT_ACCEPTED = '93610';
192
+ const MERCHANT_CURRENCIES_ARE_INVALID = '93614';
193
+ const MERCHANT_EMAIL_FORMAT_IS_INVALID = '93602';
194
+ const MERCHANT_EMAIL_IS_REQUIRED = '83601';
195
+ const MERCHANT_INCONSISTENT_COUNTRY = '93612';
196
+ const MERCHANT_ACCOUNT_PAYMENT_METHODS_ARE_INVALID = '93613';
197
+ const MERCHANT_PAYMENT_METHODS_ARE_NOT_ALLOWED = '93615';
198
+ const MERCHANT_MERCHANT_ACCOUNT_EXISTS_FOR_CURRENCY = '93616';
199
+ const MERCHANT_CURRENCY_IS_REQUIRED = '93617';
200
+ const MERCHANT_CURRENCY_IS_INVALID = '93618';
201
+ const MERCHANT_NO_MERCHANT_ACCOUNTS = '93619';
202
+ const MERCHANT_MERCHANT_ACCOUNT_EXISTS_FOR_ID = '93620';
203
+ const MERCHANT_MERCHANT_ACCOUNT_NOT_AUTH_ONBOARDED = '93621';
204
+
205
+ const MERCHANT_ACCOUNT_ID_FORMAT_IS_INVALID = '82603';
206
+ const MERCHANT_ACCOUNT_ID_IS_IN_USE = '82604';
207
+ const MERCHANT_ACCOUNT_ID_IS_NOT_ALLOWED = '82605';
208
+ const MERCHANT_ACCOUNT_ID_IS_TOO_LONG = '82602';
209
+ const MERCHANT_ACCOUNT_MASTER_MERCHANT_ACCOUNT_ID_IS_INVALID = '82607';
210
+ const MERCHANT_ACCOUNT_MASTER_MERCHANT_ACCOUNT_ID_IS_REQUIRED = '82606';
211
+ const MERCHANT_ACCOUNT_MASTER_MERCHANT_ACCOUNT_MUST_BE_ACTIVE = '82608';
212
+ const MERCHANT_ACCOUNT_TOS_ACCEPTED_IS_REQUIRED = '82610';
213
+ const MERCHANT_ACCOUNT_CANNOT_BE_UPDATED = '82674';
214
+ const MERCHANT_ACCOUNT_DECLINED = '82626';
215
+ const MERCHANT_ACCOUNT_DECLINED_MASTER_CARD_MATCH = '82622';
216
+ const MERCHANT_ACCOUNT_DECLINED_OFAC = '82621';
217
+ const MERCHANT_ACCOUNT_DECLINED_FAILED_KYC = '82623';
218
+ const MERCHANT_ACCOUNT_DECLINED_SSN_INVALID = '82624';
219
+ const MERCHANT_ACCOUNT_DECLINED_SSN_MATCHES_DECEASED = '82625';
220
+ const MERCHANT_ACCOUNT_ID_CANNOT_BE_UPDATED = '82675';
221
+ const MERCHANT_ACCOUNT_MASTER_MERCHANT_ACCOUNT_ID_CANNOT_BE_UPDATED = '82676';
222
+
223
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ACCOUNT_NUMBER_IS_REQUIRED = '82614';
224
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_COMPANY_NAME_IS_INVALID = '82631';
225
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_COMPANY_NAME_IS_REQUIRED_WITH_TAX_ID = '82633';
226
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_DATE_OF_BIRTH_IS_REQUIRED = '82612';
227
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_DECLINED = '82626'; // Keep for backwards compatibility
228
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_DECLINED_MASTER_CARD_MATCH = '82622'; // Keep for backwards compatibility
229
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_DECLINED_OFAC = '82621'; // Keep for backwards compatibility
230
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_DECLINED_FAILED_KYC = '82623'; // Keep for backwards compatibility
231
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_DECLINED_SSN_INVALID = '82624'; // Keep for backwards compatibility
232
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_DECLINED_SSN_MATCHES_DECEASED = '82625'; // Keep for backwards compatibility
233
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_EMAIL_ADDRESS_IS_INVALID = '82616';
234
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_FIRST_NAME_IS_INVALID = '82627';
235
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_FIRST_NAME_IS_REQUIRED = '82609';
236
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_LAST_NAME_IS_INVALID = '82628';
237
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_LAST_NAME_IS_REQUIRED = '82611';
238
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_PHONE_IS_INVALID = '82636';
239
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ROUTING_NUMBER_IS_INVALID = '82635';
240
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ROUTING_NUMBER_IS_REQUIRED = '82613';
241
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_SSN_IS_INVALID = '82615';
242
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_TAX_ID_IS_INVALID = '82632';
243
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_TAX_ID_IS_REQUIRED_WITH_COMPANY_NAME = '82634';
244
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_DATE_OF_BIRTH_IS_INVALID = '82663';
245
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ADDRESS_REGION_IS_INVALID = '82664';
246
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_EMAIL_ADDRESS_IS_REQUIRED = '82665';
247
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ACCOUNT_NUMBER_IS_INVALID = '82670';
248
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_TAX_ID_MUST_BE_BLANK = '82673';
249
+
250
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ADDRESS_LOCALITY_IS_REQUIRED = '82618';
251
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ADDRESS_POSTAL_CODE_IS_INVALID = '82630';
252
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ADDRESS_POSTAL_CODE_IS_REQUIRED = '82619';
253
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ADDRESS_REGION_IS_REQUIRED = '82620';
254
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ADDRESS_STREET_ADDRESS_IS_INVALID = '82629';
255
+ const MERCHANT_ACCOUNT_APPLICANT_DETAILS_ADDRESS_STREET_ADDRESS_IS_REQUIRED = '82617';
256
+
257
+ const MERCHANT_ACCOUNT_BUSINESS_DBA_NAME_IS_INVALID = '82646';
258
+ const MERCHANT_ACCOUNT_BUSINESS_TAX_ID_IS_INVALID = '82647';
259
+ const MERCHANT_ACCOUNT_BUSINESS_TAX_ID_IS_REQUIRED_WITH_LEGAL_NAME = '82648';
260
+ const MERCHANT_ACCOUNT_BUSINESS_LEGAL_NAME_IS_REQUIRED_WITH_TAX_ID = '82669';
261
+ const MERCHANT_ACCOUNT_BUSINESS_TAX_ID_MUST_BE_BLANK = '82672';
262
+ const MERCHANT_ACCOUNT_BUSINESS_LEGAL_NAME_IS_INVALID = '82677';
263
+ const MERCHANT_ACCOUNT_BUSINESS_ADDRESS_REGION_IS_INVALID = '82684';
264
+ const MERCHANT_ACCOUNT_BUSINESS_ADDRESS_STREET_ADDRESS_IS_INVALID = '82685';
265
+ const MERCHANT_ACCOUNT_BUSINESS_ADDRESS_POSTAL_CODE_IS_INVALID = '82686';
266
+
267
+ const MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_REQUIRED = '82637';
268
+ const MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_REQUIRED = '82638';
269
+ const MERCHANT_ACCOUNT_INDIVIDUAL_DATE_OF_BIRTH_IS_REQUIRED = '82639';
270
+ const MERCHANT_ACCOUNT_INDIVIDUAL_SSN_IS_INVALID = '82642';
271
+ const MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_INVALID = '82643';
272
+ const MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_INVALID = '82644';
273
+ const MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_INVALID = '82645';
274
+ const MERCHANT_ACCOUNT_INDIVIDUAL_PHONE_IS_INVALID = '82656';
275
+ const MERCHANT_ACCOUNT_INDIVIDUAL_DATE_OF_BIRTH_IS_INVALID = '82666';
276
+ const MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_REQUIRED = '82667';
277
+
278
+ const MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_REQUIRED = '82657';
279
+ const MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_LOCALITY_IS_REQUIRED = '82658';
280
+ const MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_REQUIRED = '82659';
281
+ const MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_REQUIRED = '82660';
282
+ const MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_INVALID = '82661';
283
+ const MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_INVALID = '82662';
284
+ const MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_INVALID = '82668';
285
+
286
+ const MERCHANT_ACCOUNT_FUNDING_ROUTING_NUMBER_IS_REQUIRED = '82640';
287
+ const MERCHANT_ACCOUNT_FUNDING_ACCOUNT_NUMBER_IS_REQUIRED = '82641';
288
+ const MERCHANT_ACCOUNT_FUNDING_ROUTING_NUMBER_IS_INVALID = '82649';
289
+ const MERCHANT_ACCOUNT_FUNDING_ACCOUNT_NUMBER_IS_INVALID = '82671';
290
+ const MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_REQUIRED = '82678';
291
+ const MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_INVALID = '82679';
292
+ const MERCHANT_ACCOUNT_FUNDING_EMAIL_IS_REQUIRED = '82680';
293
+ const MERCHANT_ACCOUNT_FUNDING_EMAIL_IS_INVALID = '82681';
294
+ const MERCHANT_ACCOUNT_FUNDING_MOBILE_PHONE_IS_REQUIRED = '82682';
295
+ const MERCHANT_ACCOUNT_FUNDING_MOBILE_PHONE_IS_INVALID = '82683';
296
+
297
+ const OAUTH_INVALID_GRANT = '93801';
298
+ const OAUTH_INVALID_CREDENTIALS = '93802';
299
+ const OAUTH_INVALID_SCOPE = '93803';
300
+ const OAUTH_INVALID_REQUEST = '93804';
301
+ const OAUTH_UNSUPPORTED_GRANT_TYPE = '93805';
302
+
303
+ const PAYMENT_METHOD_CANNOT_FORWARD_PAYMENT_METHOD_TYPE = '93106';
304
+ const PAYMENT_METHOD_CUSTOMER_ID_IS_INVALID = '93105';
305
+ const PAYMENT_METHOD_CUSTOMER_ID_IS_REQUIRED = '93104';
306
+ const PAYMENT_METHOD_NONCE_IS_INVALID = '93102';
307
+ const PAYMENT_METHOD_NONCE_IS_REQUIRED = '93103';
308
+ const PAYMENT_METHOD_PAYMENT_METHOD_NONCE_CONSUMED = '93107';
309
+ const PAYMENT_METHOD_PAYMENT_METHOD_NONCE_UNKNOWN = '93108';
310
+ const PAYMENT_METHOD_PAYMENT_METHOD_NONCE_LOCKED = '93109';
311
+ const PAYMENT_METHOD_PAYMENT_METHOD_PARAMS_ARE_REQUIRED = '93101';
312
+
313
+ const PAYPAL_ACCOUNT_AUTH_EXPIRED = '92911';
314
+ const PAYPAL_ACCOUNT_CANNOT_HAVE_BOTH_ACCESS_TOKEN_AND_CONSENT_CODE = '82903';
315
+ const PAYPAL_ACCOUNT_CANNOT_HAVE_FUNDING_SOURCE_WITHOUT_ACCESS_TOKEN = '92912';
316
+ const PAYPAL_ACCOUNT_CANNOT_UPDATE_PAYPAL_ACCOUNT_USING_PAYMENT_METHOD_NONCE = '92914';
317
+ const PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT = '82902';
318
+ const PAYPAL_ACCOUNT_CONSENT_CODE_OR_ACCESS_TOKEN_IS_REQUIRED = '82901';
319
+ const PAYPAL_ACCOUNT_CUSTOMER_ID_IS_REQUIRED_FOR_VAULTING = '82905';
320
+ const PAYPAL_ACCOUNT_INVALID_FUNDING_SOURCE_SELECTION = '92913';
321
+ const PAYPAL_ACCOUNT_INVALID_PARAMS_FOR_PAYPAL_ACCOUNT_UPDATE = '92915';
322
+ const PAYPAL_ACCOUNT_PAYMENT_METHOD_NONCE_CONSUMED = '92907';
323
+ const PAYPAL_ACCOUNT_PAYMENT_METHOD_NONCE_LOCKED = '92909';
324
+ const PAYPAL_ACCOUNT_PAYMENT_METHOD_NONCE_UNKNOWN = '92908';
325
+ const PAYPAL_ACCOUNT_PAYPAL_ACCOUNTS_ARE_NOT_ACCEPTED = '82904';
326
+ const PAYPAL_ACCOUNT_PAYPAL_COMMUNICATION_ERROR = '92910';
327
+ const PAYPAL_ACCOUNT_TOKEN_IS_IN_USE = '92906';
328
+
329
+ const SEPA_BANK_ACCOUNT_ACCOUNT_HOLDER_NAME_IS_REQUIRED = '93003';
330
+ const SEPA_BANK_ACCOUNT_BIC_IS_REQUIRED = '93002';
331
+ const SEPA_BANK_ACCOUNT_IBAN_IS_REQUIRED = '93001';
332
+
333
+ const SEPA_MANDATE_ACCOUNT_HOLDER_NAME_IS_REQUIRED = '83301';
334
+ const SEPA_MANDATE_BIC_INVALID_CHARACTER = '83306';
335
+ const SEPA_MANDATE_BIC_IS_REQUIRED = '83302';
336
+ const SEPA_MANDATE_BIC_LENGTH_IS_INVALID = '83307';
337
+ const SEPA_MANDATE_BIC_UNSUPPORTED_COUNTRY = '83308';
338
+ const SEPA_MANDATE_BILLING_ADDRESS_CONFLICT = '93311';
339
+ const SEPA_MANDATE_BILLING_ADDRESS_ID_IS_INVALID = '93312';
340
+ const SEPA_MANDATE_IBAN_INVALID_CHARACTER = '83305';
341
+ const SEPA_MANDATE_IBAN_INVALID_FORMAT = '83310';
342
+ const SEPA_MANDATE_IBAN_IS_REQUIRED = '83303';
343
+ const SEPA_MANDATE_IBAN_UNSUPPORTED_COUNTRY = '83309';
344
+ const SEPA_MANDATE_TYPE_IS_REQUIRED = '93304';
345
+ const SEPA_MANDATE_TYPE_IS_INVALID = '93313';
346
+
347
+ const SETTLEMENT_BATCH_SUMMARY_SETTLEMENT_DATE_IS_INVALID = '82302';
348
+ const SETTLEMENT_BATCH_SUMMARY_SETTLEMENT_DATE_IS_REQUIRED = '82301';
349
+ const SETTLEMENT_BATCH_SUMMARY_CUSTOM_FIELD_IS_INVALID = '82303';
350
+
351
+ const SUBSCRIPTION_BILLING_DAY_OF_MONTH_CANNOT_BE_UPDATED = '91918';
352
+ const SUBSCRIPTION_BILLING_DAY_OF_MONTH_IS_INVALID = '91914';
353
+ const SUBSCRIPTION_BILLING_DAY_OF_MONTH_MUST_BE_NUMERIC = '91913';
354
+ const SUBSCRIPTION_CANNOT_ADD_DUPLICATE_ADDON_OR_DISCOUNT = '91911';
355
+ const SUBSCRIPTION_CANNOT_EDIT_CANCELED_SUBSCRIPTION = '81901';
356
+ const SUBSCRIPTION_CANNOT_EDIT_EXPIRED_SUBSCRIPTION = '81910';
357
+ const SUBSCRIPTION_CANNOT_EDIT_PRICE_CHANGING_FIELDS_ON_PAST_DUE_SUBSCRIPTION = '91920';
358
+ const SUBSCRIPTION_FIRST_BILLING_DATE_CANNOT_BE_IN_THE_PAST = '91916';
359
+ const SUBSCRIPTION_FIRST_BILLING_DATE_CANNOT_BE_UPDATED = '91919';
360
+ const SUBSCRIPTION_FIRST_BILLING_DATE_IS_INVALID = '91915';
361
+ const SUBSCRIPTION_ID_IS_IN_USE = '81902';
362
+ const SUBSCRIPTION_INCONSISTENT_NUMBER_OF_BILLING_CYCLES = '91908';
363
+ const SUBSCRIPTION_INCONSISTENT_START_DATE = '91917';
364
+ const SUBSCRIPTION_INVALID_REQUEST_FORMAT = '91921';
365
+ const SUBSCRIPTION_MERCHANT_ACCOUNT_ID_IS_INVALID = '91901';
366
+ const SUBSCRIPTION_MISMATCH_CURRENCY_ISO_CODE = '91923';
367
+ const SUBSCRIPTION_NUMBER_OF_BILLING_CYCLES_CANNOT_BE_BLANK = '91912';
368
+ const SUBSCRIPTION_NUMBER_OF_BILLING_CYCLES_IS_TOO_SMALL = '91909';
369
+ const SUBSCRIPTION_NUMBER_OF_BILLING_CYCLES_MUST_BE_GREATER_THAN_ZERO = '91907';
370
+ const SUBSCRIPTION_NUMBER_OF_BILLING_CYCLES_MUST_BE_NUMERIC = '91906';
371
+ const SUBSCRIPTION_PAYMENT_METHOD_NONCE_CARD_TYPE_IS_NOT_ACCEPTED = '91924';
372
+ const SUBSCRIPTION_PAYMENT_METHOD_NONCE_IS_INVALID = '91925';
373
+ const SUBSCRIPTION_PAYMENT_METHOD_NONCE_NOT_ASSOCIATED_WITH_CUSTOMER = '91926';
374
+ const SUBSCRIPTION_PAYMENT_METHOD_NONCE_UNVAULTED_CARD_IS_NOT_ACCEPTED = '91927';
375
+ const SUBSCRIPTION_PAYMENT_METHOD_TOKEN_CARD_TYPE_IS_NOT_ACCEPTED = '91902';
376
+ const SUBSCRIPTION_PAYMENT_METHOD_TOKEN_IS_INVALID = '91903';
377
+ const SUBSCRIPTION_PAYMENT_METHOD_TOKEN_NOT_ASSOCIATED_WITH_CUSTOMER = '91905';
378
+ const SUBSCRIPTION_PLAN_BILLING_FREQUENCY_CANNOT_BE_UPDATED = '91922';
379
+ const SUBSCRIPTION_PLAN_ID_IS_INVALID = '91904';
380
+ const SUBSCRIPTION_PRICE_CANNOT_BE_BLANK = '81903';
381
+ const SUBSCRIPTION_PRICE_FORMAT_IS_INVALID = '81904';
382
+ const SUBSCRIPTION_PRICE_IS_TOO_LARGE = '81923';
383
+ const SUBSCRIPTION_STATUS_IS_CANCELED = '81905';
384
+ const SUBSCRIPTION_TOKEN_FORMAT_IS_INVALID = '81906';
385
+ const SUBSCRIPTION_TRIAL_DURATION_FORMAT_IS_INVALID = '81907';
386
+ const SUBSCRIPTION_TRIAL_DURATION_IS_REQUIRED = '81908';
387
+ const SUBSCRIPTION_TRIAL_DURATION_UNIT_IS_INVALID = '81909';
388
+ const SUBSCRIPTION_MERCHANT_ACCOUNT_DOES_NOT_SUPPORT_INSTRUMENT_TYPE = '91930';
389
+ const SUBSCRIPTION_PAYMENT_METHOD_NONCE_INSTRUMENT_TYPE_DOES_NOT_SUPPORT_SUBSCRIPTIONS = '91929';
390
+ const SUBSCRIPTION_PAYMENT_METHOD_TOKEN_INSTRUMENT_TYPE_DOES_NOT_SUPPORT_SUBSCRIPTIONS = '91928';
391
+
392
+ const SUBSCRIPTION_MODIFICATION_AMOUNT_CANNOT_BE_BLANK = '92003';
393
+ const SUBSCRIPTION_MODIFICATION_AMOUNT_IS_INVALID = '92002';
394
+ const SUBSCRIPTION_MODIFICATION_AMOUNT_IS_TOO_LARGE = '92023';
395
+ const SUBSCRIPTION_MODIFICATION_CANNOT_EDIT_MODIFICATIONS_ON_PAST_DUE_SUBSCRIPTION = '92022';
396
+ const SUBSCRIPTION_MODIFICATION_CANNOT_UPDATE_AND_REMOVE = '92015';
397
+ const SUBSCRIPTION_MODIFICATION_EXISTING_ID_IS_INCORRECT_KIND = '92020';
398
+ const SUBSCRIPTION_MODIFICATION_EXISTING_ID_IS_INVALID = '92011';
399
+ const SUBSCRIPTION_MODIFICATION_EXISTING_ID_IS_REQUIRED = '92012';
400
+ const SUBSCRIPTION_MODIFICATION_ID_TO_REMOVE_IS_INCORRECT_KIND = '92021';
401
+ const SUBSCRIPTION_MODIFICATION_ID_TO_REMOVE_IS_INVALID = '92025';
402
+ const SUBSCRIPTION_MODIFICATION_ID_TO_REMOVE_IS_NOT_PRESENT = '92016';
403
+ const SUBSCRIPTION_MODIFICATION_INCONSISTENT_NUMBER_OF_BILLING_CYCLES = '92018';
404
+ const SUBSCRIPTION_MODIFICATION_INHERITED_FROM_ID_IS_INVALID = '92013';
405
+ const SUBSCRIPTION_MODIFICATION_INHERITED_FROM_ID_IS_REQUIRED = '92014';
406
+ const SUBSCRIPTION_MODIFICATION_MISSING = '92024';
407
+ const SUBSCRIPTION_MODIFICATION_NUMBER_OF_BILLING_CYCLES_CANNOT_BE_BLANK = '92017';
408
+ const SUBSCRIPTION_MODIFICATION_NUMBER_OF_BILLING_CYCLES_IS_INVALID = '92005';
409
+ const SUBSCRIPTION_MODIFICATION_NUMBER_OF_BILLING_CYCLES_MUST_BE_GREATER_THAN_ZERO = '92019';
410
+ const SUBSCRIPTION_MODIFICATION_QUANTITY_CANNOT_BE_BLANK = '92004';
411
+ const SUBSCRIPTION_MODIFICATION_QUANTITY_IS_INVALID = '92001';
412
+ const SUBSCRIPTION_MODIFICATION_QUANTITY_MUST_BE_GREATER_THAN_ZERO = '92010';
413
+
414
+ const TRANSACTION_AMOUNT_CANNOT_BE_NEGATIVE = '81501';
415
+ const TRANSACTION_AMOUNT_DOES_NOT_MATCH3_D_SECURE_AMOUNT = '91585';
416
+ const TRANSACTION_AMOUNT_DOES_NOT_MATCH_IDEAL_PAYMENT_AMOUNT = '915144';
417
+ const TRANSACTION_AMOUNT_FORMAT_IS_INVALID = '81503';
418
+ const TRANSACTION_AMOUNT_IS_INVALID = '81503';
419
+ const TRANSACTION_AMOUNT_IS_REQUIRED = '81502';
420
+ const TRANSACTION_AMOUNT_IS_TOO_LARGE = '81528';
421
+ const TRANSACTION_AMOUNT_MUST_BE_GREATER_THAN_ZERO = '81531';
422
+ const TRANSACTION_BILLING_ADDRESS_CONFLICT = '91530';
423
+ const TRANSACTION_CANNOT_BE_VOIDED = '91504';
424
+ const TRANSACTION_CANNOT_CANCEL_RELEASE = '91562';
425
+ const TRANSACTION_CANNOT_CLONE_CREDIT = '91543';
426
+ const TRANSACTION_CANNOT_CLONE_MARKETPLACE_TRANSACTION = '915137';
427
+ const TRANSACTION_CANNOT_CLONE_TRANSACTION_WITH_PAYPAL_ACCOUNT = '91573';
428
+ const TRANSACTION_CANNOT_CLONE_TRANSACTION_WITH_VAULT_CREDIT_CARD = '91540';
429
+ const TRANSACTION_CANNOT_CLONE_UNSUCCESSFUL_TRANSACTION = '91542';
430
+ const TRANSACTION_CANNOT_CLONE_VOICE_AUTHORIZATIONS = '91541';
431
+ const TRANSACTION_CANNOT_HOLD_IN_ESCROW = '91560';
432
+ const TRANSACTION_CANNOT_PARTIALLY_REFUND_ESCROWED_TRANSACTION = '91563';
433
+ const TRANSACTION_CANNOT_REFUND_CREDIT = '91505';
434
+ const TRANSACTION_CANNOT_REFUND_SETTLING_TRANSACTION = '91574';
435
+ const TRANSACTION_CANNOT_REFUND_UNLESS_SETTLED = '91506';
436
+ const TRANSACTION_CANNOT_REFUND_WITH_PENDING_MERCHANT_ACCOUNT = '91559';
437
+ const TRANSACTION_CANNOT_REFUND_WITH_SUSPENDED_MERCHANT_ACCOUNT = '91538';
438
+ const TRANSACTION_CANNOT_RELEASE_FROM_ESCROW = '91561';
439
+ const TRANSACTION_CANNOT_SIMULATE_SETTLEMENT = '91575';
440
+ const TRANSACTION_CANNOT_SUBMIT_FOR_PARTIAL_SETTLEMENT = '915103';
441
+ const TRANSACTION_CANNOT_SUBMIT_FOR_SETTLEMENT = '91507';
442
+ const TRANSACTION_CANNOT_UPDATE_DETAILS_NOT_SUBMITTED_FOR_SETTLEMENT = '915129';
443
+ const TRANSACTION_CHANNEL_IS_TOO_LONG = '91550';
444
+ const TRANSACTION_CREDIT_CARD_IS_REQUIRED = '91508';
445
+ const TRANSACTION_CUSTOMER_DEFAULT_PAYMENT_METHOD_CARD_TYPE_IS_NOT_ACCEPTED = '81509';
446
+ const TRANSACTION_CUSTOMER_DOES_NOT_HAVE_CREDIT_CARD = '91511';
447
+ const TRANSACTION_CUSTOMER_ID_IS_INVALID = '91510';
448
+ const TRANSACTION_CUSTOM_FIELD_IS_INVALID = '91526';
449
+ const TRANSACTION_CUSTOM_FIELD_IS_TOO_LONG = '81527';
450
+ const TRANSACTION_HAS_ALREADY_BEEN_REFUNDED = '91512';
451
+ const TRANSACTION_IDEAL_PAYMENT_NOT_COMPLETE = '815141';
452
+ const TRANSACTION_MERCHANT_ACCOUNT_DOES_NOT_MATCH3_D_SECURE_MERCHANT_ACCOUNT = '91584';
453
+ const TRANSACTION_MERCHANT_ACCOUNT_DOES_NOT_MATCH_IDEAL_PAYMENT_MERCHANT_ACCOUNT = '915143';
454
+ const TRANSACTION_MERCHANT_ACCOUNT_DOES_NOT_SUPPORT_MOTO = '91558';
455
+ const TRANSACTION_MERCHANT_ACCOUNT_DOES_NOT_SUPPORT_REFUNDS = '91547';
456
+ const TRANSACTION_MERCHANT_ACCOUNT_ID_IS_INVALID = '91513';
457
+ const TRANSACTION_MERCHANT_ACCOUNT_IS_SUSPENDED = '91514';
458
+ const TRANSACTION_MERCHANT_ACCOUNT_NAME_IS_INVALID = '91513'; //Deprecated
459
+ const TRANSACTION_OPTIONS_PAY_PAL_CUSTOM_FIELD_TOO_LONG = '91580';
460
+ const TRANSACTION_OPTIONS_SUBMIT_FOR_SETTLEMENT_IS_REQUIRED_FOR_CLONING = '91544';
461
+ const TRANSACTION_OPTIONS_SUBMIT_FOR_SETTLEMENT_IS_REQUIRED_FOR_PAYPAL_UNILATERAL = '91582';
462
+ const TRANSACTION_OPTIONS_USE_BILLING_FOR_SHIPPING_DISABLED = '91572';
463
+ const TRANSACTION_OPTIONS_VAULT_IS_DISABLED = '91525';
464
+ const TRANSACTION_ORDER_ID_DOES_NOT_MATCH_IDEAL_PAYMENT_ORDER_ID = '91503';
465
+ const TRANSACTION_ORDER_ID_IS_REQUIRED_WITH_IDEAL_PAYMENT = '91502';
466
+ const TRANSACTION_ORDER_ID_IS_TOO_LONG = '91501';
467
+ const TRANSACTION_PAYMENT_INSTRUMENT_NOT_SUPPORTED_BY_MERCHANT_ACCOUNT = '91577';
468
+ const TRANSACTION_PAYMENT_INSTRUMENT_TYPE_IS_NOT_ACCEPTED = '915101';
469
+ const TRANSACTION_PAYMENT_METHOD_CONFLICT = '91515';
470
+ const TRANSACTION_PAYMENT_METHOD_CONFLICT_WITH_VENMO_SDK = '91549';
471
+ const TRANSACTION_PAYMENT_METHOD_DOES_NOT_BELONG_TO_CUSTOMER = '91516';
472
+ const TRANSACTION_PAYMENT_METHOD_DOES_NOT_BELONG_TO_SUBSCRIPTION = '91527';
473
+ const TRANSACTION_PAYMENT_METHOD_NONCE_CARD_TYPE_IS_NOT_ACCEPTED = '91567';
474
+ const TRANSACTION_PAYMENT_METHOD_NONCE_CONSUMED = '91564';
475
+ const TRANSACTION_PAYMENT_METHOD_NONCE_HAS_NO_VALID_PAYMENT_INSTRUMENT_TYPE = '91569';
476
+ const TRANSACTION_PAYMENT_METHOD_NONCE_LOCKED = '91566';
477
+ const TRANSACTION_PAYMENT_METHOD_NONCE_UNKNOWN = '91565';
478
+ const TRANSACTION_PAYMENT_METHOD_TOKEN_CARD_TYPE_IS_NOT_ACCEPTED = '91517';
479
+ const TRANSACTION_PAYMENT_METHOD_TOKEN_IS_INVALID = '91518';
480
+ const TRANSACTION_PAYPAL_NOT_ENABLED = '91576';
481
+ const TRANSACTION_PAY_PAL_AUTH_EXPIRED = '91579';
482
+ const TRANSACTION_PAY_PAL_VAULT_RECORD_MISSING_DATA = '91583';
483
+ const TRANSACTION_PROCESSOR_AUTHORIZATION_CODE_CANNOT_BE_SET = '91519';
484
+ const TRANSACTION_PROCESSOR_AUTHORIZATION_CODE_IS_INVALID = '81520';
485
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_AUTHS = '915104';
486
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_CREDITS = '91546';
487
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_PARTIAL_SETTLEMENT = '915102';
488
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_UPDATING_ORDER_ID = '915107';
489
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_UPDATING_DESCRIPTOR = '915108';
490
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_UPDATING_DETAILS = '915130';
491
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_VOICE_AUTHORIZATIONS = '91545';
492
+ const TRANSACTION_PURCHASE_ORDER_NUMBER_IS_INVALID = '91548';
493
+ const TRANSACTION_PURCHASE_ORDER_NUMBER_IS_TOO_LONG = '91537';
494
+ const TRANSACTION_REFUND_AMOUNT_IS_TOO_LARGE = '91521';
495
+ const TRANSACTION_SERVICE_FEE_AMOUNT_CANNOT_BE_NEGATIVE = '91554';
496
+ const TRANSACTION_SERVICE_FEE_AMOUNT_FORMAT_IS_INVALID = '91555';
497
+ const TRANSACTION_SERVICE_FEE_AMOUNT_IS_TOO_LARGE = '91556';
498
+ const TRANSACTION_SERVICE_FEE_AMOUNT_NOT_ALLOWED_ON_MASTER_MERCHANT_ACCOUNT = '91557';
499
+ const TRANSACTION_SERVICE_FEE_IS_NOT_ALLOWED_ON_CREDITS = '91552';
500
+ const TRANSACTION_SERVICE_FEE_NOT_ACCEPTED_FOR_PAYPAL = '91578';
501
+ const TRANSACTION_SETTLEMENT_AMOUNT_IS_LESS_THAN_SERVICE_FEE_AMOUNT = '91551';
502
+ const TRANSACTION_SETTLEMENT_AMOUNT_IS_TOO_LARGE = '91522';
503
+ const TRANSACTION_SHIPPING_ADDRESS_DOESNT_MATCH_CUSTOMER = '91581';
504
+ const TRANSACTION_SUBSCRIPTION_DOES_NOT_BELONG_TO_CUSTOMER = '91529';
505
+ const TRANSACTION_SUBSCRIPTION_ID_IS_INVALID = '91528';
506
+ const TRANSACTION_SUBSCRIPTION_STATUS_MUST_BE_PAST_DUE = '91531';
507
+ const TRANSACTION_SUB_MERCHANT_ACCOUNT_REQUIRES_SERVICE_FEE_AMOUNT = '91553';
508
+ const TRANSACTION_TAX_AMOUNT_CANNOT_BE_NEGATIVE = '81534';
509
+ const TRANSACTION_TAX_AMOUNT_FORMAT_IS_INVALID = '81535';
510
+ const TRANSACTION_TAX_AMOUNT_IS_TOO_LARGE = '81536';
511
+
512
+ const TRANSACTION_THREE_D_SECURE_AUTHENTICATION_FAILED = '81571';
513
+ const TRANSACTION_THREE_D_SECURE_TOKEN_IS_INVALID = '91568';
514
+ const TRANSACTION_THREE_D_SECURE_TRANSACTION_DATA_DOESNT_MATCH_VERIFY = '91570';
515
+ const TRANSACTION_THREE_D_SECURE_ECI_FLAG_IS_REQUIRED = '915113';
516
+ const TRANSACTION_THREE_D_SECURE_CAVV_IS_REQUIRED = '915116';
517
+ const TRANSACTION_THREE_D_SECURE_XID_IS_REQUIRED = '915115';
518
+ const TRANSACTION_THREE_D_SECURE_ECI_FLAG_IS_INVALID = '915114';
519
+ const TRANSACTION_THREE_D_SECURE_MERCHANT_ACCOUNT_DOES_NOT_SUPPORT_CARD_TYPE = '915131';
520
+ const TRANSACTION_TYPE_IS_INVALID = '91523';
521
+ const TRANSACTION_TYPE_IS_REQUIRED = '91524';
522
+ const TRANSACTION_UNSUPPORTED_VOICE_AUTHORIZATION = '91539';
523
+
524
+ const VERIFICATION_OPTIONS_AMOUNT_CANNOT_BE_NEGATIVE = '94201';
525
+ const VERIFICATION_OPTIONS_AMOUNT_FORMAT_IS_INVALID = '94202';
526
+ const VERIFICATION_OPTIONS_AMOUNT_IS_TOO_LARGE = '94207';
527
+ const VERIFICATION_OPTIONS_AMOUNT_NOT_SUPPORTED_BY_PROCESSOR = '94203';
528
+ const VERIFICATION_OPTIONS_MERCHANT_ACCOUNT_ID_IS_INVALID = '94204';
529
+ const VERIFICATION_OPTIONS_MERCHANT_ACCOUNT_IS_SUSPENDED = '94205';
530
+ const VERIFICATION_OPTIONS_MERCHANT_ACCOUNT_IS_FORBIDDEN = '94206';
531
+ const VERIFICATION_OPTIONS_MERCHANT_ACCOUNT_CANNOT_BE_SUB_MERCHANT_ACCOUNT = '94208';
532
+ }
533
+ class_alias('Braintree\Error\Codes', 'Braintree_Error_Codes');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Error/ErrorCollection.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Error;
3
+
4
+ use Braintree\Util;
5
+
6
+ /**
7
+ *
8
+ * Error handler
9
+ * Handles validation errors
10
+ *
11
+ * Contains a read-only property $error which is a ValidationErrorCollection
12
+ *
13
+ * @package Braintree
14
+ * @subpackage Errors
15
+ * @category Errors
16
+ *
17
+ * @property-read object $errors
18
+ */
19
+ class ErrorCollection implements \Countable
20
+ {
21
+ private $_errors;
22
+
23
+ public function __construct($errorData)
24
+ {
25
+ $this->_errors =
26
+ new ValidationErrorCollection($errorData);
27
+ }
28
+
29
+ /**
30
+ * Return count of items in collection
31
+ * Implements countable
32
+ *
33
+ * @return integer
34
+ */
35
+ public function count()
36
+ {
37
+ return $this->deepSize();
38
+ }
39
+
40
+ /**
41
+ * Returns all of the validation errors at all levels of nesting in a single, flat array.
42
+ */
43
+ public function deepAll()
44
+ {
45
+ return $this->_errors->deepAll();
46
+ }
47
+
48
+ /**
49
+ * Returns the total number of validation errors at all levels of nesting. For example,
50
+ *if creating a customer with a credit card and a billing address, and each of the customer,
51
+ * credit card, and billing address has 1 error, this method will return 3.
52
+ *
53
+ * @return int size
54
+ */
55
+ public function deepSize()
56
+ {
57
+ $size = $this->_errors->deepSize();
58
+ return $size;
59
+ }
60
+
61
+ /**
62
+ * return errors for the passed key name
63
+ *
64
+ * @param string $key
65
+ * @return mixed
66
+ */
67
+ public function forKey($key)
68
+ {
69
+ return $this->_errors->forKey($key);
70
+ }
71
+
72
+ /**
73
+ * return errors for the passed html field.
74
+ * For example, $result->errors->onHtmlField("transaction[customer][last_name]")
75
+ *
76
+ * @param string $field
77
+ * @return array
78
+ */
79
+ public function onHtmlField($field)
80
+ {
81
+ $pieces = preg_split("/[\[\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY);
82
+ $errors = $this;
83
+ foreach(array_slice($pieces, 0, -1) as $key) {
84
+ $errors = $errors->forKey(Util::delimiterToCamelCase($key));
85
+ if (!isset($errors)) { return []; }
86
+ }
87
+ $finalKey = Util::delimiterToCamelCase(end($pieces));
88
+ return $errors->onAttribute($finalKey);
89
+ }
90
+
91
+ /**
92
+ * Returns the errors at the given nesting level (see forKey) in a single, flat array:
93
+ *
94
+ * <code>
95
+ * $result = Customer::create(...);
96
+ * $customerErrors = $result->errors->forKey('customer')->shallowAll();
97
+ * </code>
98
+ */
99
+ public function shallowAll()
100
+ {
101
+ return $this->_errors->shallowAll();
102
+ }
103
+
104
+ /**
105
+ *
106
+ * @ignore
107
+ */
108
+ public function __get($name)
109
+ {
110
+ $varName = "_$name";
111
+ return isset($this->$varName) ? $this->$varName : null;
112
+ }
113
+
114
+ /**
115
+ *
116
+ * @ignore
117
+ */
118
+ public function __toString()
119
+ {
120
+ return sprintf('%s', $this->_errors);
121
+ }
122
+ }
123
+ class_alias('Braintree\Error\ErrorCollection', 'Braintree_Error_ErrorCollection');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Error/Validation.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Error;
3
+
4
+ use Braintree\Util;
5
+
6
+ /**
7
+ * error object returned as part of a validation error collection
8
+ * provides read-only access to $attribute, $code, and $message
9
+ *
10
+ * <b>== More information ==</b>
11
+ *
12
+ * For more detailed information on Validation errors, see {@link http://www.braintreepayments.com/gateway/validation-errors http://www.braintreepaymentsolutions.com/gateway/validation-errors}
13
+ *
14
+ * @package Braintree
15
+ * @subpackage Error
16
+ *
17
+ * @property-read string $attribute
18
+ * @property-read string $code
19
+ * @property-read string $message
20
+ */
21
+ class Validation
22
+ {
23
+ private $_attribute;
24
+ private $_code;
25
+ private $_message;
26
+
27
+ /**
28
+ * @ignore
29
+ * @param array $attributes
30
+ */
31
+ public function __construct($attributes)
32
+ {
33
+ $this->_initializeFromArray($attributes);
34
+ }
35
+ /**
36
+ * initializes instance properties from the keys/values of an array
37
+ * @ignore
38
+ * @access protected
39
+ * @param array $attributes array of properties to set - single level
40
+ * @return void
41
+ */
42
+ private function _initializeFromArray($attributes)
43
+ {
44
+ foreach($attributes AS $name => $value) {
45
+ $varName = "_$name";
46
+ $this->$varName = Util::delimiterToCamelCase($value, '_');
47
+ }
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @ignore
53
+ */
54
+ public function __get($name)
55
+ {
56
+ $varName = "_$name";
57
+ return isset($this->$varName) ? $this->$varName : null;
58
+ }
59
+ }
60
+ class_alias('Braintree\Error\Validation', 'Braintree_Error_Validation');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Error/ValidationErrorCollection.php ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Error;
3
+
4
+ use Braintree\Collection;
5
+
6
+ /**
7
+ * collection of errors enumerating all validation errors for a given request
8
+ *
9
+ * <b>== More information ==</b>
10
+ *
11
+ * For more detailed information on Validation errors, see {@link http://www.braintreepayments.com/gateway/validation-errors http://www.braintreepaymentsolutions.com/gateway/validation-errors}
12
+ *
13
+ * @package Braintree
14
+ * @subpackage Error
15
+ *
16
+ * @property-read array $errors
17
+ * @property-read array $nested
18
+ */
19
+ class ValidationErrorCollection extends Collection
20
+ {
21
+ private $_errors = [];
22
+ private $_nested = [];
23
+
24
+ /**
25
+ * @ignore
26
+ */
27
+ public function __construct($data)
28
+ {
29
+ foreach($data AS $key => $errorData)
30
+ // map errors to new collections recursively
31
+ if ($key == 'errors') {
32
+ foreach ($errorData AS $error) {
33
+ $this->_errors[] = new Validation($error);
34
+ }
35
+ } else {
36
+ $this->_nested[$key] = new ValidationErrorCollection($errorData);
37
+ }
38
+
39
+ }
40
+
41
+ public function deepAll()
42
+ {
43
+ $validationErrors = array_merge([], $this->_errors);
44
+ foreach($this->_nested as $nestedErrors)
45
+ {
46
+ $validationErrors = array_merge($validationErrors, $nestedErrors->deepAll());
47
+ }
48
+ return $validationErrors;
49
+ }
50
+
51
+ public function deepSize()
52
+ {
53
+ $total = sizeof($this->_errors);
54
+ foreach($this->_nested as $_nestedErrors)
55
+ {
56
+ $total = $total + $_nestedErrors->deepSize();
57
+ }
58
+ return $total;
59
+ }
60
+
61
+ public function forIndex($index)
62
+ {
63
+ return $this->forKey("index" . $index);
64
+ }
65
+
66
+ public function forKey($key)
67
+ {
68
+ return isset($this->_nested[$key]) ? $this->_nested[$key] : null;
69
+ }
70
+
71
+ public function onAttribute($attribute)
72
+ {
73
+ $matches = [];
74
+ foreach ($this->_errors AS $key => $error) {
75
+ if($error->attribute == $attribute) {
76
+ $matches[] = $error;
77
+ }
78
+ }
79
+ return $matches;
80
+ }
81
+
82
+
83
+ public function shallowAll()
84
+ {
85
+ return $this->_errors;
86
+ }
87
+
88
+ /**
89
+ *
90
+ * @ignore
91
+ */
92
+ public function __get($name)
93
+ {
94
+ $varName = "_$name";
95
+ return isset($this->$varName) ? $this->$varName : null;
96
+ }
97
+
98
+ /**
99
+ * @ignore
100
+ */
101
+ public function __toString()
102
+ {
103
+ $output = [];
104
+
105
+ // TODO: implement scope
106
+ if (!empty($this->_errors)) {
107
+ $output[] = $this->_inspect($this->_errors);
108
+ }
109
+ if (!empty($this->_nested)) {
110
+ foreach ($this->_nested AS $key => $values) {
111
+ $output[] = $this->_inspect($this->_nested);
112
+ }
113
+ }
114
+ return join(', ', $output);
115
+ }
116
+
117
+ /**
118
+ * @ignore
119
+ */
120
+ private function _inspect($errors, $scope = null)
121
+ {
122
+ $eOutput = '[' . __CLASS__ . '/errors:[';
123
+ foreach($errors AS $error => $errorObj) {
124
+ $outputErrs[] = "({$errorObj->error['code']} {$errorObj->error['message']})";
125
+ }
126
+ $eOutput .= join(', ', $outputErrs) . ']]';
127
+
128
+ return $eOutput;
129
+ }
130
+ }
131
+ class_alias('Braintree\Error\ValidationErrorCollection', 'Braintree_Error_ValidationErrorCollection');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/EuropeBankAccount.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree EuropeBankAccount module
6
+ * Creates and manages Braintree Europe Bank Accounts
7
+ *
8
+ * <b>== More information ==</b>
9
+ *
10
+ * See {@link https://developers.braintreepayments.com/javascript+php}<br />
11
+ *
12
+ * @package Braintree
13
+ * @category Resources
14
+ *
15
+ * @property-read string $account-holder-name
16
+ * @property-read string $bic
17
+ * @property-read string $customerId
18
+ * @property-read string $default
19
+ * @property-read string $image-url
20
+ * @property-read string $mandate-reference-number
21
+ * @property-read string $masked-iban
22
+ * @property-read string $token
23
+ */
24
+ class EuropeBankAccount extends Base
25
+ {
26
+
27
+ /* instance methods */
28
+ /**
29
+ * returns false if default is null or false
30
+ *
31
+ * @return boolean
32
+ */
33
+ public function isDefault()
34
+ {
35
+ return $this->default;
36
+ }
37
+
38
+ /**
39
+ * factory method: returns an instance of EuropeBankAccount
40
+ * to the requesting method, with populated properties
41
+ *
42
+ * @ignore
43
+ * @return EuropeBankAccount
44
+ */
45
+ public static function factory($attributes)
46
+ {
47
+ $defaultAttributes = [
48
+ ];
49
+
50
+ $instance = new self();
51
+ $instance->_initialize(array_merge($defaultAttributes, $attributes));
52
+ return $instance;
53
+ }
54
+
55
+ /**
56
+ * sets instance properties from an array of values
57
+ *
58
+ * @access protected
59
+ * @param array $europeBankAccountAttribs array of EuropeBankAccount properties
60
+ * @return void
61
+ */
62
+ protected function _initialize($europeBankAccountAttribs)
63
+ {
64
+ $this->_attributes = $europeBankAccountAttribs;
65
+ }
66
+ }
67
+ class_alias('Braintree\EuropeBankAccount', 'Braintree_EuropeBankAccount');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * super class for all Braintree exceptions
6
+ *
7
+ * @package Braintree
8
+ * @subpackage Exception
9
+ */
10
+ class Exception extends \Exception
11
+ {
12
+ }
13
+ class_alias('Braintree\Exception', 'Braintree_Exception');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Authentication.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when authentication fails.
8
+ * This may be caused by an incorrect Configuration
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Exception
12
+ */
13
+ class Authentication extends Exception
14
+ {
15
+
16
+ }
17
+ class_alias('Braintree\Exception\Authentication', 'Braintree_Exception_Authentication');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Authorization.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when authorization fails
8
+ * Raised when the API key being used is not authorized to perform
9
+ * the attempted action according to the roles assigned to the user
10
+ * who owns the API key.
11
+ *
12
+ * @package Braintree
13
+ * @subpackage Exception
14
+ */
15
+ class Authorization extends Exception
16
+ {
17
+
18
+ }
19
+ class_alias('Braintree\Exception\Authorization', 'Braintree_Exception_Authorization');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Configuration.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when the Braintree library is not completely configured.
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ * @see Configuration
12
+ */
13
+ class Configuration extends Exception
14
+ {
15
+
16
+ }
17
+ class_alias('Braintree\Exception\Configuration', 'Braintree_Exception_Configuration');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Connection.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when the connection fails
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
+ */
13
+ class Connection extends Exception
14
+ {
15
+
16
+ }
17
+ class_alias('Braintree\Exception\Connection', 'Braintree_Exception_Connection');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/DownForMaintenance.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when the gateway is down for maintenance.
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ */
12
+ class DownForMaintenance extends Exception
13
+ {
14
+
15
+ }
16
+ class_alias('Braintree\Exception\DownForMaintenance', 'Braintree_Exception_DownForMaintenance');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/ForgedQueryString.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when a suspected forged query string is present
8
+ * Raised from methods that confirm transparent redirect requests
9
+ * when the given query string cannot be verified. This may indicate
10
+ * an attempted hack on the merchant's transparent redirect
11
+ * confirmation URL.
12
+ *
13
+ * @package Braintree
14
+ * @subpackage Exception
15
+ */
16
+ class ForgedQueryString extends Exception
17
+ {
18
+
19
+ }
20
+ class_alias('Braintree\Exception\ForgedQueryString', 'Braintree_Exception_ForgedQueryString');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/InvalidChallenge.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ class InvalidChallenge extends Exception
7
+ {
8
+ }
9
+ class_alias('Braintree\Exception\InvalidChallenge', 'Braintree_Exception_InvalidChallenge');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/InvalidSignature.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ class InvalidSignature extends Exception
7
+ {
8
+ }
9
+ class_alias('Braintree\Exception\InvalidSignature', 'Braintree_Exception_InvalidSignature');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/NotFound.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when a record could not be found.
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ */
12
+ class NotFound extends Exception
13
+ {
14
+
15
+ }
16
+ class_alias('Braintree\Exception\NotFound', 'Braintree_Exception_NotFound');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/SSLCaFileNotFound.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when the SSL CaFile is not found.
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ */
12
+ class SSLCaFileNotFound extends Exception
13
+ {
14
+
15
+ }
16
+ class_alias('Braintree\Exception\SSLCaFileNotFound', 'Braintree_Exception_SSLCaFileNotFound');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/SSLCertificate.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when the SSL certificate fails verification.
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ */
12
+ class SSLCertificate extends Exception
13
+ {
14
+
15
+ }
16
+ class_alias('Braintree\Exception\SSLCertificate', 'Braintree_Exception_SSLCertificate');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/ServerError.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when an unexpected server error occurs.
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ */
12
+ class ServerError extends Exception
13
+ {
14
+
15
+ }
16
+ class_alias('Braintree\Exception\ServerError', 'Braintree_Exception_ServerError');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/TestOperationPerformedInProduction.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when a test method is used in production.
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ */
12
+ class TestOperationPerformedInProduction extends Exception
13
+ {
14
+ }
15
+ class_alias('Braintree\Exception\TestOperationPerformedInProduction', 'Braintree_Exception_TestOperationPerformedInProduction');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Timeout.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when a Timeout occurs
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ */
12
+ class Timeout extends Exception
13
+ {
14
+
15
+ }
16
+ class_alias('Braintree\Exception\Timeout', 'Braintree_Exception_Timeout');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/TooManyRequests.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when the gateway request rate-limit is exceeded.
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ */
12
+ class TooManyRequests extends Exception
13
+ {
14
+
15
+ }
16
+ class_alias('Braintree\Exception\TooManyRequests', 'Braintree_Exception_TooManyRequests');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/Unexpected.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when an error occurs that the client library is not built to handle.
8
+ * This shouldn't happen.
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Exception
12
+ */
13
+ class Unexpected extends Exception
14
+ {
15
+
16
+ }
17
+ class_alias('Braintree\Exception\Unexpected', 'Braintree_Exception_Unexpected');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/UpgradeRequired.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised when a client library must be upgraded.
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ */
12
+ class UpgradeRequired extends Exception
13
+ {
14
+
15
+ }
16
+ class_alias('Braintree\Exception\UpgradeRequired', 'Braintree_Exception_UpgradeRequired');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Exception/ValidationsFailed.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Exception;
3
+
4
+ use Braintree\Exception;
5
+
6
+ /**
7
+ * Raised from non-validating methods when gateway validations fail.
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Exception
11
+ */
12
+ class ValidationsFailed extends Exception
13
+ {
14
+
15
+ }
16
+ class_alias('Braintree\Exception\ValidationsFailed', 'Braintree_Exception_ValidationsFailed');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/FacilitatorDetails.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class FacilitatorDetails extends Base
5
+ {
6
+ public static function factory($attributes)
7
+ {
8
+ $instance = new self();
9
+ $instance->_initialize($attributes);
10
+
11
+ return $instance;
12
+ }
13
+
14
+ protected function _initialize($attributes)
15
+ {
16
+ $this->_attributes = $attributes;
17
+ }
18
+
19
+ /**
20
+ * returns a string representation of the three d secure info
21
+ * @return string
22
+ */
23
+ public function __toString()
24
+ {
25
+ return __CLASS__ . '[' .
26
+ Util::attributesToString($this->_attributes) .']';
27
+ }
28
+
29
+ }
30
+ class_alias('Braintree\FacilitatorDetails', 'Braintree_FacilitatorDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Gateway.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree Gateway module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+ class Gateway
11
+ {
12
+ /**
13
+ *
14
+ * @var Configuration
15
+ */
16
+ public $config;
17
+
18
+ public function __construct($config)
19
+ {
20
+ if (is_array($config)) {
21
+ $config = new Configuration($config);
22
+ }
23
+ $this->config = $config;
24
+ }
25
+
26
+ /**
27
+ *
28
+ * @return AddOnGateway
29
+ */
30
+ public function addOn()
31
+ {
32
+ return new AddOnGateway($this);
33
+ }
34
+
35
+ /**
36
+ *
37
+ * @return AddressGateway
38
+ */
39
+ public function address()
40
+ {
41
+ return new AddressGateway($this);
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @return ClientTokenGateway
47
+ */
48
+ public function clientToken()
49
+ {
50
+ return new ClientTokenGateway($this);
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @return CreditCardGateway
56
+ */
57
+ public function creditCard()
58
+ {
59
+ return new CreditCardGateway($this);
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @return CreditCardVerificationGateway
65
+ */
66
+ public function creditCardVerification()
67
+ {
68
+ return new CreditCardVerificationGateway($this);
69
+ }
70
+
71
+ /**
72
+ *
73
+ * @return CustomerGateway
74
+ */
75
+ public function customer()
76
+ {
77
+ return new CustomerGateway($this);
78
+ }
79
+
80
+ /**
81
+ *
82
+ * @return DiscountGateway
83
+ */
84
+ public function discount()
85
+ {
86
+ return new DiscountGateway($this);
87
+ }
88
+
89
+ /**
90
+ *
91
+ * @return MerchantGateway
92
+ */
93
+ public function merchant()
94
+ {
95
+ return new MerchantGateway($this);
96
+ }
97
+
98
+ /**
99
+ *
100
+ * @return MerchantAccountGateway
101
+ */
102
+ public function merchantAccount()
103
+ {
104
+ return new MerchantAccountGateway($this);
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @return OAuthGateway
110
+ */
111
+ public function oauth()
112
+ {
113
+ return new OAuthGateway($this);
114
+ }
115
+
116
+ /**
117
+ *
118
+ * @return PaymentMethodGateway
119
+ */
120
+ public function paymentMethod()
121
+ {
122
+ return new PaymentMethodGateway($this);
123
+ }
124
+
125
+ /**
126
+ *
127
+ * @return PaymentMethodNonceGateway
128
+ */
129
+ public function paymentMethodNonce()
130
+ {
131
+ return new PaymentMethodNonceGateway($this);
132
+ }
133
+
134
+ /**
135
+ *
136
+ * @return PayPalAccountGateway
137
+ */
138
+ public function payPalAccount()
139
+ {
140
+ return new PayPalAccountGateway($this);
141
+ }
142
+
143
+ /**
144
+ *
145
+ * @return PlanGateway
146
+ */
147
+ public function plan()
148
+ {
149
+ return new PlanGateway($this);
150
+ }
151
+
152
+ /**
153
+ *
154
+ * @return SettlementBatchSummaryGateway
155
+ */
156
+ public function settlementBatchSummary()
157
+ {
158
+ return new SettlementBatchSummaryGateway($this);
159
+ }
160
+
161
+ /**
162
+ *
163
+ * @return SubscriptionGateway
164
+ */
165
+ public function subscription()
166
+ {
167
+ return new SubscriptionGateway($this);
168
+ }
169
+
170
+ /**
171
+ *
172
+ * @return TestingGateway
173
+ */
174
+ public function testing()
175
+ {
176
+ return new TestingGateway($this);
177
+ }
178
+
179
+ /**
180
+ *
181
+ * @return TransactionGateway
182
+ */
183
+ public function transaction()
184
+ {
185
+ return new TransactionGateway($this);
186
+ }
187
+
188
+ /**
189
+ *
190
+ * @return TransparentRedirectGateway
191
+ */
192
+ public function transparentRedirect()
193
+ {
194
+ return new TransparentRedirectGateway($this);
195
+ }
196
+
197
+ /**
198
+ *
199
+ * @return UsBankAccountGateway
200
+ */
201
+ public function usBankAccount()
202
+ {
203
+ return new UsBankAccountGateway($this);
204
+ }
205
+
206
+ /**
207
+ *
208
+ * @return IdealPaymentGateway
209
+ */
210
+ public function idealPayment()
211
+ {
212
+ return new IdealPaymentGateway($this);
213
+ }
214
+
215
+ /**
216
+ *
217
+ * @return WebhookNotificationGateway
218
+ */
219
+ public function webhookNotification()
220
+ {
221
+ return new WebhookNotificationGateway($this);
222
+ }
223
+ }
224
+ class_alias('Braintree\Gateway', 'Braintree_Gateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Http.php ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree HTTP Client
6
+ * processes Http requests using curl
7
+ */
8
+ class Http
9
+ {
10
+ protected $_config;
11
+ private $_useClientCredentials = false;
12
+
13
+ public function __construct($config)
14
+ {
15
+ $this->_config = $config;
16
+ }
17
+
18
+ public function delete($path)
19
+ {
20
+ $response = $this->_doRequest('DELETE', $path);
21
+ if ($response['status'] === 200) {
22
+ return true;
23
+ } else {
24
+ Util::throwStatusCodeException($response['status']);
25
+ }
26
+ }
27
+
28
+ public function get($path)
29
+ {
30
+ $response = $this->_doRequest('GET', $path);
31
+ if ($response['status'] === 200) {
32
+ return Xml::buildArrayFromXml($response['body']);
33
+ } else {
34
+ Util::throwStatusCodeException($response['status']);
35
+ }
36
+ }
37
+
38
+ public function post($path, $params = null)
39
+ {
40
+ $response = $this->_doRequest('POST', $path, $this->_buildXml($params));
41
+ $responseCode = $response['status'];
42
+ if ($responseCode === 200 || $responseCode === 201 || $responseCode === 422 || $responseCode == 400) {
43
+ return Xml::buildArrayFromXml($response['body']);
44
+ } else {
45
+ Util::throwStatusCodeException($responseCode);
46
+ }
47
+ }
48
+
49
+ public function put($path, $params = null)
50
+ {
51
+ $response = $this->_doRequest('PUT', $path, $this->_buildXml($params));
52
+ $responseCode = $response['status'];
53
+ if ($responseCode === 200 || $responseCode === 201 || $responseCode === 422 || $responseCode == 400) {
54
+ return Xml::buildArrayFromXml($response['body']);
55
+ } else {
56
+ Util::throwStatusCodeException($responseCode);
57
+ }
58
+ }
59
+
60
+ private function _buildXml($params)
61
+ {
62
+ return empty($params) ? null : Xml::buildXmlFromArray($params);
63
+ }
64
+
65
+ private function _getHeaders()
66
+ {
67
+ return [
68
+ 'Accept: application/xml',
69
+ 'Content-Type: application/xml',
70
+ ];
71
+ }
72
+
73
+ private function _getAuthorization()
74
+ {
75
+ if ($this->_useClientCredentials) {
76
+ return [
77
+ 'user' => $this->_config->getClientId(),
78
+ 'password' => $this->_config->getClientSecret(),
79
+ ];
80
+ } else if ($this->_config->isAccessToken()) {
81
+ return [
82
+ 'token' => $this->_config->getAccessToken(),
83
+ ];
84
+ } else {
85
+ return [
86
+ 'user' => $this->_config->getPublicKey(),
87
+ 'password' => $this->_config->getPrivateKey(),
88
+ ];
89
+ }
90
+ }
91
+
92
+ public function useClientCredentials()
93
+ {
94
+ $this->_useClientCredentials = true;
95
+ }
96
+
97
+ private function _doRequest($httpVerb, $path, $requestBody = null)
98
+ {
99
+ return $this->_doUrlRequest($httpVerb, $this->_config->baseUrl() . $path, $requestBody);
100
+ }
101
+
102
+ public function _doUrlRequest($httpVerb, $url, $requestBody = null)
103
+ {
104
+ $curl = curl_init();
105
+ curl_setopt($curl, CURLOPT_TIMEOUT, $this->_config->timeout());
106
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpVerb);
107
+ curl_setopt($curl, CURLOPT_URL, $url);
108
+
109
+ if ($this->_config->acceptGzipEncoding()) {
110
+ curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
111
+ }
112
+ if ($this->_config->sslVersion()) {
113
+ curl_setopt($curl, CURLOPT_SSLVERSION, $this->_config->sslVersion());
114
+ }
115
+
116
+ $headers = $this->_getHeaders($curl);
117
+ $headers[] = 'User-Agent: Braintree PHP Library ' . Version::get();
118
+ $headers[] = 'X-ApiVersion: ' . Configuration::API_VERSION;
119
+
120
+ $authorization = $this->_getAuthorization();
121
+ if (isset($authorization['user'])) {
122
+ curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
123
+ curl_setopt($curl, CURLOPT_USERPWD, $authorization['user'] . ':' . $authorization['password']);
124
+ } else if (isset($authorization['token'])) {
125
+ $headers[] = 'Authorization: Bearer ' . $authorization['token'];
126
+ }
127
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
128
+
129
+ // curl_setopt($curl, CURLOPT_VERBOSE, true);
130
+ if ($this->_config->sslOn()) {
131
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
132
+ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
133
+ curl_setopt($curl, CURLOPT_CAINFO, $this->getCaFile());
134
+ }
135
+
136
+ if (!empty($requestBody)) {
137
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
138
+ }
139
+
140
+ if ($this->_config->isUsingProxy()) {
141
+ $proxyHost = $this->_config->getProxyHost();
142
+ $proxyPort = $this->_config->getProxyPort();
143
+ $proxyType = $this->_config->getProxyType();
144
+ $proxyUser = $this->_config->getProxyUser();
145
+ $proxyPwd= $this->_config->getProxyPassword();
146
+ curl_setopt($curl, CURLOPT_PROXY, $proxyHost . ':' . $proxyPort);
147
+ if (!empty($proxyType)) {
148
+ curl_setopt($curl, CURLOPT_PROXYTYPE, $proxyType);
149
+ }
150
+ if ($this->_config->isAuthenticatedProxy()) {
151
+ curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyUser . ':' . $proxyPwd);
152
+ }
153
+ }
154
+
155
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
156
+ $response = curl_exec($curl);
157
+ $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
158
+ $error_code = curl_errno($curl);
159
+ $error = curl_error($curl);
160
+
161
+ if ($error_code == 28 && $httpStatus == 0) {
162
+ throw new Exception\Timeout();
163
+ }
164
+
165
+ curl_close($curl);
166
+ if ($this->_config->sslOn()) {
167
+ if ($httpStatus == 0) {
168
+ throw new Exception\SSLCertificate($error, $error_code);
169
+ }
170
+ } else if ($error_code) {
171
+ throw new Exception\Connection($error, $error_code);
172
+ }
173
+
174
+ return ['status' => $httpStatus, 'body' => $response];
175
+ }
176
+
177
+ private function getCaFile()
178
+ {
179
+ static $memo;
180
+
181
+ if ($memo === null) {
182
+ $caFile = $this->_config->caFile();
183
+
184
+ if (substr($caFile, 0, 7) !== 'phar://') {
185
+ return $caFile;
186
+ }
187
+
188
+ $extractedCaFile = sys_get_temp_dir() . '/api_braintreegateway_com.ca.crt';
189
+
190
+ if (!file_exists($extractedCaFile) || sha1_file($extractedCaFile) != sha1_file($caFile)) {
191
+ if (!copy($caFile, $extractedCaFile)) {
192
+ throw new Exception\SSLCaFileNotFound();
193
+ }
194
+ }
195
+ $memo = $extractedCaFile;
196
+ }
197
+
198
+ return $memo;
199
+ }
200
+ }
201
+ class_alias('Braintree\Http', 'Braintree_Http');
202
+
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/IbanBankAccount.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree IbanBankAccount module
6
+ * PHP Version 5
7
+ *
8
+ * @package Braintree
9
+ *
10
+ * @property-read string $maskedIban
11
+ * @property-read string $bic
12
+ * @property-read string $ibanCountry
13
+ * @property-read string $description
14
+ * @property-read string $ibanAccountNumberLast4
15
+ */
16
+ class IbanBankAccount extends Base
17
+ {
18
+ /**
19
+ * create a printable representation of the object as:
20
+ * ClassName[property=value, property=value]
21
+ * @ignore
22
+ * @return string
23
+ */
24
+ public function __toString()
25
+ {
26
+ return __CLASS__ . '[' .
27
+ Util::attributesToString($this->_attributes) . ']';
28
+ }
29
+
30
+ /**
31
+ * sets instance properties from an array of values
32
+ *
33
+ * @ignore
34
+ * @access protected
35
+ * @param array $ibanAttribs array of ibanBankAccount data
36
+ * @return void
37
+ */
38
+ protected function _initialize($ibanAttribs)
39
+ {
40
+ // set the attributes
41
+ $this->_attributes = $ibanAttribs;
42
+ }
43
+
44
+ /**
45
+ * factory method: returns an instance of IbanBankAccount
46
+ * to the requesting method, with populated properties
47
+ * @ignore
48
+ * @return IbanBankAccount
49
+ */
50
+ public static function factory($attributes)
51
+ {
52
+ $instance = new self();
53
+ $instance->_initialize($attributes);
54
+ return $instance;
55
+ }
56
+ }
57
+ class_alias('Braintree\IbanBankAccount', 'Braintree_IbanBankAccount');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/IdealPayment.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree IdealPayment module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+
11
+ /**
12
+ * Manages Braintree IdealPayments
13
+ *
14
+ * <b>== More information ==</b>
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @category Resources
19
+ *
20
+ * @property-read string $id
21
+ * @property-read string $idealTransactionId
22
+ * @property-read string $currency
23
+ * @property-read string $amount
24
+ * @property-read string $status
25
+ * @property-read string $orderId
26
+ * @property-read string $issuer
27
+ * @property-read string $ibanBankAccount
28
+ */
29
+ class IdealPayment extends Base
30
+ {
31
+ /**
32
+ * factory method: returns an instance of IdealPayment
33
+ * to the requesting method, with populated properties
34
+ *
35
+ * @ignore
36
+ * @return IdealPayment
37
+ */
38
+ public static function factory($attributes)
39
+ {
40
+ $instance = new self();
41
+ $instance->_initialize($attributes);
42
+ return $instance;
43
+ }
44
+
45
+ /* instance methods */
46
+
47
+ /**
48
+ * sets instance properties from an array of values
49
+ *
50
+ * @access protected
51
+ * @param array $idealPaymentAttribs array of idealPayment data
52
+ * @return void
53
+ */
54
+ protected function _initialize($idealPaymentAttribs)
55
+ {
56
+ // set the attributes
57
+ $this->_attributes = $idealPaymentAttribs;
58
+
59
+ $ibanBankAccount = isset($idealPaymentAttribs['ibanBankAccount']) ?
60
+ IbanBankAccount::factory($idealPaymentAttribs['ibanBankAccount']) :
61
+ null;
62
+ $this->_set('ibanBankAccount', $ibanBankAccount);
63
+ }
64
+
65
+ /**
66
+ * create a printable representation of the object as:
67
+ * ClassName[property=value, property=value]
68
+ * @return string
69
+ */
70
+ public function __toString()
71
+ {
72
+ return __CLASS__ . '[' .
73
+ Util::attributesToString($this->_attributes) . ']';
74
+ }
75
+
76
+
77
+ // static methods redirecting to gateway
78
+
79
+ public static function find($idealPaymentId)
80
+ {
81
+ return Configuration::gateway()->idealPayment()->find($idealPaymentId);
82
+ }
83
+
84
+ public static function sale($idealPaymentId, $transactionAttribs)
85
+ {
86
+ $transactionAttribs['options'] = [
87
+ 'submitForSettlement' => true
88
+ ];
89
+ return Configuration::gateway()->idealPayment()->sale($idealPaymentId, $transactionAttribs);
90
+ }
91
+ }
92
+ class_alias('Braintree\IdealPayment', 'Braintree_IdealPayment');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/IdealPaymentGateway.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ /**
7
+ * Braintree IdealPaymentGateway module
8
+ *
9
+ * @package Braintree
10
+ * @category Resources
11
+ */
12
+
13
+ /**
14
+ * Manages Braintree IdealPayments
15
+ *
16
+ * <b>== More information ==</b>
17
+ *
18
+ *
19
+ * @package Braintree
20
+ * @category Resources
21
+ */
22
+ class IdealPaymentGateway
23
+ {
24
+ private $_gateway;
25
+ private $_config;
26
+ private $_http;
27
+
28
+ public function __construct($gateway)
29
+ {
30
+ $this->_gateway = $gateway;
31
+ $this->_config = $gateway->config;
32
+ $this->_config->assertHasAccessTokenOrKeys();
33
+ $this->_http = new Http($gateway->config);
34
+ }
35
+
36
+ /**
37
+ * find an IdealPayment by id
38
+ *
39
+ * @access public
40
+ * @param string $idealPaymentId
41
+ * @return IdealPayment
42
+ * @throws Exception\NotFound
43
+ */
44
+ public function find($idealPaymentId)
45
+ {
46
+ try {
47
+ $path = $this->_config->merchantPath() . '/ideal_payments/' . $idealPaymentId;
48
+ $response = $this->_http->get($path);
49
+ return IdealPayment::factory($response['idealPayment']);
50
+ } catch (Exception\NotFound $e) {
51
+ throw new Exception\NotFound(
52
+ 'iDEAL Payment with id ' . $idealPaymentId . ' not found'
53
+ );
54
+ }
55
+ }
56
+
57
+ /**
58
+ * create a new sale for the current IdealPayment
59
+ *
60
+ * @param string $idealPaymentId
61
+ * @param array $transactionAttribs
62
+ * @return Result\Successful|Result\Error
63
+ * @see Transaction::sale()
64
+ */
65
+ public function sale($idealPaymentId, $transactionAttribs)
66
+ {
67
+ return Transaction::sale(
68
+ array_merge(
69
+ $transactionAttribs,
70
+ ['paymentMethodNonce' => $idealPaymentId]
71
+ )
72
+ );
73
+ }
74
+
75
+ /**
76
+ * generic method for validating incoming gateway responses
77
+ *
78
+ * creates a new IdealPayment object and encapsulates
79
+ * it inside a Result\Successful object, or
80
+ * encapsulates a Errors object inside a Result\Error
81
+ * alternatively, throws an Unexpected exception if the response is invalid.
82
+ *
83
+ * @ignore
84
+ * @param array $response gateway response values
85
+ * @return Result\Successful|Result\Error
86
+ * @throws Exception\Unexpected
87
+ */
88
+ private function _verifyGatewayResponse($response)
89
+ {
90
+ if (isset($response['idealPayment'])) {
91
+ // return a populated instance of IdealPayment
92
+ return new Result\Successful(
93
+ IdealPayment::factory($response['idealPayment'])
94
+ );
95
+ } else if (isset($response['apiErrorResponse'])) {
96
+ return new Result\Error($response['apiErrorResponse']);
97
+ } else {
98
+ throw new Exception\Unexpected(
99
+ 'Expected Ideal Payment or apiErrorResponse'
100
+ );
101
+ }
102
+ }
103
+ }
104
+ class_alias('Braintree\IdealPaymentGateway', 'Braintree_IdealPaymentGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Instance.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree Class Instance template
6
+ *
7
+ * @abstract
8
+ */
9
+ abstract class Instance
10
+ {
11
+ protected $_attributes = [];
12
+
13
+ /**
14
+ *
15
+ * @param array $attributes
16
+ */
17
+ public function __construct($attributes)
18
+ {
19
+ if (!empty($attributes)) {
20
+ $this->_initializeFromArray($attributes);
21
+ }
22
+ }
23
+
24
+ /**
25
+ * returns private/nonexistent instance properties
26
+ * @access public
27
+ * @param string $name property name
28
+ * @return mixed contents of instance properties
29
+ */
30
+ public function __get($name)
31
+ {
32
+ if (array_key_exists($name, $this->_attributes)) {
33
+ return $this->_attributes[$name];
34
+ } else {
35
+ trigger_error('Undefined property on ' . get_class($this) . ': ' . $name, E_USER_NOTICE);
36
+ return null;
37
+ }
38
+ }
39
+
40
+ /**
41
+ * used by isset() and empty()
42
+ * @access public
43
+ * @param string $name property name
44
+ * @return boolean
45
+ */
46
+ public function __isset($name)
47
+ {
48
+ return array_key_exists($name, $this->_attributes);
49
+ }
50
+
51
+ /**
52
+ * create a printable representation of the object as:
53
+ * ClassName[property=value, property=value]
54
+ * @return string
55
+ */
56
+ public function __toString()
57
+ {
58
+ $objOutput = Util::implodeAssociativeArray($this->_attributes);
59
+ return get_class($this) .'[' . $objOutput . ']';
60
+ }
61
+ /**
62
+ * initializes instance properties from the keys/values of an array
63
+ * @ignore
64
+ * @access protected
65
+ * @param <type> $aAttribs array of properties to set - single level
66
+ * @return void
67
+ */
68
+ private function _initializeFromArray($attributes)
69
+ {
70
+ $this->_attributes = $attributes;
71
+ }
72
+
73
+ }
74
+ class_alias('Braintree\Instance', 'Braintree_Instance');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/IsNode.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class IsNode
5
+ {
6
+ public function __construct($name)
7
+ {
8
+ $this->name = $name;
9
+ $this->searchTerms = [];
10
+ }
11
+
12
+ public function is($value)
13
+ {
14
+ $this->searchTerms['is'] = strval($value);
15
+
16
+ return $this;
17
+ }
18
+
19
+ public function toParam()
20
+ {
21
+ return $this->searchTerms;
22
+ }
23
+ }
24
+ class_alias('Braintree\IsNode', 'Braintree_IsNode');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/KeyValueNode.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class KeyValueNode
5
+ {
6
+ public function __construct($name)
7
+ {
8
+ $this->name = $name;
9
+ $this->searchTerm = True;
10
+ }
11
+
12
+ public function is($value)
13
+ {
14
+ $this->searchTerm = $value;
15
+ return $this;
16
+ }
17
+
18
+ public function toParam()
19
+ {
20
+ return $this->searchTerm;
21
+ }
22
+ }
23
+ class_alias('Braintree\KeyValueNode', 'Braintree_KeyValueNode');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MasterpassCard.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree MasterpassCard module
6
+ * Creates and manages Braintree MasterpassCards
7
+ *
8
+ * <b>== More information ==</b>
9
+ *
10
+ * For more detailed information on CreditCard verifications, see {@link http://www.braintreepayments.com/gateway/credit-card-verification-api http://www.braintreepaymentsolutions.com/gateway/credit-card-verification-api}
11
+ *
12
+ * @package Braintree
13
+ * @category Resources
14
+ *
15
+ * @property-read string $billingAddress
16
+ * @property-read string $bin
17
+ * @property-read string $cardType
18
+ * @property-read string $cardholderName
19
+ * @property-read string $commercial
20
+ * @property-read string $countryOfIssuance
21
+ * @property-read string $createdAt
22
+ * @property-read string $customerId
23
+ * @property-read string $customerLocation
24
+ * @property-read string $debit
25
+ * @property-read string $default
26
+ * @property-read string $durbinRegulated
27
+ * @property-read string $expirationDate
28
+ * @property-read string $expirationMonth
29
+ * @property-read string $expirationYear
30
+ * @property-read string $expired
31
+ * @property-read string $healthcare
32
+ * @property-read string $imageUrl
33
+ * @property-read string $issuingBank
34
+ * @property-read string $last4
35
+ * @property-read string $maskedNumber
36
+ * @property-read string $payroll
37
+ * @property-read string $prepaid
38
+ * @property-read string $productId
39
+ * @property-read string $subscriptions
40
+ * @property-read string $token
41
+ * @property-read string $uniqueNumberIdentifier
42
+ * @property-read string $updatedAt
43
+ */
44
+ class MasterpassCard extends Base
45
+ {
46
+ /* instance methods */
47
+ /**
48
+ * returns false if default is null or false
49
+ *
50
+ * @return boolean
51
+ */
52
+ public function isDefault()
53
+ {
54
+ return $this->default;
55
+ }
56
+
57
+ /**
58
+ * checks whether the card is expired based on the current date
59
+ *
60
+ * @return boolean
61
+ */
62
+ public function isExpired()
63
+ {
64
+ return $this->expired;
65
+ }
66
+
67
+ /**
68
+ * sets instance properties from an array of values
69
+ *
70
+ * @access protected
71
+ * @param array $creditCardAttribs array of creditcard data
72
+ * @return void
73
+ */
74
+ protected function _initialize($creditCardAttribs)
75
+ {
76
+ // set the attributes
77
+ $this->_attributes = $creditCardAttribs;
78
+
79
+ // map each address into its own object
80
+ $billingAddress = isset($creditCardAttribs['billingAddress']) ?
81
+ Address::factory($creditCardAttribs['billingAddress']) :
82
+ null;
83
+
84
+ $subscriptionArray = [];
85
+ if (isset($creditCardAttribs['subscriptions'])) {
86
+ foreach ($creditCardAttribs['subscriptions'] AS $subscription) {
87
+ $subscriptionArray[] = Subscription::factory($subscription);
88
+ }
89
+ }
90
+
91
+ $this->_set('subscriptions', $subscriptionArray);
92
+ $this->_set('billingAddress', $billingAddress);
93
+ $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
94
+ $this->_set('maskedNumber', $this->bin . '******' . $this->last4);
95
+ }
96
+
97
+ /**
98
+ * returns false if comparing object is not a CreditCard,
99
+ * or is a CreditCard with a different id
100
+ *
101
+ * @param object $otherCreditCard customer to compare against
102
+ * @return boolean
103
+ */
104
+ public function isEqual($otherMasterpassCard)
105
+ {
106
+ return !($otherMasterpassCard instanceof self) ? false : $this->token === $otherMasterpassCard->token;
107
+ }
108
+
109
+ /**
110
+ * create a printable representation of the object as:
111
+ * ClassName[property=value, property=value]
112
+ * @return string
113
+ */
114
+ public function __toString()
115
+ {
116
+ return __CLASS__ . '[' .
117
+ Util::attributesToString($this->_attributes) .']';
118
+ }
119
+
120
+ /**
121
+ * factory method: returns an instance of CreditCard
122
+ * to the requesting method, with populated properties
123
+ *
124
+ * @ignore
125
+ * @return MasterpassCard
126
+ */
127
+ public static function factory($attributes)
128
+ {
129
+ $defaultAttributes = [
130
+ 'bin' => '',
131
+ 'expirationMonth' => '',
132
+ 'expirationYear' => '',
133
+ 'last4' => '',
134
+ ];
135
+
136
+ $instance = new self();
137
+ $instance->_initialize(array_merge($defaultAttributes, $attributes));
138
+ return $instance;
139
+ }
140
+ }
141
+ class_alias('Braintree\MasterpassCard', 'Braintree_MasterpassCard');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Merchant.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class Merchant extends Base
5
+ {
6
+ protected function _initialize($attribs)
7
+ {
8
+ $this->_attributes = $attribs;
9
+
10
+ $merchantAccountArray = [];
11
+ if (isset($attribs['merchantAccounts'])) {
12
+ foreach ($attribs['merchantAccounts'] AS $merchantAccount) {
13
+ $merchantAccountArray[] = MerchantAccount::factory($merchantAccount);
14
+ }
15
+ }
16
+ $this->_set('merchantAccounts', $merchantAccountArray);
17
+ }
18
+
19
+ public static function factory($attributes)
20
+ {
21
+ $instance = new self();
22
+ $instance->_initialize($attributes);
23
+ return $instance;
24
+ }
25
+
26
+ /**
27
+ * returns a string representation of the merchant
28
+ * @return string
29
+ */
30
+ public function __toString()
31
+ {
32
+ return __CLASS__ . '[' .
33
+ Util::attributesToString($this->_attributes) .']';
34
+ }
35
+ }
36
+ class_alias('Braintree\Merchant', 'Braintree_Merchant');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccount.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class MerchantAccount extends Base
5
+ {
6
+ const STATUS_ACTIVE = 'active';
7
+ const STATUS_PENDING = 'pending';
8
+ const STATUS_SUSPENDED = 'suspended';
9
+
10
+ const FUNDING_DESTINATION_BANK = 'bank';
11
+ const FUNDING_DESTINATION_EMAIL = 'email';
12
+ const FUNDING_DESTINATION_MOBILE_PHONE = 'mobile_phone';
13
+
14
+ public static function factory($attributes)
15
+ {
16
+ $instance = new self();
17
+ $instance->_initialize($attributes);
18
+ return $instance;
19
+ }
20
+
21
+ protected function _initialize($merchantAccountAttribs)
22
+ {
23
+ $this->_attributes = $merchantAccountAttribs;
24
+
25
+ if (isset($merchantAccountAttribs['individual'])) {
26
+ $individual = $merchantAccountAttribs['individual'];
27
+ $this->_set('individualDetails', MerchantAccount\IndividualDetails::Factory($individual));
28
+ }
29
+
30
+ if (isset($merchantAccountAttribs['business'])) {
31
+ $business = $merchantAccountAttribs['business'];
32
+ $this->_set('businessDetails', MerchantAccount\BusinessDetails::Factory($business));
33
+ }
34
+
35
+ if (isset($merchantAccountAttribs['funding'])) {
36
+ $funding = $merchantAccountAttribs['funding'];
37
+ $this->_set('fundingDetails', new MerchantAccount\FundingDetails($funding));
38
+ }
39
+
40
+ if (isset($merchantAccountAttribs['masterMerchantAccount'])) {
41
+ $masterMerchantAccount = $merchantAccountAttribs['masterMerchantAccount'];
42
+ $this->_set('masterMerchantAccount', self::Factory($masterMerchantAccount));
43
+ }
44
+ }
45
+
46
+
47
+ // static methods redirecting to gateway
48
+
49
+ public static function create($attribs)
50
+ {
51
+ return Configuration::gateway()->merchantAccount()->create($attribs);
52
+ }
53
+
54
+ public static function find($merchant_account_id)
55
+ {
56
+ return Configuration::gateway()->merchantAccount()->find($merchant_account_id);
57
+ }
58
+
59
+ public static function update($merchant_account_id, $attributes)
60
+ {
61
+ return Configuration::gateway()->merchantAccount()->update($merchant_account_id, $attributes);
62
+ }
63
+ }
64
+ class_alias('Braintree\MerchantAccount', 'Braintree_MerchantAccount');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccount/AddressDetails.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\MerchantAccount;
3
+
4
+ use Braintree\Instance;
5
+
6
+ class AddressDetails extends Instance
7
+ {
8
+ protected $_attributes = [];
9
+ }
10
+ class_alias('Braintree\MerchantAccount\AddressDetails', 'Braintree_MerchantAccount_AddressDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccount/BusinessDetails.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\MerchantAccount;
3
+
4
+ use Braintree\Base;
5
+
6
+ class BusinessDetails extends Base
7
+ {
8
+ protected function _initialize($businessAttribs)
9
+ {
10
+ $this->_attributes = $businessAttribs;
11
+ if (isset($businessAttribs['address'])) {
12
+ $this->_set('addressDetails', new AddressDetails($businessAttribs['address']));
13
+ }
14
+ }
15
+
16
+ public static function factory($attributes)
17
+ {
18
+ $instance = new self();
19
+ $instance->_initialize($attributes);
20
+ return $instance;
21
+ }
22
+ }
23
+ class_alias('Braintree\MerchantAccount\BusinessDetails', 'Braintree_MerchantAccount_BusinessDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccount/FundingDetails.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\MerchantAccount;
3
+
4
+ use Braintree\Instance;
5
+
6
+ class FundingDetails extends Instance
7
+ {
8
+ protected $_attributes = [];
9
+ }
10
+ class_alias('Braintree\MerchantAccount\FundingDetails', 'Braintree_MerchantAccount_FundingDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccount/IndividualDetails.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\MerchantAccount;
3
+
4
+ use Braintree\Base;
5
+
6
+ class IndividualDetails extends Base
7
+ {
8
+ protected function _initialize($individualAttribs)
9
+ {
10
+ $this->_attributes = $individualAttribs;
11
+ if (isset($individualAttribs['address'])) {
12
+ $this->_set('addressDetails', new AddressDetails($individualAttribs['address']));
13
+ }
14
+ }
15
+
16
+ public static function factory($attributes)
17
+ {
18
+ $instance = new self();
19
+ $instance->_initialize($attributes);
20
+ return $instance;
21
+ }
22
+ }
23
+ class_alias('Braintree\MerchantAccount\IndividualDetails', 'Braintree_MerchantAccount_IndividualDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantAccountGateway.php ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class MerchantAccountGateway
5
+ {
6
+ private $_gateway;
7
+ private $_config;
8
+ private $_http;
9
+
10
+ public function __construct($gateway)
11
+ {
12
+ $this->_gateway = $gateway;
13
+ $this->_config = $gateway->config;
14
+ $this->_config->assertHasAccessTokenOrKeys();
15
+ $this->_http = new Http($gateway->config);
16
+ }
17
+
18
+ public function create($attribs)
19
+ {
20
+ Util::verifyKeys(self::detectSignature($attribs), $attribs);
21
+ return $this->_doCreate('/merchant_accounts/create_via_api', ['merchant_account' => $attribs]);
22
+ }
23
+
24
+ public function find($merchant_account_id)
25
+ {
26
+ try {
27
+ $path = $this->_config->merchantPath() . '/merchant_accounts/' . $merchant_account_id;
28
+ $response = $this->_http->get($path);
29
+ return MerchantAccount::factory($response['merchantAccount']);
30
+ } catch (Exception\NotFound $e) {
31
+ throw new Exception\NotFound('merchant account with id ' . $merchant_account_id . ' not found');
32
+ }
33
+ }
34
+
35
+ public function update($merchant_account_id, $attributes)
36
+ {
37
+ Util::verifyKeys(self::updateSignature(), $attributes);
38
+ return $this->_doUpdate('/merchant_accounts/' . $merchant_account_id . '/update_via_api', ['merchant_account' => $attributes]);
39
+ }
40
+
41
+ public static function detectSignature($attribs)
42
+ {
43
+ if (isset($attribs['applicantDetails'])) {
44
+ trigger_error("DEPRECATED: Passing applicantDetails to create is deprecated. Please use individual, business, and funding", E_USER_NOTICE);
45
+ return self::createDeprecatedSignature();
46
+ } else {
47
+ return self::createSignature();
48
+ }
49
+ }
50
+
51
+ public static function updateSignature()
52
+ {
53
+ $signature = self::createSignature();
54
+ unset($signature['tosAccepted']);
55
+ return $signature;
56
+ }
57
+
58
+ public function createForCurrency($attribs)
59
+ {
60
+ $response = $this->_http->post($this->_config->merchantPath() . '/merchant_accounts/create_for_currency', ['merchant_account' => $attribs]);
61
+ return $this->_verifyGatewayResponse($response);
62
+ }
63
+
64
+ public function all()
65
+ {
66
+ $pager = [
67
+ 'object' => $this,
68
+ 'method' => 'fetchMerchantAccounts',
69
+ ];
70
+ return new PaginatedCollection($pager);
71
+ }
72
+
73
+ public function fetchMerchantAccounts($page)
74
+ {
75
+ $response = $this->_http->get($this->_config->merchantPath() . '/merchant_accounts?page=' . $page);
76
+ $body = $response['merchantAccounts'];
77
+ $merchantAccounts = Util::extractattributeasarray($body, 'merchantAccount');
78
+ $totalItems = $body['totalItems'][0];
79
+ $pageSize = $body['pageSize'][0];
80
+ return new PaginatedResult($totalItems, $pageSize, $merchantAccounts);
81
+ }
82
+
83
+ public static function createSignature()
84
+ {
85
+ $addressSignature = ['streetAddress', 'postalCode', 'locality', 'region'];
86
+ $individualSignature = [
87
+ 'firstName',
88
+ 'lastName',
89
+ 'email',
90
+ 'phone',
91
+ 'dateOfBirth',
92
+ 'ssn',
93
+ ['address' => $addressSignature]
94
+ ];
95
+
96
+ $businessSignature = [
97
+ 'dbaName',
98
+ 'legalName',
99
+ 'taxId',
100
+ ['address' => $addressSignature]
101
+ ];
102
+
103
+ $fundingSignature = [
104
+ 'routingNumber',
105
+ 'accountNumber',
106
+ 'destination',
107
+ 'email',
108
+ 'mobilePhone',
109
+ 'descriptor',
110
+ ];
111
+
112
+ return [
113
+ 'id',
114
+ 'tosAccepted',
115
+ 'masterMerchantAccountId',
116
+ ['individual' => $individualSignature],
117
+ ['funding' => $fundingSignature],
118
+ ['business' => $businessSignature]
119
+ ];
120
+ }
121
+
122
+ public static function createDeprecatedSignature()
123
+ {
124
+ $applicantDetailsAddressSignature = ['streetAddress', 'postalCode', 'locality', 'region'];
125
+ $applicantDetailsSignature = [
126
+ 'companyName',
127
+ 'firstName',
128
+ 'lastName',
129
+ 'email',
130
+ 'phone',
131
+ 'dateOfBirth',
132
+ 'ssn',
133
+ 'taxId',
134
+ 'routingNumber',
135
+ 'accountNumber',
136
+ ['address' => $applicantDetailsAddressSignature]
137
+ ];
138
+
139
+ return [
140
+ ['applicantDetails' => $applicantDetailsSignature],
141
+ 'id',
142
+ 'tosAccepted',
143
+ 'masterMerchantAccountId'
144
+ ];
145
+ }
146
+
147
+ public function _doCreate($subPath, $params)
148
+ {
149
+ $fullPath = $this->_config->merchantPath() . $subPath;
150
+ $response = $this->_http->post($fullPath, $params);
151
+
152
+ return $this->_verifyGatewayResponse($response);
153
+ }
154
+
155
+ private function _doUpdate($subPath, $params)
156
+ {
157
+ $fullPath = $this->_config->merchantPath() . $subPath;
158
+ $response = $this->_http->put($fullPath, $params);
159
+
160
+ return $this->_verifyGatewayResponse($response);
161
+ }
162
+
163
+ private function _verifyGatewayResponse($response)
164
+ {
165
+ if (isset($response['response'])) {
166
+ $response = $response['response'];
167
+ }
168
+ if (isset($response['merchantAccount'])) {
169
+ // return a populated instance of merchantAccount
170
+ return new Result\Successful(
171
+ MerchantAccount::factory($response['merchantAccount'])
172
+ );
173
+ } else if (isset($response['apiErrorResponse'])) {
174
+ return new Result\Error($response['apiErrorResponse']);
175
+ } else {
176
+ throw new Exception\Unexpected(
177
+ "Expected merchant account or apiErrorResponse"
178
+ );
179
+ }
180
+ }
181
+ }
182
+ class_alias('Braintree\MerchantAccountGateway', 'Braintree_MerchantAccountGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MerchantGateway.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class MerchantGateway
5
+ {
6
+ private $_gateway;
7
+ private $_config;
8
+ private $_http;
9
+
10
+ public function __construct($gateway)
11
+ {
12
+ $this->_gateway = $gateway;
13
+ $this->_config = $gateway->config;
14
+ $this->_config->assertHasClientCredentials();
15
+ $this->_http = new Http($gateway->config);
16
+ $this->_http->useClientCredentials();
17
+ }
18
+
19
+ public function create($attribs)
20
+ {
21
+ $response = $this->_http->post('/merchants/create_via_api', ['merchant' => $attribs]);
22
+ return $this->_verifyGatewayResponse($response);
23
+ }
24
+
25
+ private function _verifyGatewayResponse($response)
26
+ {
27
+ if (isset($response['response']['merchant'])) {
28
+ // return a populated instance of merchant
29
+ return new Result\Successful([
30
+ Merchant::factory($response['response']['merchant']),
31
+ OAuthCredentials::factory($response['response']['credentials']),
32
+ ]);
33
+ } else if (isset($response['apiErrorResponse'])) {
34
+ return new Result\Error($response['apiErrorResponse']);
35
+ } else {
36
+ throw new Exception\Unexpected(
37
+ "Expected merchant or apiErrorResponse"
38
+ );
39
+ }
40
+ }
41
+ }
42
+ class_alias('Braintree\MerchantGateway', 'Braintree_MerchantGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Modification.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class Modification extends Base
5
+ {
6
+ protected function _initialize($attributes)
7
+ {
8
+ $this->_attributes = $attributes;
9
+ }
10
+
11
+ public static function factory($attributes)
12
+ {
13
+ $instance = new self();
14
+ $instance->_initialize($attributes);
15
+ return $instance;
16
+ }
17
+
18
+ public function __toString() {
19
+ return get_called_class() . '[' . Util::attributesToString($this->_attributes) . ']';
20
+ }
21
+ }
22
+ class_alias('Braintree\Modification', 'Braintree_Modification');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MultipleValueNode.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ class MultipleValueNode
7
+ {
8
+ public function __construct($name, $allowedValues = [])
9
+ {
10
+ $this->name = $name;
11
+ $this->items = [];
12
+ $this->allowedValues = $allowedValues;
13
+ }
14
+
15
+ public function in($values)
16
+ {
17
+ $bad_values = array_diff($values, $this->allowedValues);
18
+ if (count($this->allowedValues) > 0 && count($bad_values) > 0) {
19
+ $message = 'Invalid argument(s) for ' . $this->name . ':';
20
+ foreach ($bad_values AS $bad_value) {
21
+ $message .= ' ' . $bad_value;
22
+ }
23
+
24
+ throw new InvalidArgumentException($message);
25
+ }
26
+
27
+ $this->items = $values;
28
+ return $this;
29
+ }
30
+
31
+ public function is($value)
32
+ {
33
+ return $this->in([$value]);
34
+ }
35
+
36
+ public function toParam()
37
+ {
38
+ return $this->items;
39
+ }
40
+ }
41
+ class_alias('Braintree\MultipleValueNode', 'Braintree_MultipleValueNode');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/MultipleValueOrTextNode.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class MultipleValueOrTextNode extends MultipleValueNode
5
+ {
6
+ public function __construct($name)
7
+ {
8
+ parent::__construct($name);
9
+ $this->textNode = new TextNode($name);
10
+ }
11
+
12
+ public function contains($value)
13
+ {
14
+ $this->textNode->contains($value);
15
+ return $this;
16
+ }
17
+
18
+ public function endsWith($value)
19
+ {
20
+ $this->textNode->endsWith($value);
21
+ return $this;
22
+ }
23
+
24
+ public function is($value)
25
+ {
26
+ $this->textNode->is($value);
27
+ return $this;
28
+ }
29
+
30
+ public function isNot($value)
31
+ {
32
+ $this->textNode->isNot($value);
33
+ return $this;
34
+ }
35
+
36
+ public function startsWith($value)
37
+ {
38
+ $this->textNode->startsWith($value);
39
+ return $this;
40
+ }
41
+
42
+ public function toParam()
43
+ {
44
+ return array_merge(parent::toParam(), $this->textNode->toParam());
45
+ }
46
+ }
47
+ class_alias('Braintree\MultipleValueOrTextNode', 'Braintree_MultipleValueOrTextNode');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/OAuthCredentials.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree OAuthCredentials module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+ class OAuthCredentials extends Base
11
+ {
12
+ protected function _initialize($attribs)
13
+ {
14
+ $this->_attributes = $attribs;
15
+ }
16
+
17
+ public static function factory($attributes)
18
+ {
19
+ $instance = new self();
20
+ $instance->_initialize($attributes);
21
+ return $instance;
22
+ }
23
+
24
+ /**
25
+ * returns a string representation of the access token
26
+ * @return string
27
+ */
28
+ public function __toString()
29
+ {
30
+ return __CLASS__ . '[' .
31
+ Util::attributesToString($this->_attributes) .']';
32
+ }
33
+ }
34
+ class_alias('Braintree\OAuthCredentials', 'Braintree_OAuthCredentials');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/OAuthGateway.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree OAuthGateway module
6
+ * PHP Version 5
7
+ * Creates and manages Braintree Addresses
8
+ *
9
+ * @package Braintree
10
+ */
11
+ class OAuthGateway
12
+ {
13
+ private $_gateway;
14
+ private $_config;
15
+ private $_http;
16
+
17
+ public function __construct($gateway)
18
+ {
19
+ $this->_gateway = $gateway;
20
+ $this->_config = $gateway->config;
21
+ $this->_http = new Http($gateway->config);
22
+ $this->_http->useClientCredentials();
23
+
24
+ $this->_config->assertHasClientCredentials();
25
+ }
26
+
27
+ public function createTokenFromCode($params)
28
+ {
29
+ $params['grantType'] = "authorization_code";
30
+ return $this->_createToken($params);
31
+ }
32
+
33
+ public function createTokenFromRefreshToken($params)
34
+ {
35
+ $params['grantType'] = "refresh_token";
36
+ return $this->_createToken($params);
37
+ }
38
+
39
+ public function revokeAccessToken($accessToken)
40
+ {
41
+ $params = ['token' => $accessToken];
42
+ $response = $this->_http->post('/oauth/revoke_access_token', $params);
43
+ return $this->_verifyGatewayResponse($response);
44
+ }
45
+
46
+ private function _createToken($params)
47
+ {
48
+ $params = ['credentials' => $params];
49
+ $response = $this->_http->post('/oauth/access_tokens', $params);
50
+ return $this->_verifyGatewayResponse($response);
51
+ }
52
+
53
+ private function _verifyGatewayResponse($response)
54
+ {
55
+ if (isset($response['credentials'])) {
56
+ $result = new Result\Successful(
57
+ OAuthCredentials::factory($response['credentials'])
58
+ );
59
+ return $this->_mapSuccess($result);
60
+ } else if (isset($response['result'])) {
61
+ $result = new Result\Successful(
62
+ OAuthResult::factory($response['result'])
63
+ );
64
+ return $this->_mapAccessTokenRevokeSuccess($result);
65
+ } else if (isset($response['apiErrorResponse'])) {
66
+ $result = new Result\Error($response['apiErrorResponse']);
67
+ return $this->_mapError($result);
68
+ } else {
69
+ throw new Exception\Unexpected(
70
+ "Expected credentials or apiErrorResponse"
71
+ );
72
+ }
73
+ }
74
+
75
+ public function _mapError($result)
76
+ {
77
+ $error = $result->errors->deepAll()[0];
78
+
79
+ if ($error->code == Error\Codes::OAUTH_INVALID_GRANT) {
80
+ $result->error = 'invalid_grant';
81
+ } else if ($error->code == Error\Codes::OAUTH_INVALID_CREDENTIALS) {
82
+ $result->error = 'invalid_credentials';
83
+ } else if ($error->code == Error\Codes::OAUTH_INVALID_SCOPE) {
84
+ $result->error = 'invalid_scope';
85
+ }
86
+ $result->errorDescription = explode(': ', $error->message)[1];
87
+ return $result;
88
+ }
89
+
90
+ public function _mapAccessTokenRevokeSuccess($result)
91
+ {
92
+ $result->revocationResult = $result->success;
93
+ return $result;
94
+ }
95
+
96
+ public function _mapSuccess($result)
97
+ {
98
+ $credentials = $result->credentials;
99
+ $result->accessToken = $credentials->accessToken;
100
+ $result->refreshToken = $credentials->refreshToken;
101
+ $result->tokenType = $credentials->tokenType;
102
+ $result->expiresAt = $credentials->expiresAt;
103
+ return $result;
104
+ }
105
+
106
+ public function connectUrl($params = [])
107
+ {
108
+ $query = Util::camelCaseToDelimiterArray($params, '_');
109
+ $query['client_id'] = $this->_config->getClientId();
110
+ $queryString = preg_replace('/\%5B\d+\%5D/', '%5B%5D', http_build_query($query));
111
+ $url = $this->_config->baseUrl() . '/oauth/connect?' . $queryString;
112
+
113
+ return $url . '&signature=' . $this->computeSignature($url) . '&algorithm=SHA256';
114
+ }
115
+
116
+ public function computeSignature($url)
117
+ {
118
+ $key = hash('sha256', $this->_config->getClientSecret(), true);
119
+ return hash_hmac('sha256', $url, $key);
120
+ }
121
+ }
122
+ class_alias('Braintree\OAuthGateway', 'Braintree_OAuthGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/OAuthResult.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree OAuthCredentials module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+ class OAuthResult extends Base
11
+ {
12
+ protected function _initialize($attribs)
13
+ {
14
+ $this->_attributes = $attribs;
15
+ }
16
+
17
+ public static function factory($attributes)
18
+ {
19
+ $instance = new self();
20
+ $instance->_initialize($attributes);
21
+ return $instance;
22
+ }
23
+
24
+ /**
25
+ * returns a string representation of the result
26
+ * @return string
27
+ */
28
+ public function __toString()
29
+ {
30
+ return __CLASS__ . '[' .
31
+ Util::attributesToString($this->_attributes) .']';
32
+ }
33
+ }
34
+ class_alias('Braintree\OAuthResult', 'Braintree_OAuthResult');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaginatedCollection.php ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use Iterator;
5
+
6
+ /**
7
+ * Braintree PaginatedCollection
8
+ * PaginatedCollection is a container object for paginated data
9
+ *
10
+ * retrieves and pages through large collections of results
11
+ *
12
+ * example:
13
+ * <code>
14
+ * $result = MerchantAccount::all();
15
+ *
16
+ * foreach($result as $merchantAccount) {
17
+ * print_r($merchantAccount->status);
18
+ * }
19
+ * </code>
20
+ *
21
+ * @package Braintree
22
+ * @subpackage Utility
23
+ */
24
+ class PaginatedCollection implements Iterator
25
+ {
26
+ private $_pager;
27
+ private $_pageSize;
28
+ private $_currentPage;
29
+ private $_index;
30
+ private $_totalItems;
31
+ private $_items;
32
+
33
+ /**
34
+ * set up the paginated collection
35
+ *
36
+ * expects an array of an object and method to call on it
37
+ *
38
+ * @param array $pager
39
+ */
40
+ public function __construct($pager)
41
+ {
42
+ $this->_pager = $pager;
43
+ $this->_pageSize = 0;
44
+ $this->_currentPage = 0;
45
+ $this->_totalItems = 0;
46
+ $this->_index = 0;
47
+ }
48
+
49
+ /**
50
+ * returns the current item when iterating with foreach
51
+ */
52
+ public function current()
53
+ {
54
+ return $this->_items[($this->_index % $this->_pageSize)];
55
+ }
56
+
57
+ public function key()
58
+ {
59
+ return null;
60
+ }
61
+
62
+ /**
63
+ * advances to the next item in the collection when iterating with foreach
64
+ */
65
+ public function next()
66
+ {
67
+ ++$this->_index;
68
+ }
69
+
70
+ /**
71
+ * rewinds the collection to the first item when iterating with foreach
72
+ */
73
+ public function rewind()
74
+ {
75
+ $this->_index = 0;
76
+ $this->_currentPage = 0;
77
+ $this->_pageSize = 0;
78
+ $this->_totalItems = 0;
79
+ $this->_items = [];
80
+ }
81
+
82
+ /**
83
+ * returns whether the current item is valid when iterating with foreach
84
+ */
85
+ public function valid()
86
+ {
87
+ if ($this->_currentPage == 0 || $this->_index % $this->_pageSize == 0 && $this->_index < $this->_totalItems)
88
+ {
89
+ $this->_getNextPage();
90
+ }
91
+
92
+ return $this->_index < $this->_totalItems;
93
+ }
94
+
95
+ private function _getNextPage()
96
+ {
97
+ $this->_currentPage++;
98
+ $object = $this->_pager['object'];
99
+ $method = $this->_pager['method'];
100
+ $result = call_user_func(
101
+ [$object, $method],
102
+ $this->_currentPage
103
+ );
104
+
105
+ $this->_totalItems= $result->getTotalItems();
106
+ $this->_pageSize = $result->getPageSize();
107
+ $this->_items = $result->getCurrentPage();
108
+ }
109
+ }
110
+ class_alias('Braintree\PaginatedCollection', 'Braintree_PaginatedCollection');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaginatedResult.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class PaginatedResult
5
+ {
6
+ private $_totalItems;
7
+ private $_pageSize;
8
+ private $_currentPage;
9
+
10
+ public function __construct($totalItems, $pageSize, $currentPage)
11
+ {
12
+ $this->_totalItems = $totalItems;
13
+ $this->_pageSize = $pageSize;
14
+ $this->_currentPage = $currentPage;
15
+ }
16
+
17
+ public function getTotalItems()
18
+ {
19
+ return $this->_totalItems;
20
+ }
21
+
22
+ public function getPageSize()
23
+ {
24
+ return $this->_pageSize;
25
+ }
26
+
27
+ public function getCurrentPage()
28
+ {
29
+ return $this->_currentPage;
30
+ }
31
+ }
32
+ class_alias('Braintree\PaginatedResult', 'Braintree_PaginatedResult');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PartialMatchNode.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class PartialMatchNode extends EqualityNode
5
+ {
6
+ public function startsWith($value)
7
+ {
8
+ $this->searchTerms["starts_with"] = strval($value);
9
+ return $this;
10
+ }
11
+
12
+ public function endsWith($value)
13
+ {
14
+ $this->searchTerms["ends_with"] = strval($value);
15
+ return $this;
16
+ }
17
+ }
18
+ class_alias('Braintree\PartialMatchNode', 'Braintree_PartialMatchNode');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PartnerMerchant.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Partner Merchant information that is generated when a partner is connected
6
+ * to or disconnected from a user.
7
+ *
8
+ * Creates an instance of PartnerMerchants
9
+ *
10
+ * @package Braintree
11
+ *
12
+ * @property-read string $merchantPublicId
13
+ * @property-read string $publicKey
14
+ * @property-read string $privateKey
15
+ * @property-read string $clientSideEncryptionKey
16
+ * @property-read string $partnerMerchantId
17
+ */
18
+ class PartnerMerchant extends Base
19
+ {
20
+ protected $_attributes = [];
21
+
22
+ /**
23
+ * @ignore
24
+ */
25
+ public static function factory($attributes)
26
+ {
27
+ $instance = new self();
28
+ $instance->_initialize($attributes);
29
+
30
+ return $instance;
31
+ }
32
+
33
+ /**
34
+ * @ignore
35
+ */
36
+ protected function _initialize($attributes)
37
+ {
38
+ $this->_attributes = $attributes;
39
+ }
40
+ }
41
+ class_alias('Braintree\PartnerMerchant', 'Braintree_PartnerMerchant');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PayPalAccount.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree PayPalAccount module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+
11
+ /**
12
+ * Manages Braintree PayPalAccounts
13
+ *
14
+ * <b>== More information ==</b>
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @category Resources
19
+ *
20
+ * @property-read string $customerId
21
+ * @property-read string $email
22
+ * @property-read string $token
23
+ * @property-read string $imageUrl
24
+ */
25
+ class PayPalAccount extends Base
26
+ {
27
+ /**
28
+ * factory method: returns an instance of PayPalAccount
29
+ * to the requesting method, with populated properties
30
+ *
31
+ * @ignore
32
+ * @return PayPalAccount
33
+ */
34
+ public static function factory($attributes)
35
+ {
36
+ $instance = new self();
37
+ $instance->_initialize($attributes);
38
+ return $instance;
39
+ }
40
+
41
+ /* instance methods */
42
+
43
+ /**
44
+ * returns false if default is null or false
45
+ *
46
+ * @return boolean
47
+ */
48
+ public function isDefault()
49
+ {
50
+ return $this->default;
51
+ }
52
+
53
+ /**
54
+ * sets instance properties from an array of values
55
+ *
56
+ * @access protected
57
+ * @param array $paypalAccountAttribs array of paypalAccount data
58
+ * @return void
59
+ */
60
+ protected function _initialize($paypalAccountAttribs)
61
+ {
62
+ // set the attributes
63
+ $this->_attributes = $paypalAccountAttribs;
64
+
65
+ $subscriptionArray = [];
66
+ if (isset($paypalAccountAttribs['subscriptions'])) {
67
+ foreach ($paypalAccountAttribs['subscriptions'] AS $subscription) {
68
+ $subscriptionArray[] = Subscription::factory($subscription);
69
+ }
70
+ }
71
+
72
+ $this->_set('subscriptions', $subscriptionArray);
73
+ }
74
+
75
+ /**
76
+ * create a printable representation of the object as:
77
+ * ClassName[property=value, property=value]
78
+ * @return string
79
+ */
80
+ public function __toString()
81
+ {
82
+ return __CLASS__ . '[' .
83
+ Util::attributesToString($this->_attributes) . ']';
84
+ }
85
+
86
+
87
+ // static methods redirecting to gateway
88
+
89
+ public static function find($token)
90
+ {
91
+ return Configuration::gateway()->payPalAccount()->find($token);
92
+ }
93
+
94
+ public static function update($token, $attributes)
95
+ {
96
+ return Configuration::gateway()->payPalAccount()->update($token, $attributes);
97
+ }
98
+
99
+ public static function delete($token)
100
+ {
101
+ return Configuration::gateway()->payPalAccount()->delete($token);
102
+ }
103
+
104
+ public static function sale($token, $transactionAttribs)
105
+ {
106
+ return Configuration::gateway()->payPalAccount()->sale($token, $transactionAttribs);
107
+ }
108
+ }
109
+ class_alias('Braintree\PayPalAccount', 'Braintree_PayPalAccount');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PayPalAccountGateway.php ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ /**
7
+ * Braintree PayPalAccountGateway module
8
+ *
9
+ * @package Braintree
10
+ * @category Resources
11
+ */
12
+
13
+ /**
14
+ * Manages Braintree PayPalAccounts
15
+ *
16
+ * <b>== More information ==</b>
17
+ *
18
+ *
19
+ * @package Braintree
20
+ * @category Resources
21
+ */
22
+ class PayPalAccountGateway
23
+ {
24
+ private $_gateway;
25
+ private $_config;
26
+ private $_http;
27
+
28
+ public function __construct($gateway)
29
+ {
30
+ $this->_gateway = $gateway;
31
+ $this->_config = $gateway->config;
32
+ $this->_config->assertHasAccessTokenOrKeys();
33
+ $this->_http = new Http($gateway->config);
34
+ }
35
+
36
+
37
+ /**
38
+ * find a paypalAccount by token
39
+ *
40
+ * @access public
41
+ * @param string $token paypal accountunique id
42
+ * @return PayPalAccount
43
+ * @throws Exception\NotFound
44
+ */
45
+ public function find($token)
46
+ {
47
+ $this->_validateId($token);
48
+ try {
49
+ $path = $this->_config->merchantPath() . '/payment_methods/paypal_account/' . $token;
50
+ $response = $this->_http->get($path);
51
+ return PayPalAccount::factory($response['paypalAccount']);
52
+ } catch (Exception\NotFound $e) {
53
+ throw new Exception\NotFound(
54
+ 'paypal account with token ' . $token . ' not found'
55
+ );
56
+ }
57
+
58
+ }
59
+
60
+ /**
61
+ * updates the paypalAccount record
62
+ *
63
+ * if calling this method in context, $token
64
+ * is the 2nd attribute. $token is not sent in object context.
65
+ *
66
+ * @access public
67
+ * @param array $attributes
68
+ * @param string $token (optional)
69
+ * @return Result\Successful or Result\Error
70
+ */
71
+ public function update($token, $attributes)
72
+ {
73
+ Util::verifyKeys(self::updateSignature(), $attributes);
74
+ $this->_validateId($token);
75
+ return $this->_doUpdate('put', '/payment_methods/paypal_account/' . $token, ['paypalAccount' => $attributes]);
76
+ }
77
+
78
+ public function delete($token)
79
+ {
80
+ $this->_validateId($token);
81
+ $path = $this->_config->merchantPath() . '/payment_methods/paypal_account/' . $token;
82
+ $this->_http->delete($path);
83
+ return new Result\Successful();
84
+ }
85
+
86
+ /**
87
+ * create a new sale for the current PayPal account
88
+ *
89
+ * @param string $token
90
+ * @param array $transactionAttribs
91
+ * @return Result\Successful|Result\Error
92
+ * @see Transaction::sale()
93
+ */
94
+ public function sale($token, $transactionAttribs)
95
+ {
96
+ $this->_validateId($token);
97
+ return Transaction::sale(
98
+ array_merge(
99
+ $transactionAttribs,
100
+ ['paymentMethodToken' => $token]
101
+ )
102
+ );
103
+ }
104
+
105
+ public static function updateSignature()
106
+ {
107
+ return [
108
+ 'token',
109
+ ['options' => ['makeDefault']]
110
+ ];
111
+ }
112
+
113
+ /**
114
+ * sends the update request to the gateway
115
+ *
116
+ * @ignore
117
+ * @param string $subPath
118
+ * @param array $params
119
+ * @return mixed
120
+ */
121
+ private function _doUpdate($httpVerb, $subPath, $params)
122
+ {
123
+ $fullPath = $this->_config->merchantPath() . $subPath;
124
+ $response = $this->_http->$httpVerb($fullPath, $params);
125
+ return $this->_verifyGatewayResponse($response);
126
+ }
127
+
128
+ /**
129
+ * generic method for validating incoming gateway responses
130
+ *
131
+ * creates a new PayPalAccount object and encapsulates
132
+ * it inside a Result\Successful object, or
133
+ * encapsulates a Errors object inside a Result\Error
134
+ * alternatively, throws an Unexpected exception if the response is invalid.
135
+ *
136
+ * @ignore
137
+ * @param array $response gateway response values
138
+ * @return Result\Successful|Result\Error
139
+ * @throws Exception\Unexpected
140
+ */
141
+ private function _verifyGatewayResponse($response)
142
+ {
143
+ if (isset($response['paypalAccount'])) {
144
+ // return a populated instance of PayPalAccount
145
+ return new Result\Successful(
146
+ PayPalAccount::factory($response['paypalAccount'])
147
+ );
148
+ } else if (isset($response['apiErrorResponse'])) {
149
+ return new Result\Error($response['apiErrorResponse']);
150
+ } else {
151
+ throw new Exception\Unexpected(
152
+ 'Expected paypal account or apiErrorResponse'
153
+ );
154
+ }
155
+ }
156
+
157
+ /**
158
+ * verifies that a valid paypal account identifier is being used
159
+ * @ignore
160
+ * @param string $identifier
161
+ * @param Optional $string $identifierType type of identifier supplied, default 'token'
162
+ * @throws InvalidArgumentException
163
+ */
164
+ private function _validateId($identifier = null, $identifierType = 'token')
165
+ {
166
+ if (empty($identifier)) {
167
+ throw new InvalidArgumentException(
168
+ 'expected paypal account id to be set'
169
+ );
170
+ }
171
+ if (!preg_match('/^[0-9A-Za-z_-]+$/', $identifier)) {
172
+ throw new InvalidArgumentException(
173
+ $identifier . ' is an invalid paypal account ' . $identifierType . '.'
174
+ );
175
+ }
176
+ }
177
+ }
178
+ class_alias('Braintree\PayPalAccountGateway', 'Braintree_PayPalAccountGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaymentInstrumentType.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class PaymentInstrumentType
5
+ {
6
+ const PAYPAL_ACCOUNT = 'paypal_account';
7
+ const COINBASE_ACCOUNT = 'coinbase_account';
8
+ const EUROPE_BANK_ACCOUNT = 'europe_bank_account';
9
+ const CREDIT_CARD = 'credit_card';
10
+ const VISA_CHECKOUT_CARD = 'visa_checkout_card';
11
+ const MASTERPASS_CARD = 'masterpass_card';
12
+ const APPLE_PAY_CARD = 'apple_pay_card';
13
+ const ANDROID_PAY_CARD = 'android_pay_card';
14
+ const VENMO_ACCOUNT = 'venmo_account';
15
+ const US_BANK_ACCOUNT = 'us_bank_account';
16
+ }
17
+ class_alias('Braintree\PaymentInstrumentType', 'Braintree_PaymentInstrumentType');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaymentMethod.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree PaymentMethod module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+
11
+ /**
12
+ * Creates and manages Braintree PaymentMethods
13
+ *
14
+ * <b>== More information ==</b>
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @category Resources
19
+ */
20
+ class PaymentMethod extends Base
21
+ {
22
+ // static methods redirecting to gateway
23
+
24
+ public static function create($attribs)
25
+ {
26
+ return Configuration::gateway()->paymentMethod()->create($attribs);
27
+ }
28
+
29
+ public static function find($token)
30
+ {
31
+ return Configuration::gateway()->paymentMethod()->find($token);
32
+ }
33
+
34
+ public static function update($token, $attribs)
35
+ {
36
+ return Configuration::gateway()->paymentMethod()->update($token, $attribs);
37
+ }
38
+
39
+ public static function delete($token, $options=[])
40
+ {
41
+ return Configuration::gateway()->paymentMethod()->delete($token, $options);
42
+ }
43
+ }
44
+ class_alias('Braintree\PaymentMethod', 'Braintree_PaymentMethod');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaymentMethodGateway.php ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ /**
7
+ * Braintree PaymentMethodGateway module
8
+ *
9
+ * @package Braintree
10
+ * @category Resources
11
+ */
12
+
13
+ /**
14
+ * Creates and manages Braintree PaymentMethods
15
+ *
16
+ * <b>== More information ==</b>
17
+ *
18
+ *
19
+ * @package Braintree
20
+ * @category Resources
21
+ */
22
+ class PaymentMethodGateway
23
+ {
24
+ private $_gateway;
25
+ private $_config;
26
+ private $_http;
27
+
28
+ public function __construct($gateway)
29
+ {
30
+ $this->_gateway = $gateway;
31
+ $this->_config = $gateway->config;
32
+ $this->_config->assertHasAccessTokenOrKeys();
33
+ $this->_http = new Http($gateway->config);
34
+ }
35
+
36
+
37
+ public function create($attribs)
38
+ {
39
+ Util::verifyKeys(self::createSignature(), $attribs);
40
+ return $this->_doCreate('/payment_methods', ['payment_method' => $attribs]);
41
+ }
42
+
43
+ /**
44
+ * find a PaymentMethod by token
45
+ *
46
+ * @param string $token payment method unique id
47
+ * @return CreditCard|PayPalAccount
48
+ * @throws Exception\NotFound
49
+ */
50
+ public function find($token)
51
+ {
52
+ $this->_validateId($token);
53
+ try {
54
+ $path = $this->_config->merchantPath() . '/payment_methods/any/' . $token;
55
+ $response = $this->_http->get($path);
56
+ if (isset($response['creditCard'])) {
57
+ return CreditCard::factory($response['creditCard']);
58
+ } else if (isset($response['paypalAccount'])) {
59
+ return PayPalAccount::factory($response['paypalAccount']);
60
+ } else if (isset($response['coinbaseAccount'])) {
61
+ return CoinbaseAccount::factory($response['coinbaseAccount']);
62
+ } else if (isset($response['applePayCard'])) {
63
+ return ApplePayCard::factory($response['applePayCard']);
64
+ } else if (isset($response['androidPayCard'])) {
65
+ return AndroidPayCard::factory($response['androidPayCard']);
66
+ } else if (isset($response['amexExpressCheckoutCard'])) {
67
+ return AmexExpressCheckoutCard::factory($response['amexExpressCheckoutCard']);
68
+ } else if (isset($response['europeBankAccount'])) {
69
+ return EuropeBankAccount::factory($response['europeBankAccount']);
70
+ } else if (isset($response['usBankAccount'])) {
71
+ return UsBankAccount::factory($response['usBankAccount']);
72
+ } else if (isset($response['venmoAccount'])) {
73
+ return VenmoAccount::factory($response['venmoAccount']);
74
+ } else if (isset($response['visaCheckoutCard'])) {
75
+ return VisaCheckoutCard::factory($response['visaCheckoutCard']);
76
+ } else if (isset($response['masterpassCard'])) {
77
+ return MasterpassCard::factory($response['masterpassCard']);
78
+ } else if (is_array($response)) {
79
+ return UnknownPaymentMethod::factory($response);
80
+ }
81
+ } catch (Exception\NotFound $e) {
82
+ throw new Exception\NotFound(
83
+ 'payment method with token ' . $token . ' not found'
84
+ );
85
+ }
86
+ }
87
+
88
+ public function update($token, $attribs)
89
+ {
90
+ Util::verifyKeys(self::updateSignature(), $attribs);
91
+ return $this->_doUpdate('/payment_methods/any/' . $token, ['payment_method' => $attribs]);
92
+ }
93
+
94
+ public function delete($token, $options=[])
95
+ {
96
+ Util::verifyKeys(self::deleteSignature(), $options);
97
+ $this->_validateId($token);
98
+ $queryString = "";
99
+ if (!empty($options)) {
100
+ $queryString = "?" . http_build_query(Util::camelCaseToDelimiterArray($options, '_'));
101
+ }
102
+ return $this->_doDelete('/payment_methods/any/' . $token . $queryString);
103
+ }
104
+
105
+ public function grant($sharedPaymentMethodToken, $attribs=[])
106
+ {
107
+ if (is_bool($attribs) === true) {
108
+ $attribs = ['allow_vaulting' => $attribs];
109
+ }
110
+ $options = [ 'shared_payment_method_token' => $sharedPaymentMethodToken ];
111
+
112
+ return $this->_doCreate(
113
+ '/payment_methods/grant',
114
+ [
115
+ 'payment_method' => array_merge($attribs, $options)
116
+ ]
117
+ );
118
+ }
119
+
120
+ public function revoke($sharedPaymentMethodToken)
121
+ {
122
+ return $this->_doCreate(
123
+ '/payment_methods/revoke',
124
+ [
125
+ 'payment_method' => [
126
+ 'shared_payment_method_token' => $sharedPaymentMethodToken
127
+ ]
128
+ ]
129
+ );
130
+ }
131
+
132
+ private static function baseSignature()
133
+ {
134
+ $billingAddressSignature = AddressGateway::createSignature();
135
+ $optionsSignature = [
136
+ 'failOnDuplicatePaymentMethod',
137
+ 'makeDefault',
138
+ 'verificationMerchantAccountId',
139
+ 'verifyCard',
140
+ 'verificationAmount',
141
+ ['paypal' => [
142
+ 'payee_email',
143
+ 'order_id',
144
+ 'custom_field',
145
+ 'description',
146
+ 'amount',
147
+ ]],
148
+ ];
149
+ return [
150
+ 'billingAddressId',
151
+ 'cardholderName',
152
+ 'cvv',
153
+ 'deviceData',
154
+ 'expirationDate',
155
+ 'expirationMonth',
156
+ 'expirationYear',
157
+ 'number',
158
+ 'paymentMethodNonce',
159
+ 'token',
160
+ ['options' => $optionsSignature],
161
+ ['billingAddress' => $billingAddressSignature]
162
+ ];
163
+ }
164
+
165
+ public static function createSignature()
166
+ {
167
+ $signature = array_merge(self::baseSignature(), ['customerId']);
168
+ return $signature;
169
+ }
170
+
171
+ public static function updateSignature()
172
+ {
173
+ $billingAddressSignature = AddressGateway::updateSignature();
174
+ array_push($billingAddressSignature, [
175
+ 'options' => [
176
+ 'updateExisting'
177
+ ]
178
+ ]);
179
+ $signature = array_merge(self::baseSignature(), [
180
+ 'deviceSessionId',
181
+ 'venmoSdkPaymentMethodCode',
182
+ 'fraudMerchantId',
183
+ ['billingAddress' => $billingAddressSignature]
184
+ ]);
185
+ return $signature;
186
+ }
187
+
188
+ private static function deleteSignature()
189
+ {
190
+ return ['revokeAllGrants'];
191
+ }
192
+
193
+ /**
194
+ * sends the create request to the gateway
195
+ *
196
+ * @ignore
197
+ * @param string $subPath
198
+ * @param array $params
199
+ * @return mixed
200
+ */
201
+ public function _doCreate($subPath, $params)
202
+ {
203
+ $fullPath = $this->_config->merchantPath() . $subPath;
204
+ $response = $this->_http->post($fullPath, $params);
205
+
206
+ return $this->_verifyGatewayResponse($response);
207
+ }
208
+
209
+ /**
210
+ * sends the update request to the gateway
211
+ *
212
+ * @ignore
213
+ * @param string $subPath
214
+ * @param array $params
215
+ * @return mixed
216
+ */
217
+ public function _doUpdate($subPath, $params)
218
+ {
219
+ $fullPath = $this->_config->merchantPath() . $subPath;
220
+ $response = $this->_http->put($fullPath, $params);
221
+
222
+ return $this->_verifyGatewayResponse($response);
223
+ }
224
+
225
+
226
+ /**
227
+ * sends the delete request to the gateway
228
+ *
229
+ * @ignore
230
+ * @param string $subPath
231
+ * @return mixed
232
+ */
233
+ public function _doDelete($subPath)
234
+ {
235
+ $fullPath = $this->_config->merchantPath() . $subPath;
236
+ $this->_http->delete($fullPath);
237
+ return new Result\Successful();
238
+ }
239
+
240
+ /**
241
+ * generic method for validating incoming gateway responses
242
+ *
243
+ * creates a new CreditCard or PayPalAccount object
244
+ * and encapsulates it inside a Result\Successful object, or
245
+ * encapsulates a Errors object inside a Result\Error
246
+ * alternatively, throws an Unexpected exception if the response is invalid.
247
+ *
248
+ * @ignore
249
+ * @param array $response gateway response values
250
+ * @return Result\Successful|Result\Error
251
+ * @throws Exception\Unexpected
252
+ */
253
+ private function _verifyGatewayResponse($response)
254
+ {
255
+ if (isset($response['creditCard'])) {
256
+ return new Result\Successful(
257
+ CreditCard::factory($response['creditCard']),
258
+ 'paymentMethod'
259
+ );
260
+ } else if (isset($response['paypalAccount'])) {
261
+ return new Result\Successful(
262
+ PayPalAccount::factory($response['paypalAccount']),
263
+ "paymentMethod"
264
+ );
265
+ } else if (isset($response['coinbaseAccount'])) {
266
+ return new Result\Successful(
267
+ CoinbaseAccount::factory($response['coinbaseAccount']),
268
+ "paymentMethod"
269
+ );
270
+ } else if (isset($response['applePayCard'])) {
271
+ return new Result\Successful(
272
+ ApplePayCard::factory($response['applePayCard']),
273
+ "paymentMethod"
274
+ );
275
+ } else if (isset($response['androidPayCard'])) {
276
+ return new Result\Successful(
277
+ AndroidPayCard::factory($response['androidPayCard']),
278
+ "paymentMethod"
279
+ );
280
+ } else if (isset($response['amexExpressCheckoutCard'])) {
281
+ return new Result\Successful(
282
+ AmexExpressCheckoutCard::factory($response['amexExpressCheckoutCard']),
283
+ "paymentMethod"
284
+ );
285
+ } else if (isset($response['europeBankAccount'])) {
286
+ return new Result\Successful(
287
+ EuropeBankAccount::factory($response['europeBankAccount']),
288
+ "paymentMethod"
289
+ );
290
+ } else if (isset($response['usBankAccount'])) {
291
+ return new Result\Successful(
292
+ UsBankAccount::factory($response['usBankAccount']),
293
+ "paymentMethod"
294
+ );
295
+ } else if (isset($response['venmoAccount'])) {
296
+ return new Result\Successful(
297
+ VenmoAccount::factory($response['venmoAccount']),
298
+ "paymentMethod"
299
+ );
300
+ } else if (isset($response['visaCheckoutCard'])) {
301
+ return new Result\Successful(
302
+ VisaCheckoutCard::factory($response['visaCheckoutCard']),
303
+ "paymentMethod"
304
+ );
305
+ } else if (isset($response['masterpassCard'])) {
306
+ return new Result\Successful(
307
+ MasterpassCard::factory($response['masterpassCard']),
308
+ "paymentMethod"
309
+ );
310
+ } else if (isset($response['paymentMethodNonce'])) {
311
+ return new Result\Successful(
312
+ PaymentMethodNonce::factory($response['paymentMethodNonce']),
313
+ "paymentMethodNonce"
314
+ );
315
+ } else if (isset($response['apiErrorResponse'])) {
316
+ return new Result\Error($response['apiErrorResponse']);
317
+ } else if (is_array($response)) {
318
+ return new Result\Successful(
319
+ UnknownPaymentMethod::factory($response),
320
+ "paymentMethod"
321
+ );
322
+ } else {
323
+ throw new Exception\Unexpected(
324
+ 'Expected payment method or apiErrorResponse'
325
+ );
326
+ }
327
+ }
328
+
329
+ /**
330
+ * verifies that a valid payment method identifier is being used
331
+ * @ignore
332
+ * @param string $identifier
333
+ * @param Optional $string $identifierType type of identifier supplied, default 'token'
334
+ * @throws InvalidArgumentException
335
+ */
336
+ private function _validateId($identifier = null, $identifierType = 'token')
337
+ {
338
+ if (empty($identifier)) {
339
+ throw new InvalidArgumentException(
340
+ 'expected payment method id to be set'
341
+ );
342
+ }
343
+ if (!preg_match('/^[0-9A-Za-z_-]+$/', $identifier)) {
344
+ throw new InvalidArgumentException(
345
+ $identifier . ' is an invalid payment method ' . $identifierType . '.'
346
+ );
347
+ }
348
+ }
349
+ }
350
+ class_alias('Braintree\PaymentMethodGateway', 'Braintree_PaymentMethodGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaymentMethodNonce.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree PaymentMethodNonce module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+
11
+ /**
12
+ * Creates and manages Braintree PaymentMethodNonces
13
+ *
14
+ * <b>== More information ==</b>
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @category Resources
19
+ */
20
+ class PaymentMethodNonce extends Base
21
+ {
22
+ // static methods redirecting to gateway
23
+
24
+ public static function create($token)
25
+ {
26
+ return Configuration::gateway()->paymentMethodNonce()->create($token);
27
+ }
28
+
29
+ public static function find($nonce)
30
+ {
31
+ return Configuration::gateway()->paymentMethodNonce()->find($nonce);
32
+ }
33
+
34
+ public static function factory($attributes)
35
+ {
36
+ $instance = new self();
37
+ $instance->_initialize($attributes);
38
+ return $instance;
39
+ }
40
+
41
+ protected function _initialize($nonceAttributes)
42
+ {
43
+ $this->_attributes = $nonceAttributes;
44
+ $this->_set('nonce', $nonceAttributes['nonce']);
45
+ $this->_set('type', $nonceAttributes['type']);
46
+
47
+ if(isset($nonceAttributes['threeDSecureInfo'])) {
48
+ $this->_set('threeDSecureInfo', ThreeDSecureInfo::factory($nonceAttributes['threeDSecureInfo']));
49
+ }
50
+ }
51
+ }
52
+ class_alias('Braintree\PaymentMethodNonce', 'Braintree_PaymentMethodNonce');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PaymentMethodNonceGateway.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree PaymentMethodNonceGateway module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+
11
+ /**
12
+ * Creates and manages Braintree PaymentMethodNonces
13
+ *
14
+ * <b>== More information ==</b>
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @category Resources
19
+ */
20
+ class PaymentMethodNonceGateway
21
+ {
22
+ private $_gateway;
23
+ private $_config;
24
+ private $_http;
25
+
26
+ public function __construct($gateway)
27
+ {
28
+ $this->_gateway = $gateway;
29
+ $this->_config = $gateway->config;
30
+ $this->_http = new Http($gateway->config);
31
+ }
32
+
33
+
34
+ public function create($token)
35
+ {
36
+ $subPath = '/payment_methods/' . $token . '/nonces';
37
+ $fullPath = $this->_config->merchantPath() . $subPath;
38
+ $response = $this->_http->post($fullPath);
39
+
40
+ return new Result\Successful(
41
+ PaymentMethodNonce::factory($response['paymentMethodNonce']),
42
+ "paymentMethodNonce"
43
+ );
44
+ }
45
+
46
+ /**
47
+ * @access public
48
+ *
49
+ */
50
+ public function find($nonce)
51
+ {
52
+ try {
53
+ $path = $this->_config->merchantPath() . '/payment_method_nonces/' . $nonce;
54
+ $response = $this->_http->get($path);
55
+ return PaymentMethodNonce::factory($response['paymentMethodNonce']);
56
+ } catch (Exception\NotFound $e) {
57
+ throw new Exception\NotFound(
58
+ 'payment method nonce with id ' . $nonce . ' not found'
59
+ );
60
+ }
61
+
62
+ }
63
+ }
64
+ class_alias('Braintree\PaymentMethodNonceGateway', 'Braintree_PaymentMethodNonceGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Plan.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class Plan extends Base
5
+ {
6
+ public static function factory($attributes)
7
+ {
8
+ $instance = new self();
9
+ $instance->_initialize($attributes);
10
+
11
+ return $instance;
12
+ }
13
+
14
+ protected function _initialize($attributes)
15
+ {
16
+ $this->_attributes = $attributes;
17
+
18
+ $addOnArray = [];
19
+ if (isset($attributes['addOns'])) {
20
+ foreach ($attributes['addOns'] AS $addOn) {
21
+ $addOnArray[] = AddOn::factory($addOn);
22
+ }
23
+ }
24
+ $this->_attributes['addOns'] = $addOnArray;
25
+
26
+ $discountArray = [];
27
+ if (isset($attributes['discounts'])) {
28
+ foreach ($attributes['discounts'] AS $discount) {
29
+ $discountArray[] = Discount::factory($discount);
30
+ }
31
+ }
32
+ $this->_attributes['discounts'] = $discountArray;
33
+
34
+ $planArray = [];
35
+ if (isset($attributes['plans'])) {
36
+ foreach ($attributes['plans'] AS $plan) {
37
+ $planArray[] = self::factory($plan);
38
+ }
39
+ }
40
+ $this->_attributes['plans'] = $planArray;
41
+ }
42
+
43
+
44
+ // static methods redirecting to gateway
45
+
46
+ public static function all()
47
+ {
48
+ return Configuration::gateway()->plan()->all();
49
+ }
50
+ }
51
+ class_alias('Braintree\Plan', 'Braintree_Plan');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/PlanGateway.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class PlanGateway
5
+ {
6
+ private $_gateway;
7
+ private $_config;
8
+ private $_http;
9
+
10
+ public function __construct($gateway)
11
+ {
12
+ $this->_gateway = $gateway;
13
+ $this->_config = $gateway->config;
14
+ $this->_config->assertHasAccessTokenOrKeys();
15
+ $this->_http = new Http($gateway->config);
16
+ }
17
+
18
+ public function all()
19
+ {
20
+ $path = $this->_config->merchantPath() . '/plans';
21
+ $response = $this->_http->get($path);
22
+ if (key_exists('plans', $response)){
23
+ $plans = ["plan" => $response['plans']];
24
+ } else {
25
+ $plans = ["plan" => []];
26
+ }
27
+
28
+ return Util::extractAttributeAsArray(
29
+ $plans,
30
+ 'plan'
31
+ );
32
+ }
33
+ }
34
+ class_alias('Braintree\PlanGateway', 'Braintree_PlanGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/RangeNode.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class RangeNode
5
+ {
6
+ public function __construct($name)
7
+ {
8
+ $this->name = $name;
9
+ $this->searchTerms = [];
10
+ }
11
+
12
+ public function greaterThanOrEqualTo($value)
13
+ {
14
+ $this->searchTerms['min'] = $value;
15
+ return $this;
16
+ }
17
+
18
+ public function lessThanOrEqualTo($value)
19
+ {
20
+ $this->searchTerms['max'] = $value;
21
+ return $this;
22
+ }
23
+
24
+ public function is($value)
25
+ {
26
+ $this->searchTerms['is'] = $value;
27
+ return $this;
28
+ }
29
+
30
+ public function between($min, $max)
31
+ {
32
+ return $this->greaterThanOrEqualTo($min)->lessThanOrEqualTo($max);
33
+ }
34
+
35
+ public function toParam()
36
+ {
37
+ return $this->searchTerms;
38
+ }
39
+ }
40
+ class_alias('Braintree\RangeNode', 'Braintree_RangeNode');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ResourceCollection.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use Iterator;
5
+
6
+ /**
7
+ * Braintree ResourceCollection
8
+ * ResourceCollection is a container object for result data
9
+ *
10
+ * stores and retrieves search results and aggregate data
11
+ *
12
+ * example:
13
+ * <code>
14
+ * $result = Customer::all();
15
+ *
16
+ * foreach($result as $transaction) {
17
+ * print_r($transaction->id);
18
+ * }
19
+ * </code>
20
+ *
21
+ * @package Braintree
22
+ * @subpackage Utility
23
+ */
24
+ class ResourceCollection implements Iterator
25
+ {
26
+ private $_batchIndex;
27
+ private $_ids;
28
+ private $_index;
29
+ private $_items;
30
+ private $_pageSize;
31
+ private $_pager;
32
+
33
+ /**
34
+ * set up the resource collection
35
+ *
36
+ * expects an array of attributes with literal keys
37
+ *
38
+ * @param array $response
39
+ * @param array $pager
40
+ */
41
+ public function __construct($response, $pager)
42
+ {
43
+ $this->_pageSize = $response["searchResults"]["pageSize"];
44
+ $this->_ids = $response["searchResults"]["ids"];
45
+ $this->_pager = $pager;
46
+ }
47
+
48
+ /**
49
+ * returns the current item when iterating with foreach
50
+ */
51
+ public function current()
52
+ {
53
+ return $this->_items[$this->_index];
54
+ }
55
+
56
+ /**
57
+ * returns the first item in the collection
58
+ *
59
+ * @return mixed
60
+ */
61
+ public function firstItem()
62
+ {
63
+ $ids = $this->_ids;
64
+ $page = $this->_getPage([$ids[0]]);
65
+ return $page[0];
66
+ }
67
+
68
+ public function key()
69
+ {
70
+ return null;
71
+ }
72
+
73
+ /**
74
+ * advances to the next item in the collection when iterating with foreach
75
+ */
76
+ public function next()
77
+ {
78
+ ++$this->_index;
79
+ }
80
+
81
+ /**
82
+ * rewinds the testIterateOverResults collection to the first item when iterating with foreach
83
+ */
84
+ public function rewind()
85
+ {
86
+ $this->_batchIndex = 0;
87
+ $this->_getNextPage();
88
+ }
89
+
90
+ /**
91
+ * returns whether the current item is valid when iterating with foreach
92
+ */
93
+ public function valid()
94
+ {
95
+ if ($this->_index == count($this->_items) && $this->_batchIndex < count($this->_ids)) {
96
+ $this->_getNextPage();
97
+ }
98
+
99
+ if ($this->_index < count($this->_items)) {
100
+ return true;
101
+ } else {
102
+ return false;
103
+ }
104
+ }
105
+
106
+ public function maximumCount()
107
+ {
108
+ return count($this->_ids);
109
+ }
110
+
111
+ private function _getNextPage()
112
+ {
113
+ if (empty($this->_ids))
114
+ {
115
+ $this->_items = [];
116
+ }
117
+ else
118
+ {
119
+ $this->_items = $this->_getPage(array_slice($this->_ids, $this->_batchIndex, $this->_pageSize));
120
+ $this->_batchIndex += $this->_pageSize;
121
+ $this->_index = 0;
122
+ }
123
+ }
124
+
125
+ /**
126
+ * requests the next page of results for the collection
127
+ *
128
+ * @return void
129
+ */
130
+ private function _getPage($ids)
131
+ {
132
+ $object = $this->_pager['object'];
133
+ $method = $this->_pager['method'];
134
+ $methodArgs = [];
135
+ foreach ($this->_pager['methodArgs'] as $arg) {
136
+ array_push($methodArgs, $arg);
137
+ }
138
+ array_push($methodArgs, $ids);
139
+
140
+ return call_user_func_array(
141
+ [$object, $method],
142
+ $methodArgs
143
+ );
144
+ }
145
+
146
+ /**
147
+ * returns all IDs in the collection
148
+ *
149
+ * @return array
150
+ */
151
+ public function getIds()
152
+ {
153
+ return $this->_ids;
154
+ }
155
+ }
156
+ class_alias('Braintree\ResourceCollection', 'Braintree_ResourceCollection');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Result/CreditCardVerification.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Result;
3
+
4
+ use Braintree\RiskData;
5
+ use Braintree\Util;
6
+
7
+ /**
8
+ * Braintree Credit Card Verification Result
9
+ *
10
+ * This object is returned as part of an Error Result; it provides
11
+ * access to the credit card verification data from the gateway
12
+ *
13
+ *
14
+ * @package Braintree
15
+ * @subpackage Result
16
+ *
17
+ * @property-read string $avsErrorResponseCode
18
+ * @property-read string $avsPostalCodeResponseCode
19
+ * @property-read string $avsStreetAddressResponseCode
20
+ * @property-read string $cvvResponseCode
21
+ * @property-read string $status
22
+ *
23
+ */
24
+ class CreditCardVerification
25
+ {
26
+ // Status
27
+ const FAILED = 'failed';
28
+ const GATEWAY_REJECTED = 'gateway_rejected';
29
+ const PROCESSOR_DECLINED = 'processor_declined';
30
+ const VERIFIED = 'verified';
31
+
32
+ private $_attributes;
33
+ private $_amount;
34
+ private $_avsErrorResponseCode;
35
+ private $_avsPostalCodeResponseCode;
36
+ private $_avsStreetAddressResponseCode;
37
+ private $_currencyIsoCode;
38
+ private $_cvvResponseCode;
39
+ private $_gatewayRejectionReason;
40
+ private $_status;
41
+
42
+ /**
43
+ * @ignore
44
+ */
45
+ public function __construct($attributes)
46
+ {
47
+ $this->_initializeFromArray($attributes);
48
+ }
49
+
50
+ /**
51
+ * initializes instance properties from the keys/values of an array
52
+ * @ignore
53
+ * @access protected
54
+ * @param <type> $aAttribs array of properties to set - single level
55
+ * @return void
56
+ */
57
+ private function _initializeFromArray($attributes)
58
+ {
59
+ if(isset($attributes['riskData']))
60
+ {
61
+ $attributes['riskData'] = RiskData::factory($attributes['riskData']);
62
+ }
63
+
64
+ $this->_attributes = $attributes;
65
+ foreach($attributes AS $name => $value) {
66
+ $varName = "_$name";
67
+ $this->$varName = $value;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * @ignore
73
+ */
74
+ public function __get($name)
75
+ {
76
+ $varName = "_$name";
77
+ return isset($this->$varName) ? $this->$varName : null;
78
+ }
79
+
80
+ /**
81
+ * returns a string representation of the customer
82
+ * @return string
83
+ */
84
+ public function __toString()
85
+ {
86
+ return __CLASS__ . '[' .
87
+ Util::attributesToString($this->_attributes) . ']';
88
+ }
89
+
90
+ public static function allStatuses()
91
+ {
92
+ return [
93
+ CreditCardVerification::FAILED,
94
+ CreditCardVerification::GATEWAY_REJECTED,
95
+ CreditCardVerification::PROCESSOR_DECLINED,
96
+ CreditCardVerification::VERIFIED
97
+ ];
98
+ }
99
+ }
100
+ class_alias('Braintree\Result\CreditCardVerification', 'Braintree_Result_CreditCardVerification');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Result/Error.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Result;
3
+
4
+ use Braintree\Base;
5
+ use Braintree\Transaction;
6
+ use Braintree\Subscription;
7
+ use Braintree\MerchantAccount;
8
+ use Braintree\Util;
9
+ use Braintree\Error\ErrorCollection;
10
+
11
+ /**
12
+ * Braintree Error Result
13
+ *
14
+ * An Error Result will be returned from gateway methods when
15
+ * the gateway responds with an error. It will provide access
16
+ * to the original request.
17
+ * For example, when voiding a transaction, Error Result will
18
+ * respond to the void request if it failed:
19
+ *
20
+ * <code>
21
+ * $result = Transaction::void('abc123');
22
+ * if ($result->success) {
23
+ * // Successful Result
24
+ * } else {
25
+ * // Result\Error
26
+ * }
27
+ * </code>
28
+ *
29
+ * @package Braintree
30
+ * @subpackage Result
31
+ *
32
+ * @property-read array $params original passed params
33
+ * @property-read \Braintree\Error\ErrorCollection $errors
34
+ * @property-read \Braintree\Result\CreditCardVerification $creditCardVerification credit card verification data
35
+ */
36
+ class Error extends Base
37
+ {
38
+ /**
39
+ * @var bool always false
40
+ */
41
+ public $success = false;
42
+
43
+ /**
44
+ * return original value for a field
45
+ * For example, if a user tried to submit 'invalid-email' in the html field transaction[customer][email],
46
+ * $result->valueForHtmlField("transaction[customer][email]") would yield "invalid-email"
47
+ *
48
+ * @param string $field
49
+ * @return string
50
+ */
51
+ public function valueForHtmlField($field)
52
+ {
53
+ $pieces = preg_split("/[\[\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY);
54
+ $params = $this->params;
55
+ foreach(array_slice($pieces, 0, -1) as $key) {
56
+ $params = $params[Util::delimiterToCamelCase($key)];
57
+ }
58
+ if ($key != 'custom_fields') {
59
+ $finalKey = Util::delimiterToCamelCase(end($pieces));
60
+ } else {
61
+ $finalKey = end($pieces);
62
+ }
63
+ $fieldValue = isset($params[$finalKey]) ? $params[$finalKey] : null;
64
+ return $fieldValue;
65
+ }
66
+
67
+ /**
68
+ * overrides default constructor
69
+ * @ignore
70
+ * @param array $response gateway response array
71
+ */
72
+ public function __construct($response)
73
+ {
74
+ $this->_attributes = $response;
75
+ $this->_set('errors', new ErrorCollection($response['errors']));
76
+
77
+ if(isset($response['verification'])) {
78
+ $this->_set('creditCardVerification', new CreditCardVerification($response['verification']));
79
+ } else {
80
+ $this->_set('creditCardVerification', null);
81
+ }
82
+
83
+ if(isset($response['transaction'])) {
84
+ $this->_set('transaction', Transaction::factory($response['transaction']));
85
+ } else {
86
+ $this->_set('transaction', null);
87
+ }
88
+
89
+ if(isset($response['subscription'])) {
90
+ $this->_set('subscription', Subscription::factory($response['subscription']));
91
+ } else {
92
+ $this->_set('subscription', null);
93
+ }
94
+
95
+ if(isset($response['merchantAccount'])) {
96
+ $this->_set('merchantAccount', MerchantAccount::factory($response['merchantAccount']));
97
+ } else {
98
+ $this->_set('merchantAccount', null);
99
+ }
100
+
101
+ if(isset($response['verification'])) {
102
+ $this->_set('verification', new CreditCardVerification($response['verification']));
103
+ } else {
104
+ $this->_set('verification', null);
105
+ }
106
+ }
107
+
108
+ /**
109
+ * create a printable representation of the object as:
110
+ * ClassName[property=value, property=value]
111
+ * @ignore
112
+ * @return string
113
+ */
114
+ public function __toString()
115
+ {
116
+ $output = Util::attributesToString($this->_attributes);
117
+ if (isset($this->_creditCardVerification)) {
118
+ $output .= sprintf('%s', $this->_creditCardVerification);
119
+ }
120
+ return __CLASS__ .'[' . $output . ']';
121
+ }
122
+ }
123
+ class_alias('Braintree\Result\Error', 'Braintree_Result_Error');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Result/Successful.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Result;
3
+
4
+ use Braintree\Instance;
5
+ use Braintree\Util;
6
+
7
+ /**
8
+ * Braintree Successful Result
9
+ *
10
+ * A Successful Result will be returned from gateway methods when
11
+ * validations pass. It will provide access to the created resource.
12
+ *
13
+ * For example, when creating a customer, Successful will
14
+ * respond to <b>customer</b> like so:
15
+ *
16
+ * <code>
17
+ * $result = Customer::create(array('first_name' => "John"));
18
+ * if ($result->success) {
19
+ * // Successful
20
+ * echo "Created customer {$result->customer->id}";
21
+ * } else {
22
+ * // Error
23
+ * }
24
+ * </code>
25
+ *
26
+ *
27
+ * @package Braintree
28
+ * @subpackage Result
29
+ */
30
+ class Successful extends Instance
31
+ {
32
+ /**
33
+ *
34
+ * @var boolean always true
35
+ */
36
+ public $success = true;
37
+ /**
38
+ *
39
+ * @var string stores the internal name of the object providing access to
40
+ */
41
+ private $_returnObjectNames;
42
+
43
+ /**
44
+ * @ignore
45
+ * @param array|null $objsToReturn
46
+ * @param array|null $propertyNames
47
+ */
48
+ public function __construct($objsToReturn = [], $propertyNames = [])
49
+ {
50
+ // Sanitize arguments (preserves backwards compatibility)
51
+ if (!is_array($objsToReturn)) { $objsToReturn = [$objsToReturn]; }
52
+ if (!is_array($propertyNames)) { $propertyNames = [$propertyNames]; }
53
+
54
+ $objects = $this->_mapPropertyNamesToObjsToReturn($propertyNames, $objsToReturn);
55
+ $this->_attributes = [];
56
+ $this->_returnObjectNames = [];
57
+
58
+ foreach ($objects as $propertyName => $objToReturn) {
59
+
60
+ // save the name for indirect access
61
+ array_push($this->_returnObjectNames, $propertyName);
62
+
63
+ // create the property!
64
+ $this->$propertyName = $objToReturn;
65
+ }
66
+ }
67
+
68
+ /**
69
+ *
70
+ * @ignore
71
+ * @return string string representation of the object's structure
72
+ */
73
+ public function __toString()
74
+ {
75
+ $objects = [];
76
+ foreach ($this->_returnObjectNames as $returnObjectName) {
77
+ array_push($objects, $this->$returnObjectName);
78
+ }
79
+ return __CLASS__ . '[' . implode(', ', $objects) . ']';
80
+ }
81
+
82
+ private function _mapPropertyNamesToObjsToReturn($propertyNames, $objsToReturn) {
83
+ if(count($objsToReturn) != count($propertyNames)) {
84
+ $propertyNames = [];
85
+ foreach ($objsToReturn as $obj) {
86
+ array_push($propertyNames, Util::cleanClassName(get_class($obj)));
87
+ }
88
+ }
89
+ return array_combine($propertyNames, $objsToReturn);
90
+ }
91
+ }
92
+ class_alias('Braintree\Result\Successful', 'Braintree_Result_Successful');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/RiskData.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class RiskData extends Base
5
+ {
6
+ public static function factory($attributes)
7
+ {
8
+ $instance = new self();
9
+ $instance->_initialize($attributes);
10
+
11
+ return $instance;
12
+ }
13
+
14
+ protected function _initialize($attributes)
15
+ {
16
+ $this->_attributes = $attributes;
17
+ }
18
+
19
+ /**
20
+ * returns a string representation of the risk data
21
+ * @return string
22
+ */
23
+ public function __toString()
24
+ {
25
+ return __CLASS__ . '[' .
26
+ Util::attributesToString($this->_attributes) .']';
27
+ }
28
+
29
+ }
30
+ class_alias('Braintree\RiskData', 'Braintree_RiskData');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/SettlementBatchSummary.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class SettlementBatchSummary extends Base
5
+ {
6
+ /**
7
+ *
8
+ * @param array $attributes
9
+ * @return SettlementBatchSummary
10
+ */
11
+ public static function factory($attributes)
12
+ {
13
+ $instance = new self();
14
+ $instance->_initialize($attributes);
15
+ return $instance;
16
+ }
17
+
18
+ /**
19
+ * @ignore
20
+ * @param array $attributes
21
+ */
22
+ protected function _initialize($attributes)
23
+ {
24
+ $this->_attributes = $attributes;
25
+ }
26
+
27
+ public function records()
28
+ {
29
+ return $this->_attributes['records'];
30
+ }
31
+
32
+
33
+ /**
34
+ * static method redirecting to gateway
35
+ *
36
+ * @param string $settlement_date Date YYYY-MM-DD
37
+ * @param string $groupByCustomField
38
+ * @return Result\Successful|Result\Error
39
+ */
40
+ public static function generate($settlement_date, $groupByCustomField = NULL)
41
+ {
42
+ return Configuration::gateway()->settlementBatchSummary()->generate($settlement_date, $groupByCustomField);
43
+ }
44
+ }
45
+ class_alias('Braintree\SettlementBatchSummary', 'Braintree_SettlementBatchSummary');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/SettlementBatchSummaryGateway.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class SettlementBatchSummaryGateway
5
+ {
6
+ /**
7
+ *
8
+ * @var Gateway
9
+ */
10
+ private $_gateway;
11
+
12
+ /**
13
+ *
14
+ * @var Configuration
15
+ */
16
+ private $_config;
17
+
18
+ /**
19
+ *
20
+ * @var Http
21
+ */
22
+ private $_http;
23
+
24
+ /**
25
+ *
26
+ * @param Gateway $gateway
27
+ */
28
+ public function __construct($gateway)
29
+ {
30
+ $this->_gateway = $gateway;
31
+ $this->_config = $gateway->config;
32
+ $this->_config->assertHasAccessTokenOrKeys();
33
+ $this->_http = new Http($gateway->config);
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @param string $settlement_date
39
+ * @param string $groupByCustomField
40
+ * @return SettlementBatchSummary|Result\Error
41
+ */
42
+ public function generate($settlement_date, $groupByCustomField = NULL)
43
+ {
44
+ $criteria = ['settlement_date' => $settlement_date];
45
+ if (isset($groupByCustomField))
46
+ {
47
+ $criteria['group_by_custom_field'] = $groupByCustomField;
48
+ }
49
+ $params = ['settlement_batch_summary' => $criteria];
50
+ $path = $this->_config->merchantPath() . '/settlement_batch_summary';
51
+ $response = $this->_http->post($path, $params);
52
+
53
+ if (isset($groupByCustomField))
54
+ {
55
+ $response['settlementBatchSummary']['records'] = $this->_underscoreCustomField(
56
+ $groupByCustomField,
57
+ $response['settlementBatchSummary']['records']
58
+ );
59
+ }
60
+
61
+ return $this->_verifyGatewayResponse($response);
62
+ }
63
+
64
+ /**
65
+ *
66
+ * @param string $groupByCustomField
67
+ * @param array $records
68
+ * @return array
69
+ */
70
+ private function _underscoreCustomField($groupByCustomField, $records)
71
+ {
72
+ $updatedRecords = [];
73
+
74
+ foreach ($records as $record)
75
+ {
76
+ $camelized = Util::delimiterToCamelCase($groupByCustomField);
77
+ $record[$groupByCustomField] = $record[$camelized];
78
+ unset($record[$camelized]);
79
+ $updatedRecords[] = $record;
80
+ }
81
+
82
+ return $updatedRecords;
83
+ }
84
+
85
+ /**
86
+ *
87
+ * @param array $response
88
+ * @return Result\Successful|Result\Error
89
+ * @throws Exception\Unexpected
90
+ */
91
+ private function _verifyGatewayResponse($response)
92
+ {
93
+ if (isset($response['settlementBatchSummary'])) {
94
+ return new Result\Successful(
95
+ SettlementBatchSummary::factory($response['settlementBatchSummary'])
96
+ );
97
+ } else if (isset($response['apiErrorResponse'])) {
98
+ return new Result\Error($response['apiErrorResponse']);
99
+ } else {
100
+ throw new Exception\Unexpected(
101
+ "Expected settlementBatchSummary or apiErrorResponse"
102
+ );
103
+ }
104
+ }
105
+ }
106
+ class_alias('Braintree\SettlementBatchSummaryGateway', 'Braintree_SettlementBatchSummaryGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/SignatureService.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class SignatureService
5
+ {
6
+
7
+ public function __construct($key, $digest)
8
+ {
9
+ $this->key = $key;
10
+ $this->digest = $digest;
11
+ }
12
+
13
+ public function sign($payload)
14
+ {
15
+ return $this->hash($payload) . "|" . $payload;
16
+ }
17
+
18
+ public function hash($data)
19
+ {
20
+ return call_user_func($this->digest, $this->key, $data);
21
+ }
22
+
23
+ }
24
+ class_alias('Braintree\SignatureService', 'Braintree_SignatureService');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Subscription.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree Subscription module
6
+ *
7
+ * <b>== More information ==</b>
8
+ *
9
+ * For more detailed information on Subscriptions, see {@link http://www.braintreepayments.com/gateway/subscription-api http://www.braintreepaymentsolutions.com/gateway/subscription-api}
10
+ *
11
+ * PHP Version 5
12
+ *
13
+ * @package Braintree
14
+ */
15
+ class Subscription extends Base
16
+ {
17
+ const ACTIVE = 'Active';
18
+ const CANCELED = 'Canceled';
19
+ const EXPIRED = 'Expired';
20
+ const PAST_DUE = 'Past Due';
21
+ const PENDING = 'Pending';
22
+
23
+ // Subscription Sources
24
+ const API = 'api';
25
+ const CONTROL_PANEL = 'control_panel';
26
+ const RECURRING = 'recurring';
27
+
28
+ /**
29
+ * @ignore
30
+ */
31
+ public static function factory($attributes)
32
+ {
33
+ $instance = new self();
34
+ $instance->_initialize($attributes);
35
+
36
+ return $instance;
37
+ }
38
+
39
+ /**
40
+ * @ignore
41
+ */
42
+ protected function _initialize($attributes)
43
+ {
44
+ $this->_attributes = $attributes;
45
+
46
+ $addOnArray = [];
47
+ if (isset($attributes['addOns'])) {
48
+ foreach ($attributes['addOns'] AS $addOn) {
49
+ $addOnArray[] = AddOn::factory($addOn);
50
+ }
51
+ }
52
+ $this->_attributes['addOns'] = $addOnArray;
53
+
54
+ $discountArray = [];
55
+ if (isset($attributes['discounts'])) {
56
+ foreach ($attributes['discounts'] AS $discount) {
57
+ $discountArray[] = Discount::factory($discount);
58
+ }
59
+ }
60
+ $this->_attributes['discounts'] = $discountArray;
61
+
62
+ if (isset($attributes['descriptor'])) {
63
+ $this->_set('descriptor', new Descriptor($attributes['descriptor']));
64
+ }
65
+
66
+ $statusHistory = [];
67
+ if (isset($attributes['statusHistory'])) {
68
+ foreach ($attributes['statusHistory'] AS $history) {
69
+ $statusHistory[] = new Subscription\StatusDetails($history);
70
+ }
71
+ }
72
+ $this->_attributes['statusHistory'] = $statusHistory;
73
+
74
+ $transactionArray = [];
75
+ if (isset($attributes['transactions'])) {
76
+ foreach ($attributes['transactions'] AS $transaction) {
77
+ $transactionArray[] = Transaction::factory($transaction);
78
+ }
79
+ }
80
+ $this->_attributes['transactions'] = $transactionArray;
81
+ }
82
+
83
+ /**
84
+ * returns a string representation of the customer
85
+ * @return string
86
+ */
87
+ public function __toString()
88
+ {
89
+ $excludedAttributes = ['statusHistory'];
90
+
91
+ $displayAttributes = [];
92
+ foreach($this->_attributes as $key => $val) {
93
+ if (!in_array($key, $excludedAttributes)) {
94
+ $displayAttributes[$key] = $val;
95
+ }
96
+ }
97
+
98
+ return __CLASS__ . '[' .
99
+ Util::attributesToString($displayAttributes) .']';
100
+ }
101
+
102
+
103
+ // static methods redirecting to gateway
104
+
105
+ public static function create($attributes)
106
+ {
107
+ return Configuration::gateway()->subscription()->create($attributes);
108
+ }
109
+
110
+ public static function find($id)
111
+ {
112
+ return Configuration::gateway()->subscription()->find($id);
113
+ }
114
+
115
+ public static function search($query)
116
+ {
117
+ return Configuration::gateway()->subscription()->search($query);
118
+ }
119
+
120
+ public static function fetch($query, $ids)
121
+ {
122
+ return Configuration::gateway()->subscription()->fetch($query, $ids);
123
+ }
124
+
125
+ public static function update($subscriptionId, $attributes)
126
+ {
127
+ return Configuration::gateway()->subscription()->update($subscriptionId, $attributes);
128
+ }
129
+
130
+ public static function retryCharge($subscriptionId, $amount = null)
131
+ {
132
+ return Configuration::gateway()->subscription()->retryCharge($subscriptionId, $amount);
133
+ }
134
+
135
+ public static function cancel($subscriptionId)
136
+ {
137
+ return Configuration::gateway()->subscription()->cancel($subscriptionId);
138
+ }
139
+ }
140
+ class_alias('Braintree\Subscription', 'Braintree_Subscription');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Subscription/StatusDetails.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Subscription;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * Status details from a subscription
8
+ * Creates an instance of StatusDetails, as part of a subscription response
9
+ *
10
+ * @package Braintree
11
+ *
12
+ * @property-read string $price
13
+ * @property-read string $currencyIsoCode
14
+ * @property-read string $planId
15
+ * @property-read string $balance
16
+ * @property-read string $status
17
+ * @property-read string $timestamp
18
+ * @property-read string $subscriptionSource
19
+ * @property-read string $user
20
+ */
21
+ class StatusDetails extends Instance
22
+ {
23
+ }
24
+ class_alias('Braintree\Subscription\StatusDetails', 'Braintree_Subscription_StatusDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/SubscriptionGateway.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ /**
7
+ * Braintree SubscriptionGateway module
8
+ *
9
+ * <b>== More information ==</b>
10
+ *
11
+ * For more detailed information on Subscriptions, see {@link http://www.braintreepayments.com/gateway/subscription-api http://www.braintreepaymentsolutions.com/gateway/subscription-api}
12
+ *
13
+ * PHP Version 5
14
+ *
15
+ * @package Braintree
16
+ */
17
+ class SubscriptionGateway
18
+ {
19
+ private $_gateway;
20
+ private $_config;
21
+ private $_http;
22
+
23
+ public function __construct($gateway)
24
+ {
25
+ $this->_gateway = $gateway;
26
+ $this->_config = $gateway->config;
27
+ $this->_config->assertHasAccessTokenOrKeys();
28
+ $this->_http = new Http($gateway->config);
29
+ }
30
+
31
+ public function create($attributes)
32
+ {
33
+ Util::verifyKeys(self::_createSignature(), $attributes);
34
+ $path = $this->_config->merchantPath() . '/subscriptions';
35
+ $response = $this->_http->post($path, ['subscription' => $attributes]);
36
+ return $this->_verifyGatewayResponse($response);
37
+ }
38
+
39
+ public function find($id)
40
+ {
41
+ $this->_validateId($id);
42
+
43
+ try {
44
+ $path = $this->_config->merchantPath() . '/subscriptions/' . $id;
45
+ $response = $this->_http->get($path);
46
+ return Subscription::factory($response['subscription']);
47
+ } catch (Exception\NotFound $e) {
48
+ throw new Exception\NotFound('subscription with id ' . $id . ' not found');
49
+ }
50
+
51
+ }
52
+
53
+ public function search($query)
54
+ {
55
+ $criteria = [];
56
+ foreach ($query as $term) {
57
+ $criteria[$term->name] = $term->toparam();
58
+ }
59
+
60
+
61
+ $path = $this->_config->merchantPath() . '/subscriptions/advanced_search_ids';
62
+ $response = $this->_http->post($path, ['search' => $criteria]);
63
+ $pager = [
64
+ 'object' => $this,
65
+ 'method' => 'fetch',
66
+ 'methodArgs' => [$query]
67
+ ];
68
+
69
+ return new ResourceCollection($response, $pager);
70
+ }
71
+
72
+ public function fetch($query, $ids)
73
+ {
74
+ $criteria = [];
75
+ foreach ($query as $term) {
76
+ $criteria[$term->name] = $term->toparam();
77
+ }
78
+ $criteria["ids"] = SubscriptionSearch::ids()->in($ids)->toparam();
79
+ $path = $this->_config->merchantPath() . '/subscriptions/advanced_search';
80
+ $response = $this->_http->post($path, ['search' => $criteria]);
81
+
82
+ return Util::extractAttributeAsArray(
83
+ $response['subscriptions'],
84
+ 'subscription'
85
+ );
86
+ }
87
+
88
+ public function update($subscriptionId, $attributes)
89
+ {
90
+ Util::verifyKeys(self::_updateSignature(), $attributes);
91
+ $path = $this->_config->merchantPath() . '/subscriptions/' . $subscriptionId;
92
+ $response = $this->_http->put($path, ['subscription' => $attributes]);
93
+ return $this->_verifyGatewayResponse($response);
94
+ }
95
+
96
+ public function retryCharge($subscriptionId, $amount = null)
97
+ {
98
+ $transaction_params = ['type' => Transaction::SALE,
99
+ 'subscriptionId' => $subscriptionId];
100
+ if (isset($amount)) {
101
+ $transaction_params['amount'] = $amount;
102
+ }
103
+
104
+ $path = $this->_config->merchantPath() . '/transactions';
105
+ $response = $this->_http->post($path, ['transaction' => $transaction_params]);
106
+ return $this->_verifyGatewayResponse($response);
107
+ }
108
+
109
+ public function cancel($subscriptionId)
110
+ {
111
+ $path = $this->_config->merchantPath() . '/subscriptions/' . $subscriptionId . '/cancel';
112
+ $response = $this->_http->put($path);
113
+ return $this->_verifyGatewayResponse($response);
114
+ }
115
+
116
+ private static function _createSignature()
117
+ {
118
+ return array_merge(
119
+ [
120
+ 'billingDayOfMonth',
121
+ 'firstBillingDate',
122
+ 'createdAt',
123
+ 'updatedAt',
124
+ 'id',
125
+ 'merchantAccountId',
126
+ 'neverExpires',
127
+ 'numberOfBillingCycles',
128
+ 'paymentMethodToken',
129
+ 'paymentMethodNonce',
130
+ 'planId',
131
+ 'price',
132
+ 'trialDuration',
133
+ 'trialDurationUnit',
134
+ 'trialPeriod',
135
+ ['descriptor' => ['name', 'phone', 'url']],
136
+ ['options' => ['doNotInheritAddOnsOrDiscounts', 'startImmediately']],
137
+ ],
138
+ self::_addOnDiscountSignature()
139
+ );
140
+ }
141
+
142
+ private static function _updateSignature()
143
+ {
144
+ return array_merge(
145
+ [
146
+ 'merchantAccountId', 'numberOfBillingCycles', 'paymentMethodToken', 'planId',
147
+ 'paymentMethodNonce', 'id', 'neverExpires', 'price',
148
+ ['descriptor' => ['name', 'phone', 'url']],
149
+ ['options' => ['prorateCharges', 'replaceAllAddOnsAndDiscounts', 'revertSubscriptionOnProrationFailure']],
150
+ ],
151
+ self::_addOnDiscountSignature()
152
+ );
153
+ }
154
+
155
+ private static function _addOnDiscountSignature()
156
+ {
157
+ return [
158
+ [
159
+ 'addOns' => [
160
+ ['add' => ['amount', 'inheritedFromId', 'neverExpires', 'numberOfBillingCycles', 'quantity']],
161
+ ['update' => ['amount', 'existingId', 'neverExpires', 'numberOfBillingCycles', 'quantity']],
162
+ ['remove' => ['_anyKey_']],
163
+ ]
164
+ ],
165
+ [
166
+ 'discounts' => [
167
+ ['add' => ['amount', 'inheritedFromId', 'neverExpires', 'numberOfBillingCycles', 'quantity']],
168
+ ['update' => ['amount', 'existingId', 'neverExpires', 'numberOfBillingCycles', 'quantity']],
169
+ ['remove' => ['_anyKey_']],
170
+ ]
171
+ ]
172
+ ];
173
+ }
174
+
175
+ /**
176
+ * @ignore
177
+ */
178
+ private function _validateId($id = null) {
179
+ if (empty($id)) {
180
+ throw new InvalidArgumentException(
181
+ 'expected subscription id to be set'
182
+ );
183
+ }
184
+ if (!preg_match('/^[0-9A-Za-z_-]+$/', $id)) {
185
+ throw new InvalidArgumentException(
186
+ $id . ' is an invalid subscription id.'
187
+ );
188
+ }
189
+ }
190
+
191
+ /**
192
+ * @ignore
193
+ */
194
+ private function _verifyGatewayResponse($response)
195
+ {
196
+ if (isset($response['subscription'])) {
197
+ return new Result\Successful(
198
+ Subscription::factory($response['subscription'])
199
+ );
200
+ } else if (isset($response['transaction'])) {
201
+ // return a populated instance of Transaction, for subscription retryCharge
202
+ return new Result\Successful(
203
+ Transaction::factory($response['transaction'])
204
+ );
205
+ } else if (isset($response['apiErrorResponse'])) {
206
+ return new Result\Error($response['apiErrorResponse']);
207
+ } else {
208
+ throw new Exception\Unexpected(
209
+ "Expected subscription, transaction, or apiErrorResponse"
210
+ );
211
+ }
212
+ }
213
+ }
214
+ class_alias('Braintree\SubscriptionGateway', 'Braintree_SubscriptionGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/SubscriptionSearch.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class SubscriptionSearch
5
+ {
6
+ public static function billingCyclesRemaining()
7
+ {
8
+ return new RangeNode('billing_cycles_remaining');
9
+ }
10
+
11
+ public static function daysPastDue()
12
+ {
13
+ return new RangeNode('days_past_due');
14
+ }
15
+
16
+ public static function id()
17
+ {
18
+ return new TextNode('id');
19
+ }
20
+
21
+ public static function inTrialPeriod()
22
+ {
23
+ return new MultipleValueNode('in_trial_period', [true, false]);
24
+ }
25
+
26
+ public static function merchantAccountId()
27
+ {
28
+ return new MultipleValueNode('merchant_account_id');
29
+ }
30
+
31
+ public static function nextBillingDate()
32
+ {
33
+ return new RangeNode('next_billing_date');
34
+ }
35
+
36
+ public static function planId()
37
+ {
38
+ return new MultipleValueOrTextNode('plan_id');
39
+ }
40
+
41
+ public static function price()
42
+ {
43
+ return new RangeNode('price');
44
+ }
45
+
46
+ public static function status()
47
+ {
48
+ return new MultipleValueNode('status', [
49
+ Subscription::ACTIVE,
50
+ Subscription::CANCELED,
51
+ Subscription::EXPIRED,
52
+ Subscription::PAST_DUE,
53
+ Subscription::PENDING,
54
+ ]);
55
+ }
56
+
57
+ public static function transactionId()
58
+ {
59
+ return new TextNode('transaction_id');
60
+ }
61
+
62
+ public static function ids()
63
+ {
64
+ return new MultipleValueNode('ids');
65
+ }
66
+
67
+ public static function createdAt()
68
+ {
69
+ return new RangeNode('created_at');
70
+ }
71
+ }
72
+ class_alias('Braintree\SubscriptionSearch', 'Braintree_SubscriptionSearch');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/CreditCardNumbers.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Test;
3
+
4
+ /**
5
+ * Credit card information used for testing purposes
6
+ *
7
+ * The constants contained in the Test\CreditCardNumbers class provide
8
+ * credit card numbers that should be used when working in the sandbox environment.
9
+ * The sandbox will not accept any credit card numbers other than the ones listed below.
10
+ *
11
+ * @package Braintree
12
+ * @subpackage Test
13
+ */
14
+ class CreditCardNumbers
15
+ {
16
+ public static $amExes = [
17
+ '378282246310005',
18
+ '371449635398431',
19
+ '378734493671000',
20
+ ];
21
+ public static $carteBlanches = ['30569309025904',];
22
+ public static $dinersClubs = ['38520000023237',];
23
+ public static $discoverCards = [
24
+ '6011111111111117',
25
+ '6011000990139424',
26
+ ];
27
+ public static $JCBs = [
28
+ '3530111333300000',
29
+ '3566002020360505',
30
+ ];
31
+
32
+ public static $masterCard = '5555555555554444';
33
+ public static $masterCardInternational = '5105105105105100';
34
+ public static $masterCards = [
35
+ '5105105105105100',
36
+ '5555555555554444',
37
+ ];
38
+
39
+ public static $visa = '4012888888881881';
40
+ public static $visaInternational = '4009348888881881';
41
+ public static $visas = [
42
+ '4009348888881881',
43
+ '4012888888881881',
44
+ '4111111111111111',
45
+ '4000111111111115',
46
+ ];
47
+
48
+ public static $unknowns = [
49
+ '1000000000000008',
50
+ ];
51
+
52
+ public static $failsSandboxVerification = [
53
+ 'AmEx' => '378734493671000',
54
+ 'Discover' => '6011000990139424',
55
+ 'MasterCard' => '5105105105105100',
56
+ 'Visa' => '4000111111111115',
57
+ ];
58
+
59
+ public static $amexPayWithPoints = [
60
+ 'Success' => "371260714673002",
61
+ 'IneligibleCard' => "378267515471109",
62
+ 'InsufficientPoints' => "371544868764018",
63
+ ];
64
+
65
+ public static function getAll()
66
+ {
67
+ return array_merge(
68
+ self::$amExes,
69
+ self::$discoverCards,
70
+ self::$masterCards,
71
+ self::$visas
72
+ );
73
+ }
74
+ }
75
+ class_alias('Braintree\Test\CreditCardNumbers', 'Braintree_Test_CreditCardNumbers');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/MerchantAccount.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Test;
3
+
4
+ /**
5
+ * Merchant Account constants used for testing purposes
6
+ *
7
+ * @package Braintree
8
+ * @subpackage Test
9
+ */
10
+ class MerchantAccount
11
+ {
12
+ public static $approve = "approve_me";
13
+
14
+ public static $insufficientFundsContactUs = "insufficient_funds__contact";
15
+ public static $accountNotAuthorizedContactUs = "account_not_authorized__contact";
16
+ public static $bankRejectedUpdateFundingInformation = "bank_rejected__update";
17
+ public static $bankRejectedNone = "bank_rejected__none";
18
+
19
+
20
+ }
21
+ class_alias('Braintree\Test\MerchantAccount', 'Braintree_Test_MerchantAccount');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/Nonces.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Test;
3
+
4
+ /**
5
+ * Nonces used for testing purposes
6
+ *
7
+ * @package Braintree
8
+ * @subpackage Test
9
+ */
10
+
11
+ /**
12
+ * Nonces used for testing purposes
13
+ *
14
+ * The constants in this class can be used to perform nonce operations
15
+ * with the desired status in the sandbox environment.
16
+ *
17
+ * @package Braintree
18
+ * @subpackage Test
19
+ */
20
+ class Nonces
21
+ {
22
+ public static $transactable = "fake-valid-nonce";
23
+ public static $consumed = "fake-consumed-nonce";
24
+ public static $paypalOneTimePayment = "fake-paypal-one-time-nonce";
25
+ public static $paypalFuturePayment = "fake-paypal-future-nonce";
26
+ public static $paypalBillingAgreement = "fake-paypal-billing-agreement-nonce";
27
+ public static $applePayVisa = "fake-apple-pay-visa-nonce";
28
+ public static $applePayMasterCard = "fake-apple-pay-visa-nonce";
29
+ public static $applePayAmEx = "fake-apple-pay-amex-nonce";
30
+ public static $androidPay = "fake-android-pay-nonce";
31
+ public static $androidPayDiscover = "fake-android-pay-discover-nonce";
32
+ public static $androidPayVisa = "fake-android-pay-visa-nonce";
33
+ public static $androidPayMasterCard = "fake-android-pay-mastercard-nonce";
34
+ public static $androidPayAmEx = "fake-android-pay-amex-nonce";
35
+ public static $amexExpressCheckout = "fake-amex-express-checkout-nonce";
36
+ public static $abstractTransactable = "fake-abstract-transactable-nonce";
37
+ public static $europe = "fake-europe-bank-account-nonce";
38
+ public static $coinbase = "fake-coinbase-nonce";
39
+ public static $transactableVisa = "fake-valid-visa-nonce";
40
+ public static $transactableAmEx = "fake-valid-amex-nonce";
41
+ public static $transactableMasterCard = "fake-valid-mastercard-nonce";
42
+ public static $transactableDiscover = "fake-valid-discover-nonce";
43
+ public static $transactableJCB = "fake-valid-jcb-nonce";
44
+ public static $transactableMaestro = "fake-valid-maestro-nonce";
45
+ public static $transactableDinersClub = "fake-valid-dinersclub-nonce";
46
+ public static $transactablePrepaid = "fake-valid-prepaid-nonce";
47
+ public static $transactableCommercial = "fake-valid-commercial-nonce";
48
+ public static $transactableDurbinRegulated = "fake-valid-durbin-regulated-nonce";
49
+ public static $transactableHealthcare = "fake-valid-healthcare-nonce";
50
+ public static $transactableDebit = "fake-valid-debit-nonce";
51
+ public static $transactablePayroll = "fake-valid-payroll-nonce";
52
+ public static $transactableNoIndicators = "fake-valid-no-indicators-nonce";
53
+ public static $transactableUnknownIndicators = "fake-valid-unknown-indicators-nonce";
54
+ public static $transactableCountryOfIssuanceUSA = "fake-valid-country-of-issuance-usa-nonce";
55
+ public static $transactableCountryOfIssuanceCAD = "fake-valid-country-of-issuance-cad-nonce";
56
+ public static $transactableIssuingBankNetworkOnly = "fake-valid-issuing-bank-network-only-nonce";
57
+ public static $processorDeclinedVisa = "fake-processor-declined-visa-nonce";
58
+ public static $processorDeclinedMasterCard = "fake-processor-declined-mastercard-nonce";
59
+ public static $processorDeclinedAmEx = "fake-processor-declined-amex-nonce";
60
+ public static $processorDeclinedDiscover = "fake-processor-declined-discover-nonce";
61
+ public static $processorFailureJCB = "fake-processor-failure-jcb-nonce";
62
+ public static $luhnInvalid = "fake-luhn-invalid-nonce";
63
+ public static $paypalFuturePaymentRefreshToken = "fake-paypal-future-refresh-token-nonce";
64
+ public static $sepa = "fake-sepa-bank-account-nonce";
65
+ public static $gatewayRejectedFraud = "fake-gateway-rejected-fraud-nonce";
66
+ public static $venmoAccount = "fake-venmo-account-nonce";
67
+ public static $visaCheckoutAmEx = "fake-visa-checkout-amex-nonce";
68
+ public static $visaCheckoutDiscover = "fake-visa-checkout-discover-nonce";
69
+ public static $visaCheckoutMasterCard = "fake-visa-checkout-mastercard-nonce";
70
+ public static $visaCheckoutVisa = "fake-visa-checkout-visa-nonce";
71
+ public static $masterpassAmEx = "fake-masterpass-amex-nonce";
72
+ public static $masterpassDiscover = "fake-masterpass-discover-nonce";
73
+ public static $masterpassMasterCard = "fake-masterpass-mastercard-nonce";
74
+ public static $masterpassVisa = "fake-masterpass-visa-nonce";
75
+ }
76
+ class_alias('Braintree\Test\Nonces', 'Braintree_Test_Nonces');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/Transaction.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Test;
3
+
4
+ use Braintree\Configuration;
5
+
6
+ /**
7
+ * Transaction amounts used for testing purposes
8
+ *
9
+ * The constants in this class can be used to create transactions with
10
+ * the desired status in the sandbox environment.
11
+ */
12
+ class Transaction
13
+ {
14
+ /**
15
+ * settle a transaction by id in sandbox
16
+ *
17
+ * @param string $id transaction id
18
+ * @param Configuration $config gateway config
19
+ * @return Transaction
20
+ */
21
+ public static function settle($transactionId)
22
+ {
23
+ return Configuration::gateway()->testing()->settle($transactionId);
24
+ }
25
+
26
+ /**
27
+ * settlement confirm a transaction by id in sandbox
28
+ *
29
+ * @param string $id transaction id
30
+ * @param Configuration $config gateway config
31
+ * @return Transaction
32
+ */
33
+ public static function settlementConfirm($transactionId)
34
+ {
35
+ return Configuration::gateway()->testing()->settlementConfirm($transactionId);
36
+ }
37
+
38
+ /**
39
+ * settlement decline a transaction by id in sandbox
40
+ *
41
+ * @param string $id transaction id
42
+ * @param Configuration $config gateway config
43
+ * @return Transaction
44
+ */
45
+ public static function settlementDecline($transactionId)
46
+ {
47
+ return Configuration::gateway()->testing()->settlementDecline($transactionId);
48
+ }
49
+
50
+ /**
51
+ * settlement pending a transaction by id in sandbox
52
+ *
53
+ * @param string $id transaction id
54
+ * @param Configuration $config gateway config
55
+ * @return Transaction
56
+ */
57
+ public static function settlementPending($transactionId)
58
+ {
59
+ return Configuration::gateway()->testing()->settlementPending($transactionId);
60
+ }
61
+ }
62
+ class_alias('Braintree\Test\Transaction', 'Braintree_Test_Transaction');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/TransactionAmounts.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Test;
3
+
4
+ /**
5
+ * Transaction amounts used for testing purposes
6
+ *
7
+ * The constants in this class can be used to create transactions with
8
+ * the desired status in the sandbox environment.
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Test
12
+ */
13
+ class TransactionAmounts
14
+ {
15
+ public static $authorize = '1000.00';
16
+ public static $decline = '2000.00';
17
+ }
18
+ class_alias('Braintree\Test\TransactionAmounts', 'Braintree_Test_TransactionAmounts');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Test/VenmoSdk.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Test;
3
+
4
+ /**
5
+ * VenmoSdk payment method codes used for testing purposes
6
+ *
7
+ * @package Braintree
8
+ * @subpackage Test
9
+ */
10
+ class VenmoSdk
11
+ {
12
+ public static $visaPaymentMethodCode = "stub-4111111111111111";
13
+
14
+ public static function generateTestPaymentMethodCode($number) {
15
+ return "stub-" . $number;
16
+ }
17
+
18
+ public static function getInvalidPaymentMethodCode() {
19
+ return "stub-invalid-payment-method-code";
20
+ }
21
+
22
+ public static function getTestSession() {
23
+ return "stub-session";
24
+ }
25
+
26
+ public static function getInvalidTestSession() {
27
+ return "stub-invalid-session";
28
+ }
29
+ }
30
+ class_alias('Braintree\Test\VenmoSdk', 'Braintree_Test_VenmoSdk');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TestingGateway.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class TestingGateway
5
+ {
6
+ private $_gateway;
7
+ private $_config;
8
+ private $_http;
9
+
10
+ public function __construct($gateway)
11
+ {
12
+ $this->_gateway = $gateway;
13
+ $this->_config = $gateway->config;
14
+ $this->_http = new Http($this->_config);
15
+ }
16
+
17
+ public function settle($transactionId)
18
+ {
19
+ return self::_doTestRequest('/settle', $transactionId);
20
+ }
21
+
22
+ public function settlementPending($transactionId)
23
+ {
24
+ return self::_doTestRequest('/settlement_pending', $transactionId);
25
+ }
26
+
27
+ public function settlementConfirm($transactionId)
28
+ {
29
+ return self::_doTestRequest('/settlement_confirm', $transactionId);
30
+ }
31
+
32
+ public function settlementDecline($transactionId)
33
+ {
34
+ return self::_doTestRequest('/settlement_decline', $transactionId);
35
+ }
36
+
37
+ private function _doTestRequest($testPath, $transactionId)
38
+ {
39
+ self::_checkEnvironment();
40
+ $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . $testPath;
41
+ $response = $this->_http->put($path);
42
+ return Transaction::factory($response['transaction']);
43
+ }
44
+
45
+ private function _checkEnvironment()
46
+ {
47
+ if (Configuration::$global->getEnvironment() === 'production') {
48
+ throw new Exception\TestOperationPerformedInProduction();
49
+ }
50
+ }
51
+ }
52
+ class_alias('Braintree\TestingGateway', 'Braintree_TestingGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TextNode.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class TextNode extends PartialMatchNode
5
+ {
6
+ public function contains($value)
7
+ {
8
+ $this->searchTerms["contains"] = strval($value);
9
+ return $this;
10
+ }
11
+ }
12
+ class_alias('Braintree\TextNode', 'Braintree_TextNode');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/ThreeDSecureInfo.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class ThreeDSecureInfo extends Base
5
+ {
6
+ public static function factory($attributes)
7
+ {
8
+ $instance = new self();
9
+ $instance->_initialize($attributes);
10
+
11
+ return $instance;
12
+ }
13
+
14
+ protected function _initialize($attributes)
15
+ {
16
+ $this->_attributes = $attributes;
17
+ }
18
+
19
+ /**
20
+ * returns a string representation of the three d secure info
21
+ * @return string
22
+ */
23
+ public function __toString()
24
+ {
25
+ return __CLASS__ . '[' .
26
+ Util::attributesToString($this->_attributes) .']';
27
+ }
28
+
29
+ }
30
+ class_alias('Braintree\ThreeDSecureInfo', 'Braintree_ThreeDSecureInfo');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction.php ADDED
@@ -0,0 +1,596 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree Transaction processor
6
+ * Creates and manages transactions
7
+ *
8
+ * At minimum, an amount, credit card number, and
9
+ * credit card expiration date are required.
10
+ *
11
+ * <b>Minimalistic example:</b>
12
+ * <code>
13
+ * Transaction::saleNoValidate(array(
14
+ * 'amount' => '100.00',
15
+ * 'creditCard' => array(
16
+ * 'number' => '5105105105105100',
17
+ * 'expirationDate' => '05/12',
18
+ * ),
19
+ * ));
20
+ * </code>
21
+ *
22
+ * <b>Full example:</b>
23
+ * <code>
24
+ * Transaction::saleNoValidate(array(
25
+ * 'amount' => '100.00',
26
+ * 'orderId' => '123',
27
+ * 'channel' => 'MyShoppingCardProvider',
28
+ * 'creditCard' => array(
29
+ * // if token is omitted, the gateway will generate a token
30
+ * 'token' => 'credit_card_123',
31
+ * 'number' => '5105105105105100',
32
+ * 'expirationDate' => '05/2011',
33
+ * 'cvv' => '123',
34
+ * ),
35
+ * 'customer' => array(
36
+ * // if id is omitted, the gateway will generate an id
37
+ * 'id' => 'customer_123',
38
+ * 'firstName' => 'Dan',
39
+ * 'lastName' => 'Smith',
40
+ * 'company' => 'Braintree',
41
+ * 'email' => 'dan@example.com',
42
+ * 'phone' => '419-555-1234',
43
+ * 'fax' => '419-555-1235',
44
+ * 'website' => 'http://braintreepayments.com'
45
+ * ),
46
+ * 'billing' => array(
47
+ * 'firstName' => 'Carl',
48
+ * 'lastName' => 'Jones',
49
+ * 'company' => 'Braintree',
50
+ * 'streetAddress' => '123 E Main St',
51
+ * 'extendedAddress' => 'Suite 403',
52
+ * 'locality' => 'Chicago',
53
+ * 'region' => 'IL',
54
+ * 'postalCode' => '60622',
55
+ * 'countryName' => 'United States of America'
56
+ * ),
57
+ * 'shipping' => array(
58
+ * 'firstName' => 'Andrew',
59
+ * 'lastName' => 'Mason',
60
+ * 'company' => 'Braintree',
61
+ * 'streetAddress' => '456 W Main St',
62
+ * 'extendedAddress' => 'Apt 2F',
63
+ * 'locality' => 'Bartlett',
64
+ * 'region' => 'IL',
65
+ * 'postalCode' => '60103',
66
+ * 'countryName' => 'United States of America'
67
+ * ),
68
+ * 'customFields' => array(
69
+ * 'birthdate' => '11/13/1954'
70
+ * )
71
+ * )
72
+ * </code>
73
+ *
74
+ * <b>== Storing in the Vault ==</b>
75
+ *
76
+ * The customer and credit card information used for
77
+ * a transaction can be stored in the vault by setting
78
+ * <i>transaction[options][storeInVault]</i> to true.
79
+ * <code>
80
+ * $transaction = Transaction::saleNoValidate(array(
81
+ * 'customer' => array(
82
+ * 'firstName' => 'Adam',
83
+ * 'lastName' => 'Williams'
84
+ * ),
85
+ * 'creditCard' => array(
86
+ * 'number' => '5105105105105100',
87
+ * 'expirationDate' => '05/2012'
88
+ * ),
89
+ * 'options' => array(
90
+ * 'storeInVault' => true
91
+ * )
92
+ * ));
93
+ *
94
+ * echo $transaction->customerDetails->id
95
+ * // '865534'
96
+ * echo $transaction->creditCardDetails->token
97
+ * // '6b6m'
98
+ * </code>
99
+ *
100
+ * To also store the billing address in the vault, pass the
101
+ * <b>addBillingAddressToPaymentMethod</b> option.
102
+ * <code>
103
+ * Transaction.saleNoValidate(array(
104
+ * ...
105
+ * 'options' => array(
106
+ * 'storeInVault' => true
107
+ * 'addBillingAddressToPaymentMethod' => true
108
+ * )
109
+ * ));
110
+ * </code>
111
+ *
112
+ * <b>== Submitting for Settlement==</b>
113
+ *
114
+ * This can only be done when the transction's
115
+ * status is <b>authorized</b>. If <b>amount</b> is not specified,
116
+ * the full authorized amount will be settled. If you would like to settle
117
+ * less than the full authorized amount, pass the desired amount.
118
+ * You cannot settle more than the authorized amount.
119
+ *
120
+ * A transaction can be submitted for settlement when created by setting
121
+ * $transaction[options][submitForSettlement] to true.
122
+ *
123
+ * <code>
124
+ * $transaction = Transaction::saleNoValidate(array(
125
+ * 'amount' => '100.00',
126
+ * 'creditCard' => array(
127
+ * 'number' => '5105105105105100',
128
+ * 'expirationDate' => '05/2012'
129
+ * ),
130
+ * 'options' => array(
131
+ * 'submitForSettlement' => true
132
+ * )
133
+ * ));
134
+ * </code>
135
+ *
136
+ * <b>== More information ==</b>
137
+ *
138
+ * For more detailed information on Transactions, see {@link http://www.braintreepayments.com/gateway/transaction-api http://www.braintreepaymentsolutions.com/gateway/transaction-api}
139
+ *
140
+ * @package Braintree
141
+ * @category Resources
142
+ *
143
+ *
144
+ * @property-read string $avsErrorResponseCode
145
+ * @property-read string $avsPostalCodeResponseCode
146
+ * @property-read string $avsStreetAddressResponseCode
147
+ * @property-read string $cvvResponseCode
148
+ * @property-read string $id transaction id
149
+ * @property-read string $amount transaction amount
150
+ * @property-read Braintree\Transaction\AddressDetails $billingDetails transaction billing address
151
+ * @property-read \DateTime $createdAt transaction created DateTime
152
+ * @property-read Braintree\ApplePayCardDetails $applePayCardDetails transaction Apple Pay card info
153
+ * @property-read Braintree\AndroidPayCardDetails $androidPayCardDetails transaction Android Pay card info
154
+ * @property-read Braintree\AmexExpressCheckoutCardDetails $amexExpressCheckoutCardDetails transaction Amex Express Checkout card info
155
+ * @property-read Braintree\CreditCardDetails $creditCardDetails transaction credit card info
156
+ * @property-read Braintree\CoinbaseDetails $coinbaseDetails transaction Coinbase account info
157
+ * @property-read Braintree\MasterpassCardDetails $masterpassCardDetails transaction Masterpass card info
158
+ * @property-read Braintree\PayPalDetails $paypalDetails transaction paypal account info
159
+ * @property-read Braintree\Transaction\CustomerDetails $customerDetails transaction customer info
160
+ * @property-read Braintree\VenmoAccount $venmoAccountDetails transaction Venmo Account info
161
+ * @property-read Braintree\IdealPayment $idealPaymentDetails transaction Ideal Payment info
162
+ * @property-read Braintree\VisaCheckoutCardDetails $visaCheckoutCardDetails transaction Visa Checkout card info
163
+ * @property-read array $customFields custom fields passed with the request
164
+ * @property-read string $processorResponseCode gateway response code
165
+ * @property-read string $additionalProcessorResponse raw response from processor
166
+ * @property-read Braintree\Transaction\AddressDetails $shippingDetails transaction shipping address
167
+ * @property-read string $status transaction status
168
+ * @property-read array $statusHistory array of StatusDetails objects
169
+ * @property-read string $type transaction type
170
+ * @property-read \DateTime $updatedAt transaction updated DateTime
171
+ * @property-read Braintree\Disbursement $disbursementDetails populated when transaction is disbursed
172
+ * @property-read Braintree\Dispute $disputes populated when transaction is disputed
173
+ *
174
+ */
175
+
176
+ class Transaction extends Base
177
+ {
178
+ // Transaction Status
179
+ const AUTHORIZATION_EXPIRED = 'authorization_expired';
180
+ const AUTHORIZING = 'authorizing';
181
+ const AUTHORIZED = 'authorized';
182
+ const GATEWAY_REJECTED = 'gateway_rejected';
183
+ const FAILED = 'failed';
184
+ const PROCESSOR_DECLINED = 'processor_declined';
185
+ const SETTLED = 'settled';
186
+ const SETTLING = 'settling';
187
+ const SUBMITTED_FOR_SETTLEMENT = 'submitted_for_settlement';
188
+ const VOIDED = 'voided';
189
+ const UNRECOGNIZED = 'unrecognized';
190
+ const SETTLEMENT_DECLINED = 'settlement_declined';
191
+ const SETTLEMENT_PENDING = 'settlement_pending';
192
+ const SETTLEMENT_CONFIRMED = 'settlement_confirmed';
193
+
194
+ // Transaction Escrow Status
195
+ const ESCROW_HOLD_PENDING = 'hold_pending';
196
+ const ESCROW_HELD = 'held';
197
+ const ESCROW_RELEASE_PENDING = 'release_pending';
198
+ const ESCROW_RELEASED = 'released';
199
+ const ESCROW_REFUNDED = 'refunded';
200
+
201
+ // Transaction Types
202
+ const SALE = 'sale';
203
+ const CREDIT = 'credit';
204
+
205
+ // Transaction Created Using
206
+ const FULL_INFORMATION = 'full_information';
207
+ const TOKEN = 'token';
208
+
209
+ // Transaction Sources
210
+ const API = 'api';
211
+ const CONTROL_PANEL = 'control_panel';
212
+ const RECURRING = 'recurring';
213
+
214
+ // Gateway Rejection Reason
215
+ const AVS = 'avs';
216
+ const AVS_AND_CVV = 'avs_and_cvv';
217
+ const CVV = 'cvv';
218
+ const DUPLICATE = 'duplicate';
219
+ const FRAUD = 'fraud';
220
+ const THREE_D_SECURE = 'three_d_secure';
221
+ const APPLICATION_INCOMPLETE = 'application_incomplete';
222
+
223
+ // Industry Types
224
+ const LODGING_INDUSTRY = 'lodging';
225
+ const TRAVEL_AND_CRUISE_INDUSTRY = 'travel_cruise';
226
+
227
+ /**
228
+ * sets instance properties from an array of values
229
+ *
230
+ * @ignore
231
+ * @access protected
232
+ * @param array $transactionAttribs array of transaction data
233
+ * @return void
234
+ */
235
+ protected function _initialize($transactionAttribs)
236
+ {
237
+ $this->_attributes = $transactionAttribs;
238
+
239
+ if (isset($transactionAttribs['applePay'])) {
240
+ $this->_set('applePayCardDetails',
241
+ new Transaction\ApplePayCardDetails(
242
+ $transactionAttribs['applePay']
243
+ )
244
+ );
245
+ }
246
+
247
+ if (isset($transactionAttribs['androidPayCard'])) {
248
+ $this->_set('androidPayCardDetails',
249
+ new Transaction\AndroidPayCardDetails(
250
+ $transactionAttribs['androidPayCard']
251
+ )
252
+ );
253
+ }
254
+
255
+ if (isset($transactionAttribs['masterpassCard'])) {
256
+ $this->_set('masterpassCardDetails',
257
+ new Transaction\MasterpassCardDetails(
258
+ $transactionAttribs['masterpassCard']
259
+ )
260
+ );
261
+ }
262
+
263
+ if (isset($transactionAttribs['visaCheckoutCard'])) {
264
+ $this->_set('visaCheckoutCardDetails',
265
+ new Transaction\VisaCheckoutCardDetails(
266
+ $transactionAttribs['visaCheckoutCard']
267
+ )
268
+ );
269
+ }
270
+
271
+ if (isset($transactionAttribs['amexExpressCheckoutCard'])) {
272
+ $this->_set('amexExpressCheckoutCardDetails',
273
+ new Transaction\AmexExpressCheckoutCardDetails(
274
+ $transactionAttribs['amexExpressCheckoutCard']
275
+ )
276
+ );
277
+ }
278
+
279
+ if (isset($transactionAttribs['venmoAccount'])) {
280
+ $this->_set('venmoAccountDetails',
281
+ new Transaction\VenmoAccountDetails(
282
+ $transactionAttribs['venmoAccount']
283
+ )
284
+ );
285
+ }
286
+
287
+ if (isset($transactionAttribs['creditCard'])) {
288
+ $this->_set('creditCardDetails',
289
+ new Transaction\CreditCardDetails(
290
+ $transactionAttribs['creditCard']
291
+ )
292
+ );
293
+ }
294
+
295
+ if (isset($transactionAttribs['coinbaseAccount'])) {
296
+ $this->_set('coinbaseDetails',
297
+ new Transaction\CoinbaseDetails(
298
+ $transactionAttribs['coinbaseAccount']
299
+ )
300
+ );
301
+ }
302
+
303
+ if (isset($transactionAttribs['europeBankAccount'])) {
304
+ $this->_set('europeBankAccount',
305
+ new Transaction\EuropeBankAccountDetails(
306
+ $transactionAttribs['europeBankAccount']
307
+ )
308
+ );
309
+ }
310
+
311
+ if (isset($transactionAttribs['usBankAccount'])) {
312
+ $this->_set('usBankAccount',
313
+ new Transaction\UsBankAccountDetails(
314
+ $transactionAttribs['usBankAccount']
315
+ )
316
+ );
317
+ }
318
+
319
+ if (isset($transactionAttribs['idealPayment'])) {
320
+ $this->_set('idealPayment',
321
+ new Transaction\IdealPaymentDetails(
322
+ $transactionAttribs['idealPayment']
323
+ )
324
+ );
325
+ }
326
+
327
+ if (isset($transactionAttribs['paypal'])) {
328
+ $this->_set('paypalDetails',
329
+ new Transaction\PayPalDetails(
330
+ $transactionAttribs['paypal']
331
+ )
332
+ );
333
+ }
334
+
335
+ if (isset($transactionAttribs['customer'])) {
336
+ $this->_set('customerDetails',
337
+ new Transaction\CustomerDetails(
338
+ $transactionAttribs['customer']
339
+ )
340
+ );
341
+ }
342
+
343
+ if (isset($transactionAttribs['billing'])) {
344
+ $this->_set('billingDetails',
345
+ new Transaction\AddressDetails(
346
+ $transactionAttribs['billing']
347
+ )
348
+ );
349
+ }
350
+
351
+ if (isset($transactionAttribs['shipping'])) {
352
+ $this->_set('shippingDetails',
353
+ new Transaction\AddressDetails(
354
+ $transactionAttribs['shipping']
355
+ )
356
+ );
357
+ }
358
+
359
+ if (isset($transactionAttribs['subscription'])) {
360
+ $this->_set('subscriptionDetails',
361
+ new Transaction\SubscriptionDetails(
362
+ $transactionAttribs['subscription']
363
+ )
364
+ );
365
+ }
366
+
367
+ if (isset($transactionAttribs['descriptor'])) {
368
+ $this->_set('descriptor',
369
+ new Descriptor(
370
+ $transactionAttribs['descriptor']
371
+ )
372
+ );
373
+ }
374
+
375
+ if (isset($transactionAttribs['disbursementDetails'])) {
376
+ $this->_set('disbursementDetails',
377
+ new DisbursementDetails($transactionAttribs['disbursementDetails'])
378
+ );
379
+ }
380
+
381
+ $disputes = [];
382
+ if (isset($transactionAttribs['disputes'])) {
383
+ foreach ($transactionAttribs['disputes'] AS $dispute) {
384
+ $disputes[] = Dispute::factory($dispute);
385
+ }
386
+ }
387
+
388
+ $this->_set('disputes', $disputes);
389
+
390
+ $statusHistory = [];
391
+ if (isset($transactionAttribs['statusHistory'])) {
392
+ foreach ($transactionAttribs['statusHistory'] AS $history) {
393
+ $statusHistory[] = new Transaction\StatusDetails($history);
394
+ }
395
+ }
396
+
397
+ $this->_set('statusHistory', $statusHistory);
398
+
399
+ $addOnArray = [];
400
+ if (isset($transactionAttribs['addOns'])) {
401
+ foreach ($transactionAttribs['addOns'] AS $addOn) {
402
+ $addOnArray[] = AddOn::factory($addOn);
403
+ }
404
+ }
405
+ $this->_set('addOns', $addOnArray);
406
+
407
+ $discountArray = [];
408
+ if (isset($transactionAttribs['discounts'])) {
409
+ foreach ($transactionAttribs['discounts'] AS $discount) {
410
+ $discountArray[] = Discount::factory($discount);
411
+ }
412
+ }
413
+ $this->_set('discounts', $discountArray);
414
+
415
+ if(isset($transactionAttribs['riskData'])) {
416
+ $this->_set('riskData', RiskData::factory($transactionAttribs['riskData']));
417
+ }
418
+ if(isset($transactionAttribs['threeDSecureInfo'])) {
419
+ $this->_set('threeDSecureInfo', ThreeDSecureInfo::factory($transactionAttribs['threeDSecureInfo']));
420
+ }
421
+ if(isset($transactionAttribs['facilitatorDetails'])) {
422
+ $this->_set('facilitatorDetails', FacilitatorDetails::factory($transactionAttribs['facilitatorDetails']));
423
+ }
424
+ }
425
+
426
+ /**
427
+ * returns a string representation of the transaction
428
+ * @return string
429
+ */
430
+ public function __toString()
431
+ {
432
+ // array of attributes to print
433
+ $display = [
434
+ 'id', 'type', 'amount', 'status',
435
+ 'createdAt', 'creditCardDetails', 'customerDetails'
436
+ ];
437
+
438
+ $displayAttributes = [];
439
+ foreach ($display AS $attrib) {
440
+ $displayAttributes[$attrib] = $this->$attrib;
441
+ }
442
+ return __CLASS__ . '[' .
443
+ Util::attributesToString($displayAttributes) .']';
444
+ }
445
+
446
+ public function isEqual($otherTx)
447
+ {
448
+ return $this->id === $otherTx->id;
449
+ }
450
+
451
+ public function vaultCreditCard()
452
+ {
453
+ $token = $this->creditCardDetails->token;
454
+ if (empty($token)) {
455
+ return null;
456
+ }
457
+ else {
458
+ return CreditCard::find($token);
459
+ }
460
+ }
461
+
462
+ /** @return void|Braintree\Customer */
463
+ public function vaultCustomer()
464
+ {
465
+ $customerId = $this->customerDetails->id;
466
+ if (empty($customerId)) {
467
+ return null;
468
+ }
469
+ else {
470
+ return Customer::find($customerId);
471
+ }
472
+ }
473
+
474
+ /** @return bool */
475
+ public function isDisbursed() {
476
+ return $this->disbursementDetails->isValid();
477
+ }
478
+
479
+ /**
480
+ * factory method: returns an instance of Transaction
481
+ * to the requesting method, with populated properties
482
+ *
483
+ * @ignore
484
+ * @return Transaction
485
+ */
486
+ public static function factory($attributes)
487
+ {
488
+ $instance = new self();
489
+ $instance->_initialize($attributes);
490
+ return $instance;
491
+ }
492
+
493
+
494
+ // static methods redirecting to gateway
495
+
496
+ public static function cloneTransaction($transactionId, $attribs)
497
+ {
498
+ return Configuration::gateway()->transaction()->cloneTransaction($transactionId, $attribs);
499
+ }
500
+
501
+ public static function createFromTransparentRedirect($queryString)
502
+ {
503
+ return Configuration::gateway()->transaction()->createFromTransparentRedirect($queryString);
504
+ }
505
+
506
+ public static function createTransactionUrl()
507
+ {
508
+ return Configuration::gateway()->transaction()->createTransactionUrl();
509
+ }
510
+
511
+ public static function credit($attribs)
512
+ {
513
+ return Configuration::gateway()->transaction()->credit($attribs);
514
+ }
515
+
516
+ public static function creditNoValidate($attribs)
517
+ {
518
+ return Configuration::gateway()->transaction()->creditNoValidate($attribs);
519
+ }
520
+
521
+ public static function find($id)
522
+ {
523
+ return Configuration::gateway()->transaction()->find($id);
524
+ }
525
+
526
+ public static function sale($attribs)
527
+ {
528
+ return Configuration::gateway()->transaction()->sale($attribs);
529
+ }
530
+
531
+ public static function saleNoValidate($attribs)
532
+ {
533
+ return Configuration::gateway()->transaction()->saleNoValidate($attribs);
534
+ }
535
+
536
+ public static function search($query)
537
+ {
538
+ return Configuration::gateway()->transaction()->search($query);
539
+ }
540
+
541
+ public static function fetch($query, $ids)
542
+ {
543
+ return Configuration::gateway()->transaction()->fetch($query, $ids);
544
+ }
545
+
546
+ public static function void($transactionId)
547
+ {
548
+ return Configuration::gateway()->transaction()->void($transactionId);
549
+ }
550
+
551
+ public static function voidNoValidate($transactionId)
552
+ {
553
+ return Configuration::gateway()->transaction()->voidNoValidate($transactionId);
554
+ }
555
+
556
+ public static function submitForSettlement($transactionId, $amount = null, $attribs = [])
557
+ {
558
+ return Configuration::gateway()->transaction()->submitForSettlement($transactionId, $amount, $attribs);
559
+ }
560
+
561
+ public static function submitForSettlementNoValidate($transactionId, $amount = null, $attribs = [])
562
+ {
563
+ return Configuration::gateway()->transaction()->submitForSettlementNoValidate($transactionId, $amount, $attribs);
564
+ }
565
+
566
+ public static function updateDetails($transactionId, $attribs = [])
567
+ {
568
+ return Configuration::gateway()->transaction()->updateDetails($transactionId, $attribs);
569
+ }
570
+
571
+ public static function submitForPartialSettlement($transactionId, $amount, $attribs = [])
572
+ {
573
+ return Configuration::gateway()->transaction()->submitForPartialSettlement($transactionId, $amount, $attribs);
574
+ }
575
+
576
+ public static function holdInEscrow($transactionId)
577
+ {
578
+ return Configuration::gateway()->transaction()->holdInEscrow($transactionId);
579
+ }
580
+
581
+ public static function releaseFromEscrow($transactionId)
582
+ {
583
+ return Configuration::gateway()->transaction()->releaseFromEscrow($transactionId);
584
+ }
585
+
586
+ public static function cancelRelease($transactionId)
587
+ {
588
+ return Configuration::gateway()->transaction()->cancelRelease($transactionId);
589
+ }
590
+
591
+ public static function refund($transactionId, $amount = null)
592
+ {
593
+ return Configuration::gateway()->transaction()->refund($transactionId, $amount);
594
+ }
595
+ }
596
+ class_alias('Braintree\Transaction', 'Braintree_Transaction');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/AddressDetails.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * Creates an instance of AddressDetails as returned from a transaction
8
+ *
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Transaction
12
+ *
13
+ * @property-read string $firstName
14
+ * @property-read string $lastName
15
+ * @property-read string $company
16
+ * @property-read string $streetAddress
17
+ * @property-read string $extendedAddress
18
+ * @property-read string $locality
19
+ * @property-read string $region
20
+ * @property-read string $postalCode
21
+ * @property-read string $countryName
22
+ */
23
+ class AddressDetails extends Instance
24
+ {
25
+ protected $_attributes = [];
26
+ }
27
+ class_alias('Braintree\Transaction\AddressDetails', 'Braintree_Transaction_AddressDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/AmexExpressCheckoutCardDetails.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+ /**
6
+ * Amex Express Checkout card details from a transaction
7
+ *
8
+ * @package Braintree
9
+ * @subpackage Transaction
10
+ */
11
+
12
+ /**
13
+ * creates an instance of AmexExpressCheckoutCardDetails
14
+ *
15
+ *
16
+ * @package Braintree
17
+ * @subpackage Transaction
18
+ *
19
+ * @property-read string $cardType
20
+ * @property-read string $bin
21
+ * @property-read string $cardMemberExpiryDate
22
+ * @property-read string $cardMemberNumber
23
+ * @property-read string $cardType
24
+ * @property-read string $sourceDescription
25
+ * @property-read string $token
26
+ * @property-read string $imageUrl
27
+ * @property-read string $expirationMonth
28
+ * @property-read string $expirationYear
29
+ * @uses Instance inherits methods
30
+ */
31
+ class AmexExpressCheckoutCardDetails extends Instance
32
+ {
33
+ protected $_attributes = [];
34
+
35
+ /**
36
+ * @ignore
37
+ */
38
+ public function __construct($attributes)
39
+ {
40
+ parent::__construct($attributes);
41
+ }
42
+ }
43
+ class_alias('Braintree\Transaction\AmexExpressCheckoutCardDetails', 'Braintree_Transaction_AmexExpressCheckoutCardDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/AndroidPayCardDetails.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * Android Pay card details from a transaction
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Transaction
11
+ */
12
+
13
+ /**
14
+ * creates an instance of AndroidPayCardDetails
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @subpackage Transaction
19
+ *
20
+ * @property-read string $bin
21
+ * @property-read string $default
22
+ * @property-read string $expirationMonth
23
+ * @property-read string $expirationYear
24
+ * @property-read string $googleTransactionId
25
+ * @property-read string $imageUrl
26
+ * @property-read string $sourceCardLast4
27
+ * @property-read string $sourceCardType
28
+ * @property-read string $sourceDescription
29
+ * @property-read string $token
30
+ * @property-read string $virtualCardLast4
31
+ * @property-read string $virtualCardType
32
+ */
33
+ class AndroidPayCardDetails extends Instance
34
+ {
35
+ protected $_attributes = [];
36
+
37
+ /**
38
+ * @ignore
39
+ */
40
+ public function __construct($attributes)
41
+ {
42
+ parent::__construct($attributes);
43
+ $this->_attributes['cardType'] = $this->virtualCardType;
44
+ $this->_attributes['last4'] = $this->virtualCardLast4;
45
+ }
46
+ }
47
+ class_alias('Braintree\Transaction\AndroidPayCardDetails', 'Braintree_Transaction_AndroidPayCardDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/ApplePayCardDetails.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * Apple Pay card details from a transaction
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Transaction
11
+ */
12
+
13
+ /**
14
+ * creates an instance of ApplePayCardDetails
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @subpackage Transaction
19
+ *
20
+ * @property-read string $cardType
21
+ * @property-read string $paymentInstrumentName
22
+ * @property-read string $expirationMonth
23
+ * @property-read string $expirationYear
24
+ * @property-read string $cardholderName
25
+ * @property-read string $sourceDescription
26
+ */
27
+ class ApplePayCardDetails extends Instance
28
+ {
29
+ protected $_attributes = [];
30
+
31
+ /**
32
+ * @ignore
33
+ */
34
+ public function __construct($attributes)
35
+ {
36
+ parent::__construct($attributes);
37
+ }
38
+ }
39
+ class_alias('Braintree\Transaction\ApplePayCardDetails', 'Braintree_Transaction_ApplePayCardDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/CoinbaseDetails.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * Coinbase details from a transaction
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Transaction
11
+ */
12
+
13
+ /**
14
+ * creates an instance of Coinbase
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @subpackage Transaction
19
+ *
20
+ * @property-read string $token
21
+ * @property-read string $userId
22
+ * @property-read string $userName
23
+ * @property-read string $userEmail
24
+ * @property-read string $imageUrl
25
+ */
26
+ class CoinbaseDetails extends Instance
27
+ {
28
+ protected $_attributes = [];
29
+
30
+ /**
31
+ * @ignore
32
+ */
33
+ public function __construct($attributes)
34
+ {
35
+ parent::__construct($attributes);
36
+ }
37
+ }
38
+ class_alias('Braintree\Transaction\CoinbaseDetails', 'Braintree_Transaction_CoinbaseDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/CreditCardDetails.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * CreditCard details from a transaction
8
+ * creates an instance of CreditCardDetails
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Transaction
12
+ *
13
+ * @property-read string $bin
14
+ * @property-read string $cardType
15
+ * @property-read string $expirationDate
16
+ * @property-read string $expirationMonth
17
+ * @property-read string $expirationYear
18
+ * @property-read string $issuerLocation
19
+ * @property-read string $last4
20
+ * @property-read string $maskedNumber
21
+ * @property-read string $token
22
+ */
23
+ class CreditCardDetails extends Instance
24
+ {
25
+ protected $_attributes = [];
26
+
27
+ /**
28
+ * @ignore
29
+ */
30
+ public function __construct($attributes)
31
+ {
32
+ parent::__construct($attributes);
33
+ $this->_attributes['expirationDate'] = $this->expirationMonth . '/' . $this->expirationYear;
34
+ $this->_attributes['maskedNumber'] = $this->bin . '******' . $this->last4;
35
+
36
+ }
37
+ }
38
+ class_alias('Braintree\Transaction\CreditCardDetails', 'Braintree_Transaction_CreditCardDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/CustomerDetails.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * Customer details from a transaction
8
+ * Creates an instance of customer details as returned from a transaction
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Transaction
12
+ *
13
+ * @property-read string $company
14
+ * @property-read string $email
15
+ * @property-read string $fax
16
+ * @property-read string $firstName
17
+ * @property-read string $id
18
+ * @property-read string $lastName
19
+ * @property-read string $phone
20
+ * @property-read string $website
21
+ */
22
+ class CustomerDetails extends Instance
23
+ {
24
+ }
25
+ class_alias('Braintree\Transaction\CustomerDetails', 'Braintree_Transaction_CustomerDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/EuropeBankAccountDetails.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * Europe bank account details from a transaction
8
+ * Creates an instance of europe bank account details as returned from a transaction
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Transaction
12
+ *
13
+ * @property-read string $accountHolderName
14
+ * @property-read string $bic
15
+ * @property-read string $imageUrl
16
+ * @property-read string $mandateAcceptedAt
17
+ * @property-read string $mandateReferenceNumber
18
+ * @property-read string $maskedIban
19
+ * @property-read string $token
20
+ */
21
+ class EuropeBankAccountDetails extends Instance
22
+ {
23
+ }
24
+ class_alias('Braintree\Transaction\EuropeBankAccountDetails', 'Braintree_Transaction_EuropeBankAccountDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/IdealPaymentDetails.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * iDEAL payment details from a transaction
8
+ * creates an instance of IdealPaymentDetails
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Transaction
12
+ *
13
+ * @property-read string $idealPaymentId
14
+ * @property-read string $idealTransactionId
15
+ * @property-read string $imageUrl
16
+ * @property-read string $maskedIban
17
+ * @property-read string $bic
18
+ */
19
+ class IdealPaymentDetails extends Instance
20
+ {
21
+ protected $_attributes = [];
22
+ }
23
+ class_alias('Braintree\Transaction\IdealPaymentDetails', 'Braintree_Transaction_IdealPaymentDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/MasterpassCardDetails.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * MasterpassCard details from a transaction
8
+ * creates an instance of MasterpassCardDetails
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Transaction
12
+ *
13
+ * @property-read string $bin
14
+ * @property-read string $callId
15
+ * @property-read string $cardholderName
16
+ * @property-read string $commercial
17
+ * @property-read string $countryOfIssuance
18
+ * @property-read string $customerId
19
+ * @property-read string $customerLocation
20
+ * @property-read string $debit
21
+ * @property-read string $durbinRegulated
22
+ * @property-read string $expirationDate
23
+ * @property-read string $expirationMonth
24
+ * @property-read string $expirationYear
25
+ * @property-read string $healthcare
26
+ * @property-read string $imageUrl
27
+ * @property-read string $issuingBank
28
+ * @property-read string $last4
29
+ * @property-read string $maskedNumber
30
+ * @property-read string $payroll
31
+ * @property-read string $prepaid
32
+ * @property-read string $productId
33
+ * @property-read string $token
34
+ * @property-read string $updatedAt
35
+ */
36
+ class MasterpassCardDetails extends Instance
37
+ {
38
+ protected $_attributes = [];
39
+
40
+ /**
41
+ * @ignore
42
+ */
43
+ public function __construct($attributes)
44
+ {
45
+ parent::__construct($attributes);
46
+ $this->_attributes['expirationDate'] = $this->expirationMonth . '/' . $this->expirationYear;
47
+ $this->_attributes['maskedNumber'] = $this->bin . '******' . $this->last4;
48
+
49
+ }
50
+ }
51
+ class_alias('Braintree\Transaction\MasterpassCardDetails', 'Braintree_Transaction_MasterpassCardDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/PayPalDetails.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * PayPal details from a transaction
8
+ *
9
+ * @package Braintree
10
+ * @subpackage Transaction
11
+ */
12
+
13
+ /**
14
+ * creates an instance of PayPalDetails
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @subpackage Transaction
19
+ *
20
+ * @property-read string $payerEmail
21
+ * @property-read string $paymentId
22
+ * @property-read string $authorizationId
23
+ * @property-read string $token
24
+ * @property-read string $imageUrl
25
+ * @property-read string $transactionFeeAmount
26
+ * @property-read string $transactionFeeCurrencyIsoCode
27
+ * @property-read string $description
28
+ */
29
+ class PayPalDetails extends Instance
30
+ {
31
+ protected $_attributes = [];
32
+
33
+ /**
34
+ * @ignore
35
+ */
36
+ public function __construct($attributes)
37
+ {
38
+ parent::__construct($attributes);
39
+ }
40
+ }
41
+ class_alias('Braintree\Transaction\PayPalDetails', 'Braintree_Transaction_PayPalDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/StatusDetails.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * Status details from a transaction
8
+ * Creates an instance of StatusDetails, as part of a transaction response
9
+ *
10
+ * @package Braintree
11
+ *
12
+ * @property-read string $amount
13
+ * @property-read string $status
14
+ * @property-read string $timestamp
15
+ * @property-read string $transactionSource
16
+ * @property-read string $user
17
+ */
18
+ class StatusDetails extends Instance
19
+ {
20
+ }
21
+ class_alias('Braintree\Transaction\StatusDetails', 'Braintree_Transaction_StatusDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/SubscriptionDetails.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * Customer details from a transaction
8
+ * Creates an instance of customer details as returned from a transaction
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Transaction
12
+ *
13
+ * @property-read string $billing_period_start_date
14
+ * @property-read string $billing_period_end_date
15
+ */
16
+ class SubscriptionDetails extends Instance
17
+ {
18
+ }
19
+ class_alias('Braintree\Transaction\SubscriptionDetails', 'Braintree_Transaction_SubscriptionDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/UsBankAccountDetails.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+ use Braintree\AchMandate;
6
+
7
+ /**
8
+ * US Bank Account details from a transaction
9
+ * creates an instance of UsbankAccountDetails
10
+ *
11
+ * @package Braintree
12
+ * @subpackage Transaction
13
+ *
14
+ * @property-read string $token
15
+ * @property-read string $imageUrl
16
+ * @property-read string $routingNumber
17
+ * @property-read string $accountType
18
+ * @property-read string $accountHolderName
19
+ * @property-read string $last4
20
+ * @property-read string $bankName
21
+ * @property-read string $achMandate
22
+ */
23
+ class UsBankAccountDetails extends Instance
24
+ {
25
+ protected $_attributes = [];
26
+
27
+ /**
28
+ * @ignore
29
+ */
30
+ public function __construct($attributes)
31
+ {
32
+ parent::__construct($attributes);
33
+
34
+ $achMandate = isset($attributes['achMandate']) ?
35
+ AchMandate::factory($attributes['achMandate']) :
36
+ null;
37
+ $this->achMandate = $achMandate;
38
+ }
39
+ }
40
+ class_alias('Braintree\Transaction\UsBankAccountDetails', 'Braintree_Transaction_UsBankAccountDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/VenmoAccountDetails.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+ /**
6
+ * Venmo account details from a transaction
7
+ *
8
+ * @package Braintree
9
+ * @subpackage Transaction
10
+ */
11
+
12
+ /**
13
+ * creates an instance of VenmoAccountDetails
14
+ *
15
+ *
16
+ * @package Braintree
17
+ * @subpackage Transaction
18
+ *
19
+ * @property-read string $sourceDescription
20
+ * @property-read string $token
21
+ * @property-read string $imageUrl
22
+ * @property-read string $username
23
+ * @property-read string $venmo_user_id
24
+ * @uses Instance inherits methods
25
+ */
26
+ class VenmoAccountDetails extends Instance
27
+ {
28
+ protected $_attributes = array();
29
+
30
+ /**
31
+ * @ignore
32
+ */
33
+ public function __construct($attributes)
34
+ {
35
+ parent::__construct($attributes);
36
+ }
37
+ }
38
+ class_alias('Braintree\Transaction\VenmoAccountDetails', 'Braintree_Transaction_VenmoAccountDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Transaction/VisaCheckoutCardDetails.php ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Transaction;
3
+
4
+ use Braintree\Instance;
5
+
6
+ /**
7
+ * VisaCheckoutCard details from a transaction
8
+ * creates an instance of VisaCheckoutCardDetails
9
+ *
10
+ * @package Braintree
11
+ * @subpackage Transaction
12
+ *
13
+ * @property-read string $bin
14
+ * @property-read string $callId
15
+ * @property-read string $cardType
16
+ * @property-read string $cardholderName
17
+ * @property-read string $commercial
18
+ * @property-read string $countryOfIssuance
19
+ * @property-read string $customerId
20
+ * @property-read string $customerLocation
21
+ * @property-read string $debit
22
+ * @property-read string $durbinRegulated
23
+ * @property-read string $expirationDate
24
+ * @property-read string $expirationMonth
25
+ * @property-read string $expirationYear
26
+ * @property-read string $healthcare
27
+ * @property-read string $imageUrl
28
+ * @property-read string $issuingBank
29
+ * @property-read string $last4
30
+ * @property-read string $maskedNumber
31
+ * @property-read string $payroll
32
+ * @property-read string $prepaid
33
+ * @property-read string $productId
34
+ * @property-read string $token
35
+ * @property-read string $updatedAt
36
+ */
37
+ class VisaCheckoutCardDetails extends Instance
38
+ {
39
+ protected $_attributes = [];
40
+
41
+ /**
42
+ * @ignore
43
+ */
44
+ public function __construct($attributes)
45
+ {
46
+ parent::__construct($attributes);
47
+ $this->_attributes['expirationDate'] = $this->expirationMonth . '/' . $this->expirationYear;
48
+ $this->_attributes['maskedNumber'] = $this->bin . '******' . $this->last4;
49
+
50
+ }
51
+ }
52
+ class_alias('Braintree\Transaction\VisaCheckoutCardDetails', 'Braintree_Transaction_VisaCheckoutCardDetails');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TransactionGateway.php ADDED
@@ -0,0 +1,532 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ /**
7
+ * Braintree TransactionGateway processor
8
+ * Creates and manages transactions
9
+ *
10
+ *
11
+ * <b>== More information ==</b>
12
+ *
13
+ * For more detailed information on Transactions, see {@link http://www.braintreepayments.com/gateway/transaction-api http://www.braintreepaymentsolutions.com/gateway/transaction-api}
14
+ *
15
+ * @package Braintree
16
+ * @category Resources
17
+ */
18
+
19
+ class TransactionGateway
20
+ {
21
+ private $_gateway;
22
+ private $_config;
23
+ private $_http;
24
+
25
+ public function __construct($gateway)
26
+ {
27
+ $this->_gateway = $gateway;
28
+ $this->_config = $gateway->config;
29
+ $this->_config->assertHasAccessTokenOrKeys();
30
+ $this->_http = new Http($gateway->config);
31
+ }
32
+
33
+ public function cloneTransaction($transactionId, $attribs)
34
+ {
35
+ Util::verifyKeys(self::cloneSignature(), $attribs);
36
+ return $this->_doCreate('/transactions/' . $transactionId . '/clone', ['transactionClone' => $attribs]);
37
+ }
38
+
39
+ /**
40
+ * @ignore
41
+ * @access private
42
+ * @param array $attribs
43
+ * @return object
44
+ */
45
+ private function create($attribs)
46
+ {
47
+ Util::verifyKeys(self::createSignature(), $attribs);
48
+ return $this->_doCreate('/transactions', ['transaction' => $attribs]);
49
+ }
50
+
51
+ /**
52
+ * @ignore
53
+ * @access private
54
+ * @param array $attribs
55
+ * @return object
56
+ * @throws Exception\ValidationError
57
+ */
58
+ private function createNoValidate($attribs)
59
+ {
60
+ $result = $this->create($attribs);
61
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
62
+ }
63
+ /**
64
+ *
65
+ * @deprecated since version 2.3.0
66
+ * @access public
67
+ * @param array $attribs
68
+ * @return object
69
+ */
70
+ public function createFromTransparentRedirect($queryString)
71
+ {
72
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::confirm", E_USER_NOTICE);
73
+ $params = TransparentRedirect::parseAndValidateQueryString(
74
+ $queryString
75
+ );
76
+ return $this->_doCreate(
77
+ '/transactions/all/confirm_transparent_redirect_request',
78
+ ['id' => $params['id']]
79
+ );
80
+ }
81
+ /**
82
+ *
83
+ * @deprecated since version 2.3.0
84
+ * @access public
85
+ * @param none
86
+ * @return string
87
+ */
88
+ public function createTransactionUrl()
89
+ {
90
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::url", E_USER_NOTICE);
91
+ return $this->_config->baseUrl() . $this->_config->merchantPath() .
92
+ '/transactions/all/create_via_transparent_redirect_request';
93
+ }
94
+
95
+ public static function cloneSignature()
96
+ {
97
+ return ['amount', 'channel', ['options' => ['submitForSettlement']]];
98
+ }
99
+
100
+ /**
101
+ * creates a full array signature of a valid gateway request
102
+ * @return array gateway request signature format
103
+ */
104
+ public static function createSignature()
105
+ {
106
+ return [
107
+ 'amount',
108
+ 'billingAddressId',
109
+ 'channel',
110
+ 'customerId',
111
+ 'deviceData',
112
+ 'deviceSessionId',
113
+ 'fraudMerchantId',
114
+ 'merchantAccountId',
115
+ 'orderId',
116
+ 'paymentMethodNonce',
117
+ 'paymentMethodToken',
118
+ 'purchaseOrderNumber',
119
+ 'recurring',
120
+ 'serviceFeeAmount',
121
+ 'sharedPaymentMethodToken',
122
+ 'sharedCustomerId',
123
+ 'sharedShippingAddressId',
124
+ 'sharedBillingAddressId',
125
+ 'shippingAddressId',
126
+ 'taxAmount',
127
+ 'taxExempt',
128
+ 'threeDSecureToken',
129
+ 'transactionSource',
130
+ 'type',
131
+ 'venmoSdkPaymentMethodCode',
132
+ ['riskData' =>
133
+ ['customerBrowser', 'customerIp', 'customer_browser', 'customer_ip']
134
+ ],
135
+ ['creditCard' =>
136
+ ['token', 'cardholderName', 'cvv', 'expirationDate', 'expirationMonth', 'expirationYear', 'number'],
137
+ ],
138
+ ['customer' =>
139
+ [
140
+ 'id', 'company', 'email', 'fax', 'firstName',
141
+ 'lastName', 'phone', 'website'],
142
+ ],
143
+ ['billing' =>
144
+ [
145
+ 'firstName', 'lastName', 'company', 'countryName',
146
+ 'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric',
147
+ 'extendedAddress', 'locality', 'postalCode', 'region',
148
+ 'streetAddress'],
149
+ ],
150
+ ['shipping' =>
151
+ [
152
+ 'firstName', 'lastName', 'company', 'countryName',
153
+ 'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric',
154
+ 'extendedAddress', 'locality', 'postalCode', 'region',
155
+ 'streetAddress'],
156
+ ],
157
+ ['threeDSecurePassThru' =>
158
+ [
159
+ 'eciFlag',
160
+ 'cavv',
161
+ 'xid'],
162
+ ],
163
+ ['options' =>
164
+ [
165
+ 'holdInEscrow',
166
+ 'storeInVault',
167
+ 'storeInVaultOnSuccess',
168
+ 'submitForSettlement',
169
+ 'addBillingAddressToPaymentMethod',
170
+ 'venmoSdkSession',
171
+ 'storeShippingAddressInVault',
172
+ 'payeeEmail',
173
+ 'skipAdvancedFraudChecking',
174
+ 'skipAvs',
175
+ 'skipCvv',
176
+ ['threeDSecure' =>
177
+ ['required']
178
+ ],
179
+ # Included for backwards compatiblity. Remove in the next major version
180
+ ['three_d_secure' =>
181
+ ['required']
182
+ ],
183
+ ['paypal' =>
184
+ [
185
+ 'payeeEmail',
186
+ 'customField',
187
+ 'description',
188
+ ['supplementaryData' => ['_anyKey_']],
189
+ ]
190
+ ],
191
+ ['amexRewards' =>
192
+ [
193
+ 'requestId',
194
+ 'points',
195
+ 'currencyAmount',
196
+ 'currencyIsoCode'
197
+ ]
198
+ ]
199
+ ],
200
+ ],
201
+ ['customFields' => ['_anyKey_']],
202
+ ['descriptor' => ['name', 'phone', 'url']],
203
+ ['paypalAccount' => ['payeeEmail']],
204
+ ['apple_pay_card' => ['number', 'cardholder_name', 'cryptogram', 'expiration_month', 'expiration_year']], #backwards compatibility
205
+ ['applePayCard' => ['number', 'cardholderName', 'cryptogram', 'expirationMonth', 'expirationYear']],
206
+ ['industry' =>
207
+ ['industryType',
208
+ ['data' =>
209
+ [
210
+ 'folioNumber',
211
+ 'checkInDate',
212
+ 'checkOutDate',
213
+ 'travelPackage',
214
+ 'departureDate',
215
+ 'lodgingCheckInDate',
216
+ 'lodgingCheckOutDate',
217
+ 'lodgingName',
218
+ 'roomRate'
219
+ ]
220
+ ]
221
+ ]
222
+ ]
223
+ ];
224
+ }
225
+
226
+ public static function submitForSettlementSignature()
227
+ {
228
+ return ['orderId', ['descriptor' => ['name', 'phone', 'url']]];
229
+ }
230
+
231
+ public static function updateDetailsSignature()
232
+ {
233
+ return ['amount', 'orderId', ['descriptor' => ['name', 'phone', 'url']]];
234
+ }
235
+
236
+ public static function refundSignature()
237
+ {
238
+ return ['amount', 'orderId'];
239
+ }
240
+
241
+ /**
242
+ *
243
+ * @access public
244
+ * @param array $attribs
245
+ * @return Result\Successful|Result\Error
246
+ */
247
+ public function credit($attribs)
248
+ {
249
+ return $this->create(array_merge($attribs, ['type' => Transaction::CREDIT]));
250
+ }
251
+
252
+ /**
253
+ *
254
+ * @access public
255
+ * @param array $attribs
256
+ * @return Result\Successful|Result\Error
257
+ * @throws Exception\ValidationError
258
+ */
259
+ public function creditNoValidate($attribs)
260
+ {
261
+ $result = $this->credit($attribs);
262
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
263
+ }
264
+
265
+ /**
266
+ * @access public
267
+ * @param string id
268
+ * @return Transaction
269
+ */
270
+ public function find($id)
271
+ {
272
+ $this->_validateId($id);
273
+ try {
274
+ $path = $this->_config->merchantPath() . '/transactions/' . $id;
275
+ $response = $this->_http->get($path);
276
+ return Transaction::factory($response['transaction']);
277
+ } catch (Exception\NotFound $e) {
278
+ throw new Exception\NotFound(
279
+ 'transaction with id ' . $id . ' not found'
280
+ );
281
+ }
282
+ }
283
+ /**
284
+ * new sale
285
+ * @param array $attribs
286
+ * @return array
287
+ */
288
+ public function sale($attribs)
289
+ {
290
+ return $this->create(array_merge(['type' => Transaction::SALE], $attribs));
291
+ }
292
+
293
+ /**
294
+ * roughly equivalent to the ruby bang method
295
+ * @access public
296
+ * @param array $attribs
297
+ * @return array
298
+ * @throws Exception\ValidationsFailed
299
+ */
300
+ public function saleNoValidate($attribs)
301
+ {
302
+ $result = $this->sale($attribs);
303
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
304
+ }
305
+
306
+ /**
307
+ * Returns a ResourceCollection of transactions matching the search query.
308
+ *
309
+ * If <b>query</b> is a string, the search will be a basic search.
310
+ * If <b>query</b> is a hash, the search will be an advanced search.
311
+ * For more detailed information and examples, see {@link http://www.braintreepayments.com/gateway/transaction-api#searching http://www.braintreepaymentsolutions.com/gateway/transaction-api}
312
+ *
313
+ * @param mixed $query search query
314
+ * @param array $options options such as page number
315
+ * @return ResourceCollection
316
+ * @throws InvalidArgumentException
317
+ */
318
+ public function search($query)
319
+ {
320
+ $criteria = [];
321
+ foreach ($query as $term) {
322
+ $criteria[$term->name] = $term->toparam();
323
+ }
324
+
325
+ $path = $this->_config->merchantPath() . '/transactions/advanced_search_ids';
326
+ $response = $this->_http->post($path, ['search' => $criteria]);
327
+ if (array_key_exists('searchResults', $response)) {
328
+ $pager = [
329
+ 'object' => $this,
330
+ 'method' => 'fetch',
331
+ 'methodArgs' => [$query]
332
+ ];
333
+
334
+ return new ResourceCollection($response, $pager);
335
+ } else {
336
+ throw new Exception\DownForMaintenance();
337
+ }
338
+ }
339
+
340
+ public function fetch($query, $ids)
341
+ {
342
+ $criteria = [];
343
+ foreach ($query as $term) {
344
+ $criteria[$term->name] = $term->toparam();
345
+ }
346
+ $criteria["ids"] = TransactionSearch::ids()->in($ids)->toparam();
347
+ $path = $this->_config->merchantPath() . '/transactions/advanced_search';
348
+ $response = $this->_http->post($path, ['search' => $criteria]);
349
+
350
+ if (array_key_exists('creditCardTransactions', $response)) {
351
+ return Util::extractattributeasarray(
352
+ $response['creditCardTransactions'],
353
+ 'transaction'
354
+ );
355
+ } else {
356
+ throw new Exception\DownForMaintenance();
357
+ }
358
+ }
359
+
360
+ /**
361
+ * void a transaction by id
362
+ *
363
+ * @param string $id transaction id
364
+ * @return Result\Successful|Result\Error
365
+ */
366
+ public function void($transactionId)
367
+ {
368
+ $this->_validateId($transactionId);
369
+
370
+ $path = $this->_config->merchantPath() . '/transactions/'. $transactionId . '/void';
371
+ $response = $this->_http->put($path);
372
+ return $this->_verifyGatewayResponse($response);
373
+ }
374
+ /**
375
+ *
376
+ */
377
+ public function voidNoValidate($transactionId)
378
+ {
379
+ $result = $this->void($transactionId);
380
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
381
+ }
382
+
383
+ public function submitForSettlement($transactionId, $amount = null, $attribs = [])
384
+ {
385
+ $this->_validateId($transactionId);
386
+ Util::verifyKeys(self::submitForSettlementSignature(), $attribs);
387
+ $attribs['amount'] = $amount;
388
+
389
+ $path = $this->_config->merchantPath() . '/transactions/'. $transactionId . '/submit_for_settlement';
390
+ $response = $this->_http->put($path, ['transaction' => $attribs]);
391
+ return $this->_verifyGatewayResponse($response);
392
+ }
393
+
394
+ public function submitForSettlementNoValidate($transactionId, $amount = null, $attribs = [])
395
+ {
396
+ $result = $this->submitForSettlement($transactionId, $amount, $attribs);
397
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
398
+ }
399
+
400
+ public function updateDetails($transactionId, $attribs = [])
401
+ {
402
+ $this->_validateId($transactionId);
403
+ Util::verifyKeys(self::updateDetailsSignature(), $attribs);
404
+
405
+ $path = $this->_config->merchantPath() . '/transactions/'. $transactionId . '/update_details';
406
+ $response = $this->_http->put($path, ['transaction' => $attribs]);
407
+ return $this->_verifyGatewayResponse($response);
408
+ }
409
+
410
+ public function submitForPartialSettlement($transactionId, $amount, $attribs = [])
411
+ {
412
+ $this->_validateId($transactionId);
413
+ Util::verifyKeys(self::submitForSettlementSignature(), $attribs);
414
+ $attribs['amount'] = $amount;
415
+
416
+ $path = $this->_config->merchantPath() . '/transactions/'. $transactionId . '/submit_for_partial_settlement';
417
+ $response = $this->_http->post($path, ['transaction' => $attribs]);
418
+ return $this->_verifyGatewayResponse($response);
419
+ }
420
+
421
+ public function holdInEscrow($transactionId)
422
+ {
423
+ $this->_validateId($transactionId);
424
+
425
+ $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/hold_in_escrow';
426
+ $response = $this->_http->put($path, []);
427
+ return $this->_verifyGatewayResponse($response);
428
+ }
429
+
430
+ public function releaseFromEscrow($transactionId)
431
+ {
432
+ $this->_validateId($transactionId);
433
+
434
+ $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/release_from_escrow';
435
+ $response = $this->_http->put($path, []);
436
+ return $this->_verifyGatewayResponse($response);
437
+ }
438
+
439
+ public function cancelRelease($transactionId)
440
+ {
441
+ $this->_validateId($transactionId);
442
+
443
+ $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/cancel_release';
444
+ $response = $this->_http->put($path, []);
445
+ return $this->_verifyGatewayResponse($response);
446
+ }
447
+
448
+ public function refund($transactionId, $amount_or_options = null)
449
+ {
450
+ self::_validateId($transactionId);
451
+
452
+ if(gettype($amount_or_options) == "array") {
453
+ $options = $amount_or_options;
454
+ } else {
455
+ $options = [
456
+ "amount" => $amount_or_options
457
+ ];
458
+ }
459
+ Util::verifyKeys(self::refundSignature(), $options);
460
+
461
+ $params = ['transaction' => $options];
462
+ $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/refund';
463
+ $response = $this->_http->post($path, $params);
464
+ return $this->_verifyGatewayResponse($response);
465
+ }
466
+
467
+ /**
468
+ * sends the create request to the gateway
469
+ *
470
+ * @ignore
471
+ * @param var $subPath
472
+ * @param array $params
473
+ * @return mixed
474
+ */
475
+ public function _doCreate($subPath, $params)
476
+ {
477
+ $fullPath = $this->_config->merchantPath() . $subPath;
478
+ $response = $this->_http->post($fullPath, $params);
479
+
480
+
481
+ return $this->_verifyGatewayResponse($response);
482
+ }
483
+
484
+ /**
485
+ * verifies that a valid transaction id is being used
486
+ * @ignore
487
+ * @param string transaction id
488
+ * @throws InvalidArgumentException
489
+ */
490
+ private function _validateId($id = null) {
491
+ if (empty($id)) {
492
+ throw new InvalidArgumentException(
493
+ 'expected transaction id to be set'
494
+ );
495
+ }
496
+ if (!preg_match('/^[0-9a-z]+$/', $id)) {
497
+ throw new InvalidArgumentException(
498
+ $id . ' is an invalid transaction id.'
499
+ );
500
+ }
501
+ }
502
+
503
+ /**
504
+ * generic method for validating incoming gateway responses
505
+ *
506
+ * creates a new Transaction object and encapsulates
507
+ * it inside a Result\Successful object, or
508
+ * encapsulates a Errors object inside a Result\Error
509
+ * alternatively, throws an Unexpected exception if the response is invalid.
510
+ *
511
+ * @ignore
512
+ * @param array $response gateway response values
513
+ * @return Result\Successful|Result\Error
514
+ * @throws Exception\Unexpected
515
+ */
516
+ private function _verifyGatewayResponse($response)
517
+ {
518
+ if (isset($response['transaction'])) {
519
+ // return a populated instance of Transaction
520
+ return new Result\Successful(
521
+ Transaction::factory($response['transaction'])
522
+ );
523
+ } else if (isset($response['apiErrorResponse'])) {
524
+ return new Result\Error($response['apiErrorResponse']);
525
+ } else {
526
+ throw new Exception\Unexpected(
527
+ "Expected transaction or apiErrorResponse"
528
+ );
529
+ }
530
+ }
531
+ }
532
+ class_alias('Braintree\TransactionGateway', 'Braintree_TransactionGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TransactionSearch.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class TransactionSearch
5
+ {
6
+ public static function amount() { return new RangeNode("amount"); }
7
+ public static function authorizationExpiredAt() { return new RangeNode("authorizationExpiredAt"); }
8
+ public static function authorizedAt() { return new RangeNode("authorizedAt"); }
9
+ public static function billingCompany() { return new TextNode('billing_company'); }
10
+ public static function billingCountryName() { return new TextNode('billing_country_name'); }
11
+ public static function billingExtendedAddress() { return new TextNode('billing_extended_address'); }
12
+ public static function billingFirstName() { return new TextNode('billing_first_name'); }
13
+ public static function billingLastName() { return new TextNode('billing_last_name'); }
14
+ public static function billingLocality() { return new TextNode('billing_locality'); }
15
+ public static function billingPostalCode() { return new TextNode('billing_postal_code'); }
16
+ public static function billingRegion() { return new TextNode('billing_region'); }
17
+ public static function billingStreetAddress() { return new TextNode('billing_street_address'); }
18
+ public static function createdAt() { return new RangeNode("createdAt"); }
19
+ public static function creditCardCardholderName() { return new TextNode('credit_card_cardholderName'); }
20
+ public static function creditCardExpirationDate() { return new EqualityNode('credit_card_expiration_date'); }
21
+ public static function creditCardNumber() { return new PartialMatchNode('credit_card_number'); }
22
+ public static function creditCardUniqueIdentifier() { return new TextNode('credit_card_unique_identifier'); }
23
+ public static function currency() { return new TextNode('currency'); }
24
+ public static function customerCompany() { return new TextNode('customer_company'); }
25
+ public static function customerEmail() { return new TextNode('customer_email'); }
26
+ public static function customerFax() { return new TextNode('customer_fax'); }
27
+ public static function customerFirstName() { return new TextNode('customer_first_name'); }
28
+ public static function customerId() { return new TextNode('customer_id'); }
29
+ public static function customerLastName() { return new TextNode('customer_last_name'); }
30
+ public static function customerPhone() { return new TextNode('customer_phone'); }
31
+ public static function customerWebsite() { return new TextNode('customer_website'); }
32
+ public static function disbursementDate() { return new RangeNode("disbursementDate"); }
33
+ public static function disputeDate() { return new RangeNode("disputeDate"); }
34
+ public static function europeBankAccountIban() { return new TextNode("europeBankAccountIban"); }
35
+ public static function failedAt() { return new RangeNode("failedAt"); }
36
+ public static function gatewayRejectedAt() { return new RangeNode("gatewayRejectedAt"); }
37
+ public static function id() { return new TextNode('id'); }
38
+ public static function ids() { return new MultipleValueNode('ids'); }
39
+ public static function merchantAccountId() { return new MultipleValueNode("merchant_account_id"); }
40
+ public static function orderId() { return new TextNode('order_id'); }
41
+ public static function paymentInstrumentType() { return new MultipleValueNode('paymentInstrumentType'); }
42
+ public static function paymentMethodToken() { return new TextNode('payment_method_token'); }
43
+ public static function paypalAuthorizationId() { return new TextNode('paypal_authorization_id'); }
44
+ public static function paypalPayerEmail() { return new TextNode('paypal_payer_email'); }
45
+ public static function paypalPaymentId() { return new TextNode('paypal_payment_id'); }
46
+ public static function processorAuthorizationCode() { return new TextNode('processor_authorization_code'); }
47
+ public static function processorDeclinedAt() { return new RangeNode("processorDeclinedAt"); }
48
+ public static function refund() { return new KeyValueNode("refund"); }
49
+ public static function settledAt() { return new RangeNode("settledAt"); }
50
+ public static function settlementBatchId() { return new TextNode('settlement_batch_id'); }
51
+ public static function shippingCompany() { return new TextNode('shipping_company'); }
52
+ public static function shippingCountryName() { return new TextNode('shipping_country_name'); }
53
+ public static function shippingExtendedAddress() { return new TextNode('shipping_extended_address'); }
54
+ public static function shippingFirstName() { return new TextNode('shipping_first_name'); }
55
+ public static function shippingLastName() { return new TextNode('shipping_last_name'); }
56
+ public static function shippingLocality() { return new TextNode('shipping_locality'); }
57
+ public static function shippingPostalCode() { return new TextNode('shipping_postal_code'); }
58
+ public static function shippingRegion() { return new TextNode('shipping_region'); }
59
+ public static function shippingStreetAddress() { return new TextNode('shipping_street_address'); }
60
+ public static function submittedForSettlementAt() { return new RangeNode("submittedForSettlementAt"); }
61
+ public static function user() { return new MultipleValueNode('user'); }
62
+ public static function voidedAt() { return new RangeNode("voidedAt"); }
63
+
64
+ public static function createdUsing()
65
+ {
66
+ return new MultipleValueNode('created_using', [
67
+ Transaction::FULL_INFORMATION,
68
+ Transaction::TOKEN
69
+ ]);
70
+ }
71
+
72
+ public static function creditCardCardType()
73
+ {
74
+ return new MultipleValueNode('credit_card_card_type', [
75
+ CreditCard::AMEX,
76
+ CreditCard::CARTE_BLANCHE,
77
+ CreditCard::CHINA_UNION_PAY,
78
+ CreditCard::DINERS_CLUB_INTERNATIONAL,
79
+ CreditCard::DISCOVER,
80
+ CreditCard::JCB,
81
+ CreditCard::LASER,
82
+ CreditCard::MAESTRO,
83
+ CreditCard::MASTER_CARD,
84
+ CreditCard::SOLO,
85
+ CreditCard::SWITCH_TYPE,
86
+ CreditCard::VISA,
87
+ CreditCard::UNKNOWN
88
+ ]);
89
+ }
90
+
91
+ public static function creditCardCustomerLocation()
92
+ {
93
+ return new MultipleValueNode('credit_card_customer_location', [
94
+ CreditCard::INTERNATIONAL,
95
+ CreditCard::US
96
+ ]);
97
+ }
98
+
99
+ public static function source()
100
+ {
101
+ return new MultipleValueNode('source', []);
102
+ }
103
+
104
+ public static function status()
105
+ {
106
+ return new MultipleValueNode('status', [
107
+ Transaction::AUTHORIZATION_EXPIRED,
108
+ Transaction::AUTHORIZING,
109
+ Transaction::AUTHORIZED,
110
+ Transaction::GATEWAY_REJECTED,
111
+ Transaction::FAILED,
112
+ Transaction::PROCESSOR_DECLINED,
113
+ Transaction::SETTLED,
114
+ Transaction::SETTLING,
115
+ Transaction::SUBMITTED_FOR_SETTLEMENT,
116
+ Transaction::VOIDED,
117
+ Transaction::SETTLEMENT_DECLINED,
118
+ Transaction::SETTLEMENT_PENDING
119
+ ]);
120
+ }
121
+
122
+ public static function type()
123
+ {
124
+ return new MultipleValueNode('type', [
125
+ Transaction::SALE,
126
+ Transaction::CREDIT
127
+ ]);
128
+ }
129
+ }
130
+ class_alias('Braintree\TransactionSearch', 'Braintree_TransactionSearch');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TransparentRedirect.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree Transparent Redirect module
6
+ * Static class providing methods to build Transparent Redirect urls.
7
+ *
8
+ * The TransparentRedirect module provides methods to build the tr_data param
9
+ * that must be submitted when using the transparent redirect API.
10
+ * For more information
11
+ * about transparent redirect, see (TODO).
12
+ *
13
+ * You must provide a redirectUrl to which the gateway will redirect the
14
+ * user the action is complete.
15
+ *
16
+ * <code>
17
+ * $trData = TransparentRedirect::createCustomerData(array(
18
+ * 'redirectUrl => 'http://example.com/redirect_back_to_merchant_site',
19
+ * ));
20
+ * </code>
21
+ *
22
+ * In addition to the redirectUrl, any data that needs to be protected
23
+ * from user tampering should be included in the trData.
24
+ * For example, to prevent the user from tampering with the transaction
25
+ * amount, include the amount in the trData.
26
+ *
27
+ * <code>
28
+ * $trData = TransparentRedirect::transactionData(array(
29
+ * 'redirectUrl' => 'http://example.com/complete_transaction',
30
+ * 'transaction' => array('amount' => '100.00'),
31
+ * ));
32
+ *
33
+ * </code>
34
+ *
35
+ * @package Braintree
36
+ * @category Resources
37
+ */
38
+ class TransparentRedirect
39
+ {
40
+ // Request Kinds
41
+ const CREATE_TRANSACTION = 'create_transaction';
42
+ const CREATE_PAYMENT_METHOD = 'create_payment_method';
43
+ const UPDATE_PAYMENT_METHOD = 'update_payment_method';
44
+ const CREATE_CUSTOMER = 'create_customer';
45
+ const UPDATE_CUSTOMER = 'update_customer';
46
+
47
+ /**
48
+ * @ignore
49
+ * don't permit an explicit call of the constructor!
50
+ * (like $t = new TransparentRedirect())
51
+ */
52
+ protected function __construct()
53
+ {
54
+
55
+ }
56
+
57
+
58
+ // static methods redirecting to gateway
59
+
60
+ public static function confirm($queryString)
61
+ {
62
+ return Configuration::gateway()->transparentRedirect()->confirm($queryString);
63
+ }
64
+
65
+ public static function createCreditCardData($params)
66
+ {
67
+ return Configuration::gateway()->transparentRedirect()->createCreditCardData($params);
68
+ }
69
+
70
+ public static function createCustomerData($params)
71
+ {
72
+ return Configuration::gateway()->transparentRedirect()->createCustomerData($params);
73
+ }
74
+
75
+ public static function url()
76
+ {
77
+ return Configuration::gateway()->transparentRedirect()->url();
78
+ }
79
+
80
+ public static function transactionData($params)
81
+ {
82
+ return Configuration::gateway()->transparentRedirect()->transactionData($params);
83
+ }
84
+
85
+ public static function updateCreditCardData($params)
86
+ {
87
+ return Configuration::gateway()->transparentRedirect()->updateCreditCardData($params);
88
+ }
89
+
90
+ public static function updateCustomerData($params)
91
+ {
92
+ return Configuration::gateway()->transparentRedirect()->updateCustomerData($params);
93
+ }
94
+
95
+ public static function parseAndValidateQueryString($queryString)
96
+ {
97
+ return Configuration::gateway()->transparentRedirect()->parseAndValidateQueryString($queryString);
98
+ }
99
+ }
100
+ class_alias('Braintree\TransparentRedirect', 'Braintree_TransparentRedirect');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/TransparentRedirectGateway.php ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+ use DateTime;
6
+ use DateTimeZone;
7
+
8
+ /**
9
+ * Braintree Transparent Redirect Gateway module
10
+ * Static class providing methods to build Transparent Redirect urls
11
+ *
12
+ * @package Braintree
13
+ * @category Resources
14
+ */
15
+ class TransparentRedirectGateway
16
+ {
17
+ private $_gateway;
18
+ private $_config;
19
+
20
+ public function __construct($gateway)
21
+ {
22
+ $this->_gateway = $gateway;
23
+ $this->_config = $gateway->config;
24
+ $this->_config->assertHasAccessTokenOrKeys();
25
+ }
26
+
27
+ /**
28
+ *
29
+ * @ignore
30
+ */
31
+ private static $_transparentRedirectKeys = 'redirectUrl';
32
+ private static $_createCustomerSignature;
33
+ private static $_updateCustomerSignature;
34
+ private static $_transactionSignature;
35
+ private static $_createCreditCardSignature;
36
+ private static $_updateCreditCardSignature;
37
+
38
+ /**
39
+ * create signatures for different call types
40
+ * @ignore
41
+ */
42
+ public static function init()
43
+ {
44
+
45
+ self::$_createCustomerSignature = [
46
+ self::$_transparentRedirectKeys,
47
+ ['customer' => CustomerGateway::createSignature()],
48
+ ];
49
+ self::$_updateCustomerSignature = [
50
+ self::$_transparentRedirectKeys,
51
+ 'customerId',
52
+ ['customer' => CustomerGateway::updateSignature()],
53
+ ];
54
+ self::$_transactionSignature = [
55
+ self::$_transparentRedirectKeys,
56
+ ['transaction' => TransactionGateway::createSignature()],
57
+ ];
58
+ self::$_createCreditCardSignature = [
59
+ self::$_transparentRedirectKeys,
60
+ ['creditCard' => CreditCardGateway::createSignature()],
61
+ ];
62
+ self::$_updateCreditCardSignature = [
63
+ self::$_transparentRedirectKeys,
64
+ 'paymentMethodToken',
65
+ ['creditCard' => CreditCardGateway::updateSignature()],
66
+ ];
67
+ }
68
+
69
+ public function confirm($queryString)
70
+ {
71
+ $params = TransparentRedirect::parseAndValidateQueryString(
72
+ $queryString
73
+ );
74
+ $confirmationKlasses = [
75
+ TransparentRedirect::CREATE_TRANSACTION => 'Braintree\TransactionGateway',
76
+ TransparentRedirect::CREATE_CUSTOMER => 'Braintree\CustomerGateway',
77
+ TransparentRedirect::UPDATE_CUSTOMER => 'Braintree\CustomerGateway',
78
+ TransparentRedirect::CREATE_PAYMENT_METHOD => 'Braintree\CreditCardGateway',
79
+ TransparentRedirect::UPDATE_PAYMENT_METHOD => 'Braintree\CreditCardGateway',
80
+ ];
81
+ $confirmationGateway = new $confirmationKlasses[$params["kind"]]($this->_gateway);
82
+ return $confirmationGateway->_doCreate('/transparent_redirect_requests/' . $params['id'] . '/confirm', []);
83
+ }
84
+
85
+ /**
86
+ * returns the trData string for creating a credit card,
87
+ * @param array $params
88
+ * @return string
89
+ */
90
+ public function createCreditCardData($params)
91
+ {
92
+ Util::verifyKeys(
93
+ self::$_createCreditCardSignature,
94
+ $params
95
+ );
96
+ $params["kind"] = TransparentRedirect::CREATE_PAYMENT_METHOD;
97
+ return $this->_data($params);
98
+ }
99
+
100
+ /**
101
+ * returns the trData string for creating a customer.
102
+ * @param array $params
103
+ * @return string
104
+ */
105
+ public function createCustomerData($params)
106
+ {
107
+ Util::verifyKeys(
108
+ self::$_createCustomerSignature,
109
+ $params
110
+ );
111
+ $params["kind"] = TransparentRedirect::CREATE_CUSTOMER;
112
+ return $this->_data($params);
113
+
114
+ }
115
+
116
+ public function url()
117
+ {
118
+ return $this->_config->baseUrl() . $this->_config->merchantPath() . '/transparent_redirect_requests';
119
+ }
120
+
121
+ /**
122
+ * returns the trData string for creating a transaction
123
+ * @param array $params
124
+ * @return string
125
+ */
126
+ public function transactionData($params)
127
+ {
128
+ Util::verifyKeys(
129
+ self::$_transactionSignature,
130
+ $params
131
+ );
132
+ $params["kind"] = TransparentRedirect::CREATE_TRANSACTION;
133
+ $transactionType = isset($params['transaction']['type']) ?
134
+ $params['transaction']['type'] :
135
+ null;
136
+ if ($transactionType != Transaction::SALE && $transactionType != Transaction::CREDIT) {
137
+ throw new InvalidArgumentException(
138
+ 'expected transaction[type] of sale or credit, was: ' .
139
+ $transactionType
140
+ );
141
+ }
142
+
143
+ return $this->_data($params);
144
+ }
145
+
146
+ /**
147
+ * Returns the trData string for updating a credit card.
148
+ *
149
+ * The paymentMethodToken of the credit card to update is required.
150
+ *
151
+ * <code>
152
+ * $trData = TransparentRedirect::updateCreditCardData(array(
153
+ * 'redirectUrl' => 'http://example.com/redirect_here',
154
+ * 'paymentMethodToken' => 'token123',
155
+ * ));
156
+ * </code>
157
+ *
158
+ * @param array $params
159
+ * @return string
160
+ */
161
+ public function updateCreditCardData($params)
162
+ {
163
+ Util::verifyKeys(
164
+ self::$_updateCreditCardSignature,
165
+ $params
166
+ );
167
+ if (!isset($params['paymentMethodToken'])) {
168
+ throw new InvalidArgumentException(
169
+ 'expected params to contain paymentMethodToken.'
170
+ );
171
+ }
172
+ $params["kind"] = TransparentRedirect::UPDATE_PAYMENT_METHOD;
173
+ return $this->_data($params);
174
+ }
175
+
176
+ /**
177
+ * Returns the trData string for updating a customer.
178
+ *
179
+ * The customerId of the customer to update is required.
180
+ *
181
+ * <code>
182
+ * $trData = TransparentRedirect::updateCustomerData(array(
183
+ * 'redirectUrl' => 'http://example.com/redirect_here',
184
+ * 'customerId' => 'customer123',
185
+ * ));
186
+ * </code>
187
+ *
188
+ * @param array $params
189
+ * @return string
190
+ */
191
+ public function updateCustomerData($params)
192
+ {
193
+ Util::verifyKeys(
194
+ self::$_updateCustomerSignature,
195
+ $params
196
+ );
197
+ if (!isset($params['customerId'])) {
198
+ throw new InvalidArgumentException(
199
+ 'expected params to contain customerId of customer to update'
200
+ );
201
+ }
202
+ $params["kind"] = TransparentRedirect::UPDATE_CUSTOMER;
203
+ return $this->_data($params);
204
+ }
205
+
206
+ public function parseAndValidateQueryString($queryString)
207
+ {
208
+ // parse the params into an array
209
+ parse_str($queryString, $params);
210
+ // remove the hash
211
+ $queryStringWithoutHash = null;
212
+ if (preg_match('/^(.*)&hash=[a-f0-9]+$/', $queryString, $match)) {
213
+ $queryStringWithoutHash = $match[1];
214
+ }
215
+
216
+ if($params['http_status'] != '200') {
217
+ $message = null;
218
+ if(array_key_exists('bt_message', $params)) {
219
+ $message = $params['bt_message'];
220
+ }
221
+ Util::throwStatusCodeException(isset($params['http_status']) ? $params['http_status'] : null, $message);
222
+ }
223
+
224
+ // recreate the hash and compare it
225
+ if ($this->_hash($queryStringWithoutHash) == $params['hash']) {
226
+ return $params;
227
+ } else {
228
+ throw new Exception\ForgedQueryString();
229
+ }
230
+ }
231
+
232
+
233
+ /**
234
+ *
235
+ * @ignore
236
+ */
237
+ private function _data($params)
238
+ {
239
+ if (!isset($params['redirectUrl'])) {
240
+ throw new InvalidArgumentException(
241
+ 'expected params to contain redirectUrl'
242
+ );
243
+ }
244
+ $params = $this->_underscoreKeys($params);
245
+ $now = new DateTime('now', new DateTimeZone('UTC'));
246
+ $trDataParams = array_merge($params,
247
+ [
248
+ 'api_version' => Configuration::API_VERSION,
249
+ 'public_key' => $this->_config->publicKey(),
250
+ 'time' => $now->format('YmdHis'),
251
+ ]
252
+ );
253
+ ksort($trDataParams);
254
+ $urlEncodedData = http_build_query($trDataParams, null, "&");
255
+ $signatureService = new SignatureService(
256
+ $this->_config->privateKey(),
257
+ "Braintree\Digest::hexDigestSha1"
258
+ );
259
+ return $signatureService->sign($urlEncodedData);
260
+ }
261
+
262
+ private function _underscoreKeys($array)
263
+ {
264
+ foreach($array as $key=>$value)
265
+ {
266
+ $newKey = Util::camelCaseToDelimiter($key, '_');
267
+ unset($array[$key]);
268
+ if (is_array($value))
269
+ {
270
+ $array[$newKey] = $this->_underscoreKeys($value);
271
+ }
272
+ else
273
+ {
274
+ $array[$newKey] = $value;
275
+ }
276
+ }
277
+ return $array;
278
+ }
279
+
280
+ /**
281
+ * @ignore
282
+ */
283
+ private function _hash($string)
284
+ {
285
+ return Digest::hexDigestSha1($this->_config->privateKey(), $string);
286
+ }
287
+ }
288
+ TransparentRedirectGateway::init();
289
+ class_alias('Braintree\TransparentRedirectGateway', 'Braintree_TransparentRedirectGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/UnknownPaymentMethod.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree UnknownPaymentMethod module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+
11
+ /**
12
+ * Manages Braintree UnknownPaymentMethod
13
+ *
14
+ * <b>== More information ==</b>
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @category Resources
19
+ *
20
+ * @property-read string $token
21
+ * @property-read string $imageUrl
22
+ */
23
+ class UnknownPaymentMethod extends Base
24
+ {
25
+
26
+
27
+ /**
28
+ * factory method: returns an instance of UnknownPaymentMethod
29
+ * to the requesting method, with populated properties
30
+ *
31
+ * @ignore
32
+ * @return UnknownPaymentMethod
33
+ */
34
+ public static function factory($attributes)
35
+ {
36
+ $instance = new self();
37
+ $values = array_values($attributes);
38
+ $instance->_initialize(array_shift($values));
39
+ return $instance;
40
+ }
41
+
42
+ /* instance methods */
43
+
44
+ /**
45
+ * returns false if default is null or false
46
+ *
47
+ * @return boolean
48
+ */
49
+ public function isDefault()
50
+ {
51
+ return $this->default;
52
+ }
53
+
54
+ /**
55
+ * sets instance properties from an array of values
56
+ *
57
+ * @access protected
58
+ * @param array $unknownPaymentMethodAttribs array of unknownPaymentMethod data
59
+ * @return void
60
+ */
61
+ protected function _initialize($unknownPaymentMethodAttribs)
62
+ {
63
+ // set the attributes
64
+ $this->imageUrl = 'https://assets.braintreegateway.com/payment_method_logo/unknown.png';
65
+ $this->_attributes = $unknownPaymentMethodAttribs;
66
+ }
67
+
68
+ }
69
+ class_alias('Braintree\UnknownPaymentMethod', 'Braintree_UnknownPaymentMethod');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/UsBankAccount.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree UsBankAccount module
6
+ *
7
+ * @package Braintree
8
+ * @category Resources
9
+ */
10
+
11
+ /**
12
+ * Manages Braintree UsBankAccounts
13
+ *
14
+ * <b>== More information ==</b>
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @category Resources
19
+ *
20
+ * @property-read string $customerId
21
+ * @property-read string $email
22
+ * @property-read string $token
23
+ * @property-read string $imageUrl
24
+ * @property-read string $routingNumber
25
+ * @property-read string $accountType
26
+ * @property-read string $accountHolderName
27
+ * @property-read string $last4
28
+ * @property-read string $bankName
29
+ * @property-read string $achMandate
30
+ * @property-read string $default
31
+ */
32
+ class UsBankAccount extends Base
33
+ {
34
+ /**
35
+ * factory method: returns an instance of UsBankAccount
36
+ * to the requesting method, with populated properties
37
+ *
38
+ * @ignore
39
+ * @return UsBankAccount
40
+ */
41
+ public static function factory($attributes)
42
+ {
43
+ $instance = new self();
44
+ $instance->_initialize($attributes);
45
+ return $instance;
46
+ }
47
+
48
+ /* instance methods */
49
+
50
+ /**
51
+ * sets instance properties from an array of values
52
+ *
53
+ * @access protected
54
+ * @param array $usBankAccountAttribs array of usBankAccount data
55
+ * @return void
56
+ */
57
+ protected function _initialize($usBankAccountAttribs)
58
+ {
59
+ // set the attributes
60
+ $this->_attributes = $usBankAccountAttribs;
61
+
62
+ $achMandate = isset($usBankAccountAttribs['achMandate']) ?
63
+ AchMandate::factory($usBankAccountAttribs['achMandate']) :
64
+ null;
65
+ $this->_set('achMandate', $achMandate);
66
+ }
67
+
68
+ /**
69
+ * create a printable representation of the object as:
70
+ * ClassName[property=value, property=value]
71
+ * @return string
72
+ */
73
+ public function __toString()
74
+ {
75
+ return __CLASS__ . '[' .
76
+ Util::attributesToString($this->_attributes) . ']';
77
+ }
78
+
79
+
80
+ // static methods redirecting to gateway
81
+
82
+ public static function find($token)
83
+ {
84
+ return Configuration::gateway()->usBankAccount()->find($token);
85
+ }
86
+
87
+ public static function sale($token, $transactionAttribs)
88
+ {
89
+ $transactionAttribs['options'] = [
90
+ 'submitForSettlement' => true
91
+ ];
92
+ return Configuration::gateway()->usBankAccount()->sale($token, $transactionAttribs);
93
+ }
94
+ }
95
+ class_alias('Braintree\UsBankAccount', 'Braintree_UsBankAccount');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/UsBankAccountGateway.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
+ /**
7
+ * Braintree UsBankAccountGateway module
8
+ *
9
+ * @package Braintree
10
+ * @category Resources
11
+ */
12
+
13
+ /**
14
+ * Manages Braintree UsBankAccounts
15
+ *
16
+ * <b>== More information ==</b>
17
+ *
18
+ *
19
+ * @package Braintree
20
+ * @category Resources
21
+ */
22
+ class UsBankAccountGateway
23
+ {
24
+ private $_gateway;
25
+ private $_config;
26
+ private $_http;
27
+
28
+ public function __construct($gateway)
29
+ {
30
+ $this->_gateway = $gateway;
31
+ $this->_config = $gateway->config;
32
+ $this->_config->assertHasAccessTokenOrKeys();
33
+ $this->_http = new Http($gateway->config);
34
+ }
35
+
36
+
37
+ /**
38
+ * find a usBankAccount by token
39
+ *
40
+ * @access public
41
+ * @param string $token paypal accountunique id
42
+ * @return UsBankAccount
43
+ * @throws Exception\NotFound
44
+ */
45
+ public function find($token)
46
+ {
47
+ try {
48
+ $path = $this->_config->merchantPath() . '/payment_methods/us_bank_account/' . $token;
49
+ $response = $this->_http->get($path);
50
+ return UsBankAccount::factory($response['usBankAccount']);
51
+ } catch (Exception\NotFound $e) {
52
+ throw new Exception\NotFound(
53
+ 'US bank account with token ' . $token . ' not found'
54
+ );
55
+ }
56
+
57
+ }
58
+
59
+ /**
60
+ * create a new sale for the current UsBank account
61
+ *
62
+ * @param string $token
63
+ * @param array $transactionAttribs
64
+ * @return Result\Successful|Result\Error
65
+ * @see Transaction::sale()
66
+ */
67
+ public function sale($token, $transactionAttribs)
68
+ {
69
+ return Transaction::sale(
70
+ array_merge(
71
+ $transactionAttribs,
72
+ ['paymentMethodToken' => $token]
73
+ )
74
+ );
75
+ }
76
+
77
+ /**
78
+ * generic method for validating incoming gateway responses
79
+ *
80
+ * creates a new UsBankAccount object and encapsulates
81
+ * it inside a Result\Successful object, or
82
+ * encapsulates a Errors object inside a Result\Error
83
+ * alternatively, throws an Unexpected exception if the response is invalid.
84
+ *
85
+ * @ignore
86
+ * @param array $response gateway response values
87
+ * @return Result\Successful|Result\Error
88
+ * @throws Exception\Unexpected
89
+ */
90
+ private function _verifyGatewayResponse($response)
91
+ {
92
+ if (isset($response['usBankAccount'])) {
93
+ // return a populated instance of UsBankAccount
94
+ return new Result\Successful(
95
+ UsBankAccount::factory($response['usBankAccount'])
96
+ );
97
+ } else if (isset($response['apiErrorResponse'])) {
98
+ return new Result\Error($response['apiErrorResponse']);
99
+ } else {
100
+ throw new Exception\Unexpected(
101
+ 'Expected US bank account or apiErrorResponse'
102
+ );
103
+ }
104
+ }
105
+ }
106
+ class_alias('Braintree\UsBankAccountGateway', 'Braintree_UsBankAccountGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Util.php ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ use DateTime;
5
+ use InvalidArgumentException;
6
+
7
+ /**
8
+ * Braintree Utility methods
9
+ * PHP version 5
10
+ */
11
+
12
+ class Util
13
+ {
14
+ /**
15
+ * extracts an attribute and returns an array of objects
16
+ *
17
+ * extracts the requested element from an array, and converts the contents
18
+ * of its child arrays to objects of type $attributeName, or returns
19
+ * an array with a single element containing the value of that array element
20
+ *
21
+ * @param array $attribArray attributes from a search response
22
+ * @param string $attributeName indicates which element of the passed array to extract
23
+ * @return array array of $attributeName objects, or a single element array
24
+ */
25
+ public static function extractAttributeAsArray(&$attribArray, $attributeName)
26
+ {
27
+ if(!isset($attribArray[$attributeName])):
28
+ return [];
29
+ endif;
30
+
31
+ // get what should be an array from the passed array
32
+ $data = $attribArray[$attributeName];
33
+ // set up the class that will be used to convert each array element
34
+ $classFactory = self::buildClassName($attributeName) . '::factory';
35
+ if(is_array($data)):
36
+ // create an object from the data in each element
37
+ $objectArray = array_map($classFactory, $data);
38
+ else:
39
+ return [$data];
40
+ endif;
41
+
42
+ unset($attribArray[$attributeName]);
43
+ return $objectArray;
44
+ }
45
+ /**
46
+ * throws an exception based on the type of error
47
+ * @param string $statusCode HTTP status code to throw exception from
48
+ * @param null|string $message
49
+ * @throws Exception multiple types depending on the error
50
+ * @return void
51
+ */
52
+ public static function throwStatusCodeException($statusCode, $message=null)
53
+ {
54
+ switch($statusCode) {
55
+ case 401:
56
+ throw new Exception\Authentication();
57
+ break;
58
+ case 403:
59
+ throw new Exception\Authorization($message);
60
+ break;
61
+ case 404:
62
+ throw new Exception\NotFound();
63
+ break;
64
+ case 426:
65
+ throw new Exception\UpgradeRequired();
66
+ break;
67
+ case 429:
68
+ throw new Exception\TooManyRequests();
69
+ break;
70
+ case 500:
71
+ throw new Exception\ServerError();
72
+ break;
73
+ case 503:
74
+ throw new Exception\DownForMaintenance();
75
+ break;
76
+ default:
77
+ throw new Exception\Unexpected('Unexpected HTTP_RESPONSE #' . $statusCode);
78
+ break;
79
+ }
80
+ }
81
+
82
+ /**
83
+ *
84
+ * @param string $className
85
+ * @param object $resultObj
86
+ * @return object returns the passed object if successful
87
+ * @throws Exception\ValidationsFailed
88
+ */
89
+ public static function returnObjectOrThrowException($className, $resultObj)
90
+ {
91
+ $resultObjName = self::cleanClassName($className);
92
+ if ($resultObj->success) {
93
+ return $resultObj->$resultObjName;
94
+ } else {
95
+ throw new Exception\ValidationsFailed();
96
+ }
97
+ }
98
+
99
+ /**
100
+ * removes the header from a classname
101
+ *
102
+ * @param string $name ClassName
103
+ * @return camelCased classname minus header
104
+ */
105
+ public static function cleanClassName($name)
106
+ {
107
+ $classNamesToResponseKeys = [
108
+ 'Braintree\CreditCard' => 'creditCard',
109
+ 'Braintree_CreditCard' => 'creditCard',
110
+ 'Braintree\CreditCardGateway' => 'creditCard',
111
+ 'Braintree_CreditCardGateway' => 'creditCard',
112
+ 'Braintree\Customer' => 'customer',
113
+ 'Braintree_Customer' => 'customer',
114
+ 'Braintree\CustomerGateway' => 'customer',
115
+ 'Braintree_CustomerGateway' => 'customer',
116
+ 'Braintree\Subscription' => 'subscription',
117
+ 'Braintree_Subscription' => 'subscription',
118
+ 'Braintree\SubscriptionGateway' => 'subscription',
119
+ 'Braintree_SubscriptionGateway' => 'subscription',
120
+ 'Braintree\Transaction' => 'transaction',
121
+ 'Braintree_Transaction' => 'transaction',
122
+ 'Braintree\TransactionGateway' => 'transaction',
123
+ 'Braintree_TransactionGateway' => 'transaction',
124
+ 'Braintree\CreditCardVerification' => 'verification',
125
+ 'Braintree_CreditCardVerification' => 'verification',
126
+ 'Braintree\CreditCardVerificationGateway' => 'verification',
127
+ 'Braintree_CreditCardVerificationGateway' => 'verification',
128
+ 'Braintree\AddOn' => 'addOn',
129
+ 'Braintree_AddOn' => 'addOn',
130
+ 'Braintree\AddOnGateway' => 'addOn',
131
+ 'Braintree_AddOnGateway' => 'addOn',
132
+ 'Braintree\Discount' => 'discount',
133
+ 'Braintree_Discount' => 'discount',
134
+ 'Braintree\DiscountGateway' => 'discount',
135
+ 'Braintree_DiscountGateway' => 'discount',
136
+ 'Braintree\Plan' => 'plan',
137
+ 'Braintree_Plan' => 'plan',
138
+ 'Braintree\PlanGateway' => 'plan',
139
+ 'Braintree_PlanGateway' => 'plan',
140
+ 'Braintree\Address' => 'address',
141
+ 'Braintree_Address' => 'address',
142
+ 'Braintree\AddressGateway' => 'address',
143
+ 'Braintree_AddressGateway' => 'address',
144
+ 'Braintree\SettlementBatchSummary' => 'settlementBatchSummary',
145
+ 'Braintree_SettlementBatchSummary' => 'settlementBatchSummary',
146
+ 'Braintree\SettlementBatchSummaryGateway' => 'settlementBatchSummary',
147
+ 'Braintree_SettlementBatchSummaryGateway' => 'settlementBatchSummary',
148
+ 'Braintree\Merchant' => 'merchant',
149
+ 'Braintree_Merchant' => 'merchant',
150
+ 'Braintree\MerchantGateway' => 'merchant',
151
+ 'Braintree_MerchantGateway' => 'merchant',
152
+ 'Braintree\MerchantAccount' => 'merchantAccount',
153
+ 'Braintree_MerchantAccount' => 'merchantAccount',
154
+ 'Braintree\MerchantAccountGateway' => 'merchantAccount',
155
+ 'Braintree_MerchantAccountGateway' => 'merchantAccount',
156
+ 'Braintree\OAuthCredentials' => 'credentials',
157
+ 'Braintree_OAuthCredentials' => 'credentials',
158
+ 'Braintree\OAuthResult' => 'result',
159
+ 'Braintree_OAuthResult' => 'result',
160
+ 'Braintree\PayPalAccount' => 'paypalAccount',
161
+ 'Braintree_PayPalAccount' => 'paypalAccount',
162
+ 'Braintree\PayPalAccountGateway' => 'paypalAccount',
163
+ 'Braintree_PayPalAccountGateway' => 'paypalAccount',
164
+ ];
165
+
166
+ return $classNamesToResponseKeys[$name];
167
+ }
168
+
169
+ /**
170
+ *
171
+ * @param string $name className
172
+ * @return string ClassName
173
+ */
174
+ public static function buildClassName($name)
175
+ {
176
+ $responseKeysToClassNames = [
177
+ 'creditCard' => 'Braintree\CreditCard',
178
+ 'customer' => 'Braintree\Customer',
179
+ 'subscription' => 'Braintree\Subscription',
180
+ 'transaction' => 'Braintree\Transaction',
181
+ 'verification' => 'Braintree\CreditCardVerification',
182
+ 'addOn' => 'Braintree\AddOn',
183
+ 'discount' => 'Braintree\Discount',
184
+ 'plan' => 'Braintree\Plan',
185
+ 'address' => 'Braintree\Address',
186
+ 'settlementBatchSummary' => 'Braintree\SettlementBatchSummary',
187
+ 'merchantAccount' => 'Braintree\MerchantAccount',
188
+ ];
189
+
190
+ return (string) $responseKeysToClassNames[$name];
191
+ }
192
+
193
+ /**
194
+ * convert alpha-beta-gamma to alphaBetaGamma
195
+ *
196
+ * @access public
197
+ * @param string $string
198
+ * @param null|string $delimiter
199
+ * @return string modified string
200
+ */
201
+ public static function delimiterToCamelCase($string, $delimiter = '[\-\_]')
202
+ {
203
+ // php doesn't garbage collect functions created by create_function()
204
+ // so use a static variable to avoid adding a new function to memory
205
+ // every time this function is called.
206
+ static $callback = null;
207
+ if ($callback === null) {
208
+ $callback = create_function('$matches', 'return strtoupper($matches[1]);');
209
+ }
210
+
211
+ return preg_replace_callback('/' . $delimiter . '(\w)/', $callback, $string);
212
+ }
213
+
214
+ /**
215
+ * convert alpha-beta-gamma to alpha_beta_gamma
216
+ *
217
+ * @access public
218
+ * @param string $string
219
+ * @return string modified string
220
+ */
221
+ public static function delimiterToUnderscore($string)
222
+ {
223
+ return preg_replace('/-/', '_', $string);
224
+ }
225
+
226
+
227
+ /**
228
+ * find capitals and convert to delimiter + lowercase
229
+ *
230
+ * @access public
231
+ * @param string $string
232
+ * @param null|string $delimiter
233
+ * @return string modified string
234
+ */
235
+ public static function camelCaseToDelimiter($string, $delimiter = '-')
236
+ {
237
+ return strtolower(preg_replace('/([A-Z])/', "$delimiter\\1", $string));
238
+ }
239
+
240
+ public static function delimiterToCamelCaseArray($array, $delimiter = '[\-\_]')
241
+ {
242
+ $converted = [];
243
+ foreach ($array as $key => $value) {
244
+ if (is_string($key)) {
245
+ $key = self::delimiterToCamelCase($key, $delimiter);
246
+ }
247
+
248
+ if (is_array($value)) {
249
+ // Make an exception for custom fields, which must be underscore (can't be
250
+ // camelCase).
251
+ if ($key === 'customFields') {
252
+ $value = self::delimiterToUnderscoreArray($value);
253
+ } else {
254
+ $value = self::delimiterToCamelCaseArray($value, $delimiter);
255
+ }
256
+ }
257
+ $converted[$key] = $value;
258
+ }
259
+ return $converted;
260
+ }
261
+
262
+ public static function camelCaseToDelimiterArray($array, $delimiter = '-')
263
+ {
264
+ $converted = [];
265
+ foreach ($array as $key => $value) {
266
+ if (is_string($key)) {
267
+ $key = self::camelCaseToDelimiter($key, $delimiter);
268
+ }
269
+ if (is_array($value)) {
270
+ $value = self::camelCaseToDelimiterArray($value, $delimiter);
271
+ }
272
+ $converted[$key] = $value;
273
+ }
274
+ return $converted;
275
+ }
276
+
277
+ public static function delimiterToUnderscoreArray($array)
278
+ {
279
+ $converted = [];
280
+ foreach ($array as $key => $value) {
281
+ $key = self::delimiterToUnderscore($key);
282
+ $converted[$key] = $value;
283
+ }
284
+ return $converted;
285
+ }
286
+
287
+ /**
288
+ *
289
+ * @param array $array associative array to implode
290
+ * @param string $separator (optional, defaults to =)
291
+ * @param string $glue (optional, defaults to ', ')
292
+ * @return bool
293
+ */
294
+ public static function implodeAssociativeArray($array, $separator = '=', $glue = ', ')
295
+ {
296
+ // build a new array with joined keys and values
297
+ $tmpArray = null;
298
+ foreach ($array AS $key => $value) {
299
+ if ($value instanceof DateTime) {
300
+ $value = $value->format('r');
301
+ }
302
+ $tmpArray[] = $key . $separator . $value;
303
+ }
304
+ // implode and return the new array
305
+ return (is_array($tmpArray)) ? implode($glue, $tmpArray) : false;
306
+ }
307
+
308
+ public static function attributesToString($attributes) {
309
+ $printableAttribs = [];
310
+ foreach ($attributes AS $key => $value) {
311
+ if (is_array($value)) {
312
+ $pAttrib = self::attributesToString($value);
313
+ } else if ($value instanceof DateTime) {
314
+ $pAttrib = $value->format(DateTime::RFC850);
315
+ } else {
316
+ $pAttrib = $value;
317
+ }
318
+ $printableAttribs[$key] = sprintf('%s', $pAttrib);
319
+ }
320
+ return self::implodeAssociativeArray($printableAttribs);
321
+ }
322
+
323
+ /**
324
+ * verify user request structure
325
+ *
326
+ * compares the expected signature of a gateway request
327
+ * against the actual structure sent by the user
328
+ *
329
+ * @param array $signature
330
+ * @param array $attributes
331
+ */
332
+ public static function verifyKeys($signature, $attributes)
333
+ {
334
+ $validKeys = self::_flattenArray($signature);
335
+ $userKeys = self::_flattenUserKeys($attributes);
336
+ $invalidKeys = array_diff($userKeys, $validKeys);
337
+ $invalidKeys = self::_removeWildcardKeys($validKeys, $invalidKeys);
338
+
339
+ if(!empty($invalidKeys)) {
340
+ asort($invalidKeys);
341
+ $sortedList = join(', ', $invalidKeys);
342
+ throw new InvalidArgumentException('invalid keys: ' . $sortedList);
343
+ }
344
+ }
345
+ /**
346
+ * flattens a numerically indexed nested array to a single level
347
+ * @param array $keys
348
+ * @param string $namespace
349
+ * @return array
350
+ */
351
+ private static function _flattenArray($keys, $namespace = null)
352
+ {
353
+ $flattenedArray = [];
354
+ foreach($keys AS $key) {
355
+ if(is_array($key)) {
356
+ $theKeys = array_keys($key);
357
+ $theValues = array_values($key);
358
+ $scope = $theKeys[0];
359
+ $fullKey = empty($namespace) ? $scope : $namespace . '[' . $scope . ']';
360
+ $flattenedArray = array_merge($flattenedArray, self::_flattenArray($theValues[0], $fullKey));
361
+ } else {
362
+ $fullKey = empty($namespace) ? $key : $namespace . '[' . $key . ']';
363
+ $flattenedArray[] = $fullKey;
364
+ }
365
+ }
366
+ sort($flattenedArray);
367
+ return $flattenedArray;
368
+ }
369
+
370
+ private static function _flattenUserKeys($keys, $namespace = null)
371
+ {
372
+ $flattenedArray = [];
373
+
374
+ foreach($keys AS $key => $value) {
375
+ $fullKey = empty($namespace) ? $key : $namespace;
376
+ if (!is_numeric($key) && $namespace != null) {
377
+ $fullKey .= '[' . $key . ']';
378
+ }
379
+ if (is_numeric($key) && is_string($value)) {
380
+ $fullKey .= '[' . $value . ']';
381
+ }
382
+ if(is_array($value)) {
383
+ $more = self::_flattenUserKeys($value, $fullKey);
384
+ $flattenedArray = array_merge($flattenedArray, $more);
385
+ } else {
386
+ $flattenedArray[] = $fullKey;
387
+ }
388
+ }
389
+ sort($flattenedArray);
390
+ return $flattenedArray;
391
+ }
392
+
393
+ /**
394
+ * removes wildcard entries from the invalid keys array
395
+ * @param array $validKeys
396
+ * @param <array $invalidKeys
397
+ * @return array
398
+ */
399
+ private static function _removeWildcardKeys($validKeys, $invalidKeys)
400
+ {
401
+ foreach($validKeys AS $key) {
402
+ if (stristr($key, '[_anyKey_]')) {
403
+ $wildcardKey = str_replace('[_anyKey_]', '', $key);
404
+ foreach ($invalidKeys AS $index => $invalidKey) {
405
+ if (stristr($invalidKey, $wildcardKey)) {
406
+ unset($invalidKeys[$index]);
407
+ }
408
+ }
409
+ }
410
+ }
411
+ return $invalidKeys;
412
+ }
413
+ }
414
+ class_alias('Braintree\Util', 'Braintree_Util');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/VenmoAccount.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree VenmoAccount module
6
+ * Creates and manages Braintree Venmo accounts
7
+ *
8
+ * <b>== More information ==</b>
9
+ *
10
+ * See {@link https://developers.braintreepayments.com/javascript+php}<br />
11
+ *
12
+ * @package Braintree
13
+ * @category Resources
14
+ *
15
+ * @property-read string $createdAt
16
+ * @property-read string $default
17
+ * @property-read string $updatedAt
18
+ * @property-read string $customerId
19
+ * @property-read string $sourceDescription
20
+ * @property-read string $token
21
+ * @property-read string $imageUrl
22
+ * @property-read string $username
23
+ * @property-read string $venmoUserId
24
+ */
25
+ class VenmoAccount extends Base
26
+ {
27
+ /* instance methods */
28
+ /**
29
+ * returns false if default is null or false
30
+ *
31
+ * @return boolean
32
+ */
33
+ public function isDefault()
34
+ {
35
+ return $this->default;
36
+ }
37
+
38
+ /**
39
+ * factory method: returns an instance of VenmoAccount
40
+ * to the requesting method, with populated properties
41
+ *
42
+ * @ignore
43
+ * @return VenmoAccount
44
+ */
45
+ public static function factory($attributes)
46
+ {
47
+
48
+ $instance = new self();
49
+ $instance->_initialize($attributes);
50
+ return $instance;
51
+ }
52
+
53
+ /**
54
+ * sets instance properties from an array of values
55
+ *
56
+ * @access protected
57
+ * @param array $venmoAccountAttribs array of Venmo account properties
58
+ * @return void
59
+ */
60
+ protected function _initialize($venmoAccountAttribs)
61
+ {
62
+ $this->_attributes = $venmoAccountAttribs;
63
+
64
+ $subscriptionArray = array();
65
+ if (isset($venmoAccountAttribs['subscriptions'])) {
66
+ foreach ($venmoAccountAttribs['subscriptions'] AS $subscription) {
67
+ $subscriptionArray[] = Subscription::factory($subscription);
68
+ }
69
+ }
70
+
71
+ $this->_set('subscriptions', $subscriptionArray);
72
+ }
73
+ }
74
+ class_alias('Braintree\VenmoAccount', 'Braintree_VenmoAccount');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Version.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree Library Version
6
+ * stores version information about the Braintree library
7
+ */
8
+ class Version
9
+ {
10
+ /**
11
+ * class constants
12
+ */
13
+ const MAJOR = 3;
14
+ const MINOR = 23;
15
+ const TINY = 1;
16
+
17
+ /**
18
+ * @ignore
19
+ * @access protected
20
+ */
21
+ protected function __construct()
22
+ {
23
+ }
24
+
25
+ /**
26
+ *
27
+ * @return string the current library version
28
+ */
29
+ public static function get()
30
+ {
31
+ return self::MAJOR . '.' . self::MINOR . '.' . self::TINY;
32
+ }
33
+ }
34
+ class_alias('Braintree\Version', 'Braintree_Version');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/VisaCheckoutCard.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree VisaCheckoutCard module
6
+ * Creates and manages Braintree VisaCheckoutCards
7
+ *
8
+ * <b>== More information ==</b>
9
+ *
10
+ * For more detailed information on CreditCard verifications, see {@link http://www.braintreepayments.com/gateway/credit-card-verification-api http://www.braintreepaymentsolutions.com/gateway/credit-card-verification-api}
11
+ *
12
+ * @package Braintree
13
+ * @category Resources
14
+ *
15
+ * @property-read string $billingAddress
16
+ * @property-read string $bin
17
+ * @property-read string $callId
18
+ * @property-read string $cardType
19
+ * @property-read string $cardholderName
20
+ * @property-read string $commercial
21
+ * @property-read string $countryOfIssuance
22
+ * @property-read string $createdAt
23
+ * @property-read string $customerId
24
+ * @property-read string $customerLocation
25
+ * @property-read string $debit
26
+ * @property-read string $default
27
+ * @property-read string $durbinRegulated
28
+ * @property-read string $expirationDate
29
+ * @property-read string $expirationMonth
30
+ * @property-read string $expirationYear
31
+ * @property-read string $expired
32
+ * @property-read string $healthcare
33
+ * @property-read string $imageUrl
34
+ * @property-read string $issuingBank
35
+ * @property-read string $last4
36
+ * @property-read string $maskedNumber
37
+ * @property-read string $payroll
38
+ * @property-read string $prepaid
39
+ * @property-read string $productId
40
+ * @property-read string $subscriptions
41
+ * @property-read string $token
42
+ * @property-read string $uniqueNumberIdentifier
43
+ * @property-read string $updatedAt
44
+ */
45
+ class VisaCheckoutCard extends Base
46
+ {
47
+ /* instance methods */
48
+ /**
49
+ * returns false if default is null or false
50
+ *
51
+ * @return boolean
52
+ */
53
+ public function isDefault()
54
+ {
55
+ return $this->default;
56
+ }
57
+
58
+ /**
59
+ * checks whether the card is expired based on the current date
60
+ *
61
+ * @return boolean
62
+ */
63
+ public function isExpired()
64
+ {
65
+ return $this->expired;
66
+ }
67
+
68
+ /**
69
+ * sets instance properties from an array of values
70
+ *
71
+ * @access protected
72
+ * @param array $creditCardAttribs array of creditcard data
73
+ * @return void
74
+ */
75
+ protected function _initialize($creditCardAttribs)
76
+ {
77
+ // set the attributes
78
+ $this->_attributes = $creditCardAttribs;
79
+
80
+ // map each address into its own object
81
+ $billingAddress = isset($creditCardAttribs['billingAddress']) ?
82
+ Address::factory($creditCardAttribs['billingAddress']) :
83
+ null;
84
+
85
+ $subscriptionArray = [];
86
+ if (isset($creditCardAttribs['subscriptions'])) {
87
+ foreach ($creditCardAttribs['subscriptions'] AS $subscription) {
88
+ $subscriptionArray[] = Subscription::factory($subscription);
89
+ }
90
+ }
91
+
92
+ $this->_set('subscriptions', $subscriptionArray);
93
+ $this->_set('billingAddress', $billingAddress);
94
+ $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
95
+ $this->_set('maskedNumber', $this->bin . '******' . $this->last4);
96
+
97
+ if(isset($creditCardAttribs['verifications']) && count($creditCardAttribs['verifications']) > 0) {
98
+ $verifications = $creditCardAttribs['verifications'];
99
+ usort($verifications, [$this, '_compareCreatedAtOnVerifications']);
100
+
101
+ $this->_set('verification', CreditCardVerification::factory($verifications[0]));
102
+ }
103
+ }
104
+
105
+ private function _compareCreatedAtOnVerifications($verificationAttrib1, $verificationAttrib2)
106
+ {
107
+ return ($verificationAttrib2['createdAt'] < $verificationAttrib1['createdAt']) ? -1 : 1;
108
+ }
109
+
110
+ /**
111
+ * returns false if comparing object is not a VisaCheckoutCard,
112
+ * or is a VisaCheckoutCard with a different id
113
+ *
114
+ * @param object $otherVisaCheckoutCard customer to compare against
115
+ * @return boolean
116
+ */
117
+ public function isEqual($otherVisaCheckoutCard)
118
+ {
119
+ return !($otherVisaCheckoutCard instanceof self) ? false : $this->token === $otherVisaCheckoutCard->token;
120
+ }
121
+
122
+ /**
123
+ * create a printable representation of the object as:
124
+ * ClassName[property=value, property=value]
125
+ * @return string
126
+ */
127
+ public function __toString()
128
+ {
129
+ return __CLASS__ . '[' .
130
+ Util::attributesToString($this->_attributes) .']';
131
+ }
132
+
133
+ /**
134
+ * factory method: returns an instance of VisaCheckoutCard
135
+ * to the requesting method, with populated properties
136
+ *
137
+ * @ignore
138
+ * @return VisaCheckoutCard
139
+ */
140
+ public static function factory($attributes)
141
+ {
142
+ $defaultAttributes = [
143
+ 'bin' => '',
144
+ 'expirationMonth' => '',
145
+ 'expirationYear' => '',
146
+ 'last4' => '',
147
+ ];
148
+
149
+ $instance = new self();
150
+ $instance->_initialize(array_merge($defaultAttributes, $attributes));
151
+ return $instance;
152
+ }
153
+ }
154
+ class_alias('Braintree\VisaCheckoutCard', 'Braintree_VisaCheckoutCard');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/WebhookNotification.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class WebhookNotification extends Base
5
+ {
6
+ const SUBSCRIPTION_CANCELED = 'subscription_canceled';
7
+ const SUBSCRIPTION_CHARGED_SUCCESSFULLY = 'subscription_charged_successfully';
8
+ const SUBSCRIPTION_CHARGED_UNSUCCESSFULLY = 'subscription_charged_unsuccessfully';
9
+ const SUBSCRIPTION_EXPIRED = 'subscription_expired';
10
+ const SUBSCRIPTION_TRIAL_ENDED = 'subscription_trial_ended';
11
+ const SUBSCRIPTION_WENT_ACTIVE = 'subscription_went_active';
12
+ const SUBSCRIPTION_WENT_PAST_DUE = 'subscription_went_past_due';
13
+ const SUB_MERCHANT_ACCOUNT_APPROVED = 'sub_merchant_account_approved';
14
+ const SUB_MERCHANT_ACCOUNT_DECLINED = 'sub_merchant_account_declined';
15
+ const TRANSACTION_DISBURSED = 'transaction_disbursed';
16
+ const TRANSACTION_SETTLED = 'transaction_settled';
17
+ const TRANSACTION_SETTLEMENT_DECLINED = 'transaction_settlement_declined';
18
+ const DISBURSEMENT_EXCEPTION = 'disbursement_exception';
19
+ const DISBURSEMENT = 'disbursement';
20
+ const DISPUTE_OPENED = 'dispute_opened';
21
+ const DISPUTE_LOST = 'dispute_lost';
22
+ const DISPUTE_WON = 'dispute_won';
23
+ const PARTNER_MERCHANT_CONNECTED = 'partner_merchant_connected';
24
+ const PARTNER_MERCHANT_DISCONNECTED = 'partner_merchant_disconnected';
25
+ const PARTNER_MERCHANT_DECLINED = 'partner_merchant_declined';
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
+
31
+ public static function parse($signature, $payload) {
32
+ return Configuration::gateway()->webhookNotification()->parse($signature, $payload);
33
+ }
34
+
35
+ public static function verify($challenge) {
36
+ return Configuration::gateway()->webhookNotification()->verify($challenge);
37
+ }
38
+
39
+ public static function factory($attributes)
40
+ {
41
+ $instance = new self();
42
+ $instance->_initialize($attributes);
43
+ return $instance;
44
+ }
45
+
46
+ protected function _initialize($attributes)
47
+ {
48
+ $this->_attributes = $attributes;
49
+
50
+ if (isset($attributes['subject']['apiErrorResponse'])) {
51
+ $wrapperNode = $attributes['subject']['apiErrorResponse'];
52
+ } else {
53
+ $wrapperNode = $attributes['subject'];
54
+ }
55
+
56
+ if (isset($wrapperNode['subscription'])) {
57
+ $this->_set('subscription', Subscription::factory($attributes['subject']['subscription']));
58
+ }
59
+
60
+ if (isset($wrapperNode['merchantAccount'])) {
61
+ $this->_set('merchantAccount', MerchantAccount::factory($wrapperNode['merchantAccount']));
62
+ }
63
+
64
+ if (isset($wrapperNode['transaction'])) {
65
+ $this->_set('transaction', Transaction::factory($wrapperNode['transaction']));
66
+ }
67
+
68
+ if (isset($wrapperNode['disbursement'])) {
69
+ $this->_set('disbursement', Disbursement::factory($wrapperNode['disbursement']));
70
+ }
71
+
72
+ if (isset($wrapperNode['partnerMerchant'])) {
73
+ $this->_set('partnerMerchant', PartnerMerchant::factory($wrapperNode['partnerMerchant']));
74
+ }
75
+
76
+ if (isset($wrapperNode['connectedMerchantStatusTransitioned'])) {
77
+ $this->_set('connectedMerchantStatusTransitioned', ConnectedMerchantStatusTransitioned::factory($wrapperNode['connectedMerchantStatusTransitioned']));
78
+ }
79
+
80
+ if (isset($wrapperNode['connectedMerchantPaypalStatusChanged'])) {
81
+ $this->_set('connectedMerchantPayPalStatusChanged', ConnectedMerchantPayPalStatusChanged::factory($wrapperNode['connectedMerchantPaypalStatusChanged']));
82
+ }
83
+
84
+ if (isset($wrapperNode['dispute'])) {
85
+ $this->_set('dispute', Dispute::factory($wrapperNode['dispute']));
86
+ }
87
+
88
+ if (isset($wrapperNode['accountUpdaterDailyReport'])) {
89
+ $this->_set('accountUpdaterDailyReport', AccountUpdaterDailyReport::factory($wrapperNode['accountUpdaterDailyReport']));
90
+ }
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');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/WebhookNotificationGateway.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class WebhookNotificationGateway
5
+ {
6
+
7
+ public function __construct($gateway)
8
+ {
9
+ $this->config = $gateway->config;
10
+ $this->config->assertHasAccessTokenOrKeys();
11
+ }
12
+
13
+ public function parse($signature, $payload)
14
+ {
15
+ if (preg_match("/[^A-Za-z0-9+=\/\n]/", $payload) === 1) {
16
+ throw new Exception\InvalidSignature("payload contains illegal characters");
17
+ }
18
+
19
+ self::_validateSignature($signature, $payload);
20
+
21
+ $xml = base64_decode($payload);
22
+ $attributes = Xml::buildArrayFromXml($xml);
23
+ return WebhookNotification::factory($attributes['notification']);
24
+ }
25
+
26
+ public function verify($challenge)
27
+ {
28
+ if (!preg_match('/^[a-f0-9]{20,32}$/', $challenge)) {
29
+ throw new Exception\InvalidChallenge("challenge contains non-hex characters");
30
+ }
31
+ $publicKey = $this->config->publicKey();
32
+ $digest = Digest::hexDigestSha1($this->config->privateKey(), $challenge);
33
+ return "{$publicKey}|{$digest}";
34
+ }
35
+
36
+ private function _payloadMatches($signature, $payload)
37
+ {
38
+ $payloadSignature = Digest::hexDigestSha1($this->config->privateKey(), $payload);
39
+ return Digest::secureCompare($signature, $payloadSignature);
40
+ }
41
+
42
+ private function _validateSignature($signatureString, $payload)
43
+ {
44
+ $signaturePairs = preg_split("/&/", $signatureString);
45
+ $signature = self::_matchingSignature($signaturePairs);
46
+ if (!$signature) {
47
+ throw new Exception\InvalidSignature("no matching public key");
48
+ }
49
+
50
+ if (!(self::_payloadMatches($signature, $payload) || self::_payloadMatches($signature, $payload . "\n"))) {
51
+ throw new Exception\InvalidSignature("signature does not match payload - one has been modified");
52
+ }
53
+ }
54
+
55
+ private function _matchingSignature($signaturePairs)
56
+ {
57
+ foreach ($signaturePairs as $pair)
58
+ {
59
+ $components = preg_split("/\|/", $pair);
60
+ if ($components[0] == $this->config->publicKey()) {
61
+ return $components[1];
62
+ }
63
+ }
64
+
65
+ return null;
66
+ }
67
+ }
68
+
69
+ class_alias('Braintree\WebhookNotificationGateway', 'Braintree_WebhookNotificationGateway');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/WebhookTesting.php ADDED
@@ -0,0 +1,417 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ class WebhookTesting
5
+ {
6
+ public static function sampleNotification($kind, $id)
7
+ {
8
+ $payload = base64_encode(self::_sampleXml($kind, $id)) . "\n";
9
+ $signature = Configuration::publicKey() . "|" . Digest::hexDigestSha1(Configuration::privateKey(), $payload);
10
+
11
+ return [
12
+ 'bt_signature' => $signature,
13
+ 'bt_payload' => $payload
14
+ ];
15
+ }
16
+
17
+ private static function _sampleXml($kind, $id)
18
+ {
19
+ switch ($kind) {
20
+ case WebhookNotification::SUB_MERCHANT_ACCOUNT_APPROVED:
21
+ $subjectXml = self::_merchantAccountApprovedSampleXml($id);
22
+ break;
23
+ case WebhookNotification::SUB_MERCHANT_ACCOUNT_DECLINED:
24
+ $subjectXml = self::_merchantAccountDeclinedSampleXml($id);
25
+ break;
26
+ case WebhookNotification::TRANSACTION_DISBURSED:
27
+ $subjectXml = self::_transactionDisbursedSampleXml($id);
28
+ break;
29
+ case WebhookNotification::TRANSACTION_SETTLED:
30
+ $subjectXml = self::_transactionSettledSampleXml($id);
31
+ break;
32
+ case WebhookNotification::TRANSACTION_SETTLEMENT_DECLINED:
33
+ $subjectXml = self::_transactionSettlementDeclinedSampleXml($id);
34
+ break;
35
+ case WebhookNotification::DISBURSEMENT_EXCEPTION:
36
+ $subjectXml = self::_disbursementExceptionSampleXml($id);
37
+ break;
38
+ case WebhookNotification::DISBURSEMENT:
39
+ $subjectXml = self::_disbursementSampleXml($id);
40
+ break;
41
+ case WebhookNotification::PARTNER_MERCHANT_CONNECTED:
42
+ $subjectXml = self::_partnerMerchantConnectedSampleXml($id);
43
+ break;
44
+ case WebhookNotification::PARTNER_MERCHANT_DISCONNECTED:
45
+ $subjectXml = self::_partnerMerchantDisconnectedSampleXml($id);
46
+ break;
47
+ case WebhookNotification::PARTNER_MERCHANT_DECLINED:
48
+ $subjectXml = self::_partnerMerchantDeclinedSampleXml($id);
49
+ break;
50
+ case WebhookNotification::CONNECTED_MERCHANT_STATUS_TRANSITIONED:
51
+ $subjectXml = self::_connectedMerchantStatusTransitionedSampleXml($id);
52
+ break;
53
+ case WebhookNotification::CONNECTED_MERCHANT_PAYPAL_STATUS_CHANGED:
54
+ $subjectXml = self::_connectedMerchantPayPalStatusChangedSampleXml($id);
55
+ break;
56
+ case WebhookNotification::DISPUTE_OPENED:
57
+ $subjectXml = self::_disputeOpenedSampleXml($id);
58
+ break;
59
+ case WebhookNotification::DISPUTE_LOST:
60
+ $subjectXml = self::_disputeLostSampleXml($id);
61
+ break;
62
+ case WebhookNotification::DISPUTE_WON:
63
+ $subjectXml = self::_disputeWonSampleXml($id);
64
+ break;
65
+ case WebhookNotification::SUBSCRIPTION_CHARGED_SUCCESSFULLY:
66
+ $subjectXml = self::_subscriptionChargedSuccessfullySampleXml($id);
67
+ break;
68
+ case WebhookNotification::CHECK:
69
+ $subjectXml = self::_checkSampleXml();
70
+ break;
71
+ case WebhookNotification::ACCOUNT_UPDATER_DAILY_REPORT:
72
+ $subjectXml = self::_accountUpdaterDailyReportSampleXml($id);
73
+ break;
74
+ default:
75
+ $subjectXml = self::_subscriptionSampleXml($id);
76
+ break;
77
+ }
78
+ $timestamp = self::_timestamp();
79
+ return "
80
+ <notification>
81
+ <timestamp type=\"datetime\">{$timestamp}</timestamp>
82
+ <kind>{$kind}</kind>
83
+ <subject>{$subjectXml}</subject>
84
+ </notification>
85
+ ";
86
+ }
87
+
88
+ private static function _merchantAccountApprovedSampleXml($id)
89
+ {
90
+ return "
91
+ <merchant_account>
92
+ <id>{$id}</id>
93
+ <master_merchant_account>
94
+ <id>master_ma_for_{$id}</id>
95
+ <status>active</status>
96
+ </master_merchant_account>
97
+ <status>active</status>
98
+ </merchant_account>
99
+ ";
100
+ }
101
+
102
+ private static function _merchantAccountDeclinedSampleXml($id)
103
+ {
104
+ return "
105
+ <api-error-response>
106
+ <message>Credit score is too low</message>
107
+ <errors>
108
+ <errors type=\"array\"/>
109
+ <merchant-account>
110
+ <errors type=\"array\">
111
+ <error>
112
+ <code>82621</code>
113
+ <message>Credit score is too low</message>
114
+ <attribute type=\"symbol\">base</attribute>
115
+ </error>
116
+ </errors>
117
+ </merchant-account>
118
+ </errors>
119
+ <merchant-account>
120
+ <id>{$id}</id>
121
+ <status>suspended</status>
122
+ <master-merchant-account>
123
+ <id>master_ma_for_{$id}</id>
124
+ <status>suspended</status>
125
+ </master-merchant-account>
126
+ </merchant-account>
127
+ </api-error-response>
128
+ ";
129
+ }
130
+
131
+ private static function _transactionDisbursedSampleXml($id)
132
+ {
133
+ return "
134
+ <transaction>
135
+ <id>${id}</id>
136
+ <amount>100</amount>
137
+ <disbursement-details>
138
+ <disbursement-date type=\"date\">2013-07-09</disbursement-date>
139
+ </disbursement-details>
140
+ </transaction>
141
+ ";
142
+ }
143
+
144
+ private static function _transactionSettledSampleXml($id)
145
+ {
146
+ return "
147
+ <transaction>
148
+ <id>${id}</id>
149
+ <status>settled</status>
150
+ <type>sale</type>
151
+ <currency-iso-code>USD</currency-iso-code>
152
+ <amount>100.00</amount>
153
+ <merchant-account-id>ogaotkivejpfayqfeaimuktty</merchant-account-id>
154
+ <payment-instrument-type>us_bank_account</payment-instrument-type>
155
+ <us-bank-account>
156
+ <routing-number>123456789</routing-number>
157
+ <last-4>1234</last-4>
158
+ <account-type>checking</account-type>
159
+ <account-holder-name>Dan Schulman</account-holder-name>
160
+ </us-bank-account>
161
+ </transaction>
162
+ ";
163
+ }
164
+
165
+ private static function _transactionSettlementDeclinedSampleXml($id)
166
+ {
167
+ return "
168
+ <transaction>
169
+ <id>${id}</id>
170
+ <status>settlement_declined</status>
171
+ <type>sale</type>
172
+ <currency-iso-code>USD</currency-iso-code>
173
+ <amount>100.00</amount>
174
+ <merchant-account-id>ogaotkivejpfayqfeaimuktty</merchant-account-id>
175
+ <payment-instrument-type>us_bank_account</payment-instrument-type>
176
+ <us-bank-account>
177
+ <routing-number>123456789</routing-number>
178
+ <last-4>1234</last-4>
179
+ <account-type>checking</account-type>
180
+ <account-holder-name>Dan Schulman</account-holder-name>
181
+ </us-bank-account>
182
+ </transaction>
183
+ ";
184
+ }
185
+
186
+ private static function _disbursementExceptionSampleXml($id)
187
+ {
188
+ return "
189
+ <disbursement>
190
+ <id>${id}</id>
191
+ <transaction-ids type=\"array\">
192
+ <item>asdfg</item>
193
+ <item>qwert</item>
194
+ </transaction-ids>
195
+ <success type=\"boolean\">false</success>
196
+ <retry type=\"boolean\">false</retry>
197
+ <merchant-account>
198
+ <id>merchant_account_token</id>
199
+ <currency-iso-code>USD</currency-iso-code>
200
+ <sub-merchant-account type=\"boolean\">false</sub-merchant-account>
201
+ <status>active</status>
202
+ </merchant-account>
203
+ <amount>100.00</amount>
204
+ <disbursement-date type=\"date\">2014-02-10</disbursement-date>
205
+ <exception-message>bank_rejected</exception-message>
206
+ <follow-up-action>update_funding_information</follow-up-action>
207
+ </disbursement>
208
+ ";
209
+ }
210
+
211
+ private static function _disbursementSampleXml($id)
212
+ {
213
+ return "
214
+ <disbursement>
215
+ <id>${id}</id>
216
+ <transaction-ids type=\"array\">
217
+ <item>asdfg</item>
218
+ <item>qwert</item>
219
+ </transaction-ids>
220
+ <success type=\"boolean\">true</success>
221
+ <retry type=\"boolean\">false</retry>
222
+ <merchant-account>
223
+ <id>merchant_account_token</id>
224
+ <currency-iso-code>USD</currency-iso-code>
225
+ <sub-merchant-account type=\"boolean\">false</sub-merchant-account>
226
+ <status>active</status>
227
+ </merchant-account>
228
+ <amount>100.00</amount>
229
+ <disbursement-date type=\"date\">2014-02-10</disbursement-date>
230
+ <exception-message nil=\"true\"/>
231
+ <follow-up-action nil=\"true\"/>
232
+ </disbursement>
233
+ ";
234
+ }
235
+
236
+ private static function _disputeOpenedSampleXml($id)
237
+ {
238
+ return "
239
+ <dispute>
240
+ <amount>250.00</amount>
241
+ <currency-iso-code>USD</currency-iso-code>
242
+ <received-date type=\"date\">2014-03-01</received-date>
243
+ <reply-by-date type=\"date\">2014-03-21</reply-by-date>
244
+ <kind>chargeback</kind>
245
+ <status>open</status>
246
+ <reason>fraud</reason>
247
+ <id>${id}</id>
248
+ <transaction>
249
+ <id>${id}</id>
250
+ <amount>250.00</amount>
251
+ </transaction>
252
+ <date-opened type=\"date\">2014-03-21</date-opened>
253
+ </dispute>
254
+ ";
255
+ }
256
+
257
+ private static function _disputeLostSampleXml($id)
258
+ {
259
+ return "
260
+ <dispute>
261
+ <amount>250.00</amount>
262
+ <currency-iso-code>USD</currency-iso-code>
263
+ <received-date type=\"date\">2014-03-01</received-date>
264
+ <reply-by-date type=\"date\">2014-03-21</reply-by-date>
265
+ <kind>chargeback</kind>
266
+ <status>lost</status>
267
+ <reason>fraud</reason>
268
+ <id>${id}</id>
269
+ <transaction>
270
+ <id>${id}</id>
271
+ <amount>250.00</amount>
272
+ <next_billing-date type=\"date\">2020-02-10</next_billing-date>
273
+ </transaction>
274
+ <date-opened type=\"date\">2014-03-21</date-opened>
275
+ </dispute>
276
+ ";
277
+ }
278
+
279
+ private static function _disputeWonSampleXml($id)
280
+ {
281
+ return "
282
+ <dispute>
283
+ <amount>250.00</amount>
284
+ <currency-iso-code>USD</currency-iso-code>
285
+ <received-date type=\"date\">2014-03-01</received-date>
286
+ <reply-by-date type=\"date\">2014-03-21</reply-by-date>
287
+ <kind>chargeback</kind>
288
+ <status>won</status>
289
+ <reason>fraud</reason>
290
+ <id>${id}</id>
291
+ <transaction>
292
+ <id>${id}</id>
293
+ <amount>250.00</amount>
294
+ </transaction>
295
+ <date-opened type=\"date\">2014-03-21</date-opened>
296
+ <date-won type=\"date\">2014-03-22</date-won>
297
+ </dispute>
298
+ ";
299
+ }
300
+
301
+ private static function _subscriptionSampleXml($id)
302
+ {
303
+ return "
304
+ <subscription>
305
+ <id>{$id}</id>
306
+ <transactions type=\"array\">
307
+ </transactions>
308
+ <add_ons type=\"array\">
309
+ </add_ons>
310
+ <discounts type=\"array\">
311
+ </discounts>
312
+ </subscription>
313
+ ";
314
+ }
315
+
316
+ private static function _subscriptionChargedSuccessfullySampleXml($id)
317
+ {
318
+ return "
319
+ <subscription>
320
+ <id>{$id}</id>
321
+ <billing-period-start-date type=\"date\">2016-03-21</billing-period-start-date>
322
+ <billing-period-end-date type=\"date\">2017-03-31</billing-period-end-date>
323
+ <transactions type=\"array\">
324
+ <transaction>
325
+ <status>submitted_for_settlement</status>
326
+ <amount>49.99</amount>
327
+ </transaction>
328
+ </transactions>
329
+ <add_ons type=\"array\">
330
+ </add_ons>
331
+ <discounts type=\"array\">
332
+ </discounts>
333
+ </subscription>
334
+ ";
335
+ }
336
+
337
+ private static function _checkSampleXml()
338
+ {
339
+ return "
340
+ <check type=\"boolean\">true</check>
341
+ ";
342
+ }
343
+
344
+ private static function _partnerMerchantConnectedSampleXml($id)
345
+ {
346
+ return "
347
+ <partner-merchant>
348
+ <merchant-public-id>public_id</merchant-public-id>
349
+ <public-key>public_key</public-key>
350
+ <private-key>private_key</private-key>
351
+ <partner-merchant-id>abc123</partner-merchant-id>
352
+ <client-side-encryption-key>cse_key</client-side-encryption-key>
353
+ </partner-merchant>
354
+ ";
355
+ }
356
+
357
+ private static function _partnerMerchantDisconnectedSampleXml($id)
358
+ {
359
+ return "
360
+ <partner-merchant>
361
+ <partner-merchant-id>abc123</partner-merchant-id>
362
+ </partner-merchant>
363
+ ";
364
+ }
365
+
366
+ private static function _partnerMerchantDeclinedSampleXml($id)
367
+ {
368
+ return "
369
+ <partner-merchant>
370
+ <partner-merchant-id>abc123</partner-merchant-id>
371
+ </partner-merchant>
372
+ ";
373
+ }
374
+
375
+ private static function _accountUpdaterDailyReportSampleXml($id)
376
+ {
377
+ return "
378
+ <account-updater-daily-report>
379
+ <report-date type=\"date\">2016-01-14</report-date>
380
+ <report-url>link-to-csv-report</report-url>
381
+ </account-updater-daily-report>
382
+ ";
383
+ }
384
+
385
+ private static function _connectedMerchantStatusTransitionedSampleXml($id)
386
+ {
387
+ return "
388
+ <connected-merchant-status-transitioned>
389
+ <merchant-public-id>{$id}</merchant-public-id>
390
+ <status>new_status</status>
391
+ <oauth-application-client-id>oauth_application_client_id</oauth-application-client-id>
392
+ </connected-merchant-status-transitioned>
393
+ ";
394
+ }
395
+
396
+ private static function _connectedMerchantPayPalStatusChangedSampleXml($id)
397
+ {
398
+ return "
399
+ <connected-merchant-paypal-status-changed>
400
+ <merchant-public-id>{$id}</merchant-public-id>
401
+ <action>link</action>
402
+ <oauth-application-client-id>oauth_application_client_id</oauth-application-client-id>
403
+ </connected-merchant-paypal-status-changed>
404
+ ";
405
+ }
406
+
407
+ private static function _timestamp()
408
+ {
409
+ $originalZone = date_default_timezone_get();
410
+ date_default_timezone_set('UTC');
411
+ $timestamp = strftime('%Y-%m-%dT%TZ');
412
+ date_default_timezone_set($originalZone);
413
+
414
+ return $timestamp;
415
+ }
416
+ }
417
+ class_alias('Braintree\WebhookTesting', 'Braintree_WebhookTesting');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Xml.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree;
3
+
4
+ /**
5
+ * Braintree Xml parser and generator
6
+ * PHP version 5
7
+ * superclass for Braintree XML parsing and generation
8
+ */
9
+ class Xml
10
+ {
11
+ /**
12
+ * @ignore
13
+ */
14
+ protected function __construct()
15
+ {
16
+
17
+ }
18
+
19
+ /**
20
+ *
21
+ * @param string $xml
22
+ * @return array
23
+ */
24
+ public static function buildArrayFromXml($xml)
25
+ {
26
+ return Xml\Parser::arrayFromXml($xml);
27
+ }
28
+
29
+ /**
30
+ *
31
+ * @param array $array
32
+ * @return string
33
+ */
34
+ public static function buildXmlFromArray($array)
35
+ {
36
+ return Xml\Generator::arrayToXml($array);
37
+ }
38
+ }
39
+ class_alias('Braintree\Xml', 'Braintree_Xml');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Xml/Generator.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Xml;
3
+
4
+ use DateTime;
5
+ use DateTimeZone;
6
+ use XMLWriter;
7
+ use Braintree\Util;
8
+
9
+ /**
10
+ * PHP version 5
11
+ */
12
+
13
+ /**
14
+ * Generates XML output from arrays using PHP's
15
+ * built-in XMLWriter
16
+ */
17
+ class Generator
18
+ {
19
+ /**
20
+ * arrays passed to this method should have a single root element
21
+ * with an array as its value
22
+ * @param array $aData the array of data
23
+ * @return string XML string
24
+ */
25
+ public static function arrayToXml($aData)
26
+ {
27
+ $aData = Util::camelCaseToDelimiterArray($aData, '-');
28
+ // set up the XMLWriter
29
+ $writer = new XMLWriter();
30
+ $writer->openMemory();
31
+
32
+ $writer->setIndent(true);
33
+ $writer->setIndentString(' ');
34
+ $writer->startDocument('1.0', 'UTF-8');
35
+
36
+ // get the root element name
37
+ $aKeys = array_keys($aData);
38
+ $rootElementName = $aKeys[0];
39
+ // open the root element
40
+ $writer->startElement($rootElementName);
41
+ // create the body
42
+ self::_createElementsFromArray($writer, $aData[$rootElementName], $rootElementName);
43
+
44
+ // close the root element and document
45
+ $writer->endElement();
46
+ $writer->endDocument();
47
+
48
+ // send the output as string
49
+ return $writer->outputMemory();
50
+ }
51
+
52
+ /**
53
+ * Construct XML elements with attributes from an associative array.
54
+ *
55
+ * @access protected
56
+ * @static
57
+ * @param object $writer XMLWriter object
58
+ * @param array $aData contains attributes and values
59
+ * @return void
60
+ */
61
+ private static function _createElementsFromArray(&$writer, $aData)
62
+ {
63
+ if (!is_array($aData)) {
64
+ if (is_bool($aData)) {
65
+ $writer->text($aData ? 'true' : 'false');
66
+ } else {
67
+ $writer->text($aData);
68
+ }
69
+ return;
70
+ }
71
+ foreach ($aData AS $elementName => $element) {
72
+ // handle child elements
73
+ $writer->startElement($elementName);
74
+ if (is_array($element)) {
75
+ if (array_key_exists(0, $element) || empty($element)) {
76
+ $writer->writeAttribute('type', 'array');
77
+ foreach ($element AS $ignored => $itemInArray) {
78
+ $writer->startElement('item');
79
+ self::_createElementsFromArray($writer, $itemInArray);
80
+ $writer->endElement();
81
+ }
82
+ }
83
+ else {
84
+ self::_createElementsFromArray($writer, $element);
85
+ }
86
+ } else {
87
+ // generate attributes as needed
88
+ $attribute = self::_generateXmlAttribute($element);
89
+ if (is_array($attribute)) {
90
+ $writer->writeAttribute($attribute[0], $attribute[1]);
91
+ $element = $attribute[2];
92
+ }
93
+ $writer->text($element);
94
+ }
95
+ $writer->endElement();
96
+ }
97
+ }
98
+
99
+ /**
100
+ * convert passed data into an array of attributeType, attributeName, and value
101
+ * dates sent as DateTime objects will be converted to strings
102
+ * @access protected
103
+ * @param mixed $value
104
+ * @return array attributes and element value
105
+ */
106
+ private static function _generateXmlAttribute($value)
107
+ {
108
+ if ($value instanceof DateTime) {
109
+ return ['type', 'datetime', self::_dateTimeToXmlTimestamp($value)];
110
+ }
111
+ if (is_int($value)) {
112
+ return ['type', 'integer', $value];
113
+ }
114
+ if (is_bool($value)) {
115
+ return ['type', 'boolean', ($value ? 'true' : 'false')];
116
+ }
117
+ if ($value === NULL) {
118
+ return ['nil', 'true', $value];
119
+ }
120
+ }
121
+ /**
122
+ * converts datetime back to xml schema format
123
+ * @access protected
124
+ * @param object $dateTime
125
+ * @return string XML schema formatted timestamp
126
+ */
127
+ private static function _dateTimeToXmlTimestamp($dateTime)
128
+ {
129
+ $dateTimeForUTC = clone $dateTime;
130
+
131
+ $dateTimeForUTC->setTimeZone(new DateTimeZone('UTC'));
132
+ return ($dateTimeForUTC->format('Y-m-d\TH:i:s') . 'Z');
133
+ }
134
+
135
+ private static function _castDateTime($string)
136
+ {
137
+ try {
138
+ if (empty($string)) {
139
+ return false;
140
+ }
141
+ $dateTime = new DateTime($string);
142
+ return self::_dateTimeToXmlTimestamp($dateTime);
143
+ } catch (Exception $e) {
144
+ // not a datetime
145
+ return false;
146
+ }
147
+ }
148
+ }
149
+ class_alias('Braintree\Xml\Generator', 'Braintree_Xml_Generator');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/Braintree/Xml/Parser.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Braintree\Xml;
3
+
4
+ use DateTime;
5
+ use DateTimeZone;
6
+ use DOMDocument;
7
+ use DOMElement;
8
+ use DOMText;
9
+ use Braintree\Util;
10
+
11
+ /**
12
+ * Braintree XML Parser
13
+ */
14
+ class Parser
15
+ {
16
+ /**
17
+ * Converts an XML string into a multidimensional array
18
+ *
19
+ * @param string $xml
20
+ * @return array
21
+ */
22
+ public static function arrayFromXml($xml)
23
+ {
24
+ $document = new DOMDocument('1.0', 'UTF-8');
25
+ $document->loadXML($xml);
26
+
27
+ $root = $document->documentElement->nodeName;
28
+
29
+ return Util::delimiterToCamelCaseArray([
30
+ $root => self::_nodeToValue($document->childNodes->item(0)),
31
+ ]);
32
+ }
33
+
34
+ /**
35
+ * Converts a node to an array of values or nodes
36
+ *
37
+ * @param DOMNode @node
38
+ * @return mixed
39
+ */
40
+ private static function _nodeToArray($node)
41
+ {
42
+ $type = null;
43
+ if ($node instanceof DOMElement) {
44
+ $type = $node->getAttribute('type');
45
+ }
46
+
47
+ switch($type) {
48
+ case 'array':
49
+ $array = [];
50
+ foreach ($node->childNodes as $child) {
51
+ $value = self::_nodeToValue($child);
52
+ if ($value !== null) {
53
+ $array[] = $value;
54
+ }
55
+ }
56
+ return $array;
57
+ case 'collection':
58
+ $collection = [];
59
+ foreach ($node->childNodes as $child) {
60
+ $value = self::_nodetoValue($child);
61
+ if ($value !== null) {
62
+ if (!isset($collection[$child->nodeName])) {
63
+ $collection[$child->nodeName] = [];
64
+ }
65
+ $collection[$child->nodeName][] = self::_nodeToValue($child);
66
+ }
67
+ }
68
+ return $collection;
69
+ default:
70
+ $values = [];
71
+ if ($node->childNodes->length === 1 && $node->childNodes->item(0) instanceof DOMText) {
72
+ return $node->childNodes->item(0)->nodeValue;
73
+ } else {
74
+ foreach ($node->childNodes as $child) {
75
+ if (!$child instanceof DOMText) {
76
+ $values[$child->nodeName] = self::_nodeToValue($child);
77
+ }
78
+ }
79
+ return $values;
80
+ }
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Converts a node to a PHP value
86
+ *
87
+ * @param DOMNode $node
88
+ * @return mixed
89
+ */
90
+ private static function _nodeToValue($node)
91
+ {
92
+ $type = null;
93
+ if ($node instanceof DOMElement) {
94
+ $type = $node->getAttribute('type');
95
+ }
96
+
97
+ switch($type) {
98
+ case 'datetime':
99
+ return self::_timestampToUTC((string) $node->nodeValue);
100
+ case 'date':
101
+ return new DateTime((string) $node->nodeValue);
102
+ case 'integer':
103
+ return (int) $node->nodeValue;
104
+ case 'boolean':
105
+ $value = (string) $node->nodeValue;
106
+ if(is_numeric($value)) {
107
+ return (bool) $value;
108
+ } else {
109
+ return ($value !== "true") ? false : true;
110
+ }
111
+ case 'array':
112
+ case 'collection':
113
+ return self::_nodeToArray($node);
114
+ default:
115
+ if ($node->hasChildNodes()) {
116
+ return self::_nodeToArray($node);
117
+ } elseif (trim($node->nodeValue) === '') {
118
+ return null;
119
+ } else {
120
+ return $node->nodeValue;
121
+ }
122
+ }
123
+ }
124
+
125
+
126
+ /**
127
+ * Converts XML timestamps into DateTime instances
128
+ *
129
+ * @param string $timestamp
130
+ * @return DateTime
131
+ */
132
+ private static function _timestampToUTC($timestamp)
133
+ {
134
+ $tz = new DateTimeZone('UTC');
135
+ $dateTime = new DateTime($timestamp, $tz);
136
+ $dateTime->setTimezone($tz);
137
+ return $dateTime;
138
+ }
139
+ }
140
+ class_alias('Braintree\Xml\Parser', 'Braintree_Xml_Parser');
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/autoload.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ spl_autoload_register(function ($className) {
4
+ if (strpos($className, 'Braintree') !== 0) {
5
+ return;
6
+ }
7
+
8
+ $fileName = dirname(__DIR__) . '/lib/';
9
+
10
+ if ($lastNsPos = strripos($className, '\\')) {
11
+ $namespace = substr($className, 0, $lastNsPos);
12
+ $className = substr($className, $lastNsPos + 1);
13
+ $fileName .= str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
14
+ }
15
+
16
+ $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
17
+
18
+ if (is_file($fileName)) {
19
+ require_once $fileName;
20
+ }
21
+ });
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/lib/ssl/api_braintreegateway_com.ca.crt ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB
3
+ yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
4
+ ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp
5
+ U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW
6
+ ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0
7
+ aG9yaXR5IC0gRzUwHhcNMDYxMTA4MDAwMDAwWhcNMzYwNzE2MjM1OTU5WjCByjEL
8
+ MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZW
9
+ ZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2ln
10
+ biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJp
11
+ U2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9y
12
+ aXR5IC0gRzUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvJAgIKXo1
13
+ nmAMqudLO07cfLw8RRy7K+D+KQL5VwijZIUVJ/XxrcgxiV0i6CqqpkKzj/i5Vbex
14
+ t0uz/o9+B1fs70PbZmIVYc9gDaTY3vjgw2IIPVQT60nKWVSFJuUrjxuf6/WhkcIz
15
+ SdhDY2pSS9KP6HBRTdGJaXvHcPaz3BJ023tdS1bTlr8Vd6Gw9KIl8q8ckmcY5fQG
16
+ BO+QueQA5N06tRn/Arr0PO7gi+s3i+z016zy9vA9r911kTMZHRxAy3QkGSGT2RT+
17
+ rCpSx4/VBEnkjWNHiDxpg8v+R70rfk/Fla4OndTRQ8Bnc+MUCH7lP59zuDMKz10/
18
+ NIeWiu5T6CUVAgMBAAGjgbIwga8wDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8E
19
+ BAMCAQYwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJaW1hZ2UvZ2lmMCEwHzAH
20
+ BgUrDgMCGgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYjaHR0cDovL2xvZ28udmVy
21
+ aXNpZ24uY29tL3ZzbG9nby5naWYwHQYDVR0OBBYEFH/TZafC3ey78DAJ80M5+gKv
22
+ MzEzMA0GCSqGSIb3DQEBBQUAA4IBAQCTJEowX2LP2BqYLz3q3JktvXf2pXkiOOzE
23
+ p6B4Eq1iDkVwZMXnl2YtmAl+X6/WzChl8gGqCBpH3vn5fJJaCGkgDdk+bW48DW7Y
24
+ 5gaRQBi5+MHt39tBquCWIMnNZBU4gcmU7qKEKQsTb47bDN0lAtukixlE0kF6BWlK
25
+ WE9gyn6CagsCqiUXObXbf+eEZSqVir2G3l6BFoMtEMze/aiCKm0oHw0LxOXnGiYZ
26
+ 4fQRbxC1lfznQgUy286dUV4otp6F01vvpX1FQHKOtw5rDgb7MzVIcbidJ4vEZV8N
27
+ hnacRHr2lVz2XTIIM6RUthg/aFzyQkqFOFSDX9HoLPKsEdao7WNq
28
+ -----END CERTIFICATE-----
29
+ -----BEGIN CERTIFICATE-----
30
+ MIIDuDCCAqCgAwIBAgIQDPCOXAgWpa1Cf/DrJxhZ0DANBgkqhkiG9w0BAQUFADBI
31
+ MQswCQYDVQQGEwJVUzEgMB4GA1UEChMXU2VjdXJlVHJ1c3QgQ29ycG9yYXRpb24x
32
+ FzAVBgNVBAMTDlNlY3VyZVRydXN0IENBMB4XDTA2MTEwNzE5MzExOFoXDTI5MTIz
33
+ MTE5NDA1NVowSDELMAkGA1UEBhMCVVMxIDAeBgNVBAoTF1NlY3VyZVRydXN0IENv
34
+ cnBvcmF0aW9uMRcwFQYDVQQDEw5TZWN1cmVUcnVzdCBDQTCCASIwDQYJKoZIhvcN
35
+ AQEBBQADggEPADCCAQoCggEBAKukgeWVzfX2FI7CT8rU4niVWJxB4Q2ZQCQXOZEz
36
+ Zum+4YOvYlyJ0fwkW2Gz4BERQRwdbvC4u/jep4G6pkjGnx29vo6pQT64lO0pGtSO
37
+ 0gMdA+9tDWccV9cGrcrI9f4Or2YlSASWC12juhbDCE/RRvgUXPLIXgGZbf2IzIao
38
+ wW8xQmxSPmjL8xk037uHGFaAJsTQ3MBv396gwpEWoGQRS0S8Hvbn+mPeZqx2pHGj
39
+ 7DaUaHp3pLHnDi+BeuK1cobvomuL8A/b01k/unK8RCSc43Oz969XL0Imnal0ugBS
40
+ 8kvNU3xHCzaFDmapCJcWNFfBZveA4+1wVMeT4C4oFVmHursCAwEAAaOBnTCBmjAT
41
+ BgkrBgEEAYI3FAIEBh4EAEMAQTALBgNVHQ8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB
42
+ /zAdBgNVHQ4EFgQUQjK2FvoE/f5dS3rD/fdMQB1aQ68wNAYDVR0fBC0wKzApoCeg
43
+ JYYjaHR0cDovL2NybC5zZWN1cmV0cnVzdC5jb20vU1RDQS5jcmwwEAYJKwYBBAGC
44
+ NxUBBAMCAQAwDQYJKoZIhvcNAQEFBQADggEBADDtT0rhWDpSclu1pqNlGKa7UTt3
45
+ 6Z3q059c4EVlew3KW+JwULKUBRSuSceNQQcSc5R+DCMh/bwQf2AQWnL1mA6s7Ll/
46
+ 3XpvXdMc9P+IBWlCqQVxyLesJugutIxq/3HcuLHfmbx8IVQr5Fiiu1cprp6poxkm
47
+ D5kuCLDv/WnPmRoJjeOnnyvJNjR7JLN4TJUXpAYmHrZkUjZfYGfZnMUFdAvnZyPS
48
+ CPyI6a6Lf+Ew9Dd+/cYy2i2eRDAwbO4H3tI0/NL/QPZL9GZGBlSm8jIKYyYwa5vR
49
+ 3ItHuuG51WLQoqD0ZwV4KWMabwTW+MZMo5qxN7SN5ShLHZ4swrhovO0C7jE=
50
+ -----END CERTIFICATE-----
51
+ -----BEGIN CERTIFICATE-----
52
+ MIIDxTCCAq2gAwIBAgIBADANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMCVVMx
53
+ EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNVBAoT
54
+ EUdvRGFkZHkuY29tLCBJbmMuMTEwLwYDVQQDEyhHbyBEYWRkeSBSb290IENlcnRp
55
+ ZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5MDkwMTAwMDAwMFoXDTM3MTIzMTIz
56
+ NTk1OVowgYMxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6b25hMRMwEQYDVQQH
57
+ EwpTY290dHNkYWxlMRowGAYDVQQKExFHb0RhZGR5LmNvbSwgSW5jLjExMC8GA1UE
58
+ AxMoR28gRGFkZHkgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIw
59
+ DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL9xYgjx+lk09xvJGKP3gElY6SKD
60
+ E6bFIEMBO4Tx5oVJnyfq9oQbTqC023CYxzIBsQU+B07u9PpPL1kwIuerGVZr4oAH
61
+ /PMWdYA5UXvl+TW2dE6pjYIT5LY/qQOD+qK+ihVqf94Lw7YZFAXK6sOoBJQ7Rnwy
62
+ DfMAZiLIjWltNowRGLfTshxgtDj6AozO091GB94KPutdfMh8+7ArU6SSYmlRJQVh
63
+ GkSBjCypQ5Yj36w6gZoOKcUcqeldHraenjAKOc7xiID7S13MMuyFYkMlNAJWJwGR
64
+ tDtwKj9useiciAF9n9T521NtYJ2/LOdYq7hfRvzOxBsDPAnrSTFcaUaz4EcCAwEA
65
+ AaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYE
66
+ FDqahQcQZyi27/a9BUFuIMGU2g/eMA0GCSqGSIb3DQEBCwUAA4IBAQCZ21151fmX
67
+ WWcDYfF+OwYxdS2hII5PZYe096acvNjpL9DbWu7PdIxztDhC2gV7+AJ1uP2lsdeu
68
+ 9tfeE8tTEH6KRtGX+rcuKxGrkLAngPnon1rpN5+r5N9ss4UXnT3ZJE95kTXWXwTr
69
+ gIOrmgIttRD02JDHBHNA7XIloKmf7J6raBKZV8aPEjoJpL1E/QYVN8Gb5DKj7Tjo
70
+ 2GTzLH4U/ALqn83/B2gX2yKQOC16jdFU8WnjXzPKej17CuPKf1855eJ1usV2GDPO
71
+ LPAvTK33sefOT6jEm0pUBsV/fdUID+Ic/n4XuKxe9tQWskMJDE32p2u0mYRlynqI
72
+ 4uJEvlz36hz1
73
+ -----END CERTIFICATE-----
74
+ -----BEGIN CERTIFICATE-----
75
+ MIIDtzCCAp+gAwIBAgIQDOfg5RfYRv6P5WD8G/AwOTANBgkqhkiG9w0BAQUFADBl
76
+ MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
77
+ d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJv
78
+ b3QgQ0EwHhcNMDYxMTEwMDAwMDAwWhcNMzExMTEwMDAwMDAwWjBlMQswCQYDVQQG
79
+ EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNl
80
+ cnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgQ0EwggEi
81
+ MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtDhXO5EOAXLGH87dg+XESpa7c
82
+ JpSIqvTO9SA5KFhgDPiA2qkVlTJhPLWxKISKityfCgyDF3qPkKyK53lTXDGEKvYP
83
+ mDI2dsze3Tyoou9q+yHyUmHfnyDXH+Kx2f4YZNISW1/5WBg1vEfNoTb5a3/UsDg+
84
+ wRvDjDPZ2C8Y/igPs6eD1sNuRMBhNZYW/lmci3Zt1/GiSw0r/wty2p5g0I6QNcZ4
85
+ VYcgoc/lbQrISXwxmDNsIumH0DJaoroTghHtORedmTpyoeb6pNnVFzF1roV9Iq4/
86
+ AUaG9ih5yLHa5FcXxH4cDrC0kqZWs72yl+2qp/C3xag/lRbQ/6GW6whfGHdPAgMB
87
+ AAGjYzBhMA4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQW
88
+ BBRF66Kv9JLLgjEtUYunpyGd823IDzAfBgNVHSMEGDAWgBRF66Kv9JLLgjEtUYun
89
+ pyGd823IDzANBgkqhkiG9w0BAQUFAAOCAQEAog683+Lt8ONyc3pklL/3cmbYMuRC
90
+ dWKuh+vy1dneVrOfzM4UKLkNl2BcEkxY5NM9g0lFWJc1aRqoR+pWxnmrEthngYTf
91
+ fwk8lOa4JiwgvT2zKIn3X/8i4peEH+ll74fg38FnSbNd67IJKusm7Xi+fT8r87cm
92
+ NW1fiQG2SVufAQWbqz0lwcy2f8Lxb4bG+mRo64EtlOtCt/qMHt1i8b5QZ7dsvfPx
93
+ H2sMNgcWfzd8qVttevESRmCD1ycEvkvOl77DZypoEd+A5wwzZr8TDRRu838fYxAe
94
+ +o0bJW1sj6W3YQGx0qMmoRBxna3iw/nDmVG3KwcIzi7mULKn+gpFL6Lw8g==
95
+ -----END CERTIFICATE-----
96
+ -----BEGIN CERTIFICATE-----
97
+ MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
98
+ MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
99
+ d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
100
+ QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
101
+ MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
102
+ b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
103
+ 9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
104
+ CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
105
+ nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
106
+ 43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
107
+ T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
108
+ gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
109
+ BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
110
+ TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
111
+ DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
112
+ hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
113
+ 06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
114
+ PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
115
+ YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
116
+ CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
117
+ -----END CERTIFICATE-----
118
+ -----BEGIN CERTIFICATE-----
119
+ MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs
120
+ MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
121
+ d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j
122
+ ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL
123
+ MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3
124
+ LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug
125
+ RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm
126
+ +9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW
127
+ PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM
128
+ xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB
129
+ Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3
130
+ hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg
131
+ EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF
132
+ MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA
133
+ FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec
134
+ nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z
135
+ eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF
136
+ hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2
137
+ Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
138
+ vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep
139
+ +OkuE6N36B9K
140
+ -----END CERTIFICATE-----
141
+ -----BEGIN CERTIFICATE-----
142
+ MIIFaDCCA1CgAwIBAgIBATANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJVUzEW
143
+ MBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEeMBwGA1UEAxMVR2VvVHJ1c3QgVW5pdmVy
144
+ c2FsIENBMB4XDTA0MDMwNDA1MDAwMFoXDTI5MDMwNDA1MDAwMFowRTELMAkGA1UE
145
+ BhMCVVMxFjAUBgNVBAoTDUdlb1RydXN0IEluYy4xHjAcBgNVBAMTFUdlb1RydXN0
146
+ IFVuaXZlcnNhbCBDQTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAKYV
147
+ VaCjxuAfjJ0hUNfBvitbtaSeodlyWL0AG0y/YckUHUWCq8YdgNY96xCcOq9tJPi8
148
+ cQGeBvV8Xx7BDlXKg5pZMK4ZyzBIle0iN430SppyZj6tlcDgFgDgEB8rMQ7XlFTT
149
+ QjOgNB0eRXbdT8oYN+yFFXoZCPzVx5zw8qkuEKmS5j1YPakWaDwvdSEYfyh3peFh
150
+ F7em6fgemdtzbvQKoiFs7tqqhZJmr/Z6a4LauiIINQ/PQvE1+mrufislzDoR5G2v
151
+ c7J2Ha3QsnhnGqQ5HFELZ1aD/ThdDc7d8Lsrlh/eezJS/R27tQahsiFepdaVaH/w
152
+ mZ7cRQg+59IJDTWU3YBOU5fXtQlEIGQWFwMCTFMNaN7VqnJNk22CDtucvc+081xd
153
+ VHppCZbW2xHBjXWotM85yM48vCR85mLK4b19p71XZQvk/iXttmkQ3CgaRr0BHdCX
154
+ teGYO8A3ZNY9lO4L4fUorgtWv3GLIylBjobFS1J72HGrH4oVpjuDWtdYAVHGTEHZ
155
+ f9hBZ3KiKN9gg6meyHv8U3NyWfWTehd2Ds735VzZC1U0oqpbtWpU5xPKV+yXbfRe
156
+ Bi9Fi1jUIxaS5BZuKGNZMN9QAZxjiRqf2xeUgnA3wySemkfWWspOqGmJch+RbNt+
157
+ nhutxx9z3SxPGWX9f5NAEC7S8O08ni4oPmkmM8V7AgMBAAGjYzBhMA8GA1UdEwEB
158
+ /wQFMAMBAf8wHQYDVR0OBBYEFNq7LqqwDLiIJlF0XG0D08DYj3rWMB8GA1UdIwQY
159
+ MBaAFNq7LqqwDLiIJlF0XG0D08DYj3rWMA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG
160
+ 9w0BAQUFAAOCAgEAMXjmx7XfuJRAyXHEqDXsRh3ChfMoWIawC/yOsjmPRFWrZIRc
161
+ aanQmjg8+uUfNeVE44B5lGiku8SfPeE0zTBGi1QrlaXv9z+ZhP015s8xxtxqv6fX
162
+ IwjhmF7DWgh2qaavdy+3YL1ERmrvl/9zlcGO6JP7/TG37FcREUWbMPEaiDnBTzyn
163
+ ANXH/KttgCJwpQzgXQQpAvvLoJHRfNbDflDVnVi+QTjruXU8FdmbyUqDWcDaU/0z
164
+ uzYYm4UPFd3uLax2k7nZAY1IEKj79TiG8dsKxr2EoyNB3tZ3b4XUhRxQ4K5RirqN
165
+ Pnbiucon8l+f725ZDQbYKxek0nxru18UGkiPGkzns0ccjkxFKyDuSN/n3QmOGKja
166
+ QI2SJhFTYXNd673nxE0pN2HrrDktZy4W1vUAg4WhzH92xH3kt0tm7wNFYGm2DFKW
167
+ koRepqO1pD4r2czYG0eq8kTaT/kD6PAUyz/zg97QwVTjt+gKN02LIFkDMBmhLMi9
168
+ ER/frslKxfMnZmaGrGiR/9nmUxwPi1xpZQomyB40w11Re9epnAahNt3ViZS82eQt
169
+ DF4JbAiXfKM9fJP/P6EUp8+1Xevb2xzEdt+Iub1FBZUbrvxGakyvSOPOrg/Sfuvm
170
+ bJxPgWp6ZKy7PtXny3YuxadIwVyQD8vIP/rmMuGNG2+k5o7Y+SlIis5z/iw=
171
+ -----END CERTIFICATE-----
172
+ -----BEGIN CERTIFICATE-----
173
+ MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
174
+ MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i
175
+ YWwgQ0EwHhcNMDIwNTIxMDQwMDAwWhcNMjIwNTIxMDQwMDAwWjBCMQswCQYDVQQG
176
+ EwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEbMBkGA1UEAxMSR2VvVHJ1c3Qg
177
+ R2xvYmFsIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2swYYzD9
178
+ 9BcjGlZ+W988bDjkcbd4kdS8odhM+KhDtgPpTSEHCIjaWC9mOSm9BXiLnTjoBbdq
179
+ fnGk5sRgprDvgOSJKA+eJdbtg/OtppHHmMlCGDUUna2YRpIuT8rxh0PBFpVXLVDv
180
+ iS2Aelet8u5fa9IAjbkU+BQVNdnARqN7csiRv8lVK83Qlz6cJmTM386DGXHKTubU
181
+ 1XupGc1V3sjs0l44U+VcT4wt/lAjNvxm5suOpDkZALeVAjmRCw7+OC7RHQWa9k0+
182
+ bw8HHa8sHo9gOeL6NlMTOdReJivbPagUvTLrGAMoUgRx5aszPeE4uwc2hGKceeoW
183
+ MPRfwCvocWvk+QIDAQABo1MwUTAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTA
184
+ ephojYn7qwVkDBF9qn1luMrMTjAfBgNVHSMEGDAWgBTAephojYn7qwVkDBF9qn1l
185
+ uMrMTjANBgkqhkiG9w0BAQUFAAOCAQEANeMpauUvXVSOKVCUn5kaFOSPeCpilKIn
186
+ Z57QzxpeR+nBsqTP3UEaBU6bS+5Kb1VSsyShNwrrZHYqLizz/Tt1kL/6cdjHPTfS
187
+ tQWVYrmm3ok9Nns4d0iXrKYgjy6myQzCsplFAMfOEVEiIuCl6rYVSAlk6l5PdPcF
188
+ PseKUgzbFbS9bZvlxrFUaKnjaZC2mqUPuLk/IH2uSrW4nOQdtqvmlKXBx4Ot2/Un
189
+ hw4EbNX/3aBd7YdStysVAq45pmp06drE57xNNB6pXE0zX5IJL4hmXXeXxx12E6nV
190
+ 5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3CBWaAocvmMw==
191
+ -----END CERTIFICATE-----
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/phpunit.xml.dist ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <phpunit backupGlobals="false"
3
+ backupStaticAttributes="false"
4
+ bootstrap="./vendor/autoload.php"
5
+ convertErrorsToExceptions="true"
6
+ convertNoticesToExceptions="true"
7
+ convertWarningsToExceptions="true"
8
+ processIsolation="false"
9
+ stopOnFailure="false"
10
+ syntaxCheck="false">
11
+
12
+ <php>
13
+ <ini name="error_reporting" value="32767"/>
14
+ </php>
15
+
16
+ <testsuites>
17
+ <testsuite name="unit">
18
+ <directory>./tests/unit</directory>
19
+ </testsuite>
20
+ <testsuite name="integration">
21
+ <directory>./tests/integration</directory>
22
+ </testsuite>
23
+ </testsuites>
24
+ </phpunit>
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/Braintree/CreditCardDefaults.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Braintree;
3
+
4
+ class CreditCardDefaults
5
+ {
6
+ const ISSUING_BANK = "NETWORK ONLY";
7
+ const COUNTRY_OF_ISSUANCE = "USA";
8
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/Braintree/CreditCardNumbers/CardTypeIndicators.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Braintree\CreditCardNumbers;
3
+
4
+ class CardTypeIndicators {
5
+ const PREPAID = "4111111111111210";
6
+ const COMMERCIAL = "4111111111131010";
7
+ const PAYROLL = "4111111114101010";
8
+ const HEALTHCARE = "4111111510101010";
9
+ const DURBIN_REGULATED = "4111161010101010";
10
+ const DEBIT = "4117101010101010";
11
+ const UNKNOWN = "4111111111112101";
12
+ const NO = "4111111111310101";
13
+ const ISSUING_BANK = "4111111141010101";
14
+ const COUNTRY_OF_ISSUANCE = "4111111111121102";
15
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/Braintree/OAuthTestHelper.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Braintree;
3
+
4
+ use Braintree;
5
+
6
+ class OAuthTestHelper
7
+ {
8
+ public static function createGrant($gateway, $params)
9
+ {
10
+ $http = new Braintree\Http($gateway->config);
11
+ $http->useClientCredentials();
12
+ $response = $http->post('/oauth_testing/grants', ['grant' => $params]);
13
+ return $response['grant']['code'];
14
+ }
15
+
16
+ public static function createCredentials($params)
17
+ {
18
+ $gateway = new Braintree\Gateway([
19
+ 'clientId' => $params['clientId'],
20
+ 'clientSecret' => $params['clientSecret']
21
+ ]);
22
+
23
+ $code = OAuthTestHelper::createGrant($gateway, [
24
+ 'merchant_public_id' => $params['merchantId'],
25
+ 'scope' => 'read_write'
26
+ ]);
27
+
28
+ $credentials = $gateway->oauth()->createTokenFromCode([
29
+ 'code' => $code,
30
+ 'scope' => 'read_write',
31
+ ]);
32
+
33
+ return $credentials;
34
+ }
35
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/Helper.php ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test;
3
+
4
+ require_once __DIR__ . '/Setup.php';
5
+
6
+ use DateTime;
7
+ use DateTimeZone;
8
+ use Braintree;
9
+
10
+ class Helper
11
+ {
12
+ public static $valid_nonce_characters = 'bcdfghjkmnpqrstvwxyz23456789';
13
+
14
+ public static function testMerchantConfig()
15
+ {
16
+ Braintree\Configuration::reset();
17
+
18
+ Braintree\Configuration::environment('development');
19
+ Braintree\Configuration::merchantId('test_merchant_id');
20
+ Braintree\Configuration::publicKey('test_public_key');
21
+ Braintree\Configuration::privateKey('test_private_key');
22
+ }
23
+
24
+ public static function defaultMerchantAccountId()
25
+ {
26
+ return 'sandbox_credit_card';
27
+ }
28
+
29
+ public static function nonDefaultMerchantAccountId()
30
+ {
31
+ return 'sandbox_credit_card_non_default';
32
+ }
33
+
34
+ public static function nonDefaultSubMerchantAccountId()
35
+ {
36
+ return 'sandbox_sub_merchant_account';
37
+ }
38
+
39
+ public static function threeDSecureMerchantAccountId()
40
+ {
41
+ return 'three_d_secure_merchant_account';
42
+ }
43
+
44
+ public static function fakeAmexDirectMerchantAccountId()
45
+ {
46
+ return 'fake_amex_direct_usd';
47
+ }
48
+
49
+ public static function fakeVenmoAccountMerchantAccountId()
50
+ {
51
+ return 'fake_first_data_venmo_account';
52
+ }
53
+
54
+ public static function createViaTr($regularParams, $trParams)
55
+ {
56
+ $trData = Braintree\TransparentRedirect::transactionData(
57
+ array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
58
+ );
59
+ return self::submitTrRequest(
60
+ Braintree\TransparentRedirect::url(),
61
+ $regularParams,
62
+ $trData
63
+ );
64
+ }
65
+
66
+ public static function submitTrRequest($url, $regularParams, $trData)
67
+ {
68
+ $curl = curl_init();
69
+ curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
70
+ curl_setopt($curl, CURLOPT_URL, $url);
71
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
72
+ curl_setopt($curl, CURLOPT_HEADER, true);
73
+ // curl_setopt($curl, CURLOPT_VERBOSE, true);
74
+ curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array_merge($regularParams, ['tr_data' => $trData])));
75
+ curl_setopt($curl, CURLOPT_HTTPHEADER, [
76
+ 'Content-Type: application/x-www-form-urlencoded'
77
+ ]);
78
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
79
+ $response = curl_exec($curl);
80
+ curl_close($curl);
81
+ preg_match('/Location: .*\?(.*)/i', $response, $match);
82
+ return trim($match[1]);
83
+ }
84
+
85
+ public static function suppressDeprecationWarnings()
86
+ {
87
+ set_error_handler("Test\Helper::_errorHandler", E_USER_NOTICE);
88
+ }
89
+
90
+ public static function _errorHandler($errno, $errstr, $errfile, $errline)
91
+ {
92
+ if (preg_match('/^DEPRECATED/', $errstr) == 0) {
93
+ trigger_error('Unknown error received: ' . $errstr, E_USER_ERROR);
94
+ }
95
+ }
96
+
97
+ public static function includes($collection, $targetItem)
98
+ {
99
+ foreach ($collection AS $item) {
100
+ if ($item->id == $targetItem->id) {
101
+ return true;
102
+ }
103
+ }
104
+ return false;
105
+ }
106
+
107
+ public static function assertPrintable($object)
108
+ {
109
+ " " . $object;
110
+ }
111
+
112
+ public static function escrow($transactionId)
113
+ {
114
+ $http = new Braintree\Http(Braintree\Configuration::$global);
115
+ $path = Braintree\Configuration::$global->merchantPath() . '/transactions/' . $transactionId . '/escrow';
116
+ $http->put($path);
117
+ }
118
+
119
+ public static function create3DSVerification($merchantAccountId, $params)
120
+ {
121
+ $http = new Braintree\Http(Braintree\Configuration::$global);
122
+ $path = Braintree\Configuration::$global->merchantPath() . '/three_d_secure/create_verification/' . $merchantAccountId;
123
+ $response = $http->post($path, ['threeDSecureVerification' => $params]);
124
+ return $response['threeDSecureVerification']['threeDSecureToken'];
125
+ }
126
+
127
+ public static function generate3DSNonce($params)
128
+ {
129
+ $http = new Braintree\Http(Braintree\Configuration::$global);
130
+ $path = Braintree\Configuration::$global->merchantPath() . '/three_d_secure/create_nonce/' . self::threeDSecureMerchantAccountId();
131
+ $response = $http->post($path, $params);
132
+ return $response['paymentMethodNonce']['nonce'];
133
+ }
134
+
135
+ public static function nowInEastern()
136
+ {
137
+ $eastern = new DateTimeZone('America/New_York');
138
+ $now = new DateTime('now', $eastern);
139
+ return $now->format('Y-m-d');
140
+ }
141
+
142
+ public static function decodedClientToken($params=[]) {
143
+ $encodedClientToken = Braintree\ClientToken::generate($params);
144
+ return base64_decode($encodedClientToken);
145
+ }
146
+
147
+ public static function generateValidUsBankAccountNonce() {
148
+ $client_token = json_decode(Helper::decodedClientToken(), true);
149
+ $url = $client_token['braintree_api']['url'] . '/tokens';
150
+ $token = $client_token['braintree_api']['access_token'];
151
+
152
+ $curl = curl_init();
153
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
154
+ curl_setopt($curl, CURLOPT_URL, $url);
155
+
156
+ $headers[] = 'Content-Type: application/json';
157
+ $headers[] = 'Braintree-Version: 2015-11-01';
158
+ $headers[] = 'Authorization: Bearer ' . $token;
159
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
160
+
161
+ $requestBody = [
162
+ 'type' => 'us_bank_account',
163
+ 'billing_address' => [
164
+ 'street_address' => '123 Ave',
165
+ 'region' => 'CA',
166
+ 'locality' => 'San Francisco',
167
+ 'postal_code' => '94112'
168
+ ],
169
+ 'account_type' => 'checking',
170
+ 'routing_number' => '021000021',
171
+ 'account_number' => '567891234',
172
+ 'account_holder_name' => 'Dan Schulman',
173
+ 'ach_mandate' => [
174
+ 'text' => 'cl mandate text'
175
+ ]
176
+ ];
177
+
178
+ curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($requestBody));
179
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
180
+
181
+ $response = curl_exec($curl);
182
+ $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
183
+ $error_code = curl_errno($curl);
184
+ curl_close($curl);
185
+ $jsonResponse = json_decode($response, true);
186
+ return $jsonResponse['data']['id'];
187
+ }
188
+
189
+ public static function generateInvalidUsBankAccountNonce() {
190
+ $valid_characters = str_split(self::$valid_nonce_characters);
191
+ $nonce = 'tokenusbankacct';
192
+ for($i=0; $i<4; $i++) {
193
+ $nonce = $nonce . '_';
194
+ for($j=0; $j<6; $j++) {
195
+ $t = rand(0, sizeof($valid_characters)-1);
196
+ $nonce = $nonce . $valid_characters[$t];
197
+ }
198
+ }
199
+ return $nonce . "_xxx";
200
+ }
201
+
202
+ public static function generateValidIdealPaymentId($amount = null) {
203
+ if (null === $amount) {
204
+ $amount = '100.00';
205
+ }
206
+
207
+ $client_token = json_decode(Helper::decodedClientToken([
208
+ 'merchantAccountId' => 'ideal_merchant_account'
209
+ ]), true);
210
+
211
+ $client = new Integration\HttpClientApi(Braintree\Configuration::$global);
212
+ $configuration = $client->get_configuration([
213
+ "authorization_fingerprint" => $client_token['authorizationFingerprint'],
214
+ ]);
215
+
216
+ $url = $client_token['braintree_api']['url'] . '/ideal-payments';
217
+ $token = $client_token['braintree_api']['access_token'];
218
+
219
+ $curl = curl_init();
220
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
221
+ curl_setopt($curl, CURLOPT_URL, $url);
222
+
223
+ $headers[] = 'Content-Type: application/json';
224
+ $headers[] = 'Braintree-Version: 2015-11-01';
225
+ $headers[] = 'Authorization: Bearer ' . $token;
226
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
227
+
228
+ $requestBody = [
229
+ 'issuer' => 'RABONL2U',
230
+ 'order_id' => 'ABC123',
231
+ 'amount' => $amount,
232
+ 'currency' => 'EUR',
233
+ 'redirect_url' => 'https://braintree-api.com',
234
+ 'route_id' => $configuration->ideal->routeId,
235
+ ];
236
+
237
+ curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($requestBody));
238
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
239
+
240
+ $response = curl_exec($curl);
241
+ $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
242
+ $error_code = curl_errno($curl);
243
+ curl_close($curl);
244
+ $jsonResponse = json_decode($response, true);
245
+ return $jsonResponse['data']['id'];
246
+ }
247
+
248
+ public static function generateInvalidIdealPaymentId() {
249
+ $valid_characters = str_split(self::$valid_nonce_characters);
250
+ $ideal_payment_id = 'idealpayment';
251
+ for($i=0; $i<4; $i++) {
252
+ $ideal_payment_id = $ideal_payment_id . '_';
253
+ for($j=0; $j<6; $j++) {
254
+ $t = rand(0, sizeof($valid_characters)-1);
255
+ $ideal_payment_id = $ideal_payment_id . $valid_characters[$t];
256
+ }
257
+ }
258
+ return $ideal_payment_id . "_xxx";
259
+ }
260
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/SanityTest.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class SanityTest extends PHPUnit_Framework_TestCase
4
+ {
5
+ public function testLibraryWorksWithComposer()
6
+ {
7
+ if (version_compare(PHP_VERSION, "5.4.0", "<")) {
8
+ $this->markTestSkipped("Requires PHP >=5.4");
9
+ }
10
+
11
+ $returnValue = null;
12
+
13
+ $testFile = escapeshellarg(realpath(__DIR__ . '/Braintree/fixtures/composer_implementation.php'));
14
+ $command = sprintf('%s %s', PHP_BINARY, $testFile);
15
+
16
+ system($command, $returnValue);
17
+
18
+ $this->assertEquals(0, $returnValue);
19
+ }
20
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/Setup.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test;
3
+
4
+ require_once __DIR__ . '/Helper.php';
5
+ require_once __DIR__ . '/integration/HttpClientApi.php';
6
+ require_once __DIR__ . '/integration/SubscriptionHelper.php';
7
+ require_once __DIR__ . '/Braintree/CreditCardNumbers/CardTypeIndicators.php';
8
+ require_once __DIR__ . '/Braintree/CreditCardDefaults.php';
9
+ require_once __DIR__ . '/Braintree/OAuthTestHelper.php';
10
+
11
+ date_default_timezone_set('UTC');
12
+
13
+ use Braintree\Configuration;
14
+ use PHPUnit_Framework_TestCase;
15
+
16
+ class Setup extends PHPUnit_Framework_TestCase
17
+ {
18
+ public function __construct()
19
+ {
20
+ self::integrationMerchantConfig();
21
+ }
22
+
23
+ public static function integrationMerchantConfig()
24
+ {
25
+ Configuration::reset();
26
+
27
+ Configuration::environment('development');
28
+ Configuration::merchantId('integration_merchant_id');
29
+ Configuration::publicKey('integration_public_key');
30
+ Configuration::privateKey('integration_private_key');
31
+ }
32
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/AddOnsTest.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Braintree;
8
+
9
+ class AddOnsTest extends Setup
10
+ {
11
+ public function testAll_returnsAllAddOns()
12
+ {
13
+ $newId = strval(rand());
14
+
15
+ $addOnParams = [
16
+ "amount" => "100.00",
17
+ "description" => "some description",
18
+ "id" => $newId,
19
+ "kind" => "add_on",
20
+ "name" => "php_add_on",
21
+ "neverExpires" => "false",
22
+ "numberOfBillingCycles" => "1"
23
+ ];
24
+
25
+ $http = new Braintree\Http(Braintree\Configuration::$global);
26
+ $path = Braintree\Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
27
+ $http->post($path, ["modification" => $addOnParams]);
28
+
29
+ $addOns = Braintree\AddOn::all();
30
+
31
+ foreach ($addOns as $addOn)
32
+ {
33
+ if ($addOn->id == $newId)
34
+ {
35
+ $actualAddOn = $addOn;
36
+ }
37
+ }
38
+
39
+ $this->assertNotNull($actualAddOn);
40
+ $this->assertEquals($addOnParams["amount"], $actualAddOn->amount);
41
+ $this->assertEquals($addOnParams["description"], $actualAddOn->description);
42
+ $this->assertEquals($addOnParams["id"], $actualAddOn->id);
43
+ $this->assertEquals($addOnParams["kind"], $actualAddOn->kind);
44
+ $this->assertEquals($addOnParams["name"], $actualAddOn->name);
45
+ $this->assertFalse($actualAddOn->neverExpires);
46
+ $this->assertEquals($addOnParams["numberOfBillingCycles"], $actualAddOn->numberOfBillingCycles);
47
+ }
48
+
49
+ public function testGatewayAll_returnsAllAddOns()
50
+ {
51
+ $newId = strval(rand());
52
+
53
+ $addOnParams = [
54
+ "amount" => "100.00",
55
+ "description" => "some description",
56
+ "id" => $newId,
57
+ "kind" => "add_on",
58
+ "name" => "php_add_on",
59
+ "neverExpires" => "false",
60
+ "numberOfBillingCycles" => "1"
61
+ ];
62
+
63
+ $http = new Braintree\Http(Braintree\Configuration::$global);
64
+ $path = Braintree\Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
65
+ $http->post($path, ["modification" => $addOnParams]);
66
+
67
+ $gateway = new Braintree\Gateway([
68
+ 'environment' => 'development',
69
+ 'merchantId' => 'integration_merchant_id',
70
+ 'publicKey' => 'integration_public_key',
71
+ 'privateKey' => 'integration_private_key'
72
+ ]);
73
+ $addOns = $gateway->addOn()->all();
74
+
75
+ foreach ($addOns as $addOn)
76
+ {
77
+ if ($addOn->id == $newId)
78
+ {
79
+ $actualAddOn = $addOn;
80
+ }
81
+ }
82
+
83
+ $this->assertNotNull($actualAddOn);
84
+ $this->assertEquals($addOnParams["amount"], $actualAddOn->amount);
85
+ $this->assertEquals($addOnParams["description"], $actualAddOn->description);
86
+ $this->assertEquals($addOnParams["id"], $actualAddOn->id);
87
+ }
88
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/AddressTest.php ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Braintree;
8
+
9
+ class AddressTest extends Setup
10
+ {
11
+ public function testCreate()
12
+ {
13
+ $customer = Braintree\Customer::createNoValidate();
14
+ $result = Braintree\Address::create([
15
+ 'customerId' => $customer->id,
16
+ 'firstName' => 'Dan',
17
+ 'lastName' => 'Smith',
18
+ 'company' => 'Braintree',
19
+ 'streetAddress' => '1 E Main St',
20
+ 'extendedAddress' => 'Apt 1F',
21
+ 'locality' => 'Chicago',
22
+ 'region' => 'IL',
23
+ 'postalCode' => '60622',
24
+ 'countryName' => 'Vatican City',
25
+ 'countryCodeAlpha2' => 'VA',
26
+ 'countryCodeAlpha3' => 'VAT',
27
+ 'countryCodeNumeric' => '336'
28
+ ]);
29
+ $this->assertTrue($result->success);
30
+ $address = $result->address;
31
+ $this->assertEquals('Dan', $address->firstName);
32
+ $this->assertEquals('Smith', $address->lastName);
33
+ $this->assertEquals('Braintree', $address->company);
34
+ $this->assertEquals('1 E Main St', $address->streetAddress);
35
+ $this->assertEquals('Apt 1F', $address->extendedAddress);
36
+ $this->assertEquals('Chicago', $address->locality);
37
+ $this->assertEquals('IL', $address->region);
38
+ $this->assertEquals('60622', $address->postalCode);
39
+ $this->assertEquals('Vatican City', $address->countryName);
40
+ $this->assertEquals('VA', $address->countryCodeAlpha2);
41
+ $this->assertEquals('VAT', $address->countryCodeAlpha3);
42
+ $this->assertEquals('336', $address->countryCodeNumeric);
43
+ }
44
+
45
+ public function testGatewayCreate()
46
+ {
47
+ $customer = Braintree\Customer::createNoValidate();
48
+
49
+ $gateway = new Braintree\Gateway([
50
+ 'environment' => 'development',
51
+ 'merchantId' => 'integration_merchant_id',
52
+ 'publicKey' => 'integration_public_key',
53
+ 'privateKey' => 'integration_private_key'
54
+ ]);
55
+ $result = $gateway->address()->create([
56
+ 'customerId' => $customer->id,
57
+ 'streetAddress' => '1 E Main St',
58
+ 'locality' => 'Chicago',
59
+ 'region' => 'IL',
60
+ 'postalCode' => '60622',
61
+ ]);
62
+
63
+ $this->assertTrue($result->success);
64
+ $address = $result->address;
65
+ $this->assertEquals('1 E Main St', $address->streetAddress);
66
+ $this->assertEquals('Chicago', $address->locality);
67
+ $this->assertEquals('IL', $address->region);
68
+ $this->assertEquals('60622', $address->postalCode);
69
+ }
70
+
71
+ public function testCreate_withValidationErrors()
72
+ {
73
+ $customer = Braintree\Customer::createNoValidate();
74
+ $result = Braintree\Address::create([
75
+ 'customerId' => $customer->id,
76
+ 'countryName' => 'Invalid States of America'
77
+ ]);
78
+ $this->assertFalse($result->success);
79
+ $countryErrors = $result->errors->forKey('address')->onAttribute('countryName');
80
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, $countryErrors[0]->code);
81
+ }
82
+
83
+ public function testCreate_withValidationErrors_onCountryCodes()
84
+ {
85
+ $customer = Braintree\Customer::createNoValidate();
86
+ $result = Braintree\Address::create([
87
+ 'customerId' => $customer->id,
88
+ 'countryCodeAlpha2' => 'ZZ'
89
+ ]);
90
+ $this->assertFalse($result->success);
91
+ $countryErrors = $result->errors->forKey('address')->onAttribute('countryCodeAlpha2');
92
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_COUNTRY_CODE_ALPHA2_IS_NOT_ACCEPTED, $countryErrors[0]->code);
93
+ }
94
+
95
+ public function testCreate_withNotFoundErrors()
96
+ {
97
+ $this->setExpectedException('Braintree\Exception\NotFound','Customer nonExistentCustomerId not found.');
98
+ $result = Braintree\Address::create([
99
+ 'customerId' => 'nonExistentCustomerId',
100
+ ]);
101
+ }
102
+
103
+ public function testCreateNoValidate()
104
+ {
105
+ $customer = Braintree\Customer::createNoValidate();
106
+ $address = Braintree\Address::createNoValidate([
107
+ 'customerId' => $customer->id,
108
+ 'firstName' => 'Dan',
109
+ 'lastName' => 'Smith',
110
+ 'company' => 'Braintree',
111
+ 'streetAddress' => '1 E Main St',
112
+ 'extendedAddress' => 'Apt 1F',
113
+ 'locality' => 'Chicago',
114
+ 'region' => 'IL',
115
+ 'postalCode' => '60622',
116
+ 'countryName' => 'United States of America'
117
+ ]);
118
+ $this->assertEquals('Dan', $address->firstName);
119
+ $this->assertEquals('Smith', $address->lastName);
120
+ $this->assertEquals('Braintree', $address->company);
121
+ $this->assertEquals('1 E Main St', $address->streetAddress);
122
+ $this->assertEquals('Apt 1F', $address->extendedAddress);
123
+ $this->assertEquals('Chicago', $address->locality);
124
+ $this->assertEquals('IL', $address->region);
125
+ $this->assertEquals('60622', $address->postalCode);
126
+ $this->assertEquals('United States of America', $address->countryName);
127
+ }
128
+
129
+ public function testCreateNoValidate_withValidationErrors()
130
+ {
131
+ $customer = Braintree\Customer::createNoValidate();
132
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
133
+ Braintree\Address::createNoValidate([
134
+ 'customerId' => $customer->id,
135
+ 'countryName' => 'Invalid States of America'
136
+ ]);
137
+ }
138
+
139
+ public function testDelete()
140
+ {
141
+ $customer = Braintree\Customer::createNoValidate();
142
+ $address = Braintree\Address::createNoValidate([
143
+ 'customerId' => $customer->id,
144
+ 'streetAddress' => '1 E Main St'
145
+ ]);
146
+ Braintree\Address::find($customer->id, $address->id);
147
+ Braintree\Address::delete($customer->id, $address->id);
148
+ $this->setExpectedException('Braintree\Exception\NotFound');
149
+ Braintree\Address::find($customer->id, $address->id);
150
+ }
151
+
152
+ public function testFind()
153
+ {
154
+ $customer = Braintree\Customer::createNoValidate();
155
+ $result = Braintree\Address::create([
156
+ 'customerId' => $customer->id,
157
+ 'firstName' => 'Dan',
158
+ 'lastName' => 'Smith',
159
+ 'company' => 'Braintree',
160
+ 'streetAddress' => '1 E Main St',
161
+ 'extendedAddress' => 'Apt 1F',
162
+ 'locality' => 'Chicago',
163
+ 'region' => 'IL',
164
+ 'postalCode' => '60622',
165
+ 'countryName' => 'United States of America'
166
+ ]);
167
+ $this->assertTrue($result->success);
168
+ $address = Braintree\Address::find($customer->id, $result->address->id);
169
+ $this->assertEquals('Dan', $address->firstName);
170
+ $this->assertEquals('Smith', $address->lastName);
171
+ $this->assertEquals('Braintree', $address->company);
172
+ $this->assertEquals('1 E Main St', $address->streetAddress);
173
+ $this->assertEquals('Apt 1F', $address->extendedAddress);
174
+ $this->assertEquals('Chicago', $address->locality);
175
+ $this->assertEquals('IL', $address->region);
176
+ $this->assertEquals('60622', $address->postalCode);
177
+ $this->assertEquals('United States of America', $address->countryName);
178
+ }
179
+
180
+ public function testFind_whenNotFound()
181
+ {
182
+ $customer = Braintree\Customer::createNoValidate();
183
+ $this->setExpectedException('Braintree\Exception\NotFound');
184
+ Braintree\Address::find($customer->id, 'does-not-exist');
185
+ }
186
+
187
+ public function testUpdate()
188
+ {
189
+ $customer = Braintree\Customer::createNoValidate();
190
+ $address = Braintree\Address::createNoValidate([
191
+ 'customerId' => $customer->id,
192
+ 'firstName' => 'Old First',
193
+ 'lastName' => 'Old Last',
194
+ 'company' => 'Old Company',
195
+ 'streetAddress' => '1 E Old St',
196
+ 'extendedAddress' => 'Apt Old',
197
+ 'locality' => 'Old Chicago',
198
+ 'region' => 'Old Region',
199
+ 'postalCode' => 'Old Postal',
200
+ 'countryName' => 'United States of America',
201
+ 'countryCodeAlpha2' => 'US',
202
+ 'countryCodeAlpha3' => 'USA',
203
+ 'countryCodeNumeric' => '840'
204
+ ]);
205
+ $result = Braintree\Address::update($customer->id, $address->id, [
206
+ 'firstName' => 'New First',
207
+ 'lastName' => 'New Last',
208
+ 'company' => 'New Company',
209
+ 'streetAddress' => '1 E New St',
210
+ 'extendedAddress' => 'Apt New',
211
+ 'locality' => 'New Chicago',
212
+ 'region' => 'New Region',
213
+ 'postalCode' => 'New Postal',
214
+ 'countryName' => 'Mexico',
215
+ 'countryCodeAlpha2' => 'MX',
216
+ 'countryCodeAlpha3' => 'MEX',
217
+ 'countryCodeNumeric' => '484'
218
+ ]);
219
+ $this->assertTrue($result->success);
220
+ $address = $result->address;
221
+ $this->assertEquals('New First', $address->firstName);
222
+ $this->assertEquals('New Last', $address->lastName);
223
+ $this->assertEquals('New Company', $address->company);
224
+ $this->assertEquals('1 E New St', $address->streetAddress);
225
+ $this->assertEquals('Apt New', $address->extendedAddress);
226
+ $this->assertEquals('New Chicago', $address->locality);
227
+ $this->assertEquals('New Region', $address->region);
228
+ $this->assertEquals('New Postal', $address->postalCode);
229
+ $this->assertEquals('Mexico', $address->countryName);
230
+ $this->assertEquals('MX', $address->countryCodeAlpha2);
231
+ $this->assertEquals('MEX', $address->countryCodeAlpha3);
232
+ $this->assertEquals('484', $address->countryCodeNumeric);
233
+ }
234
+
235
+ public function testUpdate_withValidationErrors()
236
+ {
237
+ $customer = Braintree\Customer::createNoValidate();
238
+ $address = Braintree\Address::createNoValidate([
239
+ 'customerId' => $customer->id,
240
+ 'streetAddress' => '1 E Main St'
241
+ ]);
242
+ $result = Braintree\Address::update(
243
+ $customer->id,
244
+ $address->id,
245
+ [
246
+ 'countryName' => 'Invalid States of America'
247
+ ]
248
+ );
249
+ $this->assertFalse($result->success);
250
+ $countryErrors = $result->errors->forKey('address')->onAttribute('countryName');
251
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, $countryErrors[0]->code);
252
+ }
253
+
254
+ public function testUpdate_withValidationErrors_onCountry()
255
+ {
256
+ $customer = Braintree\Customer::createNoValidate();
257
+ $address = Braintree\Address::createNoValidate([
258
+ 'customerId' => $customer->id,
259
+ 'streetAddress' => '1 E Main St'
260
+ ]);
261
+ $result = Braintree\Address::update(
262
+ $customer->id,
263
+ $address->id,
264
+ [
265
+ 'countryCodeAlpha2' => 'MU',
266
+ 'countryCodeAlpha3' => 'MYT'
267
+ ]
268
+ );
269
+ $this->assertFalse($result->success);
270
+ $countryErrors = $result->errors->forKey('address')->onAttribute('base');
271
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_INCONSISTENT_COUNTRY, $countryErrors[0]->code);
272
+ }
273
+
274
+
275
+ public function testUpdateNoValidate()
276
+ {
277
+ $customer = Braintree\Customer::createNoValidate();
278
+ $createdAddress = Braintree\Address::createNoValidate([
279
+ 'customerId' => $customer->id,
280
+ 'firstName' => 'Old First',
281
+ 'lastName' => 'Old Last',
282
+ 'company' => 'Old Company',
283
+ 'streetAddress' => '1 E Old St',
284
+ 'extendedAddress' => 'Apt Old',
285
+ 'locality' => 'Old Chicago',
286
+ 'region' => 'Old Region',
287
+ 'postalCode' => 'Old Postal',
288
+ 'countryName' => 'United States of America'
289
+ ]);
290
+ $address = Braintree\Address::updateNoValidate($customer->id, $createdAddress->id, [
291
+ 'firstName' => 'New First',
292
+ 'lastName' => 'New Last',
293
+ 'company' => 'New Company',
294
+ 'streetAddress' => '1 E New St',
295
+ 'extendedAddress' => 'Apt New',
296
+ 'locality' => 'New Chicago',
297
+ 'region' => 'New Region',
298
+ 'postalCode' => 'New Postal',
299
+ 'countryName' => 'Mexico'
300
+ ]);
301
+ $this->assertEquals('New First', $address->firstName);
302
+ $this->assertEquals('New Last', $address->lastName);
303
+ $this->assertEquals('New Company', $address->company);
304
+ $this->assertEquals('1 E New St', $address->streetAddress);
305
+ $this->assertEquals('Apt New', $address->extendedAddress);
306
+ $this->assertEquals('New Chicago', $address->locality);
307
+ $this->assertEquals('New Region', $address->region);
308
+ $this->assertEquals('New Postal', $address->postalCode);
309
+ $this->assertEquals('Mexico', $address->countryName);
310
+ }
311
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/ClientTokenTest.php ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class ClientTokenTest extends Setup
11
+ {
12
+ public function test_ClientTokenAuthorizesRequest()
13
+ {
14
+ $clientToken = Test\Helper::decodedClientToken();
15
+ $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
16
+ $http = new HttpClientApi(Braintree\Configuration::$global);
17
+ $response = $http->get_cards([
18
+ "authorization_fingerprint" => $authorizationFingerprint,
19
+ "shared_customer_identifier" => "fake_identifier",
20
+ "shared_customer_identifier_type" => "testing",
21
+ ]);
22
+
23
+ $this->assertEquals(200, $response["status"]);
24
+ }
25
+
26
+ public function test_VersionOptionSupported()
27
+ {
28
+ $clientToken = Braintree\ClientToken::generate(["version" => 1]);
29
+ $version = json_decode($clientToken)->version;
30
+ $this->assertEquals(1, $version);
31
+ }
32
+
33
+ public function test_VersionDefaultsToTwo()
34
+ {
35
+ $encodedClientToken = Braintree\ClientToken::generate();
36
+ $clientToken = base64_decode($encodedClientToken);
37
+ $version = json_decode($clientToken)->version;
38
+ $this->assertEquals(2, $version);
39
+ }
40
+
41
+ public function testGateway_VersionDefaultsToTwo()
42
+ {
43
+ $gateway = new Braintree\Gateway([
44
+ 'environment' => 'development',
45
+ 'merchantId' => 'integration_merchant_id',
46
+ 'publicKey' => 'integration_public_key',
47
+ 'privateKey' => 'integration_private_key',
48
+ ]);
49
+ $encodedClientToken = $gateway->clientToken()->generate();
50
+ $clientToken = base64_decode($encodedClientToken);
51
+ $version = json_decode($clientToken)->version;
52
+ $this->assertEquals(2, $version);
53
+ }
54
+
55
+ public function test_GatewayRespectsVerifyCard()
56
+ {
57
+ $result = Braintree\Customer::create();
58
+ $this->assertTrue($result->success);
59
+ $customerId = $result->customer->id;
60
+
61
+ $clientToken = Test\Helper::decodedClientToken([
62
+ "customerId" => $customerId,
63
+ "options" => [
64
+ "verifyCard" => true
65
+ ]
66
+ ]);
67
+ $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
68
+
69
+ $http = new HttpClientApi(Braintree\Configuration::$global);
70
+ $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode([
71
+ "credit_card" => [
72
+ "number" => "4000111111111115",
73
+ "expirationDate" => "11/2099"
74
+ ],
75
+ "authorization_fingerprint" => $authorizationFingerprint,
76
+ "shared_customer_identifier" => "fake_identifier",
77
+ "shared_customer_identifier_type" => "testing"
78
+ ]));
79
+
80
+ $this->assertEquals(422, $response["status"]);
81
+ }
82
+
83
+ public function test_GatewayRespectsFailOnDuplicatePaymentMethod()
84
+ {
85
+ $result = Braintree\Customer::create();
86
+ $this->assertTrue($result->success);
87
+ $customerId = $result->customer->id;
88
+
89
+ $clientToken = Test\Helper::decodedClientToken([
90
+ "customerId" => $customerId,
91
+ ]);
92
+ $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
93
+
94
+ $http = new HttpClientApi(Braintree\Configuration::$global);
95
+ $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode([
96
+ "credit_card" => [
97
+ "number" => "4242424242424242",
98
+ "expirationDate" => "11/2099"
99
+ ],
100
+ "authorization_fingerprint" => $authorizationFingerprint,
101
+ "shared_customer_identifier" => "fake_identifier",
102
+ "shared_customer_identifier_type" => "testing"
103
+ ]));
104
+ $this->assertEquals(201, $response["status"]);
105
+
106
+ $clientToken = Test\Helper::decodedClientToken([
107
+ "customerId" => $customerId,
108
+ "options" => [
109
+ "failOnDuplicatePaymentMethod" => true
110
+ ]
111
+ ]);
112
+ $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
113
+
114
+ $http = new HttpClientApi(Braintree\Configuration::$global);
115
+ $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode([
116
+ "credit_card" => [
117
+ "number" => "4242424242424242",
118
+ "expirationDate" => "11/2099"
119
+ ],
120
+ "authorization_fingerprint" => $authorizationFingerprint,
121
+ "shared_customer_identifier" => "fake_identifier",
122
+ "shared_customer_identifier_type" => "testing"
123
+ ]));
124
+ $this->assertEquals(422, $response["status"]);
125
+ }
126
+
127
+ public function test_GatewayRespectsMakeDefault()
128
+ {
129
+ $result = Braintree\Customer::create();
130
+ $this->assertTrue($result->success);
131
+ $customerId = $result->customer->id;
132
+
133
+ $result = Braintree\CreditCard::create([
134
+ 'customerId' => $customerId,
135
+ 'number' => '4111111111111111',
136
+ 'expirationDate' => '11/2099'
137
+ ]);
138
+ $this->assertTrue($result->success);
139
+
140
+ $clientToken = Test\Helper::decodedClientToken([
141
+ "customerId" => $customerId,
142
+ "options" => [
143
+ "makeDefault" => true
144
+ ]
145
+ ]);
146
+ $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
147
+
148
+ $http = new HttpClientApi(Braintree\Configuration::$global);
149
+ $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode([
150
+ "credit_card" => [
151
+ "number" => "4242424242424242",
152
+ "expirationDate" => "11/2099"
153
+ ],
154
+ "authorization_fingerprint" => $authorizationFingerprint,
155
+ "shared_customer_identifier" => "fake_identifier",
156
+ "shared_customer_identifier_type" => "testing"
157
+ ]));
158
+
159
+ $this->assertEquals(201, $response["status"]);
160
+
161
+ $customer = Braintree\Customer::find($customerId);
162
+ $this->assertEquals(2, count($customer->creditCards));
163
+ foreach ($customer->creditCards as $creditCard) {
164
+ if ($creditCard->last4 == "4242") {
165
+ $this->assertTrue($creditCard->default);
166
+ }
167
+ }
168
+ }
169
+
170
+ public function test_ClientTokenAcceptsMerchantAccountId()
171
+ {
172
+ $expectedMerchantAccountId = Test\Helper::nonDefaultMerchantAccountId();
173
+ $clientToken = Test\Helper::decodedClientToken([
174
+ 'merchantAccountId' => $expectedMerchantAccountId
175
+ ]);
176
+ $merchantAccountId = json_decode($clientToken)->merchantAccountId;
177
+
178
+ $this->assertEquals($expectedMerchantAccountId, $merchantAccountId);
179
+ }
180
+
181
+ public function test_GenerateRaisesExceptionOnGateway422()
182
+ {
183
+ $this->setExpectedException('InvalidArgumentException', 'customer_id');
184
+
185
+ Braintree\ClientToken::generate([
186
+ "customerId" => "not_a_customer"
187
+ ]);
188
+ }
189
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/CreditCardTest.php ADDED
@@ -0,0 +1,1325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Braintree\CreditCardNumbers\CardTypeIndicators;
8
+ use Test\Setup;
9
+ use Braintree;
10
+
11
+ class CreditCardTest extends Setup
12
+ {
13
+ public function testCreate()
14
+ {
15
+ $customer = Braintree\Customer::createNoValidate();
16
+ $result = Braintree\CreditCard::create([
17
+ 'customerId' => $customer->id,
18
+ 'cardholderName' => 'Cardholder',
19
+ 'number' => '5105105105105100',
20
+ 'expirationDate' => '05/12'
21
+ ]);
22
+ $this->assertTrue($result->success);
23
+ $this->assertEquals($customer->id, $result->creditCard->customerId);
24
+ $this->assertEquals('510510', $result->creditCard->bin);
25
+ $this->assertEquals('5100', $result->creditCard->last4);
26
+ $this->assertEquals('Cardholder', $result->creditCard->cardholderName);
27
+ $this->assertEquals('05/2012', $result->creditCard->expirationDate);
28
+ $this->assertEquals(1, preg_match('/\A\w{32}\z/', $result->creditCard->uniqueNumberIdentifier));
29
+ $this->assertFalse($result->creditCard->isVenmoSdk());
30
+ $this->assertEquals(1, preg_match('/png/', $result->creditCard->imageUrl));
31
+ }
32
+
33
+ public function testGatewayCreate()
34
+ {
35
+ $customer = Braintree\Customer::createNoValidate();
36
+
37
+ $gateway = new Braintree\Gateway([
38
+ 'environment' => 'development',
39
+ 'merchantId' => 'integration_merchant_id',
40
+ 'publicKey' => 'integration_public_key',
41
+ 'privateKey' => 'integration_private_key'
42
+ ]);
43
+ $result = $gateway->creditCard()->create([
44
+ 'customerId' => $customer->id,
45
+ 'cardholderName' => 'Cardholder',
46
+ 'number' => '5105105105105100',
47
+ 'expirationDate' => '05/12'
48
+ ]);
49
+
50
+ $this->assertTrue($result->success);
51
+ $this->assertEquals($customer->id, $result->creditCard->customerId);
52
+ $this->assertEquals('510510', $result->creditCard->bin);
53
+ $this->assertEquals('5100', $result->creditCard->last4);
54
+ $this->assertEquals('Cardholder', $result->creditCard->cardholderName);
55
+ $this->assertEquals('05/2012', $result->creditCard->expirationDate);
56
+ }
57
+
58
+ public function testCreate_withDefault()
59
+ {
60
+ $customer = Braintree\Customer::createNoValidate();
61
+ $card1 = Braintree\CreditCard::create([
62
+ 'customerId' => $customer->id,
63
+ 'cardholderName' => 'Cardholder',
64
+ 'number' => '5105105105105100',
65
+ 'expirationDate' => '05/12'
66
+ ])->creditCard;
67
+ $this->assertTrue($card1->isDefault());
68
+
69
+ $card2 = Braintree\CreditCard::create([
70
+ 'customerId' => $customer->id,
71
+ 'cardholderName' => 'Cardholder',
72
+ 'number' => '5105105105105100',
73
+ 'expirationDate' => '05/12',
74
+ 'options' => [
75
+ 'makeDefault' => true
76
+ ]
77
+ ])->creditCard;
78
+
79
+ $card1 = Braintree\CreditCard::find($card1->token);
80
+ $this->assertFalse($card1->isDefault());
81
+ $this->assertTrue($card2->isDefault());
82
+ }
83
+
84
+ public function testCreateWithVerificationAmount()
85
+ {
86
+ $customer = Braintree\Customer::createNoValidate();
87
+ $result = Braintree\CreditCard::create([
88
+ 'customerId' => $customer->id,
89
+ 'cardholderName' => 'Cardholder',
90
+ 'number' => '4111111111111111',
91
+ 'expirationDate' => '05/12',
92
+ 'options' => [
93
+ 'verificationAmount' => '5.00',
94
+ 'verifyCard' => true
95
+ ]
96
+ ]);
97
+ $this->assertTrue($result->success);
98
+ $this->assertEquals($customer->id, $result->creditCard->customerId);
99
+ $this->assertEquals('411111', $result->creditCard->bin);
100
+ $this->assertEquals('1111', $result->creditCard->last4);
101
+ $this->assertEquals('Cardholder', $result->creditCard->cardholderName);
102
+ $this->assertEquals('05/2012', $result->creditCard->expirationDate);
103
+ $this->assertEquals(1, preg_match('/\A\w{32}\z/', $result->creditCard->uniqueNumberIdentifier));
104
+ $this->assertFalse($result->creditCard->isVenmoSdk());
105
+ $this->assertEquals(1, preg_match('/png/', $result->creditCard->imageUrl));
106
+ }
107
+
108
+ public function testAddCardToExistingCustomerUsingNonce()
109
+ {
110
+ $customer = Braintree\Customer::createNoValidate();
111
+ $http = new HttpClientApi(Braintree\Configuration::$global);
112
+ $nonce = $http->nonce_for_new_card([
113
+ "credit_card" => [
114
+ "number" => "4111111111111111",
115
+ "expirationMonth" => "11",
116
+ "expirationYear" => "2099"
117
+ ],
118
+ "share" => true
119
+ ]);
120
+
121
+ $result = Braintree\CreditCard::create([
122
+ 'customerId' => $customer->id,
123
+ 'paymentMethodNonce' => $nonce
124
+ ]);
125
+
126
+ $this->assertSame("411111", $result->creditCard->bin);
127
+ $this->assertSame("1111", $result->creditCard->last4);
128
+ }
129
+
130
+ public function testCreate_withSecurityParams()
131
+ {
132
+ $customer = Braintree\Customer::createNoValidate();
133
+ $result = Braintree\CreditCard::create([
134
+ 'customerId' => $customer->id,
135
+ 'deviceSessionId' => 'abc_123',
136
+ 'fraudMerchantId' => '456',
137
+ 'cardholderName' => 'Cardholder',
138
+ 'number' => '5105105105105100',
139
+ 'expirationDate' => '05/12'
140
+ ]);
141
+
142
+ $this->assertTrue($result->success);
143
+ }
144
+
145
+ public function testCreate_withExpirationMonthAndYear()
146
+ {
147
+ $customer = Braintree\Customer::createNoValidate();
148
+ $result = Braintree\CreditCard::create([
149
+ 'customerId' => $customer->id,
150
+ 'cardholderName' => 'Cardholder',
151
+ 'number' => '5105105105105100',
152
+ 'expirationMonth' => '05',
153
+ 'expirationYear' => '2011'
154
+ ]);
155
+ $this->assertTrue($result->success);
156
+ $this->assertEquals($customer->id, $result->creditCard->customerId);
157
+ $this->assertEquals('510510', $result->creditCard->bin);
158
+ $this->assertEquals('5100', $result->creditCard->last4);
159
+ $this->assertEquals('Cardholder', $result->creditCard->cardholderName);
160
+ $this->assertEquals('05/2011', $result->creditCard->expirationDate);
161
+ }
162
+
163
+ public function testCreate_withSpecifyingToken()
164
+ {
165
+ $token = strval(rand());
166
+ $customer = Braintree\Customer::createNoValidate();
167
+ $result = Braintree\CreditCard::create([
168
+ 'customerId' => $customer->id,
169
+ 'number' => '5105105105105100',
170
+ 'expirationDate' => '05/2011',
171
+ 'token' => $token
172
+ ]);
173
+ $this->assertTrue($result->success);
174
+ $this->assertEquals($token, $result->creditCard->token);
175
+ $this->assertEquals($token, Braintree\CreditCard::find($token)->token);
176
+ }
177
+
178
+ public function testCreate_withDuplicateCardCheck()
179
+ {
180
+ $customer = Braintree\Customer::createNoValidate();
181
+
182
+ $attributes = [
183
+ 'customerId' => $customer->id,
184
+ 'number' => '5105105105105100',
185
+ 'expirationDate' => '05/2011',
186
+ 'options' => ['failOnDuplicatePaymentMethod' => true]
187
+ ];
188
+ Braintree\CreditCard::create($attributes);
189
+
190
+ $result = Braintree\CreditCard::create($attributes);
191
+ $this->assertFalse($result->success);
192
+ $errors = $result->errors->forKey('creditCard')->onAttribute('number');
193
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_DUPLICATE_CARD_EXISTS, $errors[0]->code);
194
+ $this->assertEquals(1, preg_match('/Duplicate card exists in the vault\./', $result->message));
195
+ }
196
+
197
+ public function testCreate_withCardVerification()
198
+ {
199
+ $customer = Braintree\Customer::createNoValidate();
200
+ $result = Braintree\CreditCard::create([
201
+ 'customerId' => $customer->id,
202
+ 'number' => '5105105105105100',
203
+ 'expirationDate' => '05/2011',
204
+ 'options' => ['verifyCard' => true]
205
+ ]);
206
+ $this->assertFalse($result->success);
207
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
208
+ $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
209
+ $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
210
+ $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
211
+ $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
212
+ $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
213
+ $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
214
+ $this->assertEquals(Braintree\CreditCard::PREPAID_UNKNOWN, $result->creditCardVerification->creditCard['prepaid']);
215
+ }
216
+
217
+ public function testCreate_withCardVerificationReturnsVerificationWithRiskData()
218
+ {
219
+ $customer = Braintree\Customer::createNoValidate();
220
+ $result = Braintree\CreditCard::create([
221
+ 'customerId' => $customer->id,
222
+ 'number' => '4111111111111111',
223
+ 'expirationDate' => '05/2011',
224
+ 'options' => ['verifyCard' => true]
225
+ ]);
226
+ $this->assertTrue($result->success);
227
+ $this->assertNotNull($result->creditCard->verification->riskData);
228
+ $this->assertNotNull($result->creditCard->verification->riskData->decision);
229
+ }
230
+
231
+ public function testCreate_withCardVerificationAndOverriddenAmount()
232
+ {
233
+ $customer = Braintree\Customer::createNoValidate();
234
+ $result = Braintree\CreditCard::create([
235
+ 'customerId' => $customer->id,
236
+ 'number' => '5105105105105100',
237
+ 'expirationDate' => '05/2011',
238
+ 'options' => ['verifyCard' => true, 'verificationAmount' => '1.02']
239
+ ]);
240
+ $this->assertFalse($result->success);
241
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
242
+ $this->assertEquals('1.02', $result->creditCardVerification->amount);
243
+ $this->assertEquals('USD', $result->creditCardVerification->currencyIsoCode);
244
+ $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
245
+ $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
246
+ $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
247
+ $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
248
+ $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
249
+ $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
250
+ $this->assertEquals(Braintree\CreditCard::PREPAID_UNKNOWN, $result->creditCardVerification->creditCard['prepaid']);
251
+ }
252
+
253
+ public function testCreate_withCardVerificationAndSpecificMerchantAccount()
254
+ {
255
+ $customer = Braintree\Customer::createNoValidate();
256
+ $result = Braintree\CreditCard::create([
257
+ 'customerId' => $customer->id,
258
+ 'number' => '5105105105105100',
259
+ 'expirationDate' => '05/2011',
260
+ 'options' => ['verificationMerchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(), 'verifyCard' => true],
261
+ ]);
262
+ $this->assertFalse($result->success);
263
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
264
+ $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
265
+ $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
266
+ $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
267
+ $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
268
+ $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
269
+ $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
270
+ }
271
+
272
+ public function testCreate_withBillingAddress()
273
+ {
274
+ $customer = Braintree\Customer::createNoValidate();
275
+ $result = Braintree\CreditCard::create([
276
+ 'customerId' => $customer->id,
277
+ 'cardholderName' => 'Peter Tomlin',
278
+ 'number' => '5105105105105100',
279
+ 'expirationDate' => '05/12',
280
+ 'billingAddress' => [
281
+ 'firstName' => 'Drew',
282
+ 'lastName' => 'Smith',
283
+ 'company' => 'Smith Co.',
284
+ 'streetAddress' => '1 E Main St',
285
+ 'extendedAddress' => 'Suite 101',
286
+ 'locality' => 'Chicago',
287
+ 'region' => 'IL',
288
+ 'postalCode' => '60622',
289
+ 'countryName' => 'Micronesia',
290
+ 'countryCodeAlpha2' => 'FM',
291
+ 'countryCodeAlpha3' => 'FSM',
292
+ 'countryCodeNumeric' => '583'
293
+ ]
294
+ ]);
295
+ $this->assertTrue($result->success);
296
+ $this->assertEquals($customer->id, $result->creditCard->customerId);
297
+ $this->assertEquals('510510', $result->creditCard->bin);
298
+ $this->assertEquals('5100', $result->creditCard->last4);
299
+ $this->assertEquals('Peter Tomlin', $result->creditCard->cardholderName);
300
+ $this->assertEquals('05/2012', $result->creditCard->expirationDate);
301
+ $address = $result->creditCard->billingAddress;
302
+ $this->assertEquals('Drew', $address->firstName);
303
+ $this->assertEquals('Smith', $address->lastName);
304
+ $this->assertEquals('Smith Co.', $address->company);
305
+ $this->assertEquals('1 E Main St', $address->streetAddress);
306
+ $this->assertEquals('Suite 101', $address->extendedAddress);
307
+ $this->assertEquals('Chicago', $address->locality);
308
+ $this->assertEquals('IL', $address->region);
309
+ $this->assertEquals('60622', $address->postalCode);
310
+ $this->assertEquals('Micronesia', $address->countryName);
311
+ $this->assertEquals('FM', $address->countryCodeAlpha2);
312
+ $this->assertEquals('FSM', $address->countryCodeAlpha3);
313
+ $this->assertEquals('583', $address->countryCodeNumeric);
314
+ }
315
+
316
+ public function testCreate_withExistingBillingAddress()
317
+ {
318
+ $customer = Braintree\Customer::createNoValidate();
319
+ $existingAddress = Braintree\Address::createNoValidate([
320
+ 'customerId' => $customer->id,
321
+ 'firstName' => 'John'
322
+ ]);
323
+ $result = Braintree\CreditCard::create([
324
+ 'customerId' => $customer->id,
325
+ 'number' => '5105105105105100',
326
+ 'expirationDate' => '05/12',
327
+ 'billingAddressId' => $existingAddress->id
328
+ ]);
329
+ $this->assertTrue($result->success);
330
+ $address = $result->creditCard->billingAddress;
331
+ $this->assertEquals($existingAddress->id, $address->id);
332
+ $this->assertEquals('John', $address->firstName);
333
+ }
334
+
335
+ public function testCreate_withValidationErrors()
336
+ {
337
+ $customer = Braintree\Customer::createNoValidate();
338
+ $result = Braintree\CreditCard::create([
339
+ 'expirationDate' => 'invalid',
340
+ 'billingAddress' => [
341
+ 'countryName' => 'Tuvalu',
342
+ 'countryCodeAlpha2' => 'US'
343
+ ]
344
+ ]);
345
+ $this->assertFalse($result->success);
346
+ $errors = $result->errors->forKey('creditCard')->onAttribute('expirationDate');
347
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID, $errors[0]->code);
348
+ $this->assertEquals(1, preg_match('/Credit card number is required\./', $result->message));
349
+ $this->assertEquals(1, preg_match('/Customer ID is required\./', $result->message));
350
+ $this->assertEquals(1, preg_match('/Expiration date is invalid\./', $result->message));
351
+
352
+ $errors = $result->errors->forKey('creditCard')->forKey('billingAddress')->onAttribute('base');
353
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_INCONSISTENT_COUNTRY, $errors[0]->code);
354
+ }
355
+
356
+ public function testCreate_withVenmoSdkPaymentMethodCode()
357
+ {
358
+ $customer = Braintree\Customer::createNoValidate();
359
+ $result = Braintree\CreditCard::create([
360
+ 'customerId' => $customer->id,
361
+ 'venmoSdkPaymentMethodCode' => Braintree\Test\VenmoSdk::generateTestPaymentMethodCode('378734493671000')
362
+ ]);
363
+ $this->assertTrue($result->success);
364
+ $this->assertEquals("378734", $result->creditCard->bin);
365
+ }
366
+
367
+ public function testCreate_with_invalid_venmoSdkPaymentMethodCode()
368
+ {
369
+ $customer = Braintree\Customer::createNoValidate();
370
+ $result = Braintree\CreditCard::create([
371
+ 'customerId' => $customer->id,
372
+ 'venmoSdkPaymentMethodCode' => Braintree\Test\VenmoSdk::getInvalidPaymentMethodCode(),
373
+ ]);
374
+ $this->assertFalse($result->success);
375
+ $errors = $result->errors->forKey('creditCard')->onAttribute('venmoSdkPaymentMethodCode');
376
+ $this->assertEquals($errors[0]->code, Braintree\Error\Codes::CREDIT_CARD_INVALID_VENMO_SDK_PAYMENT_METHOD_CODE);
377
+
378
+ }
379
+
380
+ public function testCreate_with_venmoSdkSession()
381
+ {
382
+ $customer = Braintree\Customer::createNoValidate();
383
+ $result = Braintree\CreditCard::create([
384
+ 'customerId' => $customer->id,
385
+ 'number' => '5105105105105100',
386
+ 'expirationDate' => '05/12',
387
+ 'options' => [
388
+ 'venmoSdkSession' => Braintree\Test\VenmoSdk::getTestSession()
389
+ ]
390
+ ]);
391
+ $this->assertTrue($result->success);
392
+ $this->assertTrue($result->creditCard->isVenmoSdk());
393
+ }
394
+
395
+ public function testCreate_with_invalidVenmoSdkSession()
396
+ {
397
+ $customer = Braintree\Customer::createNoValidate();
398
+ $result = Braintree\CreditCard::create([
399
+ 'customerId' => $customer->id,
400
+ 'number' => '5105105105105100',
401
+ 'expirationDate' => '05/12',
402
+ 'options' => [
403
+ 'venmoSdkSession' => Braintree\Test\VenmoSdk::getInvalidTestSession(),
404
+ ]
405
+ ]);
406
+ $this->assertTrue($result->success);
407
+ $this->assertFalse($result->creditCard->isVenmoSdk());
408
+ }
409
+
410
+ public function testCreateNoValidate_throwsIfValidationsFail()
411
+ {
412
+
413
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
414
+ $customer = Braintree\Customer::createNoValidate();
415
+ Braintree\CreditCard::createNoValidate([
416
+ 'expirationDate' => 'invalid',
417
+ ]);
418
+ }
419
+
420
+ public function testCreateNoValidate_returnsCreditCardIfValid()
421
+ {
422
+ $customer = Braintree\Customer::createNoValidate();
423
+ $creditCard = Braintree\CreditCard::createNoValidate([
424
+ 'customerId' => $customer->id,
425
+ 'cardholderName' => 'Cardholder',
426
+ 'number' => '5105105105105100',
427
+ 'expirationDate' => '05/12'
428
+ ]);
429
+ $this->assertEquals($customer->id, $creditCard->customerId);
430
+ $this->assertEquals('510510', $creditCard->bin);
431
+ $this->assertEquals('5100', $creditCard->last4);
432
+ $this->assertEquals('Cardholder', $creditCard->cardholderName);
433
+ $this->assertEquals('05/2012', $creditCard->expirationDate);
434
+ }
435
+
436
+ public function testCreateFromTransparentRedirect()
437
+ {
438
+ Test\Helper::suppressDeprecationWarnings();
439
+ $customer = Braintree\Customer::createNoValidate();
440
+ $queryString = $this->createCreditCardViaTr(
441
+ [
442
+ 'credit_card' => [
443
+ 'number' => '5105105105105100',
444
+ 'expiration_date' => '05/12'
445
+ ]
446
+ ],
447
+ [
448
+ 'creditCard' => [
449
+ 'customerId' => $customer->id
450
+ ]
451
+ ]
452
+ );
453
+ $result = Braintree\CreditCard::createFromTransparentRedirect($queryString);
454
+ $this->assertTrue($result->success);
455
+ $this->assertEquals('510510', $result->creditCard->bin);
456
+ $this->assertEquals('5100', $result->creditCard->last4);
457
+ $this->assertEquals('05/2012', $result->creditCard->expirationDate);
458
+ }
459
+
460
+ public function testCreateFromTransparentRedirect_withDefault()
461
+ {
462
+ Test\Helper::suppressDeprecationWarnings();
463
+ $customer = Braintree\Customer::createNoValidate();
464
+ $queryString = $this->createCreditCardViaTr(
465
+ [
466
+ 'credit_card' => [
467
+ 'number' => '5105105105105100',
468
+ 'expiration_date' => '05/12',
469
+ 'options' => ['make_default' => true]
470
+ ]
471
+ ],
472
+ [
473
+ 'creditCard' => [
474
+ 'customerId' => $customer->id
475
+ ]
476
+ ]
477
+ );
478
+ $result = Braintree\CreditCard::createFromTransparentRedirect($queryString);
479
+ $this->assertTrue($result->creditCard->isDefault());
480
+ }
481
+
482
+ public function testUpdateFromTransparentRedirect()
483
+ {
484
+ $customer = Braintree\Customer::createNoValidate();
485
+ $creditCard = Braintree\CreditCard::createNoValidate([
486
+ 'customerId' => $customer->id,
487
+ 'number' => '5105105105105100',
488
+ 'expirationDate' => '05/12'
489
+ ]);
490
+ $queryString = $this->updateCreditCardViaTr(
491
+ [
492
+ 'credit_card' => [
493
+ 'number' => '4111111111111111',
494
+ 'expiration_date' => '01/11'
495
+ ]
496
+ ],
497
+ ['paymentMethodToken' => $creditCard->token]
498
+ );
499
+ $result = Braintree\CreditCard::updateFromTransparentRedirect($queryString);
500
+ $this->assertTrue($result->success);
501
+ $this->assertEquals('411111', $result->creditCard->bin);
502
+ $this->assertEquals('1111', $result->creditCard->last4);
503
+ $this->assertEquals('01/2011', $result->creditCard->expirationDate);
504
+ }
505
+
506
+ public function testUpdateFromTransparentRedirect_withDefault()
507
+ {
508
+ $customer = Braintree\Customer::createNoValidate();
509
+ $card1 = Braintree\CreditCard::createNoValidate([
510
+ 'customerId' => $customer->id,
511
+ 'number' => '5105105105105100',
512
+ 'expirationDate' => '05/12'
513
+ ]);
514
+ $card2 = Braintree\CreditCard::createNoValidate([
515
+ 'customerId' => $customer->id,
516
+ 'number' => '5105105105105100',
517
+ 'expirationDate' => '05/12'
518
+ ]);
519
+ $this->assertFalse($card2->isDefault());
520
+
521
+ $queryString = $this->updateCreditCardViaTr(
522
+ [
523
+ 'credit_card' => [
524
+ 'options' => [
525
+ 'make_default' => true
526
+ ]
527
+ ]
528
+ ],
529
+ ['paymentMethodToken' => $card2->token]
530
+ );
531
+ $result = Braintree\CreditCard::updateFromTransparentRedirect($queryString);
532
+ $this->assertFalse(Braintree\CreditCard::find($card1->token)->isDefault());
533
+ $this->assertTrue(Braintree\CreditCard::find($card2->token)->isDefault());
534
+ }
535
+
536
+ public function testUpdateFromTransparentRedirect_andUpdateExistingBillingAddress()
537
+ {
538
+ $customer = Braintree\Customer::createNoValidate();
539
+ $card = Braintree\CreditCard::createNoValidate([
540
+ 'customerId' => $customer->id,
541
+ 'number' => '5105105105105100',
542
+ 'expirationDate' => '05/12',
543
+ 'billingAddress' => [
544
+ 'firstName' => 'Drew',
545
+ 'lastName' => 'Smith',
546
+ 'company' => 'Smith Co.',
547
+ 'streetAddress' => '123 Old St',
548
+ 'extendedAddress' => 'Suite 101',
549
+ 'locality' => 'Chicago',
550
+ 'region' => 'IL',
551
+ 'postalCode' => '60622',
552
+ 'countryName' => 'United States of America'
553
+ ]
554
+ ]);
555
+
556
+ $queryString = $this->updateCreditCardViaTr(
557
+ [],
558
+ [
559
+ 'paymentMethodToken' => $card->token,
560
+ 'creditCard' => [
561
+ 'billingAddress' => [
562
+ 'streetAddress' => '123 New St',
563
+ 'locality' => 'St. Louis',
564
+ 'region' => 'MO',
565
+ 'postalCode' => '63119',
566
+ 'options' => [
567
+ 'updateExisting' => True
568
+ ]
569
+ ]
570
+ ]
571
+ ]
572
+ );
573
+ $result = Braintree\CreditCard::updateFromTransparentRedirect($queryString);
574
+ $this->assertTrue($result->success);
575
+ $card = $result->creditCard;
576
+ $this->assertEquals(1, sizeof(Braintree\Customer::find($customer->id)->addresses));
577
+ $this->assertEquals('123 New St', $card->billingAddress->streetAddress);
578
+ $this->assertEquals('St. Louis', $card->billingAddress->locality);
579
+ $this->assertEquals('MO', $card->billingAddress->region);
580
+ $this->assertEquals('63119', $card->billingAddress->postalCode);
581
+ }
582
+
583
+ public function testSale_createsASaleUsingGivenToken()
584
+ {
585
+ $customer = Braintree\Customer::createNoValidate([
586
+ 'creditCard' => [
587
+ 'number' => '5105105105105100',
588
+ 'expirationDate' => '05/12'
589
+ ]
590
+ ]);
591
+ $creditCard = $customer->creditCards[0];
592
+ $result = Braintree\CreditCard::sale($creditCard->token, [
593
+ 'amount' => '100.00'
594
+ ]);
595
+ $this->assertTrue($result->success);
596
+ $this->assertEquals('100.00', $result->transaction->amount);
597
+ $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
598
+ $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
599
+ }
600
+
601
+ public function testSaleNoValidate_createsASaleUsingGivenToken()
602
+ {
603
+ $customer = Braintree\Customer::createNoValidate([
604
+ 'creditCard' => [
605
+ 'number' => '5105105105105100',
606
+ 'expirationDate' => '05/12'
607
+ ]
608
+ ]);
609
+ $creditCard = $customer->creditCards[0];
610
+ $transaction = Braintree\CreditCard::saleNoValidate($creditCard->token, [
611
+ 'amount' => '100.00'
612
+ ]);
613
+ $this->assertEquals('100.00', $transaction->amount);
614
+ $this->assertEquals($customer->id, $transaction->customerDetails->id);
615
+ $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
616
+ }
617
+
618
+ public function testSaleNoValidate_createsASaleUsingGivenTokenAndCvv()
619
+ {
620
+ $customer = Braintree\Customer::createNoValidate([
621
+ 'creditCard' => [
622
+ 'number' => '5105105105105100',
623
+ 'expirationDate' => '05/12'
624
+ ]
625
+ ]);
626
+ $creditCard = $customer->creditCards[0];
627
+ $transaction = Braintree\CreditCard::saleNoValidate($creditCard->token, [
628
+ 'amount' => '100.00',
629
+ 'creditCard' => [
630
+ 'cvv' => '301'
631
+ ]
632
+ ]);
633
+ $this->assertEquals('100.00', $transaction->amount);
634
+ $this->assertEquals($customer->id, $transaction->customerDetails->id);
635
+ $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
636
+ $this->assertEquals('S', $transaction->cvvResponseCode);
637
+ }
638
+
639
+ public function testSaleNoValidate_throwsIfInvalid()
640
+ {
641
+ $customer = Braintree\Customer::createNoValidate([
642
+ 'creditCard' => [
643
+ 'number' => '5105105105105100',
644
+ 'expirationDate' => '05/12'
645
+ ]
646
+ ]);
647
+ $creditCard = $customer->creditCards[0];
648
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
649
+ Braintree\CreditCard::saleNoValidate($creditCard->token, [
650
+ 'amount' => 'invalid'
651
+ ]);
652
+ }
653
+
654
+ public function testCredit_createsACreditUsingGivenToken()
655
+ {
656
+ $customer = Braintree\Customer::createNoValidate([
657
+ 'creditCard' => [
658
+ 'number' => '5105105105105100',
659
+ 'expirationDate' => '05/12'
660
+ ]
661
+ ]);
662
+ $creditCard = $customer->creditCards[0];
663
+ $result = Braintree\CreditCard::credit($creditCard->token, [
664
+ 'amount' => '100.00'
665
+ ]);
666
+ $this->assertTrue($result->success);
667
+ $this->assertEquals('100.00', $result->transaction->amount);
668
+ $this->assertEquals(Braintree\Transaction::CREDIT, $result->transaction->type);
669
+ $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
670
+ $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
671
+ }
672
+
673
+ public function testCreditNoValidate_createsACreditUsingGivenToken()
674
+ {
675
+ $customer = Braintree\Customer::createNoValidate([
676
+ 'creditCard' => [
677
+ 'number' => '5105105105105100',
678
+ 'expirationDate' => '05/12'
679
+ ]
680
+ ]);
681
+ $creditCard = $customer->creditCards[0];
682
+ $transaction = Braintree\CreditCard::creditNoValidate($creditCard->token, [
683
+ 'amount' => '100.00'
684
+ ]);
685
+ $this->assertEquals('100.00', $transaction->amount);
686
+ $this->assertEquals(Braintree\Transaction::CREDIT, $transaction->type);
687
+ $this->assertEquals($customer->id, $transaction->customerDetails->id);
688
+ $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
689
+ }
690
+
691
+ public function testCreditNoValidate_throwsIfInvalid()
692
+ {
693
+ $customer = Braintree\Customer::createNoValidate([
694
+ 'creditCard' => [
695
+ 'number' => '5105105105105100',
696
+ 'expirationDate' => '05/12'
697
+ ]
698
+ ]);
699
+ $creditCard = $customer->creditCards[0];
700
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
701
+ Braintree\CreditCard::creditNoValidate($creditCard->token, [
702
+ 'amount' => 'invalid'
703
+ ]);
704
+ }
705
+
706
+ public function testExpired()
707
+ {
708
+ $collection = Braintree\CreditCard::expired();
709
+ $this->assertTrue($collection->maximumCount() > 1);
710
+
711
+ $arr = [];
712
+ foreach($collection as $creditCard) {
713
+ $this->assertTrue($creditCard->isExpired());
714
+ array_push($arr, $creditCard->token);
715
+ }
716
+ $uniqueCreditCardTokens = array_unique(array_values($arr));
717
+ $this->assertEquals($collection->maximumCount(), count($uniqueCreditCardTokens));
718
+ }
719
+
720
+
721
+ public function testExpiringBetween()
722
+ {
723
+ $collection = Braintree\CreditCard::expiringBetween(
724
+ mktime(0, 0, 0, 1, 1, 2010),
725
+ mktime(23, 59, 59, 12, 31, 2010)
726
+ );
727
+ $this->assertTrue($collection->maximumCount() > 1);
728
+
729
+ $arr = [];
730
+ foreach($collection as $creditCard) {
731
+ $this->assertEquals('2010', $creditCard->expirationYear);
732
+ array_push($arr, $creditCard->token);
733
+ }
734
+ $uniqueCreditCardTokens = array_unique(array_values($arr));
735
+ $this->assertEquals($collection->maximumCount(), count($uniqueCreditCardTokens));
736
+ }
737
+
738
+ public function testExpiringBetween_parsesCreditCardDetailsUnderTransactionsCorrectly()
739
+ {
740
+ $collection = Braintree\CreditCard::expiringBetween(
741
+ mktime(0, 0, 0, 1, 1, 2010),
742
+ mktime(23, 59, 59, 12, 31, 2010)
743
+ );
744
+ $this->assertTrue($collection->maximumCount() > 1);
745
+
746
+ foreach($collection as $creditCard) {
747
+ foreach($creditCard->subscriptions as $subscription) {
748
+ foreach($subscription->transactions as $transaction) {
749
+ $this->assertNotNull($transaction->creditCardDetails->expirationMonth);
750
+ }
751
+ }
752
+ }
753
+ }
754
+
755
+ public function testFind()
756
+ {
757
+ $customer = Braintree\Customer::createNoValidate();
758
+ $result = Braintree\CreditCard::create([
759
+ 'customerId' => $customer->id,
760
+ 'cardholderName' => 'Cardholder',
761
+ 'number' => '5105105105105100',
762
+ 'expirationDate' => '05/12'
763
+ ]);
764
+ $this->assertTrue($result->success);
765
+ $creditCard = Braintree\CreditCard::find($result->creditCard->token);
766
+ $this->assertEquals($customer->id, $creditCard->customerId);
767
+ $this->assertEquals('510510', $creditCard->bin);
768
+ $this->assertEquals('5100', $creditCard->last4);
769
+ $this->assertEquals('Cardholder', $creditCard->cardholderName);
770
+ $this->assertEquals('05/2012', $creditCard->expirationDate);
771
+ $this->assertEquals([], $creditCard->subscriptions);
772
+ }
773
+
774
+ public function testFindReturnsAssociatedSubscriptions()
775
+ {
776
+ $customer = Braintree\Customer::createNoValidate();
777
+ $result = Braintree\CreditCard::create([
778
+ 'customerId' => $customer->id,
779
+ 'cardholderName' => 'Cardholder',
780
+ 'number' => '5105105105105100',
781
+ 'expirationDate' => '05/12',
782
+ 'billingAddress' => [
783
+ 'firstName' => 'Drew',
784
+ 'lastName' => 'Smith',
785
+ 'company' => 'Smith Co.',
786
+ 'streetAddress' => '1 E Main St',
787
+ 'extendedAddress' => 'Suite 101',
788
+ 'locality' => 'Chicago',
789
+ 'region' => 'IL',
790
+ 'postalCode' => '60622',
791
+ 'countryName' => 'United States of America'
792
+ ]
793
+ ]);
794
+ $id = strval(rand());
795
+ Braintree\Subscription::create([
796
+ 'id' => $id,
797
+ 'paymentMethodToken' => $result->creditCard->token,
798
+ 'planId' => 'integration_trialless_plan',
799
+ 'price' => '1.00'
800
+ ]);
801
+ $creditCard = Braintree\CreditCard::find($result->creditCard->token);
802
+ $this->assertEquals($id, $creditCard->subscriptions[0]->id);
803
+ $this->assertEquals('integration_trialless_plan', $creditCard->subscriptions[0]->planId);
804
+ $this->assertEquals('1.00', $creditCard->subscriptions[0]->price);
805
+ }
806
+
807
+ public function testFind_throwsIfCannotBeFound()
808
+ {
809
+ $this->setExpectedException('Braintree\Exception\NotFound');
810
+ Braintree\CreditCard::find('invalid-token');
811
+ }
812
+
813
+ public function testFind_throwsUsefulErrorMessagesWhenEmpty()
814
+ {
815
+ $this->setExpectedException('InvalidArgumentException', 'expected credit card id to be set');
816
+ Braintree\CreditCard::find('');
817
+ }
818
+
819
+ public function testFind_throwsUsefulErrorMessagesWhenInvalid()
820
+ {
821
+ $this->setExpectedException('InvalidArgumentException', '@ is an invalid credit card token');
822
+ Braintree\CreditCard::find('@');
823
+ }
824
+
825
+ public function testFromNonce()
826
+ {
827
+ $customer = Braintree\Customer::createNoValidate();
828
+ $http = new HttpClientApi(Braintree\Configuration::$global);
829
+ $nonce = $http->nonce_for_new_card([
830
+ "credit_card" => [
831
+ "number" => "4009348888881881",
832
+ "expirationMonth" => "11",
833
+ "expirationYear" => "2099"
834
+ ],
835
+ "customerId" => $customer->id
836
+ ]);
837
+
838
+ $creditCard = Braintree\CreditCard::fromNonce($nonce);
839
+
840
+ $customer = Braintree\Customer::find($customer->id);
841
+ $this->assertEquals($customer->creditCards[0], $creditCard);
842
+ }
843
+
844
+ public function testFromNonce_ReturnsErrorWhenNoncePointsToSharedCard()
845
+ {
846
+ $http = new HttpClientApi(Braintree\Configuration::$global);
847
+ $nonce = $http->nonce_for_new_card([
848
+ "credit_card" => [
849
+ "number" => "4009348888881881",
850
+ "expirationMonth" => "11",
851
+ "expirationYear" => "2099"
852
+ ],
853
+ "share" => true
854
+ ]);
855
+
856
+ $this->setExpectedException('Braintree\Exception\NotFound', "not found");
857
+ Braintree\CreditCard::fromNonce($nonce);
858
+ }
859
+
860
+ public function testFromNonce_ReturnsErrorWhenNonceIsConsumed()
861
+ {
862
+ $customer = Braintree\Customer::createNoValidate();
863
+ $http = new HttpClientApi(Braintree\Configuration::$global);
864
+ $nonce = $http->nonce_for_new_card([
865
+ "credit_card" => [
866
+ "number" => "4009348888881881",
867
+ "expirationMonth" => "11",
868
+ "expirationYear" => "2099"
869
+ ],
870
+ "customerId" => $customer->id
871
+ ]);
872
+
873
+ Braintree\CreditCard::fromNonce($nonce);
874
+ $this->setExpectedException('Braintree\Exception\NotFound', "consumed");
875
+ Braintree\CreditCard::fromNonce($nonce);
876
+ }
877
+
878
+ public function testUpdate()
879
+ {
880
+ $customer = Braintree\Customer::createNoValidate();
881
+ $createResult = Braintree\CreditCard::create([
882
+ 'customerId' => $customer->id,
883
+ 'cardholderName' => 'Old Cardholder',
884
+ 'number' => '5105105105105100',
885
+ 'expirationDate' => '05/12'
886
+ ]);
887
+ $this->assertTrue($createResult->success);
888
+ $updateResult = Braintree\CreditCard::update($createResult->creditCard->token, [
889
+ 'cardholderName' => 'New Cardholder',
890
+ 'number' => '4111111111111111',
891
+ 'expirationDate' => '07/14'
892
+ ]);
893
+ $this->assertEquals($customer->id, $updateResult->creditCard->customerId);
894
+ $this->assertEquals('411111', $updateResult->creditCard->bin);
895
+ $this->assertEquals('1111', $updateResult->creditCard->last4);
896
+ $this->assertEquals('New Cardholder', $updateResult->creditCard->cardholderName);
897
+ $this->assertEquals('07/2014', $updateResult->creditCard->expirationDate);
898
+ }
899
+
900
+ public function testUpdate_withCardVerification()
901
+ {
902
+ $customer = Braintree\Customer::createNoValidate();
903
+ $initialCreditCard = Braintree\CreditCard::create([
904
+ 'customerId' => $customer->id,
905
+ 'number' => '5105105105105100',
906
+ 'expirationDate' => '05/12'
907
+ ])->creditCard;
908
+
909
+ $result = Braintree\CreditCard::update($initialCreditCard->token, [
910
+ 'billingAddress' => [
911
+ 'region' => 'IL'
912
+ ],
913
+ 'options' => ['verifyCard' => true]
914
+ ]);
915
+ $this->assertFalse($result->success);
916
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
917
+ $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
918
+ $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
919
+ $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
920
+ $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
921
+ $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
922
+ $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
923
+ $this->assertEquals(Test\Helper::defaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
924
+ }
925
+
926
+ public function testUpdate_withCardVerificationAndSpecificMerchantAccount()
927
+ {
928
+ $customer = Braintree\Customer::createNoValidate();
929
+ $initialCreditCard = Braintree\CreditCard::create([
930
+ 'customerId' => $customer->id,
931
+ 'number' => '5105105105105100',
932
+ 'expirationDate' => '05/12'
933
+ ])->creditCard;
934
+
935
+ $result = Braintree\CreditCard::update($initialCreditCard->token, [
936
+ 'billingAddress' => [
937
+ 'region' => 'IL'
938
+ ],
939
+ 'options' => [
940
+ 'verificationMerchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(),
941
+ 'verifyCard' => true
942
+ ]
943
+ ]);
944
+ $this->assertFalse($result->success);
945
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
946
+ $this->assertEquals(Test\Helper::nonDefaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
947
+ }
948
+
949
+ public function testUpdate_createsNewBillingAddressByDefault()
950
+ {
951
+ $customer = Braintree\Customer::createNoValidate();
952
+ $initialCreditCard = Braintree\CreditCard::create([
953
+ 'customerId' => $customer->id,
954
+ 'number' => '5105105105105100',
955
+ 'expirationDate' => '05/12',
956
+ 'billingAddress' => [
957
+ 'streetAddress' => '123 Nigeria Ave'
958
+ ]
959
+ ])->creditCard;
960
+
961
+ $updatedCreditCard = Braintree\CreditCard::update($initialCreditCard->token, [
962
+ 'billingAddress' => [
963
+ 'region' => 'IL'
964
+ ]
965
+ ])->creditCard;
966
+ $this->assertEquals('IL', $updatedCreditCard->billingAddress->region);
967
+ $this->assertNull($updatedCreditCard->billingAddress->streetAddress);
968
+ $this->assertNotEquals($initialCreditCard->billingAddress->id, $updatedCreditCard->billingAddress->id);
969
+ }
970
+
971
+ public function testUpdate_updatesExistingBillingAddressIfUpdateExistingOptionIsTrue()
972
+ {
973
+ $customer = Braintree\Customer::createNoValidate();
974
+ $initialCreditCard = Braintree\CreditCard::create([
975
+ 'customerId' => $customer->id,
976
+ 'number' => '5105105105105100',
977
+ 'expirationDate' => '05/12',
978
+ 'billingAddress' => [
979
+ 'countryName' => 'Turkey',
980
+ 'countryCodeAlpha2' => 'TR',
981
+ 'countryCodeAlpha3' => 'TUR',
982
+ 'countryCodeNumeric' => '792',
983
+ ]
984
+ ])->creditCard;
985
+
986
+ $updatedCreditCard = Braintree\CreditCard::update($initialCreditCard->token, [
987
+ 'billingAddress' => [
988
+ 'countryName' => 'Thailand',
989
+ 'countryCodeAlpha2' => 'TH',
990
+ 'countryCodeAlpha3' => 'THA',
991
+ 'countryCodeNumeric' => '764',
992
+ 'options' => [
993
+ 'updateExisting' => True
994
+ ]
995
+ ]
996
+ ])->creditCard;
997
+ $this->assertEquals('Thailand', $updatedCreditCard->billingAddress->countryName);
998
+ $this->assertEquals('TH', $updatedCreditCard->billingAddress->countryCodeAlpha2);
999
+ $this->assertEquals('THA', $updatedCreditCard->billingAddress->countryCodeAlpha3);
1000
+ $this->assertEquals('764', $updatedCreditCard->billingAddress->countryCodeNumeric);
1001
+ $this->assertEquals($initialCreditCard->billingAddress->id, $updatedCreditCard->billingAddress->id);
1002
+ }
1003
+
1004
+ public function testUpdate_canChangeToken()
1005
+ {
1006
+ $oldToken = strval(rand());
1007
+ $newToken = strval(rand());
1008
+
1009
+ $customer = Braintree\Customer::createNoValidate();
1010
+ $createResult = Braintree\CreditCard::create([
1011
+ 'customerId' => $customer->id,
1012
+ 'token' => $oldToken,
1013
+ 'number' => '5105105105105100',
1014
+ 'expirationDate' => '05/12'
1015
+ ]);
1016
+ $this->assertTrue($createResult->success);
1017
+ $updateResult = Braintree\CreditCard::update($oldToken, [
1018
+ 'token' => $newToken
1019
+ ]);
1020
+ $this->assertEquals($customer->id, $updateResult->creditCard->customerId);
1021
+ $this->assertEquals($newToken, $updateResult->creditCard->token);
1022
+ $this->assertEquals($newToken, Braintree\CreditCard::find($newToken)->token);
1023
+ }
1024
+
1025
+ public function testUpdateNoValidate()
1026
+ {
1027
+ $customer = Braintree\Customer::createNoValidate();
1028
+ $creditCard = Braintree\CreditCard::createNoValidate([
1029
+ 'customerId' => $customer->id,
1030
+ 'cardholderName' => 'Old Cardholder',
1031
+ 'number' => '5105105105105100',
1032
+ 'expirationDate' => '05/12'
1033
+ ]);
1034
+ $updatedCard = Braintree\CreditCard::updateNoValidate($creditCard->token, [
1035
+ 'cardholderName' => 'New Cardholder',
1036
+ 'number' => '4111111111111111',
1037
+ 'expirationDate' => '07/14'
1038
+ ]);
1039
+ $this->assertEquals($customer->id, $updatedCard->customerId);
1040
+ $this->assertEquals('411111', $updatedCard->bin);
1041
+ $this->assertEquals('1111', $updatedCard->last4);
1042
+ $this->assertEquals('New Cardholder', $updatedCard->cardholderName);
1043
+ $this->assertEquals('07/2014', $updatedCard->expirationDate);
1044
+ }
1045
+
1046
+ public function testUpdateNoValidate_throwsIfInvalid()
1047
+ {
1048
+ $customer = Braintree\Customer::createNoValidate();
1049
+ $creditCard = Braintree\CreditCard::createNoValidate([
1050
+ 'customerId' => $customer->id,
1051
+ 'cardholderName' => 'Old Cardholder',
1052
+ 'number' => '5105105105105100',
1053
+ 'expirationDate' => '05/12'
1054
+ ]);
1055
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
1056
+ Braintree\CreditCard::updateNoValidate($creditCard->token, [
1057
+ 'number' => 'invalid',
1058
+ ]);
1059
+ }
1060
+
1061
+ public function testUpdate_withDefault()
1062
+ {
1063
+ $customer = Braintree\Customer::createNoValidate();
1064
+ $card1 = Braintree\CreditCard::create([
1065
+ 'customerId' => $customer->id,
1066
+ 'cardholderName' => 'Cardholder',
1067
+ 'number' => '5105105105105100',
1068
+ 'expirationDate' => '05/12'
1069
+ ])->creditCard;
1070
+ $card2 = Braintree\CreditCard::create([
1071
+ 'customerId' => $customer->id,
1072
+ 'cardholderName' => 'Cardholder',
1073
+ 'number' => '5105105105105100',
1074
+ 'expirationDate' => '05/12'
1075
+ ])->creditCard;
1076
+
1077
+ $this->assertTrue($card1->isDefault());
1078
+ $this->assertFalse($card2->isDefault());
1079
+
1080
+ Braintree\CreditCard::update($card2->token, [
1081
+ 'options' => ['makeDefault' => true]
1082
+ ])->creditCard;
1083
+
1084
+ $this->assertFalse(Braintree\CreditCard::find($card1->token)->isDefault());
1085
+ $this->assertTrue(Braintree\CreditCard::find($card2->token)->isDefault());
1086
+ }
1087
+
1088
+ public function testDelete_deletesThePaymentMethod()
1089
+ {
1090
+ $customer = Braintree\Customer::createNoValidate([]);
1091
+ $creditCard = Braintree\CreditCard::createNoValidate([
1092
+ 'customerId' => $customer->id,
1093
+ 'number' => '5105105105105100',
1094
+ 'expirationDate' => '05/12'
1095
+ ]);
1096
+ Braintree\CreditCard::find($creditCard->token);
1097
+ Braintree\CreditCard::delete($creditCard->token);
1098
+ $this->setExpectedException('Braintree\Exception\NotFound');
1099
+ Braintree\CreditCard::find($creditCard->token);
1100
+ }
1101
+
1102
+ public function testGatewayRejectionOnCVV()
1103
+ {
1104
+ $old_merchant_id = Braintree\Configuration::merchantId();
1105
+ $old_public_key = Braintree\Configuration::publicKey();
1106
+ $old_private_key = Braintree\Configuration::privateKey();
1107
+
1108
+ Braintree\Configuration::merchantId('processing_rules_merchant_id');
1109
+ Braintree\Configuration::publicKey('processing_rules_public_key');
1110
+ Braintree\Configuration::privateKey('processing_rules_private_key');
1111
+
1112
+ $customer = Braintree\Customer::createNoValidate();
1113
+ $result = Braintree\CreditCard::create([
1114
+ 'customerId' => $customer->id,
1115
+ 'number' => '4111111111111111',
1116
+ 'expirationDate' => '05/2011',
1117
+ 'cvv' => '200',
1118
+ 'options' => ['verifyCard' => true]
1119
+ ]);
1120
+
1121
+ Braintree\Configuration::merchantId($old_merchant_id);
1122
+ Braintree\Configuration::publicKey($old_public_key);
1123
+ Braintree\Configuration::privateKey($old_private_key);
1124
+
1125
+ $this->assertFalse($result->success);
1126
+ $this->assertEquals(Braintree\Transaction::CVV, $result->creditCardVerification->gatewayRejectionReason);
1127
+ }
1128
+
1129
+ public function testGatewayRejectionIsNullOnProcessorDecline()
1130
+ {
1131
+ $old_merchant_id = Braintree\Configuration::merchantId();
1132
+ $old_public_key = Braintree\Configuration::publicKey();
1133
+ $old_private_key = Braintree\Configuration::privateKey();
1134
+
1135
+ Braintree\Configuration::merchantId('processing_rules_merchant_id');
1136
+ Braintree\Configuration::publicKey('processing_rules_public_key');
1137
+ Braintree\Configuration::privateKey('processing_rules_private_key');
1138
+
1139
+ $customer = Braintree\Customer::createNoValidate();
1140
+ $result = Braintree\CreditCard::create([
1141
+ 'customerId' => $customer->id,
1142
+ 'number' => '5105105105105100',
1143
+ 'expirationDate' => '05/2011',
1144
+ 'cvv' => '200',
1145
+ 'options' => ['verifyCard' => true]
1146
+ ]);
1147
+
1148
+ Braintree\Configuration::merchantId($old_merchant_id);
1149
+ Braintree\Configuration::publicKey($old_public_key);
1150
+ Braintree\Configuration::privateKey($old_private_key);
1151
+
1152
+ $this->assertFalse($result->success);
1153
+ $this->assertNull($result->creditCardVerification->gatewayRejectionReason);
1154
+ }
1155
+
1156
+ public function createCreditCardViaTr($regularParams, $trParams)
1157
+ {
1158
+ $trData = Braintree\TransparentRedirect::createCreditCardData(
1159
+ array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
1160
+ );
1161
+ return Test\Helper::submitTrRequest(
1162
+ Braintree\CreditCard::createCreditCardUrl(),
1163
+ $regularParams,
1164
+ $trData
1165
+ );
1166
+ }
1167
+
1168
+ public function updateCreditCardViaTr($regularParams, $trParams)
1169
+ {
1170
+ $trData = Braintree\TransparentRedirect::updateCreditCardData(
1171
+ array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
1172
+ );
1173
+ return Test\Helper::submitTrRequest(
1174
+ Braintree\CreditCard::updateCreditCardUrl(),
1175
+ $regularParams,
1176
+ $trData
1177
+ );
1178
+ }
1179
+
1180
+ public function testPrepaidCard()
1181
+ {
1182
+ $customer = Braintree\Customer::createNoValidate();
1183
+ $result = Braintree\CreditCard::create([
1184
+ 'customerId' => $customer->id,
1185
+ 'cardholderName' => 'Cardholder',
1186
+ 'number' => CardTypeIndicators::PREPAID,
1187
+ 'expirationDate' => '05/12',
1188
+ 'options' => ['verifyCard' => true]
1189
+ ]);
1190
+ $this->assertEquals(Braintree\CreditCard::PREPAID_YES, $result->creditCard->prepaid);
1191
+ }
1192
+
1193
+ public function testCommercialCard()
1194
+ {
1195
+ $customer = Braintree\Customer::createNoValidate();
1196
+ $result = Braintree\CreditCard::create([
1197
+ 'customerId' => $customer->id,
1198
+ 'cardholderName' => 'Cardholder',
1199
+ 'number' => CardTypeIndicators::COMMERCIAL,
1200
+ 'expirationDate' => '05/12',
1201
+ 'options' => ['verifyCard' => true]
1202
+ ]);
1203
+ $this->assertEquals(Braintree\CreditCard::COMMERCIAL_YES, $result->creditCard->commercial);
1204
+ }
1205
+
1206
+ public function testDebitCard()
1207
+ {
1208
+ $customer = Braintree\Customer::createNoValidate();
1209
+ $result = Braintree\CreditCard::create([
1210
+ 'customerId' => $customer->id,
1211
+ 'cardholderName' => 'Cardholder',
1212
+ 'number' => CardTypeIndicators::DEBIT,
1213
+ 'expirationDate' => '05/12',
1214
+ 'options' => ['verifyCard' => true]
1215
+ ]);
1216
+ $this->assertEquals(Braintree\CreditCard::DEBIT_YES, $result->creditCard->debit);
1217
+ }
1218
+
1219
+ public function testPayrollCard()
1220
+ {
1221
+ $customer = Braintree\Customer::createNoValidate();
1222
+ $result = Braintree\CreditCard::create([
1223
+ 'customerId' => $customer->id,
1224
+ 'cardholderName' => 'Cardholder',
1225
+ 'number' => CardTypeIndicators::PAYROLL,
1226
+ 'expirationDate' => '05/12',
1227
+ 'options' => ['verifyCard' => true]
1228
+ ]);
1229
+ $this->assertEquals(Braintree\CreditCard::PAYROLL_YES, $result->creditCard->payroll);
1230
+ $this->assertEquals('MSA', $result->creditCard->productId);
1231
+ }
1232
+
1233
+ public function testHealthCareCard()
1234
+ {
1235
+ $customer = Braintree\Customer::createNoValidate();
1236
+ $result = Braintree\CreditCard::create([
1237
+ 'customerId' => $customer->id,
1238
+ 'cardholderName' => 'Cardholder',
1239
+ 'number' => CardTypeIndicators::HEALTHCARE,
1240
+ 'expirationDate' => '05/12',
1241
+ 'options' => ['verifyCard' => true]
1242
+ ]);
1243
+ $this->assertEquals(Braintree\CreditCard::HEALTHCARE_YES, $result->creditCard->healthcare);
1244
+ $this->assertEquals('J3', $result->creditCard->productId);
1245
+ }
1246
+
1247
+ public function testDurbinRegulatedCard()
1248
+ {
1249
+ $customer = Braintree\Customer::createNoValidate();
1250
+ $result = Braintree\CreditCard::create([
1251
+ 'customerId' => $customer->id,
1252
+ 'cardholderName' => 'Cardholder',
1253
+ 'number' => CardTypeIndicators::DURBIN_REGULATED,
1254
+ 'expirationDate' => '05/12',
1255
+ 'options' => ['verifyCard' => true]
1256
+ ]);
1257
+ $this->assertEquals(Braintree\CreditCard::DURBIN_REGULATED_YES, $result->creditCard->durbinRegulated);
1258
+ }
1259
+
1260
+ public function testCountryOfIssuanceCard()
1261
+ {
1262
+ $customer = Braintree\Customer::createNoValidate();
1263
+ $result = Braintree\CreditCard::create([
1264
+ 'customerId' => $customer->id,
1265
+ 'cardholderName' => 'Cardholder',
1266
+ 'number' => CardTypeIndicators::COUNTRY_OF_ISSUANCE,
1267
+ 'expirationDate' => '05/12',
1268
+ 'options' => ['verifyCard' => true]
1269
+ ]);
1270
+ $this->assertEquals("USA", $result->creditCard->countryOfIssuance);
1271
+ }
1272
+
1273
+ public function testIssuingBankCard()
1274
+ {
1275
+ $customer = Braintree\Customer::createNoValidate();
1276
+ $result = Braintree\CreditCard::create([
1277
+ 'customerId' => $customer->id,
1278
+ 'cardholderName' => 'Cardholder',
1279
+ 'number' => CardTypeIndicators::ISSUING_BANK,
1280
+ 'expirationDate' => '05/12',
1281
+ 'options' => ['verifyCard' => true]
1282
+ ]);
1283
+ $this->assertEquals("NETWORK ONLY", $result->creditCard->issuingBank);
1284
+ }
1285
+
1286
+ public function testNegativeCardTypeIndicators()
1287
+ {
1288
+ $customer = Braintree\Customer::createNoValidate();
1289
+ $result = Braintree\CreditCard::create([
1290
+ 'customerId' => $customer->id,
1291
+ 'cardholderName' => 'Cardholder',
1292
+ 'number' => CardTypeIndicators::NO,
1293
+ 'expirationDate' => '05/12',
1294
+ 'options' => ['verifyCard' => true]
1295
+ ]);
1296
+ $this->assertEquals(Braintree\CreditCard::PREPAID_NO, $result->creditCard->prepaid);
1297
+ $this->assertEquals(Braintree\CreditCard::DURBIN_REGULATED_NO, $result->creditCard->durbinRegulated);
1298
+ $this->assertEquals(Braintree\CreditCard::PAYROLL_NO, $result->creditCard->payroll);
1299
+ $this->assertEquals(Braintree\CreditCard::DEBIT_NO, $result->creditCard->debit);
1300
+ $this->assertEquals(Braintree\CreditCard::HEALTHCARE_NO, $result->creditCard->healthcare);
1301
+ $this->assertEquals(Braintree\CreditCard::COMMERCIAL_NO, $result->creditCard->commercial);
1302
+ $this->assertEquals('MSB', $result->creditCard->productId);
1303
+ }
1304
+
1305
+ public function testUnknownCardTypeIndicators()
1306
+ {
1307
+ $customer = Braintree\Customer::createNoValidate();
1308
+ $result = Braintree\CreditCard::create([
1309
+ 'customerId' => $customer->id,
1310
+ 'cardholderName' => 'Cardholder',
1311
+ 'number' => CardTypeIndicators::UNKNOWN,
1312
+ 'expirationDate' => '05/12',
1313
+ 'options' => ['verifyCard' => true]
1314
+ ]);
1315
+ $this->assertEquals(Braintree\CreditCard::PREPAID_UNKNOWN, $result->creditCard->prepaid);
1316
+ $this->assertEquals(Braintree\CreditCard::DURBIN_REGULATED_UNKNOWN, $result->creditCard->durbinRegulated);
1317
+ $this->assertEquals(Braintree\CreditCard::PAYROLL_UNKNOWN, $result->creditCard->payroll);
1318
+ $this->assertEquals(Braintree\CreditCard::DEBIT_UNKNOWN, $result->creditCard->debit);
1319
+ $this->assertEquals(Braintree\CreditCard::HEALTHCARE_UNKNOWN, $result->creditCard->healthcare);
1320
+ $this->assertEquals(Braintree\CreditCard::COMMERCIAL_UNKNOWN, $result->creditCard->commercial);
1321
+ $this->assertEquals(Braintree\CreditCard::COUNTRY_OF_ISSUANCE_UNKNOWN, $result->creditCard->countryOfIssuance);
1322
+ $this->assertEquals(Braintree\CreditCard::ISSUING_BANK_UNKNOWN, $result->creditCard->issuingBank);
1323
+ $this->assertEquals(Braintree\CreditCard::PRODUCT_ID_UNKNOWN, $result->creditCard->productId);
1324
+ }
1325
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/CreditCardVerificationAdvancedSearchTest.php ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class CreditCardVerificationAdvancedSearchTest extends Setup
11
+ {
12
+ public function test_searchOnTextFields()
13
+ {
14
+ $searchCriteria = [
15
+ 'creditCardCardholderName' => 'Tim Toole',
16
+ 'creditCardExpirationDate' => '05/2010',
17
+ 'creditCardNumber' => Braintree\Test\CreditCardNumbers::$failsSandboxVerification['Visa'],
18
+ 'billingAddressDetailsPostalCode' => '90210',
19
+ ];
20
+ $result = Braintree\Customer::create([
21
+ 'creditCard' => [
22
+ 'cardholderName' => $searchCriteria['creditCardCardholderName'],
23
+ 'number' => $searchCriteria['creditCardNumber'],
24
+ 'expirationDate' => $searchCriteria['creditCardExpirationDate'],
25
+ 'billingAddress' => [
26
+ 'postalCode' => $searchCriteria['billingAddressDetailsPostalCode']
27
+ ],
28
+ 'options' => ['verifyCard' => true],
29
+ ],
30
+ ]);
31
+ $verification = $result->creditCardVerification;
32
+
33
+ $query = [Braintree\CreditCardVerificationSearch::id()->is($verification->id)];
34
+ foreach ($searchCriteria AS $criterion => $value) {
35
+ $query[] = Braintree\CreditCardVerificationSearch::$criterion()->is($value);
36
+ }
37
+
38
+ $collection = Braintree\CreditCardVerification::search($query);
39
+ $this->assertEquals(1, $collection->maximumCount());
40
+ $this->assertEquals($result->creditCardVerification->id, $collection->firstItem()->id);
41
+
42
+ foreach ($searchCriteria AS $criterion => $value) {
43
+ $collection = Braintree\CreditCardVerification::search([
44
+ Braintree\CreditCardVerificationSearch::$criterion()->is($value),
45
+ Braintree\CreditCardVerificationSearch::id()->is($result->creditCardVerification->id)
46
+ ]);
47
+ $this->assertEquals(1, $collection->maximumCount());
48
+ $this->assertEquals($result->creditCardVerification->id, $collection->firstItem()->id);
49
+
50
+ $collection = Braintree\CreditCardVerification::search([
51
+ Braintree\CreditCardVerificationSearch::$criterion()->is('invalid_attribute'),
52
+ Braintree\CreditCardVerificationSearch::id()->is($result->creditCardVerification->id)
53
+ ]);
54
+ $this->assertEquals(0, $collection->maximumCount());
55
+ }
56
+ }
57
+
58
+ public function test_searchOnSuccessfulCustomerAndPaymentFields()
59
+ {
60
+ $customerId = uniqid();
61
+ $searchCriteria = [
62
+ 'customerId' => $customerId,
63
+ 'customerEmail' => $customerId . 'sandworm@example.com',
64
+ 'paymentMethodToken' => $customerId . 'token',
65
+ ];
66
+ $result = Braintree\Customer::create([
67
+ 'id' => $customerId,
68
+ 'email' => $searchCriteria['customerEmail'],
69
+ 'creditCard' => [
70
+ 'token' => $searchCriteria['paymentMethodToken'],
71
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
72
+ 'expirationDate' => '05/2017',
73
+ 'options' => ['verifyCard' => true]
74
+ ]
75
+ ]);
76
+ $customer = $result->customer;
77
+
78
+ $query = [];
79
+ foreach ($searchCriteria AS $criterion => $value) {
80
+ $query[] = Braintree\CreditCardVerificationSearch::$criterion()->is($value);
81
+ }
82
+
83
+ $collection = Braintree\CreditCardVerification::search($query);
84
+ $this->assertEquals(1, $collection->maximumCount());
85
+
86
+ foreach ($searchCriteria AS $criterion => $value) {
87
+ $collection = Braintree\CreditCardVerification::search([
88
+ Braintree\CreditCardVerificationSearch::$criterion()->is($value),
89
+ ]);
90
+ $this->assertEquals(1, $collection->maximumCount());
91
+
92
+ $collection = Braintree\CreditCardVerification::search([
93
+ Braintree\CreditCardVerificationSearch::$criterion()->is('invalid_attribute'),
94
+ ]);
95
+ $this->assertEquals(0, $collection->maximumCount());
96
+ }
97
+ }
98
+
99
+ public function testGateway_searchEmpty()
100
+ {
101
+ $query = [];
102
+ $query[] = Braintree\CreditCardVerificationSearch::creditCardCardholderName()->is('Not Found');
103
+
104
+ $gateway = new Braintree\Gateway([
105
+ 'environment' => 'development',
106
+ 'merchantId' => 'integration_merchant_id',
107
+ 'publicKey' => 'integration_public_key',
108
+ 'privateKey' => 'integration_private_key'
109
+ ]);
110
+ $collection = $gateway->creditCardVerification()->search($query);
111
+
112
+ $this->assertEquals(0, $collection->maximumCount());
113
+ }
114
+
115
+ public function test_createdAt()
116
+ {
117
+ $result = Braintree\Customer::create([
118
+ 'creditCard' => [
119
+ 'cardholderName' => 'Joe Smith',
120
+ 'number' => '4000111111111115',
121
+ 'expirationDate' => '12/2016',
122
+ 'options' => ['verifyCard' => true],
123
+ ],
124
+ ]);
125
+
126
+ $verification = $result->creditCardVerification;
127
+
128
+ $past = clone $verification->createdAt;
129
+ $past->modify('-1 hour');
130
+ $future = clone $verification->createdAt;
131
+ $future->modify('+1 hour');
132
+
133
+ $collection = Braintree\CreditCardVerification::search([
134
+ Braintree\CreditCardVerificationSearch::id()->is($verification->id),
135
+ Braintree\CreditCardVerificationSearch::createdAt()->between($past, $future)
136
+ ]);
137
+ $this->assertEquals(1, $collection->maximumCount());
138
+ $this->assertEquals($verification->id, $collection->firstItem()->id);
139
+
140
+ $collection = Braintree\CreditCardVerification::search([
141
+ Braintree\CreditCardVerificationSearch::id()->is($verification->id),
142
+ Braintree\CreditCardVerificationSearch::createdAt()->lessThanOrEqualTo($future)
143
+ ]);
144
+ $this->assertEquals(1, $collection->maximumCount());
145
+ $this->assertEquals($verification->id, $collection->firstItem()->id);
146
+
147
+ $collection = Braintree\CreditCardVerification::search([
148
+ Braintree\CreditCardVerificationSearch::id()->is($verification->id),
149
+ Braintree\CreditCardVerificationSearch::createdAt()->greaterThanOrEqualTo($past)
150
+ ]);
151
+ $this->assertEquals(1, $collection->maximumCount());
152
+ $this->assertEquals($verification->id, $collection->firstItem()->id);
153
+ }
154
+
155
+ public function test_multipleValueNode_ids()
156
+ {
157
+ $result = Braintree\Customer::create([
158
+ 'creditCard' => [
159
+ 'cardholderName' => 'Joe Smith',
160
+ 'number' => '4000111111111115',
161
+ 'expirationDate' => '12/2016',
162
+ 'options' => ['verifyCard' => true],
163
+ ],
164
+ ]);
165
+
166
+ $creditCardVerification = $result->creditCardVerification;
167
+
168
+ $collection = Braintree\CreditCardVerification::search([
169
+ Braintree\CreditCardVerificationSearch::ids()->is($creditCardVerification->id)
170
+ ]);
171
+ $this->assertEquals(1, $collection->maximumCount());
172
+ $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
173
+
174
+ $collection = Braintree\CreditCardVerification::search([
175
+ Braintree\CreditCardVerificationSearch::ids()->in(
176
+ [$creditCardVerification->id,'1234']
177
+ )
178
+ ]);
179
+ $this->assertEquals(1, $collection->maximumCount());
180
+ $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
181
+
182
+ $collection = Braintree\CreditCardVerification::search([
183
+ Braintree\CreditCardVerificationSearch::ids()->is('1234')
184
+ ]);
185
+ $this->assertEquals(0, $collection->maximumCount());
186
+ }
187
+
188
+ public function test_multipleValueNode_creditCardType()
189
+ {
190
+ $result = Braintree\Customer::create([
191
+ 'creditCard' => [
192
+ 'cardholderName' => 'Joe Smith',
193
+ 'number' => '4000111111111115',
194
+ 'expirationDate' => '12/2016',
195
+ 'options' => ['verifyCard' => true],
196
+ ],
197
+ ]);
198
+
199
+ $creditCardVerification = $result->creditCardVerification;
200
+
201
+ $collection = Braintree\CreditCardVerification::search([
202
+ Braintree\CreditCardVerificationSearch::id()->is($creditCardVerification->id),
203
+ Braintree\CreditCardVerificationSearch::creditCardCardType()->is($creditCardVerification->creditCard['cardType'])
204
+ ]);
205
+ $this->assertEquals(1, $collection->maximumCount());
206
+ $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
207
+
208
+ $collection = Braintree\CreditCardVerification::search([
209
+ Braintree\CreditCardVerificationSearch::id()->is($creditCardVerification->id),
210
+ Braintree\CreditCardVerificationSearch::creditCardCardType()->in(
211
+ [$creditCardVerification->creditCard['cardType'], Braintree\CreditCard::CHINA_UNION_PAY]
212
+ )
213
+ ]);
214
+ $this->assertEquals(1, $collection->maximumCount());
215
+ $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
216
+
217
+ $collection = Braintree\CreditCardVerification::search([
218
+ Braintree\CreditCardVerificationSearch::id()->is($creditCardVerification->id),
219
+ Braintree\CreditCardVerificationSearch::creditCardCardType()->is(Braintree\CreditCard::CHINA_UNION_PAY)
220
+ ]);
221
+ $this->assertEquals(0, $collection->maximumCount());
222
+ }
223
+
224
+ public function test_multipleValueNode_status()
225
+ {
226
+ $result = Braintree\Customer::create([
227
+ 'creditCard' => [
228
+ 'cardholderName' => 'Joe Smith',
229
+ 'number' => '4000111111111115',
230
+ 'expirationDate' => '12/2016',
231
+ 'options' => ['verifyCard' => true],
232
+ ],
233
+ ]);
234
+
235
+ $creditCardVerification = $result->creditCardVerification;
236
+
237
+ $collection = Braintree\CreditCardVerification::search([
238
+ Braintree\CreditCardVerificationSearch::id()->is($creditCardVerification->id),
239
+ Braintree\CreditCardVerificationSearch::status()->is($creditCardVerification->status)
240
+ ]);
241
+ $this->assertEquals(1, $collection->maximumCount());
242
+ $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
243
+
244
+ $collection = Braintree\CreditCardVerification::search([
245
+ Braintree\CreditCardVerificationSearch::id()->is($creditCardVerification->id),
246
+ Braintree\CreditCardVerificationSearch::status()->in(
247
+ [$creditCardVerification->status, Braintree\Result\CreditCardVerification::VERIFIED]
248
+ )
249
+ ]);
250
+ $this->assertEquals(1, $collection->maximumCount());
251
+ $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
252
+
253
+ $collection = Braintree\CreditCardVerification::search([
254
+ Braintree\CreditCardVerificationSearch::id()->is($creditCardVerification->id),
255
+ Braintree\CreditCardVerificationSearch::status()->is(Braintree\Result\CreditCardVerification::VERIFIED)
256
+ ]);
257
+ $this->assertEquals(0, $collection->maximumCount());
258
+ }
259
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/CreditCardVerificationTest.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class CreditCardVerificationTest extends Setup
11
+ {
12
+ public function test_createWithSuccessfulResponse()
13
+ {
14
+ $result = Braintree\CreditCardVerification::create([
15
+ 'creditCard' => [
16
+ 'number' => '4111111111111111',
17
+ 'expirationDate' => '05/2011',
18
+ ],
19
+ ]);
20
+ $this->assertTrue($result->success);
21
+ }
22
+
23
+ public function test_createWithUnsuccessfulResponse()
24
+ {
25
+ $result = Braintree\CreditCardVerification::create([
26
+ 'creditCard' => [
27
+ 'number' => Braintree\Test\CreditCardNumbers::$failsSandboxVerification['Visa'],
28
+ 'expirationDate' => '05/2011',
29
+ ],
30
+ ]);
31
+ $this->assertFalse($result->success);
32
+ $this->assertEquals($result->verification->status, Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED);
33
+
34
+ $verification = $result->verification;
35
+
36
+ $this->assertEquals($verification->processorResponseCode, '2000');
37
+ $this->assertEquals($verification->processorResponseText, 'Do Not Honor');
38
+ }
39
+
40
+ public function test_createWithInvalidRequest()
41
+ {
42
+ $result = Braintree\CreditCardVerification::create([
43
+ 'creditCard' => [
44
+ 'number' => Braintree\Test\CreditCardNumbers::$failsSandboxVerification['Visa'],
45
+ 'expirationDate' => '05/2011',
46
+ ],
47
+ 'options' => [
48
+ 'amount' => '-5.00'
49
+ ],
50
+ ]);
51
+ $this->assertFalse($result->success);
52
+
53
+ $amountErrors = $result->errors->forKey('verification')->forKey('options')->onAttribute('amount');
54
+ $this->assertEquals(Braintree\Error\Codes::VERIFICATION_OPTIONS_AMOUNT_CANNOT_BE_NEGATIVE, $amountErrors[0]->code);
55
+ }
56
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/CustomerAdvancedSearchTest.php ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Braintree;
8
+
9
+ class CustomerAdvancedSearchTest extends Setup
10
+ {
11
+ public function test_noMatches()
12
+ {
13
+ $collection = Braintree\Customer::search([
14
+ Braintree\CustomerSearch::company()->is('badname')
15
+ ]);
16
+
17
+ $this->assertEquals(0, $collection->maximumCount());
18
+ }
19
+
20
+ public function test_noRequestsWhenIterating()
21
+ {
22
+ $resultsReturned = false;
23
+ $collection = Braintree\Customer::search([
24
+ Braintree\CustomerSearch::firstName()->is('badname')
25
+ ]);
26
+
27
+ foreach($collection as $customer) {
28
+ $resultsReturned = true;
29
+ break;
30
+ }
31
+
32
+ $this->assertSame(0, $collection->maximumCount());
33
+ $this->assertEquals(false, $resultsReturned);
34
+ }
35
+
36
+ public function test_findDuplicateCardsGivenPaymentMethodToken()
37
+ {
38
+ $creditCardRequest = ['number' => '63049580000009', 'expirationDate' => '05/2012'];
39
+
40
+ $jim = Braintree\Customer::create(['firstName' => 'Jim', 'creditCard' => $creditCardRequest])->customer;
41
+ $joe = Braintree\Customer::create(['firstName' => 'Joe', 'creditCard' => $creditCardRequest])->customer;
42
+
43
+ $query = [Braintree\CustomerSearch::paymentMethodTokenWithDuplicates()->is($jim->creditCards[0]->token)];
44
+ $collection = Braintree\Customer::search($query);
45
+
46
+ $customerIds = [];
47
+ foreach($collection as $customer)
48
+ {
49
+ $customerIds[] = $customer->id;
50
+ }
51
+
52
+ $this->assertTrue(in_array($jim->id, $customerIds));
53
+ $this->assertTrue(in_array($joe->id, $customerIds));
54
+ }
55
+
56
+ public function test_searchOnTextFields()
57
+ {
58
+ $token = 'cctoken' . rand();
59
+
60
+ $search_criteria = [
61
+ 'firstName' => 'Timmy',
62
+ 'lastName' => 'OToole',
63
+ 'company' => 'OToole and Son(s)' . rand(),
64
+ 'email' => 'timmy@example.com',
65
+ 'website' => 'http://example.com',
66
+ 'phone' => '3145551234',
67
+ 'fax' => '3145551235',
68
+ 'cardholderName' => 'Tim Toole',
69
+ 'creditCardExpirationDate' => '05/2010',
70
+ 'creditCardNumber' => '4111111111111111',
71
+ 'paymentMethodToken' => $token,
72
+ 'addressFirstName' => 'Thomas',
73
+ 'addressLastName' => 'Otool',
74
+ 'addressStreetAddress' => '1 E Main St',
75
+ 'addressExtendedAddress' => 'Suite 3',
76
+ 'addressLocality' => 'Chicago',
77
+ 'addressRegion' => 'Illinois',
78
+ 'addressPostalCode' => '60622',
79
+ 'addressCountryName' => 'United States of America'
80
+ ];
81
+
82
+ $customer = Braintree\Customer::createNoValidate([
83
+ 'firstName' => $search_criteria['firstName'],
84
+ 'lastName' => $search_criteria['lastName'],
85
+ 'company' => $search_criteria['company'],
86
+ 'email' => $search_criteria['email'],
87
+ 'fax' => $search_criteria['fax'],
88
+ 'phone' => $search_criteria['phone'],
89
+ 'website' => $search_criteria['website'],
90
+ 'creditCard' => [
91
+ 'cardholderName' => 'Tim Toole',
92
+ 'number' => '4111111111111111',
93
+ 'expirationDate' => $search_criteria['creditCardExpirationDate'],
94
+ 'token' => $token,
95
+ 'billingAddress' => [
96
+ 'firstName' => $search_criteria['addressFirstName'],
97
+ 'lastName' => $search_criteria['addressLastName'],
98
+ 'streetAddress' => $search_criteria['addressStreetAddress'],
99
+ 'extendedAddress' => $search_criteria['addressExtendedAddress'],
100
+ 'locality' => $search_criteria['addressLocality'],
101
+ 'region' => $search_criteria['addressRegion'],
102
+ 'postalCode' => $search_criteria['addressPostalCode'],
103
+ 'countryName' => 'United States of America'
104
+ ]
105
+ ]
106
+ ]);
107
+
108
+ $query = [Braintree\CustomerSearch::id()->is($customer->id)];
109
+ foreach ($search_criteria AS $criterion => $value) {
110
+ $query[] = Braintree\CustomerSearch::$criterion()->is($value);
111
+ }
112
+
113
+ $collection = Braintree\Customer::search($query);
114
+
115
+ $this->assertEquals(1, $collection->maximumCount());
116
+ $this->assertEquals($customer->id, $collection->firstItem()->id);
117
+
118
+ foreach ($search_criteria AS $criterion => $value) {
119
+ $collection = Braintree\Customer::search([
120
+ Braintree\CustomerSearch::$criterion()->is($value),
121
+ Braintree\CustomerSearch::id()->is($customer->id),
122
+ ]);
123
+ $this->assertEquals(1, $collection->maximumCount());
124
+ $this->assertEquals($customer->id, $collection->firstItem()->id);
125
+
126
+ $collection = Braintree\Customer::search([
127
+ Braintree\CustomerSearch::$criterion()->is('invalid_attribute'),
128
+ Braintree\CustomerSearch::id()->is($customer->id),
129
+ ]);
130
+ $this->assertEquals(0, $collection->maximumCount());
131
+ }
132
+ }
133
+
134
+ public function test_createdAt()
135
+ {
136
+ $customer = Braintree\Customer::createNoValidate();
137
+
138
+ $past = clone $customer->createdAt;
139
+ $past->modify("-1 hour");
140
+ $future = clone $customer->createdAt;
141
+ $future->modify("+1 hour");
142
+
143
+ $collection = Braintree\Customer::search([
144
+ Braintree\CustomerSearch::id()->is($customer->id),
145
+ Braintree\CustomerSearch::createdAt()->between($past, $future),
146
+ ]);
147
+ $this->assertEquals(1, $collection->maximumCount());
148
+ $this->assertEquals($customer->id, $collection->firstItem()->id);
149
+
150
+ $collection = Braintree\Customer::search([
151
+ Braintree\CustomerSearch::id()->is($customer->id),
152
+ Braintree\CustomerSearch::createdAt()->lessThanOrEqualTo($future),
153
+ ]);
154
+ $this->assertEquals(1, $collection->maximumCount());
155
+ $this->assertEquals($customer->id, $collection->firstItem()->id);
156
+
157
+ $collection = Braintree\Customer::search([
158
+ Braintree\CustomerSearch::id()->is($customer->id),
159
+ Braintree\CustomerSearch::createdAt()->greaterThanOrEqualTo($past),
160
+ ]);
161
+ $this->assertEquals(1, $collection->maximumCount());
162
+ $this->assertEquals($customer->id, $collection->firstItem()->id);
163
+ }
164
+
165
+ public function test_paypalAccountEmail()
166
+ {
167
+ $http = new HttpClientApi(Braintree\Configuration::$global);
168
+ $nonce = $http->nonceForPayPalAccount([
169
+ 'paypal_account' => [
170
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
171
+ ]
172
+ ]);
173
+
174
+ $customerId = 'UNIQUE_CUSTOMER_ID-' . strval(rand());
175
+ $customerResult = Braintree\Customer::create([
176
+ 'paymentMethodNonce' => $nonce,
177
+ 'id' => $customerId
178
+ ]);
179
+
180
+ $this->assertTrue($customerResult->success);
181
+
182
+ $customer = $customerResult->customer;
183
+
184
+ $collection = Braintree\Customer::search([
185
+ Braintree\CustomerSearch::id()->is($customer->id),
186
+ Braintree\CustomerSearch::paypalAccountEmail()->is('jane.doe@example.com')
187
+ ]);
188
+ $this->assertEquals(1, $collection->maximumCount());
189
+ $this->assertEquals($customer->id, $collection->firstItem()->id);
190
+ }
191
+
192
+ public function test_throwsIfNoOperatorNodeGiven()
193
+ {
194
+ $this->setExpectedException('InvalidArgumentException', 'Operator must be provided');
195
+ Braintree\Customer::search([
196
+ Braintree\CustomerSearch::creditCardExpirationDate()
197
+ ]);
198
+ }
199
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/CustomerTest.php ADDED
@@ -0,0 +1,1592 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class CustomerTest extends Setup
11
+ {
12
+ public function testAll_smokeTest()
13
+ {
14
+ $all = Braintree\Customer::all();
15
+ $this->assertTrue($all->maximumCount() > 0);
16
+ }
17
+
18
+ public function testAllWithManyResults()
19
+ {
20
+ $collection = Braintree\Customer::all();
21
+ $this->assertTrue($collection->maximumCount() > 1);
22
+ $customer = $collection->firstItem();
23
+
24
+ $this->assertTrue(strlen($customer->id) > 0);
25
+ $this->assertTrue($customer instanceof Braintree\Customer);
26
+ }
27
+
28
+ public function testCreate()
29
+ {
30
+ $result = Braintree\Customer::create([
31
+ 'firstName' => 'Mike',
32
+ 'lastName' => 'Jones',
33
+ 'company' => 'Jones Co.',
34
+ 'email' => 'mike.jones@example.com',
35
+ 'phone' => '419.555.1234',
36
+ 'fax' => '419.555.1235',
37
+ 'website' => 'http://example.com'
38
+ ]);
39
+ $this->assertEquals(true, $result->success);
40
+ $customer = $result->customer;
41
+ $this->assertEquals('Mike', $customer->firstName);
42
+ $this->assertEquals('Jones', $customer->lastName);
43
+ $this->assertEquals('Jones Co.', $customer->company);
44
+ $this->assertEquals('mike.jones@example.com', $customer->email);
45
+ $this->assertEquals('419.555.1234', $customer->phone);
46
+ $this->assertEquals('419.555.1235', $customer->fax);
47
+ $this->assertEquals('http://example.com', $customer->website);
48
+ $this->assertNotNull($customer->merchantId);
49
+ }
50
+
51
+ public function testCreateWithIdOfZero()
52
+ {
53
+ $result = Braintree\Customer::create([
54
+ 'id' => '0'
55
+ ]);
56
+
57
+ $this->assertEquals(true, $result->success);
58
+ $this->assertEquals($result->customer->id, '0');
59
+ $customer = Braintree\Customer::find('0');
60
+
61
+ $this->assertEquals('0', $customer->id);
62
+
63
+ Braintree\Customer::delete('0');
64
+ }
65
+
66
+ public function testGatewayCreate()
67
+ {
68
+ $gateway = new Braintree\Gateway([
69
+ 'environment' => 'development',
70
+ 'merchantId' => 'integration_merchant_id',
71
+ 'publicKey' => 'integration_public_key',
72
+ 'privateKey' => 'integration_private_key'
73
+ ]);
74
+ $result = $gateway->customer()->create([
75
+ 'firstName' => 'Mike',
76
+ 'lastName' => 'Jones',
77
+ ]);
78
+ $this->assertEquals(true, $result->success);
79
+ $customer = $result->customer;
80
+ $this->assertEquals('Mike', $customer->firstName);
81
+ $this->assertEquals('Jones', $customer->lastName);
82
+ $this->assertNotNull($customer->merchantId);
83
+ }
84
+
85
+ public function testCreateWithAccessToken()
86
+ {
87
+ $credentials = Test\Braintree\OAuthTestHelper::createCredentials([
88
+ 'clientId' => 'client_id$development$integration_client_id',
89
+ 'clientSecret' => 'client_secret$development$integration_client_secret',
90
+ 'merchantId' => 'integration_merchant_id',
91
+ ]);
92
+
93
+ $gateway = new Braintree\Gateway([
94
+ 'accessToken' => $credentials->accessToken,
95
+ ]);
96
+
97
+ $result = $gateway->customer()->create([
98
+ 'firstName' => 'Mike',
99
+ 'lastName' => 'Jones',
100
+ ]);
101
+ $this->assertEquals(true, $result->success);
102
+ $customer = $result->customer;
103
+ $this->assertEquals('Mike', $customer->firstName);
104
+ $this->assertEquals('Jones', $customer->lastName);
105
+ $this->assertNotNull($customer->merchantId);
106
+ }
107
+
108
+ public function testCreateCustomerWithCardUsingNonce()
109
+ {
110
+ $http = new HttpClientApi(Braintree\Configuration::$global);
111
+ $nonce = $http->nonce_for_new_card([
112
+ "creditCard" => [
113
+ "number" => "4111111111111111",
114
+ "expirationMonth" => "11",
115
+ "expirationYear" => "2099"
116
+ ],
117
+ "share" => true
118
+ ]);
119
+
120
+ $result = Braintree\Customer::create([
121
+ 'creditCard' => [
122
+ 'paymentMethodNonce' => $nonce
123
+ ]
124
+ ]);
125
+
126
+ $this->assertTrue($result->success);
127
+ $this->assertSame("411111", $result->customer->creditCards[0]->bin);
128
+ $this->assertSame("1111", $result->customer->creditCards[0]->last4);
129
+ }
130
+
131
+ public function testCreateCustomerWithApplePayCard()
132
+ {
133
+ $nonce = Braintree\Test\Nonces::$applePayVisa;
134
+ $result = Braintree\Customer::create([
135
+ 'paymentMethodNonce' => $nonce
136
+ ]);
137
+ $this->assertTrue($result->success);
138
+ $customer = $result->customer;
139
+ $this->assertNotNull($customer->applePayCards[0]);
140
+ $this->assertNotNull($customer->paymentMethods[0]);
141
+ }
142
+
143
+ public function testCreateCustomerWithAndroidPayProxyCard()
144
+ {
145
+ $nonce = Braintree\Test\Nonces::$androidPayDiscover;
146
+ $result = Braintree\Customer::create([
147
+ 'paymentMethodNonce' => $nonce
148
+ ]);
149
+ $this->assertTrue($result->success);
150
+ $customer = $result->customer;
151
+ $this->assertNotNull($customer->androidPayCards[0]);
152
+ $this->assertNotNull($customer->paymentMethods[0]);
153
+ $androidPayCard = $customer->androidPayCards[0];
154
+ $this->assertTrue($androidPayCard instanceof Braintree\AndroidPayCard);
155
+ $this->assertNotNull($androidPayCard->token);
156
+ $this->assertNotNull($androidPayCard->expirationYear);
157
+ }
158
+
159
+ public function testCreateCustomerWithAndroidPayNetworkToken()
160
+ {
161
+ $nonce = Braintree\Test\Nonces::$androidPayMasterCard;
162
+ $result = Braintree\Customer::create([
163
+ 'paymentMethodNonce' => $nonce
164
+ ]);
165
+ $this->assertTrue($result->success);
166
+ $customer = $result->customer;
167
+ $this->assertNotNull($customer->androidPayCards[0]);
168
+ $this->assertNotNull($customer->paymentMethods[0]);
169
+ $androidPayCard = $customer->androidPayCards[0];
170
+ $this->assertTrue($androidPayCard instanceof Braintree\AndroidPayCard);
171
+ $this->assertNotNull($androidPayCard->token);
172
+ $this->assertNotNull($androidPayCard->expirationYear);
173
+ }
174
+
175
+ public function testCreateCustomerWithAmexExpressCheckoutCard()
176
+ {
177
+ $nonce = Braintree\Test\Nonces::$amexExpressCheckout;
178
+ $result = Braintree\Customer::create([
179
+ 'paymentMethodNonce' => $nonce
180
+ ]);
181
+ $this->assertTrue($result->success);
182
+ $customer = $result->customer;
183
+ $this->assertNotNull($customer->amexExpressCheckoutCards[0]);
184
+ $this->assertNotNull($customer->paymentMethods[0]);
185
+ $amexExpressCheckoutCard = $customer->amexExpressCheckoutCards[0];
186
+ $this->assertTrue($amexExpressCheckoutCard instanceof Braintree\AmexExpressCheckoutCard);
187
+ $this->assertNotNull($amexExpressCheckoutCard->token);
188
+ $this->assertNotNull($amexExpressCheckoutCard->expirationYear);
189
+ }
190
+
191
+ public function testCreateCustomerWithVenmoAccount()
192
+ {
193
+ $nonce = Braintree\Test\Nonces::$venmoAccount;
194
+ $result = Braintree\Customer::create(array(
195
+ 'paymentMethodNonce' => $nonce
196
+ ));
197
+ $this->assertTrue($result->success);
198
+ $customer = $result->customer;
199
+ $this->assertNotNull($customer->venmoAccounts[0]);
200
+ $this->assertNotNull($customer->paymentMethods[0]);
201
+ $venmoAccount = $customer->venmoAccounts[0];
202
+ $this->assertTrue($venmoAccount instanceof Braintree\VenmoAccount);
203
+ $this->assertNotNull($venmoAccount->token);
204
+ $this->assertNotNull($venmoAccount->username);
205
+ $this->assertNotNull($venmoAccount->venmoUserId);
206
+ }
207
+
208
+ public function testCreateCustomerWithCoinbase()
209
+ {
210
+ $nonce = Braintree\Test\Nonces::$coinbase;
211
+ $result = Braintree\Customer::create([
212
+ 'paymentMethodNonce' => $nonce
213
+ ]);
214
+ $this->assertTrue($result->success);
215
+ $customer = $result->customer;
216
+ $this->assertNotNull($customer->coinbaseAccounts[0]);
217
+ $this->assertNotNull($customer->coinbaseAccounts[0]->userId);
218
+ $this->assertNotNull($customer->coinbaseAccounts[0]->userName);
219
+ $this->assertNotNull($customer->coinbaseAccounts[0]->userEmail);
220
+ $this->assertNotNull($customer->paymentMethods[0]);
221
+ }
222
+
223
+ public function testCreateCustomerWithUsBankAccount()
224
+ {
225
+ $nonce = Test\Helper::generateValidUsBankAccountNonce();
226
+ $result = Braintree\Customer::create(array(
227
+ 'paymentMethodNonce' => $nonce
228
+ ));
229
+ $this->assertTrue($result->success);
230
+ $customer = $result->customer;
231
+ $this->assertNotNull($customer->usBankAccounts[0]);
232
+ $this->assertNotNull($customer->paymentMethods[0]);
233
+ $usBankAccount = $customer->usBankAccounts[0];
234
+ $this->assertTrue($usBankAccount instanceof Braintree\UsBankAccount);
235
+ $this->assertNotNull($usBankAccount->token);
236
+ $this->assertEquals('Dan Schulman', $usBankAccount->accountHolderName);
237
+ $this->assertEquals('021000021', $usBankAccount->routingNumber);
238
+ $this->assertEquals('1234', $usBankAccount->last4);
239
+ $this->assertEquals('checking', $usBankAccount->accountType);
240
+ $this->assertRegexp('/CHASE/', $usBankAccount->bankName);
241
+ }
242
+
243
+ public function testCreate_withUnicode()
244
+ {
245
+ $result = Braintree\Customer::create([
246
+ 'firstName' => "Здравствуйте",
247
+ 'lastName' => 'Jones',
248
+ 'company' => 'Jones Co.',
249
+ 'email' => 'mike.jones@example.com',
250
+ 'phone' => '419.555.1234',
251
+ 'fax' => '419.555.1235',
252
+ 'website' => 'http://example.com'
253
+ ]);
254
+ $this->assertEquals(true, $result->success);
255
+ $customer = $result->customer;
256
+ $this->assertEquals("Здравствуйте", $customer->firstName);
257
+ $this->assertEquals('Jones', $customer->lastName);
258
+ $this->assertEquals('Jones Co.', $customer->company);
259
+ $this->assertEquals('mike.jones@example.com', $customer->email);
260
+ $this->assertEquals('419.555.1234', $customer->phone);
261
+ $this->assertEquals('419.555.1235', $customer->fax);
262
+ $this->assertEquals('http://example.com', $customer->website);
263
+ $this->assertNotNull($customer->merchantId);
264
+ }
265
+
266
+ public function testCreate_withCountry()
267
+ {
268
+ $result = Braintree\Customer::create([
269
+ 'firstName' => 'Bat',
270
+ 'lastName' => 'Manderson',
271
+ 'creditCard' => [
272
+ 'number' => '5105105105105100',
273
+ 'expirationDate' => '05/12',
274
+ 'billingAddress' => [
275
+ 'countryName' => 'Gabon',
276
+ 'countryCodeAlpha2' => 'GA',
277
+ 'countryCodeAlpha3' => 'GAB',
278
+ 'countryCodeNumeric' => '266'
279
+ ]
280
+ ]
281
+ ]);
282
+ $this->assertEquals(true, $result->success);
283
+ $customer = $result->customer;
284
+ $this->assertEquals('Gabon', $customer->creditCards[0]->billingAddress->countryName);
285
+ $this->assertEquals('GA', $customer->creditCards[0]->billingAddress->countryCodeAlpha2);
286
+ $this->assertEquals('GAB', $customer->creditCards[0]->billingAddress->countryCodeAlpha3);
287
+ $this->assertEquals('266', $customer->creditCards[0]->billingAddress->countryCodeNumeric);
288
+ $this->assertEquals(1, preg_match('/\A\w{32}\z/', $customer->creditCards[0]->uniqueNumberIdentifier));
289
+ }
290
+
291
+ public function testCreate_withVenmoSdkSession()
292
+ {
293
+ $result = Braintree\Customer::create([
294
+ 'firstName' => 'Bat',
295
+ 'lastName' => 'Manderson',
296
+ 'creditCard' => [
297
+ 'number' => '5105105105105100',
298
+ 'expirationDate' => '05/12',
299
+ 'options' => [
300
+ 'venmoSdkSession' => Braintree\Test\VenmoSdk::getTestSession()
301
+ ]
302
+ ]
303
+ ]);
304
+ $this->assertEquals(true, $result->success);
305
+ $customer = $result->customer;
306
+ $this->assertEquals(true, $customer->creditCards[0]->venmoSdk);
307
+ }
308
+
309
+ public function testCreate_withVenmoSdkPaymentMethodCode()
310
+ {
311
+ $result = Braintree\Customer::create([
312
+ 'firstName' => 'Bat',
313
+ 'lastName' => 'Manderson',
314
+ 'creditCard' => [
315
+ 'venmoSdkPaymentMethodCode' => Braintree\Test\VenmoSdk::$visaPaymentMethodCode
316
+ ],
317
+ ]);
318
+ $this->assertEquals(true, $result->success);
319
+ $customer = $result->customer;
320
+ $this->assertEquals("411111", $customer->creditCards[0]->bin);
321
+ }
322
+
323
+ public function testCreate_blankCustomer()
324
+ {
325
+ $result = Braintree\Customer::create();
326
+ $this->assertEquals(true, $result->success);
327
+ $this->assertNotNull($result->customer->id);
328
+
329
+ $result = Braintree\Customer::create([]);
330
+ $this->assertEquals(true, $result->success);
331
+ $this->assertNotNull($result->customer->id);
332
+ }
333
+
334
+ public function testCreate_withSpecialChars()
335
+ {
336
+ $result = Braintree\Customer::create(['firstName' => '<>&"\'']);
337
+ $this->assertEquals(true, $result->success);
338
+ $this->assertEquals('<>&"\'', $result->customer->firstName);
339
+ }
340
+
341
+ public function testCreate_withCustomFields()
342
+ {
343
+ $result = Braintree\Customer::create([
344
+ 'firstName' => 'Mike',
345
+ 'customFields' => [
346
+ 'store_me' => 'some custom value'
347
+ ]
348
+ ]);
349
+ $this->assertEquals(true, $result->success);
350
+ $customFields = $result->customer->customFields;
351
+ $this->assertEquals('some custom value', $customFields['store_me']);
352
+ }
353
+
354
+ public function testCreate_withFraudParams()
355
+ {
356
+ $result = Braintree\Customer::create([
357
+ 'firstName' => 'Mike',
358
+ 'creditCard' => [
359
+ 'number' => '5105105105105100',
360
+ 'expirationDate' => '05/12',
361
+ 'cvv' => '123',
362
+ 'cardholderName' => 'Mike Jones',
363
+ 'deviceSessionId' => 'abc123',
364
+ 'fraudMerchantId' => '456'
365
+ ]
366
+ ]);
367
+ $this->assertEquals(true, $result->success);
368
+ }
369
+
370
+ public function testCreate_withRiskData()
371
+ {
372
+ $result = Braintree\Customer::create([
373
+ 'firstName' => 'Mike',
374
+ 'creditCard' => [
375
+ 'number' => '5105105105105100',
376
+ 'expirationDate' => '05/12',
377
+ 'cvv' => '123',
378
+ 'cardholderName' => 'Mike Jones',
379
+ ],
380
+ 'riskData' => [
381
+ 'customer_browser' => 'IE5',
382
+ 'customer_ip' => '192.168.0.1'
383
+ ]
384
+ ]);
385
+ $this->assertEquals(true, $result->success);
386
+ }
387
+
388
+ public function testCreate_withCreditCard()
389
+ {
390
+ $result = Braintree\Customer::create([
391
+ 'firstName' => 'Mike',
392
+ 'lastName' => 'Jones',
393
+ 'company' => 'Jones Co.',
394
+ 'email' => 'mike.jones@example.com',
395
+ 'phone' => '419.555.1234',
396
+ 'fax' => '419.555.1235',
397
+ 'website' => 'http://example.com',
398
+ 'creditCard' => [
399
+ 'number' => '5105105105105100',
400
+ 'expirationDate' => '05/12',
401
+ 'cvv' => '123',
402
+ 'cardholderName' => 'Mike Jones'
403
+ ]
404
+ ]);
405
+ $this->assertEquals(true, $result->success);
406
+ $customer = $result->customer;
407
+ $this->assertEquals('Mike', $customer->firstName);
408
+ $this->assertEquals('Jones', $customer->lastName);
409
+ $this->assertEquals('Jones Co.', $customer->company);
410
+ $this->assertEquals('mike.jones@example.com', $customer->email);
411
+ $this->assertEquals('419.555.1234', $customer->phone);
412
+ $this->assertEquals('419.555.1235', $customer->fax);
413
+ $this->assertEquals('http://example.com', $customer->website);
414
+ $creditCard = $customer->creditCards[0];
415
+ $this->assertEquals('510510', $creditCard->bin);
416
+ $this->assertEquals('5100', $creditCard->last4);
417
+ $this->assertEquals('Mike Jones', $creditCard->cardholderName);
418
+ $this->assertEquals('05/2012', $creditCard->expirationDate);
419
+ $this->assertEquals('05', $creditCard->expirationMonth);
420
+ $this->assertEquals('2012', $creditCard->expirationYear);
421
+ }
422
+
423
+ public function testCreate_withDuplicateCardCheck()
424
+ {
425
+ $customer = Braintree\Customer::createNoValidate();
426
+
427
+ $attributes = [
428
+ 'firstName' => 'Mike',
429
+ 'lastName' => 'Jones',
430
+ 'company' => 'Jones Co.',
431
+ 'email' => 'mike.jones@example.com',
432
+ 'phone' => '419.555.1234',
433
+ 'fax' => '419.555.1235',
434
+ 'website' => 'http://example.com',
435
+ 'creditCard' => [
436
+ 'number' => '5105105105105100',
437
+ 'expirationDate' => '05/12',
438
+ 'cvv' => '123',
439
+ 'cardholderName' => 'Mike Jones',
440
+ 'options' => [
441
+ 'failOnDuplicatePaymentMethod' => true
442
+ ]
443
+ ]
444
+ ];
445
+ Braintree\Customer::create($attributes);
446
+ $result = Braintree\Customer::create($attributes);
447
+
448
+ $this->assertFalse($result->success);
449
+ $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('number');
450
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_DUPLICATE_CARD_EXISTS, $errors[0]->code);
451
+ $this->assertEquals(1, preg_match('/Duplicate card exists in the vault\./', $result->message));
452
+ }
453
+
454
+ public function testCreate_withCreditCardAndSpecificVerificationMerchantAccount()
455
+ {
456
+ $result = Braintree\Customer::create([
457
+ 'firstName' => 'Mike',
458
+ 'lastName' => 'Jones',
459
+ 'company' => 'Jones Co.',
460
+ 'email' => 'mike.jones@example.com',
461
+ 'phone' => '419.555.1234',
462
+ 'fax' => '419.555.1235',
463
+ 'website' => 'http://example.com',
464
+ 'creditCard' => [
465
+ 'number' => '5105105105105100',
466
+ 'expirationDate' => '05/12',
467
+ 'cvv' => '123',
468
+ 'cardholderName' => 'Mike Jones',
469
+ 'options' => [
470
+ 'verificationMerchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(),
471
+ 'verifyCard' => true
472
+ ]
473
+ ]
474
+ ]);
475
+ Test\Helper::assertPrintable($result);
476
+ $this->assertFalse($result->success);
477
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
478
+ $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
479
+ $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
480
+ $this->assertEquals('M', $result->creditCardVerification->cvvResponseCode);
481
+ $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
482
+ $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
483
+ $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
484
+ }
485
+
486
+ public function testCreate_withCreditCardAndVerificationAmount()
487
+ {
488
+ $result = Braintree\Customer::create([
489
+ 'firstName' => 'Mike',
490
+ 'lastName' => 'Jones',
491
+ 'company' => 'Jones Co.',
492
+ 'email' => 'mike.jones@example.com',
493
+ 'phone' => '419.555.1234',
494
+ 'fax' => '419.555.1235',
495
+ 'website' => 'http://example.com',
496
+ 'creditCard' => [
497
+ 'number' => '5555555555554444',
498
+ 'expirationDate' => '05/12',
499
+ 'cvv' => '123',
500
+ 'cardholderName' => 'Mike Jones',
501
+ 'options' => [
502
+ 'verifyCard' => true,
503
+ 'verificationAmount' => '2.00'
504
+ ]
505
+ ]
506
+ ]);
507
+
508
+ $this->assertTrue($result->success);
509
+ }
510
+
511
+ public function testCreate_withCreditCardAndBillingAddress()
512
+ {
513
+ $result = Braintree\Customer::create([
514
+ 'firstName' => 'Mike',
515
+ 'lastName' => 'Jones',
516
+ 'company' => 'Jones Co.',
517
+ 'email' => 'mike.jones@example.com',
518
+ 'phone' => '419.555.1234',
519
+ 'fax' => '419.555.1235',
520
+ 'website' => 'http://example.com',
521
+ 'creditCard' => [
522
+ 'number' => '5105105105105100',
523
+ 'expirationDate' => '05/12',
524
+ 'cvv' => '123',
525
+ 'cardholderName' => 'Mike Jones',
526
+ 'billingAddress' => [
527
+ 'firstName' => 'Drew',
528
+ 'lastName' => 'Smith',
529
+ 'company' => 'Smith Co.',
530
+ 'streetAddress' => '1 E Main St',
531
+ 'extendedAddress' => 'Suite 101',
532
+ 'locality' => 'Chicago',
533
+ 'region' => 'IL',
534
+ 'postalCode' => '60622',
535
+ 'countryName' => 'United States of America'
536
+ ]
537
+ ]
538
+ ]);
539
+ Test\Helper::assertPrintable($result);
540
+ $this->assertEquals(true, $result->success);
541
+ $customer = $result->customer;
542
+ $this->assertEquals('Mike', $customer->firstName);
543
+ $this->assertEquals('Jones', $customer->lastName);
544
+ $this->assertEquals('Jones Co.', $customer->company);
545
+ $this->assertEquals('mike.jones@example.com', $customer->email);
546
+ $this->assertEquals('419.555.1234', $customer->phone);
547
+ $this->assertEquals('419.555.1235', $customer->fax);
548
+ $this->assertEquals('http://example.com', $customer->website);
549
+ $creditCard = $customer->creditCards[0];
550
+ $this->assertEquals('510510', $creditCard->bin);
551
+ $this->assertEquals('5100', $creditCard->last4);
552
+ $this->assertEquals('Mike Jones', $creditCard->cardholderName);
553
+ $this->assertEquals('05/2012', $creditCard->expirationDate);
554
+ $this->assertEquals('05', $creditCard->expirationMonth);
555
+ $this->assertEquals('2012', $creditCard->expirationYear);
556
+ $address = $customer->addresses[0];
557
+ $this->assertEquals($address, $creditCard->billingAddress);
558
+ $this->assertEquals('Drew', $address->firstName);
559
+ $this->assertEquals('Smith', $address->lastName);
560
+ $this->assertEquals('Smith Co.', $address->company);
561
+ $this->assertEquals('1 E Main St', $address->streetAddress);
562
+ $this->assertEquals('Suite 101', $address->extendedAddress);
563
+ $this->assertEquals('Chicago', $address->locality);
564
+ $this->assertEquals('IL', $address->region);
565
+ $this->assertEquals('60622', $address->postalCode);
566
+ $this->assertEquals('United States of America', $address->countryName);
567
+ }
568
+
569
+ public function testCreate_withValidationErrors()
570
+ {
571
+ $result = Braintree\Customer::create([
572
+ 'email' => 'invalid',
573
+ 'creditCard' => [
574
+ 'number' => 'invalid',
575
+ 'billingAddress' => [
576
+ 'streetAddress' => str_repeat('x', 256)
577
+ ]
578
+ ]
579
+ ]);
580
+ Test\Helper::assertPrintable($result);
581
+ $this->assertEquals(false, $result->success);
582
+ $errors = $result->errors->forKey('customer')->onAttribute('email');
583
+ $this->assertEquals(Braintree\Error\Codes::CUSTOMER_EMAIL_IS_INVALID, $errors[0]->code);
584
+ $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('number');
585
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_NUMBER_INVALID_LENGTH, $errors[0]->code);
586
+ $errors = $result->errors->forKey('customer')->forKey('creditCard')->forKey('billingAddress')->onAttribute('streetAddress');
587
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_STREET_ADDRESS_IS_TOO_LONG, $errors[0]->code);
588
+ }
589
+
590
+ public function testCreate_countryValidations_inconsistency()
591
+ {
592
+ $result = Braintree\Customer::create([
593
+ 'creditCard' => [
594
+ 'billingAddress' => [
595
+ 'countryName' => 'Georgia',
596
+ 'countryCodeAlpha2' => 'TF'
597
+ ]
598
+ ]
599
+ ]);
600
+ $this->assertEquals(false, $result->success);
601
+ $errors = $result->errors->forKey('customer')->forKey('creditCard')->forKey('billingAddress')->onAttribute('base');
602
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_INCONSISTENT_COUNTRY, $errors[0]->code);
603
+ }
604
+
605
+ public function testCreateNoValidate_returnsCustomer()
606
+ {
607
+ $customer = Braintree\Customer::createNoValidate([
608
+ 'firstName' => 'Paul',
609
+ 'lastName' => 'Martin'
610
+ ]);
611
+ $this->assertEquals('Paul', $customer->firstName);
612
+ $this->assertEquals('Martin', $customer->lastName);
613
+ }
614
+
615
+ public function testCreateNoValidate_throwsIfInvalid()
616
+ {
617
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
618
+ $customer = Braintree\Customer::createNoValidate(['email' => 'invalid']);
619
+ }
620
+
621
+ public function testCreate_worksWithFuturePayPalNonce()
622
+ {
623
+ $nonce = Braintree\Test\Nonces::$paypalFuturePayment;
624
+
625
+ $result = Braintree\Customer::create([
626
+ 'paymentMethodNonce' => $nonce
627
+ ]);
628
+
629
+ $this->assertTrue($result->success);
630
+ }
631
+
632
+ public function testCreate_worksWithOrderPaymentPayPalNonce()
633
+ {
634
+ $http = new HttpClientApi(Braintree\Configuration::$global);
635
+ $nonce = $http->nonceForPayPalAccount([
636
+ 'paypal_account' => [
637
+ 'intent' => 'order',
638
+ 'payment_token' => 'paypal-payment-token',
639
+ 'payer_id' => 'paypal-payer-id',
640
+ ]
641
+ ]);
642
+
643
+ $result = Braintree\Customer::create([
644
+ 'paymentMethodNonce' => $nonce
645
+ ]);
646
+
647
+ $this->assertTrue($result->success);
648
+ }
649
+
650
+ public function testCreate_worksWithOrderPaymentPayPalNonceWithPayeeEmail()
651
+ {
652
+ $http = new HttpClientApi(Braintree\Configuration::$global);
653
+ $nonce = $http->nonceForPayPalAccount([
654
+ 'paypal_account' => [
655
+ 'intent' => 'order',
656
+ 'payment_token' => 'paypal-payment-token',
657
+ 'payer_id' => 'paypal-payer-id',
658
+ ]
659
+ ]);
660
+
661
+ $result = Braintree\Customer::create([
662
+ 'paymentMethodNonce' => $nonce,
663
+ 'options' => [
664
+ 'paypal' => [
665
+ 'payee_email' => 'payee@example.com',
666
+ 'order_id' => 'merchant-order-id',
667
+ 'custom_field' => 'custom merchant field',
668
+ 'description' => 'merchant description',
669
+ 'amount' => '1.23',
670
+ ],
671
+ ],
672
+ ]);
673
+
674
+ $this->assertTrue($result->success);
675
+ }
676
+
677
+ public function testCreate_doesNotWorkWithOnetimePayPalNonce()
678
+ {
679
+ $nonce = Braintree\Test\Nonces::$paypalOneTimePayment;
680
+
681
+ $result = Braintree\Customer::create([
682
+ 'paymentMethodNonce' => $nonce
683
+ ]);
684
+
685
+ $this->assertFalse($result->success);
686
+ $errors = $result->errors->forKey('customer')->forKey('paypalAccount')->errors;
687
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
688
+ }
689
+
690
+ public function testDelete_deletesTheCustomer()
691
+ {
692
+ $result = Braintree\Customer::create([]);
693
+ $this->assertEquals(true, $result->success);
694
+ Braintree\Customer::find($result->customer->id);
695
+ Braintree\Customer::delete($result->customer->id);
696
+ $this->setExpectedException('Braintree\Exception\NotFound');
697
+ Braintree\Customer::find($result->customer->id);
698
+ }
699
+
700
+ public function testFind()
701
+ {
702
+ $result = Braintree\Customer::create([
703
+ 'firstName' => 'Mike',
704
+ 'lastName' => 'Jones',
705
+ 'company' => 'Jones Co.',
706
+ 'email' => 'mike.jones@example.com',
707
+ 'phone' => '419.555.1234',
708
+ 'fax' => '419.555.1235',
709
+ 'website' => 'http://example.com'
710
+ ]);
711
+ $this->assertEquals(true, $result->success);
712
+ $customer = Braintree\Customer::find($result->customer->id);
713
+ $this->assertEquals('Mike', $customer->firstName);
714
+ $this->assertEquals('Jones', $customer->lastName);
715
+ $this->assertEquals('Jones Co.', $customer->company);
716
+ $this->assertEquals('mike.jones@example.com', $customer->email);
717
+ $this->assertEquals('419.555.1234', $customer->phone);
718
+ $this->assertEquals('419.555.1235', $customer->fax);
719
+ $this->assertEquals('http://example.com', $customer->website);
720
+ }
721
+
722
+ public function test_findUsBankAccountGivenPaymentMethodToken()
723
+ {
724
+ $nonce = Test\Helper::generateValidUsBankAccountNonce();
725
+ $result = Braintree\Customer::create(array(
726
+ 'paymentMethodNonce' => $nonce
727
+ ));
728
+ $this->assertTrue($result->success);
729
+
730
+ $customer = Braintree\Customer::find($result->customer->id);
731
+ $this->assertNotNull($customer->usBankAccounts[0]);
732
+ $this->assertNotNull($customer->paymentMethods[0]);
733
+ $usBankAccount = $customer->usBankAccounts[0];
734
+ $this->assertTrue($usBankAccount instanceof Braintree\UsBankAccount);
735
+ $this->assertNotNull($usBankAccount->token);
736
+ $this->assertEquals('Dan Schulman', $usBankAccount->accountHolderName);
737
+ $this->assertEquals('021000021', $usBankAccount->routingNumber);
738
+ $this->assertEquals('1234', $usBankAccount->last4);
739
+ $this->assertEquals('checking', $usBankAccount->accountType);
740
+ $this->assertRegexp('/CHASE/', $usBankAccount->bankName);
741
+ }
742
+
743
+ public function testFind_throwsExceptionIfNotFound()
744
+ {
745
+ $this->setExpectedException('Braintree\Exception\NotFound');
746
+ Braintree\Customer::find("does-not-exist");
747
+ }
748
+
749
+ public function testUpdate()
750
+ {
751
+ $result = Braintree\Customer::create([
752
+ 'firstName' => 'Old First',
753
+ 'lastName' => 'Old Last',
754
+ 'company' => 'Old Company',
755
+ 'email' => 'old.email@example.com',
756
+ 'phone' => 'old phone',
757
+ 'fax' => 'old fax',
758
+ 'website' => 'http://old.example.com'
759
+ ]);
760
+ $this->assertEquals(true, $result->success);
761
+ $customer = $result->customer;
762
+ $updateResult = Braintree\Customer::update($customer->id, [
763
+ 'firstName' => 'New First',
764
+ 'lastName' => 'New Last',
765
+ 'company' => 'New Company',
766
+ 'email' => 'new.email@example.com',
767
+ 'phone' => 'new phone',
768
+ 'fax' => 'new fax',
769
+ 'website' => 'http://new.example.com'
770
+ ]);
771
+ $this->assertEquals(true, $updateResult->success);
772
+ $this->assertEquals('New First', $updateResult->customer->firstName);
773
+ $this->assertEquals('New Last', $updateResult->customer->lastName);
774
+ $this->assertEquals('New Company', $updateResult->customer->company);
775
+ $this->assertEquals('new.email@example.com', $updateResult->customer->email);
776
+ $this->assertEquals('new phone', $updateResult->customer->phone);
777
+ $this->assertEquals('new fax', $updateResult->customer->fax);
778
+ $this->assertEquals('http://new.example.com', $updateResult->customer->website);
779
+ }
780
+
781
+ public function testUpdate_withCountry()
782
+ {
783
+ $customer = Braintree\Customer::create([
784
+ 'firstName' => 'Bat',
785
+ 'lastName' => 'Manderson',
786
+ 'creditCard' => [
787
+ 'number' => '5105105105105100',
788
+ 'expirationDate' => '05/12',
789
+ 'billingAddress' => [
790
+ 'countryName' => 'United States of America',
791
+ 'countryCodeAlpha2' => 'US',
792
+ 'countryCodeAlpha3' => 'USA',
793
+ 'countryCodeNumeric' => '840'
794
+ ]
795
+ ]
796
+ ])->customer;
797
+
798
+ $result = Braintree\Customer::update($customer->id, [
799
+ 'firstName' => 'Bat',
800
+ 'lastName' => 'Manderson',
801
+ 'creditCard' => [
802
+ 'options' => [
803
+ 'updateExistingToken' => $customer->creditCards[0]->token
804
+ ],
805
+ 'billingAddress' => [
806
+ 'countryName' => 'Gabon',
807
+ 'countryCodeAlpha2' => 'GA',
808
+ 'countryCodeAlpha3' => 'GAB',
809
+ 'countryCodeNumeric' => '266',
810
+ 'options' => [
811
+ 'updateExisting' => true
812
+ ]
813
+ ]
814
+ ]
815
+ ]);
816
+
817
+ $this->assertEquals(true, $result->success);
818
+ $updatedCustomer = $result->customer;
819
+ $this->assertEquals('Gabon', $updatedCustomer->creditCards[0]->billingAddress->countryName);
820
+ $this->assertEquals('GA', $updatedCustomer->creditCards[0]->billingAddress->countryCodeAlpha2);
821
+ $this->assertEquals('GAB', $updatedCustomer->creditCards[0]->billingAddress->countryCodeAlpha3);
822
+ $this->assertEquals('266', $updatedCustomer->creditCards[0]->billingAddress->countryCodeNumeric);
823
+ }
824
+
825
+ public function testUpdate_withUpdatingExistingCreditCard()
826
+ {
827
+ $create_result = Braintree\Customer::create([
828
+ 'firstName' => 'Old First',
829
+ 'lastName' => 'Old Last',
830
+ 'website' => 'http://old.example.com',
831
+ 'creditCard' => [
832
+ 'number' => '5105105105105100',
833
+ 'expirationDate' => '05/12',
834
+ 'cardholderName' => 'Old Cardholder'
835
+ ]
836
+ ]);
837
+ $this->assertEquals(true, $create_result->success);
838
+ $customer = $create_result->customer;
839
+ $creditCard = $customer->creditCards[0];
840
+ $result = Braintree\Customer::update($customer->id, [
841
+ 'firstName' => 'New First',
842
+ 'lastName' => 'New Last',
843
+ 'creditCard' => [
844
+ 'number' => '4111111111111111',
845
+ 'expirationDate' => '11/14',
846
+ 'cardholderName' => 'New Cardholder',
847
+ 'options' => [
848
+ 'updateExistingToken' => $creditCard->token
849
+ ]
850
+ ]
851
+ ]);
852
+ $this->assertEquals(true, $result->success);
853
+ $this->assertEquals('New First', $result->customer->firstName);
854
+ $this->assertEquals('New Last', $result->customer->lastName);
855
+ $this->assertEquals(1, sizeof($result->customer->creditCards));
856
+ $creditCard = $result->customer->creditCards[0];
857
+ $this->assertEquals('411111', $creditCard->bin);
858
+ $this->assertEquals('11/2014', $creditCard->expirationDate);
859
+ $this->assertEquals('New Cardholder', $creditCard->cardholderName);
860
+ }
861
+
862
+ public function testUpdate_failOnDuplicatePaymentMethod()
863
+ {
864
+ $create_result = Braintree\Customer::create([
865
+ 'creditCard' => [
866
+ 'number' => '4111111111111111',
867
+ 'expirationDate' => '11/14',
868
+ ]
869
+ ]);
870
+ $this->assertEquals(true, $create_result->success);
871
+ $result = Braintree\Customer::update($create_result->customer->id, [
872
+ 'creditCard' => [
873
+ 'number' => '4111111111111111',
874
+ 'expirationDate' => '11/14',
875
+ 'options' => [
876
+ 'failOnDuplicatePaymentMethod' => true
877
+ ]
878
+ ]
879
+ ]);
880
+ $this->assertFalse($result->success);
881
+ $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('number');
882
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_DUPLICATE_CARD_EXISTS, $errors[0]->code);
883
+ $this->assertEquals(1, preg_match('/Duplicate card exists in the vault\./', $result->message));
884
+ }
885
+
886
+ public function testUpdate_forBillingAddressAndExistingCreditCardAndCustomerDetailsTogether()
887
+ {
888
+ $create_result = Braintree\Customer::create([
889
+ 'firstName' => 'Old First',
890
+ 'lastName' => 'Old Last',
891
+ 'creditCard' => [
892
+ 'number' => '5105105105105100',
893
+ 'expirationDate' => '05/12',
894
+ 'cvv' => '123',
895
+ 'cardholderName' => 'Old Cardholder',
896
+ 'billingAddress' => [
897
+ 'firstName' => 'Drew',
898
+ 'lastName' => 'Smith'
899
+ ]
900
+ ]
901
+ ]);
902
+ $this->assertEquals(true, $create_result->success);
903
+ $customer = $create_result->customer;
904
+ $creditCard = $customer->creditCards[0];
905
+ $result = Braintree\Customer::update($customer->id, [
906
+ 'firstName' => 'New Customer First',
907
+ 'lastName' => 'New Customer Last',
908
+ 'creditCard' => [
909
+ 'number' => '4111111111111111',
910
+ 'expirationDate' => '11/14',
911
+ 'options' => [
912
+ 'updateExistingToken' => $creditCard->token
913
+ ],
914
+ 'billingAddress' => [
915
+ 'firstName' => 'New Billing First',
916
+ 'lastName' => 'New Billing Last',
917
+ 'options' => [
918
+ 'updateExisting' => true
919
+ ]
920
+ ]
921
+ ]
922
+ ]);
923
+ $this->assertEquals(true, $result->success);
924
+ $this->assertEquals('New Customer First', $result->customer->firstName);
925
+ $this->assertEquals('New Customer Last', $result->customer->lastName);
926
+ $this->assertEquals(1, sizeof($result->customer->creditCards));
927
+ $this->assertEquals(1, sizeof($result->customer->addresses));
928
+
929
+ $creditCard = $result->customer->creditCards[0];
930
+ $this->assertEquals('411111', $creditCard->bin);
931
+ $this->assertEquals('11/2014', $creditCard->expirationDate);
932
+
933
+ $billingAddress = $creditCard->billingAddress;
934
+ $this->assertEquals('New Billing First', $billingAddress->firstName);
935
+ $this->assertEquals('New Billing Last', $billingAddress->lastName);
936
+ }
937
+
938
+ public function testUpdate_withNewCreditCardAndExistingBillingAddress()
939
+ {
940
+ $customer = Braintree\Customer::create()->customer;
941
+ $address = Braintree\Address::create([
942
+ 'customerId' => $customer->id,
943
+ 'firstName' => 'Dan'
944
+ ])->address;
945
+
946
+ $result = Braintree\Customer::update($customer->id, [
947
+ 'creditCard' => [
948
+ 'number' => '4111111111111111',
949
+ 'expirationDate' => '11/14',
950
+ 'billingAddressId' => $address->id
951
+ ]
952
+ ]);
953
+
954
+ $billingAddress = $result->customer->creditCards[0]->billingAddress;
955
+ $this->assertEquals($address->id, $billingAddress->id);
956
+ $this->assertEquals('Dan', $billingAddress->firstName);
957
+ }
958
+
959
+ public function testUpdate_withNewCreditCardAndVerificationAmount()
960
+ {
961
+ $customer = Braintree\Customer::create()->customer;
962
+ $result = Braintree\Customer::update($customer->id, [
963
+ 'creditCard' => [
964
+ 'number' => '4111111111111111',
965
+ 'expirationDate' => '11/14',
966
+ 'options' => [
967
+ 'verifyCard' => true,
968
+ 'verificationAmount' => '2.00'
969
+ ]
970
+ ]
971
+ ]);
972
+
973
+ $this->assertTrue($result->success);
974
+ }
975
+
976
+ public function testUpdate_worksWithFuturePayPalNonce()
977
+ {
978
+ $customerResult = Braintree\Customer::create([
979
+ 'creditCard' => [
980
+ 'number' => '5105105105105100',
981
+ 'expirationDate' => '05/12',
982
+ 'options' => [
983
+ 'makeDefault' => true
984
+ ]
985
+ ]
986
+ ]);
987
+ $paypalAccountToken = 'PAYPALToken-' . strval(rand());
988
+ $http = new HttpClientApi(Braintree\Configuration::$global);
989
+ $nonce = $http->nonceForPayPalAccount([
990
+ 'paypal_account' => [
991
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
992
+ 'token' => $paypalAccountToken,
993
+ 'options' => [
994
+ 'makeDefault' => true
995
+ ]
996
+ ]
997
+ ]);
998
+
999
+ $result = Braintree\Customer::update($customerResult->customer->id, [
1000
+ 'paymentMethodNonce' => $nonce
1001
+ ]);
1002
+
1003
+ $this->assertTrue($result->success);
1004
+ $this->assertEquals($result->customer->defaultPaymentMethod()->token, $paypalAccountToken);
1005
+
1006
+ }
1007
+
1008
+ public function testUpdate_worksWithOrderPaymentPayPalNonce()
1009
+ {
1010
+ $customerResult = Braintree\Customer::create([
1011
+ 'creditCard' => [
1012
+ 'number' => '5105105105105100',
1013
+ 'expirationDate' => '05/12',
1014
+ 'options' => [
1015
+ 'makeDefault' => true
1016
+ ]
1017
+ ]
1018
+ ]);
1019
+ $paypalAccountToken = 'PAYPALToken-' . strval(rand());
1020
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1021
+ $nonce = $http->nonceForPayPalAccount([
1022
+ 'paypal_account' => [
1023
+ 'intent' => 'order',
1024
+ 'payment_token' => 'paypal-payment-token',
1025
+ 'payer_id' => 'paypal-payer-id',
1026
+ 'token' => $paypalAccountToken,
1027
+ 'options' => [
1028
+ 'makeDefault' => true
1029
+ ]
1030
+ ]
1031
+ ]);
1032
+
1033
+ $result = Braintree\Customer::update($customerResult->customer->id, [
1034
+ 'paymentMethodNonce' => $nonce
1035
+ ]);
1036
+
1037
+ $this->assertTrue($result->success);
1038
+ $this->assertEquals($result->customer->defaultPaymentMethod()->token, $paypalAccountToken);
1039
+ }
1040
+
1041
+ public function testUpdate_worksWithOrderPaymentPayPalNonceWithPayeeEmail()
1042
+ {
1043
+ $customerResult = Braintree\Customer::create([
1044
+ 'creditCard' => [
1045
+ 'number' => '5105105105105100',
1046
+ 'expirationDate' => '05/12',
1047
+ 'options' => [
1048
+ 'makeDefault' => true
1049
+ ]
1050
+ ]
1051
+ ]);
1052
+ $paypalAccountToken = 'PAYPALToken-' . strval(rand());
1053
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1054
+ $nonce = $http->nonceForPayPalAccount([
1055
+ 'paypal_account' => [
1056
+ 'intent' => 'order',
1057
+ 'payment_token' => 'paypal-payment-token',
1058
+ 'payer_id' => 'paypal-payer-id',
1059
+ 'token' => $paypalAccountToken,
1060
+ 'options' => [
1061
+ 'makeDefault' => true
1062
+ ]
1063
+ ]
1064
+ ]);
1065
+
1066
+ $result = Braintree\Customer::update($customerResult->customer->id, [
1067
+ 'paymentMethodNonce' => $nonce,
1068
+ 'options' => [
1069
+ 'paypal' => [
1070
+ 'payee_email' => 'payee@example.com',
1071
+ ],
1072
+ ],
1073
+ ]);
1074
+
1075
+ $this->assertTrue($result->success);
1076
+ $this->assertEquals($result->customer->defaultPaymentMethod()->token, $paypalAccountToken);
1077
+ }
1078
+
1079
+ public function testUpdateDefaultPaymentMethod()
1080
+ {
1081
+ $result = Braintree\Customer::create([
1082
+ 'firstName' => 'Old First',
1083
+ 'lastName' => 'Old Last',
1084
+ ]);
1085
+
1086
+ $this->assertEquals(true, $result->success);
1087
+ $customer = $result->customer;
1088
+
1089
+ $token1 = 'TOKEN-' . strval(rand());
1090
+
1091
+ $result = Braintree\PaymentMethod::create([
1092
+ 'customerId' => $customer->id,
1093
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$transactableVisa,
1094
+ 'token' => $token1
1095
+ ]);
1096
+
1097
+ $updateResult = Braintree\Customer::update($customer->id, [
1098
+ 'defaultPaymentMethodToken' => $token1
1099
+ ]);
1100
+
1101
+ $this->assertEquals(true, $updateResult->success);
1102
+ $this->assertEquals($updateResult->customer->defaultPaymentMethod()->token, $token1);
1103
+
1104
+ $token2 = 'TOKEN-' . strval(rand());
1105
+
1106
+ $result = Braintree\PaymentMethod::create([
1107
+ 'customerId' => $customer->id,
1108
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$transactableMasterCard,
1109
+ 'token' => $token2
1110
+ ]);
1111
+
1112
+ $updateResult = Braintree\Customer::update($customer->id, [
1113
+ 'defaultPaymentMethodToken' => $token2
1114
+ ]);
1115
+
1116
+ $this->assertEquals(true, $updateResult->success);
1117
+ $this->assertEquals($updateResult->customer->defaultPaymentMethod()->token, $token2);
1118
+ }
1119
+
1120
+
1121
+ public function testUpdateDefaultPaymentMethodFromOptions()
1122
+ {
1123
+ $result = Braintree\Customer::create([
1124
+ 'firstName' => 'Old First',
1125
+ 'lastName' => 'Old Last',
1126
+ ]);
1127
+
1128
+ $this->assertEquals(true, $result->success);
1129
+ $customer = $result->customer;
1130
+
1131
+ $token1 = 'TOKEN-' . strval(rand());
1132
+
1133
+ $result = Braintree\PaymentMethod::create([
1134
+ 'customerId' => $customer->id,
1135
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$transactableVisa,
1136
+ 'token' => $token1
1137
+ ]);
1138
+
1139
+ $updateResult = Braintree\Customer::update($customer->id, [
1140
+ 'creditCard' => [
1141
+ 'options' => [
1142
+ 'updateExistingToken' => $token1,
1143
+ 'makeDefault' => true
1144
+ ]
1145
+ ]
1146
+ ]);
1147
+
1148
+ $this->assertEquals(true, $updateResult->success);
1149
+ $this->assertEquals($updateResult->customer->defaultPaymentMethod()->token, $token1);
1150
+
1151
+ $token2 = 'TOKEN-' . strval(rand());
1152
+
1153
+ $result = Braintree\PaymentMethod::create([
1154
+ 'customerId' => $customer->id,
1155
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$transactableMasterCard,
1156
+ 'token' => $token2
1157
+ ]);
1158
+
1159
+ $updateResult = Braintree\Customer::update($customer->id, [
1160
+ 'creditCard' => [
1161
+ 'options' => [
1162
+ 'updateExistingToken' => $token2,
1163
+ 'makeDefault' => true
1164
+ ]
1165
+ ]
1166
+ ]);
1167
+
1168
+ $this->assertEquals(true, $updateResult->success);
1169
+ $this->assertEquals($updateResult->customer->defaultPaymentMethod()->token, $token2);
1170
+ }
1171
+ public function testUpdate_doesNotWorkWithOnetimePayPalNonce()
1172
+ {
1173
+ $customerResult = Braintree\Customer::create([
1174
+ 'creditCard' => [
1175
+ 'number' => '5105105105105100',
1176
+ 'expirationDate' => '05/12',
1177
+ 'options' => [
1178
+ 'makeDefault' => true
1179
+ ]
1180
+ ]
1181
+ ]);
1182
+ $paypalAccountToken = 'PAYPALToken-' . strval(rand());
1183
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1184
+ $nonce = $http->nonceForPayPalAccount([
1185
+ 'paypal_account' => [
1186
+ 'access_token' => 'PAYPAL_ACCESS_TOKEN',
1187
+ 'token' => $paypalAccountToken,
1188
+ 'options' => [
1189
+ 'makeDefault' => true
1190
+ ]
1191
+ ]
1192
+ ]);
1193
+
1194
+ $result = Braintree\Customer::update($customerResult->customer->id, [
1195
+ 'paymentMethodNonce' => $nonce
1196
+ ]);
1197
+
1198
+ $this->assertFalse($result->success);
1199
+ $errors = $result->errors->forKey('customer')->forKey('paypalAccount')->errors;
1200
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
1201
+
1202
+ }
1203
+
1204
+ public function testUpdateNoValidate()
1205
+ {
1206
+ $result = Braintree\Customer::create([
1207
+ 'firstName' => 'Old First',
1208
+ 'lastName' => 'Old Last',
1209
+ 'company' => 'Old Company',
1210
+ 'email' => 'old.email@example.com',
1211
+ 'phone' => 'old phone',
1212
+ 'fax' => 'old fax',
1213
+ 'website' => 'http://old.example.com'
1214
+ ]);
1215
+ $this->assertEquals(true, $result->success);
1216
+ $customer = $result->customer;
1217
+ $updated = Braintree\Customer::updateNoValidate($customer->id, [
1218
+ 'firstName' => 'New First',
1219
+ 'lastName' => 'New Last',
1220
+ 'company' => 'New Company',
1221
+ 'email' => 'new.email@example.com',
1222
+ 'phone' => 'new phone',
1223
+ 'fax' => 'new fax',
1224
+ 'website' => 'http://new.example.com'
1225
+ ]);
1226
+ $this->assertEquals('New First', $updated->firstName);
1227
+ $this->assertEquals('New Last', $updated->lastName);
1228
+ $this->assertEquals('New Company', $updated->company);
1229
+ $this->assertEquals('new.email@example.com', $updated->email);
1230
+ $this->assertEquals('new phone', $updated->phone);
1231
+ $this->assertEquals('new fax', $updated->fax);
1232
+ $this->assertEquals('http://new.example.com', $updated->website);
1233
+ }
1234
+
1235
+ public function testCreateFromTransparentRedirect()
1236
+ {
1237
+ Test\Helper::suppressDeprecationWarnings();
1238
+ $queryString = $this->createCustomerViaTr(
1239
+ [
1240
+ 'customer' => [
1241
+ 'first_name' => 'Joe',
1242
+ 'last_name' => 'Martin',
1243
+ 'credit_card' => [
1244
+ 'number' => '5105105105105100',
1245
+ 'expiration_date' => '05/12'
1246
+ ]
1247
+ ]
1248
+ ],
1249
+ [
1250
+ ]
1251
+ );
1252
+ $result = Braintree\Customer::createFromTransparentRedirect($queryString);
1253
+ $this->assertTrue($result->success);
1254
+ $this->assertEquals('Joe', $result->customer->firstName);
1255
+ $this->assertEquals('Martin', $result->customer->lastName);
1256
+ $creditCard = $result->customer->creditCards[0];
1257
+ $this->assertEquals('510510', $creditCard->bin);
1258
+ $this->assertEquals('5100', $creditCard->last4);
1259
+ $this->assertEquals('05/2012', $creditCard->expirationDate);
1260
+ }
1261
+
1262
+ public function testCreateFromTransparentRedirect_withParamsInTrData()
1263
+ {
1264
+ Test\Helper::suppressDeprecationWarnings();
1265
+ $queryString = $this->createCustomerViaTr(
1266
+ [
1267
+ ],
1268
+ [
1269
+ 'customer' => [
1270
+ 'firstName' => 'Joe',
1271
+ 'lastName' => 'Martin',
1272
+ 'creditCard' => [
1273
+ 'number' => '5105105105105100',
1274
+ 'expirationDate' => '05/12'
1275
+ ]
1276
+ ]
1277
+ ]
1278
+ );
1279
+ $result = Braintree\Customer::createFromTransparentRedirect($queryString);
1280
+ $this->assertTrue($result->success);
1281
+ $this->assertEquals('Joe', $result->customer->firstName);
1282
+ $this->assertEquals('Martin', $result->customer->lastName);
1283
+ $creditCard = $result->customer->creditCards[0];
1284
+ $this->assertEquals('510510', $creditCard->bin);
1285
+ $this->assertEquals('5100', $creditCard->last4);
1286
+ $this->assertEquals('05/2012', $creditCard->expirationDate);
1287
+ }
1288
+
1289
+ public function testCreateFromTransparentRedirect_withValidationErrors()
1290
+ {
1291
+ Test\Helper::suppressDeprecationWarnings();
1292
+ $queryString = $this->createCustomerViaTr(
1293
+ [
1294
+ 'customer' => [
1295
+ 'first_name' => str_repeat('x', 256),
1296
+ 'credit_card' => [
1297
+ 'number' => 'invalid',
1298
+ 'expiration_date' => ''
1299
+ ]
1300
+ ]
1301
+ ],
1302
+ [
1303
+ ]
1304
+ );
1305
+ $result = Braintree\Customer::createFromTransparentRedirect($queryString);
1306
+ $this->assertFalse($result->success);
1307
+ $errors = $result->errors->forKey('customer')->onAttribute('firstName');
1308
+ $this->assertEquals(Braintree\Error\Codes::CUSTOMER_FIRST_NAME_IS_TOO_LONG, $errors[0]->code);
1309
+ $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('number');
1310
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_NUMBER_INVALID_LENGTH, $errors[0]->code);
1311
+ $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('expirationDate');
1312
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_EXPIRATION_DATE_IS_REQUIRED, $errors[0]->code);
1313
+ }
1314
+
1315
+ public function testCreateWithInvalidUTF8Bytes()
1316
+ {
1317
+ $result = Braintree\Customer::create([
1318
+ 'firstName' => "Jos\xe8 Maria"
1319
+ ]);
1320
+ $this->assertEquals(true, $result->success);
1321
+ $customer = $result->customer;
1322
+ $this->assertEquals("Jos\xc3\xa8 Maria", $customer->firstName);
1323
+ }
1324
+
1325
+ public function testCreateWithValidUTF8Bytes()
1326
+ {
1327
+ $result = Braintree\Customer::create([
1328
+ 'firstName' => "Jos\303\251"
1329
+ ]);
1330
+ $this->assertEquals(true, $result->success);
1331
+ $customer = $result->customer;
1332
+ $this->assertEquals("Jos\303\251", $customer->firstName);
1333
+ }
1334
+
1335
+ public function testUpdateFromTransparentRedirect()
1336
+ {
1337
+ Test\Helper::suppressDeprecationWarnings();
1338
+ $customer = Braintree\Customer::createNoValidate();
1339
+ $queryString = $this->updateCustomerViaTr(
1340
+ [
1341
+ 'customer' => [
1342
+ 'first_name' => 'Joe',
1343
+ 'last_name' => 'Martin',
1344
+ 'email' => 'joe.martin@example.com'
1345
+ ]
1346
+ ],
1347
+ [
1348
+ 'customerId' => $customer->id
1349
+ ]
1350
+ );
1351
+ $result = Braintree\Customer::updateFromTransparentRedirect($queryString);
1352
+ $this->assertTrue($result->success);
1353
+ $this->assertEquals('Joe', $result->customer->firstName);
1354
+ $this->assertEquals('Martin', $result->customer->lastName);
1355
+ $this->assertEquals('joe.martin@example.com', $result->customer->email);
1356
+ }
1357
+
1358
+ public function testUpdateFromTransparentRedirect_withParamsInTrData()
1359
+ {
1360
+ Test\Helper::suppressDeprecationWarnings();
1361
+ $customer = Braintree\Customer::createNoValidate();
1362
+ $queryString = $this->updateCustomerViaTr(
1363
+ [
1364
+ ],
1365
+ [
1366
+ 'customerId' => $customer->id,
1367
+ 'customer' => [
1368
+ 'firstName' => 'Joe',
1369
+ 'lastName' => 'Martin',
1370
+ 'email' => 'joe.martin@example.com'
1371
+ ]
1372
+ ]
1373
+ );
1374
+ $result = Braintree\Customer::updateFromTransparentRedirect($queryString);
1375
+ $this->assertTrue($result->success);
1376
+ $this->assertEquals('Joe', $result->customer->firstName);
1377
+ $this->assertEquals('Martin', $result->customer->lastName);
1378
+ $this->assertEquals('joe.martin@example.com', $result->customer->email);
1379
+ }
1380
+
1381
+ public function testUpdateFromTransparentRedirect_withValidationErrors()
1382
+ {
1383
+ Test\Helper::suppressDeprecationWarnings();
1384
+ $customer = Braintree\Customer::createNoValidate();
1385
+ $queryString = $this->updateCustomerViaTr(
1386
+ [
1387
+ 'customer' => [
1388
+ 'first_name' => str_repeat('x', 256),
1389
+ ]
1390
+ ],
1391
+ [
1392
+ 'customerId' => $customer->id
1393
+ ]
1394
+ );
1395
+ $result = Braintree\Customer::updateFromTransparentRedirect($queryString);
1396
+ $this->assertFalse($result->success);
1397
+ $errors = $result->errors->forKey('customer')->onAttribute('firstName');
1398
+ $this->assertEquals(Braintree\Error\Codes::CUSTOMER_FIRST_NAME_IS_TOO_LONG, $errors[0]->code);
1399
+ }
1400
+
1401
+ public function testUpdateFromTransparentRedirect_withUpdateExisting()
1402
+ {
1403
+ Test\Helper::suppressDeprecationWarnings();
1404
+ $customer = Braintree\Customer::create([
1405
+ 'firstName' => 'Mike',
1406
+ 'lastName' => 'Jones',
1407
+ 'creditCard' => [
1408
+ 'number' => '5105105105105100',
1409
+ 'expirationDate' => '05/12',
1410
+ 'cardholderName' => 'Mike Jones',
1411
+ 'billingAddress' => [
1412
+ 'firstName' => 'Drew',
1413
+ 'lastName' => 'Smith'
1414
+ ]
1415
+ ]
1416
+ ])->customer;
1417
+
1418
+ $queryString = $this->updateCustomerViaTr(
1419
+ [],
1420
+ [
1421
+ 'customerId' => $customer->id,
1422
+ 'customer' => [
1423
+ 'firstName' => 'New First',
1424
+ 'lastName' => 'New Last',
1425
+ 'creditCard' => [
1426
+ 'number' => '4111111111111111',
1427
+ 'expirationDate' => '05/13',
1428
+ 'cardholderName' => 'New Cardholder',
1429
+ 'options' => [
1430
+ 'updateExistingToken' => $customer->creditCards[0]->token
1431
+ ],
1432
+ 'billingAddress' => [
1433
+ 'firstName' => 'New First Billing',
1434
+ 'lastName' => 'New Last Billing',
1435
+ 'options' => [
1436
+ 'updateExisting' => true
1437
+ ]
1438
+ ]
1439
+ ]
1440
+ ]
1441
+ ]
1442
+ );
1443
+ $result = Braintree\Customer::updateFromTransparentRedirect($queryString);
1444
+ $this->assertTrue($result->success);
1445
+
1446
+ $this->assertEquals(true, $result->success);
1447
+ $customer = $result->customer;
1448
+ $this->assertEquals('New First', $customer->firstName);
1449
+ $this->assertEquals('New Last', $customer->lastName);
1450
+
1451
+ $this->assertEquals(1, sizeof($result->customer->creditCards));
1452
+ $creditCard = $customer->creditCards[0];
1453
+ $this->assertEquals('411111', $creditCard->bin);
1454
+ $this->assertEquals('1111', $creditCard->last4);
1455
+ $this->assertEquals('New Cardholder', $creditCard->cardholderName);
1456
+ $this->assertEquals('05/2013', $creditCard->expirationDate);
1457
+
1458
+ $this->assertEquals(1, sizeof($result->customer->addresses));
1459
+ $address = $customer->addresses[0];
1460
+ $this->assertEquals($address, $creditCard->billingAddress);
1461
+ $this->assertEquals('New First Billing', $address->firstName);
1462
+ $this->assertEquals('New Last Billing', $address->lastName);
1463
+ }
1464
+
1465
+ public function testSale_createsASaleUsingGivenToken()
1466
+ {
1467
+ $customer = Braintree\Customer::createNoValidate([
1468
+ 'creditCard' => [
1469
+ 'number' => '5105105105105100',
1470
+ 'expirationDate' => '05/12'
1471
+ ]
1472
+ ]);
1473
+ $creditCard = $customer->creditCards[0];
1474
+ $result = Braintree\Customer::sale($customer->id, [
1475
+ 'amount' => '100.00'
1476
+ ]);
1477
+ $this->assertTrue($result->success);
1478
+ $this->assertEquals('100.00', $result->transaction->amount);
1479
+ $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
1480
+ $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
1481
+ }
1482
+
1483
+ public function testSaleNoValidate_createsASaleUsingGivenToken()
1484
+ {
1485
+ $customer = Braintree\Customer::createNoValidate([
1486
+ 'creditCard' => [
1487
+ 'number' => '5105105105105100',
1488
+ 'expirationDate' => '05/12'
1489
+ ]
1490
+ ]);
1491
+ $creditCard = $customer->creditCards[0];
1492
+ $transaction = Braintree\Customer::saleNoValidate($customer->id, [
1493
+ 'amount' => '100.00'
1494
+ ]);
1495
+ $this->assertEquals('100.00', $transaction->amount);
1496
+ $this->assertEquals($customer->id, $transaction->customerDetails->id);
1497
+ $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
1498
+ }
1499
+
1500
+ public function testSaleNoValidate_throwsIfInvalid()
1501
+ {
1502
+ $customer = Braintree\Customer::createNoValidate([
1503
+ 'creditCard' => [
1504
+ 'number' => '5105105105105100',
1505
+ 'expirationDate' => '05/12'
1506
+ ]
1507
+ ]);
1508
+ $creditCard = $customer->creditCards[0];
1509
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
1510
+ Braintree\Customer::saleNoValidate($customer->id, [
1511
+ 'amount' => 'invalid'
1512
+ ]);
1513
+ }
1514
+
1515
+ public function testCredit_createsACreditUsingGivenCustomerId()
1516
+ {
1517
+ $customer = Braintree\Customer::createNoValidate([
1518
+ 'creditCard' => [
1519
+ 'number' => '5105105105105100',
1520
+ 'expirationDate' => '05/12'
1521
+ ]
1522
+ ]);
1523
+ $creditCard = $customer->creditCards[0];
1524
+ $result = Braintree\Customer::credit($customer->id, [
1525
+ 'amount' => '100.00'
1526
+ ]);
1527
+ $this->assertTrue($result->success);
1528
+ $this->assertEquals('100.00', $result->transaction->amount);
1529
+ $this->assertEquals(Braintree\Transaction::CREDIT, $result->transaction->type);
1530
+ $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
1531
+ $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
1532
+ }
1533
+
1534
+ public function testCreditNoValidate_createsACreditUsingGivenId()
1535
+ {
1536
+ $customer = Braintree\Customer::createNoValidate([
1537
+ 'creditCard' => [
1538
+ 'number' => '5105105105105100',
1539
+ 'expirationDate' => '05/12'
1540
+ ]
1541
+ ]);
1542
+ $creditCard = $customer->creditCards[0];
1543
+ $transaction = Braintree\Customer::creditNoValidate($customer->id, [
1544
+ 'amount' => '100.00'
1545
+ ]);
1546
+ $this->assertEquals('100.00', $transaction->amount);
1547
+ $this->assertEquals(Braintree\Transaction::CREDIT, $transaction->type);
1548
+ $this->assertEquals($customer->id, $transaction->customerDetails->id);
1549
+ $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
1550
+ }
1551
+
1552
+ public function testCreditNoValidate_throwsIfInvalid()
1553
+ {
1554
+ $customer = Braintree\Customer::createNoValidate([
1555
+ 'creditCard' => [
1556
+ 'number' => '5105105105105100',
1557
+ 'expirationDate' => '05/12'
1558
+ ]
1559
+ ]);
1560
+ $creditCard = $customer->creditCards[0];
1561
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
1562
+ Braintree\Customer::creditNoValidate($customer->id, [
1563
+ 'amount' => 'invalid'
1564
+ ]);
1565
+ }
1566
+
1567
+ public function createCustomerViaTr($regularParams, $trParams)
1568
+ {
1569
+ Test\Helper::suppressDeprecationWarnings();
1570
+ $trData = Braintree\TransparentRedirect::createCustomerData(
1571
+ array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
1572
+ );
1573
+ return Test\Helper::submitTrRequest(
1574
+ Braintree\Customer::createCustomerUrl(),
1575
+ $regularParams,
1576
+ $trData
1577
+ );
1578
+ }
1579
+
1580
+ public function updateCustomerViaTr($regularParams, $trParams)
1581
+ {
1582
+ Test\Helper::suppressDeprecationWarnings();
1583
+ $trData = Braintree\TransparentRedirect::updateCustomerData(
1584
+ array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
1585
+ );
1586
+ return Test\Helper::submitTrRequest(
1587
+ Braintree\Customer::updateCustomerUrl(),
1588
+ $regularParams,
1589
+ $trData
1590
+ );
1591
+ }
1592
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/DisbursementTest.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use DateTime;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class DisbursementTest extends Setup
11
+ {
12
+ public function testTransactions()
13
+ {
14
+ $disbursement = Braintree\Disbursement::factory([
15
+ "id" => "123456",
16
+ "merchantAccount" => [
17
+ "id" => "sandbox_sub_merchant_account",
18
+ "masterMerchantAccount" => [
19
+ "id" => "sandbox_master_merchant_account",
20
+ "status" => "active"
21
+ ],
22
+ "status" => "active"
23
+ ],
24
+ "transactionIds" => ["sub_merchant_transaction"],
25
+ "exceptionMessage" => "invalid_account_number",
26
+ "amount" => "100.00",
27
+ "disbursementDate" => new DateTime("2013-04-10"),
28
+ "followUpAction" => "update",
29
+ "retry" => false,
30
+ "success" => false
31
+ ]);
32
+
33
+ $transactions = $disbursement->transactions();
34
+
35
+ $this->assertNotNull($transactions);
36
+ $this->assertEquals(sizeOf($transactions), 1);
37
+ $this->assertEquals($transactions->firstItem()->id, 'sub_merchant_transaction');
38
+ }
39
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/DiscountTest.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Braintree;
8
+
9
+ class DiscountTest extends Setup
10
+ {
11
+ public function testAll_returnsAllDiscounts()
12
+ {
13
+ $newId = strval(rand());
14
+
15
+ $discountParams = [
16
+ "amount" => "100.00",
17
+ "description" => "some description",
18
+ "id" => $newId,
19
+ "kind" => "discount",
20
+ "name" => "php_discount",
21
+ "neverExpires" => "false",
22
+ "numberOfBillingCycles" => "1"
23
+ ];
24
+
25
+ $http = new Braintree\Http(Braintree\Configuration::$global);
26
+ $path = Braintree\Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
27
+ $http->post($path, ["modification" => $discountParams]);
28
+
29
+ $discounts = Braintree\Discount::all();
30
+
31
+ foreach ($discounts as $discount)
32
+ {
33
+ if ($discount->id == $newId)
34
+ {
35
+ $actualDiscount = $discount;
36
+ }
37
+ }
38
+
39
+ $this->assertNotNull($actualDiscount);
40
+ $this->assertEquals($discountParams["amount"], $actualDiscount->amount);
41
+ $this->assertEquals($discountParams["description"], $actualDiscount->description);
42
+ $this->assertEquals($discountParams["id"], $actualDiscount->id);
43
+ $this->assertEquals($discountParams["kind"], $actualDiscount->kind);
44
+ $this->assertEquals($discountParams["name"], $actualDiscount->name);
45
+ $this->assertFalse($actualDiscount->neverExpires);
46
+ $this->assertEquals($discountParams["numberOfBillingCycles"], $actualDiscount->numberOfBillingCycles);
47
+ }
48
+
49
+ public function testGatewayAll_returnsAllDiscounts()
50
+ {
51
+ $newId = strval(rand());
52
+
53
+ $discountParams = [
54
+ "amount" => "100.00",
55
+ "description" => "some description",
56
+ "id" => $newId,
57
+ "kind" => "discount",
58
+ "name" => "php_discount",
59
+ "neverExpires" => "false",
60
+ "numberOfBillingCycles" => "1"
61
+ ];
62
+
63
+ $http = new Braintree\Http(Braintree\Configuration::$global);
64
+ $path = Braintree\Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
65
+ $http->post($path, ["modification" => $discountParams]);
66
+
67
+ $gateway = new Braintree\Gateway([
68
+ 'environment' => 'development',
69
+ 'merchantId' => 'integration_merchant_id',
70
+ 'publicKey' => 'integration_public_key',
71
+ 'privateKey' => 'integration_private_key'
72
+ ]);
73
+ $discounts = $gateway->discount()->all();
74
+
75
+ foreach ($discounts as $discount)
76
+ {
77
+ if ($discount->id == $newId)
78
+ {
79
+ $actualDiscount = $discount;
80
+ }
81
+ }
82
+
83
+ $this->assertNotNull($actualDiscount);
84
+ $this->assertEquals($discountParams["amount"], $actualDiscount->amount);
85
+ $this->assertEquals($discountParams["id"], $actualDiscount->id);
86
+ $this->assertEquals($discountParams["kind"], $actualDiscount->kind);
87
+ }
88
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/Error/ErrorCollectionTest.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration\Error;
3
+
4
+ require_once dirname(dirname(__DIR__)) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Braintree;
8
+
9
+ class ErrorCollectionTest extends Setup
10
+ {
11
+ public function testDeepSize_withNestedErrors()
12
+ {
13
+ $result = Braintree\Customer::create([
14
+ 'email' => 'invalid',
15
+ 'creditCard' => [
16
+ 'number' => 'invalid',
17
+ 'expirationDate' => 'invalid',
18
+ 'billingAddress' => [
19
+ 'countryName' => 'invaild'
20
+ ]
21
+ ]
22
+ ]);
23
+ $this->assertEquals(false, $result->success);
24
+ $this->assertEquals(4, $result->errors->deepSize());
25
+ }
26
+
27
+ public function testOnHtmlField()
28
+ {
29
+ $result = Braintree\Customer::create([
30
+ 'email' => 'invalid',
31
+ 'creditCard' => [
32
+ 'number' => 'invalid',
33
+ 'expirationDate' => 'invalid',
34
+ 'billingAddress' => [
35
+ 'countryName' => 'invaild'
36
+ ]
37
+ ]
38
+ ]);
39
+ $this->assertEquals(false, $result->success);
40
+ $errors = $result->errors->onHtmlField('customer[email]');
41
+ $this->assertEquals(Braintree\Error\Codes::CUSTOMER_EMAIL_IS_INVALID, $errors[0]->code);
42
+ $errors = $result->errors->onHtmlField('customer[credit_card][number]');
43
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_NUMBER_INVALID_LENGTH, $errors[0]->code);
44
+ $errors = $result->errors->onHtmlField('customer[credit_card][billing_address][country_name]');
45
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, $errors[0]->code);
46
+ }
47
+
48
+ public function testOnHtmlField_returnsEmptyArrayIfNone()
49
+ {
50
+ $result = Braintree\Customer::create([
51
+ 'email' => 'invalid',
52
+ 'creditCard' => [
53
+ 'number' => '5105105105105100',
54
+ 'expirationDate' => '05/12',
55
+ 'billingAddress' => [
56
+ 'streetAddress' => '1 E Main St'
57
+ ]
58
+ ]
59
+ ]);
60
+ $this->assertEquals(false, $result->success);
61
+ $errors = $result->errors->onHtmlField('customer[email]');
62
+ $this->assertEquals(Braintree\Error\Codes::CUSTOMER_EMAIL_IS_INVALID, $errors[0]->code);
63
+ $this->assertEquals([], $result->errors->onHtmlField('customer[credit_card][number]'));
64
+ $this->assertEquals([], $result->errors->onHtmlField('customer[credit_card][billing_address][country_name]'));
65
+ }
66
+
67
+ public function testOnHtmlField_returnsEmptyForCustomFieldsIfNoErrors()
68
+ {
69
+ $result = Braintree\Customer::create([
70
+ 'email' => 'invalid',
71
+ 'creditCard' => [
72
+ 'number' => '5105105105105100',
73
+ 'expirationDate' => '05/12',
74
+ ],
75
+ 'customFields' => ['storeMe' => 'value']
76
+ ]);
77
+ $this->assertEquals(false, $result->success);
78
+ $this->assertEquals([], $result->errors->onHtmlField('customer[custom_fields][store_me]'));
79
+ }
80
+
81
+ public function testCount_returnsTheNumberOfErrors()
82
+ {
83
+ $result = Braintree\Customer::create([
84
+ 'email' => 'invalid',
85
+ 'creditCard' => [
86
+ 'number' => 'invalid',
87
+ 'expirationDate' => 'invalid',
88
+ 'billingAddress' => [
89
+ 'countryName' => 'invaild'
90
+ ]
91
+ ]
92
+ ]);
93
+ $this->assertEquals(false, $result->success);
94
+ $this->assertEquals(4, count($result->errors));
95
+ }
96
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/Error/ValidationErrorCollectionTest.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration\Error;
3
+
4
+ require_once dirname(dirname(__DIR__)) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Braintree;
8
+
9
+ class ValidationErrorCollectionTest extends Setup
10
+ {
11
+ public function mapValidationErrorsToCodes($validationErrors)
12
+ {
13
+ $codes = array_map(create_function('$validationError', 'return $validationError->code;'), $validationErrors);
14
+ sort($codes);
15
+ return $codes;
16
+ }
17
+
18
+ public function test_shallowAll_givesAllErrorsShallowly()
19
+ {
20
+ $result = Braintree\Customer::create([
21
+ 'email' => 'invalid',
22
+ 'creditCard' => [
23
+ 'number' => '1234123412341234',
24
+ 'expirationDate' => 'invalid',
25
+ 'billingAddress' => [
26
+ 'countryName' => 'invalid'
27
+ ]
28
+ ]
29
+ ]);
30
+
31
+ $this->assertEquals([], $result->errors->shallowAll());
32
+
33
+ $expectedCustomerErrors = [Braintree\Error\Codes::CUSTOMER_EMAIL_IS_INVALID];
34
+ $actualCustomerErrors = $result->errors->forKey('customer')->shallowAll();
35
+ $this->assertEquals($expectedCustomerErrors, self::mapValidationErrorsToCodes($actualCustomerErrors));
36
+
37
+ $expectedCreditCardErrors = [
38
+ Braintree\Error\Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID,
39
+ Braintree\Error\Codes::CREDIT_CARD_NUMBER_IS_INVALID,
40
+ ];
41
+ $actualCreditCardErrors = $result->errors->forKey('customer')->forKey('creditCard')->shallowAll();
42
+ $this->assertEquals($expectedCreditCardErrors, self::mapValidationErrorsToCodes($actualCreditCardErrors));
43
+ }
44
+
45
+ public function test_deepAll_givesAllErrorsDeeply()
46
+ {
47
+ $result = Braintree\Customer::create([
48
+ 'email' => 'invalid',
49
+ 'creditCard' => [
50
+ 'number' => '1234123412341234',
51
+ 'expirationDate' => 'invalid',
52
+ 'billingAddress' => [
53
+ 'countryName' => 'invalid'
54
+ ]
55
+ ]
56
+ ]);
57
+
58
+ $expectedErrors = [
59
+ Braintree\Error\Codes::CUSTOMER_EMAIL_IS_INVALID,
60
+ Braintree\Error\Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID,
61
+ Braintree\Error\Codes::CREDIT_CARD_NUMBER_IS_INVALID,
62
+ Braintree\Error\Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED,
63
+ ];
64
+ $actualErrors = $result->errors->deepAll();
65
+ $this->assertEquals($expectedErrors, self::mapValidationErrorsToCodes($actualErrors));
66
+
67
+ $expectedErrors = [
68
+ Braintree\Error\Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID,
69
+ Braintree\Error\Codes::CREDIT_CARD_NUMBER_IS_INVALID,
70
+ Braintree\Error\Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED,
71
+ ];
72
+ $actualErrors = $result->errors->forKey('customer')->forKey('creditCard')->deepAll();
73
+ $this->assertEquals($expectedErrors, self::mapValidationErrorsToCodes($actualErrors));
74
+ }
75
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/EuropeBankAccountTest.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Braintree;
8
+
9
+ class EuropeBankAccountTest extends Setup
10
+ {
11
+ public function testCanExchangeNonceForEuropeBankAccount()
12
+ {
13
+ $gateway = new Braintree\Gateway([
14
+ 'environment' => 'development',
15
+ 'merchantId' => 'altpay_merchant',
16
+ 'publicKey' => 'altpay_merchant_public_key',
17
+ 'privateKey' => 'altpay_merchant_private_key'
18
+ ]);
19
+
20
+ $result = $gateway->customer()->create();
21
+ $this->assertTrue($result->success);
22
+ $customer = $result->customer;
23
+ $clientApi = new HttpClientApi($gateway->config);
24
+ $nonce = $clientApi->nonceForNewEuropeanBankAccount([
25
+ "customerId" => $customer->id,
26
+ "sepa_mandate" => [
27
+ "locale" => "de-DE",
28
+ "bic" => "DEUTDEFF",
29
+ "iban" => "DE89370400440532013000",
30
+ "accountHolderName" => "Bob Holder",
31
+ "billingAddress" => [
32
+ "streetAddress" => "123 Currywurst Way",
33
+ "extendedAddress" => "Lager Suite",
34
+ "firstName" => "Wilhelm",
35
+ "lastName" => "Dix",
36
+ "locality" => "Frankfurt",
37
+ "postalCode" => "60001",
38
+ "countryCodeAlpha2" => "DE",
39
+ "region" => "Hesse"
40
+ ]
41
+ ]
42
+ ]);
43
+ $result = $gateway->paymentMethod()->create([
44
+ "customerId" => $customer->id,
45
+ "paymentMethodNonce" => $nonce
46
+ ]);
47
+
48
+ $this->assertTrue($result->success);
49
+ $paymentMethod = $result->paymentMethod;
50
+ $account = $gateway->paymentMethod()->find($paymentMethod->token);
51
+ $this->assertEquals($paymentMethod->token, $account->token);
52
+ $this->assertEquals($account->bic, "DEUTDEFF");
53
+ }
54
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/HttpClientApi.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Braintree;
7
+ use Test;
8
+
9
+ class HttpClientApi extends Braintree\Http
10
+ {
11
+ protected function _doRequest($httpVerb, $path, $requestBody = null)
12
+ {
13
+ return $this->_doUrlRequest($httpVerb, $this->_config->baseUrl() . "/merchants/" . $this->_config->getMerchantId() . $path, $requestBody);
14
+ }
15
+
16
+ public function get($path)
17
+ {
18
+ return $this->_doRequest('GET', $path);
19
+ }
20
+
21
+ public function post($path, $body = null)
22
+ {
23
+ return $this->_doRequest('POST', $path, $body);
24
+ }
25
+
26
+ public function _doUrlRequest($httpVerb, $url, $requestBody = null)
27
+ {
28
+ $curl = curl_init();
29
+ curl_setopt($curl, CURLOPT_TIMEOUT, 60);
30
+ curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpVerb);
31
+ curl_setopt($curl, CURLOPT_URL, $url);
32
+ curl_setopt($curl, CURLOPT_HTTPHEADER, [
33
+ 'Content-Type: application/json',
34
+ 'X-ApiVersion: ' . Braintree\Configuration::API_VERSION,
35
+ ]);
36
+ curl_setopt($curl, CURLOPT_USERPWD, $this->_config->publicKey() . ':' . $this->_config->privateKey());
37
+
38
+ if(!empty($requestBody)) {
39
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
40
+ }
41
+
42
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
43
+ $response = curl_exec($curl);
44
+ $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
45
+ curl_close($curl);
46
+ return ['status' => $httpStatus, 'body' => $response];
47
+ }
48
+
49
+ public function get_configuration($options) {
50
+ $encoded_fingerprint = urlencode($options["authorization_fingerprint"]);
51
+ $url = "/client_api/v1/configuration?";
52
+ $url .= "authorizationFingerprint=" . $encoded_fingerprint;
53
+ $url .= "&configVersion=3";
54
+
55
+ $response = $this->get($url);
56
+ if ($response["status"] == 200) {
57
+ return json_decode($response["body"]);
58
+ } else {
59
+ throw new Exception(print_r($response, true));
60
+ }
61
+ }
62
+
63
+ public function get_cards($options) {
64
+ $encoded_fingerprint = urlencode($options["authorization_fingerprint"]);
65
+ $url = "/client_api/v1/payment_methods.json?";
66
+ $url .= "authorizationFingerprint=" . $encoded_fingerprint;
67
+ $url .= "&sharedCustomerIdentifier=" . $options["shared_customer_identifier"];
68
+ $url .= "&sharedCustomerIdentifierType=" . $options["shared_customer_identifier_type"];
69
+
70
+ return $this->get($url);
71
+ }
72
+
73
+ public function nonce_for_new_card($options) {
74
+ $clientTokenOptions = [];
75
+ if (array_key_exists("customerId", $options)) {
76
+ $clientTokenOptions["customerId"] = $options["customerId"];
77
+ unset($options["customerId"]);
78
+ }
79
+
80
+ $clientToken = json_decode(Test\Helper::decodedClientToken($clientTokenOptions));
81
+
82
+ $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
83
+ $options["shared_customer_identifier"] = "fake_identifier_" . rand();
84
+ $options["shared_customer_identifier_type"] = "testing";
85
+ $response = $this->post('/client_api/v1/payment_methods/credit_cards.json', json_encode($options));
86
+ if ($response["status"] == 201 || $response["status"] == 202) {
87
+ $body = json_decode($response["body"]);
88
+ return $body->creditCards[0]->nonce;
89
+ } else {
90
+ throw new Exception(print_r($response, true));
91
+ }
92
+ }
93
+
94
+ public function nonceForNewEuropeanBankAccount($options) {
95
+ $clientTokenOptions = [
96
+ 'sepaMandateType' => 'business',
97
+ 'sepaMandateAcceptanceLocation' => 'Rostock, Germany'
98
+ ];
99
+
100
+ if (array_key_exists("customerId", $options)) {
101
+ $clientTokenOptions["customerId"] = $options["customerId"];
102
+ unset($options["customerId"]);
103
+ }
104
+
105
+ $gateway = new Braintree\Gateway($this->_config);
106
+
107
+ $clientToken = json_decode(base64_decode($gateway->clientToken()->generate($clientTokenOptions)));
108
+ $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
109
+
110
+ $response = $this->post('/client_api/v1/sepa_mandates/', json_encode($options));
111
+ if ($response["status"] == 201 || $response["status"] == 202) {
112
+ $body = json_decode($response["body"]);
113
+ return $body->europeBankAccounts[0]->nonce;
114
+ } else {
115
+ throw new Exception(print_r($response, true));
116
+ }
117
+ }
118
+
119
+ public function nonceForPayPalAccount($options) {
120
+ $clientToken = json_decode(Test\Helper::decodedClientToken());
121
+ $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
122
+ $response = $this->post('/client_api/v1/payment_methods/paypal_accounts.json', json_encode($options));
123
+ if ($response["status"] == 201 || $response["status"] == 202) {
124
+ $body = json_decode($response["body"], true);
125
+ return $body["paypalAccounts"][0]["nonce"];
126
+ } else {
127
+ throw new Exception(print_r($response, true));
128
+ }
129
+ }
130
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/HttpTest.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Braintree;
8
+
9
+ class HttpTest extends Setup
10
+ {
11
+ public function testProductionSSL()
12
+ {
13
+ try {
14
+ Braintree\Configuration::environment('production');
15
+ $this->setExpectedException('Braintree\Exception\Authentication');
16
+ $http = new Braintree\Http(Braintree\Configuration::$global);
17
+ $http->get('/');
18
+ } catch (Braintree\Exception $e) {
19
+ Braintree\Configuration::environment('development');
20
+ throw $e;
21
+ }
22
+ Braintree\Configuration::environment('development');
23
+ }
24
+
25
+ public function testSandboxSSL()
26
+ {
27
+ try {
28
+ Braintree\Configuration::environment('sandbox');
29
+ $this->setExpectedException('Braintree\Exception\Authentication');
30
+ $http = new Braintree\Http(Braintree\Configuration::$global);
31
+ $http->get('/');
32
+ } catch (Braintree\Exception $e) {
33
+ Braintree\Configuration::environment('development');
34
+ throw $e;
35
+ }
36
+ Braintree\Configuration::environment('development');
37
+ }
38
+
39
+ public function testSandboxSSLWithExplicitVersionSet()
40
+ {
41
+ try {
42
+ Braintree\Configuration::environment('sandbox');
43
+ Braintree\Configuration::sslVersion(6);
44
+ $this->setExpectedException('Braintree\Exception\Authentication');
45
+ $http = new Braintree\Http(Braintree\Configuration::$global);
46
+ $http->get('/');
47
+ } catch (Braintree\Exception $e) {
48
+ Braintree\Configuration::environment('development');
49
+ Braintree\Configuration::sslVersion(null);
50
+ throw $e;
51
+ }
52
+ Braintree\Configuration::environment('development');
53
+ Braintree\Configuration::sslVersion(null);
54
+ }
55
+
56
+ public function testSandboxSSLFailsWithIncompatibleSSLVersion()
57
+ {
58
+ try {
59
+ Braintree\Configuration::environment('sandbox');
60
+ Braintree\Configuration::sslVersion(3);
61
+ $this->setExpectedException('Braintree\Exception\SSLCertificate', null, 35);
62
+ $http = new Braintree\Http(Braintree\Configuration::$global);
63
+ $http->get('/');
64
+ } catch (Braintree\Exception $e) {
65
+ Braintree\Configuration::environment('development');
66
+ Braintree\Configuration::sslVersion(null);
67
+ throw $e;
68
+ }
69
+ Braintree\Configuration::environment('development');
70
+ Braintree\Configuration::sslVersion(null);
71
+ }
72
+
73
+ public function testSslError()
74
+ {
75
+ try {
76
+ Braintree\Configuration::environment('sandbox');
77
+ $this->setExpectedException('Braintree\Exception\SSLCertificate', null, 3);
78
+ $http = new Braintree\Http(Braintree\Configuration::$global);
79
+ $http->_doUrlRequest('get', '/malformed_url');
80
+ } catch (Braintree\Exception $e) {
81
+ Braintree\Configuration::environment('development');
82
+ throw $e;
83
+ }
84
+ Braintree\Configuration::environment('development');
85
+ }
86
+
87
+ public function testAcceptGzipEncodingSetFalse()
88
+ {
89
+ $originalGzipEncoding = Braintree\Configuration::acceptGzipEncoding();
90
+ Braintree\Configuration::acceptGzipEncoding(false);
91
+ try {
92
+ $result = Braintree\Customer::create([
93
+ 'firstName' => 'Mike',
94
+ 'lastName' => 'Jones',
95
+ 'company' => 'Jones Co.',
96
+ 'email' => 'mike.jones@example.com',
97
+ 'phone' => '419.555.1234',
98
+ 'fax' => '419.555.1235',
99
+ 'website' => 'http://example.com'
100
+ ]);
101
+ $this->assertEquals(true, $result->success);
102
+ $customer = $result->customer;
103
+ $this->assertEquals('Mike', $customer->firstName);
104
+ } catch(Braintree\Exception $e) {
105
+ Braintree\Configuration::acceptGzipEncoding($originalGzipEncoding);
106
+ throw $e;
107
+ }
108
+ Braintree\Configuration::acceptGzipEncoding($originalGzipEncoding);
109
+ }
110
+
111
+ public function testAcceptGzipEncodingSetToTrue()
112
+ {
113
+ $originalGzipEncoding = Braintree\Configuration::acceptGzipEncoding();
114
+ Braintree\Configuration::acceptGzipEncoding(true);
115
+ try {
116
+ $result = Braintree\Customer::create([
117
+ 'firstName' => 'Mike',
118
+ 'lastName' => 'Jones',
119
+ 'company' => 'Jones Co.',
120
+ 'email' => 'mike.jones@example.com',
121
+ 'phone' => '419.555.1234',
122
+ 'fax' => '419.555.1235',
123
+ 'website' => 'http://example.com'
124
+ ]);
125
+ $this->assertEquals(true, $result->success);
126
+ $customer = $result->customer;
127
+ $this->assertEquals('Mike', $customer->firstName);
128
+ } catch(Braintree\Exception $e) {
129
+ Braintree\Configuration::acceptGzipEncoding($originalGzipEncoding);
130
+ throw $e;
131
+ }
132
+ Braintree\Configuration::acceptGzipEncoding($originalGzipEncoding);
133
+ }
134
+
135
+ public function testAuthorizationWithConfig()
136
+ {
137
+ $config = new Braintree\Configuration([
138
+ 'environment' => 'development',
139
+ 'merchant_id' => 'integration_merchant_id',
140
+ 'publicKey' => 'badPublicKey',
141
+ 'privateKey' => 'badPrivateKey'
142
+ ]);
143
+
144
+ $http = new Braintree\Http($config);
145
+ $result = $http->_doUrlRequest('GET', $config->baseUrl() . '/merchants/integration_merchant_id/customers');
146
+ $this->assertEquals(401, $result['status']);
147
+ }
148
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/IdealPaymentTest.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class IdealPaymentTest extends Setup
11
+ {
12
+ public function testFindIdealPayment()
13
+ {
14
+ $http = new HttpClientApi(Braintree\Configuration::$global);
15
+ $idealPaymentId = Test\Helper::generateValidIdealPaymentId();
16
+
17
+ $foundIdealPayment= Braintree\IdealPayment::find($idealPaymentId);
18
+ $this->assertInstanceOf('Braintree\IdealPayment', $foundIdealPayment);
19
+ $this->assertRegExp('/^idealpayment_\w{6,}$/', $foundIdealPayment->id);
20
+ $this->assertRegExp('/^\d{16,}$/', $foundIdealPayment->idealTransactionId);
21
+ $this->assertNotNull($foundIdealPayment->currency);
22
+ $this->assertNotNull($foundIdealPayment->amount);
23
+ $this->assertEquals('COMPLETE', $foundIdealPayment->status);
24
+ $this->assertEquals('ABC123', $foundIdealPayment->orderId);
25
+ $this->assertNotNull($foundIdealPayment->issuer);
26
+ $this->assertRegExp('/^https:\/\//', $foundIdealPayment->approvalUrl);
27
+ $this->assertNotNull($foundIdealPayment->ibanBankAccount->maskedIban);
28
+ $this->assertNotNull($foundIdealPayment->ibanBankAccount->bic);
29
+ $this->assertNotNull($foundIdealPayment->ibanBankAccount->ibanCountry);
30
+ $this->assertNotNull($foundIdealPayment->ibanBankAccount->description);
31
+ $this->assertRegExp('/^\d{4}$/', $foundIdealPayment->ibanBankAccount->ibanAccountNumberLast4);
32
+ }
33
+
34
+ public function testFindIdealPayment_throwsIfCannotBeFound()
35
+ {
36
+ $this->setExpectedException('Braintree\Exception\NotFound');
37
+ Braintree\IdealPayment::find(Test\Helper::generateInvalidIdealPaymentId());
38
+ }
39
+
40
+ public function testSale_createsASaleUsingId()
41
+ {
42
+ $http = new HttpClientApi(Braintree\Configuration::$global);
43
+ $idealPaymentId = Test\Helper::generateValidIdealPaymentId();
44
+
45
+ $result = Braintree\IdealPayment::sale($idealPaymentId, [
46
+ 'merchantAccountId' => 'ideal_merchant_account',
47
+ 'amount' => '100.00',
48
+ 'orderId' => 'ABC123'
49
+ ]);
50
+
51
+ $this->assertTrue($result->success);
52
+ $transaction = $result->transaction;
53
+ $this->assertEquals(Braintree\Transaction::SETTLED, $transaction->status);
54
+ $this->assertEquals(Braintree\Transaction::SALE, $transaction->type);
55
+ $this->assertEquals('100.00', $transaction->amount);
56
+ $this->assertRegExp('/^idealpayment_\w{6,}$/', $transaction->idealPayment->idealPaymentId);
57
+ $this->assertRegExp('/^\d{16,}$/', $transaction->idealPayment->idealTransactionId);
58
+ $this->assertRegExp('/^https:\/\//', $transaction->idealPayment->imageUrl);
59
+ $this->assertNotNull($transaction->idealPayment->maskedIban);
60
+ $this->assertNotNull($transaction->idealPayment->bic);
61
+ }
62
+
63
+ public function testSale_createsASaleWithNotCompletePayment()
64
+ {
65
+ $http = new HttpClientApi(Braintree\Configuration::$global);
66
+ $idealPaymentId = Test\Helper::generateValidIdealPaymentId('3.00');
67
+
68
+ $result = Braintree\IdealPayment::sale($idealPaymentId, [
69
+ 'merchantAccountId' => 'ideal_merchant_account',
70
+ 'amount' => '3.00',
71
+ 'orderId' => 'ABC123'
72
+ ]);
73
+
74
+ $this->assertFalse($result->success);
75
+ $baseErrors = $result->errors->forKey('transaction')->onAttribute('paymentMethodNonce');
76
+ $this->assertEquals(Braintree\Error\Codes::TRANSACTION_IDEAL_PAYMENT_NOT_COMPLETE, $baseErrors[0]->code);
77
+ }
78
+
79
+ public function testSale_createsASaleUsingInvalidId()
80
+ {
81
+ $http = new HttpClientApi(Braintree\Configuration::$global);
82
+
83
+ $result = Braintree\IdealPayment::sale('invalid_id', [
84
+ 'merchantAccountId' => 'ideal_merchant_account',
85
+ 'amount' => '100.00',
86
+ 'orderId' => 'ABC123'
87
+ ]);
88
+
89
+ $this->assertFalse($result->success);
90
+ $baseErrors = $result->errors->forKey('transaction')->onAttribute('paymentMethodNonce');
91
+ $this->assertEquals(Braintree\Error\Codes::TRANSACTION_PAYMENT_METHOD_NONCE_UNKNOWN, $baseErrors[0]->code);
92
+ }
93
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/MasterpassCardTest.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Braintree\CreditCardNumbers\CardTypeIndicators;
8
+ use Test\Setup;
9
+ use Braintree;
10
+
11
+ class MasterpassCardTest extends Setup
12
+ {
13
+ public function testCreateWithMasterpassCardNonce()
14
+ {
15
+ $customer = Braintree\Customer::createNoValidate();
16
+ $result = Braintree\PaymentMethod::create([
17
+ 'customerId' => $customer->id,
18
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$masterpassDiscover,
19
+ ]);
20
+
21
+ $this->assertTrue($result->success);
22
+ $masterpassCard = $result->paymentMethod;
23
+ $this->assertSame(Braintree\CreditCard::DISCOVER, $masterpassCard->cardType);
24
+ $this->assertTrue($masterpassCard->default);
25
+ $this->assertContains('discover', $masterpassCard->imageUrl);
26
+ $this->assertTrue(intval($masterpassCard->expirationMonth) > 0);
27
+ $this->assertTrue(intval($masterpassCard->expirationYear) > 0);
28
+ $this->assertSame($customer->id, $masterpassCard->customerId);
29
+ $this->assertSame($masterpassCard->last4, '1117');
30
+ $this->assertSame($masterpassCard->maskedNumber, '601111******1117');
31
+
32
+ $this->assertNotNull($masterpassCard->billingAddress);
33
+ $this->assertNotNull($masterpassCard->bin);
34
+ $this->assertNotNull($masterpassCard->cardType);
35
+ $this->assertNotNull($masterpassCard->cardholderName);
36
+ $this->assertNotNull($masterpassCard->commercial);
37
+ $this->assertNotNull($masterpassCard->countryOfIssuance);
38
+ $this->assertNotNull($masterpassCard->createdAt);
39
+ $this->assertNotNull($masterpassCard->customerId);
40
+ $this->assertNotNull($masterpassCard->customerLocation);
41
+ $this->assertNotNull($masterpassCard->debit);
42
+ $this->assertNotNull($masterpassCard->default);
43
+ $this->assertNotNull($masterpassCard->durbinRegulated);
44
+ $this->assertNotNull($masterpassCard->expirationDate);
45
+ $this->assertNotNull($masterpassCard->expirationMonth);
46
+ $this->assertNotNull($masterpassCard->expirationYear);
47
+ $this->assertNotNull($masterpassCard->expired);
48
+ $this->assertNotNull($masterpassCard->healthcare);
49
+ $this->assertNotNull($masterpassCard->imageUrl);
50
+ $this->assertNotNull($masterpassCard->issuingBank);
51
+ $this->assertNotNull($masterpassCard->last4);
52
+ $this->assertNotNull($masterpassCard->maskedNumber);
53
+ $this->assertNotNull($masterpassCard->payroll);
54
+ $this->assertNotNull($masterpassCard->prepaid);
55
+ $this->assertNotNull($masterpassCard->productId);
56
+ $this->assertNotNull($masterpassCard->subscriptions);
57
+ $this->assertNotNull($masterpassCard->token);
58
+ $this->assertNotNull($masterpassCard->uniqueNumberIdentifier);
59
+ $this->assertNotNull($masterpassCard->updatedAt);
60
+ }
61
+
62
+ public function testTransactionSearchWithMasterpass()
63
+ {
64
+ $transaction = Braintree\Transaction::saleNoValidate([
65
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
66
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$masterpassDiscover,
67
+ ]);
68
+
69
+ $collection = Braintree\Transaction::search([
70
+ Braintree\TransactionSearch::id()->is($transaction->id),
71
+ Braintree\TransactionSearch::paymentInstrumentType()->is(Braintree\PaymentInstrumentType::MASTERPASS_CARD)
72
+ ]);
73
+
74
+
75
+ $this->assertEquals($transaction->paymentInstrumentType, Braintree\PaymentInstrumentType::MASTERPASS_CARD);
76
+ $this->assertEquals($transaction->id, $collection->firstItem()->id);
77
+ }
78
+
79
+ public function testCreateCustomerwithMasterpassCard()
80
+ {
81
+ $nonce = Braintree\Test\Nonces::$masterpassDiscover;
82
+ $result = Braintree\Customer::create([
83
+ 'paymentMethodNonce' => $nonce
84
+ ]);
85
+ $this->assertTrue($result->success);
86
+ $customer = $result->customer;
87
+ $this->assertNotNull($customer->masterpassCards[0]);
88
+ $this->assertNotNull($customer->paymentMethods[0]);
89
+ }
90
+
91
+ public function testCreateTransactionWithMasterpassNonceAndVault()
92
+ {
93
+ $result = Braintree\Transaction::sale([
94
+ 'amount' => '47.00',
95
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$masterpassAmEx,
96
+ 'options' => [
97
+ 'storeInVault' => true
98
+ ]
99
+ ]);
100
+
101
+ $this->assertTrue($result->success);
102
+ $transaction = $result->transaction;
103
+ $this->assertEquals('47.00', $transaction->amount);
104
+ $masterpassCardDetails = $transaction->masterpassCardDetails;
105
+ $this->assertSame(Braintree\CreditCard::AMEX, $masterpassCardDetails->cardType);
106
+
107
+ $this->assertNotNull($masterpassCardDetails->bin);
108
+ $this->assertNotNull($masterpassCardDetails->cardType);
109
+ $this->assertNotNull($masterpassCardDetails->cardholderName);
110
+ $this->assertNotNull($masterpassCardDetails->commercial);
111
+ $this->assertNotNull($masterpassCardDetails->countryOfIssuance);
112
+ $this->assertNotNull($masterpassCardDetails->customerLocation);
113
+ $this->assertNotNull($masterpassCardDetails->debit);
114
+ $this->assertNotNull($masterpassCardDetails->durbinRegulated);
115
+ $this->assertNotNull($masterpassCardDetails->expirationDate);
116
+ $this->assertNotNull($masterpassCardDetails->expirationMonth);
117
+ $this->assertNotNull($masterpassCardDetails->expirationYear);
118
+ $this->assertNotNull($masterpassCardDetails->healthcare);
119
+ $this->assertNotNull($masterpassCardDetails->imageUrl);
120
+ $this->assertNotNull($masterpassCardDetails->issuingBank);
121
+ $this->assertNotNull($masterpassCardDetails->last4);
122
+ $this->assertNotNull($masterpassCardDetails->maskedNumber);
123
+ $this->assertNotNull($masterpassCardDetails->payroll);
124
+ $this->assertNotNull($masterpassCardDetails->prepaid);
125
+ $this->assertNotNull($masterpassCardDetails->productId);
126
+ $this->assertNotNull($masterpassCardDetails->token);
127
+ }
128
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/MerchantAccountTest.php ADDED
@@ -0,0 +1,631 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class MerchantAccountTest extends Setup
11
+ {
12
+ private static $deprecatedValidParams = [
13
+ 'applicantDetails' => [
14
+ 'companyName' => "Robot City",
15
+ 'firstName' => "Joe",
16
+ 'lastName' => "Bloggs",
17
+ 'email' => "joe@bloggs.com",
18
+ 'phone' => "555-555-5555",
19
+ 'address' => [
20
+ 'streetAddress' => "123 Credibility St.",
21
+ 'postalCode' => "60606",
22
+ 'locality' => "Chicago",
23
+ 'region' => "IL",
24
+ ],
25
+ 'dateOfBirth' => "10/9/1980",
26
+ 'ssn' => "123-00-1234",
27
+ 'taxId' => "123456789",
28
+ 'routingNumber' => "122100024",
29
+ 'accountNumber' => "43759348798"
30
+ ],
31
+ 'tosAccepted' => true,
32
+ 'masterMerchantAccountId' => "sandbox_master_merchant_account"
33
+ ];
34
+
35
+ private static $validParams = [
36
+ 'individual' => [
37
+ 'firstName' => "Joe",
38
+ 'lastName' => "Bloggs",
39
+ 'email' => "joe@bloggs.com",
40
+ 'phone' => "555-555-5555",
41
+ 'address' => [
42
+ 'streetAddress' => "123 Credibility St.",
43
+ 'postalCode' => "60606",
44
+ 'locality' => "Chicago",
45
+ 'region' => "IL",
46
+ ],
47
+ 'dateOfBirth' => "10/9/1980",
48
+ 'ssn' => "123-00-1234",
49
+ ],
50
+ 'business' => [
51
+ 'dbaName' => "Robot City",
52
+ 'legalName' => "Robot City INC",
53
+ 'taxId' => "123456789",
54
+ ],
55
+ 'funding' => [
56
+ 'routingNumber' => "122100024",
57
+ 'accountNumber' => "43759348798",
58
+ 'destination' => Braintree\MerchantAccount::FUNDING_DESTINATION_BANK,
59
+ 'descriptor' => 'Joes Bloggs MI',
60
+ ],
61
+ 'tosAccepted' => true,
62
+ 'masterMerchantAccountId' => "sandbox_master_merchant_account"
63
+ ];
64
+
65
+ public function testCreate()
66
+ {
67
+ $result = Braintree\MerchantAccount::create(self::$validParams);
68
+ $this->assertEquals(true, $result->success);
69
+ $merchantAccount = $result->merchantAccount;
70
+ $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $merchantAccount->status);
71
+ $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
72
+ }
73
+
74
+ public function testGatewayCreate()
75
+ {
76
+ $gateway = new Braintree\Gateway([
77
+ 'environment' => 'development',
78
+ 'merchantId' => 'integration_merchant_id',
79
+ 'publicKey' => 'integration_public_key',
80
+ 'privateKey' => 'integration_private_key'
81
+ ]);
82
+ $result = $gateway->merchantAccount()->create(self::$validParams);
83
+ $this->assertEquals(true, $result->success);
84
+ $merchantAccount = $result->merchantAccount;
85
+ $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $merchantAccount->status);
86
+ $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
87
+ }
88
+
89
+ public function testCreateWithDeprecatedParameters()
90
+ {
91
+ Test\Helper::suppressDeprecationWarnings();
92
+ $result = Braintree\MerchantAccount::create(self::$deprecatedValidParams);
93
+ $this->assertEquals(true, $result->success);
94
+ $merchantAccount = $result->merchantAccount;
95
+ $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $merchantAccount->status);
96
+ $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
97
+ }
98
+
99
+ public function testCreateWithId()
100
+ {
101
+ $rand = rand(1, 1000);
102
+ $subMerchantAccountId = "sub_merchant_account_id" + $rand;
103
+ $validParamsWithId = array_merge([], self::$validParams);
104
+ $validParamsWithId['id'] = $subMerchantAccountId;
105
+ $result = Braintree\MerchantAccount::create($validParamsWithId);
106
+ $this->assertEquals(true, $result->success);
107
+ $merchantAccount = $result->merchantAccount;
108
+ $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $merchantAccount->status);
109
+ $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
110
+ $this->assertEquals("sub_merchant_account_id" + $rand, $merchantAccount->id);
111
+ }
112
+
113
+ public function testFailedCreate()
114
+ {
115
+ $result = Braintree\MerchantAccount::create([]);
116
+ $this->assertEquals(false, $result->success);
117
+ $errors = $result->errors->forKey('merchantAccount')->onAttribute('masterMerchantAccountId');
118
+ $this->assertEquals(Braintree\Error\Codes::MERCHANT_ACCOUNT_MASTER_MERCHANT_ACCOUNT_ID_IS_REQUIRED, $errors[0]->code);
119
+ }
120
+
121
+ public function testCreateWithFundingDestination()
122
+ {
123
+ $params = array_merge([], self::$validParams);
124
+ $params['funding']['destination'] = Braintree\MerchantAccount::FUNDING_DESTINATION_BANK;
125
+ $result = Braintree\MerchantAccount::create($params);
126
+ $this->assertEquals(true, $result->success);
127
+
128
+ $params = array_merge([], self::$validParams);
129
+ $params['funding']['destination'] = Braintree\MerchantAccount::FUNDING_DESTINATION_EMAIL;
130
+ $params['funding']['email'] = "billgates@outlook.com";
131
+ $result = Braintree\MerchantAccount::create($params);
132
+ $this->assertEquals(true, $result->success);
133
+
134
+ $params = array_merge([], self::$validParams);
135
+ $params['funding']['destination'] = Braintree\MerchantAccount::FUNDING_DESTINATION_MOBILE_PHONE;
136
+ $params['funding']['mobilePhone'] = "1112224444";
137
+ $result = Braintree\MerchantAccount::create($params);
138
+ $this->assertEquals(true, $result->success);
139
+ }
140
+
141
+ public function testFind()
142
+ {
143
+ $params = array_merge([], self::$validParams);
144
+ $result = Braintree\MerchantAccount::create(self::$validParams);
145
+ $this->assertEquals(true, $result->success);
146
+ $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $result->merchantAccount->status);
147
+
148
+ $id = $result->merchantAccount->id;
149
+ $merchantAccount = Braintree\MerchantAccount::find($id);
150
+
151
+ $this->assertEquals(Braintree\MerchantAccount::STATUS_ACTIVE, $merchantAccount->status);
152
+ $this->assertEquals($params['individual']['firstName'], $merchantAccount->individualDetails->firstName);
153
+ $this->assertEquals($params['individual']['lastName'], $merchantAccount->individualDetails->lastName);
154
+ }
155
+
156
+ public function testRetrievesMasterMerchantAccountCurrencyIsoCode()
157
+ {
158
+ $merchantAccount = Braintree\MerchantAccount::find("sandbox_master_merchant_account");
159
+
160
+ $this->assertEquals("USD", $merchantAccount->currencyIsoCode);
161
+ }
162
+
163
+ public function testFind_throwsIfNotFound()
164
+ {
165
+ $this->setExpectedException('Braintree\Exception\NotFound', 'merchant account with id does-not-exist not found');
166
+ Braintree\MerchantAccount::find('does-not-exist');
167
+ }
168
+
169
+ public function testUpdate()
170
+ {
171
+ $params = array_merge([], self::$validParams);
172
+ unset($params["tosAccepted"]);
173
+ unset($params["masterMerchantAccountId"]);
174
+ $params["individual"]["firstName"] = "John";
175
+ $params["individual"]["lastName"] = "Doe";
176
+ $params["individual"]["email"] = "john.doe@example.com";
177
+ $params["individual"]["dateOfBirth"] = "1970-01-01";
178
+ $params["individual"]["phone"] = "3125551234";
179
+ $params["individual"]["address"]["streetAddress"] = "123 Fake St";
180
+ $params["individual"]["address"]["locality"] = "Chicago";
181
+ $params["individual"]["address"]["region"] = "IL";
182
+ $params["individual"]["address"]["postalCode"] = "60622";
183
+ $params["business"]["dbaName"] = "James's Bloggs";
184
+ $params["business"]["legalName"] = "James's Bloggs Inc";
185
+ $params["business"]["taxId"] = "123456789";
186
+ $params["business"]["address"]["streetAddress"] = "999 Fake St";
187
+ $params["business"]["address"]["locality"] = "Miami";
188
+ $params["business"]["address"]["region"] = "FL";
189
+ $params["business"]["address"]["postalCode"] = "99999";
190
+ $params["funding"]["accountNumber"] = "43759348798";
191
+ $params["funding"]["routingNumber"] = "071000013";
192
+ $params["funding"]["email"] = "check@this.com";
193
+ $params["funding"]["mobilePhone"] = "1234567890";
194
+ $params["funding"]["destination"] = Braintree\MerchantAccount::FUNDING_DESTINATION_BANK;
195
+ $params["funding"]["descriptor"] = "Joes Bloggs FL";
196
+
197
+ $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
198
+ $this->assertEquals(true, $result->success);
199
+
200
+ $updatedMerchantAccount = $result->merchantAccount;
201
+ $this->assertEquals("active", $updatedMerchantAccount->status);
202
+ $this->assertEquals("sandbox_sub_merchant_account", $updatedMerchantAccount->id);
203
+ $this->assertEquals("sandbox_master_merchant_account", $updatedMerchantAccount->masterMerchantAccount->id);
204
+ $this->assertEquals("John", $updatedMerchantAccount->individualDetails->firstName);
205
+ $this->assertEquals("Doe", $updatedMerchantAccount->individualDetails->lastName);
206
+ $this->assertEquals("john.doe@example.com", $updatedMerchantAccount->individualDetails->email);
207
+ $this->assertEquals("1970-01-01", $updatedMerchantAccount->individualDetails->dateOfBirth);
208
+ $this->assertEquals("3125551234", $updatedMerchantAccount->individualDetails->phone);
209
+ $this->assertEquals("123 Fake St", $updatedMerchantAccount->individualDetails->addressDetails->streetAddress);
210
+ $this->assertEquals("Chicago", $updatedMerchantAccount->individualDetails->addressDetails->locality);
211
+ $this->assertEquals("IL", $updatedMerchantAccount->individualDetails->addressDetails->region);
212
+ $this->assertEquals("60622", $updatedMerchantAccount->individualDetails->addressDetails->postalCode);
213
+ $this->assertEquals("James's Bloggs", $updatedMerchantAccount->businessDetails->dbaName);
214
+ $this->assertEquals("James's Bloggs Inc", $updatedMerchantAccount->businessDetails->legalName);
215
+ $this->assertEquals("123456789", $updatedMerchantAccount->businessDetails->taxId);
216
+ $this->assertEquals("999 Fake St", $updatedMerchantAccount->businessDetails->addressDetails->streetAddress);
217
+ $this->assertEquals("Miami", $updatedMerchantAccount->businessDetails->addressDetails->locality);
218
+ $this->assertEquals("FL", $updatedMerchantAccount->businessDetails->addressDetails->region);
219
+ $this->assertEquals("99999", $updatedMerchantAccount->businessDetails->addressDetails->postalCode);
220
+ $this->assertEquals("8798", $updatedMerchantAccount->fundingDetails->accountNumberLast4);
221
+ $this->assertEquals("071000013", $updatedMerchantAccount->fundingDetails->routingNumber);
222
+ $this->assertEquals("check@this.com", $updatedMerchantAccount->fundingDetails->email);
223
+ $this->assertEquals("1234567890", $updatedMerchantAccount->fundingDetails->mobilePhone);
224
+ $this->assertEquals(Braintree\MerchantAccount::FUNDING_DESTINATION_BANK, $updatedMerchantAccount->fundingDetails->destination);
225
+ $this->assertEquals("Joes Bloggs FL", $updatedMerchantAccount->fundingDetails->descriptor);
226
+ }
227
+
228
+ public function testUpdateDoesNotRequireAllFields()
229
+ {
230
+ $params = [
231
+ 'individual' => [
232
+ 'firstName' => "Joe"
233
+ ]
234
+ ];
235
+ $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
236
+ $this->assertEquals(true, $result->success);
237
+ }
238
+
239
+ public function testUpdateWithBlankFields()
240
+ {
241
+ $params = [
242
+ 'individual' => [
243
+ 'firstName' => "",
244
+ 'lastName' => "",
245
+ 'email' => "",
246
+ 'phone' => "",
247
+ 'address' => [
248
+ 'streetAddress' => "",
249
+ 'postalCode' => "",
250
+ 'locality' => "",
251
+ 'region' => "",
252
+ ],
253
+ 'dateOfBirth' => "",
254
+ 'ssn' => "",
255
+ ],
256
+ 'business' => [
257
+ 'dbaName' => "",
258
+ 'legalName' => "",
259
+ 'taxId' => "",
260
+ ],
261
+ 'funding' => [
262
+ 'routingNumber' => "",
263
+ 'accountNumber' => "",
264
+ 'destination' => "",
265
+ ],
266
+ ];
267
+
268
+ $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
269
+ $this->assertEquals(false, $result->success);
270
+
271
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("firstName");
272
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_REQUIRED);
273
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("lastName");
274
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_REQUIRED);
275
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("dateOfBirth");
276
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_DATE_OF_BIRTH_IS_REQUIRED);
277
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("email");
278
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_REQUIRED);
279
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("streetAddress");
280
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_REQUIRED);
281
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("postalCode");
282
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_REQUIRED);
283
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("locality");
284
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_LOCALITY_IS_REQUIRED);
285
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("region");
286
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_REQUIRED);
287
+ $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("destination");
288
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_REQUIRED);
289
+ }
290
+
291
+ public function testUpdateWithInvalidFields()
292
+ {
293
+ $params = [
294
+ "individual" => [
295
+ "firstName" => "<>",
296
+ "lastName" => "<>",
297
+ "email" => "bad",
298
+ "phone" => "999",
299
+ "address" => [
300
+ "streetAddress" => "nope",
301
+ "postalCode" => "1",
302
+ "region" => "QQ",
303
+ ],
304
+ "dateOfBirth" => "hah",
305
+ "ssn" => "12345",
306
+ ],
307
+ "business" => [
308
+ "legalName" => "``{}",
309
+ "dbaName" => "{}``",
310
+ "taxId" => "bad",
311
+ "address" => [
312
+ "streetAddress" => "nope",
313
+ "postalCode" => "1",
314
+ "region" => "QQ",
315
+ ],
316
+ ],
317
+ "funding" => [
318
+ "destination" => "MY WALLET",
319
+ "routingNumber" => "LEATHER",
320
+ "accountNumber" => "BACK POCKET",
321
+ "email" => "BILLFOLD",
322
+ "mobilePhone" => "TRIFOLD"
323
+ ],
324
+ ];
325
+
326
+
327
+ $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
328
+ $this->assertEquals(false, $result->success);
329
+
330
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("firstName");
331
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_INVALID);
332
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("lastName");
333
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_INVALID);
334
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("email");
335
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_INVALID);
336
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("phone");
337
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_PHONE_IS_INVALID);
338
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("streetAddress");
339
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_INVALID);
340
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("postalCode");
341
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_INVALID);
342
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("region");
343
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_INVALID);
344
+ $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("ssn");
345
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_INDIVIDUAL_SSN_IS_INVALID);
346
+ ;
347
+ $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("legalName");
348
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_LEGAL_NAME_IS_INVALID);
349
+ $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("dbaName");
350
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_DBA_NAME_IS_INVALID);
351
+ $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("taxId");
352
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_TAX_ID_IS_INVALID);
353
+ $error = $result->errors->forKey("merchantAccount")->forKey("business")->forKey("address")->onAttribute("streetAddress");
354
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_ADDRESS_STREET_ADDRESS_IS_INVALID);
355
+ $error = $result->errors->forKey("merchantAccount")->forKey("business")->forKey("address")->onAttribute("postalCode");
356
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_ADDRESS_POSTAL_CODE_IS_INVALID);
357
+ $error = $result->errors->forKey("merchantAccount")->forKey("business")->forKey("address")->onAttribute("region");
358
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_ADDRESS_REGION_IS_INVALID);
359
+
360
+ $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("destination");
361
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_INVALID);
362
+ $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("routingNumber");
363
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_ROUTING_NUMBER_IS_INVALID);
364
+ $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("accountNumber");
365
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_ACCOUNT_NUMBER_IS_INVALID);
366
+ $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("email");
367
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_EMAIL_IS_INVALID);
368
+ $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("mobilePhone");
369
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_MOBILE_PHONE_IS_INVALID);
370
+ }
371
+
372
+ public function testUpdateWithInvalidBusinessFields()
373
+ {
374
+ $params = [
375
+ "business" => [
376
+ "legalName" => "",
377
+ "taxId" => "111223333",
378
+ ]
379
+ ];
380
+
381
+ $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
382
+ $this->assertEquals(false, $result->success);
383
+
384
+ $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("legalName");
385
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_LEGAL_NAME_IS_REQUIRED_WITH_TAX_ID);
386
+ $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("taxId");
387
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_TAX_ID_MUST_BE_BLANK);
388
+
389
+ $params = [
390
+ "business" => [
391
+ "legalName" => "legal name",
392
+ "taxId" => "",
393
+ ]
394
+ ];
395
+
396
+ $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
397
+ $this->assertEquals(false, $result->success);
398
+
399
+ $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("taxId");
400
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_BUSINESS_TAX_ID_IS_REQUIRED_WITH_LEGAL_NAME);
401
+ }
402
+
403
+ public function testUpdateWithInvalidFundingFields()
404
+ {
405
+ $params = [
406
+ "funding" => [
407
+ "destination" => Braintree\MerchantAccount::FUNDING_DESTINATION_EMAIL,
408
+ "email" => "",
409
+ ]
410
+ ];
411
+
412
+ $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
413
+ $this->assertEquals(false, $result->success);
414
+
415
+ $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("email");
416
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_EMAIL_IS_REQUIRED);
417
+
418
+ $params = [
419
+ "funding" => [
420
+ "destination" => Braintree\MerchantAccount::FUNDING_DESTINATION_MOBILE_PHONE,
421
+ "mobilePhone" => "",
422
+ ]
423
+ ];
424
+
425
+ $result = Braintree\MerchantAccount::update("sandbox_sub_merchant_account", $params);
426
+ $this->assertEquals(false, $result->success);
427
+
428
+ $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("mobilePhone");
429
+ $this->assertEquals($error[0]->code, Braintree\Error\Codes::MERCHANT_ACCOUNT_FUNDING_MOBILE_PHONE_IS_REQUIRED);
430
+ }
431
+
432
+ public function testCreateForCurrency()
433
+ {
434
+ $gateway = new Braintree\Gateway([
435
+ 'clientId' => 'client_id$development$signup_client_id',
436
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
437
+ ]);
438
+ $result = $gateway->merchant()->create([
439
+ 'email' => 'name@email.com',
440
+ 'countryCodeAlpha3' => 'GBR',
441
+ 'paymentMethods' => ['credit_card', 'paypal'],
442
+ ]);
443
+
444
+ $this->assertEquals(true, $result->success);
445
+
446
+ $gateway = new Braintree\Gateway([
447
+ 'accessToken' => $result->credentials->accessToken,
448
+ ]);
449
+
450
+ $result = $gateway->merchantAccount()->createForCurrency([
451
+ 'currency' => "USD",
452
+ ]);
453
+
454
+ $this->assertEquals(true, $result->success);
455
+
456
+ $merchantAccount = $result->merchantAccount;
457
+ $this->assertEquals("USD", $merchantAccount->currencyIsoCode);
458
+ $this->assertEquals("USD", $merchantAccount->id);
459
+ }
460
+
461
+ public function testCreateForCurrencyWithDuplicateCurrency()
462
+ {
463
+ $gateway = new Braintree\Gateway([
464
+ 'clientId' => 'client_id$development$signup_client_id',
465
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
466
+ ]);
467
+ $result = $gateway->merchant()->create([
468
+ 'email' => 'name@email.com',
469
+ 'countryCodeAlpha3' => 'GBR',
470
+ 'paymentMethods' => ['credit_card', 'paypal'],
471
+ ]);
472
+
473
+ $this->assertEquals(true, $result->success);
474
+
475
+ $gateway = new Braintree\Gateway([
476
+ 'accessToken' => $result->credentials->accessToken,
477
+ ]);
478
+
479
+ $merchantAccount = $result->merchant->merchantAccounts[0];
480
+ $result = $gateway->merchantAccount()->createForCurrency([
481
+ 'currency' => "GBP",
482
+ ]);
483
+
484
+ $this->assertEquals(false, $result->success);
485
+
486
+ $errors = $result->errors->forKey('merchant')->onAttribute('currency');
487
+ $this->assertEquals(Braintree\Error\Codes::MERCHANT_MERCHANT_ACCOUNT_EXISTS_FOR_CURRENCY, $errors[0]->code);
488
+ }
489
+
490
+ public function testCreateForCurrencyWithInvalidCurrency()
491
+ {
492
+ $gateway = new Braintree\Gateway([
493
+ 'clientId' => 'client_id$development$signup_client_id',
494
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
495
+ ]);
496
+ $result = $gateway->merchant()->create([
497
+ 'email' => 'name@email.com',
498
+ 'countryCodeAlpha3' => 'GBR',
499
+ 'paymentMethods' => ['credit_card', 'paypal'],
500
+ ]);
501
+
502
+ $this->assertEquals(true, $result->success);
503
+
504
+ $gateway = new Braintree\Gateway([
505
+ 'accessToken' => $result->credentials->accessToken,
506
+ ]);
507
+
508
+ $result = $gateway->merchantAccount()->createForCurrency([
509
+ 'currency' => "FAKE_CURRENCY",
510
+ ]);
511
+
512
+ $this->assertEquals(false, $result->success);
513
+
514
+ $errors = $result->errors->forKey('merchant')->onAttribute('currency');
515
+ $this->assertEquals(Braintree\Error\Codes::MERCHANT_CURRENCY_IS_INVALID, $errors[0]->code);
516
+ }
517
+
518
+ public function testCreateForCurrencyWithoutCurrency()
519
+ {
520
+ $gateway = new Braintree\Gateway([
521
+ 'clientId' => 'client_id$development$signup_client_id',
522
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
523
+ ]);
524
+ $result = $gateway->merchant()->create([
525
+ 'email' => 'name@email.com',
526
+ 'countryCodeAlpha3' => 'GBR',
527
+ 'paymentMethods' => ['credit_card', 'paypal'],
528
+ ]);
529
+
530
+ $this->assertEquals(true, $result->success);
531
+
532
+ $gateway = new Braintree\Gateway([
533
+ 'accessToken' => $result->credentials->accessToken,
534
+ ]);
535
+
536
+ $result = $gateway->merchantAccount()->createForCurrency([]);
537
+
538
+ $this->assertEquals(false, $result->success);
539
+
540
+ $errors = $result->errors->forKey('merchant')->onAttribute('currency');
541
+ $this->assertEquals(Braintree\Error\Codes::MERCHANT_CURRENCY_IS_REQUIRED, $errors[0]->code);
542
+ }
543
+
544
+ public function testCreateForCurrencyWithDuplicateId()
545
+ {
546
+ $gateway = new Braintree\Gateway([
547
+ 'clientId' => 'client_id$development$signup_client_id',
548
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
549
+ ]);
550
+ $result = $gateway->merchant()->create([
551
+ 'email' => 'name@email.com',
552
+ 'countryCodeAlpha3' => 'GBR',
553
+ 'paymentMethods' => ['credit_card', 'paypal'],
554
+ ]);
555
+
556
+ $this->assertEquals(true, $result->success);
557
+
558
+ $gateway = new Braintree\Gateway([
559
+ 'accessToken' => $result->credentials->accessToken,
560
+ ]);
561
+
562
+ $merchantAccount = $result->merchant->merchantAccounts[0];
563
+ $result = $gateway->merchantAccount()->createForCurrency([
564
+ 'currency' => "USD",
565
+ 'id' => $merchantAccount->id,
566
+ ]);
567
+
568
+ $this->assertEquals(false, $result->success);
569
+
570
+ $errors = $result->errors->forKey('merchant')->onAttribute('id');
571
+ $this->assertEquals(Braintree\Error\Codes::MERCHANT_MERCHANT_ACCOUNT_EXISTS_FOR_ID, $errors[0]->code);
572
+ }
573
+
574
+ public function testAllReturnsAllMerchantAccounts()
575
+ {
576
+ $gateway = new Braintree\Gateway([
577
+ 'clientId' => 'client_id$development$integration_client_id',
578
+ 'clientSecret' => 'client_secret$development$integration_client_secret',
579
+ ]);
580
+
581
+ $code = Test\Braintree\OAuthTestHelper::createGrant($gateway, [
582
+ 'merchant_public_id' => 'integration_merchant_id',
583
+ 'scope' => 'read_write'
584
+ ]);
585
+
586
+ $credentials = $gateway->oauth()->createTokenFromCode([
587
+ 'code' => $code,
588
+ ]);
589
+
590
+ $gateway = new Braintree\Gateway([
591
+ 'accessToken' => $credentials->accessToken
592
+ ]);
593
+
594
+ $result = $gateway->merchantAccount()->all();
595
+ $merchantAccounts = [];
596
+ foreach($result as $ma) {
597
+ array_push($merchantAccounts, $ma);
598
+ }
599
+ $this->assertEquals(true, count($merchantAccounts) > 20);
600
+ }
601
+
602
+ public function testAllReturnsMerchantAccountWithCorrectAttributes()
603
+ {
604
+ $gateway = new Braintree\Gateway([
605
+ 'clientId' => 'client_id$development$integration_client_id',
606
+ 'clientSecret' => 'client_secret$development$integration_client_secret',
607
+ ]);
608
+
609
+ $result = $gateway->merchant()->create([
610
+ 'email' => 'name@email.com',
611
+ 'countryCodeAlpha3' => 'USA',
612
+ 'paymentMethods' => ['credit_card', 'paypal'],
613
+ ]);
614
+
615
+ $gateway = new Braintree\Gateway([
616
+ 'accessToken' => $result->credentials->accessToken,
617
+ ]);
618
+
619
+ $result = $gateway->merchantAccount()->all();
620
+ $merchantAccounts = [];
621
+ foreach($result as $ma) {
622
+ array_push($merchantAccounts, $ma);
623
+ }
624
+
625
+ $this->assertEquals(1, count($merchantAccounts));
626
+ $merchantAccount = $merchantAccounts[0];
627
+ $this->assertEquals("USD", $merchantAccount->currencyIsoCode);
628
+ $this->assertEquals(Braintree\MerchantAccount::STATUS_ACTIVE, $merchantAccount->status);
629
+ $this->assertTrue($merchantAccount->default);
630
+ }
631
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/MerchantTest.php ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class MerchantTest extends Setup
11
+ {
12
+ public function testCreateMerchant()
13
+ {
14
+ $gateway = new Braintree\Gateway([
15
+ 'clientId' => 'client_id$development$integration_client_id',
16
+ 'clientSecret' => 'client_secret$development$integration_client_secret',
17
+ ]);
18
+ $result = $gateway->merchant()->create([
19
+ 'email' => 'name@email.com',
20
+ 'countryCodeAlpha3' => 'USA',
21
+ 'paymentMethods' => ['credit_card', 'paypal'],
22
+ ]);
23
+
24
+ $this->assertEquals(true, $result->success);
25
+ $merchant = $result->merchant;
26
+ $this->assertNotNull($merchant->id);
27
+ $credentials = $result->credentials;
28
+ $this->assertNotNull($credentials->accessToken);
29
+ }
30
+
31
+ /**
32
+ * @expectedException Braintree\Exception\Configuration
33
+ * @expectedExceptionMessage clientId needs to be passed to Braintree\Gateway
34
+ */
35
+ public function testAssertsHasCredentials()
36
+ {
37
+ $gateway = new Braintree\Gateway([
38
+ 'clientSecret' => 'client_secret$development$integration_client_secret',
39
+ ]);
40
+ $gateway->merchant()->create([
41
+ 'email' => 'name@email.com',
42
+ 'countryCodeAlpha3' => 'USA',
43
+ ]);
44
+ }
45
+
46
+ public function testBadPaymentMethods()
47
+ {
48
+ $gateway = new Braintree\Gateway([
49
+ 'clientId' => 'client_id$development$integration_client_id',
50
+ 'clientSecret' => 'client_secret$development$integration_client_secret',
51
+ ]);
52
+ $result = $gateway->merchant()->create([
53
+ 'email' => 'name@email.com',
54
+ 'countryCodeAlpha3' => 'USA',
55
+ 'paymentMethods' => ['fake_money'],
56
+ ]);
57
+
58
+ $this->assertEquals(false, $result->success);
59
+ $errors = $result->errors->forKey('merchant')->onAttribute('paymentMethods');
60
+ $this->assertEquals(Braintree\Error\Codes::MERCHANT_ACCOUNT_PAYMENT_METHODS_ARE_INVALID, $errors[0]->code);
61
+ }
62
+
63
+ public function testCreateUSMerchantThatAcceptsMultipleCurrencies()
64
+ {
65
+ $gateway = new Braintree\Gateway([
66
+ 'clientId' => 'client_id$development$signup_client_id',
67
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
68
+ ]);
69
+ $result = $gateway->merchant()->create([
70
+ 'email' => 'name@email.com',
71
+ 'countryCodeAlpha3' => 'USA',
72
+ 'paymentMethods' => ['credit_card', 'paypal'],
73
+ 'currencies' => ['GBP', 'USD']
74
+ ]);
75
+
76
+ $this->assertEquals(true, $result->success);
77
+ $merchant = $result->merchant;
78
+ $this->assertNotNull($merchant->id);
79
+ $credentials = $result->credentials;
80
+ $this->assertNotNull($credentials->accessToken);
81
+
82
+ $merchantAccounts = $merchant->merchantAccounts;
83
+ $this->assertEquals(2, count($merchantAccounts));
84
+
85
+ $usdMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'USD');
86
+ $this->assertNotNull($usdMerchantAccount);
87
+ $this->assertEquals(true, $usdMerchantAccount->default);
88
+ $this->assertEquals('USD', $usdMerchantAccount->currencyIsoCode);
89
+
90
+ $gbpMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'GBP');
91
+ $this->assertNotNull($gbpMerchantAccount);
92
+ $this->assertEquals(false, $gbpMerchantAccount->default);
93
+ $this->assertEquals('GBP', $gbpMerchantAccount->currencyIsoCode);
94
+ }
95
+
96
+ public function testCreateEUMerchantThatAcceptsMultipleCurrencies()
97
+ {
98
+ $gateway = new Braintree\Gateway([
99
+ 'clientId' => 'client_id$development$signup_client_id',
100
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
101
+ ]);
102
+ $result = $gateway->merchant()->create([
103
+ 'email' => 'name@email.com',
104
+ 'countryCodeAlpha3' => 'GBR',
105
+ 'paymentMethods' => ['credit_card', 'paypal'],
106
+ 'currencies' => ['GBP', 'USD']
107
+ ]);
108
+
109
+ $this->assertEquals(true, $result->success);
110
+ $merchant = $result->merchant;
111
+ $this->assertNotNull($merchant->id);
112
+ $credentials = $result->credentials;
113
+ $this->assertNotNull($credentials->accessToken);
114
+
115
+ $merchantAccounts = $merchant->merchantAccounts;
116
+ $this->assertEquals(2, count($merchantAccounts));
117
+
118
+ $usdMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'USD');
119
+ $this->assertNotNull($usdMerchantAccount);
120
+ $this->assertEquals(false, $usdMerchantAccount->default);
121
+ $this->assertEquals('USD', $usdMerchantAccount->currencyIsoCode);
122
+
123
+ $gbpMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'GBP');
124
+ $this->assertNotNull($gbpMerchantAccount);
125
+ $this->assertEquals(true, $gbpMerchantAccount->default);
126
+ $this->assertEquals('GBP', $gbpMerchantAccount->currencyIsoCode);
127
+ }
128
+
129
+ public function testCreatePaypalOnlyMerchantThatAcceptsMultipleCurrencies()
130
+ {
131
+ $gateway = new Braintree\Gateway([
132
+ 'clientId' => 'client_id$development$signup_client_id',
133
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
134
+ ]);
135
+ $result = $gateway->merchant()->create([
136
+ 'email' => 'name@email.com',
137
+ 'countryCodeAlpha3' => 'USA',
138
+ 'paymentMethods' => ['paypal'],
139
+ 'currencies' => ['GBP', 'USD'],
140
+ 'paypalAccount' => [
141
+ 'clientId' => 'fake_client_id',
142
+ 'clientSecret' => 'fake_client_secret',
143
+ ]
144
+ ]);
145
+
146
+ $this->assertEquals(true, $result->success);
147
+ $merchant = $result->merchant;
148
+ $this->assertNotNull($merchant->id);
149
+ $credentials = $result->credentials;
150
+ $this->assertNotNull($credentials->accessToken);
151
+
152
+ $merchantAccounts = $merchant->merchantAccounts;
153
+ $this->assertEquals(2, count($merchantAccounts));
154
+
155
+ $usdMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'USD');
156
+ $this->assertNotNull($usdMerchantAccount);
157
+ $this->assertEquals(true, $usdMerchantAccount->default);
158
+ $this->assertEquals('USD', $usdMerchantAccount->currencyIsoCode);
159
+
160
+ $gbpMerchantAccount = $this->getMerchantAccountForCurrency($merchantAccounts, 'GBP');
161
+ $this->assertNotNull($gbpMerchantAccount);
162
+ $this->assertEquals(false, $gbpMerchantAccount->default);
163
+ $this->assertEquals('GBP', $gbpMerchantAccount->currencyIsoCode);
164
+ }
165
+
166
+ private function getMerchantAccountForCurrency($merchantAccounts, $currency)
167
+ {
168
+ foreach($merchantAccounts as $merchantAccount) {
169
+ if($merchantAccount->id == $currency) {
170
+ return $merchantAccount;
171
+ }
172
+ }
173
+ return null;
174
+ }
175
+
176
+ public function testCreatePaypalOnlyMerchantWithNoCurrenciesProvided()
177
+ {
178
+ $gateway = new Braintree\Gateway([
179
+ 'clientId' => 'client_id$development$signup_client_id',
180
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
181
+ ]);
182
+ $result = $gateway->merchant()->create([
183
+ 'email' => 'name@email.com',
184
+ 'countryCodeAlpha3' => 'JPN',
185
+ 'paymentMethods' => ['paypal'],
186
+ 'paypalAccount' => [
187
+ 'clientId' => 'fake_client_id',
188
+ 'clientSecret' => 'fake_client_secret',
189
+ ]
190
+ ]);
191
+
192
+ $this->assertEquals(true, $result->success);
193
+ $merchant = $result->merchant;
194
+ $this->assertNotNull($merchant->id);
195
+ $credentials = $result->credentials;
196
+ $this->assertNotNull($credentials->accessToken);
197
+
198
+ $merchantAccounts = $merchant->merchantAccounts;
199
+ $this->assertEquals(1, count($merchantAccounts));
200
+
201
+ $jpyMerchantAccount = $merchantAccounts[0];
202
+ $this->assertEquals(true, $jpyMerchantAccount->default);
203
+ $this->assertEquals('JPY', $jpyMerchantAccount->currencyIsoCode);
204
+ }
205
+
206
+ public function testCreatePaypalOnlyMerchantWithUnsupportedCountryCodeProvided()
207
+ {
208
+ $gateway = new Braintree\Gateway([
209
+ 'clientId' => 'client_id$development$signup_client_id',
210
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
211
+ ]);
212
+ $result = $gateway->merchant()->create([
213
+ 'email' => 'name@email.com',
214
+ 'countryCodeAlpha3' => 'YEM',
215
+ 'paymentMethods' => ['paypal'],
216
+ 'paypalAccount' => [
217
+ 'clientId' => 'fake_client_id',
218
+ 'clientSecret' => 'fake_client_secret',
219
+ ]
220
+ ]);
221
+
222
+ $this->assertEquals(true, $result->success);
223
+ $merchant = $result->merchant;
224
+ $this->assertNotNull($merchant->id);
225
+ $credentials = $result->credentials;
226
+ $this->assertNotNull($credentials->accessToken);
227
+
228
+ $merchantAccounts = $merchant->merchantAccounts;
229
+ $this->assertEquals(1, count($merchantAccounts));
230
+
231
+ $usdMerchantAccount = $merchantAccounts[0];
232
+ $this->assertEquals(true, $usdMerchantAccount->default);
233
+ $this->assertEquals('USD', $usdMerchantAccount->currencyIsoCode);
234
+ }
235
+
236
+ public function testInvalidCurrencyForMultiCurrency()
237
+ {
238
+ $gateway = new Braintree\Gateway([
239
+ 'clientId' => 'client_id$development$signup_client_id',
240
+ 'clientSecret' => 'client_secret$development$signup_client_secret',
241
+ ]);
242
+ $result = $gateway->merchant()->create([
243
+ 'email' => 'name@email.com',
244
+ 'countryCodeAlpha3' => 'USA',
245
+ 'paymentMethods' => ['paypal'],
246
+ 'currencies' => ['FAKE', 'USD'],
247
+ 'paypalAccount' => [
248
+ 'clientId' => 'fake_client_id',
249
+ 'clientSecret' => 'fake_client_secret',
250
+ ]
251
+ ]);
252
+
253
+ $this->assertEquals(false, $result->success);
254
+ $errors = $result->errors->forKey('merchant')->onAttribute('currencies');
255
+ $this->assertEquals(Braintree\Error\Codes::MERCHANT_CURRENCIES_ARE_INVALID, $errors[0]->code);
256
+ }
257
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/MultipleValueNodeTest.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class MultipleValueNodeTest extends Setup
11
+ {
12
+ public function testIn_singleValue()
13
+ {
14
+ $creditCard = SubscriptionHelper::createCreditCard();
15
+ $triallessPlan = SubscriptionHelper::triallessPlan();
16
+
17
+ $activeSubscription = Braintree\Subscription::create([
18
+ 'paymentMethodToken' => $creditCard->token,
19
+ 'planId' => $triallessPlan['id'],
20
+ 'price' => '3'
21
+ ])->subscription;
22
+
23
+ $canceledSubscription = Braintree\Subscription::create([
24
+ 'paymentMethodToken' => $creditCard->token,
25
+ 'planId' => $triallessPlan['id'],
26
+ 'price' => '3'
27
+ ])->subscription;
28
+ Braintree\Subscription::cancel($canceledSubscription->id);
29
+
30
+ $collection = Braintree\Subscription::search([
31
+ Braintree\SubscriptionSearch::status()->in([Braintree\Subscription::ACTIVE]),
32
+ Braintree\SubscriptionSearch::price()->is('3'),
33
+ ]);
34
+ foreach ($collection AS $item) {
35
+ $this->assertEquals(Braintree\Subscription::ACTIVE, $item->status);
36
+ }
37
+
38
+ $this->assertTrue(Test\Helper::includes($collection, $activeSubscription));
39
+ $this->assertFalse(Test\Helper::includes($collection, $canceledSubscription));
40
+ }
41
+
42
+ public function testIs()
43
+ {
44
+ $found = false;
45
+ $collection = Braintree\Subscription::search([
46
+ Braintree\SubscriptionSearch::status()->is(Braintree\Subscription::PAST_DUE)
47
+ ]);
48
+ foreach ($collection AS $item) {
49
+ $found = true;
50
+ $this->assertEquals(Braintree\Subscription::PAST_DUE, $item->status);
51
+ }
52
+ $this->assertTrue($found);
53
+ }
54
+
55
+ public function testSearch_statusIsExpired()
56
+ {
57
+ $found = false;
58
+ $collection = Braintree\Subscription::search([
59
+ Braintree\SubscriptionSearch::status()->in([Braintree\Subscription::EXPIRED])
60
+ ]);
61
+ foreach ($collection AS $item) {
62
+ $found = true;
63
+ $this->assertEquals(Braintree\Subscription::EXPIRED, $item->status);
64
+ }
65
+ $this->assertTrue($found);
66
+ }
67
+
68
+ public function testIn_multipleValues()
69
+ {
70
+ $creditCard = SubscriptionHelper::createCreditCard();
71
+ $triallessPlan = SubscriptionHelper::triallessPlan();
72
+
73
+ $activeSubscription = Braintree\Subscription::create([
74
+ 'paymentMethodToken' => $creditCard->token,
75
+ 'planId' => $triallessPlan['id'],
76
+ 'price' => '4'
77
+ ])->subscription;
78
+
79
+ $canceledSubscription = Braintree\Subscription::create([
80
+ 'paymentMethodToken' => $creditCard->token,
81
+ 'planId' => $triallessPlan['id'],
82
+ 'price' => '4'
83
+ ])->subscription;
84
+ Braintree\Subscription::cancel($canceledSubscription->id);
85
+
86
+ $collection = Braintree\Subscription::search([
87
+ Braintree\SubscriptionSearch::status()->in([Braintree\Subscription::ACTIVE, Braintree\Subscription::CANCELED]),
88
+ Braintree\SubscriptionSearch::price()->is('4')
89
+ ]);
90
+
91
+ $this->assertTrue(Test\Helper::includes($collection, $activeSubscription));
92
+ $this->assertTrue(Test\Helper::includes($collection, $canceledSubscription));
93
+ }
94
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/OAuthTest.php ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class OAuthTest extends Setup
11
+ {
12
+ public function testCreateTokenFromCode()
13
+ {
14
+ $gateway = new Braintree\Gateway([
15
+ 'clientId' => 'client_id$development$integration_client_id',
16
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
17
+ ]);
18
+ $code = Test\Braintree\OAuthTestHelper::createGrant($gateway, [
19
+ 'merchant_public_id' => 'integration_merchant_id',
20
+ 'scope' => 'read_write'
21
+ ]);
22
+ $result = $gateway->oauth()->createTokenFromCode([
23
+ 'code' => $code,
24
+ 'scope' => 'read_write',
25
+ ]);
26
+
27
+ $this->assertEquals(true, $result->success);
28
+ $credentials = $result->credentials;
29
+ $this->assertNotNull($credentials->accessToken);
30
+ $this->assertNotNull($credentials->refreshToken);
31
+ $this->assertEquals('bearer', $credentials->tokenType);
32
+ $this->assertNotNull($credentials->expiresAt);
33
+ }
34
+
35
+ /**
36
+ * @expectedException Braintree\Exception\Configuration
37
+ * @expectedExceptionMessage clientSecret needs to be passed to Braintree\Gateway.
38
+ */
39
+ public function testAssertsHasCredentials()
40
+ {
41
+ $gateway = new Braintree\Gateway([
42
+ 'clientId' => 'client_id$development$integration_client_id'
43
+ ]);
44
+ $gateway->oauth()->createTokenFromCode([
45
+ 'code' => 'integration_oauth_auth_code_' . rand(0,299)
46
+ ]);
47
+ }
48
+
49
+ public function testCreateTokenFromCodeWithMixedCredentials()
50
+ {
51
+ $gateway = new Braintree\Gateway([
52
+ 'clientId' => 'client_id$development$integration_client_id',
53
+ 'clientSecret' => 'client_secret$development$integration_client_secret',
54
+ 'accessToken' => 'access_token$development$integration_merchant_id$f9ac33b3dd',
55
+ ]);
56
+ $code = Test\Braintree\OAuthTestHelper::createGrant($gateway, [
57
+ 'merchant_public_id' => 'integration_merchant_id',
58
+ 'scope' => 'read_write'
59
+ ]);
60
+ $result = $gateway->oauth()->createTokenFromCode([
61
+ 'code' => $code,
62
+ 'scope' => 'read_write',
63
+ ]);
64
+
65
+ $this->assertEquals(true, $result->success);
66
+ $credentials = $result->credentials;
67
+ $this->assertNotNull($credentials->accessToken);
68
+ $this->assertNotNull($credentials->refreshToken);
69
+ $this->assertEquals('bearer', $credentials->tokenType);
70
+ $this->assertNotNull($credentials->expiresAt);
71
+ }
72
+
73
+ public function testCreateTokenFromCode_JsonAPI()
74
+ {
75
+ $gateway = new Braintree\Gateway([
76
+ 'clientId' => 'client_id$development$integration_client_id',
77
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
78
+ ]);
79
+ $code = Test\Braintree\OAuthTestHelper::createGrant($gateway, [
80
+ 'merchant_public_id' => 'integration_merchant_id',
81
+ 'scope' => 'read_write'
82
+ ]);
83
+ $result = $gateway->oauth()->createTokenFromCode([
84
+ 'code' => $code,
85
+ 'scope' => 'read_write',
86
+ ]);
87
+
88
+ $this->assertEquals(true, $result->success);
89
+ $this->assertNotNull($result->accessToken);
90
+ $this->assertNotNull($result->refreshToken);
91
+ $this->assertEquals('bearer', $result->tokenType);
92
+ $this->assertNotNull($result->expiresAt);
93
+ }
94
+
95
+ public function testRevokeAccessToken()
96
+ {
97
+ $gateway = new Braintree\Gateway([
98
+ 'clientId' => 'client_id$development$integration_client_id',
99
+ 'clientSecret' => 'client_secret$development$integration_client_secret',
100
+ ]);
101
+ $code = Test\Braintree\OAuthTestHelper::createGrant($gateway, [
102
+ 'merchant_public_id' => 'integration_merchant_id',
103
+ 'scope' => 'read_write'
104
+ ]);
105
+ $result = $gateway->oauth()->createTokenFromCode([
106
+ 'code' => $code,
107
+ 'scope' => 'read_write',
108
+ ]);
109
+
110
+ $revokeAccessTokenResult = $gateway->oauth()->revokeAccessToken($result->accessToken);
111
+
112
+ $this->assertTrue($revokeAccessTokenResult->success);
113
+ $this->assertTrue($revokeAccessTokenResult->result->success);
114
+
115
+ $gateway = new Braintree\Gateway(['accessToken' => $result->accessToken]);
116
+ $this->setExpectedException('Braintree\Exception\Authentication');
117
+ $gateway->customer()->create();
118
+ }
119
+
120
+ public function testCreateTokenFromCode_ValidationErrorTest()
121
+ {
122
+ $gateway = new Braintree\Gateway([
123
+ 'clientId' => 'client_id$development$integration_client_id',
124
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
125
+ ]);
126
+ $result = $gateway->oauth()->createTokenFromCode([
127
+ 'code' => 'bad_code',
128
+ 'scope' => 'read_write',
129
+ ]);
130
+
131
+ $this->assertEquals(false, $result->success);
132
+ $errors = $result->errors->forKey('credentials')->onAttribute('code');
133
+ $this->assertEquals(Braintree\Error\Codes::OAUTH_INVALID_GRANT, $errors[0]->code);
134
+ $this->assertEquals(1, preg_match('/Invalid grant: code not found/', $result->message));
135
+ }
136
+
137
+ public function testCreateTokenFromCode_OldError()
138
+ {
139
+ $gateway = new Braintree\Gateway([
140
+ 'clientId' => 'client_id$development$integration_client_id',
141
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
142
+ ]);
143
+ $result = $gateway->oauth()->createTokenFromCode([
144
+ 'code' => 'bad_code',
145
+ 'scope' => 'read_write',
146
+ ]);
147
+
148
+ $this->assertEquals(false, $result->success);
149
+ $this->assertEquals('invalid_grant', $result->error);
150
+ $this->assertEquals('code not found', $result->errorDescription);
151
+ }
152
+
153
+ public function testCreateTokenFromRefreshToken()
154
+ {
155
+ $gateway = new Braintree\Gateway([
156
+ 'clientId' => 'client_id$development$integration_client_id',
157
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
158
+ ]);
159
+ $code = Test\Braintree\OAuthTestHelper::createGrant($gateway, [
160
+ 'merchant_public_id' => 'integration_merchant_id',
161
+ 'scope' => 'read_write'
162
+ ]);
163
+ $refreshToken = $gateway->oauth()->createTokenFromCode([
164
+ 'code' => $code,
165
+ 'scope' => 'read_write',
166
+ ])->credentials->refreshToken;
167
+
168
+ $result = $gateway->oauth()->createTokenFromRefreshToken([
169
+ 'refreshToken' => $refreshToken,
170
+ 'scope' => 'read_write',
171
+ ]);
172
+
173
+ $this->assertEquals(true, $result->success);
174
+ $credentials = $result->credentials;
175
+ $this->assertNotNull($credentials->accessToken);
176
+ $this->assertNotNull($credentials->refreshToken);
177
+ $this->assertEquals('bearer', $credentials->tokenType);
178
+ $this->assertNotNull($credentials->expiresAt);
179
+ }
180
+
181
+
182
+ public function testBuildConnectUrl()
183
+ {
184
+ $gateway = new Braintree\Gateway([
185
+ 'clientId' => 'client_id$development$integration_client_id',
186
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
187
+ ]);
188
+ $url = $gateway->oauth()->connectUrl([
189
+ 'merchantId' => 'integration_merchant_id',
190
+ 'redirectUri' => 'http://bar.example.com',
191
+ 'scope' => 'read_write',
192
+ 'state' => 'baz_state',
193
+ 'landingPage' => 'login',
194
+ 'user' => [
195
+ 'country' => 'USA',
196
+ 'email' => 'foo@example.com',
197
+ 'firstName' => 'Bob',
198
+ 'lastName' => 'Jones',
199
+ 'phone' => '555-555-5555',
200
+ 'dobYear' => '1970',
201
+ 'dobMonth' => '01',
202
+ 'dobDay' => '01',
203
+ 'streetAddress' => '222 W Merchandise Mart',
204
+ 'locality' => 'Chicago',
205
+ 'region' => 'IL',
206
+ 'postalCode' => '60606',
207
+ ],
208
+ 'business' => [
209
+ 'name' => '14 Ladders',
210
+ 'registeredAs' => '14.0 Ladders',
211
+ 'industry' => 'Ladders',
212
+ 'description' => 'We sell the best ladders',
213
+ 'streetAddress' => '111 N Canal',
214
+ 'locality' => 'Chicago',
215
+ 'region' => 'IL',
216
+ 'postalCode' => '60606',
217
+ 'country' => 'USA',
218
+ 'annualVolumeAmount' => '1000000',
219
+ 'averageTransactionAmount' => '100',
220
+ 'maximumTransactionAmount' => '10000',
221
+ 'shipPhysicalGoods' => true,
222
+ 'fulfillmentCompletedIn' => 7,
223
+ 'currency' => 'USD',
224
+ 'website' => 'http://example.com',
225
+ ],
226
+ 'paymentMethods' => ['credit_card'],
227
+ ]);
228
+
229
+ $components = parse_url($url);
230
+ $queryString = $components['query'];
231
+ parse_str($queryString, $query);
232
+
233
+ $this->assertEquals('localhost', $components['host']);
234
+ $this->assertEquals('/oauth/connect', $components['path']);
235
+ $this->assertEquals('integration_merchant_id', $query['merchant_id']);
236
+ $this->assertEquals('client_id$development$integration_client_id', $query['client_id']);
237
+ $this->assertEquals('http://bar.example.com', $query['redirect_uri']);
238
+ $this->assertEquals('read_write', $query['scope']);
239
+ $this->assertEquals('baz_state', $query['state']);
240
+ $this->assertEquals('login', $query['landing_page']);
241
+
242
+ $this->assertEquals('USA', $query['user']['country']);
243
+ $this->assertEquals('foo@example.com', $query['user']['email']);
244
+ $this->assertEquals('Bob', $query['user']['first_name']);
245
+ $this->assertEquals('Jones', $query['user']['last_name']);
246
+ $this->assertEquals('555-555-5555', $query['user']['phone']);
247
+ $this->assertEquals('1970', $query['user']['dob_year']);
248
+ $this->assertEquals('01', $query['user']['dob_month']);
249
+ $this->assertEquals('01', $query['user']['dob_day']);
250
+ $this->assertEquals('222 W Merchandise Mart', $query['user']['street_address']);
251
+ $this->assertEquals('Chicago', $query['user']['locality']);
252
+ $this->assertEquals('IL', $query['user']['region']);
253
+ $this->assertEquals('60606', $query['user']['postal_code']);
254
+
255
+ $this->assertEquals('14 Ladders', $query['business']['name']);
256
+ $this->assertEquals('14.0 Ladders', $query['business']['registered_as']);
257
+ $this->assertEquals('Ladders', $query['business']['industry']);
258
+ $this->assertEquals('We sell the best ladders', $query['business']['description']);
259
+ $this->assertEquals('111 N Canal', $query['business']['street_address']);
260
+ $this->assertEquals('Chicago', $query['business']['locality']);
261
+ $this->assertEquals('IL', $query['business']['region']);
262
+ $this->assertEquals('60606', $query['business']['postal_code']);
263
+ $this->assertEquals('USA', $query['business']['country']);
264
+ $this->assertEquals('1000000', $query['business']['annual_volume_amount']);
265
+ $this->assertEquals('100', $query['business']['average_transaction_amount']);
266
+ $this->assertEquals('10000', $query['business']['maximum_transaction_amount']);
267
+ $this->assertEquals(true, $query['business']['ship_physical_goods']);
268
+ $this->assertEquals(7, $query['business']['fulfillment_completed_in']);
269
+ $this->assertEquals('USD', $query['business']['currency']);
270
+ $this->assertEquals('http://example.com', $query['business']['website']);
271
+
272
+ $this->assertCount(1, $query['payment_methods']);
273
+ $this->assertEquals('credit_card', $query['payment_methods'][0]);
274
+
275
+ $this->assertEquals(64, strlen($query['signature']));
276
+ $this->assertEquals('SHA256', $query['algorithm']);
277
+ }
278
+
279
+ public function testBuildConnectUrlWithoutOptionalParams()
280
+ {
281
+ $gateway = new Braintree\Gateway([
282
+ 'clientId' => 'client_id$development$integration_client_id',
283
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
284
+ ]);
285
+ $url = $gateway->oauth()->connectUrl();
286
+
287
+ $queryString = parse_url($url)['query'];
288
+ parse_str($queryString, $query);
289
+
290
+ $this->assertEquals('client_id$development$integration_client_id', $query['client_id']);
291
+ $this->assertArrayNotHasKey('merchant_id', $query);
292
+ $this->assertArrayNotHasKey('redirect_uri', $query);
293
+ $this->assertArrayNotHasKey('scope', $query);
294
+ }
295
+
296
+ public function testBuildConnectUrlWithPaymentMethods()
297
+ {
298
+ $gateway = new Braintree\Gateway([
299
+ 'clientId' => 'client_id$development$integration_client_id',
300
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
301
+ ]);
302
+ $url = $gateway->oauth()->connectUrl([
303
+ 'paymentMethods' => ['credit_card', 'paypal']
304
+ ]);
305
+
306
+ $queryString = parse_url($url)['query'];
307
+ parse_str($queryString, $query);
308
+
309
+ $this->assertEquals(['credit_card', 'paypal'], $query['payment_methods']);
310
+ }
311
+
312
+ public function testComputeSignature()
313
+ {
314
+ $gateway = new Braintree\Gateway([
315
+ 'clientId' => 'client_id$development$integration_client_id',
316
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
317
+ ]);
318
+ $urlToSign = 'http://localhost:3000/oauth/connect?business%5Bname%5D=We+Like+Spaces&client_id=client_id%24development%24integration_client_id';
319
+
320
+ $signature = $gateway->oauth()->computeSignature($urlToSign);
321
+
322
+ $this->assertEquals("a36bcf10dd982e2e47e0d6a2cb930aea47ade73f954b7d59c58dae6167894d41", $signature);
323
+ }
324
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/PayPalAccountTest.php ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Braintree;
8
+
9
+ class PayPalAccountTest extends Setup
10
+ {
11
+ public function testFind()
12
+ {
13
+ $paymentMethodToken = 'PAYPALToken-' . strval(rand());
14
+ $customer = Braintree\Customer::createNoValidate();
15
+ $http = new HttpClientApi(Braintree\Configuration::$global);
16
+ $nonce = $http->nonceForPayPalAccount([
17
+ 'paypal_account' => [
18
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
19
+ 'token' => $paymentMethodToken
20
+ ]
21
+ ]);
22
+
23
+ Braintree\PaymentMethod::create([
24
+ 'customerId' => $customer->id,
25
+ 'paymentMethodNonce' => $nonce
26
+ ]);
27
+
28
+ $foundPayPalAccount = Braintree\PayPalAccount::find($paymentMethodToken);
29
+
30
+ $this->assertSame('jane.doe@example.com', $foundPayPalAccount->email);
31
+ $this->assertSame($paymentMethodToken, $foundPayPalAccount->token);
32
+ $this->assertNotNull($foundPayPalAccount->imageUrl);
33
+ }
34
+
35
+ public function testGatewayFind()
36
+ {
37
+ $paymentMethodToken = 'PAYPALToken-' . strval(rand());
38
+ $customer = Braintree\Customer::createNoValidate();
39
+ $http = new HttpClientApi(Braintree\Configuration::$global);
40
+ $nonce = $http->nonceForPayPalAccount([
41
+ 'paypal_account' => [
42
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
43
+ 'token' => $paymentMethodToken
44
+ ]
45
+ ]);
46
+
47
+ Braintree\PaymentMethod::create([
48
+ 'customerId' => $customer->id,
49
+ 'paymentMethodNonce' => $nonce
50
+ ]);
51
+
52
+ $gateway = new Braintree\Gateway([
53
+ 'environment' => 'development',
54
+ 'merchantId' => 'integration_merchant_id',
55
+ 'publicKey' => 'integration_public_key',
56
+ 'privateKey' => 'integration_private_key'
57
+ ]);
58
+ $foundPayPalAccount = $gateway->paypalAccount()->find($paymentMethodToken);
59
+
60
+ $this->assertSame('jane.doe@example.com', $foundPayPalAccount->email);
61
+ $this->assertSame($paymentMethodToken, $foundPayPalAccount->token);
62
+ $this->assertNotNull($foundPayPalAccount->imageUrl);
63
+ }
64
+
65
+ public function testFind_doesNotReturnIncorrectPaymentMethodType()
66
+ {
67
+ $creditCardToken = 'creditCardToken-' . strval(rand());
68
+ $customer = Braintree\Customer::createNoValidate();
69
+ $result = Braintree\CreditCard::create([
70
+ 'customerId' => $customer->id,
71
+ 'cardholderName' => 'Cardholder',
72
+ 'number' => '5105105105105100',
73
+ 'expirationDate' => '05/12',
74
+ 'token' => $creditCardToken
75
+ ]);
76
+ $this->assertTrue($result->success);
77
+
78
+ $this->setExpectedException('Braintree\Exception\NotFound');
79
+ Braintree\PayPalAccount::find($creditCardToken);
80
+ }
81
+
82
+ public function test_PayPalAccountExposesTimestamps()
83
+ {
84
+ $customer = Braintree\Customer::createNoValidate();
85
+ $result = Braintree\PaymentMethod::create([
86
+ 'customerId' => $customer->id,
87
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$paypalFuturePayment,
88
+ ]);
89
+ $this->assertTrue($result->success);
90
+
91
+ $this->assertNotNull($result->paymentMethod->createdAt);
92
+ $this->assertNotNull($result->paymentMethod->updatedAt);
93
+ }
94
+
95
+ public function test_PayPalAccountExposesBillingAgreementId()
96
+ {
97
+ $customer = Braintree\Customer::createNoValidate();
98
+ $result = Braintree\PaymentMethod::create([
99
+ 'customerId' => $customer->id,
100
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$paypalBillingAgreement
101
+ ]);
102
+ $this->assertTrue($result->success);
103
+
104
+ $foundPayPalAccount = Braintree\PayPalAccount::find($result->paymentMethod->token);
105
+
106
+ $this->assertNotNull($foundPayPalAccount->billingAgreementId);
107
+ }
108
+
109
+ public function testFind_throwsIfCannotBeFound()
110
+ {
111
+ $this->setExpectedException('Braintree\Exception\NotFound');
112
+ Braintree\PayPalAccount::find('invalid-token');
113
+ }
114
+
115
+ public function testFind_throwsUsefulErrorMessagesWhenEmpty()
116
+ {
117
+ $this->setExpectedException('InvalidArgumentException', 'expected paypal account id to be set');
118
+ Braintree\PayPalAccount::find('');
119
+ }
120
+
121
+ public function testFind_throwsUsefulErrorMessagesWhenInvalid()
122
+ {
123
+ $this->setExpectedException('InvalidArgumentException', '@ is an invalid paypal account token');
124
+ Braintree\PayPalAccount::find('@');
125
+ }
126
+
127
+ public function testFind_returnsSubscriptionsAssociatedWithAPaypalAccount()
128
+ {
129
+ $customer = Braintree\Customer::createNoValidate();
130
+ $paymentMethodToken = 'paypal-account-' . strval(rand());
131
+
132
+ $http = new HttpClientApi(Braintree\Configuration::$global);
133
+ $nonce = $http->nonceForPayPalAccount([
134
+ 'paypal_account' => [
135
+ 'consent_code' => 'consent-code',
136
+ 'token' => $paymentMethodToken
137
+ ]
138
+ ]);
139
+
140
+ $result = Braintree\PaymentMethod::create([
141
+ 'paymentMethodNonce' => $nonce,
142
+ 'customerId' => $customer->id
143
+ ]);
144
+ $this->assertTrue($result->success);
145
+
146
+ $token = $result->paymentMethod->token;
147
+ $triallessPlan = SubscriptionHelper::triallessPlan();
148
+
149
+ $subscription1 = Braintree\Subscription::create([
150
+ 'paymentMethodToken' => $token,
151
+ 'planId' => $triallessPlan['id']
152
+ ])->subscription;
153
+
154
+ $subscription2 = Braintree\Subscription::create([
155
+ 'paymentMethodToken' => $token,
156
+ 'planId' => $triallessPlan['id']
157
+ ])->subscription;
158
+
159
+ $paypalAccount = Braintree\PayPalAccount::find($token);
160
+ $getIds = function($sub) { return $sub->id; };
161
+ $subIds = array_map($getIds, $paypalAccount->subscriptions);
162
+ $this->assertTrue(in_array($subscription1->id, $subIds));
163
+ $this->assertTrue(in_array($subscription2->id, $subIds));
164
+ }
165
+
166
+ public function testUpdate()
167
+ {
168
+ $originalToken = 'ORIGINAL_PAYPALToken-' . strval(rand());
169
+ $customer = Braintree\Customer::createNoValidate();
170
+ $http = new HttpClientApi(Braintree\Configuration::$global);
171
+ $nonce = $http->nonceForPayPalAccount([
172
+ 'paypal_account' => [
173
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
174
+ 'token' => $originalToken
175
+ ]
176
+ ]);
177
+
178
+ $createResult = Braintree\PaymentMethod::create([
179
+ 'customerId' => $customer->id,
180
+ 'paymentMethodNonce' => $nonce
181
+ ]);
182
+ $this->assertTrue($createResult->success);
183
+
184
+ $newToken = 'NEW_PAYPALToken-' . strval(rand());
185
+ $updateResult = Braintree\PayPalAccount::update($originalToken, [
186
+ 'token' => $newToken
187
+ ]);
188
+
189
+ $this->assertTrue($updateResult->success);
190
+ $this->assertEquals($newToken, $updateResult->paypalAccount->token);
191
+
192
+ $this->setExpectedException('Braintree\Exception\NotFound');
193
+ Braintree\PayPalAccount::find($originalToken);
194
+
195
+ }
196
+
197
+ public function testUpdateAndMakeDefault()
198
+ {
199
+ $customer = Braintree\Customer::createNoValidate();
200
+
201
+ $creditCardResult = Braintree\CreditCard::create([
202
+ 'customerId' => $customer->id,
203
+ 'number' => '5105105105105100',
204
+ 'expirationDate' => '05/12'
205
+ ]);
206
+ $this->assertTrue($creditCardResult->success);
207
+
208
+ $http = new HttpClientApi(Braintree\Configuration::$global);
209
+ $nonce = $http->nonceForPayPalAccount([
210
+ 'paypal_account' => [
211
+ 'consent_code' => 'PAYPAL_CONSENT_CODE'
212
+ ]
213
+ ]);
214
+
215
+ $createResult = Braintree\PaymentMethod::create([
216
+ 'customerId' => $customer->id,
217
+ 'paymentMethodNonce' => $nonce
218
+ ]);
219
+ $this->assertTrue($createResult->success);
220
+
221
+ $updateResult = Braintree\PayPalAccount::update($createResult->paymentMethod->token, [
222
+ 'options' => ['makeDefault' => true]
223
+ ]);
224
+
225
+ $this->assertTrue($updateResult->success);
226
+ $this->assertTrue($updateResult->paypalAccount->isDefault());
227
+ }
228
+
229
+ public function testUpdate_handleErrors()
230
+ {
231
+ $customer = Braintree\Customer::createNoValidate();
232
+
233
+ $firstToken = 'FIRST_PAYPALToken-' . strval(rand());
234
+ $http = new HttpClientApi(Braintree\Configuration::$global);
235
+ $firstNonce = $http->nonceForPayPalAccount([
236
+ 'paypal_account' => [
237
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
238
+ 'token' => $firstToken
239
+ ]
240
+ ]);
241
+ $firstPaypalAccount = Braintree\PaymentMethod::create([
242
+ 'customerId' => $customer->id,
243
+ 'paymentMethodNonce' => $firstNonce
244
+ ]);
245
+ $this->assertTrue($firstPaypalAccount->success);
246
+
247
+ $secondToken = 'SECOND_PAYPALToken-' . strval(rand());
248
+ $http = new HttpClientApi(Braintree\Configuration::$global);
249
+ $secondNonce = $http->nonceForPayPalAccount([
250
+ 'paypal_account' => [
251
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
252
+ 'token' => $secondToken
253
+ ]
254
+ ]);
255
+ $secondPaypalAccount = Braintree\PaymentMethod::create([
256
+ 'customerId' => $customer->id,
257
+ 'paymentMethodNonce' => $secondNonce
258
+ ]);
259
+ $this->assertTrue($secondPaypalAccount->success);
260
+
261
+ $updateResult = Braintree\PayPalAccount::update($firstToken, [
262
+ 'token' => $secondToken
263
+ ]);
264
+
265
+ $this->assertFalse($updateResult->success);
266
+ $errors = $updateResult->errors->forKey('paypalAccount')->errors;
267
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_TOKEN_IS_IN_USE, $errors[0]->code);
268
+ }
269
+
270
+ public function testDelete()
271
+ {
272
+ $paymentMethodToken = 'PAYPALToken-' . strval(rand());
273
+ $customer = Braintree\Customer::createNoValidate();
274
+ $http = new HttpClientApi(Braintree\Configuration::$global);
275
+ $nonce = $http->nonceForPayPalAccount([
276
+ 'paypal_account' => [
277
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
278
+ 'token' => $paymentMethodToken
279
+ ]
280
+ ]);
281
+
282
+ Braintree\PaymentMethod::create([
283
+ 'customerId' => $customer->id,
284
+ 'paymentMethodNonce' => $nonce
285
+ ]);
286
+
287
+ Braintree\PayPalAccount::delete($paymentMethodToken);
288
+
289
+ $this->setExpectedException('Braintree\Exception\NotFound');
290
+ Braintree\PayPalAccount::find($paymentMethodToken);
291
+ }
292
+
293
+ public function testSale_createsASaleUsingGivenToken()
294
+ {
295
+ $nonce = Braintree\Test\Nonces::$paypalFuturePayment;
296
+ $customer = Braintree\Customer::createNoValidate([
297
+ 'paymentMethodNonce' => $nonce
298
+ ]);
299
+ $paypalAccount = $customer->paypalAccounts[0];
300
+
301
+ $result = Braintree\PayPalAccount::sale($paypalAccount->token, [
302
+ 'amount' => '100.00'
303
+ ]);
304
+ $this->assertTrue($result->success);
305
+ $this->assertEquals('100.00', $result->transaction->amount);
306
+ $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
307
+ $this->assertEquals($paypalAccount->token, $result->transaction->paypalDetails->token);
308
+ }
309
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/PaymentMethodNonceTest.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Test\Helper;
8
+ use Braintree;
9
+
10
+ class PaymentMethodNonceTest extends Setup
11
+ {
12
+ public function testCreate_fromPaymentMethodToken()
13
+ {
14
+ $customer = Braintree\Customer::createNoValidate();
15
+ $card = Braintree\CreditCard::create([
16
+ 'customerId' => $customer->id,
17
+ 'cardholderName' => 'Cardholder',
18
+ 'number' => '5105105105105100',
19
+ 'expirationDate' => '05/12',
20
+ ])->creditCard;
21
+
22
+ $result = Braintree\PaymentMethodNonce::create($card->token);
23
+
24
+ $this->assertTrue($result->success);
25
+ $this->assertNotNull($result->paymentMethodNonce);
26
+ $this->assertNotNull($result->paymentMethodNonce->nonce);
27
+ }
28
+
29
+ public function testCreate_fromNonExistentPaymentMethodToken()
30
+ {
31
+ $this->setExpectedException('Braintree\Exception\NotFound');
32
+ Braintree\PaymentMethodNonce::create('not_a_token');
33
+ }
34
+
35
+ public function testFind_exposesThreeDSecureInfo()
36
+ {
37
+ $creditCard = [
38
+ 'creditCard' => [
39
+ 'number' => '4111111111111111',
40
+ 'expirationMonth' => '12',
41
+ 'expirationYear' => '2020'
42
+ ]
43
+ ];
44
+ $nonce = Helper::generate3DSNonce($creditCard);
45
+ $foundNonce = Braintree\PaymentMethodNonce::find($nonce);
46
+ $info = $foundNonce->threeDSecureInfo;
47
+
48
+ $this->assertEquals($nonce, $foundNonce->nonce);
49
+ $this->assertEquals('CreditCard', $foundNonce->type);
50
+ $this->assertEquals('Y', $info->enrolled);
51
+ $this->assertEquals('authenticate_successful', $info->status);
52
+ $this->assertTrue($info->liabilityShifted);
53
+ $this->assertTrue($info->liabilityShiftPossible);
54
+ }
55
+
56
+ public function testFind_exposesNullThreeDSecureInfoIfNoneExists()
57
+ {
58
+ $http = new HttpClientApi(Braintree\Configuration::$global);
59
+ $nonce = $http->nonce_for_new_card([
60
+ "creditCard" => [
61
+ "number" => "4111111111111111",
62
+ "expirationMonth" => "11",
63
+ "expirationYear" => "2099"
64
+ ]
65
+ ]);
66
+
67
+ $foundNonce = Braintree\PaymentMethodNonce::find($nonce);
68
+ $info = $foundNonce->threeDSecureInfo;
69
+
70
+ $this->assertEquals($nonce, $foundNonce->nonce);
71
+ $this->assertNull($info);
72
+ }
73
+
74
+ public function testFind_nonExistantNonce()
75
+ {
76
+ $this->setExpectedException('Braintree\Exception\NotFound');
77
+ Braintree\PaymentMethodNonce::find('not_a_nonce');
78
+ }
79
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/PaymentMethodTest.php ADDED
@@ -0,0 +1,1668 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test;
7
+ use Test\Setup;
8
+ use Braintree;
9
+
10
+ class PaymentMethodTest extends Setup
11
+ {
12
+ public function testCreate_fromVaultedCreditCardNonce()
13
+ {
14
+ $customer = Braintree\Customer::createNoValidate();
15
+ $http = new HttpClientApi(Braintree\Configuration::$global);
16
+ $nonce = $http->nonce_for_new_card([
17
+ 'credit_card' => [
18
+ 'number' => '4111111111111111',
19
+ 'expirationMonth' => '11',
20
+ 'expirationYear' => '2099'
21
+ ],
22
+ 'share' => true
23
+ ]);
24
+
25
+ $result = Braintree\PaymentMethod::create([
26
+ 'customerId' => $customer->id,
27
+ 'paymentMethodNonce' => $nonce
28
+ ]);
29
+
30
+ $this->assertSame('411111', $result->paymentMethod->bin);
31
+ $this->assertSame('1111', $result->paymentMethod->last4);
32
+ $this->assertNotNull($result->paymentMethod->token);
33
+ $this->assertNotNull($result->paymentMethod->imageUrl);
34
+ $this->assertSame($customer->id, $result->paymentMethod->customerId);
35
+ }
36
+
37
+ public function testGatewayCreate_fromVaultedCreditCardNonce()
38
+ {
39
+ $customer = Braintree\Customer::createNoValidate();
40
+ $http = new HttpClientApi(Braintree\Configuration::$global);
41
+ $nonce = $http->nonce_for_new_card([
42
+ 'credit_card' => [
43
+ 'number' => '4111111111111111',
44
+ 'expirationMonth' => '11',
45
+ 'expirationYear' => '2099'
46
+ ],
47
+ 'share' => true
48
+ ]);
49
+
50
+ $gateway = new Braintree\Gateway([
51
+ 'environment' => 'development',
52
+ 'merchantId' => 'integration_merchant_id',
53
+ 'publicKey' => 'integration_public_key',
54
+ 'privateKey' => 'integration_private_key'
55
+ ]);
56
+ $result = $gateway->paymentMethod()->create([
57
+ 'customerId' => $customer->id,
58
+ 'paymentMethodNonce' => $nonce
59
+ ]);
60
+
61
+ $this->assertSame('411111', $result->paymentMethod->bin);
62
+ $this->assertSame('1111', $result->paymentMethod->last4);
63
+ $this->assertNotNull($result->paymentMethod->token);
64
+ $this->assertNotNull($result->paymentMethod->imageUrl);
65
+ $this->assertSame($customer->id, $result->paymentMethod->customerId);
66
+ }
67
+
68
+ public function testCreate_fromFakeApplePayNonce()
69
+ {
70
+ $customer = Braintree\Customer::createNoValidate();
71
+ $result = Braintree\PaymentMethod::create([
72
+ 'customerId' => $customer->id,
73
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$applePayVisa,
74
+ ]);
75
+
76
+ $this->assertTrue($result->success);
77
+ $applePayCard = $result->paymentMethod;
78
+ $this->assertNotNull($applePayCard->token);
79
+ $this->assertSame(Braintree\ApplePayCard::VISA, $applePayCard->cardType);
80
+ $this->assertContains("Visa ", $applePayCard->paymentInstrumentName);
81
+ $this->assertContains("Visa ", $applePayCard->sourceDescription);
82
+ $this->assertTrue($applePayCard->default);
83
+ $this->assertContains('apple_pay', $applePayCard->imageUrl);
84
+ $this->assertTrue(intval($applePayCard->expirationMonth) > 0);
85
+ $this->assertTrue(intval($applePayCard->expirationYear) > 0);
86
+ $this->assertSame($customer->id, $applePayCard->customerId);
87
+ }
88
+
89
+ public function testCreate_fromFakeAndroidPayProxyCardNonce()
90
+ {
91
+ $customer = Braintree\Customer::createNoValidate();
92
+ $result = Braintree\PaymentMethod::create([
93
+ 'customerId' => $customer->id,
94
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$androidPayDiscover
95
+ ]);
96
+
97
+ $this->assertTrue($result->success);
98
+ $androidPayCard = $result->paymentMethod;
99
+ $this->assertNotNull($androidPayCard->token);
100
+ $this->assertSame(Braintree\CreditCard::DISCOVER, $androidPayCard->virtualCardType);
101
+ $this->assertSame(Braintree\CreditCard::DISCOVER, $androidPayCard->cardType);
102
+ $this->assertSame("1117", $androidPayCard->virtualCardLast4);
103
+ $this->assertSame("1117", $androidPayCard->last4);
104
+ $this->assertSame(Braintree\CreditCard::VISA, $androidPayCard->sourceCardType);
105
+ $this->assertSame("1111", $androidPayCard->sourceCardLast4);
106
+ $this->assertSame("Visa 1111", $androidPayCard->sourceDescription);
107
+ $this->assertTrue($androidPayCard->default);
108
+ $this->assertContains('android_pay', $androidPayCard->imageUrl);
109
+ $this->assertTrue(intval($androidPayCard->expirationMonth) > 0);
110
+ $this->assertTrue(intval($androidPayCard->expirationYear) > 0);
111
+ $this->assertSame($customer->id, $androidPayCard->customerId);
112
+ }
113
+
114
+ public function testCreate_fromFakeAndroidPayNetworkTokenNonce()
115
+ {
116
+ $customer = Braintree\Customer::createNoValidate();
117
+ $result = Braintree\PaymentMethod::create([
118
+ 'customerId' => $customer->id,
119
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$androidPayMasterCard
120
+ ]);
121
+
122
+ $this->assertTrue($result->success);
123
+ $androidPayCard = $result->paymentMethod;
124
+ $this->assertNotNull($androidPayCard->token);
125
+ $this->assertSame(Braintree\CreditCard::MASTER_CARD, $androidPayCard->virtualCardType);
126
+ $this->assertSame(Braintree\CreditCard::MASTER_CARD, $androidPayCard->cardType);
127
+ $this->assertSame("4444", $androidPayCard->virtualCardLast4);
128
+ $this->assertSame("4444", $androidPayCard->last4);
129
+ $this->assertSame(Braintree\CreditCard::MASTER_CARD, $androidPayCard->sourceCardType);
130
+ $this->assertSame("4444", $androidPayCard->sourceCardLast4);
131
+ $this->assertSame("MasterCard 4444", $androidPayCard->sourceDescription);
132
+ $this->assertTrue($androidPayCard->default);
133
+ $this->assertContains('android_pay', $androidPayCard->imageUrl);
134
+ $this->assertTrue(intval($androidPayCard->expirationMonth) > 0);
135
+ $this->assertTrue(intval($androidPayCard->expirationYear) > 0);
136
+ $this->assertSame($customer->id, $androidPayCard->customerId);
137
+ }
138
+
139
+ public function testCreate_fromFakeAmexExpressCheckoutCardNonce()
140
+ {
141
+ $customer = Braintree\Customer::createNoValidate();
142
+ $result = Braintree\PaymentMethod::create([
143
+ 'customerId' => $customer->id,
144
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$amexExpressCheckout
145
+ ]);
146
+
147
+ $this->assertTrue($result->success);
148
+ $amexExpressCheckoutCard = $result->paymentMethod;
149
+ $this->assertInstanceOf('Braintree\AmexExpressCheckoutCard', $amexExpressCheckoutCard);
150
+
151
+ $this->assertNotNull($amexExpressCheckoutCard->token);
152
+ $this->assertSame(Braintree\CreditCard::AMEX, $amexExpressCheckoutCard->cardType);
153
+ $this->assertSame("341111", $amexExpressCheckoutCard->bin);
154
+ $this->assertSame("12/21", $amexExpressCheckoutCard->cardMemberExpiryDate);
155
+ $this->assertSame("0005", $amexExpressCheckoutCard->cardMemberNumber);
156
+ $this->assertSame("American Express", $amexExpressCheckoutCard->cardType);
157
+ $this->assertNotNull($amexExpressCheckoutCard->sourceDescription);
158
+ $this->assertContains(".png", $amexExpressCheckoutCard->imageUrl);
159
+ $this->assertTrue(intval($amexExpressCheckoutCard->expirationMonth) > 0);
160
+ $this->assertTrue(intval($amexExpressCheckoutCard->expirationYear) > 0);
161
+ $this->assertTrue($amexExpressCheckoutCard->default);
162
+ $this->assertSame($customer->id, $amexExpressCheckoutCard->customerId);
163
+ $this->assertEquals([], $amexExpressCheckoutCard->subscriptions);
164
+ }
165
+
166
+ public function testCreate_fromFakeVenmoAccountNonce()
167
+ {
168
+ $customer = Braintree\Customer::createNoValidate();
169
+ $result = Braintree\PaymentMethod::create(array(
170
+ 'customerId' => $customer->id,
171
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$venmoAccount
172
+ ));
173
+
174
+ $this->assertTrue($result->success);
175
+ $venmoAccount = $result->paymentMethod;
176
+ $this->assertInstanceOf('Braintree\VenmoAccount', $venmoAccount);
177
+
178
+ $this->assertNotNull($venmoAccount->token);
179
+ $this->assertNotNull($venmoAccount->sourceDescription);
180
+ $this->assertContains(".png", $venmoAccount->imageUrl);
181
+ $this->assertTrue($venmoAccount->default);
182
+ $this->assertSame($customer->id, $venmoAccount->customerId);
183
+ $this->assertEquals(array(), $venmoAccount->subscriptions);
184
+ $this->assertSame("venmojoe", $venmoAccount->username);
185
+ $this->assertSame("Venmo-Joe-1", $venmoAccount->venmoUserId);
186
+ }
187
+
188
+ public function testCreate_fromUnvalidatedCreditCardNonce()
189
+ {
190
+ $customer = Braintree\Customer::createNoValidate();
191
+ $http = new HttpClientApi(Braintree\Configuration::$global);
192
+ $nonce = $http->nonce_for_new_card([
193
+ 'credit_card' => [
194
+ 'number' => '4111111111111111',
195
+ 'expirationMonth' => '11',
196
+ 'expirationYear' => '2099',
197
+ 'options' => [
198
+ 'validate' => false
199
+ ]
200
+ ]
201
+ ]);
202
+
203
+ $result = Braintree\PaymentMethod::create([
204
+ 'customerId' => $customer->id,
205
+ 'paymentMethodNonce' => $nonce
206
+ ]);
207
+
208
+ $this->assertSame('411111', $result->paymentMethod->bin);
209
+ $this->assertSame('1111', $result->paymentMethod->last4);
210
+ $this->assertSame($customer->id, $result->paymentMethod->customerId);
211
+ $this->assertNotNull($result->paymentMethod->token);
212
+ }
213
+
214
+ public function testCreate_fromUnvalidatedFuturePaypalAccountNonce()
215
+ {
216
+ $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
217
+ $customer = Braintree\Customer::createNoValidate();
218
+ $http = new HttpClientApi(Braintree\Configuration::$global);
219
+ $nonce = $http->nonceForPayPalAccount([
220
+ 'paypal_account' => [
221
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
222
+ 'token' => $paymentMethodToken
223
+ ]
224
+ ]);
225
+
226
+ $result = Braintree\PaymentMethod::create([
227
+ 'customerId' => $customer->id,
228
+ 'paymentMethodNonce' => $nonce
229
+ ]);
230
+
231
+ $this->assertSame('jane.doe@example.com', $result->paymentMethod->email);
232
+ $this->assertSame($paymentMethodToken, $result->paymentMethod->token);
233
+ $this->assertSame($customer->id, $result->paymentMethod->customerId);
234
+ }
235
+
236
+ public function testCreate_fromOrderPaymentPaypalAccountNonce()
237
+ {
238
+ $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
239
+ $customer = Braintree\Customer::createNoValidate();
240
+ $http = new HttpClientApi(Braintree\Configuration::$global);
241
+ $nonce = $http->nonceForPayPalAccount([
242
+ 'paypal_account' => [
243
+ 'intent' => 'order',
244
+ 'payment_token' => 'paypal-payment-token',
245
+ 'payer_id' => 'paypal-payer-id',
246
+ 'token' => $paymentMethodToken,
247
+ ]
248
+ ]);
249
+
250
+ $result = Braintree\PaymentMethod::create([
251
+ 'customerId' => $customer->id,
252
+ 'paymentMethodNonce' => $nonce
253
+ ]);
254
+
255
+ $this->assertSame('bt_buyer_us@paypal.com', $result->paymentMethod->email);
256
+ $this->assertSame($paymentMethodToken, $result->paymentMethod->token);
257
+ $this->assertSame($customer->id, $result->paymentMethod->customerId);
258
+ }
259
+
260
+ public function testCreate_fromOrderPaymentPaypalAccountNonceWithPayPalOptions()
261
+ {
262
+ $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
263
+ $customer = Braintree\Customer::createNoValidate();
264
+ $http = new HttpClientApi(Braintree\Configuration::$global);
265
+ $nonce = $http->nonceForPayPalAccount([
266
+ 'paypal_account' => [
267
+ 'intent' => 'order',
268
+ 'payment_token' => 'paypal-payment-token',
269
+ 'payer_id' => 'paypal-payer-id',
270
+ 'token' => $paymentMethodToken,
271
+ ]
272
+ ]);
273
+
274
+ $result = Braintree\PaymentMethod::create([
275
+ 'customerId' => $customer->id,
276
+ 'paymentMethodNonce' => $nonce,
277
+ 'options' => [
278
+ 'paypal' => [
279
+ 'payee_email' => 'payee@example.com',
280
+ 'order_id' => 'merchant-order-id',
281
+ 'custom_field' => 'custom merchant field',
282
+ 'description' => 'merchant description',
283
+ 'amount' => '1.23',
284
+ ]
285
+ ],
286
+ ]);
287
+
288
+ $this->assertSame('bt_buyer_us@paypal.com', $result->paymentMethod->email);
289
+ $this->assertSame($paymentMethodToken, $result->paymentMethod->token);
290
+ $this->assertSame($customer->id, $result->paymentMethod->customerId);
291
+ }
292
+
293
+ public function testCreate_fromUsBankAccountNonce()
294
+ {
295
+ $customer = Braintree\Customer::createNoValidate();
296
+ $http = new HttpClientApi(Braintree\Configuration::$global);
297
+ $result = Braintree\PaymentMethod::create([
298
+ 'customerId' => $customer->id,
299
+ 'paymentMethodNonce' => Test\Helper::generateValidUsBankAccountNonce()
300
+ ]);
301
+
302
+ $usBankAccount = $result->paymentMethod;
303
+ $this->assertEquals('021000021', $usBankAccount->routingNumber);
304
+ $this->assertEquals('1234', $usBankAccount->last4);
305
+ $this->assertEquals('checking', $usBankAccount->accountType);
306
+ $this->assertEquals('Dan Schulman', $usBankAccount->accountHolderName);
307
+ $this->assertRegexp('/CHASE/', $usBankAccount->bankName);
308
+ }
309
+
310
+ public function testCreate_fromAbstractPaymentMethodNonce()
311
+ {
312
+ $customer = Braintree\Customer::createNoValidate();
313
+
314
+ $result = Braintree\PaymentMethod::create([
315
+ 'customerId' => $customer->id,
316
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$abstractTransactable,
317
+ ]);
318
+
319
+ $this->assertTrue($result->success);
320
+ $this->assertNotNull($result->paymentMethod->token);
321
+ $this->assertSame($customer->id, $result->paymentMethod->customerId);
322
+ }
323
+
324
+ public function testCreate_doesNotWorkForUnvalidatedOnetimePaypalAccountNonce()
325
+ {
326
+ $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
327
+ $customer = Braintree\Customer::createNoValidate();
328
+ $http = new HttpClientApi(Braintree\Configuration::$global);
329
+ $nonce = $http->nonceForPayPalAccount([
330
+ 'paypal_account' => [
331
+ 'access_token' => 'PAYPAL_ACCESS_TOKEN',
332
+ 'token' => $paymentMethodToken
333
+ ]
334
+ ]);
335
+
336
+ $result = Braintree\PaymentMethod::create([
337
+ 'customerId' => $customer->id,
338
+ 'paymentMethodNonce' => $nonce
339
+ ]);
340
+
341
+ $this->assertFalse($result->success);
342
+ $errors = $result->errors->forKey('paypalAccount')->errors;
343
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
344
+ }
345
+
346
+ public function testCreate_handlesValidationErrorsForPayPalAccounts()
347
+ {
348
+ $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
349
+ $customer = Braintree\Customer::createNoValidate();
350
+ $http = new HttpClientApi(Braintree\Configuration::$global);
351
+ $nonce = $http->nonceForPayPalAccount([
352
+ 'paypal_account' => [
353
+ 'token' => $paymentMethodToken
354
+ ]
355
+ ]);
356
+
357
+ $result = Braintree\PaymentMethod::create([
358
+ 'customerId' => $customer->id,
359
+ 'paymentMethodNonce' => $nonce
360
+ ]);
361
+
362
+ $this->assertFalse($result->success);
363
+ $errors = $result->errors->forKey('paypalAccount')->errors;
364
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
365
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CONSENT_CODE_OR_ACCESS_TOKEN_IS_REQUIRED, $errors[1]->code);
366
+ }
367
+
368
+ public function testCreate_allowsPassingDefaultOptionWithNonce()
369
+ {
370
+ $customer = Braintree\Customer::createNoValidate();
371
+ $card1 = Braintree\CreditCard::create([
372
+ 'customerId' => $customer->id,
373
+ 'cardholderName' => 'Cardholder',
374
+ 'number' => '5105105105105100',
375
+ 'expirationDate' => '05/12'
376
+ ])->creditCard;
377
+
378
+ $this->assertTrue($card1->isDefault());
379
+
380
+ $http = new HttpClientApi(Braintree\Configuration::$global);
381
+ $nonce = $http->nonce_for_new_card([
382
+ 'credit_card' => [
383
+ 'number' => '4111111111111111',
384
+ 'expirationMonth' => '11',
385
+ 'expirationYear' => '2099',
386
+ 'options' => [
387
+ 'validate' => false
388
+ ]
389
+ ]
390
+ ]);
391
+
392
+ $result = Braintree\PaymentMethod::create([
393
+ 'customerId' => $customer->id,
394
+ 'paymentMethodNonce' => $nonce,
395
+ 'options' => [
396
+ 'makeDefault' => true
397
+ ]
398
+ ]);
399
+
400
+ $card2 = $result->paymentMethod;
401
+ $card1 = Braintree\CreditCard::find($card1->token);
402
+ $this->assertFalse($card1->isDefault());
403
+ $this->assertTrue($card2->isDefault());
404
+ }
405
+
406
+ public function testCreate_overridesNonceToken()
407
+ {
408
+ $customer = Braintree\Customer::createNoValidate();
409
+ $firstToken = 'FIRST_TOKEN-' . strval(rand());
410
+ $secondToken = 'SECOND_TOKEN-' . strval(rand());
411
+ $http = new HttpClientApi(Braintree\Configuration::$global);
412
+ $nonce = $http->nonce_for_new_card([
413
+ 'credit_card' => [
414
+ 'token' => $firstToken,
415
+ 'number' => '4111111111111111',
416
+ 'expirationMonth' => '11',
417
+ 'expirationYear' => '2099',
418
+ 'options' => [
419
+ 'validate' => false
420
+ ]
421
+ ]
422
+ ]);
423
+
424
+ $result = Braintree\PaymentMethod::create([
425
+ 'customerId' => $customer->id,
426
+ 'paymentMethodNonce' => $nonce,
427
+ 'token' => $secondToken
428
+ ]);
429
+
430
+ $card = $result->paymentMethod;
431
+ $this->assertEquals($secondToken, $card->token);
432
+ }
433
+
434
+ public function testCreateWithVerificationAmount()
435
+ {
436
+ $http = new HttpClientApi(Braintree\Configuration::$global);
437
+ $nonce = $http->nonce_for_new_card([
438
+ 'credit_card' => [
439
+ 'number' => '4000111111111115',
440
+ 'expirationMonth' => '11',
441
+ 'expirationYear' => '2099',
442
+ ]
443
+ ]);
444
+ $customer = Braintree\Customer::createNoValidate();
445
+ $result = Braintree\PaymentMethod::create([
446
+ 'paymentMethodNonce' => $nonce,
447
+ 'customerId' => $customer->id,
448
+ 'options' => [
449
+ 'verifyCard' => 'true',
450
+ 'verificationAmount' => '5.00',
451
+ ]
452
+ ]);
453
+
454
+ $this->assertFalse($result->success);
455
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
456
+ }
457
+
458
+ public function testCreate_respectsVerifyCardAndVerificationMerchantAccountIdWhenIncludedOutsideOfTheNonce()
459
+ {
460
+ $http = new HttpClientApi(Braintree\Configuration::$global);
461
+ $nonce = $http->nonce_for_new_card([
462
+ 'credit_card' => [
463
+ 'number' => '4000111111111115',
464
+ 'expirationMonth' => '11',
465
+ 'expirationYear' => '2099',
466
+ ]
467
+ ]);
468
+ $customer = Braintree\Customer::createNoValidate();
469
+ $result = Braintree\PaymentMethod::create([
470
+ 'paymentMethodNonce' => $nonce,
471
+ 'customerId' => $customer->id,
472
+ 'options' => [
473
+ 'verifyCard' => 'true',
474
+ 'verificationMerchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(),
475
+ ]
476
+ ]);
477
+
478
+ $this->assertFalse($result->success);
479
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
480
+ $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
481
+ $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
482
+ $this->assertEquals(Test\Helper::nonDefaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
483
+ }
484
+
485
+ public function testCreate_respectsFailOnDuplicatePaymentMethodWhenIncludedOutsideTheNonce()
486
+ {
487
+ $customer = Braintree\Customer::createNoValidate();
488
+ $result = Braintree\CreditCard::create([
489
+ 'customerId' => $customer->id,
490
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
491
+ 'expirationDate' => "05/2012"
492
+ ]);
493
+ $this->assertTrue($result->success);
494
+
495
+ $http = new HttpClientApi(Braintree\Configuration::$global);
496
+ $nonce = $http->nonce_for_new_card([
497
+ 'credit_card' => [
498
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
499
+ 'expirationDate' => "05/2012"
500
+ ]
501
+ ]);
502
+ $updateResult = Braintree\PaymentMethod::create([
503
+ 'paymentMethodNonce' => $nonce,
504
+ 'customerId' => $customer->id,
505
+ 'options' => [
506
+ 'failOnDuplicatePaymentMethod' => 'true',
507
+ ]
508
+ ]);
509
+
510
+ $this->assertFalse($updateResult->success);
511
+ $resultErrors = $updateResult->errors->deepAll();
512
+ $this->assertEquals("81724", $resultErrors[0]->code);
513
+ }
514
+
515
+ public function testCreate_allowsPassingABillingAddressOutsideOfTheNonce()
516
+ {
517
+ $customer = Braintree\Customer::createNoValidate();
518
+ $http = new HttpClientApi(Braintree\Configuration::$global);
519
+ $nonce = $http->nonce_for_new_card([
520
+ 'credit_card' => [
521
+ 'number' => '4111111111111111',
522
+ 'expirationMonth' => '12',
523
+ 'expirationYear' => '2020',
524
+ 'options' => [
525
+ 'validate' => false
526
+ ]
527
+ ]
528
+ ]);
529
+
530
+ $result = Braintree\PaymentMethod::create([
531
+ 'paymentMethodNonce' => $nonce,
532
+ 'customerId' => $customer->id,
533
+ 'billingAddress' => [
534
+ 'streetAddress' => '123 Abc Way'
535
+ ]
536
+ ]);
537
+
538
+ $this->assertTrue($result->success);
539
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
540
+ $token = $result->paymentMethod->token;
541
+
542
+ $foundCreditCard = Braintree\CreditCard::find($token);
543
+ $this->assertTrue(NULL != $foundCreditCard);
544
+ $this->assertEquals('123 Abc Way', $foundCreditCard->billingAddress->streetAddress);
545
+ }
546
+
547
+ public function testCreate_overridesTheBillingAddressInTheNonce()
548
+ {
549
+ $customer = Braintree\Customer::createNoValidate();
550
+ $http = new HttpClientApi(Braintree\Configuration::$global);
551
+ $nonce = $http->nonce_for_new_card([
552
+ 'credit_card' => [
553
+ 'number' => '4111111111111111',
554
+ 'expirationMonth' => '12',
555
+ 'expirationYear' => '2020',
556
+ 'options' => [
557
+ 'validate' => false
558
+ ],
559
+ 'billingAddress' => [
560
+ 'streetAddress' => '456 Xyz Way'
561
+ ]
562
+ ]
563
+ ]);
564
+
565
+ $result = Braintree\PaymentMethod::create([
566
+ 'paymentMethodNonce' => $nonce,
567
+ 'customerId' => $customer->id,
568
+ 'billingAddress' => [
569
+ 'streetAddress' => '123 Abc Way'
570
+ ]
571
+ ]);
572
+
573
+ $this->assertTrue($result->success);
574
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
575
+ $token = $result->paymentMethod->token;
576
+
577
+ $foundCreditCard = Braintree\CreditCard::find($token);
578
+ $this->assertTrue(NULL != $foundCreditCard);
579
+ $this->assertEquals('123 Abc Way', $foundCreditCard->billingAddress->streetAddress);
580
+ }
581
+
582
+ public function testCreate_doesNotOverrideTheBillingAddressForAVaultedCreditCard()
583
+ {
584
+ $customer = Braintree\Customer::createNoValidate();
585
+ $http = new HttpClientApi(Braintree\Configuration::$global);
586
+ $nonce = $http->nonce_for_new_card([
587
+ 'customerId' => $customer->id,
588
+ 'credit_card' => [
589
+ 'number' => '4111111111111111',
590
+ 'expirationMonth' => '12',
591
+ 'expirationYear' => '2020',
592
+ 'billingAddress' => [
593
+ 'streetAddress' => '456 Xyz Way'
594
+ ]
595
+ ]
596
+ ]);
597
+
598
+ $result = Braintree\PaymentMethod::create([
599
+ 'paymentMethodNonce' => $nonce,
600
+ 'customerId' => $customer->id,
601
+ 'billingAddress' => [
602
+ 'streetAddress' => '123 Abc Way'
603
+ ]
604
+ ]);
605
+
606
+ $this->assertTrue($result->success);
607
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
608
+ $token = $result->paymentMethod->token;
609
+
610
+ $foundCreditCard = Braintree\CreditCard::find($token);
611
+ $this->assertTrue(NULL != $foundCreditCard);
612
+ $this->assertEquals('456 Xyz Way', $foundCreditCard->billingAddress->streetAddress);
613
+ }
614
+
615
+ public function testCreate_allowsPassingABillingAddressIdOutsideOfTheNonce()
616
+ {
617
+ $customer = Braintree\Customer::createNoValidate();
618
+ $http = new HttpClientApi(Braintree\Configuration::$global);
619
+ $nonce = $http->nonce_for_new_card([
620
+ 'credit_card' => [
621
+ 'number' => '4111111111111111',
622
+ 'expirationMonth' => '12',
623
+ 'expirationYear' => '2020',
624
+ 'options' => [
625
+ 'validate' => false
626
+ ]
627
+ ]
628
+ ]);
629
+
630
+ $address = Braintree\Address::create([
631
+ 'customerId' => $customer->id,
632
+ 'firstName' => 'Bobby',
633
+ 'lastName' => 'Tables'
634
+ ])->address;
635
+ $result = Braintree\PaymentMethod::create([
636
+ 'paymentMethodNonce' => $nonce,
637
+ 'customerId' => $customer->id,
638
+ 'billingAddressId' => $address->id
639
+ ]);
640
+
641
+ $this->assertTrue($result->success);
642
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
643
+ $token = $result->paymentMethod->token;
644
+
645
+ $foundCreditCard = Braintree\CreditCard::find($token);
646
+ $this->assertTrue(NULL != $foundCreditCard);
647
+ $this->assertEquals('Bobby', $foundCreditCard->billingAddress->firstName);
648
+ $this->assertEquals('Tables', $foundCreditCard->billingAddress->lastName);
649
+ }
650
+
651
+ public function testCreate_doesNotReturnAnErrorIfCreditCardOptionsArePresentForAPaypalNonce()
652
+ {
653
+ $customer = Braintree\Customer::createNoValidate();
654
+ $originalToken = 'paypal-account-' . strval(rand());
655
+ $http = new HttpClientApi(Braintree\Configuration::$global);
656
+ $nonce = $http->nonceForPaypalAccount([
657
+ 'paypalAccount' => [
658
+ 'consentCode' => 'consent-code',
659
+ 'token' => $originalToken
660
+ ]
661
+ ]);
662
+
663
+ $result = Braintree\PaymentMethod::create([
664
+ 'paymentMethodNonce' => $nonce,
665
+ 'customerId' => $customer->id,
666
+ 'options' => [
667
+ 'verifyCard' => 'true',
668
+ 'failOnDuplicatePaymentMethod' => 'true',
669
+ 'verificationMerchantAccountId' => 'Not a Real Merchant Account Id'
670
+ ]
671
+ ]);
672
+
673
+ $this->assertTrue($result->success);
674
+ }
675
+
676
+ public function testCreate_ignoresPassedBillingAddressParamsForPaypalAccount()
677
+ {
678
+ $http = new HttpClientApi(Braintree\Configuration::$global);
679
+ $nonce = $http->nonceForPaypalAccount([
680
+ 'paypalAccount' => [
681
+ 'consentCode' => 'PAYPAL_CONSENT_CODE',
682
+ ]
683
+ ]);
684
+ $customer = Braintree\Customer::createNoValidate();
685
+ $result = Braintree\PaymentMethod::create([
686
+ 'paymentMethodNonce' => $nonce,
687
+ 'customerId' => $customer->id,
688
+ 'billingAddress' => [
689
+ 'streetAddress' => '123 Abc Way'
690
+ ]
691
+ ]);
692
+
693
+ $this->assertTrue($result->success);
694
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\PaypalAccount'));
695
+ $token = $result->paymentMethod->token;
696
+
697
+ $foundPaypalAccount = Braintree\PaypalAccount::find($token);
698
+ $this->assertTrue(NULL != $foundPaypalAccount);
699
+ }
700
+
701
+ public function testCreate_ignoresPassedBillingAddressIdForPaypalAccount()
702
+ {
703
+ $http = new HttpClientApi(Braintree\Configuration::$global);
704
+ $nonce = $http->nonceForPaypalAccount([
705
+ 'paypalAccount' => [
706
+ 'consentCode' => 'PAYPAL_CONSENT_CODE',
707
+ ]
708
+ ]);
709
+ $customer = Braintree\Customer::createNoValidate();
710
+ $result = Braintree\PaymentMethod::create([
711
+ 'paymentMethodNonce' => $nonce,
712
+ 'customerId' => $customer->id,
713
+ 'billingAddressId' => 'address_id'
714
+ ]);
715
+
716
+ $this->assertTrue($result->success);
717
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\PaypalAccount'));
718
+ $token = $result->paymentMethod->token;
719
+
720
+ $foundPaypalAccount = Braintree\PaypalAccount::find($token);
721
+ $this->assertTrue(NULL != $foundPaypalAccount);
722
+ }
723
+
724
+ public function testCreate_acceptsNumberAndOtherCreditCardParameters()
725
+ {
726
+ $customer = Braintree\Customer::createNoValidate();
727
+ $result = Braintree\PaymentMethod::create([
728
+ 'customerId' => $customer->id,
729
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$transactable,
730
+ 'cardholderName' => 'Jane Doe',
731
+ 'cvv' => '123',
732
+ 'expirationMonth' => '10',
733
+ 'expirationYear' => '24',
734
+ 'number' => '4242424242424242'
735
+ ]);
736
+
737
+ $this->assertTrue($result->success);
738
+ $this->assertTrue('Jane Doe' == $result->paymentMethod->cardholderName);
739
+ $this->assertTrue('10' == $result->paymentMethod->expirationMonth);
740
+ $this->assertTrue('2024' == $result->paymentMethod->expirationYear);
741
+ $this->assertTrue('424242' == $result->paymentMethod->bin);
742
+ $this->assertTrue('4242' == $result->paymentMethod->last4);
743
+ }
744
+
745
+ public function testFind_returnsCreditCards()
746
+ {
747
+ $paymentMethodToken = 'CREDIT_CARD_TOKEN-' . strval(rand());
748
+ $customer = Braintree\Customer::createNoValidate();
749
+ $creditCardResult = Braintree\CreditCard::create([
750
+ 'customerId' => $customer->id,
751
+ 'number' => '5105105105105100',
752
+ 'expirationDate' => '05/2011',
753
+ 'token' => $paymentMethodToken
754
+ ]);
755
+ $this->assertTrue($creditCardResult->success);
756
+
757
+ $foundCreditCard = Braintree\PaymentMethod::find($creditCardResult->creditCard->token);
758
+
759
+ $this->assertEquals($paymentMethodToken, $foundCreditCard->token);
760
+ $this->assertEquals('510510', $foundCreditCard->bin);
761
+ $this->assertEquals('5100', $foundCreditCard->last4);
762
+ $this->assertEquals('05/2011', $foundCreditCard->expirationDate);
763
+ }
764
+
765
+ public function testFind_returnsCreditCardsWithSubscriptions()
766
+ {
767
+ $customer = Braintree\Customer::createNoValidate();
768
+ $creditCardResult = Braintree\CreditCard::create([
769
+ 'customerId' => $customer->id,
770
+ 'number' => '5105105105105100',
771
+ 'expirationDate' => '05/2011',
772
+ ]);
773
+ $this->assertTrue($creditCardResult->success);
774
+
775
+ $subscriptionId = strval(rand());
776
+ Braintree\Subscription::create([
777
+ 'id' => $subscriptionId,
778
+ 'paymentMethodToken' => $creditCardResult->creditCard->token,
779
+ 'planId' => 'integration_trialless_plan',
780
+ 'price' => '1.00'
781
+ ]);
782
+
783
+ $foundCreditCard = Braintree\PaymentMethod::find($creditCardResult->creditCard->token);
784
+ $this->assertEquals($subscriptionId, $foundCreditCard->subscriptions[0]->id);
785
+ $this->assertEquals('integration_trialless_plan', $foundCreditCard->subscriptions[0]->planId);
786
+ $this->assertEquals('1.00', $foundCreditCard->subscriptions[0]->price);
787
+ }
788
+
789
+ public function testFind_returnsPayPalAccounts()
790
+ {
791
+ $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
792
+ $customer = Braintree\Customer::createNoValidate();
793
+ $http = new HttpClientApi(Braintree\Configuration::$global);
794
+ $nonce = $http->nonceForPayPalAccount([
795
+ 'paypal_account' => [
796
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
797
+ 'token' => $paymentMethodToken
798
+ ]
799
+ ]);
800
+
801
+ Braintree\PaymentMethod::create([
802
+ 'customerId' => $customer->id,
803
+ 'paymentMethodNonce' => $nonce
804
+ ]);
805
+
806
+ $foundPayPalAccount = Braintree\PaymentMethod::find($paymentMethodToken);
807
+
808
+ $this->assertSame('jane.doe@example.com', $foundPayPalAccount->email);
809
+ $this->assertSame($paymentMethodToken, $foundPayPalAccount->token);
810
+ }
811
+
812
+ public function testFind_returnsUsBankAccount()
813
+ {
814
+ $customer = Braintree\Customer::createNoValidate();
815
+ $http = new HttpClientApi(Braintree\Configuration::$global);
816
+ $result = Braintree\PaymentMethod::create([
817
+ 'customerId' => $customer->id,
818
+ 'paymentMethodNonce' => Test\Helper::generateValidUsBankAccountNonce()
819
+ ]);
820
+
821
+ $foundUsBankAccount = Braintree\PaymentMethod::find($result->paymentMethod->token);
822
+ $this->assertInstanceOf('Braintree\UsBankAccount', $foundUsBankAccount);
823
+ $this->assertEquals('021000021', $foundUsBankAccount->routingNumber);
824
+ $this->assertEquals('1234', $foundUsBankAccount->last4);
825
+ $this->assertEquals('checking', $foundUsBankAccount->accountType);
826
+ $this->assertEquals('Dan Schulman', $foundUsBankAccount->accountHolderName);
827
+ $this->assertRegExp('/CHASE/', $foundUsBankAccount->bankName);
828
+ }
829
+
830
+ public function testFind_returnsApplePayCards()
831
+ {
832
+ $paymentMethodToken = 'APPLE_PAY-' . strval(rand());
833
+ $customer = Braintree\Customer::createNoValidate();
834
+ $nonce = Braintree\Test\Nonces::$applePayVisa;
835
+ Braintree\PaymentMethod::create([
836
+ 'customerId' => $customer->id,
837
+ 'paymentMethodNonce' => $nonce,
838
+ 'token' => $paymentMethodToken
839
+ ]);
840
+
841
+ $foundApplePayCard = Braintree\PaymentMethod::find($paymentMethodToken);
842
+
843
+ $this->assertSame($paymentMethodToken, $foundApplePayCard->token);
844
+ $this->assertInstanceOf('Braintree\ApplePayCard', $foundApplePayCard);
845
+ $this->assertTrue(intval($foundApplePayCard->expirationMonth) > 0);
846
+ $this->assertTrue(intval($foundApplePayCard->expirationYear) > 0);
847
+ }
848
+
849
+ public function testFind_returnsAndroidPayCards()
850
+ {
851
+ $paymentMethodToken = 'ANDROID-PAY-' . strval(rand());
852
+ $customer = Braintree\Customer::createNoValidate();
853
+ $nonce = Braintree\Test\Nonces::$androidPay;
854
+ Braintree\PaymentMethod::create([
855
+ 'customerId' => $customer->id,
856
+ 'paymentMethodNonce' => $nonce,
857
+ 'token' => $paymentMethodToken
858
+ ]);
859
+
860
+ $foundAndroidPayCard = Braintree\PaymentMethod::find($paymentMethodToken);
861
+
862
+ $this->assertSame($paymentMethodToken, $foundAndroidPayCard->token);
863
+ $this->assertInstanceOf('Braintree\AndroidPayCard', $foundAndroidPayCard);
864
+ $this->assertSame(Braintree\CreditCard::DISCOVER, $foundAndroidPayCard->virtualCardType);
865
+ $this->assertSame("1117", $foundAndroidPayCard->virtualCardLast4);
866
+ $this->assertSame(Braintree\CreditCard::VISA, $foundAndroidPayCard->sourceCardType);
867
+ $this->assertSame("1111", $foundAndroidPayCard->sourceCardLast4);
868
+ $this->assertSame($customer->id, $foundAndroidPayCard->customerId);
869
+ $this->assertTrue($foundAndroidPayCard->default);
870
+ $this->assertContains('android_pay', $foundAndroidPayCard->imageUrl);
871
+ $this->assertTrue(intval($foundAndroidPayCard->expirationMonth) > 0);
872
+ $this->assertTrue(intval($foundAndroidPayCard->expirationYear) > 0);
873
+ }
874
+
875
+ public function testFind_returnsCoinbaseAccounts()
876
+ {
877
+ $customer = Braintree\Customer::createNoValidate();
878
+ $result = Braintree\PaymentMethod::create([
879
+ 'customerId' => $customer->id,
880
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$coinbase
881
+ ]);
882
+
883
+ $this->assertTrue($result->success);
884
+ $coinbaseAccount = $result->paymentMethod;
885
+ $this->assertNotNull($coinbaseAccount->token);
886
+ $foundCoinbaseAccount = Braintree\PaymentMethod::find($coinbaseAccount->token);
887
+ $this->assertInstanceOf('Braintree\CoinbaseAccount', $foundCoinbaseAccount);
888
+ $this->assertNotNull($foundCoinbaseAccount->userId);
889
+ $this->assertNotNull($foundCoinbaseAccount->userName);
890
+ $this->assertNotNull($foundCoinbaseAccount->userEmail);
891
+ $this->assertNotNull($foundCoinbaseAccount->customerId);
892
+ }
893
+
894
+
895
+ public function testFind_returnsAbstractPaymentMethods()
896
+ {
897
+ $paymentMethodToken = 'ABSTRACT-' . strval(rand());
898
+ $customer = Braintree\Customer::createNoValidate();
899
+ $nonce = Braintree\Test\Nonces::$abstractTransactable;
900
+ Braintree\PaymentMethod::create([
901
+ 'customerId' => $customer->id,
902
+ 'paymentMethodNonce' => $nonce,
903
+ 'token' => $paymentMethodToken
904
+ ]);
905
+
906
+ $foundPaymentMethod = Braintree\PaymentMethod::find($paymentMethodToken);
907
+
908
+ $this->assertSame($paymentMethodToken, $foundPaymentMethod-> token);
909
+ }
910
+
911
+ public function testFind_throwsIfCannotBeFound()
912
+ {
913
+ $this->setExpectedException('Braintree\Exception\NotFound');
914
+ Braintree\PaymentMethod::find('NON_EXISTENT_TOKEN');
915
+ }
916
+
917
+ public function testUpdate_updatesTheCreditCard()
918
+ {
919
+ $customer = Braintree\Customer::createNoValidate();
920
+ $creditCardResult = Braintree\CreditCard::create([
921
+ 'cardholderName' => 'Original Holder',
922
+ 'customerId' => $customer->id,
923
+ 'cvv' => '123',
924
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
925
+ 'expirationDate' => "05/2012"
926
+ ]);
927
+ $this->assertTrue($creditCardResult->success);
928
+ $creditCard = $creditCardResult->creditCard;
929
+
930
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
931
+ 'cardholderName' => 'New Holder',
932
+ 'cvv' => '456',
933
+ 'number' => Braintree\Test\CreditCardNumbers::$masterCard,
934
+ 'expirationDate' => "06/2013"
935
+ ]);
936
+
937
+ $this->assertTrue($updateResult->success);
938
+ $this->assertSame($updateResult->paymentMethod->token, $creditCard->token);
939
+ $updatedCreditCard = $updateResult->paymentMethod;
940
+ $this->assertSame("New Holder", $updatedCreditCard->cardholderName);
941
+ $this->assertSame(substr(Braintree\Test\CreditCardNumbers::$masterCard, 0, 6), $updatedCreditCard->bin);
942
+ $this->assertSame(substr(Braintree\Test\CreditCardNumbers::$masterCard, -4), $updatedCreditCard->last4);
943
+ $this->assertSame("06/2013", $updatedCreditCard->expirationDate);
944
+ }
945
+
946
+ public function testUpdate_updatesTheCoinbaseAccount()
947
+ {
948
+ $customer = Braintree\Customer::createNoValidate();
949
+
950
+ $result = Braintree\PaymentMethod::create([
951
+ 'customerId' => $customer->id,
952
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$venmoAccount
953
+ ]);
954
+ $this->assertTrue($result->success);
955
+ $this->assertTrue($result->paymentMethod->isDefault());
956
+
957
+ $result = Braintree\PaymentMethod::create([
958
+ 'customerId' => $customer->id,
959
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$coinbase
960
+ ]);
961
+ $this->assertTrue($result->success);
962
+ $coinbaseAccount = $result->paymentMethod;
963
+
964
+ $updateResult = Braintree\PaymentMethod::update($coinbaseAccount->token, [
965
+ 'options' => [
966
+ 'makeDefault' => 'true'
967
+ ]
968
+ ]);
969
+
970
+ $this->assertTrue($updateResult->success);
971
+ $this->assertSame($updateResult->paymentMethod->token, $coinbaseAccount->token);
972
+ $updatedCoinbaseAccount = $updateResult->paymentMethod;
973
+ $this->assertTrue($updatedCoinbaseAccount->isDefault());
974
+ }
975
+
976
+ public function testUpdate_createsANewBillingAddressByDefault()
977
+ {
978
+ $customer = Braintree\Customer::createNoValidate();
979
+ $creditCardResult = Braintree\CreditCard::create([
980
+ 'customerId' => $customer->id,
981
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
982
+ 'expirationDate' => "05/2012",
983
+ 'billingAddress' => [
984
+ 'streetAddress' => '123 Nigeria Ave'
985
+ ]
986
+ ]);
987
+ $this->assertTrue($creditCardResult->success);
988
+ $creditCard = $creditCardResult->creditCard;
989
+
990
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
991
+ 'billingAddress' => [
992
+ 'region' => 'IL'
993
+ ]
994
+ ]);
995
+
996
+ $this->assertTrue($updateResult->success);
997
+ $updatedCreditCard = $updateResult->paymentMethod;
998
+ $this->assertSame("IL", $updatedCreditCard->billingAddress->region);
999
+ $this->assertSame(NULL, $updatedCreditCard->billingAddress->streetAddress);
1000
+ $this->assertFalse($creditCard->billingAddress->id == $updatedCreditCard->billingAddress->id);
1001
+ }
1002
+
1003
+ public function testUpdate_updatesTheBillingAddressIfOptionIsSpecified()
1004
+ {
1005
+ $customer = Braintree\Customer::createNoValidate();
1006
+ $creditCardResult = Braintree\CreditCard::create([
1007
+ 'customerId' => $customer->id,
1008
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1009
+ 'expirationDate' => "05/2012",
1010
+ 'billingAddress' => [
1011
+ 'streetAddress' => '123 Nigeria Ave'
1012
+ ]
1013
+ ]);
1014
+ $this->assertTrue($creditCardResult->success);
1015
+ $creditCard = $creditCardResult->creditCard;
1016
+
1017
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
1018
+ 'billingAddress' => [
1019
+ 'region' => 'IL',
1020
+ 'options' => [
1021
+ 'updateExisting' => 'true'
1022
+ ]
1023
+ ],
1024
+ ]);
1025
+
1026
+ $this->assertTrue($updateResult->success);
1027
+ $updatedCreditCard = $updateResult->paymentMethod;
1028
+ $this->assertSame("IL", $updatedCreditCard->billingAddress->region);
1029
+ $this->assertSame("123 Nigeria Ave", $updatedCreditCard->billingAddress->streetAddress);
1030
+ $this->assertTrue($creditCard->billingAddress->id == $updatedCreditCard->billingAddress->id);
1031
+ }
1032
+
1033
+ public function testUpdate_updatesTheCountryViaCodes()
1034
+ {
1035
+ $customer = Braintree\Customer::createNoValidate();
1036
+ $creditCardResult = Braintree\CreditCard::create([
1037
+ 'customerId' => $customer->id,
1038
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1039
+ 'expirationDate' => "05/2012",
1040
+ 'billingAddress' => [
1041
+ 'streetAddress' => '123 Nigeria Ave'
1042
+ ]
1043
+ ]);
1044
+ $this->assertTrue($creditCardResult->success);
1045
+ $creditCard = $creditCardResult->creditCard;
1046
+
1047
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
1048
+ 'billingAddress' => [
1049
+ 'countryName' => 'American Samoa',
1050
+ 'countryCodeAlpha2' => 'AS',
1051
+ 'countryCodeAlpha3' => 'ASM',
1052
+ 'countryCodeNumeric' => '016',
1053
+ 'options' => [
1054
+ 'updateExisting' => 'true'
1055
+ ]
1056
+ ],
1057
+ ]);
1058
+
1059
+ $this->assertTrue($updateResult->success);
1060
+ $updatedCreditCard = $updateResult->paymentMethod;
1061
+ $this->assertSame("American Samoa", $updatedCreditCard->billingAddress->countryName);
1062
+ $this->assertSame("AS", $updatedCreditCard->billingAddress->countryCodeAlpha2);
1063
+ $this->assertSame("ASM", $updatedCreditCard->billingAddress->countryCodeAlpha3);
1064
+ $this->assertSame("016", $updatedCreditCard->billingAddress->countryCodeNumeric);
1065
+ }
1066
+
1067
+ public function testUpdate_canPassExpirationMonthAndExpirationYear()
1068
+ {
1069
+ $customer = Braintree\Customer::createNoValidate();
1070
+ $creditCardResult = Braintree\CreditCard::create([
1071
+ 'customerId' => $customer->id,
1072
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1073
+ 'expirationDate' => "05/2012"
1074
+ ]);
1075
+ $this->assertTrue($creditCardResult->success);
1076
+ $creditCard = $creditCardResult->creditCard;
1077
+
1078
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
1079
+ 'number' => Braintree\Test\CreditCardNumbers::$masterCard,
1080
+ 'expirationMonth' => "07",
1081
+ 'expirationYear' => "2011"
1082
+ ]);
1083
+
1084
+ $this->assertTrue($updateResult->success);
1085
+ $this->assertSame($updateResult->paymentMethod->token, $creditCard->token);
1086
+ $updatedCreditCard = $updateResult->paymentMethod;
1087
+ $this->assertSame("07", $updatedCreditCard->expirationMonth);
1088
+ $this->assertSame("07", $updatedCreditCard->expirationMonth);
1089
+ $this->assertSame("07/2011", $updatedCreditCard->expirationDate);
1090
+ }
1091
+
1092
+ public function testUpdate_verifiesTheUpdateIfOptionsVerifyCardIsTrue()
1093
+ {
1094
+ $customer = Braintree\Customer::createNoValidate();
1095
+ $creditCardResult = Braintree\CreditCard::create([
1096
+ 'cardholderName' => 'Original Holder',
1097
+ 'customerId' => $customer->id,
1098
+ 'cvv' => '123',
1099
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1100
+ 'expirationDate' => "05/2012"
1101
+ ]);
1102
+ $this->assertTrue($creditCardResult->success);
1103
+ $creditCard = $creditCardResult->creditCard;
1104
+
1105
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
1106
+ 'cardholderName' => 'New Holder',
1107
+ 'cvv' => '456',
1108
+ 'number' => Braintree\Test\CreditCardNumbers::$failsSandboxVerification['MasterCard'],
1109
+ 'expirationDate' => "06/2013",
1110
+ 'options' => [
1111
+ 'verifyCard' => 'true'
1112
+ ]
1113
+ ]);
1114
+
1115
+ $this->assertFalse($updateResult->success);
1116
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $updateResult->creditCardVerification->status);
1117
+ $this->assertEquals(NULL, $updateResult->creditCardVerification->gatewayRejectionReason);
1118
+ }
1119
+
1120
+ public function testUpdate_canPassCustomVerificationAmount()
1121
+ {
1122
+ $customer = Braintree\Customer::createNoValidate();
1123
+ $creditCardResult = Braintree\CreditCard::create([
1124
+ 'cardholderName' => 'Card Holder',
1125
+ 'customerId' => $customer->id,
1126
+ 'cvv' => '123',
1127
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1128
+ 'expirationDate' => "05/2020"
1129
+ ]);
1130
+ $this->assertTrue($creditCardResult->success);
1131
+ $creditCard = $creditCardResult->creditCard;
1132
+
1133
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
1134
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$processorDeclinedMasterCard,
1135
+ 'options' => [
1136
+ 'verifyCard' => 'true',
1137
+ 'verificationAmount' => '2.34'
1138
+ ]
1139
+ ]);
1140
+
1141
+ $this->assertFalse($updateResult->success);
1142
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $updateResult->creditCardVerification->status);
1143
+ $this->assertEquals(NULL, $updateResult->creditCardVerification->gatewayRejectionReason);
1144
+ }
1145
+
1146
+ public function testUpdate_canUpdateTheBillingAddress()
1147
+ {
1148
+ $customer = Braintree\Customer::createNoValidate();
1149
+ $creditCardResult = Braintree\CreditCard::create([
1150
+ 'cardholderName' => 'Original Holder',
1151
+ 'customerId' => $customer->id,
1152
+ 'cvv' => '123',
1153
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1154
+ 'expirationDate' => '05/2012',
1155
+ 'billingAddress' => [
1156
+ 'firstName' => 'Old First Name',
1157
+ 'lastName' => 'Old Last Name',
1158
+ 'company' => 'Old Company',
1159
+ 'streetAddress' => '123 Old St',
1160
+ 'extendedAddress' => 'Apt Old',
1161
+ 'locality' => 'Old City',
1162
+ 'region' => 'Old State',
1163
+ 'postalCode' => '12345',
1164
+ 'countryName' => 'Canada'
1165
+ ]
1166
+ ]);
1167
+ $this->assertTrue($creditCardResult->success);
1168
+ $creditCard = $creditCardResult->creditCard;
1169
+
1170
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
1171
+ 'billingAddress' => [
1172
+ 'firstName' => 'New First Name',
1173
+ 'lastName' => 'New Last Name',
1174
+ 'company' => 'New Company',
1175
+ 'streetAddress' => '123 New St',
1176
+ 'extendedAddress' => 'Apt New',
1177
+ 'locality' => 'New City',
1178
+ 'region' => 'New State',
1179
+ 'postalCode' => '56789',
1180
+ 'countryName' => 'United States of America'
1181
+ ]
1182
+ ]);
1183
+
1184
+ $this->assertTrue($updateResult->success);
1185
+ $address = $updateResult->paymentMethod->billingAddress;
1186
+ $this->assertSame('New First Name', $address->firstName);
1187
+ $this->assertSame('New Last Name', $address->lastName);
1188
+ $this->assertSame('New Company', $address->company);
1189
+ $this->assertSame('123 New St', $address->streetAddress);
1190
+ $this->assertSame('Apt New', $address->extendedAddress);
1191
+ $this->assertSame('New City', $address->locality);
1192
+ $this->assertSame('New State', $address->region);
1193
+ $this->assertSame('56789', $address->postalCode);
1194
+ $this->assertSame('United States of America', $address->countryName);
1195
+ }
1196
+
1197
+ public function testUpdate_returnsAnErrorIfInvalid()
1198
+ {
1199
+ $customer = Braintree\Customer::createNoValidate();
1200
+ $creditCardResult = Braintree\CreditCard::create([
1201
+ 'cardholderName' => 'Original Holder',
1202
+ 'customerId' => $customer->id,
1203
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1204
+ 'expirationDate' => "05/2012"
1205
+ ]);
1206
+ $this->assertTrue($creditCardResult->success);
1207
+ $creditCard = $creditCardResult->creditCard;
1208
+
1209
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
1210
+ 'cardholderName' => 'New Holder',
1211
+ 'number' => 'invalid',
1212
+ 'expirationDate' => "05/2014",
1213
+ ]);
1214
+
1215
+ $this->assertFalse($updateResult->success);
1216
+ $numberErrors = $updateResult->errors->forKey('creditCard')->onAttribute('number');
1217
+ $this->assertEquals("Credit card number must be 12-19 digits.", $numberErrors[0]->message);
1218
+ }
1219
+
1220
+ public function testUpdate_canUpdateTheDefault()
1221
+ {
1222
+ $customer = Braintree\Customer::createNoValidate();
1223
+
1224
+ $creditCardResult1 = Braintree\CreditCard::create([
1225
+ 'customerId' => $customer->id,
1226
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1227
+ 'expirationDate' => "05/2009"
1228
+ ]);
1229
+ $this->assertTrue($creditCardResult1->success);
1230
+ $creditCard1 = $creditCardResult1->creditCard;
1231
+
1232
+ $creditCardResult2 = Braintree\CreditCard::create([
1233
+ 'customerId' => $customer->id,
1234
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1235
+ 'expirationDate' => "05/2009"
1236
+ ]);
1237
+ $this->assertTrue($creditCardResult2->success);
1238
+ $creditCard2 = $creditCardResult2->creditCard;
1239
+
1240
+ $this->assertTrue($creditCard1->default);
1241
+ $this->assertFalse($creditCard2->default);
1242
+
1243
+
1244
+ $updateResult = Braintree\PaymentMethod::update($creditCard2->token, [
1245
+ 'options' => [
1246
+ 'makeDefault' => 'true'
1247
+ ]
1248
+ ]);
1249
+ $this->assertTrue($updateResult->success);
1250
+
1251
+ $this->assertFalse(Braintree\PaymentMethod::find($creditCard1->token)->default);
1252
+ $this->assertTrue(Braintree\PaymentMethod::find($creditCard2->token)->default);
1253
+ }
1254
+
1255
+ public function testUpdate_updatesAPaypalAccountsToken()
1256
+ {
1257
+ $customer = Braintree\Customer::createNoValidate();
1258
+ $originalToken = 'paypal-account-' . strval(rand());
1259
+ $customer = Braintree\Customer::createNoValidate();
1260
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1261
+ $nonce = $http->nonceForPayPalAccount([
1262
+ 'paypal_account' => [
1263
+ 'consent_code' => 'consent-code',
1264
+ 'token' => $originalToken
1265
+ ]
1266
+ ]);
1267
+
1268
+ $originalResult = Braintree\PaymentMethod::create([
1269
+ 'paymentMethodNonce' => $nonce,
1270
+ 'customerId' => $customer->id
1271
+ ]);
1272
+ $this->assertTrue($originalResult->success);
1273
+
1274
+ $originalPaypalAccount = $originalResult->paymentMethod;
1275
+
1276
+ $updatedToken = 'UPDATED_TOKEN-' . strval(rand());
1277
+ $updateResult = Braintree\PaymentMethod::update($originalPaypalAccount->token, [
1278
+ 'token' => $updatedToken
1279
+ ]);
1280
+ $this->assertTrue($updateResult->success);
1281
+
1282
+ $updatedPaypalAccount = Braintree\PaymentMethod::find($updatedToken);
1283
+ $this->assertEquals($originalPaypalAccount->email, $updatedPaypalAccount->email);
1284
+
1285
+ $this->setExpectedException('Braintree\Exception\NotFound', 'payment method with token ' . $originalToken . ' not found');
1286
+ Braintree\PaymentMethod::find($originalToken);
1287
+
1288
+ }
1289
+
1290
+ public function testUpdate_canMakeAPaypalAccountTheDefaultPaymentMethod()
1291
+ {
1292
+ $customer = Braintree\Customer::createNoValidate();
1293
+ $creditCardResult = Braintree\CreditCard::create([
1294
+ 'customerId' => $customer->id,
1295
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1296
+ 'expirationDate' => '05/2009',
1297
+ 'options' => [
1298
+ 'makeDefault' => 'true'
1299
+ ]
1300
+ ]);
1301
+ $this->assertTrue($creditCardResult->success);
1302
+ $creditCard = $creditCardResult->creditCard;
1303
+
1304
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1305
+ $nonce = $http->nonceForPayPalAccount([
1306
+ 'paypal_account' => [
1307
+ 'consent_code' => 'consent-code',
1308
+ ]
1309
+ ]);
1310
+
1311
+ $originalToken = Braintree\PaymentMethod::create([
1312
+ 'paymentMethodNonce' => $nonce,
1313
+ 'customerId' => $customer->id
1314
+ ])->paymentMethod->token;
1315
+
1316
+ $updateResult = Braintree\PaymentMethod::update($originalToken, [
1317
+ 'options' => [
1318
+ 'makeDefault' => 'true'
1319
+ ]
1320
+ ]);
1321
+ $this->assertTrue($updateResult->success);
1322
+
1323
+ $updatedPaypalAccount = Braintree\PaymentMethod::find($originalToken);
1324
+ $this->assertTrue($updatedPaypalAccount->default);
1325
+
1326
+ }
1327
+
1328
+ public function testUpdate_returnsAnErrorIfATokenForAccountIsUsedToAttemptAnUpdate()
1329
+ {
1330
+ $customer = Braintree\Customer::createNoValidate();
1331
+ $firstToken = 'paypal-account-' . strval(rand());
1332
+ $secondToken = 'paypal-account-' . strval(rand());
1333
+
1334
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1335
+ $firstNonce = $http->nonceForPayPalAccount([
1336
+ 'paypal_account' => [
1337
+ 'consent_code' => 'consent-code',
1338
+ 'token' => $firstToken
1339
+ ]
1340
+ ]);
1341
+ $firstResult = Braintree\PaymentMethod::create([
1342
+ 'paymentMethodNonce' => $firstNonce,
1343
+ 'customerId' => $customer->id
1344
+ ]);
1345
+ $this->assertTrue($firstResult->success);
1346
+ $firstPaypalAccount = $firstResult->paymentMethod;
1347
+
1348
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1349
+ $secondNonce = $http->nonceForPayPalAccount([
1350
+ 'paypal_account' => [
1351
+ 'consent_code' => 'consent-code',
1352
+ 'token' => $secondToken
1353
+ ]
1354
+ ]);
1355
+ $secondResult = Braintree\PaymentMethod::create([
1356
+ 'paymentMethodNonce' => $secondNonce,
1357
+ 'customerId' => $customer->id
1358
+ ]);
1359
+ $this->assertTrue($secondResult->success);
1360
+ $secondPaypalAccount = $firstResult->paymentMethod;
1361
+
1362
+
1363
+ $updateResult = Braintree\PaymentMethod::update($firstToken, [
1364
+ 'token' => $secondToken
1365
+ ]);
1366
+
1367
+ $this->assertFalse($updateResult->success);
1368
+ $resultErrors = $updateResult->errors->deepAll();
1369
+ $this->assertEquals("92906", $resultErrors[0]->code);
1370
+
1371
+ }
1372
+
1373
+ public function testDelete_worksWithCreditCards()
1374
+ {
1375
+ $paymentMethodToken = 'CREDIT_CARD_TOKEN-' . strval(rand());
1376
+ $customer = Braintree\Customer::createNoValidate();
1377
+ $creditCardResult = Braintree\CreditCard::create([
1378
+ 'customerId' => $customer->id,
1379
+ 'number' => '5105105105105100',
1380
+ 'expirationDate' => '05/2011',
1381
+ 'token' => $paymentMethodToken
1382
+ ]);
1383
+ $this->assertTrue($creditCardResult->success);
1384
+
1385
+ Braintree\PaymentMethod::delete($paymentMethodToken);
1386
+
1387
+ $this->setExpectedException('Braintree\Exception\NotFound');
1388
+ Braintree\PaymentMethod::find($paymentMethodToken);
1389
+ self::integrationMerchantConfig();
1390
+ }
1391
+
1392
+ public function testDelete_worksWithPayPalAccounts()
1393
+ {
1394
+ $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
1395
+ $customer = Braintree\Customer::createNoValidate();
1396
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1397
+ $nonce = $http->nonceForPayPalAccount([
1398
+ 'paypal_account' => [
1399
+ 'consent_code' => 'PAYPAL_CONSENT_CODE',
1400
+ 'token' => $paymentMethodToken
1401
+ ]
1402
+ ]);
1403
+
1404
+ $paypalAccountResult = Braintree\PaymentMethod::create([
1405
+ 'customerId' => $customer->id,
1406
+ 'paymentMethodNonce' => $nonce
1407
+ ]);
1408
+ $this->assertTrue($paypalAccountResult->success);
1409
+
1410
+ Braintree\PaymentMethod::delete($paymentMethodToken, ['revokeAllGrants' => false]);
1411
+
1412
+ $this->setExpectedException('Braintree\Exception\NotFound');
1413
+ Braintree\PaymentMethod::find($paymentMethodToken);
1414
+ }
1415
+
1416
+ public function testGrant_returnsASingleUseNonce()
1417
+ {
1418
+ $partnerMerchantGateway = new Braintree\Gateway([
1419
+ 'environment' => 'development',
1420
+ 'merchantId' => 'integration_merchant_public_id',
1421
+ 'publicKey' => 'oauth_app_partner_user_public_key',
1422
+ 'privateKey' => 'oauth_app_partner_user_private_key'
1423
+ ]);
1424
+
1425
+ $customer = $partnerMerchantGateway->customer()->create([
1426
+ 'firstName' => 'Joe',
1427
+ 'lastName' => 'Brown'
1428
+ ])->customer;
1429
+ $creditCard = $partnerMerchantGateway->creditCard()->create([
1430
+ 'customerId' => $customer->id,
1431
+ 'cardholderName' => 'Adam Davis',
1432
+ 'number' => '4111111111111111',
1433
+ 'expirationDate' => '05/2009'
1434
+ ])->creditCard;
1435
+
1436
+ $oauthAppGateway = new Braintree\Gateway([
1437
+ 'clientId' => 'client_id$development$integration_client_id',
1438
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1439
+ ]);
1440
+
1441
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1442
+ 'merchant_public_id' => 'integration_merchant_id',
1443
+ 'scope' => 'grant_payment_method'
1444
+ ]);
1445
+
1446
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1447
+ 'code' => $code,
1448
+ ]);
1449
+
1450
+ $grantingGateway = new Braintree\Gateway([
1451
+ 'accessToken' => $credentials->accessToken
1452
+ ]);
1453
+
1454
+ $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token);
1455
+ $this->assertTrue($grantResult->success);
1456
+
1457
+ $result = Braintree\Transaction::sale([
1458
+ 'amount' => '100.00',
1459
+ 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
1460
+ ]);
1461
+ $this->assertTrue($result->success);
1462
+
1463
+ $secondResult = Braintree\Transaction::sale([
1464
+ 'amount' => '100.00',
1465
+ 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
1466
+ ]);
1467
+ $this->assertFalse($secondResult->success);
1468
+ }
1469
+
1470
+ public function testGrant_returnsANonceThatIsNotVaultable()
1471
+ {
1472
+ $partnerMerchantGateway = new Braintree\Gateway([
1473
+ 'environment' => 'development',
1474
+ 'merchantId' => 'integration_merchant_public_id',
1475
+ 'publicKey' => 'oauth_app_partner_user_public_key',
1476
+ 'privateKey' => 'oauth_app_partner_user_private_key'
1477
+ ]);
1478
+
1479
+ $customer = $partnerMerchantGateway->customer()->create([
1480
+ 'firstName' => 'Joe',
1481
+ 'lastName' => 'Brown'
1482
+ ])->customer;
1483
+ $creditCard = $partnerMerchantGateway->creditCard()->create([
1484
+ 'customerId' => $customer->id,
1485
+ 'cardholderName' => 'Adam Davis',
1486
+ 'number' => '4111111111111111',
1487
+ 'expirationDate' => '05/2009'
1488
+ ])->creditCard;
1489
+
1490
+ $oauthAppGateway = new Braintree\Gateway([
1491
+ 'clientId' => 'client_id$development$integration_client_id',
1492
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1493
+ ]);
1494
+
1495
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1496
+ 'merchant_public_id' => 'integration_merchant_id',
1497
+ 'scope' => 'grant_payment_method'
1498
+ ]);
1499
+
1500
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1501
+ 'code' => $code,
1502
+ ]);
1503
+
1504
+ $grantingGateway = new Braintree\Gateway([
1505
+ 'accessToken' => $credentials->accessToken
1506
+ ]);
1507
+
1508
+ $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, ['allow_vaulting' => false]);
1509
+
1510
+ $customer = $partnerMerchantGateway->customer()->create([
1511
+ 'firstName' => 'Bob',
1512
+ 'lastName' => 'Rob'
1513
+ ])->customer;
1514
+ $result = Braintree\PaymentMethod::create([
1515
+ 'customerId' => $customer->id,
1516
+ 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
1517
+ ]);
1518
+ $this->assertFalse($result->success);
1519
+ }
1520
+
1521
+ public function testGrant_returnsANonceThatIsVaultable()
1522
+ {
1523
+ $partnerMerchantGateway = new Braintree\Gateway([
1524
+ 'environment' => 'development',
1525
+ 'merchantId' => 'integration_merchant_public_id',
1526
+ 'publicKey' => 'oauth_app_partner_user_public_key',
1527
+ 'privateKey' => 'oauth_app_partner_user_private_key'
1528
+ ]);
1529
+
1530
+ $customer = $partnerMerchantGateway->customer()->create([
1531
+ 'firstName' => 'Joe',
1532
+ 'lastName' => 'Brown'
1533
+ ])->customer;
1534
+ $creditCard = $partnerMerchantGateway->creditCard()->create([
1535
+ 'customerId' => $customer->id,
1536
+ 'cardholderName' => 'Adam Davis',
1537
+ 'number' => '4111111111111111',
1538
+ 'expirationDate' => '05/2009'
1539
+ ])->creditCard;
1540
+
1541
+ $oauthAppGateway = new Braintree\Gateway([
1542
+ 'clientId' => 'client_id$development$integration_client_id',
1543
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1544
+ ]);
1545
+
1546
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1547
+ 'merchant_public_id' => 'integration_merchant_id',
1548
+ 'scope' => 'grant_payment_method'
1549
+ ]);
1550
+
1551
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1552
+ 'code' => $code,
1553
+ ]);
1554
+
1555
+ $grantingGateway = new Braintree\Gateway([
1556
+ 'accessToken' => $credentials->accessToken
1557
+ ]);
1558
+
1559
+ $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, ['allow_vaulting' => true]);
1560
+
1561
+ $customer = Braintree\Customer::create([
1562
+ 'firstName' => 'Bob',
1563
+ 'lastName' => 'Rob'
1564
+ ])->customer;
1565
+ $result = Braintree\PaymentMethod::create([
1566
+ 'customerId' => $customer->id,
1567
+ 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
1568
+ ]);
1569
+ $this->assertTrue($result->success);
1570
+ }
1571
+
1572
+ public function testGrant_raisesAnErrorIfTokenIsNotFound()
1573
+ {
1574
+ $oauthAppGateway = new Braintree\Gateway([
1575
+ 'clientId' => 'client_id$development$integration_client_id',
1576
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1577
+ ]);
1578
+
1579
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1580
+ 'merchant_public_id' => 'integration_merchant_id',
1581
+ 'scope' => 'grant_payment_method'
1582
+ ]);
1583
+
1584
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1585
+ 'code' => $code,
1586
+ ]);
1587
+
1588
+ $grantingGateway = new Braintree\Gateway([
1589
+ 'accessToken' => $credentials->accessToken
1590
+ ]);
1591
+
1592
+ $this->setExpectedException('Braintree\Exception\NotFound');
1593
+ $grantResult = $grantingGateway->paymentMethod()->grant("not_a_real_token", false);
1594
+ }
1595
+
1596
+ public function testRevoke_rendersANonceUnusable()
1597
+ {
1598
+ $partnerMerchantGateway = new Braintree\Gateway([
1599
+ 'environment' => 'development',
1600
+ 'merchantId' => 'integration_merchant_public_id',
1601
+ 'publicKey' => 'oauth_app_partner_user_public_key',
1602
+ 'privateKey' => 'oauth_app_partner_user_private_key'
1603
+ ]);
1604
+
1605
+ $customer = $partnerMerchantGateway->customer()->create([
1606
+ 'firstName' => 'Joe',
1607
+ 'lastName' => 'Brown'
1608
+ ])->customer;
1609
+ $creditCard = $partnerMerchantGateway->creditCard()->create([
1610
+ 'customerId' => $customer->id,
1611
+ 'cardholderName' => 'Adam Davis',
1612
+ 'number' => '4111111111111111',
1613
+ 'expirationDate' => '05/2009'
1614
+ ])->creditCard;
1615
+
1616
+ $oauthAppGateway = new Braintree\Gateway([
1617
+ 'clientId' => 'client_id$development$integration_client_id',
1618
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1619
+ ]);
1620
+
1621
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1622
+ 'merchant_public_id' => 'integration_merchant_id',
1623
+ 'scope' => 'grant_payment_method'
1624
+ ]);
1625
+
1626
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1627
+ 'code' => $code,
1628
+ ]);
1629
+
1630
+ $grantingGateway = new Braintree\Gateway([
1631
+ 'accessToken' => $credentials->accessToken
1632
+ ]);
1633
+
1634
+ $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, false);
1635
+ $revokeResult = $grantingGateway->paymentMethod()->revoke($creditCard->token);
1636
+ $this->assertTrue($revokeResult->success);
1637
+
1638
+ $result = Braintree\Transaction::sale([
1639
+ 'amount' => '100.00',
1640
+ 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
1641
+ ]);
1642
+ $this->assertFalse($result->success);
1643
+ }
1644
+
1645
+ public function testRevoke_raisesAnErrorIfTokenIsNotFound()
1646
+ {
1647
+ $oauthAppGateway = new Braintree\Gateway([
1648
+ 'clientId' => 'client_id$development$integration_client_id',
1649
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1650
+ ]);
1651
+
1652
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1653
+ 'merchant_public_id' => 'integration_merchant_id',
1654
+ 'scope' => 'grant_payment_method'
1655
+ ]);
1656
+
1657
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1658
+ 'code' => $code,
1659
+ ]);
1660
+
1661
+ $grantingGateway = new Braintree\Gateway([
1662
+ 'accessToken' => $credentials->accessToken
1663
+ ]);
1664
+
1665
+ $this->setExpectedException('Braintree\Exception\NotFound');
1666
+ $grantResult = $grantingGateway->paymentMethod()->revoke("not_a_real_token");
1667
+ }
1668
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/PlanTest.php ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Test\Helper;
8
+ use Braintree;
9
+
10
+ class PlanTest extends Setup
11
+ {
12
+ public function testAll_withNoPlans_returnsEmptyArray()
13
+ {
14
+ Helper::testMerchantConfig();
15
+ $plans = Braintree\Plan::all();
16
+ $this->assertEquals($plans, []);
17
+ self::integrationMerchantConfig();
18
+
19
+ }
20
+
21
+ public function testAll_returnsAllPlans()
22
+ {
23
+ $newId = strval(rand());
24
+ $params = [
25
+ "id" => $newId,
26
+ "billingDayOfMonth" => "1",
27
+ "billingFrequency" => "1",
28
+ "currencyIsoCode" => "USD",
29
+ "description" => "some description",
30
+ "name" => "php test plan",
31
+ "numberOfBillingCycles" => "1",
32
+ "price" => "1.00",
33
+ "trialPeriod" => "false"
34
+ ];
35
+
36
+ $http = new Braintree\Http(Braintree\Configuration::$global);
37
+ $path = Braintree\Configuration::$global->merchantPath() . '/plans/create_plan_for_tests';
38
+ $http->post($path, ["plan" => $params]);
39
+
40
+ $addOnParams = [
41
+ "kind" => "add_on",
42
+ "plan_id" => $newId,
43
+ "amount" => "1.00",
44
+ "name" => "add_on_name"
45
+ ];
46
+
47
+ $http = new Braintree\Http(Braintree\Configuration::$global);
48
+ $path = Braintree\Configuration::$global->merchantPath() . '/modifications/create_modification_for_tests';
49
+ $http->post($path, ['modification' => $addOnParams]);
50
+
51
+ $discountParams = [
52
+ "kind" => "discount",
53
+ "plan_id" => $newId,
54
+ "amount" => "1.00",
55
+ "name" => "discount_name"
56
+ ];
57
+
58
+ $http = new Braintree\Http(Braintree\Configuration::$global);
59
+ $path = Braintree\Configuration::$global->merchantPath() . '/modifications/create_modification_for_tests';
60
+ $http->post($path, ["modification" => $discountParams]);
61
+
62
+ $plans = Braintree\Plan::all();
63
+
64
+ foreach ($plans as $plan)
65
+ {
66
+ if ($plan->id == $newId)
67
+ {
68
+ $actualPlan = $plan;
69
+ }
70
+ }
71
+
72
+ $this->assertNotNull($actualPlan);
73
+ $this->assertEquals($params["billingDayOfMonth"], $actualPlan->billingDayOfMonth);
74
+ $this->assertEquals($params["billingFrequency"], $actualPlan->billingFrequency);
75
+ $this->assertEquals($params["currencyIsoCode"], $actualPlan->currencyIsoCode);
76
+ $this->assertEquals($params["description"], $actualPlan->description);
77
+ $this->assertEquals($params["name"], $actualPlan->name);
78
+ $this->assertEquals($params["numberOfBillingCycles"], $actualPlan->numberOfBillingCycles);
79
+ $this->assertEquals($params["price"], $actualPlan->price);
80
+
81
+ $addOn = $actualPlan->addOns[0];
82
+ $this->assertEquals($addOnParams["name"], $addOn->name);
83
+
84
+ $discount = $actualPlan->discounts[0];
85
+ $this->assertEquals($discountParams["name"], $discount->name);
86
+ }
87
+
88
+ public function testGatewayAll_returnsAllPlans()
89
+ {
90
+ $newId = strval(rand());
91
+ $params = [
92
+ "id" => $newId,
93
+ "billingDayOfMonth" => "1",
94
+ "billingFrequency" => "1",
95
+ "currencyIsoCode" => "USD",
96
+ "description" => "some description",
97
+ "name" => "php test plan",
98
+ "numberOfBillingCycles" => "1",
99
+ "price" => "1.00",
100
+ "trialPeriod" => "false"
101
+ ];
102
+
103
+ $http = new Braintree\Http(Braintree\Configuration::$global);
104
+ $path = Braintree\Configuration::$global->merchantPath() . '/plans/create_plan_for_tests';
105
+ $http->post($path, ["plan" => $params]);
106
+
107
+ $gateway = new Braintree\Gateway([
108
+ 'environment' => 'development',
109
+ 'merchantId' => 'integration_merchant_id',
110
+ 'publicKey' => 'integration_public_key',
111
+ 'privateKey' => 'integration_private_key'
112
+ ]);
113
+ $plans = $gateway->plan()->all();
114
+
115
+ foreach ($plans as $plan)
116
+ {
117
+ if ($plan->id == $newId)
118
+ {
119
+ $actualPlan = $plan;
120
+ }
121
+ }
122
+
123
+ $this->assertNotNull($actualPlan);
124
+ $this->assertEquals($params["billingDayOfMonth"], $actualPlan->billingDayOfMonth);
125
+ $this->assertEquals($params["billingFrequency"], $actualPlan->billingFrequency);
126
+ $this->assertEquals($params["currencyIsoCode"], $actualPlan->currencyIsoCode);
127
+ $this->assertEquals($params["description"], $actualPlan->description);
128
+ $this->assertEquals($params["name"], $actualPlan->name);
129
+ $this->assertEquals($params["numberOfBillingCycles"], $actualPlan->numberOfBillingCycles);
130
+ $this->assertEquals($params["price"], $actualPlan->price);
131
+ }
132
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/Result/ErrorTest.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration\Result;
3
+
4
+ require_once dirname(dirname(__DIR__)) . '/Setup.php';
5
+
6
+ use Test\Setup;
7
+ use Braintree;
8
+
9
+ class ErrorTest extends Setup
10
+ {
11
+ public function testValueForHtmlField()
12
+ {
13
+ $result = Braintree\Customer::create([
14
+ 'email' => 'invalid-email',
15
+ 'creditCard' => [
16
+ 'number' => 'invalid-number',
17
+ 'expirationDate' => 'invalid-exp',
18
+ 'billingAddress' => [
19
+ 'countryName' => 'invalid-country'
20
+ ]
21
+ ],
22
+ 'customFields' => [
23
+ 'store_me' => 'some custom value'
24
+ ]
25
+ ]);
26
+ $this->assertEquals(false, $result->success);
27
+ $this->assertEquals('invalid-email', $result->valueForHtmlField('customer[email]'));
28
+ $this->assertEquals('', $result->valueForHtmlField('customer[credit_card][number]'));
29
+ $this->assertEquals('invalid-exp', $result->valueForHtmlField('customer[credit_card][expiration_date]'));
30
+ $this->assertEquals('invalid-country', $result->valueForHtmlField('customer[credit_card][billing_address][country_name]'));
31
+ $this->assertEquals('some custom value', $result->valueForHtmlField('customer[custom_fields][store_me]'));
32
+ }
33
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/SettlementBatchSummaryTest.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use DateTime;
7
+ use Test;
8
+ use Test\Setup;
9
+ use Braintree;
10
+
11
+ class SettlementBatchSummaryTest extends Setup
12
+ {
13
+ public function isMasterCard($record)
14
+ {
15
+ return $record['cardType'] == Braintree\CreditCard::MASTER_CARD;
16
+ }
17
+
18
+ public function testGenerate_returnsAnEmptyCollectionWhenThereIsNoData()
19
+ {
20
+ $result = Braintree\SettlementBatchSummary::generate('2000-01-01');
21
+
22
+ $this->assertTrue($result->success);
23
+ $this->assertEquals(0, count($result->settlementBatchSummary->records));
24
+ }
25
+
26
+ public function testGatewayGenerate_returnsAnEmptyCollectionWhenThereIsNoData()
27
+ {
28
+ $gateway = new Braintree\Gateway([
29
+ 'environment' => 'development',
30
+ 'merchantId' => 'integration_merchant_id',
31
+ 'publicKey' => 'integration_public_key',
32
+ 'privateKey' => 'integration_private_key'
33
+ ]);
34
+ $result = $gateway->settlementBatchSummary()->generate('2000-01-01');
35
+
36
+ $this->assertTrue($result->success);
37
+ $this->assertEquals(0, count($result->settlementBatchSummary->records));
38
+ }
39
+
40
+ public function testGenerate_returnsAnErrorIfTheDateCanNotBeParsed()
41
+ {
42
+ $result = Braintree\SettlementBatchSummary::generate('OMG NOT A DATE');
43
+
44
+ $this->assertFalse($result->success);
45
+ $errors = $result->errors->forKey('settlementBatchSummary')->onAttribute('settlementDate');
46
+ $this->assertEquals(Braintree\Error\Codes::SETTLEMENT_BATCH_SUMMARY_SETTLEMENT_DATE_IS_INVALID, $errors[0]->code);
47
+ }
48
+
49
+ public function testGenerate_returnsTransactionsSettledOnAGivenDay()
50
+ {
51
+ $transaction = Braintree\Transaction::saleNoValidate([
52
+ 'amount' => '100.00',
53
+ 'creditCard' => [
54
+ 'number' => '5105105105105100',
55
+ 'expirationDate' => '05/12'
56
+ ],
57
+ 'options' => ['submitForSettlement' => true]
58
+ ]);
59
+ Braintree\Test\Transaction::settle($transaction->id);
60
+
61
+ $today = new Datetime;
62
+ $result = Braintree\SettlementBatchSummary::generate(Test\Helper::nowInEastern());
63
+
64
+ $this->assertTrue($result->success);
65
+ $masterCardRecords = array_filter($result->settlementBatchSummary->records, 'self::isMasterCard');
66
+ $masterCardKeys = array_keys($masterCardRecords);
67
+ $masterCardIndex = $masterCardKeys[0];
68
+ $this->assertTrue(count($masterCardRecords) > 0);
69
+ $this->assertEquals(Braintree\CreditCard::MASTER_CARD, $masterCardRecords[$masterCardIndex]['cardType']);
70
+ }
71
+
72
+ public function testGenerate_canBeGroupedByACustomField()
73
+ {
74
+ $transaction = Braintree\Transaction::saleNoValidate([
75
+ 'amount' => '100.00',
76
+ 'creditCard' => [
77
+ 'number' => '5105105105105100',
78
+ 'expirationDate' => '05/12'
79
+ ],
80
+ 'customFields' => [
81
+ 'store_me' => 'custom value'
82
+ ],
83
+ 'options' => ['submitForSettlement' => true]
84
+ ]);
85
+
86
+ Braintree\Test\Transaction::settle($transaction->id);
87
+
88
+ $today = new Datetime;
89
+ $result = Braintree\SettlementBatchSummary::generate(Test\Helper::nowInEastern(), 'store_me');
90
+
91
+ $this->assertTrue($result->success);
92
+ $this->assertTrue(count($result->settlementBatchSummary->records) > 0);
93
+ $this->assertArrayHasKey('store_me', $result->settlementBatchSummary->records[0]);
94
+ }
95
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/SubscriptionHelper.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ use Braintree;
5
+
6
+ class SubscriptionHelper
7
+ {
8
+ public static function addOnDiscountPlan()
9
+ {
10
+ return [
11
+ 'description' => "Plan for integration tests -- with add-ons and discounts",
12
+ 'id' => "integration_plan_with_add_ons_and_discounts",
13
+ 'price' => '9.99',
14
+ 'trial_period' => true,
15
+ 'trial_duration' => 2,
16
+ 'trial_duration_unit' => 'day'
17
+ ];
18
+ }
19
+
20
+ public static function billingDayOfMonthPlan()
21
+ {
22
+ return [
23
+ 'description' => 'Plan for integration tests -- with billing day of month',
24
+ 'id' => 'integration_plan_with_billing_day_of_month',
25
+ 'numberOfBillingCycles' => 5,
26
+ 'price' => '8.88',
27
+ 'trial_period' => false
28
+ ];
29
+ }
30
+
31
+ public static function trialPlan()
32
+ {
33
+ return [
34
+ 'description' => 'Plan for integration tests -- with trial',
35
+ 'id' => 'integration_trial_plan',
36
+ 'numberOfBillingCycles' => 12,
37
+ 'price' => '43.21',
38
+ 'trial_period' => true,
39
+ 'trial_duration' => 2,
40
+ 'trial_duration_unit' => 'day'
41
+ ];
42
+ }
43
+
44
+ public static function triallessPlan()
45
+ {
46
+ return [
47
+ 'description' => 'Plan for integration tests -- without a trial',
48
+ 'id' => 'integration_trialless_plan',
49
+ 'numberOfBillingCycles' => 12,
50
+ 'price' => '12.34',
51
+ 'trial_period' => false
52
+ ];
53
+ }
54
+
55
+ public static function createCreditCard()
56
+ {
57
+ $customer = Braintree\Customer::createNoValidate([
58
+ 'creditCard' => [
59
+ 'number' => '5105105105105100',
60
+ 'expirationDate' => '05/2010'
61
+ ]
62
+ ]);
63
+ return $customer->creditCards[0];
64
+ }
65
+
66
+ public static function createSubscription()
67
+ {
68
+ $plan = self::triallessPlan();
69
+ $result = Braintree\Subscription::create([
70
+ 'paymentMethodToken' => self::createCreditCard()->token,
71
+ 'price' => '54.99',
72
+ 'planId' => $plan['id']
73
+ ]);
74
+ return $result->subscription;
75
+ }
76
+
77
+ public static function compareModificationsById($left, $right)
78
+ {
79
+ return strcmp($left->id, $right->id);
80
+ }
81
+
82
+ public static function sortModificationsById(&$modifications)
83
+ {
84
+ usort($modifications, ['Test\Integration\SubscriptionHelper', 'compareModificationsById']);
85
+ }
86
+ }
wpsc-components/merchant-core-v3/libraries/pp-braintree/sdk/tests/integration/SubscriptionSearchTest.php ADDED
@@ -0,0 +1,479 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Test\Integration;
3
+
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use DateTime;
7
+ use DateTimeZone;
8
+ use Test;
9
+ use Test\Setup;
10
+ use Braintree;
11
+
12
+ class SubscriptionSearchTest extends Setup
13
+ {
14
+ public function testSearch_planIdIs()
15
+ {
16
+ $creditCard = SubscriptionHelper::createCreditCard();
17
+ $triallessPlan = SubscriptionHelper::triallessPlan();
18
+ $trialPlan = SubscriptionHelper::trialPlan();
19
+
20
+ $trialSubscription = Braintree\Subscription::create([
21
+ 'paymentMethodToken' => $creditCard->token,
22
+ 'planId' => $trialPlan['id'],
23
+ 'price' => '1'
24
+ ])->subscription;
25
+
26
+ $triallessSubscription = Braintree\Subscription::create([
27
+ 'paymentMethodToken' => $creditCard->token,
28
+ 'planId' => $triallessPlan['id'],
29
+ 'price' => '1'
30
+ ])->subscription;
31
+
32
+ $collection = Braintree\Subscription::search([
33
+ Braintree\SubscriptionSearch::planId()->is('integration_trial_plan'),
34
+ Braintree\SubscriptionSearch::price()->is('1')
35
+ ]);
36
+
37
+ $this->assertTrue(Test\Helper::includes($collection, $trialSubscription));
38
+ $this->assertFalse(Test\Helper::includes($collection, $triallessSubscription));
39
+ }
40
+
41
+ public function test_noRequestsWhenIterating()
42
+ {
43
+ $resultsReturned = false;
44
+ $collection = Braintree\Subscription::search([
45
+ Braintree\SubscriptionSearch::planId()->is('imaginary')
46
+ ]);
47
+
48
+ foreach ($collection as $transaction) {
49
+ $resultsReturned = true;
50
+ break;
51
+ }
52
+
53
+ $this->assertSame(0, $collection->maximumCount());
54
+ $this->assertEquals(false, $resultsReturned);
55
+ }
56
+
57
+ public function testSearch_inTrialPeriod()
58
+ {
59
+ $creditCard = SubscriptionHelper::createCreditCard();
60
+ $triallessPlan = SubscriptionHelper::triallessPlan();
61
+ $trialPlan = SubscriptionHelper::trialPlan();
62
+
63
+ $trialSubscription = Braintree\Subscription::create([
64
+ 'paymentMethodToken' => $creditCard->token,
65
+ 'planId' => $trialPlan['id'],
66
+ 'price' => '1'
67
+ ])->subscription;
68
+
69
+ $triallessSubscription = Braintree\Subscription::create([
70
+ 'paymentMethodToken' => $creditCard->token,
71
+ 'planId' => $triallessPlan['id'],
72
+ 'price' => '1'
73
+ ])->subscription;
74
+
75
+ $subscriptions_in_trial = Braintree\Subscription::search([
76
+ Braintree\SubscriptionSearch::inTrialPeriod()->is(true)
77
+ ]);
78
+
79
+ $this->assertTrue(Test\Helper::includes($subscriptions_in_trial, $trialSubscription));
80
+ $this->assertFalse(Test\Helper::includes($subscriptions_in_trial, $triallessSubscription));
81
+
82
+ $subscriptions_not_in_trial = Braintree\Subscription::search([
83
+ Braintree\SubscriptionSearch::inTrialPeriod()->is(false)
84
+ ]);
85
+
86
+ $this->assertTrue(Test\Helper::includes($subscriptions_not_in_trial, $triallessSubscription));
87
+ $this->assertFalse(Test\Helper::includes($subscriptions_not_in_trial, $trialSubscription));
88
+ }
89
+
90
+ public function testSearch_statusIsPastDue()
91
+ {
92
+ $found = false;
93
+ $collection = Braintree\Subscription::search([
94
+ Braintree\SubscriptionSearch::status()->in([Braintree\Subscription::PAST_DUE])
95
+ ]);
96
+ foreach ($collection AS $item) {
97
+ $found = true;
98
+ $this->assertEquals(Braintree\Subscription::PAST_DUE, $item->status);
99
+ }
100
+ $this->assertTrue($found);
101
+ }
102
+
103
+ public function testSearch_statusIsExpired()
104
+ {
105
+ $found = false;
106
+ $collection = Braintree\Subscription::search([
107
+ Braintree\SubscriptionSearch::status()->in([Braintree\Subscription::EXPIRED])
108
+ ]);
109
+ foreach ($collection as $item) {
110
+ $found = true;
111
+ $this->assertEquals(Braintree\Subscription::EXPIRED, $item->status);
112
+ }
113
+ $this->assertTrue($found);
114
+ }
115
+
116
+ public function testSearch_billingCyclesRemaing()
117
+ {
118
+ $creditCard = SubscriptionHelper::createCreditCard();
119
+ $triallessPlan = SubscriptionHelper::triallessPlan();
120
+
121
+ $subscription_4 = Braintree\Subscription::create([
122
+ 'paymentMethodToken' => $creditCard->token,
123
+ 'planId' => $triallessPlan['id'],
124
+ 'numberOfBillingCycles' => 4
125
+ ])->subscription;
126
+
127
+ $subscription_8 = Braintree\Subscription::create([
128
+ 'paymentMethodToken' => $creditCard->token,
129
+ 'planId' => $triallessPlan['id'],
130
+ 'numberOfBillingCycles' => 8
131
+ ])->subscription;
132
+
133
+ $subscription_10 = Braintree\Subscription::create([
134
+ 'paymentMethodToken' => $creditCard->token,
135
+ 'planId' => $triallessPlan['id'],
136
+ 'numberOfBillingCycles' => 10
137
+ ])->subscription;
138
+
139
+ $collection = Braintree\Subscription::search([
140
+ Braintree\SubscriptionSearch::billingCyclesRemaining()->between(5, 10)
141
+ ]);
142
+
143
+ $this->assertFalse(Test\Helper::includes($collection, $subscription_4));
144
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_8));
145
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_10));
146
+ }
147
+
148
+ public function testSearch_subscriptionId()
149
+ {
150
+ $creditCard = SubscriptionHelper::createCreditCard();
151
+ $triallessPlan = SubscriptionHelper::triallessPlan();
152
+
153
+ $rand_id = strval(rand());
154
+
155
+ $subscription_1 = Braintree\Subscription::create([
156
+ 'paymentMethodToken' => $creditCard->token,
157
+ 'planId' => $triallessPlan['id'],
158
+ 'id' => 'subscription_123_id_' . $rand_id
159
+ ])->subscription;
160
+
161
+ $subscription_2 = Braintree\Subscription::create([
162
+ 'paymentMethodToken' => $creditCard->token,
163
+ 'planId' => $triallessPlan['id'],
164
+ 'id' => 'subscription_23_id_' . $rand_id
165
+ ])->subscription;
166
+
167
+ $subscription_3 = Braintree\Subscription::create([
168
+ 'paymentMethodToken' => $creditCard->token,
169
+ 'planId' => $triallessPlan['id'],
170
+ 'id' => 'subscription_3_id_' . $rand_id
171
+ ])->subscription;
172
+
173
+ $collection = Braintree\Subscription::search([
174
+ Braintree\SubscriptionSearch::id()->contains('23_id_')
175
+ ]);
176
+
177
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_1));
178
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_2));
179
+ $this->assertFalse(Test\Helper::includes($collection, $subscription_3));
180
+ }
181
+
182
+ public function testSearch_merchantAccountId()
183
+ {
184
+ $creditCard = SubscriptionHelper::createCreditCard();
185
+ $triallessPlan = SubscriptionHelper::triallessPlan();
186
+
187
+ $rand_id = strval(rand());
188
+
189
+ $subscription_1 = Braintree\Subscription::create([
190
+ 'paymentMethodToken' => $creditCard->token,
191
+ 'planId' => $triallessPlan['id'],
192
+ 'id' => strval(rand()) . '_subscription_' . $rand_id,
193
+ 'price' => '2'
194
+ ])->subscription;
195
+
196
+ $subscription_2 = Braintree\Subscription::create([
197
+ 'paymentMethodToken' => $creditCard->token,
198
+ 'planId' => $triallessPlan['id'],
199
+ 'id' => strval(rand()) . '_subscription_' . $rand_id,
200
+ 'merchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(),
201
+ 'price' => '2'
202
+ ])->subscription;
203
+
204
+ $collection = Braintree\Subscription::search([
205
+ Braintree\SubscriptionSearch::id()->endsWith('subscription_' . $rand_id),
206
+ Braintree\SubscriptionSearch::merchantAccountId()->in([Test\Helper::nonDefaultMerchantAccountId()]),
207
+ Braintree\SubscriptionSearch::price()->is('2')
208
+ ]);
209
+
210
+ $this->assertFalse(Test\Helper::includes($collection, $subscription_1));
211
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_2));
212
+ }
213
+
214
+ public function testSearch_bogusMerchantAccountId()
215
+ {
216
+ $creditCard = SubscriptionHelper::createCreditCard();
217
+ $triallessPlan = SubscriptionHelper::triallessPlan();
218
+
219
+ $rand_id = strval(rand());
220
+
221
+ $subscription = Braintree\Subscription::create([
222
+ 'paymentMethodToken' => $creditCard->token,
223
+ 'planId' => $triallessPlan['id'],
224
+ 'id' => strval(rand()) . '_subscription_' . $rand_id,
225
+ 'price' => '11.38'
226
+ ])->subscription;
227
+
228
+ $collection = Braintree\Subscription::search([
229
+ Braintree\SubscriptionSearch::id()->endsWith('subscription_' . $rand_id),
230
+ Braintree\SubscriptionSearch::merchantAccountId()->in(['bogus_merchant_account']),
231
+ Braintree\SubscriptionSearch::price()->is('11.38')
232
+ ]);
233
+
234
+ $this->assertFalse(Test\Helper::includes($collection, $subscription));
235
+ }
236
+
237
+ public function testSearch_daysPastDue()
238
+ {
239
+ $creditCard = SubscriptionHelper::createCreditCard();
240
+ $triallessPlan = SubscriptionHelper::triallessPlan();
241
+
242
+ $subscription = Braintree\Subscription::create([
243
+ 'paymentMethodToken' => $creditCard->token,
244
+ 'planId' => $triallessPlan['id']
245
+ ])->subscription;
246
+
247
+ $http = new Braintree\Http(Braintree\Configuration::$global);
248
+ $path = Braintree\Configuration::$global->merchantPath() . '/subscriptions/' . $subscription->id . '/make_past_due';
249
+ $http->put($path, ['daysPastDue' => 5]);
250
+
251
+ $found = false;
252
+ $collection = Braintree\Subscription::search([
253
+ Braintree\SubscriptionSearch::daysPastDue()->between(2, 10)
254
+ ]);
255
+ foreach ($collection AS $item) {
256
+ $found = true;
257
+ $this->assertTrue($item->daysPastDue <= 10);
258
+ $this->assertTrue($item->daysPastDue >= 2);
259
+ }
260
+ $this->assertTrue($found);
261
+ }
262
+
263
+ public function testSearch_price()
264
+ {
265
+ $creditCard = SubscriptionHelper::createCreditCard();
266
+ $triallessPlan = SubscriptionHelper::triallessPlan();
267
+
268
+ $subscription_850 = Braintree\Subscription::create([
269
+ 'paymentMethodToken' => $creditCard->token,
270
+ 'planId' => $triallessPlan['id'],
271
+ 'price' => '8.50'
272
+ ])->subscription;
273
+
274
+ $subscription_851 = Braintree\Subscription::create([
275
+ 'paymentMethodToken' => $creditCard->token,
276
+ 'planId' => $triallessPlan['id'],
277
+ 'price' => '8.51'
278
+ ])->subscription;
279
+
280
+ $subscription_852 = Braintree\Subscription::create([
281
+ 'paymentMethodToken' => $creditCard->token,
282
+ 'planId' => $triallessPlan['id'],
283
+ 'price' => '8.52'
284
+ ])->subscription;
285
+
286
+ $collection = Braintree\Subscription::search([
287
+ Braintree\SubscriptionSearch::price()->between('8.51', '8.52')
288
+ ]);
289
+
290
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_851));
291
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_852));
292
+ $this->assertFalse(Test\Helper::includes($collection, $subscription_850));
293
+ }
294
+
295
+ public function testSearch_nextBillingDate()
296
+ {
297
+ $creditCard = SubscriptionHelper::createCreditCard();
298
+ $triallessPlan = SubscriptionHelper::triallessPlan();
299
+ $trialPlan = SubscriptionHelper::trialPlan();
300
+
301
+ $triallessSubscription = Braintree\Subscription::create([
302
+ 'paymentMethodToken' => $creditCard->token,
303
+ 'planId' => $triallessPlan['id'],
304
+ ])->subscription;
305
+
306
+ $trialSubscription = Braintree\Subscription::create([
307
+ 'paymentMethodToken' => $creditCard->token,
308
+ 'planId' => $trialPlan['id'],
309
+ ])->subscription;
310
+
311
+ $fiveDaysFromNow = new DateTime();
312
+ $fiveDaysFromNow->modify("+5 days");
313
+
314
+ $collection = Braintree\Subscription::search([
315
+ Braintree\SubscriptionSearch::nextBillingDate()->greaterThanOrEqualTo($fiveDaysFromNow),
316
+ ]);
317
+
318
+ $this->assertTrue(Test\Helper::includes($collection, $triallessSubscription));
319
+ $this->assertFalse(Test\Helper::includes($collection, $trialSubscription));
320
+ }
321
+
322
+ public function testSearch_createdAt_lessThanOrEqualTo()
323
+ {
324
+ $creditCard = SubscriptionHelper::createCreditCard();
325
+ $plan = SubscriptionHelper::trialPlan();
326
+
327
+ $subscription= Braintree\Subscription::create([
328
+ 'paymentMethodToken' => $creditCard->token,
329
+ 'planId' => $plan['id'],
330
+ ])->subscription;
331
+
332
+ $fiveDaysFromNow = new DateTime();
333
+ $fiveDaysFromNow->modify("+5 days");
334
+
335
+ $collection = Braintree\Subscription::search([
336
+ Braintree\SubscriptionSearch::createdAt()->lessThanOrEqualTo($fiveDaysFromNow),
337
+ ]);
338
+
339
+ $this->assertTrue(Test\Helper::includes($collection, $subscription));
340
+
341
+ $fiveDaysAgo = new DateTime();
342
+ $fiveDaysAgo->modify("-5 days");
343
+
344
+ $emptyCollection = Braintree\Subscription::search([
345
+ Braintree\SubscriptionSearch::createdAt()->lessThanOrEqualTo($fiveDaysAgo),
346
+ ]);
347
+
348
+ $this->assertFalse(Test\Helper::includes($emptyCollection, $subscription));
349
+ }
350
+
351
+ public function testSearch_createdAt_greaterThanOrEqualTo()
352
+ {
353
+ $creditCard = SubscriptionHelper::createCreditCard();
354
+ $plan = SubscriptionHelper::trialPlan();
355
+
356
+ $subscription= Braintree\Subscription::create([
357
+ 'paymentMethodToken' => $creditCard->token,
358
+ 'planId' => $plan['id'],
359
+ ])->subscription;
360
+
361
+ $fiveDaysAgo = new DateTime();
362
+ $fiveDaysAgo->modify("-5 days");
363
+
364
+ $collection = Braintree\Subscription::search([
365
+ Braintree\SubscriptionSearch::createdAt()->greaterThanOrEqualTo($fiveDaysAgo),
366
+ ]);
367
+
368
+ $this->assertTrue(Test\Helper::includes($collection, $subscription));
369
+
370
+ $fiveDaysFromNow = new DateTime();
371
+ $fiveDaysFromNow->modify("+5 days");
372
+
373
+ $emptyCollection = Braintree\Subscription::search([
374
+ Braintree\SubscriptionSearch::createdAt()->greaterThanOrEqualTo($fiveDaysFromNow),
375
+ ]);
376
+
377
+ $this->assertFalse(Test\Helper::includes($emptyCollection, $subscription));
378
+ }
379
+
380
+ public function testSearch_createdAt_between()
381
+ {
382
+ $creditCard = SubscriptionHelper::createCreditCard();
383
+ $plan = SubscriptionHelper::trialPlan();
384
+
385
+ $subscription= Braintree\Subscription::create([
386
+ 'paymentMethodToken' => $creditCard->token,
387
+ 'planId' => $plan['id'],
388
+ ])->subscription;
389
+
390
+ $fiveDaysAgo = new DateTime();
391
+ $fiveDaysFromNow = new DateTime();
392
+ $tenDaysFromNow = new DateTime();
393
+
394
+ $fiveDaysAgo->modify("-5 days");
395
+ $fiveDaysFromNow->modify("+5 days");
396
+ $tenDaysFromNow->modify("+10 days");
397
+
398
+ $collection = Braintree\Subscription::search([
399
+ Braintree\SubscriptionSearch::createdAt()->between($fiveDaysAgo, $fiveDaysFromNow),
400
+ ]);
401
+
402
+ $this->assertTrue(Test\Helper::includes($collection, $subscription));
403
+
404
+ $emptyCollection = Braintree\Subscription::search([
405
+ Braintree\SubscriptionSearch::createdAt()->between($fiveDaysFromNow, $tenDaysFromNow),
406
+ ]);
407
+
408
+ $this->assertFalse(Test\Helper::includes($emptyCollection, $subscription));
409
+ }
410
+
411
+ public function testSearch_createdAt_is()
412
+ {
413
+ $creditCard = SubscriptionHelper::createCreditCard();
414
+ $plan = SubscriptionHelper::trialPlan();
415
+
416
+ $subscription= Braintree\Subscription::create([
417
+ 'paymentMethodToken' => $creditCard->token,
418
+ 'planId' => $plan['id'],
419
+ ])->subscription;
420
+
421
+ $collection = Braintree\Subscription::search([
422
+ Braintree\SubscriptionSearch::createdAt()->is($subscription->createdAt),
423
+ ]);
424
+
425
+ $this->assertTrue(Test\Helper::includes($collection, $subscription));
426
+
427
+ $oneDayAgo = $subscription->createdAt;
428
+ $oneDayAgo->modify("-1 days");
429
+
430
+ $emptyCollection = Braintree\Subscription::search([
431
+ Braintree\SubscriptionSearch::createdAt()->is($oneDayAgo),
432
+ ]);
433
+
434
+ $this->assertFalse(Test\Helper::includes($emptyCollection, $subscription));
435
+ }
436
+
437
+ public function testSearch_createdAt_convertLocalToUTC()
438
+ {
439
+ $creditCard = SubscriptionHelper::createCreditCard();
440
+ $plan = SubscriptionHelper::trialPlan();
441
+
442
+ $subscription= Braintree\Subscription::create([
443
+ 'paymentMethodToken' => $creditCard->token,
444
+ 'planId' => $plan['id'],
445
+ ])->subscription;
446
+
447
+ $tenMinAgo = date_create("now -10 minutes", new DateTimeZone("US/Pacific"));
448
+ $tenMinFromNow = date_create("now +10 minutes", new DateTimeZone("US/Pacific"));
449
+
450
+ $collection = Braintree\Subscription::search([
451
+ Braintree\SubscriptionSearch::createdAt()->between($tenMinAgo, $tenMinFromNow),
452
+ ]);
453
+
454
+ $this->assertTrue(Test\Helper::includes($collection, $subscription));
455
+ }
456
+
457
+ public function testSearch_transactionId()
458
+ {
459
+ $creditCard = SubscriptionHelper::createCreditCard();
460
+ $triallessPlan = SubscriptionHel