WooCommerce PayPal Powered by Braintree Payment Gateway - Version 1.2.0

Version Description

  • Replace array initialization code that causes a fatal error on PHP 5.2 or earlier. PHP 5.4+ is still required, but this code prevented the compatibility check from running and displaying the version requirements
  • Update to the latest Braintree SDK (3.8.0)
  • Add authorize/capture feature, allowing delayed settlement
  • Pre-fill certain merchant and store details when connecting
  • Fix missing gateway title and transaction URL when order in-hold
Download this release

Release Info

Developer akeda
Plugin Icon 128x128 WooCommerce PayPal Powered by Braintree Payment Gateway
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.0 to 1.2.0

Files changed (175) hide show
  1. braintree_sdk/CHANGELOG.md +22 -0
  2. braintree_sdk/README.md +13 -18
  3. braintree_sdk/Rakefile +15 -1
  4. braintree_sdk/composer.json +9 -1
  5. braintree_sdk/lib/Braintree.php +4 -135
  6. braintree_sdk/lib/Braintree/AddOn.php +6 -4
  7. braintree_sdk/lib/Braintree/AddOnGateway.php +15 -13
  8. braintree_sdk/lib/Braintree/Address.php +34 -31
  9. braintree_sdk/lib/Braintree/AddressGateway.php +50 -45
  10. braintree_sdk/lib/Braintree/AmexExpressCheckoutCard.php +81 -0
  11. braintree_sdk/lib/Braintree/AndroidPayCard.php +13 -9
  12. braintree_sdk/lib/Braintree/ApplePayCard.php +13 -9
  13. braintree_sdk/lib/Braintree/Base.php +14 -7
  14. braintree_sdk/lib/Braintree/ClientToken.php +12 -10
  15. braintree_sdk/lib/Braintree/ClientTokenGateway.php +20 -16
  16. braintree_sdk/lib/Braintree/CoinbaseAccount.php +17 -13
  17. braintree_sdk/lib/Braintree/Collection.php +13 -4
  18. braintree_sdk/lib/Braintree/Configuration.php +110 -23
  19. braintree_sdk/lib/Braintree/CredentialsParser.php +17 -14
  20. braintree_sdk/lib/Braintree/CreditCard.php +54 -50
  21. braintree_sdk/lib/Braintree/CreditCardGateway.php +118 -105
  22. braintree_sdk/lib/Braintree/CreditCardVerification.php +25 -4
  23. braintree_sdk/lib/Braintree/CreditCardVerificationGateway.php +37 -12
  24. braintree_sdk/lib/Braintree/CreditCardVerificationSearch.php +28 -25
  25. braintree_sdk/lib/Braintree/Customer.php +112 -89
  26. braintree_sdk/lib/Braintree/CustomerGateway.php +112 -108
  27. braintree_sdk/lib/Braintree/CustomerSearch.php +28 -25
  28. braintree_sdk/lib/Braintree/Descriptor.php +4 -1
  29. braintree_sdk/lib/Braintree/Digest.php +5 -2
  30. braintree_sdk/lib/Braintree/Disbursement.php +12 -9
  31. braintree_sdk/lib/Braintree/DisbursementDetails.php +6 -6
  32. braintree_sdk/lib/Braintree/Discount.php +5 -2
  33. braintree_sdk/lib/Braintree/DiscountGateway.php +7 -4
  34. braintree_sdk/lib/Braintree/Dispute.php +15 -8
  35. braintree_sdk/lib/Braintree/Dispute/TransactionDetails.php +7 -2
  36. braintree_sdk/lib/Braintree/EqualityNode.php +3 -1
  37. braintree_sdk/lib/Braintree/Error/Codes.php +19 -2
  38. braintree_sdk/lib/Braintree/Error/ErrorCollection.php +12 -7
  39. braintree_sdk/lib/Braintree/Error/Validation.php +12 -7
  40. braintree_sdk/lib/Braintree/Error/ValidationErrorCollection.php +14 -9
  41. braintree_sdk/lib/Braintree/EuropeBankAccount.php +16 -12
  42. braintree_sdk/lib/Braintree/Exception.php +5 -2
  43. braintree_sdk/lib/Braintree/Exception/Authentication.php +8 -3
  44. braintree_sdk/lib/Braintree/Exception/Authorization.php +7 -2
  45. braintree_sdk/lib/Braintree/Exception/Configuration.php +7 -2
  46. braintree_sdk/lib/Braintree/Exception/DownForMaintenance.php +7 -2
  47. braintree_sdk/lib/Braintree/Exception/ForgedQueryString.php +7 -2
  48. braintree_sdk/lib/Braintree/Exception/InvalidChallenge.php +6 -2
  49. braintree_sdk/lib/Braintree/Exception/InvalidSignature.php +6 -2
  50. braintree_sdk/lib/Braintree/Exception/NotFound.php +7 -2
  51. braintree_sdk/lib/Braintree/Exception/SSLCaFileNotFound.php +7 -2
  52. braintree_sdk/lib/Braintree/Exception/SSLCertificate.php +7 -2
  53. braintree_sdk/lib/Braintree/Exception/ServerError.php +7 -2
  54. braintree_sdk/lib/Braintree/Exception/TestOperationPerformedInProduction.php +7 -2
  55. braintree_sdk/lib/Braintree/Exception/Unexpected.php +7 -2
  56. braintree_sdk/lib/Braintree/Exception/UpgradeRequired.php +7 -2
  57. braintree_sdk/lib/Braintree/Exception/ValidationsFailed.php +7 -2
  58. braintree_sdk/lib/Braintree/FacilitatorDetails.php +30 -0
  59. braintree_sdk/lib/Braintree/Gateway.php +45 -42
  60. braintree_sdk/lib/Braintree/Http.php +61 -24
  61. braintree_sdk/lib/Braintree/Instance.php +14 -11
  62. braintree_sdk/lib/Braintree/IsNode.php +8 -5
  63. braintree_sdk/lib/Braintree/KeyValueNode.php +6 -5
  64. braintree_sdk/lib/Braintree/Merchant.php +4 -2
  65. braintree_sdk/lib/Braintree/MerchantAccount.php +10 -8
  66. braintree_sdk/lib/Braintree/MerchantAccount/AddressDetails.php +7 -2
  67. braintree_sdk/lib/Braintree/MerchantAccount/BusinessDetails.php +6 -2
  68. braintree_sdk/lib/Braintree/MerchantAccount/FundingDetails.php +6 -2
  69. braintree_sdk/lib/Braintree/MerchantAccount/IndividualDetails.php +6 -2
  70. braintree_sdk/lib/Braintree/MerchantAccountGateway.php +37 -35
  71. braintree_sdk/lib/Braintree/MerchantGateway.php +12 -10
  72. braintree_sdk/lib/Braintree/Modification.php +5 -2
  73. braintree_sdk/lib/Braintree/MultipleValueNode.php +11 -7
  74. braintree_sdk/lib/Braintree/MultipleValueOrTextNode.php +11 -9
  75. braintree_sdk/lib/Braintree/OAuthCredentials.php +7 -4
  76. braintree_sdk/lib/Braintree/OAuthGateway.php +16 -13
  77. braintree_sdk/lib/Braintree/PartialMatchNode.php +5 -3
  78. braintree_sdk/lib/Braintree/PartnerMerchant.php +6 -4
  79. braintree_sdk/lib/Braintree/PayPalAccount.php +17 -13
  80. braintree_sdk/lib/Braintree/PayPalAccountGateway.php +35 -30
  81. braintree_sdk/lib/Braintree/PaymentInstrumentType.php +3 -1
  82. braintree_sdk/lib/Braintree/PaymentMethod.php +10 -7
  83. braintree_sdk/lib/Braintree/PaymentMethodGateway.php +109 -67
  84. braintree_sdk/lib/Braintree/PaymentMethodNonce.php +9 -6
  85. braintree_sdk/lib/Braintree/PaymentMethodNonceGateway.php +12 -9
  86. braintree_sdk/lib/Braintree/Plan.php +11 -8
  87. braintree_sdk/lib/Braintree/PlanGateway.php +8 -5
  88. braintree_sdk/lib/Braintree/RangeNode.php +10 -8
  89. braintree_sdk/lib/Braintree/ResourceCollection.php +15 -10
  90. braintree_sdk/lib/Braintree/Result/CreditCardVerification.php +17 -12
  91. braintree_sdk/lib/Braintree/Result/Error.php +34 -19
  92. braintree_sdk/lib/Braintree/Result/Successful.php +22 -15
  93. braintree_sdk/lib/Braintree/RiskData.php +6 -3
  94. braintree_sdk/lib/Braintree/SettlementBatchSummary.php +9 -6
  95. braintree_sdk/lib/Braintree/SettlementBatchSummaryGateway.php +26 -24
  96. braintree_sdk/lib/Braintree/SignatureService.php +3 -1
  97. braintree_sdk/lib/Braintree/Subscription.php +24 -21
  98. braintree_sdk/lib/Braintree/Subscription/StatusDetails.php +7 -3
  99. braintree_sdk/lib/Braintree/SubscriptionGateway.php +59 -54
  100. braintree_sdk/lib/Braintree/SubscriptionSearch.php +32 -29
  101. braintree_sdk/lib/Braintree/Test/CreditCardNumbers.php +26 -19
  102. braintree_sdk/lib/Braintree/Test/MerchantAccount.php +5 -2
  103. braintree_sdk/lib/Braintree/Test/Nonces.php +8 -3
  104. braintree_sdk/lib/Braintree/Test/Transaction.php +26 -13
  105. braintree_sdk/lib/Braintree/Test/TransactionAmounts.php +4 -2
  106. braintree_sdk/lib/Braintree/Test/VenmoSdk.php +5 -2
  107. braintree_sdk/lib/Braintree/TestingGateway.php +8 -5
  108. braintree_sdk/lib/Braintree/TextNode.php +4 -2
  109. braintree_sdk/lib/Braintree/ThreeDSecureInfo.php +5 -2
  110. braintree_sdk/lib/Braintree/Transaction.php +99 -69
  111. braintree_sdk/lib/Braintree/Transaction/AddressDetails.php +8 -4
  112. braintree_sdk/lib/Braintree/Transaction/AmexExpressCheckoutCardDetails.php +45 -0
  113. braintree_sdk/lib/Braintree/Transaction/AndroidPayCardDetails.php +9 -5
  114. braintree_sdk/lib/Braintree/Transaction/ApplePayCardDetails.php +9 -5
  115. braintree_sdk/lib/Braintree/Transaction/CoinbaseDetails.php +9 -5
  116. braintree_sdk/lib/Braintree/Transaction/CreditCardDetails.php +8 -4
  117. braintree_sdk/lib/Braintree/Transaction/CustomerDetails.php +7 -3
  118. braintree_sdk/lib/Braintree/Transaction/EuropeBankAccountDetails.php +7 -3
  119. braintree_sdk/lib/Braintree/Transaction/PayPalDetails.php +9 -5
  120. braintree_sdk/lib/Braintree/Transaction/StatusDetails.php +7 -3
  121. braintree_sdk/lib/Braintree/Transaction/SubscriptionDetails.php +7 -2
  122. braintree_sdk/lib/Braintree/Transaction/VenmoAccountDetails.php +40 -0
  123. braintree_sdk/lib/Braintree/TransactionGateway.php +135 -109
  124. braintree_sdk/lib/Braintree/TransactionSearch.php +108 -109
  125. braintree_sdk/lib/Braintree/TransparentRedirect.php +16 -15
  126. braintree_sdk/lib/Braintree/TransparentRedirectGateway.php +59 -52
  127. braintree_sdk/lib/Braintree/UnknownPaymentMethod.php +9 -6
  128. braintree_sdk/lib/Braintree/Util.php +116 -88
  129. braintree_sdk/lib/Braintree/VenmoAccount.php +75 -0
  130. braintree_sdk/lib/Braintree/Version.php +7 -4
  131. braintree_sdk/lib/Braintree/WebhookNotification.php +24 -20
  132. braintree_sdk/lib/Braintree/WebhookTesting.php +57 -15
  133. braintree_sdk/lib/Braintree/Xml.php +7 -4
  134. braintree_sdk/lib/Braintree/Xml/Generator.php +19 -11
  135. braintree_sdk/lib/Braintree/Xml/Parser.php +17 -8
  136. braintree_sdk/lib/autoload.php +21 -0
  137. braintree_sdk/lib/ssl/api_braintreegateway_com.ca.crt +65 -225
  138. braintree_sdk/phpunit.xml.dist +1 -0
  139. braintree_sdk/tests/Braintree/CreditCardDefaults.php +1 -0
  140. braintree_sdk/tests/Braintree/CreditCardNumbers/CardTypeIndicators.php +3 -1
  141. braintree_sdk/tests/Braintree/OAuthTestHelper.php +12 -9
  142. braintree_sdk/tests/Braintree/fixtures/composer_implementation.php +0 -5
  143. braintree_sdk/tests/{TestHelper.php → Helper.php} +40 -44
  144. braintree_sdk/tests/Setup.php +32 -0
  145. braintree_sdk/tests/integration/AddOnsTest.php +22 -17
  146. braintree_sdk/tests/integration/AddressTest.php +81 -76
  147. braintree_sdk/tests/integration/ClientTokenTest.php +71 -66
  148. braintree_sdk/tests/integration/CreditCardTest.php +551 -521
  149. braintree_sdk/tests/integration/CreditCardVerificationAdvancedSearchTest.php +125 -119
  150. braintree_sdk/tests/integration/CreditCardVerificationTest.php +56 -0
  151. braintree_sdk/tests/integration/CustomerAdvancedSearchTest.php +72 -68
  152. braintree_sdk/tests/integration/CustomerTest.php +464 -426
  153. braintree_sdk/tests/integration/DisbursementTest.php +16 -10
  154. braintree_sdk/tests/integration/DiscountTest.php +22 -17
  155. braintree_sdk/tests/integration/Error/ErrorCollectionTest.php +41 -36
  156. braintree_sdk/tests/integration/Error/ValidationErrorCollectionTest.php +39 -35
  157. braintree_sdk/tests/integration/EuropeBankAccountTest.php +19 -16
  158. braintree_sdk/tests/integration/HttpClientApi.php +17 -12
  159. braintree_sdk/tests/integration/HttpTest.php +32 -27
  160. braintree_sdk/tests/integration/MerchantAccountTest.php +163 -151
  161. braintree_sdk/tests/integration/MerchantTest.php +26 -20
  162. braintree_sdk/tests/integration/MultipleValueNodeTest.php +47 -42
  163. braintree_sdk/tests/integration/OAuthTest.php +76 -69
  164. braintree_sdk/tests/integration/PayPalAccountTest.php +131 -128
  165. braintree_sdk/tests/integration/PaymentMethodNonceTest.php +28 -24
  166. braintree_sdk/tests/integration/PaymentMethodTest.php +790 -474
  167. braintree_sdk/tests/integration/PlanTest.php +38 -32
  168. braintree_sdk/tests/integration/Result/ErrorTest.php +16 -11
  169. braintree_sdk/tests/integration/SettlementBatchSummaryTest.php +38 -31
  170. braintree_sdk/tests/integration/{SubscriptionTestHelper.php → SubscriptionHelper.php} +29 -27
  171. braintree_sdk/tests/integration/SubscriptionSearchTest.php +164 -158
  172. braintree_sdk/tests/integration/SubscriptionTest.php +464 -459
  173. braintree_sdk/tests/integration/TestTransactionTest.php +28 -21
  174. braintree_sdk/tests/integration/TextNodeTest.php +83 -78
  175. braintree_sdk/tests/integration/TransactionAdvancedSearchTest.php +402 -404
braintree_sdk/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ## 3.5.0
2
  * Add support for raw ApplePay params on Transaction create
3
 
1
+ ## 3.8.0
2
+ * Add payment method revoke
3
+ * Add support for options in `submit_for_settlement` transaction flows
4
+ * Add verification create API
5
+ * Update https certificate bundle
6
+
7
+ ## 3.7.0
8
+ * Add VenmoAccount
9
+ * Allow order_id and descriptor to be passed in for Transaction submit_for_settlement
10
+ * Add facilitator details onto transactions
11
+ * Add check webhook constant
12
+
13
+ ## 3.6.1
14
+ * Fix PSR-0 style namespacing when using Symfony
15
+
16
+ ## 3.6.0
17
+ * Add support for proxy servers
18
+ * Add PSR-4 namespacing support
19
+ * Add support for AMEX Express Checkout
20
+ * Add support for new fields in dispute webhooks (`dateWon`, `dateOpened`, `kind`)
21
+ * Add transaction data to sucessful subscription webhook
22
+
23
  ## 3.5.0
24
  * Add support for raw ApplePay params on Transaction create
25
 
braintree_sdk/README.md CHANGED
@@ -21,18 +21,16 @@ The following PHP extensions are required:
21
 
22
  require_once 'PATH_TO_BRAINTREE/lib/Braintree.php';
23
 
24
- Braintree_Configuration::environment('sandbox');
25
- Braintree_Configuration::merchantId('your_merchant_id');
26
- Braintree_Configuration::publicKey('your_public_key');
27
- Braintree_Configuration::privateKey('your_private_key');
28
 
29
- $result = Braintree_Transaction::sale(array(
30
  'amount' => '1000.00',
31
- 'creditCard' => array(
32
- 'number' => '5105105105105100',
33
- 'expirationDate' => '05/12'
34
- )
35
- ));
36
 
37
  if ($result->success) {
38
  print_r("success!: " . $result->transaction->id);
@@ -44,8 +42,6 @@ if ($result->success) {
44
  print_r("Validation errors: \n");
45
  print_r($result->errors->deepAll());
46
  }
47
-
48
- ?>
49
  ```
50
 
51
  ## HHVM Support
@@ -62,13 +58,12 @@ Version [2.40.0](https://github.com/braintree/braintree_php/releases/tag/2.40.0)
62
 
63
  ## Testing
64
 
65
- Tests are written in PHPunit (installed by composer). Unit tests should run on
66
- any system meeting the base requirements:
67
-
68
- phpunit tests/unit/
69
 
70
- Please note that the integration tests require access to services internal to
71
- Braintree, and so will not run in your test environment.
 
 
72
 
73
  ## Open Source Attribution
74
 
21
 
22
  require_once 'PATH_TO_BRAINTREE/lib/Braintree.php';
23
 
24
+ Braintree\Configuration::environment('sandbox');
25
+ Braintree\Configuration::merchantId('your_merchant_id');
26
+ Braintree\Configuration::publicKey('your_public_key');
27
+ Braintree\Configuration::privateKey('your_private_key');
28
 
29
+ $result = Braintree\Transaction::sale([
30
  'amount' => '1000.00',
31
+ 'paymentMethodNonce' => 'nonceFromTheClient',
32
+ 'options' => [ 'submitForSettlement' => true ]
33
+ ]);
 
 
34
 
35
  if ($result->success) {
36
  print_r("success!: " . $result->transaction->id);
42
  print_r("Validation errors: \n");
43
  print_r($result->errors->deepAll());
44
  }
 
 
45
  ```
46
 
47
  ## HHVM Support
58
 
59
  ## Testing
60
 
61
+ 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`.
 
 
 
62
 
63
+ 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:
64
+ ```
65
+ phpunit tests/unit/
66
+ ```
67
 
68
  ## Open Source Attribution
69
 
braintree_sdk/Rakefile CHANGED
@@ -49,9 +49,19 @@ namespace :test do
49
  task :hhvm => %w[hhvm:unit hhvm:integration]
50
 
51
  desc "run a single test file"
52
- task :single_test, :file_path do |t, args|
53
  run_php_test_file(args[:file_path])
54
  end
 
 
 
 
 
 
 
 
 
 
55
  end
56
 
57
  def print_php_version(interpreter)
@@ -65,3 +75,7 @@ end
65
  def run_php_test_file(test_file)
66
  sh "./vendor/bin/phpunit #{test_file}"
67
  end
 
 
 
 
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 a single test"
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)
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
braintree_sdk/composer.json CHANGED
@@ -22,7 +22,15 @@
22
  },
23
  "autoload": {
24
  "psr-0": {
25
- "Braintree": "lib"
 
 
 
 
 
 
 
 
26
  }
27
  }
28
  }
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
  }
braintree_sdk/lib/Braintree.php CHANGED
@@ -1,143 +1,12 @@
1
  <?php
2
  /**
3
  * Braintree PHP Library
 
4
  *
5
- * Braintree base class and initialization
6
- * Provides methods to child classes. This class cannot be instantiated.
7
- *
8
- * PHP version 5
9
- *
10
- * @copyright 2014 Braintree, a division of PayPal, Inc.
11
  */
12
 
13
-
14
- set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__)));
15
-
16
- require_once('Braintree/Base.php');
17
- require_once('Braintree/Modification.php');
18
- require_once('Braintree/Instance.php');
19
-
20
- require_once('Braintree/OAuthCredentials.php');
21
- require_once('Braintree/Address.php');
22
- require_once('Braintree/AddressGateway.php');
23
- require_once('Braintree/AddOn.php');
24
- require_once('Braintree/AddOnGateway.php');
25
- require_once('Braintree/AndroidPayCard.php');
26
- require_once('Braintree/ApplePayCard.php');
27
- require_once('Braintree/ClientToken.php');
28
- require_once('Braintree/ClientTokenGateway.php');
29
- require_once('Braintree/CoinbaseAccount.php');
30
- require_once('Braintree/Collection.php');
31
- require_once('Braintree/Configuration.php');
32
- require_once('Braintree/CredentialsParser.php');
33
- require_once('Braintree/CreditCard.php');
34
- require_once('Braintree/CreditCardGateway.php');
35
- require_once('Braintree/Customer.php');
36
- require_once('Braintree/CustomerGateway.php');
37
- require_once('Braintree/CustomerSearch.php');
38
- require_once('Braintree/DisbursementDetails.php');
39
- require_once('Braintree/Dispute.php');
40
- require_once('Braintree/Dispute/TransactionDetails.php');
41
- require_once('Braintree/Descriptor.php');
42
- require_once('Braintree/Digest.php');
43
- require_once('Braintree/Discount.php');
44
- require_once('Braintree/DiscountGateway.php');
45
- require_once('Braintree/IsNode.php');
46
- require_once('Braintree/EuropeBankAccount.php');
47
- require_once('Braintree/EqualityNode.php');
48
- require_once('Braintree/Exception.php');
49
- require_once('Braintree/Gateway.php');
50
- require_once('Braintree/Http.php');
51
- require_once('Braintree/KeyValueNode.php');
52
- require_once('Braintree/Merchant.php');
53
- require_once('Braintree/MerchantGateway.php');
54
- require_once('Braintree/MerchantAccount.php');
55
- require_once('Braintree/MerchantAccountGateway.php');
56
- require_once('Braintree/MerchantAccount/BusinessDetails.php');
57
- require_once('Braintree/MerchantAccount/FundingDetails.php');
58
- require_once('Braintree/MerchantAccount/IndividualDetails.php');
59
- require_once('Braintree/MerchantAccount/AddressDetails.php');
60
- require_once('Braintree/MultipleValueNode.php');
61
- require_once('Braintree/MultipleValueOrTextNode.php');
62
- require_once('Braintree/OAuthGateway.php');
63
- require_once('Braintree/PartialMatchNode.php');
64
- require_once('Braintree/Plan.php');
65
- require_once('Braintree/PlanGateway.php');
66
- require_once('Braintree/RangeNode.php');
67
- require_once('Braintree/ResourceCollection.php');
68
- require_once('Braintree/RiskData.php');
69
- require_once('Braintree/ThreeDSecureInfo.php');
70
- require_once('Braintree/SettlementBatchSummary.php');
71
- require_once('Braintree/SettlementBatchSummaryGateway.php');
72
- require_once('Braintree/SignatureService.php');
73
- require_once('Braintree/Subscription.php');
74
- require_once('Braintree/SubscriptionGateway.php');
75
- require_once('Braintree/SubscriptionSearch.php');
76
- require_once('Braintree/Subscription/StatusDetails.php');
77
- require_once('Braintree/TextNode.php');
78
- require_once('Braintree/Transaction.php');
79
- require_once('Braintree/TransactionGateway.php');
80
- require_once('Braintree/Disbursement.php');
81
- require_once('Braintree/TransactionSearch.php');
82
- require_once('Braintree/TransparentRedirect.php');
83
- require_once('Braintree/TransparentRedirectGateway.php');
84
- require_once('Braintree/Util.php');
85
- require_once('Braintree/Version.php');
86
- require_once('Braintree/Xml.php');
87
- require_once('Braintree/Error/Codes.php');
88
- require_once('Braintree/Error/ErrorCollection.php');
89
- require_once('Braintree/Error/Validation.php');
90
- require_once('Braintree/Error/ValidationErrorCollection.php');
91
- require_once('Braintree/Exception/Authentication.php');
92
- require_once('Braintree/Exception/Authorization.php');
93
- require_once('Braintree/Exception/Configuration.php');
94
- require_once('Braintree/Exception/DownForMaintenance.php');
95
- require_once('Braintree/Exception/ForgedQueryString.php');
96
- require_once('Braintree/Exception/InvalidChallenge.php');
97
- require_once('Braintree/Exception/InvalidSignature.php');
98
- require_once('Braintree/Exception/NotFound.php');
99
- require_once('Braintree/Exception/ServerError.php');
100
- require_once('Braintree/Exception/SSLCertificate.php');
101
- require_once('Braintree/Exception/SSLCaFileNotFound.php');
102
- require_once('Braintree/Exception/Unexpected.php');
103
- require_once('Braintree/Exception/UpgradeRequired.php');
104
- require_once('Braintree/Exception/ValidationsFailed.php');
105
- require_once('Braintree/Result/CreditCardVerification.php');
106
- require_once('Braintree/Result/Error.php');
107
- require_once('Braintree/Result/Successful.php');
108
- require_once('Braintree/Test/CreditCardNumbers.php');
109
- require_once('Braintree/Test/MerchantAccount.php');
110
- require_once('Braintree/Test/TransactionAmounts.php');
111
- require_once('Braintree/Test/VenmoSdk.php');
112
- require_once('Braintree/Test/Nonces.php');
113
- require_once('Braintree/Transaction/AddressDetails.php');
114
- require_once('Braintree/Transaction/AndroidPayCardDetails.php');
115
- require_once('Braintree/Transaction/ApplePayCardDetails.php');
116
- require_once('Braintree/Transaction/CoinbaseDetails.php');
117
- require_once('Braintree/Transaction/EuropeBankAccountDetails.php');
118
- require_once('Braintree/Transaction/CreditCardDetails.php');
119
- require_once('Braintree/Transaction/PayPalDetails.php');
120
- require_once('Braintree/Transaction/CustomerDetails.php');
121
- require_once('Braintree/Transaction/StatusDetails.php');
122
- require_once('Braintree/Transaction/SubscriptionDetails.php');
123
- require_once('Braintree/WebhookNotification.php');
124
- require_once('Braintree/WebhookTesting.php');
125
- require_once('Braintree/Xml/Generator.php');
126
- require_once('Braintree/Xml/Parser.php');
127
- require_once('Braintree/CreditCardVerification.php');
128
- require_once('Braintree/CreditCardVerificationGateway.php');
129
- require_once('Braintree/CreditCardVerificationSearch.php');
130
- require_once('Braintree/PartnerMerchant.php');
131
- require_once('Braintree/PayPalAccount.php');
132
- require_once('Braintree/PayPalAccountGateway.php');
133
- require_once('Braintree/PaymentMethod.php');
134
- require_once('Braintree/PaymentMethodGateway.php');
135
- require_once('Braintree/PaymentMethodNonce.php');
136
- require_once('Braintree/PaymentMethodNonceGateway.php');
137
- require_once('Braintree/PaymentInstrumentType.php');
138
- require_once('Braintree/UnknownPaymentMethod.php');
139
- require_once('Braintree/Exception/TestOperationPerformedInProduction.php');
140
- require_once('Braintree/Test/Transaction.php');
141
 
142
  if (version_compare(PHP_VERSION, '5.4.0', '<')) {
143
  throw new Braintree_Exception('PHP version >= 5.4.0 required');
@@ -145,7 +14,7 @@ if (version_compare(PHP_VERSION, '5.4.0', '<')) {
145
 
146
 
147
  function requireDependencies() {
148
- $requiredExtensions = array('xmlwriter', 'openssl', 'dom', 'hash', 'curl');
149
  foreach ($requiredExtensions AS $ext) {
150
  if (!extension_loaded($ext)) {
151
  throw new Braintree_Exception('The Braintree library requires the ' . $ext . ' extension.');
1
  <?php
2
  /**
3
  * Braintree PHP Library
4
+ * Creates class_aliases for old class names replaced by PSR-4 Namespaces
5
  *
6
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
 
 
 
 
 
7
  */
8
 
9
+ require_once('autoload.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  if (version_compare(PHP_VERSION, '5.4.0', '<')) {
12
  throw new Braintree_Exception('PHP version >= 5.4.0 required');
14
 
15
 
16
  function requireDependencies() {
17
+ $requiredExtensions = ['xmlwriter', 'openssl', 'dom', 'hash', 'curl'];
18
  foreach ($requiredExtensions AS $ext) {
19
  if (!extension_loaded($ext)) {
20
  throw new Braintree_Exception('The Braintree library requires the ' . $ext . ' extension.');
braintree_sdk/lib/Braintree/AddOn.php CHANGED
@@ -1,11 +1,12 @@
1
  <?php
 
2
 
3
- class Braintree_AddOn extends Braintree_Modification
4
  {
5
  /**
6
  *
7
  * @param array $attributes
8
- * @return Braintree_AddOn
9
  */
10
  public static function factory($attributes)
11
  {
@@ -18,10 +19,11 @@ class Braintree_AddOn extends Braintree_Modification
18
  /**
19
  * static methods redirecting to gateway
20
  *
21
- * @return Braintree_AddOn[]
22
  */
23
  public static function all()
24
  {
25
- return Braintree_Configuration::gateway()->addOn()->all();
26
  }
27
  }
 
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
  {
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');
braintree_sdk/lib/Braintree/AddOnGateway.php CHANGED
@@ -1,51 +1,53 @@
1
  <?php
 
2
 
3
- class Braintree_AddOnGateway
4
  {
5
  /**
6
  *
7
- * @var Braintree_Gateway
8
  */
9
  private $_gateway;
10
-
11
  /**
12
  *
13
- * @var Braintree_Configuration
14
  */
15
  private $_config;
16
-
17
  /**
18
  *
19
- * @var Braintree_Http
20
  */
21
  private $_http;
22
 
23
  /**
24
- *
25
- * @param Braintree_Gateway $gateway
26
  */
27
  public function __construct($gateway)
28
  {
29
  $this->_gateway = $gateway;
30
  $this->_config = $gateway->config;
31
  $this->_config->assertHasAccessTokenOrKeys();
32
- $this->_http = new Braintree_Http($gateway->config);
33
  }
34
 
35
  /**
36
- *
37
- * @return Braintree_AddOn[]
38
  */
39
  public function all()
40
  {
41
  $path = $this->_config->merchantPath() . '/add_ons';
42
  $response = $this->_http->get($path);
43
 
44
- $addOns = array("addOn" => $response['addOns']);
45
 
46
- return Braintree_Util::extractAttributeAsArray(
47
  $addOns,
48
  'addOn'
49
  );
50
  }
51
  }
 
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');
braintree_sdk/lib/Braintree/Address.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  /**
3
  * Braintree Address module
4
  * PHP Version 5
@@ -9,7 +11,7 @@
9
  * as the shipping address when creating a Transaction.
10
  *
11
  * @package Braintree
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read string $company
15
  * @property-read string $countryName
@@ -25,18 +27,18 @@
25
  * @property-read string $streetAddress
26
  * @property-read string $updatedAt
27
  */
28
- class Braintree_Address extends Braintree_Base
29
  {
30
  /**
31
- * returns false if comparing object is not a Braintree_Address,
32
- * or is a Braintree_Address with a different id
33
  *
34
  * @param object $other address to compare against
35
  * @return boolean
36
  */
37
  public function isEqual($other)
38
  {
39
- return !($other instanceof Braintree_Address) ?
40
  false :
41
  ($this->id === $other->id && $this->customerId === $other->customerId);
42
  }
@@ -45,12 +47,12 @@ class Braintree_Address extends Braintree_Base
45
  * create a printable representation of the object as:
46
  * ClassName[property=value, property=value]
47
  * @ignore
48
- * @return var
49
  */
50
  public function __toString()
51
  {
52
  return __CLASS__ . '[' .
53
- Braintree_Util::attributesToString($this->_attributes) .']';
54
  }
55
 
56
  /**
@@ -59,7 +61,7 @@ class Braintree_Address extends Braintree_Base
59
  * @ignore
60
  * @access protected
61
  * @param array $addressAttribs array of address data
62
- * @return none
63
  */
64
  protected function _initialize($addressAttribs)
65
  {
@@ -68,10 +70,10 @@ class Braintree_Address extends Braintree_Base
68
  }
69
 
70
  /**
71
- * factory method: returns an instance of Braintree_Address
72
  * to the requesting method, with populated properties
73
  * @ignore
74
- * @return object instance of Braintree_Address
75
  */
76
  public static function factory($attributes)
77
  {
@@ -85,64 +87,65 @@ class Braintree_Address extends Braintree_Base
85
  // static methods redirecting to gateway
86
 
87
  /**
88
- *
89
  * @param array $attribs
90
- * @return Braintree_Address
91
  */
92
  public static function create($attribs)
93
  {
94
- return Braintree_Configuration::gateway()->address()->create($attribs);
95
  }
96
 
97
  /**
98
- *
99
  * @param array $attribs
100
- * @return Braintree_Address
101
  */
102
  public static function createNoValidate($attribs)
103
  {
104
- return Braintree_Configuration::gateway()->address()->createNoValidate($attribs);
105
  }
106
 
107
  /**
108
- *
109
- * @param Braintree_Customer|int $customerOrId
110
  * @param int $addressId
111
  * @throws InvalidArgumentException
112
- * @return Braintree_Result_Successful
113
  */
114
  public static function delete($customerOrId = null, $addressId = null)
115
  {
116
- return Braintree_Configuration::gateway()->address()->delete($customerOrId, $addressId);
117
  }
118
 
119
  /**
120
- *
121
- * @param Braintree_Customer|int $customerOrId
122
  * @param int $addressId
123
- * @throws Braintree_Exception_NotFound
124
- * @return Braintree_Address
125
  */
126
  public static function find($customerOrId, $addressId)
127
  {
128
- return Braintree_Configuration::gateway()->address()->find($customerOrId, $addressId);
129
  }
130
 
131
  /**
132
- *
133
- * @param Braintree_Customer|int $customerOrId
134
  * @param int $addressId
135
  * @param array $attributes
136
- * @throws Braintree_Exception_Unexpected
137
- * @return Braintree_Result_Successful|Braintree_Result_Error
138
  */
139
  public static function update($customerOrId, $addressId, $attributes)
140
  {
141
- return Braintree_Configuration::gateway()->address()->update($customerOrId, $addressId, $attributes);
142
  }
143
 
144
  public static function updateNoValidate($customerOrId, $addressId, $attributes)
145
  {
146
- return Braintree_Configuration::gateway()->address()->updateNoValidate($customerOrId, $addressId, $attributes);
147
  }
148
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree Address module
6
  * PHP Version 5
11
  * as the shipping address when creating a Transaction.
12
  *
13
  * @package Braintree
14
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
  *
16
  * @property-read string $company
17
  * @property-read string $countryName
27
  * @property-read string $streetAddress
28
  * @property-read string $updatedAt
29
  */
30
+ class Address extends Base
31
  {
32
  /**
33
+ * returns false if comparing object is not a Address,
34
+ * or is a Address with a different id
35
  *
36
  * @param object $other address to compare against
37
  * @return boolean
38
  */
39
  public function isEqual($other)
40
  {
41
+ return !($other instanceof self) ?
42
  false :
43
  ($this->id === $other->id && $this->customerId === $other->customerId);
44
  }
47
  * create a printable representation of the object as:
48
  * ClassName[property=value, property=value]
49
  * @ignore
50
+ * @return string
51
  */
52
  public function __toString()
53
  {
54
  return __CLASS__ . '[' .
55
+ Util::attributesToString($this->_attributes) . ']';
56
  }
57
 
58
  /**
61
  * @ignore
62
  * @access protected
63
  * @param array $addressAttribs array of address data
64
+ * @return void
65
  */
66
  protected function _initialize($addressAttribs)
67
  {
70
  }
71
 
72
  /**
73
+ * factory method: returns an instance of Address
74
  * to the requesting method, with populated properties
75
  * @ignore
76
+ * @return Address
77
  */
78
  public static function factory($attributes)
79
  {
87
  // static methods redirecting to gateway
88
 
89
  /**
90
+ *
91
  * @param array $attribs
92
+ * @return Address
93
  */
94
  public static function create($attribs)
95
  {
96
+ return Configuration::gateway()->address()->create($attribs);
97
  }
98
 
99
  /**
100
+ *
101
  * @param array $attribs
102
+ * @return Address
103
  */
104
  public static function createNoValidate($attribs)
105
  {
106
+ return Configuration::gateway()->address()->createNoValidate($attribs);
107
  }
108
 
109
  /**
110
+ *
111
+ * @param Customer|int $customerOrId
112
  * @param int $addressId
113
  * @throws InvalidArgumentException
114
+ * @return Result\Successful
115
  */
116
  public static function delete($customerOrId = null, $addressId = null)
117
  {
118
+ return Configuration::gateway()->address()->delete($customerOrId, $addressId);
119
  }
120
 
121
  /**
122
+ *
123
+ * @param Customer|int $customerOrId
124
  * @param int $addressId
125
+ * @throws Exception\NotFound
126
+ * @return Address
127
  */
128
  public static function find($customerOrId, $addressId)
129
  {
130
+ return Configuration::gateway()->address()->find($customerOrId, $addressId);
131
  }
132
 
133
  /**
134
+ *
135
+ * @param Customer|int $customerOrId
136
  * @param int $addressId
137
  * @param array $attributes
138
+ * @throws Exception\Unexpected
139
+ * @return Result\Successful|Result\Error
140
  */
141
  public static function update($customerOrId, $addressId, $attributes)
142
  {
143
+ return Configuration::gateway()->address()->update($customerOrId, $addressId, $attributes);
144
  }
145
 
146
  public static function updateNoValidate($customerOrId, $addressId, $attributes)
147
  {
148
+ return Configuration::gateway()->address()->updateNoValidate($customerOrId, $addressId, $attributes);
149
  }
150
  }
151
+ class_alias('Braintree\Address', 'Braintree_Address');
braintree_sdk/lib/Braintree/AddressGateway.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Braintree AddressGateway module
4
  * PHP Version 5
@@ -9,38 +13,38 @@
9
  * as the shipping address when creating a Transaction.
10
  *
11
  * @package Braintree
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  */
14
- class Braintree_AddressGateway
15
  {
16
  /**
17
  *
18
- * @var Braintree_Gateway
19
  */
20
  private $_gateway;
21
-
22
  /**
23
  *
24
- * @var Braintree_Configuration
25
  */
26
  private $_config;
27
-
28
  /**
29
  *
30
- * @var Braintree_Http
31
  */
32
  private $_http;
33
 
34
  /**
35
- *
36
- * @param Braintree_Gateway $gateway
37
  */
38
  public function __construct($gateway)
39
  {
40
  $this->_gateway = $gateway;
41
  $this->_config = $gateway->config;
42
  $this->_config->assertHasAccessTokenOrKeys();
43
- $this->_http = new Braintree_Http($gateway->config);
44
  }
45
 
46
 
@@ -49,11 +53,11 @@ class Braintree_AddressGateway
49
  *
50
  * @access public
51
  * @param array $attribs
52
- * @return object Result, either Successful or Error
53
  */
54
  public function create($attribs)
55
  {
56
- Braintree_Util::verifyKeys(self::createSignature(), $attribs);
57
  $customerId = isset($attribs['customerId']) ?
58
  $attribs['customerId'] :
59
  null;
@@ -62,23 +66,23 @@ class Braintree_AddressGateway
62
  unset($attribs['customerId']);
63
  return $this->_doCreate(
64
  '/customers/' . $customerId . '/addresses',
65
- array('address' => $attribs)
66
  );
67
  }
68
 
69
  /**
70
  * attempts the create operation assuming all data will validate
71
- * returns a Braintree_Address object instead of a Result
72
  *
73
  * @access public
74
  * @param array $attribs
75
- * @return object
76
- * @throws Braintree_Exception_ValidationError
77
  */
78
  public function createNoValidate($attribs)
79
  {
80
  $result = $this->create($attribs);
81
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
82
 
83
  }
84
 
@@ -94,7 +98,7 @@ class Braintree_AddressGateway
94
  $customerId = $this->_determineCustomerId($customerOrId);
95
  $path = $this->_config->merchantPath() . '/customers/' . $customerId . '/addresses/' . $addressId;
96
  $this->_http->delete($path);
97
- return new Braintree_Result_Successful();
98
  }
99
 
100
  /**
@@ -108,8 +112,8 @@ class Braintree_AddressGateway
108
  * @access public
109
  * @param mixed $customerOrId
110
  * @param string $addressId
111
- * @return object Braintree_Address
112
- * @throws Braintree_Exception_NotFound
113
  */
114
  public function find($customerOrId, $addressId)
115
  {
@@ -120,9 +124,9 @@ class Braintree_AddressGateway
120
  try {
121
  $path = $this->_config->merchantPath() . '/customers/' . $customerId . '/addresses/' . $addressId;
122
  $response = $this->_http->get($path);
123
- return Braintree_Address::factory($response['address']);
124
- } catch (Braintree_Exception_NotFound $e) {
125
- throw new Braintree_Exception_NotFound(
126
  'address for customer ' . $customerId .
127
  ' with id ' . $addressId . ' not found.'
128
  );
@@ -142,16 +146,16 @@ class Braintree_AddressGateway
142
  * @param array $attributes
143
  * @param mixed $customerOrId (only used in call)
144
  * @param string $addressId (only used in call)
145
- * @return object Braintree_Result_Successful or Braintree_Result_Error
146
  */
147
  public function update($customerOrId, $addressId, $attributes)
148
  {
149
  $this->_validateId($addressId);
150
  $customerId = $this->_determineCustomerId($customerOrId);
151
- Braintree_Util::verifyKeys(self::updateSignature(), $attributes);
152
 
153
  $path = $this->_config->merchantPath() . '/customers/' . $customerId . '/addresses/' . $addressId;
154
- $response = $this->_http->put($path, array('address' => $attributes));
155
 
156
  return $this->_verifyGatewayResponse($response);
157
 
@@ -167,14 +171,14 @@ class Braintree_AddressGateway
167
  * @access public
168
  * @param array $transactionAttribs
169
  * @param string $customerId
170
- * @return object Braintree_Transaction
171
- * @throws Braintree_Exception_ValidationsFailed
172
- * @see Braintree_Address::update()
173
  */
174
  public function updateNoValidate($customerOrId, $addressId, $attributes)
175
  {
176
  $result = $this->update($customerOrId, $addressId, $attributes);
177
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
178
  }
179
 
180
  /**
@@ -183,11 +187,11 @@ class Braintree_AddressGateway
183
  */
184
  public static function createSignature()
185
  {
186
- return array(
187
  'company', 'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric',
188
  'countryName', 'customerId', 'extendedAddress', 'firstName',
189
  'lastName', 'locality', 'postalCode', 'region', 'streetAddress'
190
- );
191
  }
192
 
193
  /**
@@ -250,7 +254,7 @@ class Braintree_AddressGateway
250
  */
251
  private function _determineCustomerId($customerOrId)
252
  {
253
- $customerId = ($customerOrId instanceof Braintree_Customer) ? $customerOrId->id : $customerOrId;
254
  $this->_validateCustomerId($customerId);
255
  return $customerId;
256
 
@@ -262,7 +266,7 @@ class Braintree_AddressGateway
262
  * @ignore
263
  * @param string $subPath
264
  * @param array $params
265
- * @return mixed
266
  */
267
  private function _doCreate($subPath, $params)
268
  {
@@ -276,30 +280,31 @@ class Braintree_AddressGateway
276
  /**
277
  * generic method for validating incoming gateway responses
278
  *
279
- * creates a new Braintree_Address object and encapsulates
280
- * it inside a Braintree_Result_Successful object, or
281
- * encapsulates a Braintree_Errors object inside a Result_Error
282
- * alternatively, throws an Unexpected exception if the response is invalid.
283
  *
284
  * @ignore
285
  * @param array $response gateway response values
286
- * @return object Result_Successful|Result_Error
287
- * @throws Braintree_Exception_Unexpected
288
  */
289
  private function _verifyGatewayResponse($response)
290
  {
291
  if (isset($response['address'])) {
292
- // return a populated instance of Braintree_Address
293
- return new Braintree_Result_Successful(
294
- Braintree_Address::factory($response['address'])
295
  );
296
  } else if (isset($response['apiErrorResponse'])) {
297
- return new Braintree_Result_Error($response['apiErrorResponse']);
298
  } else {
299
- throw new Braintree_Exception_Unexpected(
300
  "Expected address or apiErrorResponse"
301
  );
302
  }
303
 
304
  }
305
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
  /**
7
  * Braintree AddressGateway module
8
  * PHP Version 5
13
  * as the shipping address when creating a Transaction.
14
  *
15
  * @package Braintree
16
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
17
  */
18
+ class AddressGateway
19
  {
20
  /**
21
  *
22
+ * @var Gateway
23
  */
24
  private $_gateway;
25
+
26
  /**
27
  *
28
+ * @var Configuration
29
  */
30
  private $_config;
31
+
32
  /**
33
  *
34
+ * @var Http
35
  */
36
  private $_http;
37
 
38
  /**
39
+ *
40
+ * @param Gateway $gateway
41
  */
42
  public function __construct($gateway)
43
  {
44
  $this->_gateway = $gateway;
45
  $this->_config = $gateway->config;
46
  $this->_config->assertHasAccessTokenOrKeys();
47
+ $this->_http = new Http($gateway->config);
48
  }
49
 
50
 
53
  *
54
  * @access public
55
  * @param array $attribs
56
+ * @return Result\Successful|Result\Error
57
  */
58
  public function create($attribs)
59
  {
60
+ Util::verifyKeys(self::createSignature(), $attribs);
61
  $customerId = isset($attribs['customerId']) ?
62
  $attribs['customerId'] :
63
  null;
66
  unset($attribs['customerId']);
67
  return $this->_doCreate(
68
  '/customers/' . $customerId . '/addresses',
69
+ ['address' => $attribs]
70
  );
71
  }
72
 
73
  /**
74
  * attempts the create operation assuming all data will validate
75
+ * returns a Address object instead of a Result
76
  *
77
  * @access public
78
  * @param array $attribs
79
+ * @return self
80
+ * @throws Exception\ValidationError
81
  */
82
  public function createNoValidate($attribs)
83
  {
84
  $result = $this->create($attribs);
85
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
86
 
87
  }
88
 
98
  $customerId = $this->_determineCustomerId($customerOrId);
99
  $path = $this->_config->merchantPath() . '/customers/' . $customerId . '/addresses/' . $addressId;
100
  $this->_http->delete($path);
101
+ return new Result\Successful();
102
  }
103
 
104
  /**
112
  * @access public
113
  * @param mixed $customerOrId
114
  * @param string $addressId
115
+ * @return Address
116
+ * @throws Exception\NotFound
117
  */
118
  public function find($customerOrId, $addressId)
119
  {
124
  try {
125
  $path = $this->_config->merchantPath() . '/customers/' . $customerId . '/addresses/' . $addressId;
126
  $response = $this->_http->get($path);
127
+ return Address::factory($response['address']);
128
+ } catch (Exception\NotFound $e) {
129
+ throw new Exception\NotFound(
130
  'address for customer ' . $customerId .
131
  ' with id ' . $addressId . ' not found.'
132
  );
146
  * @param array $attributes
147
  * @param mixed $customerOrId (only used in call)
148
  * @param string $addressId (only used in call)
149
+ * @return Result\Successful|Result\Error
150
  */
151
  public function update($customerOrId, $addressId, $attributes)
152
  {
153
  $this->_validateId($addressId);
154
  $customerId = $this->_determineCustomerId($customerOrId);
155
+ Util::verifyKeys(self::updateSignature(), $attributes);
156
 
157
  $path = $this->_config->merchantPath() . '/customers/' . $customerId . '/addresses/' . $addressId;
158
+ $response = $this->_http->put($path, ['address' => $attributes]);
159
 
160
  return $this->_verifyGatewayResponse($response);
161
 
171
  * @access public
172
  * @param array $transactionAttribs
173
  * @param string $customerId
174
+ * @return Transaction
175
+ * @throws Exception\ValidationsFailed
176
+ * @see Address::update()
177
  */
178
  public function updateNoValidate($customerOrId, $addressId, $attributes)
179
  {
180
  $result = $this->update($customerOrId, $addressId, $attributes);
181
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
182
  }
183
 
184
  /**
187
  */
188
  public static function createSignature()
189
  {
190
+ return [
191
  'company', 'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric',
192
  'countryName', 'customerId', 'extendedAddress', 'firstName',
193
  'lastName', 'locality', 'postalCode', 'region', 'streetAddress'
194
+ ];
195
  }
196
 
197
  /**
254
  */
255
  private function _determineCustomerId($customerOrId)
256
  {
257
+ $customerId = ($customerOrId instanceof Customer) ? $customerOrId->id : $customerOrId;
258
  $this->_validateCustomerId($customerId);
259
  return $customerId;
260
 
266
  * @ignore
267
  * @param string $subPath
268
  * @param array $params
269
+ * @return Result\Successful|Result\Error
270
  */
271
  private function _doCreate($subPath, $params)
272
  {
280
  /**
281
  * generic method for validating incoming gateway responses
282
  *
283
+ * creates a new Address object and encapsulates
284
+ * it inside a Result\Successful object, or
285
+ * encapsulates an Errors object inside a Result\Error
286
+ * alternatively, throws an Unexpected exception if the response is invalid
287
  *
288
  * @ignore
289
  * @param array $response gateway response values
290
+ * @return Result\Successful|Result\Error
291
+ * @throws Exception\Unexpected
292
  */
293
  private function _verifyGatewayResponse($response)
294
  {
295
  if (isset($response['address'])) {
296
+ // return a populated instance of Address
297
+ return new Result\Successful(
298
+ Address::factory($response['address'])
299
  );
300
  } else if (isset($response['apiErrorResponse'])) {
301
+ return new Result\Error($response['apiErrorResponse']);
302
  } else {
303
+ throw new Exception\Unexpected(
304
  "Expected address or apiErrorResponse"
305
  );
306
  }
307
 
308
  }
309
  }
310
+ class_alias('Braintree\AddressGateway', 'Braintree_AddressGateway');
braintree_sdk/lib/Braintree/AmexExpressCheckoutCard.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
+ *
16
+ * @property-read string $createdAt
17
+ * @property-read string $default
18
+ * @property-read string $updatedAt
19
+ * @property-read string $customerId
20
+ * @property-read string $cardType
21
+ * @property-read string $bin
22
+ * @property-read string $cardMemberExpiryDate
23
+ * @property-read string $cardMemberNumber
24
+ * @property-read string $cardType
25
+ * @property-read string $sourceDescription
26
+ * @property-read string $token
27
+ * @property-read string $imageUrl
28
+ * @property-read string $expirationMonth
29
+ * @property-read string $expirationYear
30
+ */
31
+ class AmexExpressCheckoutCard extends Base
32
+ {
33
+ /* instance methods */
34
+ /**
35
+ * returns false if default is null or false
36
+ *
37
+ * @return boolean
38
+ */
39
+ public function isDefault()
40
+ {
41
+ return $this->default;
42
+ }
43
+
44
+ /**
45
+ * factory method: returns an instance of AmexExpressCheckoutCard
46
+ * to the requesting method, with populated properties
47
+ *
48
+ * @ignore
49
+ * @return AmexExpressCheckoutCard
50
+ */
51
+ public static function factory($attributes)
52
+ {
53
+
54
+ $instance = new self();
55
+ $instance->_initialize($attributes);
56
+ return $instance;
57
+ }
58
+
59
+ /**
60
+ * sets instance properties from an array of values
61
+ *
62
+ * @access protected
63
+ * @param array $amexExpressCheckoutCardAttribs array of Amex Express Checkout card properties
64
+ * @return void
65
+ */
66
+ protected function _initialize($amexExpressCheckoutCardAttribs)
67
+ {
68
+ // set the attributes
69
+ $this->_attributes = $amexExpressCheckoutCardAttribs;
70
+
71
+ $subscriptionArray = [];
72
+ if (isset($amexExpressCheckoutCardAttribs['subscriptions'])) {
73
+ foreach ($amexExpressCheckoutCardAttribs['subscriptions'] AS $subscription) {
74
+ $subscriptionArray[] = Subscription::factory($subscription);
75
+ }
76
+ }
77
+
78
+ $this->_set('subscriptions', $subscriptionArray);
79
+ }
80
+ }
81
+ class_alias('Braintree\AmexExpressCheckoutCard', 'Braintree_AmexExpressCheckoutCard');
braintree_sdk/lib/Braintree/AndroidPayCard.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  /**
3
  * Braintree AndroidPayCard module
4
  * Creates and manages Braintree Android Pay cards
@@ -9,11 +11,12 @@
9
  *
10
  * @package Braintree
11
  * @category Resources
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read string $bin
15
  * @property-read string $cardType
16
  * @property-read string $createdAt
 
17
  * @property-read string $default
18
  * @property-read string $expirationMonth
19
  * @property-read string $expirationYear
@@ -28,7 +31,7 @@
28
  * @property-read string $virtualCardLast4
29
  * @property-read string $virtualCardType
30
  */
31
- class Braintree_AndroidPayCard extends Braintree_Base
32
  {
33
  /* instance methods */
34
  /**
@@ -42,20 +45,20 @@ class Braintree_AndroidPayCard extends Braintree_Base
42
  }
43
 
44
  /**
45
- * factory method: returns an instance of Braintree_AndroidPayCard
46
  * to the requesting method, with populated properties
47
  *
48
  * @ignore
49
- * @return object instance of Braintree_AndroidPayCard
50
  */
51
  public static function factory($attributes)
52
  {
53
- $defaultAttributes = array(
54
  'expirationMonth' => '',
55
  'expirationYear' => '',
56
  'last4' => $attributes['virtualCardLast4'],
57
  'cardType' => $attributes['virtualCardType'],
58
- );
59
 
60
  $instance = new self();
61
  $instance->_initialize(array_merge($defaultAttributes, $attributes));
@@ -67,20 +70,21 @@ class Braintree_AndroidPayCard extends Braintree_Base
67
  *
68
  * @access protected
69
  * @param array $androidPayCardAttribs array of Android Pay card properties
70
- * @return none
71
  */
72
  protected function _initialize($androidPayCardAttribs)
73
  {
74
  // set the attributes
75
  $this->_attributes = $androidPayCardAttribs;
76
 
77
- $subscriptionArray = array();
78
  if (isset($androidPayCardAttribs['subscriptions'])) {
79
  foreach ($androidPayCardAttribs['subscriptions'] AS $subscription) {
80
- $subscriptionArray[] = Braintree_Subscription::factory($subscription);
81
  }
82
  }
83
 
84
  $this->_set('subscriptions', $subscriptionArray);
85
  }
86
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree AndroidPayCard module
6
  * Creates and manages Braintree Android Pay cards
11
  *
12
  * @package Braintree
13
  * @category Resources
14
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
  *
16
  * @property-read string $bin
17
  * @property-read string $cardType
18
  * @property-read string $createdAt
19
+ * @property-read string $customerId
20
  * @property-read string $default
21
  * @property-read string $expirationMonth
22
  * @property-read string $expirationYear
31
  * @property-read string $virtualCardLast4
32
  * @property-read string $virtualCardType
33
  */
34
+ class AndroidPayCard extends Base
35
  {
36
  /* instance methods */
37
  /**
45
  }
46
 
47
  /**
48
+ * factory method: returns an instance of AndroidPayCard
49
  * to the requesting method, with populated properties
50
  *
51
  * @ignore
52
+ * @return AndroidPayCard
53
  */
54
  public static function factory($attributes)
55
  {
56
+ $defaultAttributes = [
57
  'expirationMonth' => '',
58
  'expirationYear' => '',
59
  'last4' => $attributes['virtualCardLast4'],
60
  'cardType' => $attributes['virtualCardType'],
61
+ ];
62
 
63
  $instance = new self();
64
  $instance->_initialize(array_merge($defaultAttributes, $attributes));
70
  *
71
  * @access protected
72
  * @param array $androidPayCardAttribs array of Android Pay card properties
73
+ * @return void
74
  */
75
  protected function _initialize($androidPayCardAttribs)
76
  {
77
  // set the attributes
78
  $this->_attributes = $androidPayCardAttribs;
79
 
80
+ $subscriptionArray = [];
81
  if (isset($androidPayCardAttribs['subscriptions'])) {
82
  foreach ($androidPayCardAttribs['subscriptions'] AS $subscription) {
83
+ $subscriptionArray[] = Subscription::factory($subscription);
84
  }
85
  }
86
 
87
  $this->_set('subscriptions', $subscriptionArray);
88
  }
89
  }
90
+ class_alias('Braintree\AndroidPayCard', 'Braintree_AndroidPayCard');
braintree_sdk/lib/Braintree/ApplePayCard.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  /**
3
  * Braintree ApplePayCard module
4
  * Creates and manages Braintree Apple Pay cards
@@ -9,10 +11,11 @@
9
  *
10
  * @package Braintree
11
  * @category Resources
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read string $cardType
15
  * @property-read string $createdAt
 
16
  * @property-read string $expirationDate
17
  * @property-read string $expirationMonth
18
  * @property-read string $expirationYear
@@ -23,7 +26,7 @@
23
  * @property-read string $sourceDescription
24
  * @property-read string $updatedAt
25
  */
26
- class Braintree_ApplePayCard extends Braintree_Base
27
  {
28
  // Card Type
29
  const AMEX = 'Apple Pay - American Express';
@@ -52,19 +55,19 @@ class Braintree_ApplePayCard extends Braintree_Base
52
  }
53
 
54
  /**
55
- * factory method: returns an instance of Braintree_ApplePayCard
56
  * to the requesting method, with populated properties
57
  *
58
  * @ignore
59
- * @return object instance of Braintree_ApplePayCard
60
  */
61
  public static function factory($attributes)
62
  {
63
- $defaultAttributes = array(
64
  'expirationMonth' => '',
65
  'expirationYear' => '',
66
  'last4' => '',
67
- );
68
 
69
  $instance = new self();
70
  $instance->_initialize(array_merge($defaultAttributes, $attributes));
@@ -76,17 +79,17 @@ class Braintree_ApplePayCard extends Braintree_Base
76
  *
77
  * @access protected
78
  * @param array $applePayCardAttribs array of Apple Pay card properties
79
- * @return none
80
  */
81
  protected function _initialize($applePayCardAttribs)
82
  {
83
  // set the attributes
84
  $this->_attributes = $applePayCardAttribs;
85
 
86
- $subscriptionArray = array();
87
  if (isset($applePayCardAttribs['subscriptions'])) {
88
  foreach ($applePayCardAttribs['subscriptions'] AS $subscription) {
89
- $subscriptionArray[] = Braintree_Subscription::factory($subscription);
90
  }
91
  }
92
 
@@ -94,3 +97,4 @@ class Braintree_ApplePayCard extends Braintree_Base
94
  $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
95
  }
96
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree ApplePayCard module
6
  * Creates and manages Braintree Apple Pay cards
11
  *
12
  * @package Braintree
13
  * @category Resources
14
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
  *
16
  * @property-read string $cardType
17
  * @property-read string $createdAt
18
+ * @property-read string $customerId
19
  * @property-read string $expirationDate
20
  * @property-read string $expirationMonth
21
  * @property-read string $expirationYear
26
  * @property-read string $sourceDescription
27
  * @property-read string $updatedAt
28
  */
29
+ class ApplePayCard extends Base
30
  {
31
  // Card Type
32
  const AMEX = 'Apple Pay - American Express';
55
  }
56
 
57
  /**
58
+ * factory method: returns an instance of ApplePayCard
59
  * to the requesting method, with populated properties
60
  *
61
  * @ignore
62
+ * @return ApplePayCard
63
  */
64
  public static function factory($attributes)
65
  {
66
+ $defaultAttributes = [
67
  'expirationMonth' => '',
68
  'expirationYear' => '',
69
  'last4' => '',
70
+ ];
71
 
72
  $instance = new self();
73
  $instance->_initialize(array_merge($defaultAttributes, $attributes));
79
  *
80
  * @access protected
81
  * @param array $applePayCardAttribs array of Apple Pay card properties
82
+ * @return void
83
  */
84
  protected function _initialize($applePayCardAttribs)
85
  {
86
  // set the attributes
87
  $this->_attributes = $applePayCardAttribs;
88
 
89
+ $subscriptionArray = [];
90
  if (isset($applePayCardAttribs['subscriptions'])) {
91
  foreach ($applePayCardAttribs['subscriptions'] AS $subscription) {
92
+ $subscriptionArray[] = Subscription::factory($subscription);
93
  }
94
  }
95
 
97
  $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
98
  }
99
  }
100
+ class_alias('Braintree\ApplePayCard', 'Braintree_ApplePayCard');
braintree_sdk/lib/Braintree/Base.php CHANGED
@@ -1,17 +1,24 @@
1
  <?php
 
2
 
3
  /**
4
- * Base functionality for library classes
 
 
 
 
 
 
 
5
  */
6
- abstract class Braintree_Base
7
  {
 
 
8
  /**
9
- * Disable the default constructor
10
- *
11
- * Objects that inherit from Braintree_Base should be constructed with
12
- * the static factory() method.
13
- *
14
  * @ignore
 
 
15
  */
16
  protected function __construct()
17
  {
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
  */
14
+ abstract class Base
15
  {
16
+ protected $_attributes = [];
17
+
18
  /**
 
 
 
 
 
19
  * @ignore
20
+ * don't permit an explicit call of the constructor!
21
+ * (like $t = new Transaction())
22
  */
23
  protected function __construct()
24
  {
braintree_sdk/lib/Braintree/ClientToken.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
 
2
 
3
- class Braintree_ClientToken
4
  {
5
  const DEFAULT_VERSION = 2;
6
 
@@ -8,40 +9,41 @@ class Braintree_ClientToken
8
  // static methods redirecting to gateway
9
 
10
  /**
11
- *
12
  * @param array $params
13
  * @return array
14
  */
15
- public static function generate($params=array())
16
  {
17
- return Braintree_Configuration::gateway()->clientToken()->generate($params);
18
  }
19
 
20
  /**
21
- *
22
  * @param type $params
23
  * @throws InvalidArgumentException
24
  */
25
  public static function conditionallyVerifyKeys($params)
26
  {
27
- return Braintree_Configuration::gateway()->clientToken()->conditionallyVerifyKeys($params);
28
  }
29
 
30
  /**
31
- *
32
  * @return string client token retrieved from server
33
  */
34
  public static function generateWithCustomerIdSignature()
35
  {
36
- return Braintree_Configuration::gateway()->clientToken()->generateWithCustomerIdSignature();
37
  }
38
 
39
  /**
40
- *
41
  * @return string client token retrieved from server
42
  */
43
  public static function generateWithoutCustomerIdSignature()
44
  {
45
- return Braintree_Configuration::gateway()->clientToken()->generateWithoutCustomerIdSignature();
46
  }
47
  }
 
1
  <?php
2
+ namespace Braintree;
3
 
4
+ class ClientToken
5
  {
6
  const DEFAULT_VERSION = 2;
7
 
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');
braintree_sdk/lib/Braintree/ClientTokenGateway.php CHANGED
@@ -1,45 +1,48 @@
1
  <?php
 
2
 
3
- class Braintree_ClientTokenGateway
 
 
4
  {
5
  /**
6
  *
7
- * @var Braintree_Gateway
8
  */
9
  private $_gateway;
10
 
11
  /**
12
  *
13
- * @var Braintree_Configuration
14
  */
15
  private $_config;
16
 
17
  /**
18
  *
19
- * @var Braintree_Http
20
  */
21
  private $_http;
22
 
23
  /**
24
  *
25
- * @param Braintree_Gateway $gateway
26
  */
27
  public function __construct($gateway)
28
  {
29
  $this->_gateway = $gateway;
30
  $this->_config = $gateway->config;
31
  $this->_config->assertHasAccessTokenOrKeys();
32
- $this->_http = new Braintree_Http($gateway->config);
33
  }
34
 
35
- public function generate($params=array())
36
  {
37
  if (!array_key_exists("version", $params)) {
38
- $params["version"] = Braintree_ClientToken::DEFAULT_VERSION;
39
  }
40
 
41
  $this->conditionallyVerifyKeys($params);
42
- $generateParams = array("client_token" => $params);
43
 
44
  return $this->_doGenerate('/client_token', $generateParams);
45
  }
@@ -68,9 +71,9 @@ class Braintree_ClientTokenGateway
68
  public function conditionallyVerifyKeys($params)
69
  {
70
  if (array_key_exists("customerId", $params)) {
71
- Braintree_Util::verifyKeys($this->generateWithCustomerIdSignature(), $params);
72
  } else {
73
- Braintree_Util::verifyKeys($this->generateWithoutCustomerIdSignature(), $params);
74
  }
75
  }
76
 
@@ -80,10 +83,10 @@ class Braintree_ClientTokenGateway
80
  */
81
  public function generateWithCustomerIdSignature()
82
  {
83
- return array(
84
  "version", "customerId", "proxyMerchantId",
85
- array("options" => array("makeDefault", "verifyCard", "failOnDuplicatePaymentMethod")),
86
- "merchantAccountId", "sepaMandateType", "sepaMandateAcceptanceLocation");
87
  }
88
 
89
  /**
@@ -92,7 +95,7 @@ class Braintree_ClientTokenGateway
92
  */
93
  public function generateWithoutCustomerIdSignature()
94
  {
95
- return array("version", "proxyMerchantId", "merchantAccountId");
96
  }
97
 
98
  /**
@@ -116,10 +119,11 @@ class Braintree_ClientTokenGateway
116
  $response['apiErrorResponse']['message']
117
  );
118
  } else {
119
- throw new Braintree_Exception_Unexpected(
120
  "Expected clientToken or apiErrorResponse"
121
  );
122
  }
123
  }
124
 
125
  }
 
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
  }
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
 
83
  */
84
  public function generateWithCustomerIdSignature()
85
  {
86
+ return [
87
  "version", "customerId", "proxyMerchantId",
88
+ ["options" => ["makeDefault", "verifyCard", "failOnDuplicatePaymentMethod"]],
89
+ "merchantAccountId", "sepaMandateType", "sepaMandateAcceptanceLocation"];
90
  }
91
 
92
  /**
95
  */
96
  public function generateWithoutCustomerIdSignature()
97
  {
98
+ return ["version", "proxyMerchantId", "merchantAccountId"];
99
  }
100
 
101
  /**
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');
braintree_sdk/lib/Braintree/CoinbaseAccount.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
 
 
2
  /**
3
  * Braintree CoinbaseAccount module
4
  *
5
  * @package Braintree
6
  * @category Resources
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -15,21 +17,22 @@
15
  *
16
  * @package Braintree
17
  * @category Resources
18
- * @copyright 2014 Braintree, a division of PayPal, Inc.
19
  *
 
20
  * @property-read string $token
21
  * @property-read string $userId
22
  * @property-read string $userName
23
  * @property-read string $userEmail
24
  */
25
- class Braintree_CoinbaseAccount extends Braintree_Base
26
  {
27
  /**
28
- * factory method: returns an instance of Braintree_CoinbaseAccount
29
  * to the requesting method, with populated properties
30
  *
31
  * @ignore
32
- * @return object instance of Braintree_CoinbaseAccount
33
  */
34
  public static function factory($attributes)
35
  {
@@ -55,17 +58,17 @@ class Braintree_CoinbaseAccount extends Braintree_Base
55
  *
56
  * @access protected
57
  * @param array $coinbaseAccountAttribs array of coinbaseAccount data
58
- * @return none
59
  */
60
  protected function _initialize($coinbaseAccountAttribs)
61
  {
62
  // set the attributes
63
  $this->_attributes = $coinbaseAccountAttribs;
64
 
65
- $subscriptionArray = array();
66
  if (isset($coinbaseAccountAttribs['subscriptions'])) {
67
  foreach ($coinbaseAccountAttribs['subscriptions'] AS $subscription) {
68
- $subscriptionArray[] = Braintree_Subscription::factory($subscription);
69
  }
70
  }
71
 
@@ -80,7 +83,7 @@ class Braintree_CoinbaseAccount extends Braintree_Base
80
  public function __toString()
81
  {
82
  return __CLASS__ . '[' .
83
- Braintree_Util::attributesToString($this->_attributes) .']';
84
  }
85
 
86
 
@@ -88,21 +91,22 @@ class Braintree_CoinbaseAccount extends Braintree_Base
88
 
89
  public static function find($token)
90
  {
91
- return Braintree_Configuration::gateway()->coinbaseAccount()->find($token);
92
  }
93
 
94
  public static function update($token, $attributes)
95
  {
96
- return Braintree_Configuration::gateway()->coinbaseAccount()->update($token, $attributes);
97
  }
98
 
99
  public static function delete($token)
100
  {
101
- return Braintree_Configuration::gateway()->coinbaseAccount()->delete($token);
102
  }
103
 
104
  public static function sale($token, $transactionAttribs)
105
  {
106
- return Braintree_Configuration::gateway()->coinbaseAccount()->sale($token, $transactionAttribs);
107
  }
108
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree CoinbaseAccount module
6
  *
7
  * @package Braintree
8
  * @category Resources
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
 
12
  /**
17
  *
18
  * @package Braintree
19
  * @category Resources
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  *
22
+ * @property-read string $customerId
23
  * @property-read string $token
24
  * @property-read string $userId
25
  * @property-read string $userName
26
  * @property-read string $userEmail
27
  */
28
+ class CoinbaseAccount extends Base
29
  {
30
  /**
31
+ * factory method: returns an instance of CoinbaseAccount
32
  * to the requesting method, with populated properties
33
  *
34
  * @ignore
35
+ * @return CoinbaseAccount
36
  */
37
  public static function factory($attributes)
38
  {
58
  *
59
  * @access protected
60
  * @param array $coinbaseAccountAttribs array of coinbaseAccount data
61
+ * @return void
62
  */
63
  protected function _initialize($coinbaseAccountAttribs)
64
  {
65
  // set the attributes
66
  $this->_attributes = $coinbaseAccountAttribs;
67
 
68
+ $subscriptionArray = [];
69
  if (isset($coinbaseAccountAttribs['subscriptions'])) {
70
  foreach ($coinbaseAccountAttribs['subscriptions'] AS $subscription) {
71
+ $subscriptionArray[] = Subscription::factory($subscription);
72
  }
73
  }
74
 
83
  public function __toString()
84
  {
85
  return __CLASS__ . '[' .
86
+ Util::attributesToString($this->_attributes) .']';
87
  }
88
 
89
 
91
 
92
  public static function find($token)
93
  {
94
+ return Configuration::gateway()->coinbaseAccount()->find($token);
95
  }
96
 
97
  public static function update($token, $attributes)
98
  {
99
+ return Configuration::gateway()->coinbaseAccount()->update($token, $attributes);
100
  }
101
 
102
  public static function delete($token)
103
  {
104
+ return Configuration::gateway()->coinbaseAccount()->delete($token);
105
  }
106
 
107
  public static function sale($token, $transactionAttribs)
108
  {
109
+ return Configuration::gateway()->coinbaseAccount()->sale($token, $transactionAttribs);
110
  }
111
  }
112
+ class_alias('Braintree\CoinbaseAccount', 'Braintree_CoinbaseAccount');
braintree_sdk/lib/Braintree/Collection.php CHANGED
@@ -1,4 +1,12 @@
1
  <?php
 
 
 
 
 
 
 
 
2
  /**
3
  * Braintree Generic collection
4
  *
@@ -9,16 +17,16 @@
9
  *
10
  * @package Braintree
11
  * @subpackage Utility
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  */
14
 
15
- class Braintree_Collection implements Countable, IteratorAggregate, ArrayAccess
16
  {
17
  /**
18
  *
19
- * @var array $_collection collection storage
20
  */
21
- protected $_collection = array();
22
 
23
  /**
24
  * Add a value into the collection
@@ -151,3 +159,4 @@ class Braintree_Collection implements Countable, IteratorAggregate, ArrayAccess
151
  }
152
 
153
  }
 
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
  *
17
  *
18
  * @package Braintree
19
  * @subpackage Utility
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  */
22
 
23
+ class Collection implements Countable, IteratorAggregate, ArrayAccess
24
  {
25
  /**
26
  *
27
+ * @var array collection storage
28
  */
29
+ protected $_collection = [];
30
 
31
  /**
32
  * Add a value into the collection
159
  }
160
 
161
  }
162
+ class_alias('Braintree\Collection', 'Braintree_Collection');
braintree_sdk/lib/Braintree/Configuration.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
 
2
  /**
3
  *
4
  * Configuration registry
5
  *
6
  * @package Braintree
7
  * @subpackage Utility
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  */
10
 
11
- class Braintree_Configuration
12
  {
13
  public static $global;
14
 
@@ -19,6 +21,9 @@ class Braintree_Configuration
19
  private $_clientId = null;
20
  private $_clientSecret = null;
21
  private $_accessToken = null;
 
 
 
22
 
23
  /**
24
  * Braintree API version to use
@@ -26,11 +31,11 @@ class Braintree_Configuration
26
  */
27
  const API_VERSION = 4;
28
 
29
- public function __construct($attribs = array())
30
  {
31
  foreach ($attribs as $kind => $value) {
32
  if ($kind == 'environment') {
33
- Braintree_CredentialsParser::assertValidEnvironment($value);
34
  $this->_environment = $value;
35
  }
36
  if ($kind == 'merchantId') {
@@ -46,9 +51,9 @@ class Braintree_Configuration
46
 
47
  if (isset($attribs['clientId']) || isset($attribs['accessToken'])) {
48
  if (isset($attribs['environment']) || isset($attribs['merchantId']) || isset($attribs['publicKey']) || isset($attribs['privateKey'])) {
49
- throw new Braintree_Exception_Configuration('Cannot mix OAuth credentials (clientId, clientSecret, accessToken) with key credentials (publicKey, privateKey, environment, merchantId).');
50
  }
51
- $parsedCredentials = new Braintree_CredentialsParser($attribs);
52
 
53
  $this->_environment = $parsedCredentials->getEnvironment();
54
  $this->_merchantId = $parsedCredentials->getMerchantId();
@@ -64,12 +69,12 @@ class Braintree_Configuration
64
  */
65
  public static function reset()
66
  {
67
- self::$global = new Braintree_Configuration();
68
  }
69
 
70
  public static function gateway()
71
  {
72
- return new Braintree_Gateway(self::$global);
73
  }
74
 
75
  public static function environment($value=null)
@@ -77,7 +82,7 @@ class Braintree_Configuration
77
  if (empty($value)) {
78
  return self::$global->getEnvironment();
79
  }
80
- Braintree_CredentialsParser::assertValidEnvironment($value);
81
  self::$global->setEnvironment($value);
82
  }
83
 
@@ -105,6 +110,61 @@ class Braintree_Configuration
105
  self::$global->setPrivateKey($value);
106
  }
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  public static function assertGlobalHasAccessTokenOrKeys()
109
  {
110
  self::$global->assertHasAccessTokenOrKeys();
@@ -114,13 +174,13 @@ class Braintree_Configuration
114
  {
115
  if (empty($this->_accessToken)) {
116
  if (empty($this->_merchantId)) {
117
- throw new Braintree_Exception_Configuration('Braintree_Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree_Gateway).');
118
  } else if (empty($this->_environment)) {
119
- throw new Braintree_Exception_Configuration('Braintree_Configuration::environment needs to be set.');
120
  } else if (empty($this->_publicKey)) {
121
- throw new Braintree_Exception_Configuration('Braintree_Configuration::publicKey needs to be set.');
122
  } else if (empty($this->_privateKey)) {
123
- throw new Braintree_Exception_Configuration('Braintree_Configuration::privateKey needs to be set.');
124
  }
125
  }
126
  }
@@ -134,14 +194,14 @@ class Braintree_Configuration
134
  public function assertHasClientId()
135
  {
136
  if (empty($this->_clientId)) {
137
- throw new Braintree_Exception_Configuration('clientId needs to be passed to Braintree_Gateway.');
138
  }
139
  }
140
 
141
  public function assertHasClientSecret()
142
  {
143
  if (empty($this->_clientSecret)) {
144
- throw new Braintree_Exception_Configuration('clientSecret needs to be passed to Braintree_Gateway.');
145
  }
146
  }
147
 
@@ -207,6 +267,36 @@ class Braintree_Configuration
207
  $this->_privateKey = $value;
208
  }
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  public function getAccessToken()
211
  {
212
  return $this->_accessToken;
@@ -242,7 +332,7 @@ class Braintree_Configuration
242
  */
243
  public function merchantPath()
244
  {
245
- return '/merchants/'.$this->_merchantId;
246
  }
247
 
248
  /**
@@ -256,15 +346,11 @@ class Braintree_Configuration
256
  {
257
  $sslPath = $sslPath ? $sslPath : DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR .
258
  'ssl' . DIRECTORY_SEPARATOR;
259
-
260
- $caPath = realpath(
261
- dirname(__FILE__) .
262
- $sslPath . 'api_braintreegateway_com.ca.crt'
263
- );
264
 
265
  if (!file_exists($caPath))
266
  {
267
- throw new Braintree_Exception_SSLCaFileNotFound();
268
  }
269
 
270
  return $caPath;
@@ -385,4 +471,5 @@ class Braintree_Configuration
385
  error_log('[Braintree] ' . $message);
386
  }
387
  }
388
- Braintree_Configuration::reset();
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  *
6
  * Configuration registry
7
  *
8
  * @package Braintree
9
  * @subpackage Utility
10
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
11
  */
12
 
13
+ class Configuration
14
  {
15
  public static $global;
16
 
21
  private $_clientId = null;
22
  private $_clientSecret = null;
23
  private $_accessToken = null;
24
+ private $_proxyHost = null;
25
+ private $_proxyPort = null;
26
+ private $_proxyType = null;
27
 
28
  /**
29
  * Braintree API version to use
31
  */
32
  const API_VERSION = 4;
33
 
34
+ public function __construct($attribs = [])
35
  {
36
  foreach ($attribs as $kind => $value) {
37
  if ($kind == 'environment') {
38
+ CredentialsParser::assertValidEnvironment($value);
39
  $this->_environment = $value;
40
  }
41
  if ($kind == 'merchantId') {
51
 
52
  if (isset($attribs['clientId']) || isset($attribs['accessToken'])) {
53
  if (isset($attribs['environment']) || isset($attribs['merchantId']) || isset($attribs['publicKey']) || isset($attribs['privateKey'])) {
54
+ throw new Exception\Configuration('Cannot mix OAuth credentials (clientId, clientSecret, accessToken) with key credentials (publicKey, privateKey, environment, merchantId).');
55
  }
56
+ $parsedCredentials = new CredentialsParser($attribs);
57
 
58
  $this->_environment = $parsedCredentials->getEnvironment();
59
  $this->_merchantId = $parsedCredentials->getMerchantId();
69
  */
70
  public static function reset()
71
  {
72
+ self::$global = new Configuration();
73
  }
74
 
75
  public static function gateway()
76
  {
77
+ return new Gateway(self::$global);
78
  }
79
 
80
  public static function environment($value=null)
82
  if (empty($value)) {
83
  return self::$global->getEnvironment();
84
  }
85
+ CredentialsParser::assertValidEnvironment($value);
86
  self::$global->setEnvironment($value);
87
  }
88
 
110
  self::$global->setPrivateKey($value);
111
  }
112
 
113
+ /**
114
+ * Sets or gets the proxy host to use for connecting to Braintree
115
+ *
116
+ * @param string $value If provided, sets the proxy host
117
+ * @return string The proxy host used for connecting to Braintree
118
+ */
119
+ public static function proxyHost($value = null)
120
+ {
121
+ if (empty($value)) {
122
+ return self::$global->getProxyHost();
123
+ }
124
+ self::$global->setProxyHost($value);
125
+ }
126
+
127
+ /**
128
+ * Sets or gets the port of the proxy to use for connecting to Braintree
129
+ *
130
+ * @param string $value If provided, sets the port of the proxy
131
+ * @return string The port of the proxy used for connecting to Braintree
132
+ */
133
+ public static function proxyPort($value = null)
134
+ {
135
+ if (empty($value)) {
136
+ return self::$global->getProxyPort();
137
+ }
138
+ self::$global->setProxyPort($value);
139
+ }
140
+
141
+ /**
142
+ * Sets or gets the proxy type to use for connecting to Braintree. This value
143
+ * can be any of the CURLOPT_PROXYTYPE options in PHP cURL.
144
+ *
145
+ * @param string $value If provided, sets the proxy type
146
+ * @return string The proxy type used for connecting to Braintree
147
+ */
148
+ public static function proxyType($value = null)
149
+ {
150
+ if (empty($value)) {
151
+ return self::$global->getProxyType();
152
+ }
153
+ self::$global->setProxyType($value);
154
+ }
155
+
156
+ /**
157
+ * Specifies whether or not a proxy is properly configured
158
+ *
159
+ * @return bool true if a proxy is configured properly, false if not
160
+ */
161
+ public static function isUsingProxy()
162
+ {
163
+ $proxyHost = self::$global->getProxyHost();
164
+ $proxyPort = self::$global->getProxyPort();
165
+ return !empty($proxyHost) && !empty($proxyPort);
166
+ }
167
+
168
  public static function assertGlobalHasAccessTokenOrKeys()
169
  {
170
  self::$global->assertHasAccessTokenOrKeys();
174
  {
175
  if (empty($this->_accessToken)) {
176
  if (empty($this->_merchantId)) {
177
+ throw new Exception\Configuration('Braintree\\Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree\\Gateway).');
178
  } else if (empty($this->_environment)) {
179
+ throw new Exception\Configuration('Braintree\\Configuration::environment needs to be set.');
180
  } else if (empty($this->_publicKey)) {
181
+ throw new Exception\Configuration('Braintree\\Configuration::publicKey needs to be set.');
182
  } else if (empty($this->_privateKey)) {
183
+ throw new Exception\Configuration('Braintree\\Configuration::privateKey needs to be set.');
184
  }
185
  }
186
  }
194
  public function assertHasClientId()
195
  {
196
  if (empty($this->_clientId)) {
197
+ throw new Exception\Configuration('clientId needs to be passed to Braintree\\Gateway.');
198
  }
199
  }
200
 
201
  public function assertHasClientSecret()
202
  {
203
  if (empty($this->_clientSecret)) {
204
+ throw new Exception\Configuration('clientSecret needs to be passed to Braintree\\Gateway.');
205
  }
206
  }
207
 
267
  $this->_privateKey = $value;
268
  }
269
 
270
+ private function setProxyHost($value)
271
+ {
272
+ $this->_proxyHost = $value;
273
+ }
274
+
275
+ public function getProxyHost()
276
+ {
277
+ return $this->_proxyHost;
278
+ }
279
+
280
+ private function setProxyPort($value)
281
+ {
282
+ $this->_proxyPort = $value;
283
+ }
284
+
285
+ public function getProxyPort()
286
+ {
287
+ return $this->_proxyPort;
288
+ }
289
+
290
+ private function setProxyType($value)
291
+ {
292
+ $this->_proxyType = $value;
293
+ }
294
+
295
+ public function getProxyType()
296
+ {
297
+ return $this->_proxyType;
298
+ }
299
+
300
  public function getAccessToken()
301
  {
302
  return $this->_accessToken;
332
  */
333
  public function merchantPath()
334
  {
335
+ return '/merchants/' . $this->_merchantId;
336
  }
337
 
338
  /**
346
  {
347
  $sslPath = $sslPath ? $sslPath : DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR .
348
  'ssl' . DIRECTORY_SEPARATOR;
349
+ $caPath = __DIR__ . $sslPath . 'api_braintreegateway_com.ca.crt';
 
 
 
 
350
 
351
  if (!file_exists($caPath))
352
  {
353
+ throw new Exception\SSLCaFileNotFound();
354
  }
355
 
356
  return $caPath;
471
  error_log('[Braintree] ' . $message);
472
  }
473
  }
474
+ Configuration::reset();
475
+ class_alias('Braintree\Configuration', 'Braintree_Configuration');
braintree_sdk/lib/Braintree/CredentialsParser.php CHANGED
@@ -1,14 +1,16 @@
1
  <?php
 
 
2
  /**
3
  *
4
  * CredentialsParser registry
5
  *
6
  * @package Braintree
7
  * @subpackage Utility
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  */
10
 
11
- class Braintree_CredentialsParser
12
  {
13
  private $_clientId;
14
  private $_clientSecret;
@@ -38,32 +40,32 @@ class Braintree_CredentialsParser
38
  * @static
39
  * @var array valid environments, used for validation
40
  */
41
- private static $_validEnvironments = array(
42
  'development',
43
  'integration',
44
  'sandbox',
45
  'production',
46
  'qa',
47
- );
48
 
49
 
50
  public function parse()
51
  {
52
- $environments = array();
53
  if (!empty($this->_clientId)) {
54
- $environments[] = array('clientId', $this->_parseClientCredential('clientId', $this->_clientId, 'client_id'));
55
  }
56
  if (!empty($this->_clientSecret)) {
57
- $environments[] = array('clientSecret', $this->_parseClientCredential('clientSecret', $this->_clientSecret, 'client_secret'));
58
  }
59
  if (!empty($this->_accessToken)) {
60
- $environments[] = array('accessToken', $this->_parseAccessToken());
61
  }
62
 
63
  $checkEnv = $environments[0];
64
  foreach ($environments as $env) {
65
  if ($env[1] !== $checkEnv[1]) {
66
- throw new Braintree_Exception_Configuration(
67
  'Mismatched credential environments: ' . $checkEnv[0] . ' environment is ' . $checkEnv[1] .
68
  ' and ' . $env[0] . ' environment is ' . $env[1]);
69
  }
@@ -75,7 +77,7 @@ class Braintree_CredentialsParser
75
 
76
  public static function assertValidEnvironment($environment) {
77
  if (!in_array($environment, self::$_validEnvironments)) {
78
- throw new Braintree_Exception_Configuration('"' .
79
  $environment . '" is not a valid environment.');
80
  }
81
  }
@@ -84,7 +86,7 @@ class Braintree_CredentialsParser
84
  {
85
  $explodedCredential = explode('$', $value);
86
  if (sizeof($explodedCredential) != 3) {
87
- throw new Braintree_Exception_Configuration('Incorrect ' . $credentialType . ' format. Expected: type$environment$token');
88
  }
89
 
90
  $gotValuePrefix = $explodedCredential[0];
@@ -92,7 +94,7 @@ class Braintree_CredentialsParser
92
  $token = $explodedCredential[2];
93
 
94
  if ($gotValuePrefix != $expectedValuePrefix) {
95
- throw new Braintree_Exception_Configuration('Value passed for ' . $credentialType . ' is not a ' . $credentialType);
96
  }
97
 
98
  return $environment;
@@ -102,7 +104,7 @@ class Braintree_CredentialsParser
102
  {
103
  $accessTokenExploded = explode('$', $this->_accessToken);
104
  if (sizeof($accessTokenExploded) != 4) {
105
- throw new Braintree_Exception_Configuration('Incorrect accessToken syntax. Expected: type$environment$merchant_id$token');
106
  }
107
 
108
  $gotValuePrefix = $accessTokenExploded[0];
@@ -111,7 +113,7 @@ class Braintree_CredentialsParser
111
  $token = $accessTokenExploded[3];
112
 
113
  if ($gotValuePrefix != 'access_token') {
114
- throw new Braintree_Exception_Configuration('Value passed for accessToken is not an accessToken');
115
  }
116
 
117
  $this->_merchantId = $merchantId;
@@ -143,3 +145,4 @@ class Braintree_CredentialsParser
143
  return $this->_merchantId;
144
  }
145
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  *
6
  * CredentialsParser registry
7
  *
8
  * @package Braintree
9
  * @subpackage Utility
10
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
11
  */
12
 
13
+ class CredentialsParser
14
  {
15
  private $_clientId;
16
  private $_clientSecret;
40
  * @static
41
  * @var array valid environments, used for validation
42
  */
43
+ private static $_validEnvironments = [
44
  'development',
45
  'integration',
46
  'sandbox',
47
  'production',
48
  'qa',
49
+ ];
50
 
51
 
52
  public function parse()
53
  {
54
+ $environments = [];
55
  if (!empty($this->_clientId)) {
56
+ $environments[] = ['clientId', $this->_parseClientCredential('clientId', $this->_clientId, 'client_id')];
57
  }
58
  if (!empty($this->_clientSecret)) {
59
+ $environments[] = ['clientSecret', $this->_parseClientCredential('clientSecret', $this->_clientSecret, 'client_secret')];
60
  }
61
  if (!empty($this->_accessToken)) {
62
+ $environments[] = ['accessToken', $this->_parseAccessToken()];
63
  }
64
 
65
  $checkEnv = $environments[0];
66
  foreach ($environments as $env) {
67
  if ($env[1] !== $checkEnv[1]) {
68
+ throw new Exception\Configuration(
69
  'Mismatched credential environments: ' . $checkEnv[0] . ' environment is ' . $checkEnv[1] .
70
  ' and ' . $env[0] . ' environment is ' . $env[1]);
71
  }
77
 
78
  public static function assertValidEnvironment($environment) {
79
  if (!in_array($environment, self::$_validEnvironments)) {
80
+ throw new Exception\Configuration('"' .
81
  $environment . '" is not a valid environment.');
82
  }
83
  }
86
  {
87
  $explodedCredential = explode('$', $value);
88
  if (sizeof($explodedCredential) != 3) {
89
+ throw new Exception\Configuration('Incorrect ' . $credentialType . ' format. Expected: type$environment$token');
90
  }
91
 
92
  $gotValuePrefix = $explodedCredential[0];
94
  $token = $explodedCredential[2];
95
 
96
  if ($gotValuePrefix != $expectedValuePrefix) {
97
+ throw new Exception\Configuration('Value passed for ' . $credentialType . ' is not a ' . $credentialType);
98
  }
99
 
100
  return $environment;
104
  {
105
  $accessTokenExploded = explode('$', $this->_accessToken);
106
  if (sizeof($accessTokenExploded) != 4) {
107
+ throw new Exception\Configuration('Incorrect accessToken syntax. Expected: type$environment$merchant_id$token');
108
  }
109
 
110
  $gotValuePrefix = $accessTokenExploded[0];
113
  $token = $accessTokenExploded[3];
114
 
115
  if ($gotValuePrefix != 'access_token') {
116
+ throw new Exception\Configuration('Value passed for accessToken is not an accessToken');
117
  }
118
 
119
  $this->_merchantId = $merchantId;
145
  return $this->_merchantId;
146
  }
147
  }
148
+ class_alias('Braintree\CredentialsParser', 'Braintree_CredentialsParser');
braintree_sdk/lib/Braintree/CreditCard.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  /**
3
  * Braintree CreditCard module
4
  * Creates and manages Braintree CreditCards
@@ -10,7 +12,7 @@
10
  *
11
  * @package Braintree
12
  * @category Resources
13
- * @copyright 2014 Braintree, a division of PayPal, Inc.
14
  *
15
  * @property-read string $billingAddress
16
  * @property-read string $bin
@@ -27,7 +29,7 @@
27
  * @property-read string $token
28
  * @property-read string $updatedAt
29
  */
30
- class Braintree_CreditCard extends Braintree_Base
31
  {
32
  // Card Type
33
  const AMEX = 'American Express';
@@ -111,7 +113,7 @@ class Braintree_CreditCard extends Braintree_Base
111
  *
112
  * @access protected
113
  * @param array $creditCardAttribs array of creditcard data
114
- * @return none
115
  */
116
  protected function _initialize($creditCardAttribs)
117
  {
@@ -120,13 +122,13 @@ class Braintree_CreditCard extends Braintree_Base
120
 
121
  // map each address into its own object
122
  $billingAddress = isset($creditCardAttribs['billingAddress']) ?
123
- Braintree_Address::factory($creditCardAttribs['billingAddress']) :
124
  null;
125
 
126
- $subscriptionArray = array();
127
  if (isset($creditCardAttribs['subscriptions'])) {
128
  foreach ($creditCardAttribs['subscriptions'] AS $subscription) {
129
- $subscriptionArray[] = Braintree_Subscription::factory($subscription);
130
  }
131
  }
132
 
@@ -137,9 +139,9 @@ class Braintree_CreditCard extends Braintree_Base
137
 
138
  if(isset($creditCardAttribs['verifications']) && count($creditCardAttribs['verifications']) > 0) {
139
  $verifications = $creditCardAttribs['verifications'];
140
- usort($verifications, array($this, '_compareCreatedAtOnVerifications'));
141
 
142
- $this->_set('verification', Braintree_CreditCardVerification::factory($verifications[0]));
143
  }
144
  }
145
 
@@ -149,15 +151,15 @@ class Braintree_CreditCard extends Braintree_Base
149
  }
150
 
151
  /**
152
- * returns false if comparing object is not a Braintree_CreditCard,
153
- * or is a Braintree_CreditCard with a different id
154
  *
155
  * @param object $otherCreditCard customer to compare against
156
  * @return boolean
157
  */
158
  public function isEqual($otherCreditCard)
159
  {
160
- return !($otherCreditCard instanceof Braintree_CreditCard) ? false : $this->token === $otherCreditCard->token;
161
  }
162
 
163
  /**
@@ -168,24 +170,24 @@ class Braintree_CreditCard extends Braintree_Base
168
  public function __toString()
169
  {
170
  return __CLASS__ . '[' .
171
- Braintree_Util::attributesToString($this->_attributes) .']';
172
  }
173
 
174
  /**
175
- * factory method: returns an instance of Braintree_CreditCard
176
  * to the requesting method, with populated properties
177
  *
178
  * @ignore
179
- * @return object instance of Braintree_CreditCard
180
  */
181
  public static function factory($attributes)
182
  {
183
- $defaultAttributes = array(
184
  'bin' => '',
185
  'expirationMonth' => '',
186
  'expirationYear' => '',
187
  'last4' => '',
188
- );
189
 
190
  $instance = new self();
191
  $instance->_initialize(array_merge($defaultAttributes, $attributes));
@@ -197,115 +199,117 @@ class Braintree_CreditCard extends Braintree_Base
197
 
198
  public static function create($attribs)
199
  {
200
- return Braintree_Configuration::gateway()->creditCard()->create($attribs);
201
  }
202
 
203
  public static function createNoValidate($attribs)
204
  {
205
- return Braintree_Configuration::gateway()->creditCard()->createNoValidate($attribs);
206
  }
207
 
208
  public static function createFromTransparentRedirect($queryString)
209
  {
210
- return Braintree_Configuration::gateway()->creditCard()->createFromTransparentRedirect($queryString);
211
  }
212
 
213
  public static function createCreditCardUrl()
214
  {
215
- return Braintree_Configuration::gateway()->creditCard()->createCreditCardUrl();
216
  }
217
 
218
  public static function expired()
219
  {
220
- return Braintree_Configuration::gateway()->creditCard()->expired();
221
  }
222
 
223
  public static function fetchExpired($ids)
224
  {
225
- return Braintree_Configuration::gateway()->creditCard()->fetchExpired($ids);
226
  }
227
 
228
  public static function expiringBetween($startDate, $endDate)
229
  {
230
- return Braintree_Configuration::gateway()->creditCard()->expiringBetween($startDate, $endDate);
231
  }
232
 
233
  public static function fetchExpiring($startDate, $endDate, $ids)
234
  {
235
- return Braintree_Configuration::gateway()->creditCard()->fetchExpiring($startDate, $endDate, $ids);
236
  }
237
 
238
  public static function find($token)
239
  {
240
- return Braintree_Configuration::gateway()->creditCard()->find($token);
241
  }
242
 
243
  public static function fromNonce($nonce)
244
  {
245
- return Braintree_Configuration::gateway()->creditCard()->fromNonce($nonce);
246
  }
247
 
248
  public static function credit($token, $transactionAttribs)
249
  {
250
- return Braintree_Configuration::gateway()->creditCard()->credit($token, $transactionAttribs);
251
  }
252
 
253
  public static function creditNoValidate($token, $transactionAttribs)
254
  {
255
- return Braintree_Configuration::gateway()->creditCard()->creditNoValidate($token, $transactionAttribs);
256
  }
257
 
258
  public static function sale($token, $transactionAttribs)
259
  {
260
- return Braintree_Configuration::gateway()->creditCard()->sale($token, $transactionAttribs);
261
  }
262
 
263
  public static function saleNoValidate($token, $transactionAttribs)
264
  {
265
- return Braintree_Configuration::gateway()->creditCard()->saleNoValidate($token, $transactionAttribs);
266
  }
267
 
268
  public static function update($token, $attributes)
269
  {
270
- return Braintree_Configuration::gateway()->creditCard()->update($token, $attributes);
271
  }
272
 
273
  public static function updateNoValidate($token, $attributes)
274
  {
275
- return Braintree_Configuration::gateway()->creditCard()->updateNoValidate($token, $attributes);
276
  }
277
 
278
  public static function updateCreditCardUrl()
279
  {
280
- return Braintree_Configuration::gateway()->creditCard()->updateCreditCardUrl();
281
  }
282
 
283
  public static function updateFromTransparentRedirect($queryString)
284
  {
285
- return Braintree_Configuration::gateway()->creditCard()->updateFromTransparentRedirect($queryString);
286
  }
287
 
288
  public static function delete($token)
289
  {
290
- return Braintree_Configuration::gateway()->creditCard()->delete($token);
291
  }
292
 
 
293
  public static function allCardTypes()
294
  {
295
- return array(
296
- Braintree_CreditCard::AMEX,
297
- Braintree_CreditCard::CARTE_BLANCHE,
298
- Braintree_CreditCard::CHINA_UNION_PAY,
299
- Braintree_CreditCard::DINERS_CLUB_INTERNATIONAL,
300
- Braintree_CreditCard::DISCOVER,
301
- Braintree_CreditCard::JCB,
302
- Braintree_CreditCard::LASER,
303
- Braintree_CreditCard::MAESTRO,
304
- Braintree_CreditCard::MASTER_CARD,
305
- Braintree_CreditCard::SOLO,
306
- Braintree_CreditCard::SWITCH_TYPE,
307
- Braintree_CreditCard::VISA,
308
- Braintree_CreditCard::UNKNOWN
309
- );
310
  }
311
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree CreditCard module
6
  * Creates and manages Braintree CreditCards
12
  *
13
  * @package Braintree
14
  * @category Resources
15
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
16
  *
17
  * @property-read string $billingAddress
18
  * @property-read string $bin
29
  * @property-read string $token
30
  * @property-read string $updatedAt
31
  */
32
+ class CreditCard extends Base
33
  {
34
  // Card Type
35
  const AMEX = 'American Express';
113
  *
114
  * @access protected
115
  * @param array $creditCardAttribs array of creditcard data
116
+ * @return void
117
  */
118
  protected function _initialize($creditCardAttribs)
119
  {
122
 
123
  // map each address into its own object
124
  $billingAddress = isset($creditCardAttribs['billingAddress']) ?
125
+ Address::factory($creditCardAttribs['billingAddress']) :
126
  null;
127
 
128
+ $subscriptionArray = [];
129
  if (isset($creditCardAttribs['subscriptions'])) {
130
  foreach ($creditCardAttribs['subscriptions'] AS $subscription) {
131
+ $subscriptionArray[] = Subscription::factory($subscription);
132
  }
133
  }
134
 
139
 
140
  if(isset($creditCardAttribs['verifications']) && count($creditCardAttribs['verifications']) > 0) {
141
  $verifications = $creditCardAttribs['verifications'];
142
+ usort($verifications, [$this, '_compareCreatedAtOnVerifications']);
143
 
144
+ $this->_set('verification', CreditCardVerification::factory($verifications[0]));
145
  }
146
  }
147
 
151
  }
152
 
153
  /**
154
+ * returns false if comparing object is not a CreditCard,
155
+ * or is a CreditCard with a different id
156
  *
157
  * @param object $otherCreditCard customer to compare against
158
  * @return boolean
159
  */
160
  public function isEqual($otherCreditCard)
161
  {
162
+ return !($otherCreditCard instanceof self) ? false : $this->token === $otherCreditCard->token;
163
  }
164
 
165
  /**
170
  public function __toString()
171
  {
172
  return __CLASS__ . '[' .
173
+ Util::attributesToString($this->_attributes) .']';
174
  }
175
 
176
  /**
177
+ * factory method: returns an instance of CreditCard
178
  * to the requesting method, with populated properties
179
  *
180
  * @ignore
181
+ * @return CreditCard
182
  */
183
  public static function factory($attributes)
184
  {
185
+ $defaultAttributes = [
186
  'bin' => '',
187
  'expirationMonth' => '',
188
  'expirationYear' => '',
189
  'last4' => '',
190
+ ];
191
 
192
  $instance = new self();
193
  $instance->_initialize(array_merge($defaultAttributes, $attributes));
199
 
200
  public static function create($attribs)
201
  {
202
+ return Configuration::gateway()->creditCard()->create($attribs);
203
  }
204
 
205
  public static function createNoValidate($attribs)
206
  {
207
+ return Configuration::gateway()->creditCard()->createNoValidate($attribs);
208
  }
209
 
210
  public static function createFromTransparentRedirect($queryString)
211
  {
212
+ return Configuration::gateway()->creditCard()->createFromTransparentRedirect($queryString);
213
  }
214
 
215
  public static function createCreditCardUrl()
216
  {
217
+ return Configuration::gateway()->creditCard()->createCreditCardUrl();
218
  }
219
 
220
  public static function expired()
221
  {
222
+ return Configuration::gateway()->creditCard()->expired();
223
  }
224
 
225
  public static function fetchExpired($ids)
226
  {
227
+ return Configuration::gateway()->creditCard()->fetchExpired($ids);
228
  }
229
 
230
  public static function expiringBetween($startDate, $endDate)
231
  {
232
+ return Configuration::gateway()->creditCard()->expiringBetween($startDate, $endDate);
233
  }
234
 
235
  public static function fetchExpiring($startDate, $endDate, $ids)
236
  {
237
+ return Configuration::gateway()->creditCard()->fetchExpiring($startDate, $endDate, $ids);
238
  }
239
 
240
  public static function find($token)
241
  {
242
+ return Configuration::gateway()->creditCard()->find($token);
243
  }
244
 
245
  public static function fromNonce($nonce)
246
  {
247
+ return Configuration::gateway()->creditCard()->fromNonce($nonce);
248
  }
249
 
250
  public static function credit($token, $transactionAttribs)
251
  {
252
+ return Configuration::gateway()->creditCard()->credit($token, $transactionAttribs);
253
  }
254
 
255
  public static function creditNoValidate($token, $transactionAttribs)
256
  {
257
+ return Configuration::gateway()->creditCard()->creditNoValidate($token, $transactionAttribs);
258
  }
259
 
260
  public static function sale($token, $transactionAttribs)
261
  {
262
+ return Configuration::gateway()->creditCard()->sale($token, $transactionAttribs);
263
  }
264
 
265
  public static function saleNoValidate($token, $transactionAttribs)
266
  {
267
+ return Configuration::gateway()->creditCard()->saleNoValidate($token, $transactionAttribs);
268
  }
269
 
270
  public static function update($token, $attributes)
271
  {
272
+ return Configuration::gateway()->creditCard()->update($token, $attributes);
273
  }
274
 
275
  public static function updateNoValidate($token, $attributes)
276
  {
277
+ return Configuration::gateway()->creditCard()->updateNoValidate($token, $attributes);
278
  }
279
 
280
  public static function updateCreditCardUrl()
281
  {
282
+ return Configuration::gateway()->creditCard()->updateCreditCardUrl();
283
  }
284
 
285
  public static function updateFromTransparentRedirect($queryString)
286
  {
287
+ return Configuration::gateway()->creditCard()->updateFromTransparentRedirect($queryString);
288
  }
289
 
290
  public static function delete($token)
291
  {
292
+ return Configuration::gateway()->creditCard()->delete($token);
293
  }
294
 
295
+ /** @return array */
296
  public static function allCardTypes()
297
  {
298
+ return [
299
+ CreditCard::AMEX,
300
+ CreditCard::CARTE_BLANCHE,
301
+ CreditCard::CHINA_UNION_PAY,
302
+ CreditCard::DINERS_CLUB_INTERNATIONAL,
303
+ CreditCard::DISCOVER,
304
+ CreditCard::JCB,
305
+ CreditCard::LASER,
306
+ CreditCard::MAESTRO,
307
+ CreditCard::MASTER_CARD,
308
+ CreditCard::SOLO,
309
+ CreditCard::SWITCH_TYPE,
310
+ CreditCard::VISA,
311
+ CreditCard::UNKNOWN
312
+ ];
313
  }
314
  }
315
+ class_alias('Braintree\CreditCard', 'Braintree_CreditCard');
braintree_sdk/lib/Braintree/CreditCardGateway.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Braintree CreditCardGateway module
4
  * Creates and manages Braintree CreditCards
@@ -10,9 +14,9 @@
10
  *
11
  * @package Braintree
12
  * @category Resources
13
- * @copyright 2014 Braintree, a division of PayPal, Inc.
14
  */
15
- class Braintree_CreditCardGateway
16
  {
17
  private $_gateway;
18
  private $_config;
@@ -23,84 +27,86 @@ class Braintree_CreditCardGateway
23
  $this->_gateway = $gateway;
24
  $this->_config = $gateway->config;
25
  $this->_config->assertHasAccessTokenOrKeys();
26
- $this->_http = new Braintree_Http($gateway->config);
27
  }
28
 
29
  public function create($attribs)
30
  {
31
- Braintree_Util::verifyKeys(self::createSignature(), $attribs);
32
- return $this->_doCreate('/payment_methods', array('credit_card' => $attribs));
33
  }
34
 
35
  /**
36
  * attempts the create operation assuming all data will validate
37
- * returns a Braintree_CreditCard object instead of a Result
38
  *
39
  * @access public
40
  * @param array $attribs
41
- * @return object
42
- * @throws Braintree_Exception_ValidationError
43
  */
44
  public function createNoValidate($attribs)
45
  {
46
  $result = $this->create($attribs);
47
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
48
  }
49
  /**
50
  * create a customer from a TransparentRedirect operation
51
  *
 
52
  * @access public
53
  * @param array $attribs
54
- * @return object
55
  */
56
  public function createFromTransparentRedirect($queryString)
57
  {
58
- trigger_error("DEPRECATED: Please use Braintree_TransparentRedirectRequest::confirm", E_USER_NOTICE);
59
- $params = Braintree_TransparentRedirect::parseAndValidateQueryString(
60
  $queryString
61
  );
62
  return $this->_doCreate(
63
  '/payment_methods/all/confirm_transparent_redirect_request',
64
- array('id' => $params['id'])
65
  );
66
  }
67
 
68
  /**
69
  *
 
70
  * @access public
71
  * @param none
72
  * @return string
73
  */
74
  public function createCreditCardUrl()
75
  {
76
- trigger_error("DEPRECATED: Please use Braintree_TransparentRedirectRequest::url", E_USER_NOTICE);
77
- return $this->_config->baseUrl() . $this->_config->merchantPath() .
78
  '/payment_methods/all/create_via_transparent_redirect_request';
79
  }
80
 
81
  /**
82
  * returns a ResourceCollection of expired credit cards
83
- * @return object ResourceCollection
84
  */
85
  public function expired()
86
  {
87
  $path = $this->_config->merchantPath() . '/payment_methods/all/expired_ids';
88
  $response = $this->_http->post($path);
89
- $pager = array(
90
  'object' => $this,
91
  'method' => 'fetchExpired',
92
- 'methodArgs' => array()
93
- );
94
 
95
- return new Braintree_ResourceCollection($response, $pager);
96
  }
97
 
98
  public function fetchExpired($ids)
99
  {
100
  $path = $this->_config->merchantPath() . "/payment_methods/all/expired";
101
- $response = $this->_http->post($path, array('search' => array('ids' => $ids)));
102
 
103
- return Braintree_Util::extractattributeasarray(
104
  $response['paymentMethods'],
105
  'creditCard'
106
  );
@@ -108,27 +114,27 @@ class Braintree_CreditCardGateway
108
  /**
109
  * returns a ResourceCollection of credit cards expiring between start/end
110
  *
111
- * @return object ResourceCollection
112
  */
113
  public function expiringBetween($startDate, $endDate)
114
  {
115
  $queryPath = $this->_config->merchantPath() . '/payment_methods/all/expiring_ids?start=' . date('mY', $startDate) . '&end=' . date('mY', $endDate);
116
  $response = $this->_http->post($queryPath);
117
- $pager = array(
118
  'object' => $this,
119
  'method' => 'fetchExpiring',
120
- 'methodArgs' => array($startDate, $endDate)
121
- );
122
 
123
- return new Braintree_ResourceCollection($response, $pager);
124
  }
125
 
126
  public function fetchExpiring($startDate, $endDate, $ids)
127
  {
128
  $queryPath = $this->_config->merchantPath() . '/payment_methods/all/expiring?start=' . date('mY', $startDate) . '&end=' . date('mY', $endDate);
129
- $response = $this->_http->post($queryPath, array('search' => array('ids' => $ids)));
130
 
131
- return Braintree_Util::extractAttributeAsArray(
132
  $response['paymentMethods'],
133
  'creditCard'
134
  );
@@ -139,8 +145,8 @@ class Braintree_CreditCardGateway
139
  *
140
  * @access public
141
  * @param string $token credit card unique id
142
- * @return object Braintree_CreditCard
143
- * @throws Braintree_Exception_NotFound
144
  */
145
  public function find($token)
146
  {
@@ -148,9 +154,9 @@ class Braintree_CreditCardGateway
148
  try {
149
  $path = $this->_config->merchantPath() . '/payment_methods/credit_card/' . $token;
150
  $response = $this->_http->get($path);
151
- return Braintree_CreditCard::factory($response['creditCard']);
152
- } catch (Braintree_Exception_NotFound $e) {
153
- throw new Braintree_Exception_NotFound(
154
  'credit card with token ' . $token . ' not found'
155
  );
156
  }
@@ -162,8 +168,8 @@ class Braintree_CreditCardGateway
162
  *
163
  * @access public
164
  * @param string $nonce payment method nonce
165
- * @return object Braintree_CreditCard
166
- * @throws Braintree_Exception_NotFound
167
  */
168
  public function fromNonce($nonce)
169
  {
@@ -171,9 +177,9 @@ class Braintree_CreditCardGateway
171
  try {
172
  $path = $this->_config->merchantPath() . '/payment_methods/from_nonce/' . $nonce;
173
  $response = $this->_http->get($path);
174
- return Braintree_CreditCard::factory($response['creditCard']);
175
- } catch (Braintree_Exception_NotFound $e) {
176
- throw new Braintree_Exception_NotFound(
177
  'credit card with nonce ' . $nonce . ' locked, consumed or not found'
178
  );
179
  }
@@ -185,15 +191,15 @@ class Braintree_CreditCardGateway
185
  *
186
  * @access public
187
  * @param array $attribs
188
- * @return object Braintree_Result_Successful or Braintree_Result_Error
189
  */
190
  public function credit($token, $transactionAttribs)
191
  {
192
  $this->_validateId($token);
193
- return Braintree_Transaction::credit(
194
  array_merge(
195
  $transactionAttribs,
196
- array('paymentMethodToken' => $token)
197
  )
198
  );
199
  }
@@ -201,17 +207,17 @@ class Braintree_CreditCardGateway
201
  /**
202
  * create a credit on this card, assuming validations will pass
203
  *
204
- * returns a Braintree_Transaction object on success
205
  *
206
  * @access public
207
  * @param array $attribs
208
- * @return object Braintree_Transaction
209
- * @throws Braintree_Exception_ValidationError
210
  */
211
  public function creditNoValidate($token, $transactionAttribs)
212
  {
213
  $result = $this->credit($token, $transactionAttribs);
214
- return Braintree_Util::returnObjectOrThrowException('Transaction', $result);
215
  }
216
 
217
  /**
@@ -219,16 +225,16 @@ class Braintree_CreditCardGateway
219
  *
220
  * @param string $token
221
  * @param array $transactionAttribs
222
- * @return object Braintree_Result_Successful or Braintree_Result_Error
223
- * @see Braintree_Transaction::sale()
224
  */
225
  public function sale($token, $transactionAttribs)
226
  {
227
  $this->_validateId($token);
228
- return Braintree_Transaction::sale(
229
  array_merge(
230
  $transactionAttribs,
231
- array('paymentMethodToken' => $token)
232
  )
233
  );
234
  }
@@ -236,19 +242,19 @@ class Braintree_CreditCardGateway
236
  /**
237
  * create a new sale using this card, assuming validations will pass
238
  *
239
- * returns a Braintree_Transaction object on success
240
  *
241
  * @access public
242
  * @param array $transactionAttribs
243
  * @param string $token
244
- * @return object Braintree_Transaction
245
- * @throws Braintree_Exception_ValidationsFailed
246
- * @see Braintree_Transaction::sale()
247
  */
248
  public function saleNoValidate($token, $transactionAttribs)
249
  {
250
  $result = $this->sale($token, $transactionAttribs);
251
- return Braintree_Util::returnObjectOrThrowException('Transaction', $result);
252
  }
253
 
254
  /**
@@ -260,13 +266,13 @@ class Braintree_CreditCardGateway
260
  * @access public
261
  * @param array $attributes
262
  * @param string $token (optional)
263
- * @return object Braintree_Result_Successful or Braintree_Result_Error
264
  */
265
  public function update($token, $attributes)
266
  {
267
- Braintree_Util::verifyKeys(self::updateSignature(), $attributes);
268
  $this->_validateId($token);
269
- return $this->_doUpdate('put', '/payment_methods/credit_card/' . $token, array('creditCard' => $attributes));
270
  }
271
 
272
  /**
@@ -274,18 +280,18 @@ class Braintree_CreditCardGateway
274
  *
275
  * if calling this method in context, $token
276
  * is the 2nd attribute. $token is not sent in object context.
277
- * returns a Braintree_CreditCard object on success
278
  *
279
  * @access public
280
  * @param array $attributes
281
  * @param string $token
282
- * @return object Braintree_CreditCard
283
- * @throws Braintree_Exception_ValidationsFailed
284
  */
285
  public function updateNoValidate($token, $attributes)
286
  {
287
  $result = $this->update($token, $attributes);
288
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
289
  }
290
  /**
291
  *
@@ -295,7 +301,7 @@ class Braintree_CreditCardGateway
295
  */
296
  public function updateCreditCardUrl()
297
  {
298
- trigger_error("DEPRECATED: Please use Braintree_TransparentRedirectRequest::url", E_USER_NOTICE);
299
  return $this->_config->baseUrl() . $this->_config->merchantPath() .
300
  '/payment_methods/all/update_via_transparent_redirect_request';
301
  }
@@ -303,20 +309,21 @@ class Braintree_CreditCardGateway
303
  /**
304
  * update a customer from a TransparentRedirect operation
305
  *
 
306
  * @access public
307
  * @param array $attribs
308
  * @return object
309
  */
310
  public function updateFromTransparentRedirect($queryString)
311
  {
312
- trigger_error("DEPRECATED: Please use Braintree_TransparentRedirectRequest::confirm", E_USER_NOTICE);
313
- $params = Braintree_TransparentRedirect::parseAndValidateQueryString(
314
  $queryString
315
  );
316
  return $this->_doUpdate(
317
  'post',
318
  '/payment_methods/all/confirm_transparent_redirect_request',
319
- array('id' => $params['id'])
320
  );
321
  }
322
 
@@ -325,38 +332,43 @@ class Braintree_CreditCardGateway
325
  $this->_validateId($token);
326
  $path = $this->_config->merchantPath() . '/payment_methods/credit_card/' . $token;
327
  $this->_http->delete($path);
328
- return new Braintree_Result_Successful();
329
  }
330
 
331
  private static function baseOptions()
332
  {
333
- return array('makeDefault', 'verificationMerchantAccountId', 'verifyCard', 'verificationAmount', 'venmoSdkSession');
334
  }
335
 
336
  private static function baseSignature($options)
337
  {
338
- return array(
339
  'billingAddressId', 'cardholderName', 'cvv', 'number', 'deviceSessionId',
340
  'expirationDate', 'expirationMonth', 'expirationYear', 'token', 'venmoSdkPaymentMethodCode',
341
  'deviceData', 'fraudMerchantId', 'paymentMethodNonce',
342
- array('options' => $options),
343
- array(
344
- 'billingAddress' => array(
345
- 'firstName',
346
- 'lastName',
347
- 'company',
348
- 'countryCodeAlpha2',
349
- 'countryCodeAlpha3',
350
- 'countryCodeNumeric',
351
- 'countryName',
352
- 'extendedAddress',
353
- 'locality',
354
- 'region',
355
- 'postalCode',
356
- 'streetAddress'
357
- ),
358
- ),
359
- );
 
 
 
 
 
360
  }
361
 
362
  public static function createSignature()
@@ -372,13 +384,13 @@ class Braintree_CreditCardGateway
372
  {
373
  $signature = self::baseSignature(self::baseOptions());
374
 
375
- $updateExistingBillingSignature = array(
376
- array(
377
- 'options' => array(
378
  'updateExisting'
379
- )
380
- )
381
- );
382
 
383
  foreach($signature AS $key => $value) {
384
  if(is_array($value) and array_key_exists('billingAddress', $value)) {
@@ -444,29 +456,30 @@ class Braintree_CreditCardGateway
444
  /**
445
  * generic method for validating incoming gateway responses
446
  *
447
- * creates a new Braintree_CreditCard object and encapsulates
448
- * it inside a Braintree_Result_Successful object, or
449
- * encapsulates a Braintree_Errors object inside a Result_Error
450
- * alternatively, throws an Unexpected exception if the response is invalid.
451
  *
452
  * @ignore
453
  * @param array $response gateway response values
454
- * @return object Result_Successful or Result_Error
455
- * @throws Braintree_Exception_Unexpected
456
  */
457
  private function _verifyGatewayResponse($response)
458
  {
459
  if (isset($response['creditCard'])) {
460
- // return a populated instance of Braintree_Address
461
- return new Braintree_Result_Successful(
462
- Braintree_CreditCard::factory($response['creditCard'])
463
  );
464
- } else if (isset($response['apiErrorResponse'])) {
465
- return new Braintree_Result_Error($response['apiErrorResponse']);
466
  } else {
467
- throw new Braintree_Exception_Unexpected(
468
  "Expected address or apiErrorResponse"
469
  );
470
  }
471
  }
472
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
  /**
7
  * Braintree CreditCardGateway module
8
  * Creates and manages Braintree CreditCards
14
  *
15
  * @package Braintree
16
  * @category Resources
17
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
18
  */
19
+ class CreditCardGateway
20
  {
21
  private $_gateway;
22
  private $_config;
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 create($attribs)
34
  {
35
+ Util::verifyKeys(self::createSignature(), $attribs);
36
+ return $this->_doCreate('/payment_methods', ['credit_card' => $attribs]);
37
  }
38
 
39
  /**
40
  * attempts the create operation assuming all data will validate
41
+ * returns a CreditCard object instead of a Result
42
  *
43
  * @access public
44
  * @param array $attribs
45
+ * @return CreditCard
46
+ * @throws Exception\ValidationError
47
  */
48
  public function createNoValidate($attribs)
49
  {
50
  $result = $this->create($attribs);
51
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
52
  }
53
  /**
54
  * create a customer from a TransparentRedirect operation
55
  *
56
+ * @deprecated since version 2.3.0
57
  * @access public
58
  * @param array $attribs
59
+ * @return Result\Successful|Result\Error
60
  */
61
  public function createFromTransparentRedirect($queryString)
62
  {
63
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::confirm", E_USER_NOTICE);
64
+ $params = TransparentRedirect::parseAndValidateQueryString(
65
  $queryString
66
  );
67
  return $this->_doCreate(
68
  '/payment_methods/all/confirm_transparent_redirect_request',
69
+ ['id' => $params['id']]
70
  );
71
  }
72
 
73
  /**
74
  *
75
+ * @deprecated since version 2.3.0
76
  * @access public
77
  * @param none
78
  * @return string
79
  */
80
  public function createCreditCardUrl()
81
  {
82
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::url", E_USER_NOTICE);
83
+ return $this->_config->baseUrl() . $this->_config->merchantPath().
84
  '/payment_methods/all/create_via_transparent_redirect_request';
85
  }
86
 
87
  /**
88
  * returns a ResourceCollection of expired credit cards
89
+ * @return ResourceCollection
90
  */
91
  public function expired()
92
  {
93
  $path = $this->_config->merchantPath() . '/payment_methods/all/expired_ids';
94
  $response = $this->_http->post($path);
95
+ $pager = [
96
  'object' => $this,
97
  'method' => 'fetchExpired',
98
+ 'methodArgs' => []
99
+ ];
100
 
101
+ return new ResourceCollection($response, $pager);
102
  }
103
 
104
  public function fetchExpired($ids)
105
  {
106
  $path = $this->_config->merchantPath() . "/payment_methods/all/expired";
107
+ $response = $this->_http->post($path, ['search' => ['ids' => $ids]]);
108
 
109
+ return Util::extractattributeasarray(
110
  $response['paymentMethods'],
111
  'creditCard'
112
  );
114
  /**
115
  * returns a ResourceCollection of credit cards expiring between start/end
116
  *
117
+ * @return ResourceCollection
118
  */
119
  public function expiringBetween($startDate, $endDate)
120
  {
121
  $queryPath = $this->_config->merchantPath() . '/payment_methods/all/expiring_ids?start=' . date('mY', $startDate) . '&end=' . date('mY', $endDate);
122
  $response = $this->_http->post($queryPath);
123
+ $pager = [
124
  'object' => $this,
125
  'method' => 'fetchExpiring',
126
+ 'methodArgs' => [$startDate, $endDate]
127
+ ];
128
 
129
+ return new ResourceCollection($response, $pager);
130
  }
131
 
132
  public function fetchExpiring($startDate, $endDate, $ids)
133
  {
134
  $queryPath = $this->_config->merchantPath() . '/payment_methods/all/expiring?start=' . date('mY', $startDate) . '&end=' . date('mY', $endDate);
135
+ $response = $this->_http->post($queryPath, ['search' => ['ids' => $ids]]);
136
 
137
+ return Util::extractAttributeAsArray(
138
  $response['paymentMethods'],
139
  'creditCard'
140
  );
145
  *
146
  * @access public
147
  * @param string $token credit card unique id
148
+ * @return CreditCard
149
+ * @throws Exception\NotFound
150
  */
151
  public function find($token)
152
  {
154
  try {
155
  $path = $this->_config->merchantPath() . '/payment_methods/credit_card/' . $token;
156
  $response = $this->_http->get($path);
157
+ return CreditCard::factory($response['creditCard']);
158
+ } catch (Exception\NotFound $e) {
159
+ throw new Exception\NotFound(
160
  'credit card with token ' . $token . ' not found'
161
  );
162
  }
168
  *
169
  * @access public
170
  * @param string $nonce payment method nonce
171
+ * @return CreditCard
172
+ * @throws Exception\NotFound
173
  */
174
  public function fromNonce($nonce)
175
  {
177
  try {
178
  $path = $this->_config->merchantPath() . '/payment_methods/from_nonce/' . $nonce;
179
  $response = $this->_http->get($path);
180
+ return CreditCard::factory($response['creditCard']);
181
+ } catch (Exception\NotFound $e) {
182
+ throw new Exception\NotFound(
183
  'credit card with nonce ' . $nonce . ' locked, consumed or not found'
184
  );
185
  }
191
  *
192
  * @access public
193
  * @param array $attribs
194
+ * @return Result\Successful|Result\Error
195
  */
196
  public function credit($token, $transactionAttribs)
197
  {
198
  $this->_validateId($token);
199
+ return Transaction::credit(
200
  array_merge(
201
  $transactionAttribs,
202
+ ['paymentMethodToken' => $token]
203
  )
204
  );
205
  }
207
  /**
208
  * create a credit on this card, assuming validations will pass
209
  *
210
+ * returns a Transaction object on success
211
  *
212
  * @access public
213
  * @param array $attribs
214
+ * @return Transaction
215
+ * @throws Exception\ValidationError
216
  */
217
  public function creditNoValidate($token, $transactionAttribs)
218
  {
219
  $result = $this->credit($token, $transactionAttribs);
220
+ return Util::returnObjectOrThrowException('Braintree\Transaction', $result);
221
  }
222
 
223
  /**
225
  *
226
  * @param string $token
227
  * @param array $transactionAttribs
228
+ * @return Result\Successful|Result\Error
229
+ * @see Transaction::sale()
230
  */
231
  public function sale($token, $transactionAttribs)
232
  {
233
  $this->_validateId($token);
234
+ return Transaction::sale(
235
  array_merge(
236
  $transactionAttribs,
237
+ ['paymentMethodToken' => $token]
238
  )
239
  );
240
  }
242
  /**
243
  * create a new sale using this card, assuming validations will pass
244
  *
245
+ * returns a Transaction object on success
246
  *
247
  * @access public
248
  * @param array $transactionAttribs
249
  * @param string $token
250
+ * @return Transaction
251
+ * @throws Exception\ValidationsFailed
252
+ * @see Transaction::sale()
253
  */
254
  public function saleNoValidate($token, $transactionAttribs)
255
  {
256
  $result = $this->sale($token, $transactionAttribs);
257
+ return Util::returnObjectOrThrowException('Braintree\Transaction', $result);
258
  }
259
 
260
  /**
266
  * @access public
267
  * @param array $attributes
268
  * @param string $token (optional)
269
+ * @return Result\Successful|Result\Error
270
  */
271
  public function update($token, $attributes)
272
  {
273
+ Util::verifyKeys(self::updateSignature(), $attributes);
274
  $this->_validateId($token);
275
+ return $this->_doUpdate('put', '/payment_methods/credit_card/' . $token, ['creditCard' => $attributes]);
276
  }
277
 
278
  /**
280
  *
281
  * if calling this method in context, $token
282
  * is the 2nd attribute. $token is not sent in object context.
283
+ * returns a CreditCard object on success
284
  *
285
  * @access public
286
  * @param array $attributes
287
  * @param string $token
288
+ * @return CreditCard
289
+ * @throws Exception\ValidationsFailed
290
  */
291
  public function updateNoValidate($token, $attributes)
292
  {
293
  $result = $this->update($token, $attributes);
294
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
295
  }
296
  /**
297
  *
301
  */
302
  public function updateCreditCardUrl()
303
  {
304
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::url", E_USER_NOTICE);
305
  return $this->_config->baseUrl() . $this->_config->merchantPath() .
306
  '/payment_methods/all/update_via_transparent_redirect_request';
307
  }
309
  /**
310
  * update a customer from a TransparentRedirect operation
311
  *
312
+ * @deprecated since version 2.3.0
313
  * @access public
314
  * @param array $attribs
315
  * @return object
316
  */
317
  public function updateFromTransparentRedirect($queryString)
318
  {
319
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::confirm", E_USER_NOTICE);
320
+ $params = TransparentRedirect::parseAndValidateQueryString(
321
  $queryString
322
  );
323
  return $this->_doUpdate(
324
  'post',
325
  '/payment_methods/all/confirm_transparent_redirect_request',
326
+ ['id' => $params['id']]
327
  );
328
  }
329
 
332
  $this->_validateId($token);
333
  $path = $this->_config->merchantPath() . '/payment_methods/credit_card/' . $token;
334
  $this->_http->delete($path);
335
+ return new Result\Successful();
336
  }
337
 
338
  private static function baseOptions()
339
  {
340
+ return ['makeDefault', 'verificationMerchantAccountId', 'verifyCard', 'verificationAmount', 'venmoSdkSession'];
341
  }
342
 
343
  private static function baseSignature($options)
344
  {
345
+ return [
346
  'billingAddressId', 'cardholderName', 'cvv', 'number', 'deviceSessionId',
347
  'expirationDate', 'expirationMonth', 'expirationYear', 'token', 'venmoSdkPaymentMethodCode',
348
  'deviceData', 'fraudMerchantId', 'paymentMethodNonce',
349
+ ['options' => $options],
350
+ [
351
+ 'billingAddress' => self::billingAddressSignature()
352
+ ],
353
+ ];
354
+ }
355
+
356
+ public static function billingAddressSignature()
357
+ {
358
+ return [
359
+ 'firstName',
360
+ 'lastName',
361
+ 'company',
362
+ 'countryCodeAlpha2',
363
+ 'countryCodeAlpha3',
364
+ 'countryCodeNumeric',
365
+ 'countryName',
366
+ 'extendedAddress',
367
+ 'locality',
368
+ 'region',
369
+ 'postalCode',
370
+ 'streetAddress'
371
+ ];
372
  }
373
 
374
  public static function createSignature()
384
  {
385
  $signature = self::baseSignature(self::baseOptions());
386
 
387
+ $updateExistingBillingSignature = [
388
+ [
389
+ 'options' => [
390
  'updateExisting'
391
+ ]
392
+ ]
393
+ ];
394
 
395
  foreach($signature AS $key => $value) {
396
  if(is_array($value) and array_key_exists('billingAddress', $value)) {
456
  /**
457
  * generic method for validating incoming gateway responses
458
  *
459
+ * creates a new CreditCard object and encapsulates
460
+ * it inside a Result\Successful object, or
461
+ * encapsulates a Errors object inside a Result\Error
462
+ * alternatively, throws an Unexpected exception if the response is invalid
463
  *
464
  * @ignore
465
  * @param array $response gateway response values
466
+ * @return Result\Successful|Result\Error
467
+ * @throws Exception\Unexpected
468
  */
469
  private function _verifyGatewayResponse($response)
470
  {
471
  if (isset($response['creditCard'])) {
472
+ // return a populated instance of Address
473
+ return new Result\Successful(
474
+ CreditCard::factory($response['creditCard'])
475
  );
476
+ } elseif (isset($response['apiErrorResponse'])) {
477
+ return new Result\Error($response['apiErrorResponse']);
478
  } else {
479
+ throw new Exception\Unexpected(
480
  "Expected address or apiErrorResponse"
481
  );
482
  }
483
  }
484
  }
485
+ class_alias('Braintree\CreditCardGateway', 'Braintree_CreditCardGateway');
braintree_sdk/lib/Braintree/CreditCardVerification.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_CreditCardVerification extends Braintree_Result_CreditCardVerification
 
 
3
  {
4
  public static function factory($attributes)
5
  {
@@ -7,16 +9,35 @@ class Braintree_CreditCardVerification extends Braintree_Result_CreditCardVerifi
7
  return $instance;
8
  }
9
 
10
-
11
  // static methods redirecting to gateway
 
 
 
 
 
 
12
 
13
  public static function fetch($query, $ids)
14
  {
15
- return Braintree_Configuration::gateway()->creditCardVerification()->fetch($query, $ids);
16
  }
17
 
18
  public static function search($query)
19
  {
20
- return Braintree_Configuration::gateway()->creditCardVerification()->search($query);
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  }
22
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ class CreditCardVerification extends Result\CreditCardVerification
5
  {
6
  public static function factory($attributes)
7
  {
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');
braintree_sdk/lib/Braintree/CreditCardVerificationGateway.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_CreditCardVerificationGateway
 
 
3
  {
4
  private $_gateway;
5
  private $_config;
@@ -10,20 +12,42 @@ class Braintree_CreditCardVerificationGateway
10
  $this->_gateway = $gateway;
11
  $this->_config = $gateway->config;
12
  $this->_config->assertHasAccessTokenOrKeys();
13
- $this->_http = new Braintree_Http($gateway->config);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  }
15
 
16
  public function fetch($query, $ids)
17
  {
18
- $criteria = array();
19
  foreach ($query as $term) {
20
  $criteria[$term->name] = $term->toparam();
21
  }
22
- $criteria["ids"] = Braintree_CreditCardVerificationSearch::ids()->in($ids)->toparam();
23
  $path = $this->_config->merchantPath() . '/verifications/advanced_search';
24
- $response = $this->_http->post($path, array('search' => $criteria));
25
 
26
- return Braintree_Util::extractattributeasarray(
27
  $response['creditCardVerifications'],
28
  'verification'
29
  );
@@ -31,19 +55,20 @@ class Braintree_CreditCardVerificationGateway
31
 
32
  public function search($query)
33
  {
34
- $criteria = array();
35
  foreach ($query as $term) {
36
  $criteria[$term->name] = $term->toparam();
37
  }
38
 
39
  $path = $this->_config->merchantPath() . '/verifications/advanced_search_ids';
40
- $response = $this->_http->post($path, array('search' => $criteria));
41
- $pager = array(
42
  'object' => $this,
43
  'method' => 'fetch',
44
- 'methodArgs' => array($query)
45
- );
46
 
47
- return new Braintree_ResourceCollection($response, $pager);
48
  }
49
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ class CreditCardVerificationGateway
5
  {
6
  private $_gateway;
7
  private $_config;
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
  );
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');
braintree_sdk/lib/Braintree/CreditCardVerificationSearch.php CHANGED
@@ -1,53 +1,56 @@
1
  <?php
2
- class Braintree_CreditCardVerificationSearch
 
 
3
  {
4
- static function id() {
5
- return new Braintree_TextNode('id');
6
  }
7
 
8
- static function creditCardCardholderName() {
9
- return new Braintree_TextNode('credit_card_cardholder_name');
10
  }
11
 
12
- static function billingAddressDetailsPostalCode() {
13
- return new Braintree_TextNode('billing_address_details_postal_code');
14
  }
15
 
16
- static function customerEmail() {
17
- return new Braintree_TextNode('customer_email');
18
  }
19
 
20
- static function customerId() {
21
- return new Braintree_TextNode('customer_id');
22
  }
23
 
24
- static function paymentMethodToken(){
25
- return new Braintree_TextNode('payment_method_token');
26
  }
27
 
28
- static function creditCardExpirationDate() {
29
- return new Braintree_EqualityNode('credit_card_expiration_date');
30
  }
31
 
32
- static function creditCardNumber() {
33
- return new Braintree_PartialMatchNode('credit_card_number');
34
  }
35
 
36
- static function ids() {
37
- return new Braintree_MultipleValueNode('ids');
38
  }
39
 
40
- static function createdAt() {
41
- return new Braintree_RangeNode("created_at");
42
  }
43
 
44
- static function creditCardCardType()
45
  {
46
- return new Braintree_MultipleValueNode("credit_card_card_type", Braintree_CreditCard::allCardTypes());
47
  }
48
 
49
- static function status()
50
  {
51
- return new Braintree_MultipleValueNode("status", Braintree_Result_CreditCardVerification::allStatuses());
52
  }
53
  }
 
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');
braintree_sdk/lib/Braintree/Customer.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  /**
3
  * Braintree Customer module
4
  * Creates and manages Customers
@@ -9,7 +11,7 @@
9
  *
10
  * @package Braintree
11
  * @category Resources
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read array $addresses
15
  * @property-read array $paymentMethods
@@ -18,6 +20,9 @@
18
  * @property-read array $creditCards
19
  * @property-read array $paypalAccounts
20
  * @property-read array $applePayCards
 
 
 
21
  * @property-read array $coinbaseAccounts
22
  * @property-read array $customFields custom fields passed with the request
23
  * @property-read string $email
@@ -29,56 +34,56 @@
29
  * @property-read string $updatedAt
30
  * @property-read string $website
31
  */
32
- class Braintree_Customer extends Braintree_Base
33
  {
34
  /**
35
- *
36
- * @return Braintree_Customer[]
37
  */
38
  public static function all()
39
  {
40
- return Braintree_Configuration::gateway()->customer()->all();
41
  }
42
 
43
  /**
44
- *
45
  * @param string $query
46
  * @param int[] $ids
47
- * @return Braintree_Customer|Braintree_Customer[]
48
  */
49
  public static function fetch($query, $ids)
50
  {
51
- return Braintree_Configuration::gateway()->customer()->fetch($query, $ids);
52
  }
53
 
54
  /**
55
- *
56
  * @param array $attribs
57
- * @return Braintree_Customer
58
  */
59
- public static function create($attribs = array())
60
  {
61
- return Braintree_Configuration::gateway()->customer()->create($attribs);
62
  }
63
 
64
  /**
65
- *
66
  * @param array $attribs
67
- * @return Braintree_Customer
68
  */
69
- public static function createNoValidate($attribs = array())
70
  {
71
- return Braintree_Configuration::gateway()->customer()->createNoValidate($attribs);
72
  }
73
 
74
  /**
75
  * @deprecated since version 2.3.0
76
  * @param string $queryString
77
- * @return Braintree_Result_Successful
78
  */
79
  public static function createFromTransparentRedirect($queryString)
80
  {
81
- return Braintree_Configuration::gateway()->customer()->createFromTransparentRedirect($queryString);
82
  }
83
 
84
  /**
@@ -87,130 +92,130 @@ class Braintree_Customer extends Braintree_Base
87
  */
88
  public static function createCustomerUrl()
89
  {
90
- return Braintree_Configuration::gateway()->customer()->createCustomerUrl();
91
  }
92
 
93
  /**
94
- *
95
- * @throws Braintree_Exception_NotFound
96
- * @param int $id
97
- * @return Braintree_Customer
98
  */
99
  public static function find($id)
100
  {
101
- return Braintree_Configuration::gateway()->customer()->find($id);
102
  }
103
 
104
  /**
105
- *
106
  * @param int $customerId
107
  * @param array $transactionAttribs
108
- * @return Braintree_Result_Successful|Braintree_Result_Error
109
  */
110
  public static function credit($customerId, $transactionAttribs)
111
  {
112
- return Braintree_Configuration::gateway()->customer()->credit($customerId, $transactionAttribs);
113
  }
114
 
115
  /**
116
- *
117
- * @throws Braintree_Exception_ValidationError
118
  * @param type $customerId
119
  * @param type $transactionAttribs
120
- * @return Braintree_Transaction
121
  */
122
  public static function creditNoValidate($customerId, $transactionAttribs)
123
  {
124
- return Braintree_Configuration::gateway()->customer()->creditNoValidate($customerId, $transactionAttribs);
125
  }
126
 
127
  /**
128
- *
129
- * @throws Braintree_Exception on invalid id or non-200 http response code
130
  * @param int $customerId
131
- * @return Braintree_Result_Successful
132
  */
133
  public static function delete($customerId)
134
  {
135
- return Braintree_Configuration::gateway()->customer()->delete($customerId);
136
  }
137
 
138
  /**
139
- *
140
  * @param int $customerId
141
  * @param array $transactionAttribs
142
- * @return Braintree_Transaction
143
  */
144
  public static function sale($customerId, $transactionAttribs)
145
  {
146
- return Braintree_Configuration::gateway()->customer()->sale($customerId, $transactionAttribs);
147
  }
148
 
149
  /**
150
- *
151
  * @param int $customerId
152
  * @param array $transactionAttribs
153
- * @return Braintree_Transaction
154
- */
155
  public static function saleNoValidate($customerId, $transactionAttribs)
156
  {
157
- return Braintree_Configuration::gateway()->customer()->saleNoValidate($customerId, $transactionAttribs);
158
  }
159
 
160
  /**
161
- *
162
  * @throws InvalidArgumentException
163
  * @param string $query
164
- * @return Braintree_ResourceCollection
165
  */
166
  public static function search($query)
167
  {
168
- return Braintree_Configuration::gateway()->customer()->search($query);
169
  }
170
 
171
  /**
172
- *
173
- * @throws Braintree_Exception_Unexpected
174
  * @param int $customerId
175
  * @param array $attributes
176
- * @return Braintree_Result_Successful|Braintree_Result_Error
177
  */
178
  public static function update($customerId, $attributes)
179
  {
180
- return Braintree_Configuration::gateway()->customer()->update($customerId, $attributes);
181
  }
182
 
183
  /**
184
- *
185
- * @throws Braintree_Exception_Unexpected
186
  * @param int $customerId
187
  * @param array $attributes
188
- * @return Braintree_CustomerGateway
189
  */
190
  public static function updateNoValidate($customerId, $attributes)
191
  {
192
- return Braintree_Configuration::gateway()->customer()->updateNoValidate($customerId, $attributes);
193
  }
194
 
195
  /**
196
- *
197
  * @deprecated since version 2.3.0
198
  * @return string
199
  */
200
  public static function updateCustomerUrl()
201
  {
202
- return Braintree_Configuration::gateway()->customer()->updateCustomerUrl();
203
  }
204
 
205
  /**
206
- *
207
  * @deprecated since version 2.3.0
208
  * @param string $queryString
209
- * @return Braintree_Result_Successful|Braintree_Result_Error
210
  */
211
  public static function updateFromTransparentRedirect($queryString)
212
  {
213
- return Braintree_Configuration::gateway()->customer()->updateFromTransparentRedirect($queryString);
214
  }
215
 
216
  /* instance methods */
@@ -224,65 +229,82 @@ class Braintree_Customer extends Braintree_Base
224
  */
225
  protected function _initialize($customerAttribs)
226
  {
227
- // set the attributes
228
  $this->_attributes = $customerAttribs;
229
 
230
- // map each address into its own object
231
- $addressArray = array();
232
  if (isset($customerAttribs['addresses'])) {
233
 
234
  foreach ($customerAttribs['addresses'] AS $address) {
235
- $addressArray[] = Braintree_Address::factory($address);
236
  }
237
  }
238
  $this->_set('addresses', $addressArray);
239
 
240
- // map each creditCard into its own object
241
- $creditCardArray = array();
242
  if (isset($customerAttribs['creditCards'])) {
243
  foreach ($customerAttribs['creditCards'] AS $creditCard) {
244
- $creditCardArray[] = Braintree_CreditCard::factory($creditCard);
245
  }
246
  }
247
  $this->_set('creditCards', $creditCardArray);
248
 
249
- // map each coinbaseAccount into its own object
250
- $coinbaseAccountArray = array();
251
  if (isset($customerAttribs['coinbaseAccounts'])) {
252
  foreach ($customerAttribs['coinbaseAccounts'] AS $coinbaseAccount) {
253
- $coinbaseAccountArray[] = Braintree_CoinbaseAccount::factory($coinbaseAccount);
254
  }
255
  }
256
  $this->_set('coinbaseAccounts', $coinbaseAccountArray);
257
 
258
- // map each paypalAccount into its own object
259
- $paypalAccountArray = array();
260
  if (isset($customerAttribs['paypalAccounts'])) {
261
  foreach ($customerAttribs['paypalAccounts'] AS $paypalAccount) {
262
- $paypalAccountArray[] = Braintree_PayPalAccount::factory($paypalAccount);
263
  }
264
  }
265
  $this->_set('paypalAccounts', $paypalAccountArray);
266
 
267
- // map each applePayCard into its own object
268
- $applePayCardArray = array();
269
  if (isset($customerAttribs['applePayCards'])) {
270
  foreach ($customerAttribs['applePayCards'] AS $applePayCard) {
271
- $applePayCardArray[] = Braintree_ApplePayCard::factory($applePayCard);
272
  }
273
  }
274
  $this->_set('applePayCards', $applePayCardArray);
275
 
276
- // map each androidPayCard into its own object
277
- $androidPayCardArray = array();
278
  if (isset($customerAttribs['androidPayCards'])) {
279
  foreach ($customerAttribs['androidPayCards'] AS $androidPayCard) {
280
- $androidPayCardArray[] = Braintree_AndroidPayCard::factory($androidPayCard);
281
  }
282
  }
283
  $this->_set('androidPayCards', $androidPayCardArray);
284
 
285
- $this->_set('paymentMethods', array_merge($this->creditCards, $this->paypalAccounts, $this->applePayCards, $this->coinbaseAccounts, $this->androidPayCards));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  }
287
 
288
  /**
@@ -292,19 +314,19 @@ class Braintree_Customer extends Braintree_Base
292
  public function __toString()
293
  {
294
  return __CLASS__ . '[' .
295
- Braintree_Util::attributesToString($this->_attributes) .']';
296
  }
297
 
298
  /**
299
- * returns false if comparing object is not a Braintree_Customer,
300
- * or is a Braintree_Customer with a different id
301
  *
302
  * @param object $otherCust customer to compare against
303
  * @return boolean
304
  */
305
  public function isEqual($otherCust)
306
  {
307
- return !($otherCust instanceof Braintree_Customer) ? false : $this->id === $otherCust->id;
308
  }
309
 
310
  /**
@@ -322,11 +344,11 @@ class Braintree_Customer extends Braintree_Base
322
  /**
323
  * returns the customer's default payment method
324
  *
325
- * @return object Braintree_CreditCard or Braintree_PayPalAccount
326
  */
327
  public function defaultPaymentMethod()
328
  {
329
- $defaultPaymentMethods = array_filter($this->paymentMethods, 'Braintree_Customer::_defaultPaymentMethodFilter');
330
  return current($defaultPaymentMethods);
331
  }
332
 
@@ -341,7 +363,7 @@ class Braintree_Customer extends Braintree_Base
341
  * @access protected
342
  * @var array registry of customer data
343
  */
344
- protected $_attributes = array(
345
  'addresses' => '',
346
  'company' => '',
347
  'creditCards' => '',
@@ -354,20 +376,21 @@ class Braintree_Customer extends Braintree_Base
354
  'createdAt' => '',
355
  'updatedAt' => '',
356
  'website' => '',
357
- );
358
 
359
  /**
360
- * factory method: returns an instance of Braintree_Customer
361
  * to the requesting method, with populated properties
362
  *
363
  * @ignore
364
  * @param array $attributes
365
- * @return Braintree_Customer
366
  */
367
  public static function factory($attributes)
368
  {
369
- $instance = new Braintree_Customer();
370
  $instance->_initialize($attributes);
371
  return $instance;
372
  }
373
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree Customer module
6
  * Creates and manages Customers
11
  *
12
  * @package Braintree
13
  * @category Resources
14
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
  *
16
  * @property-read array $addresses
17
  * @property-read array $paymentMethods
20
  * @property-read array $creditCards
21
  * @property-read array $paypalAccounts
22
  * @property-read array $applePayCards
23
+ * @property-read array $androidPayCards
24
+ * @property-read array $amexExpressCheckoutCards
25
+ * @property-read array $venmoAccounts
26
  * @property-read array $coinbaseAccounts
27
  * @property-read array $customFields custom fields passed with the request
28
  * @property-read string $email
34
  * @property-read string $updatedAt
35
  * @property-read string $website
36
  */
37
+ class Customer extends Base
38
  {
39
  /**
40
+ *
41
+ * @return Customer[]
42
  */
43
  public static function all()
44
  {
45
+ return Configuration::gateway()->customer()->all();
46
  }
47
 
48
  /**
49
+ *
50
  * @param string $query
51
  * @param int[] $ids
52
+ * @return Customer|Customer[]
53
  */
54
  public static function fetch($query, $ids)
55
  {
56
+ return Configuration::gateway()->customer()->fetch($query, $ids);
57
  }
58
 
59
  /**
60
+ *
61
  * @param array $attribs
62
+ * @return Customer
63
  */
64
+ public static function create($attribs = [])
65
  {
66
+ return Configuration::gateway()->customer()->create($attribs);
67
  }
68
 
69
  /**
70
+ *
71
  * @param array $attribs
72
+ * @return Customer
73
  */
74
+ public static function createNoValidate($attribs = [])
75
  {
76
+ return Configuration::gateway()->customer()->createNoValidate($attribs);
77
  }
78
 
79
  /**
80
  * @deprecated since version 2.3.0
81
  * @param string $queryString
82
+ * @return Result\Successful
83
  */
84
  public static function createFromTransparentRedirect($queryString)
85
  {
86
+ return Configuration::gateway()->customer()->createFromTransparentRedirect($queryString);
87
  }
88
 
89
  /**
92
  */
93
  public static function createCustomerUrl()
94
  {
95
+ return Configuration::gateway()->customer()->createCustomerUrl();
96
  }
97
 
98
  /**
99
+ *
100
+ * @throws Exception\NotFound
101
+ * @param string $id customer id
102
+ * @return Customer
103
  */
104
  public static function find($id)
105
  {
106
+ return Configuration::gateway()->customer()->find($id);
107
  }
108
 
109
  /**
110
+ *
111
  * @param int $customerId
112
  * @param array $transactionAttribs
113
+ * @return Result\Successful|Result\Error
114
  */
115
  public static function credit($customerId, $transactionAttribs)
116
  {
117
+ return Configuration::gateway()->customer()->credit($customerId, $transactionAttribs);
118
  }
119
 
120
  /**
121
+ *
122
+ * @throws Exception\ValidationError
123
  * @param type $customerId
124
  * @param type $transactionAttribs
125
+ * @return Transaction
126
  */
127
  public static function creditNoValidate($customerId, $transactionAttribs)
128
  {
129
+ return Configuration::gateway()->customer()->creditNoValidate($customerId, $transactionAttribs);
130
  }
131
 
132
  /**
133
+ *
134
+ * @throws Exception on invalid id or non-200 http response code
135
  * @param int $customerId
136
+ * @return Result\Successful
137
  */
138
  public static function delete($customerId)
139
  {
140
+ return Configuration::gateway()->customer()->delete($customerId);
141
  }
142
 
143
  /**
144
+ *
145
  * @param int $customerId
146
  * @param array $transactionAttribs
147
+ * @return Transaction
148
  */
149
  public static function sale($customerId, $transactionAttribs)
150
  {
151
+ return Configuration::gateway()->customer()->sale($customerId, $transactionAttribs);
152
  }
153
 
154
  /**
155
+ *
156
  * @param int $customerId
157
  * @param array $transactionAttribs
158
+ * @return Transaction
159
+ */
160
  public static function saleNoValidate($customerId, $transactionAttribs)
161
  {
162
+ return Configuration::gateway()->customer()->saleNoValidate($customerId, $transactionAttribs);
163
  }
164
 
165
  /**
166
+ *
167
  * @throws InvalidArgumentException
168
  * @param string $query
169
+ * @return ResourceCollection
170
  */
171
  public static function search($query)
172
  {
173
+ return Configuration::gateway()->customer()->search($query);
174
  }
175
 
176
  /**
177
+ *
178
+ * @throws Exception\Unexpected
179
  * @param int $customerId
180
  * @param array $attributes
181
+ * @return Result\Successful|Result\Error
182
  */
183
  public static function update($customerId, $attributes)
184
  {
185
+ return Configuration::gateway()->customer()->update($customerId, $attributes);
186
  }
187
 
188
  /**
189
+ *
190
+ * @throws Exception\Unexpected
191
  * @param int $customerId
192
  * @param array $attributes
193
+ * @return CustomerGateway
194
  */
195
  public static function updateNoValidate($customerId, $attributes)
196
  {
197
+ return Configuration::gateway()->customer()->updateNoValidate($customerId, $attributes);
198
  }
199
 
200
  /**
201
+ *
202
  * @deprecated since version 2.3.0
203
  * @return string
204
  */
205
  public static function updateCustomerUrl()
206
  {
207
+ return Configuration::gateway()->customer()->updateCustomerUrl();
208
  }
209
 
210
  /**
211
+ *
212
  * @deprecated since version 2.3.0
213
  * @param string $queryString
214
+ * @return Result\Successful|Result\Error
215
  */
216
  public static function updateFromTransparentRedirect($queryString)
217
  {
218
+ return Configuration::gateway()->customer()->updateFromTransparentRedirect($queryString);
219
  }
220
 
221
  /* instance methods */
229
  */
230
  protected function _initialize($customerAttribs)
231
  {
 
232
  $this->_attributes = $customerAttribs;
233
 
234
+ $addressArray = [];
 
235
  if (isset($customerAttribs['addresses'])) {
236
 
237
  foreach ($customerAttribs['addresses'] AS $address) {
238
+ $addressArray[] = Address::factory($address);
239
  }
240
  }
241
  $this->_set('addresses', $addressArray);
242
 
243
+ $creditCardArray = [];
 
244
  if (isset($customerAttribs['creditCards'])) {
245
  foreach ($customerAttribs['creditCards'] AS $creditCard) {
246
+ $creditCardArray[] = CreditCard::factory($creditCard);
247
  }
248
  }
249
  $this->_set('creditCards', $creditCardArray);
250
 
251
+ $coinbaseAccountArray = [];
 
252
  if (isset($customerAttribs['coinbaseAccounts'])) {
253
  foreach ($customerAttribs['coinbaseAccounts'] AS $coinbaseAccount) {
254
+ $coinbaseAccountArray[] = CoinbaseAccount::factory($coinbaseAccount);
255
  }
256
  }
257
  $this->_set('coinbaseAccounts', $coinbaseAccountArray);
258
 
259
+ $paypalAccountArray = [];
 
260
  if (isset($customerAttribs['paypalAccounts'])) {
261
  foreach ($customerAttribs['paypalAccounts'] AS $paypalAccount) {
262
+ $paypalAccountArray[] = PayPalAccount::factory($paypalAccount);
263
  }
264
  }
265
  $this->_set('paypalAccounts', $paypalAccountArray);
266
 
267
+ $applePayCardArray = [];
 
268
  if (isset($customerAttribs['applePayCards'])) {
269
  foreach ($customerAttribs['applePayCards'] AS $applePayCard) {
270
+ $applePayCardArray[] = ApplePayCard::factory($applePayCard);
271
  }
272
  }
273
  $this->_set('applePayCards', $applePayCardArray);
274
 
275
+ $androidPayCardArray = [];
 
276
  if (isset($customerAttribs['androidPayCards'])) {
277
  foreach ($customerAttribs['androidPayCards'] AS $androidPayCard) {
278
+ $androidPayCardArray[] = AndroidPayCard::factory($androidPayCard);
279
  }
280
  }
281
  $this->_set('androidPayCards', $androidPayCardArray);
282
 
283
+ $amexExpressCheckoutCardArray = [];
284
+ if (isset($customerAttribs['amexExpressCheckoutCards'])) {
285
+ foreach ($customerAttribs['amexExpressCheckoutCards'] AS $amexExpressCheckoutCard) {
286
+ $amexExpressCheckoutCardArray[] = AmexExpressCheckoutCard::factory($amexExpressCheckoutCard);
287
+ }
288
+ }
289
+ $this->_set('amexExpressCheckoutCards', $amexExpressCheckoutCardArray);
290
+
291
+ $venmoAccountArray = array();
292
+ if (isset($customerAttribs['venmoAccounts'])) {
293
+ foreach ($customerAttribs['venmoAccounts'] AS $venmoAccount) {
294
+ $venmoAccountArray[] = VenmoAccount::factory($venmoAccount);
295
+ }
296
+ }
297
+ $this->_set('venmoAccounts', $venmoAccountArray);
298
+
299
+ $this->_set('paymentMethods', array_merge(
300
+ $this->creditCards,
301
+ $this->paypalAccounts,
302
+ $this->applePayCards,
303
+ $this->coinbaseAccounts,
304
+ $this->androidPayCards,
305
+ $this->amexExpressCheckoutCards,
306
+ $this->venmoAccounts
307
+ ));
308
  }
309
 
310
  /**
314
  public function __toString()
315
  {
316
  return __CLASS__ . '[' .
317
+ Util::attributesToString($this->_attributes) .']';
318
  }
319
 
320
  /**
321
+ * returns false if comparing object is not a Customer,
322
+ * or is a Customer with a different id
323
  *
324
  * @param object $otherCust customer to compare against
325
  * @return boolean
326
  */
327
  public function isEqual($otherCust)
328
  {
329
+ return !($otherCust instanceof Customer) ? false : $this->id === $otherCust->id;
330
  }
331
 
332
  /**
344
  /**
345
  * returns the customer's default payment method
346
  *
347
+ * @return CreditCard|PayPalAccount
348
  */
349
  public function defaultPaymentMethod()
350
  {
351
+ $defaultPaymentMethods = array_filter($this->paymentMethods, 'Braintree\Customer::_defaultPaymentMethodFilter');
352
  return current($defaultPaymentMethods);
353
  }
354
 
363
  * @access protected
364
  * @var array registry of customer data
365
  */
366
+ protected $_attributes = [
367
  'addresses' => '',
368
  'company' => '',
369
  'creditCards' => '',
376
  'createdAt' => '',
377
  'updatedAt' => '',
378
  'website' => '',
379
+ ];
380
 
381
  /**
382
+ * factory method: returns an instance of Customer
383
  * to the requesting method, with populated properties
384
  *
385
  * @ignore
386
  * @param array $attributes
387
+ * @return Customer
388
  */
389
  public static function factory($attributes)
390
  {
391
+ $instance = new Customer();
392
  $instance->_initialize($attributes);
393
  return $instance;
394
  }
395
  }
396
+ class_alias('Braintree\Customer', 'Braintree_Customer');
braintree_sdk/lib/Braintree/CustomerGateway.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Braintree CustomerGateway module
4
  * Creates and manages Customers
@@ -9,9 +13,9 @@
9
  *
10
  * @package Braintree
11
  * @category Resources
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  */
14
- class Braintree_CustomerGateway
15
  {
16
  private $_gateway;
17
  private $_config;
@@ -22,33 +26,33 @@ class Braintree_CustomerGateway
22
  $this->_gateway = $gateway;
23
  $this->_config = $gateway->config;
24
  $this->_config->assertHasAccessTokenOrKeys();
25
- $this->_http = new Braintree_Http($gateway->config);
26
  }
27
 
28
  public function all()
29
  {
30
  $path = $this->_config->merchantPath() . '/customers/advanced_search_ids';
31
  $response = $this->_http->post($path);
32
- $pager = array(
33
  'object' => $this,
34
  'method' => 'fetch',
35
- 'methodArgs' => array(array())
36
- );
37
 
38
- return new Braintree_ResourceCollection($response, $pager);
39
  }
40
 
41
  public function fetch($query, $ids)
42
  {
43
- $criteria = array();
44
  foreach ($query as $term) {
45
  $criteria[$term->name] = $term->toparam();
46
  }
47
- $criteria["ids"] = Braintree_CustomerSearch::ids()->in($ids)->toparam();
48
  $path = $this->_config->merchantPath() . '/customers/advanced_search';
49
- $response = $this->_http->post($path, array('search' => $criteria));
50
 
51
- return Braintree_Util::extractattributeasarray(
52
  $response['customers'],
53
  'customer'
54
  );
@@ -59,7 +63,7 @@ class Braintree_CustomerGateway
59
  * the gateway will generate it.
60
  *
61
  * <code>
62
- * $result = Braintree_Customer::create(array(
63
  * 'first_name' => 'John',
64
  * 'last_name' => 'Smith',
65
  * 'company' => 'Smith Co.',
@@ -77,27 +81,27 @@ class Braintree_CustomerGateway
77
  *
78
  * @access public
79
  * @param array $attribs
80
- * @return object Result, either Successful or Error
81
  */
82
- public function create($attribs = array())
83
  {
84
- Braintree_Util::verifyKeys(self::createSignature(), $attribs);
85
- return $this->_doCreate('/customers', array('customer' => $attribs));
86
  }
87
 
88
  /**
89
  * attempts the create operation assuming all data will validate
90
- * returns a Braintree_Customer object instead of a Result
91
  *
92
  * @access public
93
  * @param array $attribs
94
- * @return object
95
- * @throws Braintree_Exception_ValidationError
96
  */
97
- public function createNoValidate($attribs = array())
98
  {
99
  $result = $this->create($attribs);
100
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
101
  }
102
  /**
103
  * create a customer from a TransparentRedirect operation
@@ -105,17 +109,17 @@ class Braintree_CustomerGateway
105
  * @deprecated since version 2.3.0
106
  * @access public
107
  * @param array $attribs
108
- * @return object
109
  */
110
  public function createFromTransparentRedirect($queryString)
111
  {
112
- trigger_error("DEPRECATED: Please use Braintree_TransparentRedirectRequest::confirm", E_USER_NOTICE);
113
- $params = Braintree_TransparentRedirect::parseAndValidateQueryString(
114
  $queryString
115
  );
116
  return $this->_doCreate(
117
  '/customers/all/confirm_transparent_redirect_request',
118
- array('id' => $params['id'])
119
  );
120
  }
121
 
@@ -128,7 +132,7 @@ class Braintree_CustomerGateway
128
  */
129
  public function createCustomerUrl()
130
  {
131
- trigger_error("DEPRECATED: Please use Braintree_TransparentRedirectRequest::url", E_USER_NOTICE);
132
  return $this->_config->baseUrl() . $this->_config->merchantPath() .
133
  '/customers/all/create_via_transparent_redirect_request';
134
  }
@@ -141,15 +145,15 @@ class Braintree_CustomerGateway
141
  public static function createSignature()
142
  {
143
 
144
- $creditCardSignature = Braintree_CreditCardGateway::createSignature();
145
  unset($creditCardSignature[array_search('customerId', $creditCardSignature)]);
146
- $signature = array(
147
  'id', 'company', 'email', 'fax', 'firstName',
148
  'lastName', 'phone', 'website', 'deviceData',
149
  'deviceSessionId', 'fraudMerchantId', 'paymentMethodNonce',
150
- array('creditCard' => $creditCardSignature),
151
- array('customFields' => array('_anyKey_')),
152
- );
153
  return $signature;
154
  }
155
 
@@ -159,7 +163,7 @@ class Braintree_CustomerGateway
159
  */
160
  public static function updateSignature()
161
  {
162
- $creditCardSignature = Braintree_CreditCardGateway::updateSignature();
163
 
164
  foreach($creditCardSignature AS $key => $value) {
165
  if(is_array($value) and array_key_exists('options', $value)) {
@@ -167,13 +171,13 @@ class Braintree_CustomerGateway
167
  }
168
  }
169
 
170
- $signature = array(
171
  'id', 'company', 'email', 'fax', 'firstName',
172
  'lastName', 'phone', 'website', 'deviceData',
173
  'deviceSessionId', 'fraudMerchantId', 'paymentMethodNonce',
174
- array('creditCard' => $creditCardSignature),
175
- array('customFields' => array('_anyKey_')),
176
- );
177
  return $signature;
178
  }
179
 
@@ -183,8 +187,8 @@ class Braintree_CustomerGateway
183
  *
184
  * @access public
185
  * @param string id customer Id
186
- * @return object Braintree_Customer
187
- * @throws Braintree_Exception_NotFound
188
  */
189
  public function find($id)
190
  {
@@ -192,13 +196,12 @@ class Braintree_CustomerGateway
192
  try {
193
  $path = $this->_config->merchantPath() . '/customers/' . $id;
194
  $response = $this->_http->get($path);
195
- return Braintree_Customer::factory($response['customer']);
196
- } catch (Braintree_Exception_NotFound $e) {
197
- throw new Braintree_Exception_NotFound(
198
  'customer with id ' . $id . ' not found'
199
  );
200
  }
201
-
202
  }
203
 
204
  /**
@@ -207,14 +210,14 @@ class Braintree_CustomerGateway
207
  * @access public
208
  * @param int $customerId
209
  * @param array $transactionAttribs
210
- * @return Braintree_Result_Successful|Braintree_Result_Error
211
  */
212
  public function credit($customerId, $transactionAttribs)
213
  {
214
  $this->_validateId($customerId);
215
- return Braintree_Transaction::credit(
216
  array_merge($transactionAttribs,
217
- array('customerId' => $customerId)
218
  )
219
  );
220
  }
@@ -222,18 +225,18 @@ class Braintree_CustomerGateway
222
  /**
223
  * credit a customer, assuming validations will pass
224
  *
225
- * returns a Braintree_Transaction object on success
226
  *
227
  * @access public
228
  * @param int $customerId
229
  * @param array $transactionAttribs
230
- * @return Braintree_Transaction
231
- * @throws Braintree_Exception_ValidationError
232
  */
233
  public function creditNoValidate($customerId, $transactionAttribs)
234
  {
235
  $result = $this->credit($customerId, $transactionAttribs);
236
- return Braintree_Util::returnObjectOrThrowException('Braintree_Transaction', $result);
237
  }
238
 
239
  /**
@@ -246,7 +249,7 @@ class Braintree_CustomerGateway
246
  $this->_validateId($customerId);
247
  $path = $this->_config->merchantPath() . '/customers/' . $customerId;
248
  $this->_http->delete($path);
249
- return new Braintree_Result_Successful();
250
  }
251
 
252
  /**
@@ -254,15 +257,15 @@ class Braintree_CustomerGateway
254
  *
255
  * @param string $customerId
256
  * @param array $transactionAttribs
257
- * @return object Braintree_Result_Successful or Braintree_Result_Error
258
- * @see Braintree_Transaction::sale()
259
  */
260
  public function sale($customerId, $transactionAttribs)
261
  {
262
  $this->_validateId($customerId);
263
- return Braintree_Transaction::sale(
264
  array_merge($transactionAttribs,
265
- array('customerId' => $customerId)
266
  )
267
  );
268
  }
@@ -270,18 +273,18 @@ class Braintree_CustomerGateway
270
  /**
271
  * create a new sale for a customer, assuming validations will pass
272
  *
273
- * returns a Braintree_Transaction object on success
274
  * @access public
275
  * @param string $customerId
276
  * @param array $transactionAttribs
277
- * @return object Braintree_Transaction
278
- * @throws Braintree_Exception_ValidationsFailed
279
- * @see Braintree_Transaction::sale()
280
  */
281
  public function saleNoValidate($customerId, $transactionAttribs)
282
  {
283
  $result = $this->sale($customerId, $transactionAttribs);
284
- return Braintree_Util::returnObjectOrThrowException('Braintree_Transaction', $result);
285
  }
286
 
287
  /**
@@ -292,12 +295,12 @@ class Braintree_CustomerGateway
292
  * For more detailed information and examples, see {@link http://www.braintreepayments.com/gateway/customer-api#searching http://www.braintreepaymentsolutions.com/gateway/customer-api}
293
  *
294
  * @param mixed $query search query
295
- * @return object Braintree_ResourceCollection
296
  * @throws InvalidArgumentException
297
  */
298
  public function search($query)
299
  {
300
- $criteria = array();
301
  foreach ($query as $term) {
302
  $result = $term->toparam();
303
  if(is_null($result) || empty($result)) {
@@ -308,14 +311,14 @@ class Braintree_CustomerGateway
308
  }
309
 
310
  $path = $this->_config->merchantPath() . '/customers/advanced_search_ids';
311
- $response = $this->_http->post($path, array('search' => $criteria));
312
- $pager = array(
313
  'object' => $this,
314
  'method' => 'fetch',
315
- 'methodArgs' => array($query)
316
- );
317
 
318
- return new Braintree_ResourceCollection($response, $pager);
319
  }
320
 
321
  /**
@@ -327,16 +330,16 @@ class Braintree_CustomerGateway
327
  * @access public
328
  * @param string $customerId (optional)
329
  * @param array $attributes
330
- * @return object Braintree_Result_Successful or Braintree_Result_Error
331
  */
332
  public function update($customerId, $attributes)
333
  {
334
- Braintree_Util::verifyKeys(self::updateSignature(), $attributes);
335
  $this->_validateId($customerId);
336
  return $this->_doUpdate(
337
  'put',
338
  '/customers/' . $customerId,
339
- array('customer' => $attributes)
340
  );
341
  }
342
 
@@ -345,18 +348,18 @@ class Braintree_CustomerGateway
345
  *
346
  * if calling this method in static context, customerId
347
  * is the 2nd attribute. customerId is not sent in object context.
348
- * returns a Braintree_Customer object on success
349
  *
350
  * @access public
351
  * @param string $customerId
352
  * @param array $attributes
353
- * @return object Braintree_Customer
354
- * @throws Braintree_Exception_ValidationsFailed
355
  */
356
  public function updateNoValidate($customerId, $attributes)
357
  {
358
  $result = $this->update($customerId, $attributes);
359
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
360
  }
361
  /**
362
  *
@@ -366,7 +369,7 @@ class Braintree_CustomerGateway
366
  */
367
  public function updateCustomerUrl()
368
  {
369
- trigger_error("DEPRECATED: Please use Braintree_TransparentRedirectRequest::url", E_USER_NOTICE);
370
  return $this->_config->baseUrl() . $this->_config->merchantPath() .
371
  '/customers/all/update_via_transparent_redirect_request';
372
  }
@@ -381,14 +384,14 @@ class Braintree_CustomerGateway
381
  */
382
  public function updateFromTransparentRedirect($queryString)
383
  {
384
- trigger_error("DEPRECATED: Please use Braintree_TransparentRedirectRequest::confirm", E_USER_NOTICE);
385
- $params = Braintree_TransparentRedirect::parseAndValidateQueryString(
386
  $queryString
387
  );
388
  return $this->_doUpdate(
389
  'post',
390
  '/customers/all/confirm_transparent_redirect_request',
391
- array('id' => $params['id'])
392
  );
393
  }
394
 
@@ -400,7 +403,7 @@ class Braintree_CustomerGateway
400
  * @ignore
401
  * @access protected
402
  * @param array $customerAttribs array of customer data
403
- * @return none
404
  */
405
  protected function _initialize($customerAttribs)
406
  {
@@ -408,56 +411,56 @@ class Braintree_CustomerGateway
408
  $this->_attributes = $customerAttribs;
409
 
410
  // map each address into its own object
411
- $addressArray = array();
412
  if (isset($customerAttribs['addresses'])) {
413
 
414
  foreach ($customerAttribs['addresses'] AS $address) {
415
- $addressArray[] = Braintree_Address::factory($address);
416
  }
417
  }
418
  $this->_set('addresses', $addressArray);
419
 
420
  // map each creditCard into its own object
421
- $creditCardArray = array();
422
  if (isset($customerAttribs['creditCards'])) {
423
  foreach ($customerAttribs['creditCards'] AS $creditCard) {
424
- $creditCardArray[] = Braintree_CreditCard::factory($creditCard);
425
  }
426
  }
427
  $this->_set('creditCards', $creditCardArray);
428
 
429
  // map each coinbaseAccount into its own object
430
- $coinbaseAccountArray = array();
431
  if (isset($customerAttribs['coinbaseAccounts'])) {
432
  foreach ($customerAttribs['coinbaseAccounts'] AS $coinbaseAccount) {
433
- $coinbaseAccountArray[] = Braintree_CoinbaseAccount::factory($coinbaseAccount);
434
  }
435
  }
436
  $this->_set('coinbaseAccounts', $coinbaseAccountArray);
437
 
438
  // map each paypalAccount into its own object
439
- $paypalAccountArray = array();
440
  if (isset($customerAttribs['paypalAccounts'])) {
441
  foreach ($customerAttribs['paypalAccounts'] AS $paypalAccount) {
442
- $paypalAccountArray[] = Braintree_PayPalAccount::factory($paypalAccount);
443
  }
444
  }
445
  $this->_set('paypalAccounts', $paypalAccountArray);
446
 
447
  // map each applePayCard into its own object
448
- $applePayCardArray = array();
449
  if (isset($customerAttribs['applePayCards'])) {
450
  foreach ($customerAttribs['applePayCards'] AS $applePayCard) {
451
- $applePayCardArray[] = Braintree_applePayCard::factory($applePayCard);
452
  }
453
  }
454
  $this->_set('applePayCards', $applePayCardArray);
455
 
456
  // map each androidPayCard into its own object
457
- $androidPayCardArray = array();
458
  if (isset($customerAttribs['androidPayCards'])) {
459
  foreach ($customerAttribs['androidPayCards'] AS $androidPayCard) {
460
- $androidPayCardArray[] = Braintree_AndroidPayCard::factory($androidPayCard);
461
  }
462
  }
463
  $this->_set('androidPayCards', $androidPayCardArray);
@@ -472,19 +475,19 @@ class Braintree_CustomerGateway
472
  public function __toString()
473
  {
474
  return __CLASS__ . '[' .
475
- Braintree_Util::attributesToString($this->_attributes) .']';
476
  }
477
 
478
  /**
479
- * returns false if comparing object is not a Braintree_Customer,
480
- * or is a Braintree_Customer with a different id
481
  *
482
  * @param object $otherCust customer to compare against
483
  * @return boolean
484
  */
485
  public function isEqual($otherCust)
486
  {
487
- return !($otherCust instanceof Braintree_Customer) ? false : $this->id === $otherCust->id;
488
  }
489
 
490
  /**
@@ -500,11 +503,11 @@ class Braintree_CustomerGateway
500
  /**
501
  * returns the customer's default payment method
502
  *
503
- * @return object Braintree_CreditCard | Braintree_PayPalAccount | Braintree_ApplePayCard | Braintree_AndroidPayCard
504
  */
505
  public function defaultPaymentMethod()
506
  {
507
- $defaultPaymentMethods = array_filter($this->paymentMethods, 'Braintree_Customer::_defaultPaymentMethodFilter');
508
  return current($defaultPaymentMethods);
509
  }
510
 
@@ -519,7 +522,7 @@ class Braintree_CustomerGateway
519
  * @access protected
520
  * @var array registry of customer data
521
  */
522
- protected $_attributes = array(
523
  'addresses' => '',
524
  'company' => '',
525
  'creditCards' => '',
@@ -532,7 +535,7 @@ class Braintree_CustomerGateway
532
  'createdAt' => '',
533
  'updatedAt' => '',
534
  'website' => '',
535
- );
536
 
537
  /**
538
  * sends the create request to the gateway
@@ -591,29 +594,30 @@ class Braintree_CustomerGateway
591
  /**
592
  * generic method for validating incoming gateway responses
593
  *
594
- * creates a new Braintree_Customer object and encapsulates
595
- * it inside a Braintree_Result_Successful object, or
596
- * encapsulates a Braintree_Errors object inside a Result_Error
597
  * alternatively, throws an Unexpected exception if the response is invalid.
598
  *
599
  * @ignore
600
  * @param array $response gateway response values
601
- * @return object Result_Successful or Result_Error
602
- * @throws Braintree_Exception_Unexpected
603
  */
604
  private function _verifyGatewayResponse($response)
605
  {
606
  if (isset($response['customer'])) {
607
- // return a populated instance of Braintree_Customer
608
- return new Braintree_Result_Successful(
609
- Braintree_Customer::factory($response['customer'])
610
  );
611
  } else if (isset($response['apiErrorResponse'])) {
612
- return new Braintree_Result_Error($response['apiErrorResponse']);
613
  } else {
614
- throw new Braintree_Exception_Unexpected(
615
  "Expected customer or apiErrorResponse"
616
  );
617
  }
618
  }
619
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
  /**
7
  * Braintree CustomerGateway module
8
  * Creates and manages Customers
13
  *
14
  * @package Braintree
15
  * @category Resources
16
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
17
  */
18
+ class CustomerGateway
19
  {
20
  private $_gateway;
21
  private $_config;
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 all()
33
  {
34
  $path = $this->_config->merchantPath() . '/customers/advanced_search_ids';
35
  $response = $this->_http->post($path);
36
+ $pager = [
37
  'object' => $this,
38
  'method' => 'fetch',
39
+ 'methodArgs' => [[]]
40
+ ];
41
 
42
+ return new ResourceCollection($response, $pager);
43
  }
44
 
45
  public function fetch($query, $ids)
46
  {
47
+ $criteria = [];
48
  foreach ($query as $term) {
49
  $criteria[$term->name] = $term->toparam();
50
  }
51
+ $criteria["ids"] = CustomerSearch::ids()->in($ids)->toparam();
52
  $path = $this->_config->merchantPath() . '/customers/advanced_search';
53
+ $response = $this->_http->post($path, ['search' => $criteria]);
54
 
55
+ return Util::extractattributeasarray(
56
  $response['customers'],
57
  'customer'
58
  );
63
  * the gateway will generate it.
64
  *
65
  * <code>
66
+ * $result = Customer::create(array(
67
  * 'first_name' => 'John',
68
  * 'last_name' => 'Smith',
69
  * 'company' => 'Smith Co.',
81
  *
82
  * @access public
83
  * @param array $attribs
84
+ * @return Braintree_Result_Successful|Braintree_Result_Error
85
  */
86
+ public function create($attribs = [])
87
  {
88
+ Util::verifyKeys(self::createSignature(), $attribs);
89
+ return $this->_doCreate('/customers', ['customer' => $attribs]);
90
  }
91
 
92
  /**
93
  * attempts the create operation assuming all data will validate
94
+ * returns a Customer object instead of a Result
95
  *
96
  * @access public
97
  * @param array $attribs
98
+ * @return Customer
99
+ * @throws Exception\ValidationError
100
  */
101
+ public function createNoValidate($attribs = [])
102
  {
103
  $result = $this->create($attribs);
104
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
105
  }
106
  /**
107
  * create a customer from a TransparentRedirect operation
109
  * @deprecated since version 2.3.0
110
  * @access public
111
  * @param array $attribs
112
+ * @return Customer
113
  */
114
  public function createFromTransparentRedirect($queryString)
115
  {
116
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::confirm", E_USER_NOTICE);
117
+ $params = TransparentRedirect::parseAndValidateQueryString(
118
  $queryString
119
  );
120
  return $this->_doCreate(
121
  '/customers/all/confirm_transparent_redirect_request',
122
+ ['id' => $params['id']]
123
  );
124
  }
125
 
132
  */
133
  public function createCustomerUrl()
134
  {
135
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::url", E_USER_NOTICE);
136
  return $this->_config->baseUrl() . $this->_config->merchantPath() .
137
  '/customers/all/create_via_transparent_redirect_request';
138
  }
145
  public static function createSignature()
146
  {
147
 
148
+ $creditCardSignature = CreditCardGateway::createSignature();
149
  unset($creditCardSignature[array_search('customerId', $creditCardSignature)]);
150
+ $signature = [
151
  'id', 'company', 'email', 'fax', 'firstName',
152
  'lastName', 'phone', 'website', 'deviceData',
153
  'deviceSessionId', 'fraudMerchantId', 'paymentMethodNonce',
154
+ ['creditCard' => $creditCardSignature],
155
+ ['customFields' => ['_anyKey_']],
156
+ ];
157
  return $signature;
158
  }
159
 
163
  */
164
  public static function updateSignature()
165
  {
166
+ $creditCardSignature = CreditCardGateway::updateSignature();
167
 
168
  foreach($creditCardSignature AS $key => $value) {
169
  if(is_array($value) and array_key_exists('options', $value)) {
171
  }
172
  }
173
 
174
+ $signature = [
175
  'id', 'company', 'email', 'fax', 'firstName',
176
  'lastName', 'phone', 'website', 'deviceData',
177
  'deviceSessionId', 'fraudMerchantId', 'paymentMethodNonce',
178
+ ['creditCard' => $creditCardSignature],
179
+ ['customFields' => ['_anyKey_']],
180
+ ];
181
  return $signature;
182
  }
183
 
187
  *
188
  * @access public
189
  * @param string id customer Id
190
+ * @return Customer|boolean The customer object or false if the request fails.
191
+ * @throws Exception\NotFound
192
  */
193
  public function find($id)
194
  {
196
  try {
197
  $path = $this->_config->merchantPath() . '/customers/' . $id;
198
  $response = $this->_http->get($path);
199
+ return Customer::factory($response['customer']);
200
+ } catch (Exception\NotFound $e) {
201
+ throw new Exception\NotFound(
202
  'customer with id ' . $id . ' not found'
203
  );
204
  }
 
205
  }
206
 
207
  /**
210
  * @access public
211
  * @param int $customerId
212
  * @param array $transactionAttribs
213
+ * @return Result\Successful|Result\Error
214
  */
215
  public function credit($customerId, $transactionAttribs)
216
  {
217
  $this->_validateId($customerId);
218
+ return Transaction::credit(
219
  array_merge($transactionAttribs,
220
+ ['customerId' => $customerId]
221
  )
222
  );
223
  }
225
  /**
226
  * credit a customer, assuming validations will pass
227
  *
228
+ * returns a Transaction object on success
229
  *
230
  * @access public
231
  * @param int $customerId
232
  * @param array $transactionAttribs
233
+ * @return Transaction
234
+ * @throws Exception\ValidationError
235
  */
236
  public function creditNoValidate($customerId, $transactionAttribs)
237
  {
238
  $result = $this->credit($customerId, $transactionAttribs);
239
+ return Util::returnObjectOrThrowException('Braintree\Transaction', $result);
240
  }
241
 
242
  /**
249
  $this->_validateId($customerId);
250
  $path = $this->_config->merchantPath() . '/customers/' . $customerId;
251
  $this->_http->delete($path);
252
+ return new Result\Successful();
253
  }
254
 
255
  /**
257
  *
258
  * @param string $customerId
259
  * @param array $transactionAttribs
260
+ * @return Result\Successful|Result\Error
261
+ * @see Transaction::sale()
262
  */
263
  public function sale($customerId, $transactionAttribs)
264
  {
265
  $this->_validateId($customerId);
266
+ return Transaction::sale(
267
  array_merge($transactionAttribs,
268
+ ['customerId' => $customerId]
269
  )
270
  );
271
  }
273
  /**
274
  * create a new sale for a customer, assuming validations will pass
275
  *
276
+ * returns a Transaction object on success
277
  * @access public
278
  * @param string $customerId
279
  * @param array $transactionAttribs
280
+ * @return Transaction
281
+ * @throws Exception\ValidationsFailed
282
+ * @see Transaction::sale()
283
  */
284
  public function saleNoValidate($customerId, $transactionAttribs)
285
  {
286
  $result = $this->sale($customerId, $transactionAttribs);
287
+ return Util::returnObjectOrThrowException('Braintree\Transaction', $result);
288
  }
289
 
290
  /**
295
  * For more detailed information and examples, see {@link http://www.braintreepayments.com/gateway/customer-api#searching http://www.braintreepaymentsolutions.com/gateway/customer-api}
296
  *
297
  * @param mixed $query search query
298
+ * @return ResourceCollection
299
  * @throws InvalidArgumentException
300
  */
301
  public function search($query)
302
  {
303
+ $criteria = [];
304
  foreach ($query as $term) {
305
  $result = $term->toparam();
306
  if(is_null($result) || empty($result)) {
311
  }
312
 
313
  $path = $this->_config->merchantPath() . '/customers/advanced_search_ids';
314
+ $response = $this->_http->post($path, ['search' => $criteria]);
315
+ $pager = [
316
  'object' => $this,
317
  'method' => 'fetch',
318
+ 'methodArgs' => [$query]
319
+ ];
320
 
321
+ return new ResourceCollection($response, $pager);
322
  }
323
 
324
  /**
330
  * @access public
331
  * @param string $customerId (optional)
332
  * @param array $attributes
333
+ * @return Result\Successful|Result\Error
334
  */
335
  public function update($customerId, $attributes)
336
  {
337
+ Util::verifyKeys(self::updateSignature(), $attributes);
338
  $this->_validateId($customerId);
339
  return $this->_doUpdate(
340
  'put',
341
  '/customers/' . $customerId,
342
+ ['customer' => $attributes]
343
  );
344
  }
345
 
348
  *
349
  * if calling this method in static context, customerId
350
  * is the 2nd attribute. customerId is not sent in object context.
351
+ * returns a Customer object on success
352
  *
353
  * @access public
354
  * @param string $customerId
355
  * @param array $attributes
356
+ * @return Customer
357
+ * @throws Exception\ValidationsFailed
358
  */
359
  public function updateNoValidate($customerId, $attributes)
360
  {
361
  $result = $this->update($customerId, $attributes);
362
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
363
  }
364
  /**
365
  *
369
  */
370
  public function updateCustomerUrl()
371
  {
372
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::url", E_USER_NOTICE);
373
  return $this->_config->baseUrl() . $this->_config->merchantPath() .
374
  '/customers/all/update_via_transparent_redirect_request';
375
  }
384
  */
385
  public function updateFromTransparentRedirect($queryString)
386
  {
387
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::confirm", E_USER_NOTICE);
388
+ $params = TransparentRedirect::parseAndValidateQueryString(
389
  $queryString
390
  );
391
  return $this->_doUpdate(
392
  'post',
393
  '/customers/all/confirm_transparent_redirect_request',
394
+ ['id' => $params['id']]
395
  );
396
  }
397
 
403
  * @ignore
404
  * @access protected
405
  * @param array $customerAttribs array of customer data
406
+ * @return void
407
  */
408
  protected function _initialize($customerAttribs)
409
  {
411
  $this->_attributes = $customerAttribs;
412
 
413
  // map each address into its own object
414
+ $addressArray = [];
415
  if (isset($customerAttribs['addresses'])) {
416
 
417
  foreach ($customerAttribs['addresses'] AS $address) {
418
+ $addressArray[] = Address::factory($address);
419
  }
420
  }
421
  $this->_set('addresses', $addressArray);
422
 
423
  // map each creditCard into its own object
424
+ $creditCardArray = [];
425
  if (isset($customerAttribs['creditCards'])) {
426
  foreach ($customerAttribs['creditCards'] AS $creditCard) {
427
+ $creditCardArray[] = CreditCard::factory($creditCard);
428
  }
429
  }
430
  $this->_set('creditCards', $creditCardArray);
431
 
432
  // map each coinbaseAccount into its own object
433
+ $coinbaseAccountArray = [];
434
  if (isset($customerAttribs['coinbaseAccounts'])) {
435
  foreach ($customerAttribs['coinbaseAccounts'] AS $coinbaseAccount) {
436
+ $coinbaseAccountArray[] = CoinbaseAccount::factory($coinbaseAccount);
437
  }
438
  }
439
  $this->_set('coinbaseAccounts', $coinbaseAccountArray);
440
 
441
  // map each paypalAccount into its own object
442
+ $paypalAccountArray = [];
443
  if (isset($customerAttribs['paypalAccounts'])) {
444
  foreach ($customerAttribs['paypalAccounts'] AS $paypalAccount) {
445
+ $paypalAccountArray[] = PayPalAccount::factory($paypalAccount);
446
  }
447
  }
448
  $this->_set('paypalAccounts', $paypalAccountArray);
449
 
450
  // map each applePayCard into its own object
451
+ $applePayCardArray = [];
452
  if (isset($customerAttribs['applePayCards'])) {
453
  foreach ($customerAttribs['applePayCards'] AS $applePayCard) {
454
+ $applePayCardArray[] = ApplePayCard::factory($applePayCard);
455
  }
456
  }
457
  $this->_set('applePayCards', $applePayCardArray);
458
 
459
  // map each androidPayCard into its own object
460
+ $androidPayCardArray = [];
461
  if (isset($customerAttribs['androidPayCards'])) {
462
  foreach ($customerAttribs['androidPayCards'] AS $androidPayCard) {
463
+ $androidPayCardArray[] = AndroidPayCard::factory($androidPayCard);
464
  }
465
  }
466
  $this->_set('androidPayCards', $androidPayCardArray);
475
  public function __toString()
476
  {
477
  return __CLASS__ . '[' .
478
+ Util::attributesToString($this->_attributes) .']';
479
  }
480
 
481
  /**
482
+ * returns false if comparing object is not a Customer,
483
+ * or is a Customer with a different id
484
  *
485
  * @param object $otherCust customer to compare against
486
  * @return boolean
487
  */
488
  public function isEqual($otherCust)
489
  {
490
+ return !($otherCust instanceof Customer) ? false : $this->id === $otherCust->id;
491
  }
492
 
493
  /**
503
  /**
504
  * returns the customer's default payment method
505
  *
506
+ * @return CreditCard|PayPalAccount|ApplePayCard|AndroidPayCard
507
  */
508
  public function defaultPaymentMethod()
509
  {
510
+ $defaultPaymentMethods = array_filter($this->paymentMethods, 'Braintree\\Customer::_defaultPaymentMethodFilter');
511
  return current($defaultPaymentMethods);
512
  }
513
 
522
  * @access protected
523
  * @var array registry of customer data
524
  */
525
+ protected $_attributes = [
526
  'addresses' => '',
527
  'company' => '',
528
  'creditCards' => '',
535
  'createdAt' => '',
536
  'updatedAt' => '',
537
  'website' => '',
538
+ ];
539
 
540
  /**
541
  * sends the create request to the gateway
594
  /**
595
  * generic method for validating incoming gateway responses
596
  *
597
+ * creates a new Customer object and encapsulates
598
+ * it inside a Result\Successful object, or
599
+ * encapsulates a Errors object inside a Result\Error
600
  * alternatively, throws an Unexpected exception if the response is invalid.
601
  *
602
  * @ignore
603
  * @param array $response gateway response values
604
+ * @return Result\Successful|Result\Error
605
+ * @throws Exception\Unexpected
606
  */
607
  private function _verifyGatewayResponse($response)
608
  {
609
  if (isset($response['customer'])) {
610
+ // return a populated instance of Customer
611
+ return new Result\Successful(
612
+ Customer::factory($response['customer'])
613
  );
614
  } else if (isset($response['apiErrorResponse'])) {
615
+ return new Result\Error($response['apiErrorResponse']);
616
  } else {
617
+ throw new Exception\Unexpected(
618
  "Expected customer or apiErrorResponse"
619
  );
620
  }
621
  }
622
  }
623
+ class_alias('Braintree\CustomerGateway', 'Braintree_CustomerGateway');
braintree_sdk/lib/Braintree/CustomerSearch.php CHANGED
@@ -1,31 +1,34 @@
1
  <?php
2
- class Braintree_CustomerSearch
 
 
3
  {
4
- static function addressCountryName() { return new Braintree_TextNode('address_country_name'); }
5
- static function addressExtendedAddress() { return new Braintree_TextNode('address_extended_address'); }
6
- static function addressFirstName() { return new Braintree_TextNode('address_first_name'); }
7
- static function addressLastName() { return new Braintree_TextNode('address_last_name'); }
8
- static function addressLocality() { return new Braintree_TextNode('address_locality'); }
9
- static function addressPostalCode() { return new Braintree_TextNode('address_postal_code'); }
10
- static function addressRegion() { return new Braintree_TextNode('address_region'); }
11
- static function addressStreetAddress() { return new Braintree_TextNode('address_street_address'); }
12
- static function cardholderName() { return new Braintree_TextNode('cardholder_name'); }
13
- static function company() { return new Braintree_TextNode('company'); }
14
- static function email() { return new Braintree_TextNode('email'); }
15
- static function fax() { return new Braintree_TextNode('fax'); }
16
- static function firstName() { return new Braintree_TextNode('first_name'); }
17
- static function id() { return new Braintree_TextNode('id'); }
18
- static function lastName() { return new Braintree_TextNode('last_name'); }
19
- static function paymentMethodToken() { return new Braintree_TextNode('payment_method_token'); }
20
- static function paymentMethodTokenWithDuplicates() { return new Braintree_IsNode('payment_method_token_with_duplicates'); }
21
- static function paypalAccountEmail() { return new Braintree_IsNode('paypal_account_email'); }
22
- static function phone() { return new Braintree_TextNode('phone'); }
23
- static function website() { return new Braintree_TextNode('website'); }
24
 
25
- static function creditCardExpirationDate() { return new Braintree_EqualityNode('credit_card_expiration_date'); }
26
- static function creditCardNumber() { return new Braintree_PartialMatchNode('credit_card_number'); }
27
 
28
- static function ids() { return new Braintree_MultipleValueNode('ids'); }
29
 
30
- static function createdAt() { return new Braintree_RangeNode("created_at"); }
31
  }
 
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');
braintree_sdk/lib/Braintree/Descriptor.php CHANGED
@@ -1,4 +1,7 @@
1
  <?php
2
- class Braintree_Descriptor extends Braintree_Instance
 
 
3
  {
4
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ class Descriptor extends Instance
5
  {
6
  }
7
+ class_alias('Braintree\Descriptor', 'Braintree_Descriptor');
braintree_sdk/lib/Braintree/Digest.php CHANGED
@@ -1,11 +1,13 @@
1
  <?php
 
 
2
  /**
3
  * Digest encryption module
4
  * Digest creates an HMAC-SHA1 hash for encrypting messages
5
  *
6
- * @copyright 2014 Braintree, a division of PayPal, Inc.
7
  */
8
- class Braintree_Digest
9
  {
10
  public static function hexDigestSha1($key, $string)
11
  {
@@ -57,3 +59,4 @@ class Braintree_Digest
57
  return sha1($outerPad.pack($pack, sha1($innerPad.$message)));
58
  }
59
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Digest encryption module
6
  * Digest creates an HMAC-SHA1 hash for encrypting messages
7
  *
8
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
9
  */
10
+ class Digest
11
  {
12
  public static function hexDigestSha1($key, $string)
13
  {
59
  return sha1($outerPad.pack($pack, sha1($innerPad.$message)));
60
  }
61
  }
62
+ class_alias('Braintree\Digest', 'Braintree_Digest');
braintree_sdk/lib/Braintree/Disbursement.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- final class Braintree_Disbursement extends Braintree_Base
 
 
3
  {
4
  private $_merchantAccount;
5
 
@@ -10,16 +12,16 @@ final class Braintree_Disbursement extends Braintree_Base
10
 
11
  if (isset($disbursementAttribs['merchantAccount'])) {
12
  $this->_set('merchantAccount',
13
- Braintree_MerchantAccount::factory($disbursementAttribs['merchantAccount'])
14
  );
15
  }
16
  }
17
 
18
  public function transactions()
19
  {
20
- $collection = Braintree_Transaction::search(array(
21
- Braintree_TransactionSearch::ids()->in($this->transactionIds)
22
- ));
23
 
24
  return $collection;
25
  }
@@ -33,17 +35,18 @@ final class Braintree_Disbursement extends Braintree_Base
33
 
34
  public function __toString()
35
  {
36
- $display = array(
37
  'id', 'merchantAccountDetails', 'exceptionMessage', 'amount',
38
  'disbursementDate', 'followUpAction', 'retry', 'success',
39
  'transactionIds'
40
- );
41
 
42
- $displayAttributes = array();
43
  foreach ($display AS $attrib) {
44
  $displayAttributes[$attrib] = $this->$attrib;
45
  }
46
  return __CLASS__ . '[' .
47
- Braintree_Util::attributesToString($displayAttributes) .']';
48
  }
49
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ final class Disbursement extends Base
5
  {
6
  private $_merchantAccount;
7
 
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
  }
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');
braintree_sdk/lib/Braintree/DisbursementDetails.php CHANGED
@@ -1,11 +1,13 @@
1
  <?php
 
 
2
  /**
3
  * Disbursement details from a transaction
4
  * Creates an instance of DisbursementDetails as returned from a transaction
5
  *
6
  *
7
  * @package Braintree
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  *
10
  * @property-read string $settlementAmount
11
  * @property-read string $settlementCurrencyIsoCode
@@ -13,13 +15,11 @@
13
  * @property-read string $fundsHeld
14
  * @property-read string $success
15
  * @property-read string $disbursementDate
16
- * @uses Braintree_Instance inherits methods
17
  */
18
- class Braintree_DisbursementDetails extends Braintree_Instance
19
  {
20
- protected $_attributes = array();
21
-
22
- function isValid() {
23
  return !is_null($this->disbursementDate);
24
  }
25
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
11
  *
12
  * @property-read string $settlementAmount
13
  * @property-read string $settlementCurrencyIsoCode
15
  * @property-read string $fundsHeld
16
  * @property-read string $success
17
  * @property-read string $disbursementDate
 
18
  */
19
+ class DisbursementDetails extends Instance
20
  {
21
+ public function isValid() {
 
 
22
  return !is_null($this->disbursementDate);
23
  }
24
  }
25
+ class_alias('Braintree\DisbursementDetails', 'Braintree_DisbursementDetails');
braintree_sdk/lib/Braintree/Discount.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_Discount extends Braintree_Modification
 
 
3
  {
4
  public static function factory($attributes)
5
  {
@@ -13,6 +15,7 @@ class Braintree_Discount extends Braintree_Modification
13
 
14
  public static function all()
15
  {
16
- return Braintree_Configuration::gateway()->discount()->all();
17
  }
18
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ class Discount extends Modification
5
  {
6
  public static function factory($attributes)
7
  {
15
 
16
  public static function all()
17
  {
18
+ return Configuration::gateway()->discount()->all();
19
  }
20
  }
21
+ class_alias('Braintree\Discount', 'Braintree_Discount');
braintree_sdk/lib/Braintree/DiscountGateway.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_DiscountGateway
 
 
3
  {
4
  private $_gateway;
5
  private $_config;
@@ -10,7 +12,7 @@ class Braintree_DiscountGateway
10
  $this->_gateway = $gateway;
11
  $this->_config = $gateway->config;
12
  $this->_config->assertHasAccessTokenOrKeys();
13
- $this->_http = new Braintree_Http($gateway->config);
14
  }
15
 
16
  public function all()
@@ -18,11 +20,12 @@ class Braintree_DiscountGateway
18
  $path = $this->_config->merchantPath() . '/discounts';
19
  $response = $this->_http->get($path);
20
 
21
- $discounts = array("discount" => $response['discounts']);
22
 
23
- return Braintree_Util::extractAttributeAsArray(
24
  $discounts,
25
  'discount'
26
  );
27
  }
28
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ class DiscountGateway
5
  {
6
  private $_gateway;
7
  private $_config;
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()
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');
braintree_sdk/lib/Braintree/Dispute.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
 
 
2
  /**
3
  * Creates an instance of Dispute as returned from a transaction
4
  *
5
  *
6
  * @package Braintree
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  *
9
  * @property-read string $amount
10
  * @property-read string $currencyIsoCode
@@ -14,9 +16,9 @@
14
  * @property-read string $disbursementDate
15
  * @property-read object $transactionDetails
16
  */
17
- final class Braintree_Dispute extends Braintree_Base
18
  {
19
- protected $_attributes = array();
20
 
21
  /* Dispute Status */
22
  const OPEN = 'open';
@@ -39,6 +41,10 @@ final class Braintree_Dispute extends Braintree_Base
39
  const TRANSACTION_AMOUNT_DIFFERS = "transaction_amount_differs";
40
  const RETRIEVAL = "retrieval";
41
 
 
 
 
 
42
 
43
  protected function _initialize($disputeAttribs)
44
  {
@@ -46,7 +52,7 @@ final class Braintree_Dispute extends Braintree_Base
46
 
47
  if (isset($disputeAttribs['transaction'])) {
48
  $this->_set('transactionDetails',
49
- new Braintree_Dispute_TransactionDetails($disputeAttribs['transaction'])
50
  );
51
  }
52
  }
@@ -60,16 +66,17 @@ final class Braintree_Dispute extends Braintree_Base
60
 
61
  public function __toString()
62
  {
63
- $display = array(
64
  'amount', 'reason', 'status',
65
  'replyByDate', 'receivedDate', 'currencyIsoCode'
66
- );
67
 
68
- $displayAttributes = array();
69
  foreach ($display AS $attrib) {
70
  $displayAttributes[$attrib] = $this->$attrib;
71
  }
72
  return __CLASS__ . '[' .
73
- Braintree_Util::attributesToString($displayAttributes) .']';
74
  }
75
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Creates an instance of Dispute as returned from a transaction
6
  *
7
  *
8
  * @package Braintree
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  *
11
  * @property-read string $amount
12
  * @property-read string $currencyIsoCode
16
  * @property-read string $disbursementDate
17
  * @property-read object $transactionDetails
18
  */
19
+ final class Dispute extends Base
20
  {
21
+ protected $_attributes = [];
22
 
23
  /* Dispute Status */
24
  const OPEN = 'open';
41
  const TRANSACTION_AMOUNT_DIFFERS = "transaction_amount_differs";
42
  const RETRIEVAL = "retrieval";
43
 
44
+ /* Dispute Kind */
45
+ const CHARGEBACK = 'chargeback';
46
+ const PRE_ARBITRATION = 'pre_arbitration';
47
+ // RETRIEVAL for kind already defined under Dispute Reason
48
 
49
  protected function _initialize($disputeAttribs)
50
  {
52
 
53
  if (isset($disputeAttribs['transaction'])) {
54
  $this->_set('transactionDetails',
55
+ new Dispute\TransactionDetails($disputeAttribs['transaction'])
56
  );
57
  }
58
  }
66
 
67
  public function __toString()
68
  {
69
+ $display = [
70
  'amount', 'reason', 'status',
71
  'replyByDate', 'receivedDate', 'currencyIsoCode'
72
+ ];
73
 
74
+ $displayAttributes = [];
75
  foreach ($display AS $attrib) {
76
  $displayAttributes[$attrib] = $this->$attrib;
77
  }
78
  return __CLASS__ . '[' .
79
+ Util::attributesToString($displayAttributes) .']';
80
  }
81
  }
82
+ class_alias('Braintree\Dispute', 'Braintree_Dispute');
braintree_sdk/lib/Braintree/Dispute/TransactionDetails.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Transaction details for a dispute
4
  *
@@ -15,8 +19,9 @@
15
  *
16
  * @property-read string $amount
17
  * @property-read string $id
18
- * @uses Braintree_Instance inherits methods
19
  */
20
- class Braintree_Dispute_TransactionDetails extends Braintree_Instance
21
  {
22
  }
 
 
1
  <?php
2
+ namespace Braintree\Dispute;
3
+
4
+ use Braintree\Instance;
5
+
6
  /**
7
  * Transaction details for a dispute
8
  *
19
  *
20
  * @property-read string $amount
21
  * @property-read string $id
 
22
  */
23
+ class TransactionDetails extends Instance
24
  {
25
  }
26
+
27
+ class_alias('Braintree\Dispute\TransactionDetails', 'Braintree_Dispute_TransactionDetails');
braintree_sdk/lib/Braintree/EqualityNode.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
 
2
 
3
- class Braintree_EqualityNode extends Braintree_IsNode
4
  {
5
  function isNot($value)
6
  {
@@ -8,3 +9,4 @@ class Braintree_EqualityNode extends Braintree_IsNode
8
  return $this;
9
  }
10
  }
 
1
  <?php
2
+ namespace Braintree;
3
 
4
+ class EqualityNode extends IsNode
5
  {
6
  function isNot($value)
7
  {
9
  return $this;
10
  }
11
  }
12
+ class_alias('Braintree\EqualityNode', 'Braintree_EqualityNode');
braintree_sdk/lib/Braintree/Error/Codes.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  /**
3
  *
4
  * Validation Error codes and messages
@@ -12,9 +14,9 @@
12
  * @package Braintree
13
  * @subpackage Errors
14
  * @category Validation
15
- * @copyright 2014 Braintree, a division of PayPal, Inc.
16
  */
17
- class Braintree_Error_Codes
18
  {
19
  const ADDRESS_CANNOT_BE_BLANK = '81801';
20
  const ADDRESS_COMPANY_IS_INVALID = '91821';
@@ -106,6 +108,7 @@ class Braintree_Error_Codes
106
  const CREDIT_CARD_INVALID_VENMO_SDK_PAYMENT_METHOD_CODE = '91727';
107
  const CREDIT_CARD_NUMBER_INVALID_LENGTH = '81716';
108
  const CREDIT_CARD_NUMBER_IS_INVALID = '81715';
 
109
  const CREDIT_CARD_NUMBER_IS_REQUIRED = '81714';
110
  const CREDIT_CARD_NUMBER_LENGTH_IS_INVALID = '81716';
111
  const CREDIT_CARD_NUMBER_MUST_BE_TEST_NUMBER = '81717';
@@ -423,6 +426,7 @@ class Braintree_Error_Codes
423
  const TRANSACTION_CANNOT_REFUND_WITH_SUSPENDED_MERCHANT_ACCOUNT = '91538';
424
  const TRANSACTION_CANNOT_RELEASE_FROM_ESCROW = '91561';
425
  const TRANSACTION_CANNOT_SIMULATE_SETTLEMENT = '91575';
 
426
  const TRANSACTION_CANNOT_SUBMIT_FOR_SETTLEMENT = '91507';
427
  const TRANSACTION_CHANNEL_IS_TOO_LONG = '91550';
428
  const TRANSACTION_CREDIT_CARD_IS_REQUIRED = '91508';
@@ -445,6 +449,7 @@ class Braintree_Error_Codes
445
  const TRANSACTION_OPTIONS_VAULT_IS_DISABLED = '91525';
446
  const TRANSACTION_ORDER_ID_IS_TOO_LONG = '91501';
447
  const TRANSACTION_PAYMENT_INSTRUMENT_NOT_SUPPORTED_BY_MERCHANT_ACCOUNT = '91577';
 
448
  const TRANSACTION_PAYMENT_METHOD_CONFLICT = '91515';
449
  const TRANSACTION_PAYMENT_METHOD_CONFLICT_WITH_VENMO_SDK = '91549';
450
  const TRANSACTION_PAYMENT_METHOD_DOES_NOT_BELONG_TO_CUSTOMER = '91516';
@@ -461,7 +466,11 @@ class Braintree_Error_Codes
461
  const TRANSACTION_PAY_PAL_VAULT_RECORD_MISSING_DATA = '91583';
462
  const TRANSACTION_PROCESSOR_AUTHORIZATION_CODE_CANNOT_BE_SET = '91519';
463
  const TRANSACTION_PROCESSOR_AUTHORIZATION_CODE_IS_INVALID = '81520';
 
464
  const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_CREDITS = '91546';
 
 
 
465
  const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_VOICE_AUTHORIZATIONS = '91545';
466
  const TRANSACTION_PURCHASE_ORDER_NUMBER_IS_INVALID = '91548';
467
  const TRANSACTION_PURCHASE_ORDER_NUMBER_IS_TOO_LONG = '91537';
@@ -489,4 +498,12 @@ class Braintree_Error_Codes
489
  const TRANSACTION_TYPE_IS_INVALID = '91523';
490
  const TRANSACTION_TYPE_IS_REQUIRED = '91524';
491
  const TRANSACTION_UNSUPPORTED_VOICE_AUTHORIZATION = '91539';
 
 
 
 
 
 
 
492
  }
 
1
  <?php
2
+ namespace Braintree\Error;
3
+
4
  /**
5
  *
6
  * Validation Error codes and messages
14
  * @package Braintree
15
  * @subpackage Errors
16
  * @category Validation
17
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
18
  */
19
+ class Codes
20
  {
21
  const ADDRESS_CANNOT_BE_BLANK = '81801';
22
  const ADDRESS_COMPANY_IS_INVALID = '91821';
108
  const CREDIT_CARD_INVALID_VENMO_SDK_PAYMENT_METHOD_CODE = '91727';
109
  const CREDIT_CARD_NUMBER_INVALID_LENGTH = '81716';
110
  const CREDIT_CARD_NUMBER_IS_INVALID = '81715';
111
+ const CREDIT_CARD_NUMBER_IS_PROHIBITED = '81750';
112
  const CREDIT_CARD_NUMBER_IS_REQUIRED = '81714';
113
  const CREDIT_CARD_NUMBER_LENGTH_IS_INVALID = '81716';
114
  const CREDIT_CARD_NUMBER_MUST_BE_TEST_NUMBER = '81717';
426
  const TRANSACTION_CANNOT_REFUND_WITH_SUSPENDED_MERCHANT_ACCOUNT = '91538';
427
  const TRANSACTION_CANNOT_RELEASE_FROM_ESCROW = '91561';
428
  const TRANSACTION_CANNOT_SIMULATE_SETTLEMENT = '91575';
429
+ const TRANSACTION_CANNOT_SUBMIT_FOR_PARTIAL_SETTLEMENT = '915103';
430
  const TRANSACTION_CANNOT_SUBMIT_FOR_SETTLEMENT = '91507';
431
  const TRANSACTION_CHANNEL_IS_TOO_LONG = '91550';
432
  const TRANSACTION_CREDIT_CARD_IS_REQUIRED = '91508';
449
  const TRANSACTION_OPTIONS_VAULT_IS_DISABLED = '91525';
450
  const TRANSACTION_ORDER_ID_IS_TOO_LONG = '91501';
451
  const TRANSACTION_PAYMENT_INSTRUMENT_NOT_SUPPORTED_BY_MERCHANT_ACCOUNT = '91577';
452
+ const TRANSACTION_PAYMENT_INSTRUMENT_TYPE_IS_NOT_ACCEPTED = '915101';
453
  const TRANSACTION_PAYMENT_METHOD_CONFLICT = '91515';
454
  const TRANSACTION_PAYMENT_METHOD_CONFLICT_WITH_VENMO_SDK = '91549';
455
  const TRANSACTION_PAYMENT_METHOD_DOES_NOT_BELONG_TO_CUSTOMER = '91516';
466
  const TRANSACTION_PAY_PAL_VAULT_RECORD_MISSING_DATA = '91583';
467
  const TRANSACTION_PROCESSOR_AUTHORIZATION_CODE_CANNOT_BE_SET = '91519';
468
  const TRANSACTION_PROCESSOR_AUTHORIZATION_CODE_IS_INVALID = '81520';
469
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_AUTHS = '915104';
470
  const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_CREDITS = '91546';
471
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_PARTIAL_SETTLEMENT = '915102';
472
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_UPDATING_ORDER_ID = '915107';
473
+ const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_UPDATING_DESCRIPTOR = '915108';
474
  const TRANSACTION_PROCESSOR_DOES_NOT_SUPPORT_VOICE_AUTHORIZATIONS = '91545';
475
  const TRANSACTION_PURCHASE_ORDER_NUMBER_IS_INVALID = '91548';
476
  const TRANSACTION_PURCHASE_ORDER_NUMBER_IS_TOO_LONG = '91537';
498
  const TRANSACTION_TYPE_IS_INVALID = '91523';
499
  const TRANSACTION_TYPE_IS_REQUIRED = '91524';
500
  const TRANSACTION_UNSUPPORTED_VOICE_AUTHORIZATION = '91539';
501
+
502
+ const VERIFICATION_OPTIONS_AMOUNT_CANNOT_BE_NEGATIVE = '94201';
503
+ const VERIFICATION_OPTIONS_AMOUNT_FORMAT_IS_INVALID = '94202';
504
+ const VERIFICATION_OPTIONS_AMOUNT_NOT_SUPPORTED_BY_PROCESSOR = '94203';
505
+ const VERIFICATION_OPTIONS_MERCHANT_ACCOUNT_ID_IS_INVALID = '94204';
506
+ const VERIFICATION_OPTIONS_MERCHANT_ACCOUNT_IS_SUSPENDED = '94205';
507
+ const VERIFICATION_OPTIONS_MERCHANT_ACCOUNT_IS_FORBIDDEN = '94206';
508
  }
509
+ class_alias('Braintree\Error\Codes', 'Braintree_Error_Codes');
braintree_sdk/lib/Braintree/Error/ErrorCollection.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  *
4
  * Error handler
@@ -9,18 +13,18 @@
9
  * @package Braintree
10
  * @subpackage Errors
11
  * @category Errors
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read object $errors
15
  */
16
- class Braintree_Error_ErrorCollection
17
  {
18
  private $_errors;
19
 
20
  public function __construct($errorData)
21
  {
22
  $this->_errors =
23
- new Braintree_Error_ValidationErrorCollection($errorData);
24
  }
25
 
26
 
@@ -68,10 +72,10 @@ class Braintree_Error_ErrorCollection
68
  $pieces = preg_split("/[\[\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY);
69
  $errors = $this;
70
  foreach(array_slice($pieces, 0, -1) as $key) {
71
- $errors = $errors->forKey(Braintree_Util::delimiterToCamelCase($key));
72
- if (!isset($errors)) { return array(); }
73
  }
74
- $finalKey = Braintree_Util::delimiterToCamelCase(end($pieces));
75
  return $errors->onAttribute($finalKey);
76
  }
77
 
@@ -79,7 +83,7 @@ class Braintree_Error_ErrorCollection
79
  * Returns the errors at the given nesting level (see forKey) in a single, flat array:
80
  *
81
  * <code>
82
- * $result = Braintree_Customer::create(...);
83
  * $customerErrors = $result->errors->forKey('customer')->shallowAll();
84
  * </code>
85
  */
@@ -107,3 +111,4 @@ class Braintree_Error_ErrorCollection
107
  return sprintf('%s', $this->_errors);
108
  }
109
  }
 
1
  <?php
2
+ namespace Braintree\Error;
3
+
4
+ use Braintree\Util;
5
+
6
  /**
7
  *
8
  * Error handler
13
  * @package Braintree
14
  * @subpackage Errors
15
  * @category Errors
16
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
17
  *
18
  * @property-read object $errors
19
  */
20
+ class ErrorCollection
21
  {
22
  private $_errors;
23
 
24
  public function __construct($errorData)
25
  {
26
  $this->_errors =
27
+ new ValidationErrorCollection($errorData);
28
  }
29
 
30
 
72
  $pieces = preg_split("/[\[\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY);
73
  $errors = $this;
74
  foreach(array_slice($pieces, 0, -1) as $key) {
75
+ $errors = $errors->forKey(Util::delimiterToCamelCase($key));
76
+ if (!isset($errors)) { return []; }
77
  }
78
+ $finalKey = Util::delimiterToCamelCase(end($pieces));
79
  return $errors->onAttribute($finalKey);
80
  }
81
 
83
  * Returns the errors at the given nesting level (see forKey) in a single, flat array:
84
  *
85
  * <code>
86
+ * $result = Customer::create(...);
87
  * $customerErrors = $result->errors->forKey('customer')->shallowAll();
88
  * </code>
89
  */
111
  return sprintf('%s', $this->_errors);
112
  }
113
  }
114
+ class_alias('Braintree\Error\ErrorCollection', 'Braintree_Error_ErrorCollection');
braintree_sdk/lib/Braintree/Error/Validation.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * error object returned as part of a validation error collection
4
  * provides read-only access to $attribute, $code, and $message
@@ -9,17 +13,17 @@
9
  *
10
  * @package Braintree
11
  * @subpackage Error
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read string $attribute
15
  * @property-read string $code
16
  * @property-read string $message
17
  */
18
- class Braintree_Error_Validation
19
  {
20
- private $_attribute;
21
- private $_code;
22
- private $_message;
23
 
24
  /**
25
  * @ignore
@@ -34,13 +38,13 @@ class Braintree_Error_Validation
34
  * @ignore
35
  * @access protected
36
  * @param array $attributes array of properties to set - single level
37
- * @return none
38
  */
39
  private function _initializeFromArray($attributes)
40
  {
41
  foreach($attributes AS $name => $value) {
42
  $varName = "_$name";
43
- $this->$varName = Braintree_Util::delimiterToCamelCase($value, '_');
44
  }
45
  }
46
 
@@ -54,3 +58,4 @@ class Braintree_Error_Validation
54
  return isset($this->$varName) ? $this->$varName : null;
55
  }
56
  }
 
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
13
  *
14
  * @package Braintree
15
  * @subpackage Error
16
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
17
  *
18
  * @property-read string $attribute
19
  * @property-read string $code
20
  * @property-read string $message
21
  */
22
+ class Validation
23
  {
24
+ private $_attribute;
25
+ private $_code;
26
+ private $_message;
27
 
28
  /**
29
  * @ignore
38
  * @ignore
39
  * @access protected
40
  * @param array $attributes array of properties to set - single level
41
+ * @return void
42
  */
43
  private function _initializeFromArray($attributes)
44
  {
45
  foreach($attributes AS $name => $value) {
46
  $varName = "_$name";
47
+ $this->$varName = Util::delimiterToCamelCase($value, '_');
48
  }
49
  }
50
 
58
  return isset($this->$varName) ? $this->$varName : null;
59
  }
60
  }
61
+ class_alias('Braintree\Error\Validation', 'Braintree_Error_Validation');
braintree_sdk/lib/Braintree/Error/ValidationErrorCollection.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * collection of errors enumerating all validation errors for a given request
4
  *
@@ -8,15 +12,15 @@
8
  *
9
  * @package Braintree
10
  * @subpackage Error
11
- * @copyright 2014 Braintree, a division of PayPal, Inc.
12
  *
13
  * @property-read array $errors
14
  * @property-read array $nested
15
  */
16
- class Braintree_Error_ValidationErrorCollection extends Braintree_Collection
17
  {
18
- private $_errors = array();
19
- private $_nested = array();
20
 
21
  /**
22
  * @ignore
@@ -27,17 +31,17 @@ class Braintree_Error_ValidationErrorCollection extends Braintree_Collection
27
  // map errors to new collections recursively
28
  if ($key == 'errors') {
29
  foreach ($errorData AS $error) {
30
- $this->_errors[] = new Braintree_Error_Validation($error);
31
  }
32
  } else {
33
- $this->_nested[$key] = new Braintree_Error_ValidationErrorCollection($errorData);
34
  }
35
 
36
  }
37
 
38
  public function deepAll()
39
  {
40
- $validationErrors = array_merge(array(), $this->_errors);
41
  foreach($this->_nested as $nestedErrors)
42
  {
43
  $validationErrors = array_merge($validationErrors, $nestedErrors->deepAll());
@@ -67,7 +71,7 @@ class Braintree_Error_ValidationErrorCollection extends Braintree_Collection
67
 
68
  public function onAttribute($attribute)
69
  {
70
- $matches = array();
71
  foreach ($this->_errors AS $key => $error) {
72
  if($error->attribute == $attribute) {
73
  $matches[] = $error;
@@ -97,7 +101,7 @@ class Braintree_Error_ValidationErrorCollection extends Braintree_Collection
97
  */
98
  public function __toString()
99
  {
100
- $output = array();
101
 
102
  // TODO: implement scope
103
  if (!empty($this->_errors)) {
@@ -125,3 +129,4 @@ class Braintree_Error_ValidationErrorCollection extends Braintree_Collection
125
  return $eOutput;
126
  }
127
  }
 
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
  *
12
  *
13
  * @package Braintree
14
  * @subpackage Error
15
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
16
  *
17
  * @property-read array $errors
18
  * @property-read array $nested
19
  */
20
+ class ValidationErrorCollection extends Collection
21
  {
22
+ private $_errors = [];
23
+ private $_nested = [];
24
 
25
  /**
26
  * @ignore
31
  // map errors to new collections recursively
32
  if ($key == 'errors') {
33
  foreach ($errorData AS $error) {
34
+ $this->_errors[] = new Validation($error);
35
  }
36
  } else {
37
+ $this->_nested[$key] = new ValidationErrorCollection($errorData);
38
  }
39
 
40
  }
41
 
42
  public function deepAll()
43
  {
44
+ $validationErrors = array_merge([], $this->_errors);
45
  foreach($this->_nested as $nestedErrors)
46
  {
47
  $validationErrors = array_merge($validationErrors, $nestedErrors->deepAll());
71
 
72
  public function onAttribute($attribute)
73
  {
74
+ $matches = [];
75
  foreach ($this->_errors AS $key => $error) {
76
  if($error->attribute == $attribute) {
77
  $matches[] = $error;
101
  */
102
  public function __toString()
103
  {
104
+ $output = [];
105
 
106
  // TODO: implement scope
107
  if (!empty($this->_errors)) {
129
  return $eOutput;
130
  }
131
  }
132
+ class_alias('Braintree\Error\ValidationErrorCollection', 'Braintree_Error_ValidationErrorCollection');
braintree_sdk/lib/Braintree/EuropeBankAccount.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  /**
3
  * Braintree EuropeBankAccount module
4
  * Creates and manages Braintree Europe Bank Accounts
@@ -9,17 +11,18 @@
9
  *
10
  * @package Braintree
11
  * @category Resources
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  *
14
- * @property-read string $token
15
- * @property-read string $default
16
- * @property-read string $masked-iban
17
- * @property-read string $bic
18
- * @property-read string $mandate-reference-number
19
  * @property-read string $account-holder-name
 
 
 
20
  * @property-read string $image-url
 
 
 
21
  */
22
- class Braintree_EuropeBankAccount extends Braintree_Base
23
  {
24
 
25
  /* instance methods */
@@ -34,16 +37,16 @@ class Braintree_EuropeBankAccount extends Braintree_Base
34
  }
35
 
36
  /**
37
- * factory method: returns an instance of Braintree_EuropeBankAccount
38
  * to the requesting method, with populated properties
39
  *
40
  * @ignore
41
- * @return object instance of Braintree_EuropeBankAccount
42
  */
43
  public static function factory($attributes)
44
  {
45
- $defaultAttributes = array(
46
- );
47
 
48
  $instance = new self();
49
  $instance->_initialize(array_merge($defaultAttributes, $attributes));
@@ -55,10 +58,11 @@ class Braintree_EuropeBankAccount extends Braintree_Base
55
  *
56
  * @access protected
57
  * @param array $europeBankAccountAttribs array of EuropeBankAccount properties
58
- * @return none
59
  */
60
  protected function _initialize($europeBankAccountAttribs)
61
  {
62
  $this->_attributes = $europeBankAccountAttribs;
63
  }
64
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree EuropeBankAccount module
6
  * Creates and manages Braintree Europe Bank Accounts
11
  *
12
  * @package Braintree
13
  * @category Resources
14
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
  *
 
 
 
 
 
16
  * @property-read string $account-holder-name
17
+ * @property-read string $bic
18
+ * @property-read string $customerId
19
+ * @property-read string $default
20
  * @property-read string $image-url
21
+ * @property-read string $mandate-reference-number
22
+ * @property-read string $masked-iban
23
+ * @property-read string $token
24
  */
25
+ class EuropeBankAccount extends Base
26
  {
27
 
28
  /* instance methods */
37
  }
38
 
39
  /**
40
+ * factory method: returns an instance of EuropeBankAccount
41
  * to the requesting method, with populated properties
42
  *
43
  * @ignore
44
+ * @return EuropeBankAccount
45
  */
46
  public static function factory($attributes)
47
  {
48
+ $defaultAttributes = [
49
+ ];
50
 
51
  $instance = new self();
52
  $instance->_initialize(array_merge($defaultAttributes, $attributes));
58
  *
59
  * @access protected
60
  * @param array $europeBankAccountAttribs array of EuropeBankAccount properties
61
+ * @return void
62
  */
63
  protected function _initialize($europeBankAccountAttribs)
64
  {
65
  $this->_attributes = $europeBankAccountAttribs;
66
  }
67
  }
68
+ class_alias('Braintree\EuropeBankAccount', 'Braintree_EuropeBankAccount');
braintree_sdk/lib/Braintree/Exception.php CHANGED
@@ -1,11 +1,14 @@
1
  <?php
 
 
2
  /**
3
  * super class for all Braintree exceptions
4
  *
5
  * @package Braintree
6
  * @subpackage Exception
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Exception extends Exception
10
  {
11
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * super class for all Braintree exceptions
6
  *
7
  * @package Braintree
8
  * @subpackage Exception
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
+ class Exception extends \Exception
12
  {
13
  }
14
+ class_alias('Braintree\Exception', 'Braintree_Exception');
braintree_sdk/lib/Braintree/Exception/Authentication.php CHANGED
@@ -1,13 +1,18 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when authentication fails.
4
- * This may be caused by an incorrect Braintree_Configuration
5
  *
6
  * @package Braintree
7
  * @subpackage Exception
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  */
10
- class Braintree_Exception_Authentication extends Braintree_Exception
11
  {
12
 
13
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
  */
14
+ class Authentication extends Exception
15
  {
16
 
17
  }
18
+ class_alias('Braintree\Exception\Authentication', 'Braintree_Exception_Authentication');
braintree_sdk/lib/Braintree/Exception/Authorization.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when authorization fails
4
  * Raised when the API key being used is not authorized to perform
@@ -7,9 +11,10 @@
7
  *
8
  * @package Braintree
9
  * @subpackage Exception
10
- * @copyright 2014 Braintree, a division of PayPal, Inc.
11
  */
12
- class Braintree_Exception_Authorization extends Braintree_Exception
13
  {
14
 
15
  }
 
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
11
  *
12
  * @package Braintree
13
  * @subpackage Exception
14
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
  */
16
+ class Authorization extends Exception
17
  {
18
 
19
  }
20
+ class_alias('Braintree\Exception\Authorization', 'Braintree_Exception_Authorization');
braintree_sdk/lib/Braintree/Exception/Configuration.php CHANGED
@@ -1,12 +1,17 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when the Braintree library is not completely configured.
4
  *
5
  * @package Braintree
6
  * @subpackage Exception
7
- * @see Braintree_Configuration
8
  */
9
- class Braintree_Exception_Configuration extends Braintree_Exception
10
  {
11
 
12
  }
 
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');
braintree_sdk/lib/Braintree/Exception/DownForMaintenance.php CHANGED
@@ -1,12 +1,17 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when the gateway is down for maintenance.
4
  *
5
  * @package Braintree
6
  * @subpackage Exception
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Exception_DownForMaintenance extends Braintree_Exception
10
  {
11
 
12
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
+ class DownForMaintenance extends Exception
14
  {
15
 
16
  }
17
+ class_alias('Braintree\Exception\DownForMaintenance', 'Braintree_Exception_DownForMaintenance');
braintree_sdk/lib/Braintree/Exception/ForgedQueryString.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when a suspected forged query string is present
4
  * Raised from methods that confirm transparent redirect requests
@@ -8,9 +12,10 @@
8
  *
9
  * @package Braintree
10
  * @subpackage Exception
11
- * @copyright 2014 Braintree, a division of PayPal, Inc.
12
  */
13
- class Braintree_Exception_ForgedQueryString extends Braintree_Exception
14
  {
15
 
16
  }
 
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
12
  *
13
  * @package Braintree
14
  * @subpackage Exception
15
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
16
  */
17
+ class ForgedQueryString extends Exception
18
  {
19
 
20
  }
21
+ class_alias('Braintree\Exception\ForgedQueryString', 'Braintree_Exception_ForgedQueryString');
braintree_sdk/lib/Braintree/Exception/InvalidChallenge.php CHANGED
@@ -1,5 +1,9 @@
1
  <?php
2
- class Braintree_Exception_InvalidChallenge extends Braintree_Exception
3
- {
 
4
 
 
 
5
  }
 
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');
braintree_sdk/lib/Braintree/Exception/InvalidSignature.php CHANGED
@@ -1,5 +1,9 @@
1
  <?php
2
- class Braintree_Exception_InvalidSignature extends Braintree_Exception
3
- {
 
4
 
 
 
5
  }
 
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');
braintree_sdk/lib/Braintree/Exception/NotFound.php CHANGED
@@ -1,12 +1,17 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when a record could not be found.
4
  *
5
  * @package Braintree
6
  * @subpackage Exception
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Exception_NotFound extends Braintree_Exception
10
  {
11
 
12
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
+ class NotFound extends Exception
14
  {
15
 
16
  }
17
+ class_alias('Braintree\Exception\NotFound', 'Braintree_Exception_NotFound');
braintree_sdk/lib/Braintree/Exception/SSLCaFileNotFound.php CHANGED
@@ -1,12 +1,17 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when the SSL CaFile is not found.
4
  *
5
  * @package Braintree
6
  * @subpackage Exception
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Exception_SSLCaFileNotFound extends Braintree_Exception
10
  {
11
 
12
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
+ class SSLCaFileNotFound extends Exception
14
  {
15
 
16
  }
17
+ class_alias('Braintree\Exception\SSLCaFileNotFound', 'Braintree_Exception_SSLCaFileNotFound');
braintree_sdk/lib/Braintree/Exception/SSLCertificate.php CHANGED
@@ -1,12 +1,17 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when the SSL certificate fails verification.
4
  *
5
  * @package Braintree
6
  * @subpackage Exception
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Exception_SSLCertificate extends Braintree_Exception
10
  {
11
 
12
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
+ class SSLCertificate extends Exception
14
  {
15
 
16
  }
17
+ class_alias('Braintree\Exception\SSLCertificate', 'Braintree_Exception_SSLCertificate');
braintree_sdk/lib/Braintree/Exception/ServerError.php CHANGED
@@ -1,12 +1,17 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when an unexpected server error occurs.
4
  *
5
  * @package Braintree
6
  * @subpackage Exception
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Exception_ServerError extends Braintree_Exception
10
  {
11
 
12
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
+ class ServerError extends Exception
14
  {
15
 
16
  }
17
+ class_alias('Braintree\Exception\ServerError', 'Braintree_Exception_ServerError');
braintree_sdk/lib/Braintree/Exception/TestOperationPerformedInProduction.php CHANGED
@@ -1,11 +1,16 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when a test method is used in production.
4
  *
5
  * @package Braintree
6
  * @subpackage Exception
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Exception_TestOperationPerformedInProduction extends Braintree_Exception
10
  {
11
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
+ class TestOperationPerformedInProduction extends Exception
14
  {
15
  }
16
+ class_alias('Braintree\Exception\TestOperationPerformedInProduction', 'Braintree_Exception_TestOperationPerformedInProduction');
braintree_sdk/lib/Braintree/Exception/Unexpected.php CHANGED
@@ -1,13 +1,18 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when an error occurs that the client library is not built to handle.
4
  * This shouldn't happen.
5
  *
6
  * @package Braintree
7
  * @subpackage Exception
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  */
10
- class Braintree_Exception_Unexpected extends Braintree_Exception
11
  {
12
 
13
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
  */
14
+ class Unexpected extends Exception
15
  {
16
 
17
  }
18
+ class_alias('Braintree\Exception\Unexpected', 'Braintree_Exception_Unexpected');
braintree_sdk/lib/Braintree/Exception/UpgradeRequired.php CHANGED
@@ -1,12 +1,17 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised when a client library must be upgraded.
4
  *
5
  * @package Braintree
6
  * @subpackage Exception
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Exception_UpgradeRequired extends Braintree_Exception
10
  {
11
 
12
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
+ class UpgradeRequired extends Exception
14
  {
15
 
16
  }
17
+ class_alias('Braintree\Exception\UpgradeRequired', 'Braintree_Exception_UpgradeRequired');
braintree_sdk/lib/Braintree/Exception/ValidationsFailed.php CHANGED
@@ -1,12 +1,17 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Raised from non-validating methods when gateway validations fail.
4
  *
5
  * @package Braintree
6
  * @subpackage Exception
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Exception_ValidationsFailed extends Braintree_Exception
10
  {
11
 
12
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
+ class ValidationsFailed extends Exception
14
  {
15
 
16
  }
17
+ class_alias('Braintree\Exception\ValidationsFailed', 'Braintree_Exception_ValidationsFailed');
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');
braintree_sdk/lib/Braintree/Gateway.php CHANGED
@@ -1,195 +1,198 @@
1
  <?php
 
 
2
  /**
3
  * Braintree Gateway module
4
  *
5
  * @package Braintree
6
  * @category Resources
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Gateway
10
  {
11
  /**
12
  *
13
- * @var Braintree_Configuration
14
  */
15
  public $config;
16
 
17
  public function __construct($config)
18
  {
19
  if (is_array($config)) {
20
- $config = new Braintree_Configuration($config);
21
  }
22
  $this->config = $config;
23
  }
24
 
25
  /**
26
  *
27
- * @return \Braintree_AddOnGateway
28
  */
29
  public function addOn()
30
  {
31
- return new Braintree_AddOnGateway($this);
32
  }
33
 
34
  /**
35
  *
36
- * @return \Braintree_AddressGateway
37
  */
38
  public function address()
39
  {
40
- return new Braintree_AddressGateway($this);
41
  }
42
 
43
  /**
44
  *
45
- * @return \Braintree_ClientTokenGateway
46
  */
47
  public function clientToken()
48
  {
49
- return new Braintree_ClientTokenGateway($this);
50
  }
51
 
52
  /**
53
  *
54
- * @return \Braintree_CreditCardGateway
55
  */
56
  public function creditCard()
57
  {
58
- return new Braintree_CreditCardGateway($this);
59
  }
60
 
61
  /**
62
  *
63
- * @return \Braintree_CreditCardVerificationGateway
64
  */
65
  public function creditCardVerification()
66
  {
67
- return new Braintree_CreditCardVerificationGateway($this);
68
  }
69
 
70
  /**
71
  *
72
- * @return \Braintree_CustomerGateway
73
  */
74
  public function customer()
75
  {
76
- return new Braintree_CustomerGateway($this);
77
  }
78
 
79
  /**
80
  *
81
- * @return \Braintree_DiscountGateway
82
  */
83
  public function discount()
84
  {
85
- return new Braintree_DiscountGateway($this);
86
  }
87
 
88
  /**
89
  *
90
- * @return \Braintree_MerchantGateway
91
  */
92
  public function merchant()
93
  {
94
- return new Braintree_MerchantGateway($this);
95
  }
96
 
97
  /**
98
  *
99
- * @return \Braintree_MerchantAccountGateway
100
  */
101
  public function merchantAccount()
102
  {
103
- return new Braintree_MerchantAccountGateway($this);
104
  }
105
 
106
  /**
107
  *
108
- * @return \Braintree_OAuthGateway
109
  */
110
  public function oauth()
111
  {
112
- return new Braintree_OAuthGateway($this);
113
  }
114
 
115
  /**
116
  *
117
- * @return \Braintree_PaymentMethodGateway
118
  */
119
  public function paymentMethod()
120
  {
121
- return new Braintree_PaymentMethodGateway($this);
122
  }
123
 
124
  /**
125
  *
126
- * @return \Braintree_PaymentMethodNonceGateway
127
  */
128
  public function paymentMethodNonce()
129
  {
130
- return new Braintree_PaymentMethodNonceGateway($this);
131
  }
132
 
133
  /**
134
  *
135
- * @return \Braintree_PayPalAccountGateway
136
  */
137
  public function payPalAccount()
138
  {
139
- return new Braintree_PayPalAccountGateway($this);
140
  }
141
 
142
  /**
143
  *
144
- * @return \Braintree_PlanGateway
145
  */
146
  public function plan()
147
  {
148
- return new Braintree_PlanGateway($this);
149
  }
150
 
151
  /**
152
  *
153
- * @return \Braintree_SettlementBatchSummaryGateway
154
  */
155
  public function settlementBatchSummary()
156
  {
157
- return new Braintree_SettlementBatchSummaryGateway($this);
158
  }
159
 
160
  /**
161
  *
162
- * @return \Braintree_SubscriptionGateway
163
  */
164
  public function subscription()
165
  {
166
- return new Braintree_SubscriptionGateway($this);
167
  }
168
 
169
  /**
170
  *
171
- * @return \Braintree_TestingGateway
172
  */
173
  public function testing()
174
  {
175
- return new Braintree_TestingGateway($this);
176
  }
177
 
178
  /**
179
  *
180
- * @return \Braintree_TransactionGateway
181
  */
182
  public function transaction()
183
  {
184
- return new Braintree_TransactionGateway($this);
185
  }
186
 
187
  /**
188
  *
189
- * @return \Braintree_TransparentRedirectGateway
190
  */
191
  public function transparentRedirect()
192
  {
193
- return new Braintree_TransparentRedirectGateway($this);
194
  }
195
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree Gateway module
6
  *
7
  * @package Braintree
8
  * @category Resources
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
+ class Gateway
12
  {
13
  /**
14
  *
15
+ * @var Configuration
16
  */
17
  public $config;
18
 
19
  public function __construct($config)
20
  {
21
  if (is_array($config)) {
22
+ $config = new Configuration($config);
23
  }
24
  $this->config = $config;
25
  }
26
 
27
  /**
28
  *
29
+ * @return AddOnGateway
30
  */
31
  public function addOn()
32
  {
33
+ return new AddOnGateway($this);
34
  }
35
 
36
  /**
37
  *
38
+ * @return AddressGateway
39
  */
40
  public function address()
41
  {
42
+ return new AddressGateway($this);
43
  }
44
 
45
  /**
46
  *
47
+ * @return ClientTokenGateway
48
  */
49
  public function clientToken()
50
  {
51
+ return new ClientTokenGateway($this);
52
  }
53
 
54
  /**
55
  *
56
+ * @return CreditCardGateway
57
  */
58
  public function creditCard()
59
  {
60
+ return new CreditCardGateway($this);
61
  }
62
 
63
  /**
64
  *
65
+ * @return CreditCardVerificationGateway
66
  */
67
  public function creditCardVerification()
68
  {
69
+ return new CreditCardVerificationGateway($this);
70
  }
71
 
72
  /**
73
  *
74
+ * @return CustomerGateway
75
  */
76
  public function customer()
77
  {
78
+ return new CustomerGateway($this);
79
  }
80
 
81
  /**
82
  *
83
+ * @return DiscountGateway
84
  */
85
  public function discount()
86
  {
87
+ return new DiscountGateway($this);
88
  }
89
 
90
  /**
91
  *
92
+ * @return MerchantGateway
93
  */
94
  public function merchant()
95
  {
96
+ return new MerchantGateway($this);
97
  }
98
 
99
  /**
100
  *
101
+ * @return MerchantAccountGateway
102
  */
103
  public function merchantAccount()
104
  {
105
+ return new MerchantAccountGateway($this);
106
  }
107
 
108
  /**
109
  *
110
+ * @return OAuthGateway
111
  */
112
  public function oauth()
113
  {
114
+ return new OAuthGateway($this);
115
  }
116
 
117
  /**
118
  *
119
+ * @return PaymentMethodGateway
120
  */
121
  public function paymentMethod()
122
  {
123
+ return new PaymentMethodGateway($this);
124
  }
125
 
126
  /**
127
  *
128
+ * @return PaymentMethodNonceGateway
129
  */
130
  public function paymentMethodNonce()
131
  {
132
+ return new PaymentMethodNonceGateway($this);
133
  }
134
 
135
  /**
136
  *
137
+ * @return PayPalAccountGateway
138
  */
139
  public function payPalAccount()
140
  {
141
+ return new PayPalAccountGateway($this);
142
  }
143
 
144
  /**
145
  *
146
+ * @return PlanGateway
147
  */
148
  public function plan()
149
  {
150
+ return new PlanGateway($this);
151
  }
152
 
153
  /**
154
  *
155
+ * @return SettlementBatchSummaryGateway
156
  */
157
  public function settlementBatchSummary()
158
  {
159
+ return new SettlementBatchSummaryGateway($this);
160
  }
161
 
162
  /**
163
  *
164
+ * @return SubscriptionGateway
165
  */
166
  public function subscription()
167
  {
168
+ return new SubscriptionGateway($this);
169
  }
170
 
171
  /**
172
  *
173
+ * @return TestingGateway
174
  */
175
  public function testing()
176
  {
177
+ return new TestingGateway($this);
178
  }
179
 
180
  /**
181
  *
182
+ * @return TransactionGateway
183
  */
184
  public function transaction()
185
  {
186
+ return new TransactionGateway($this);
187
  }
188
 
189
  /**
190
  *
191
+ * @return TransparentRedirectGateway
192
  */
193
  public function transparentRedirect()
194
  {
195
+ return new TransparentRedirectGateway($this);
196
  }
197
  }
198
+ class_alias('Braintree\Gateway', 'Braintree_Gateway');
braintree_sdk/lib/Braintree/Http.php CHANGED
@@ -1,11 +1,13 @@
1
  <?php
 
 
2
  /**
3
  * Braintree HTTP Client
4
  * processes Http requests using curl
5
  *
6
- * @copyright 2014 Braintree, a division of PayPal, Inc.
7
  */
8
- class Braintree_Http
9
  {
10
  protected $_config;
11
  private $_useClientCredentials = false;
@@ -21,17 +23,17 @@ class Braintree_Http
21
  if($response['status'] === 200) {
22
  return true;
23
  } else {
24
- Braintree_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 Braintree_Xml::buildArrayFromXml($response['body']);
33
  } else {
34
- Braintree_Util::throwStatusCodeException($response['status']);
35
  }
36
  }
37
 
@@ -40,9 +42,9 @@ class Braintree_Http
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 Braintree_Xml::buildArrayFromXml($response['body']);
44
  } else {
45
- Braintree_Util::throwStatusCodeException($responseCode);
46
  }
47
  }
48
 
@@ -51,41 +53,41 @@ class Braintree_Http
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 Braintree_Xml::buildArrayFromXml($response['body']);
55
  } else {
56
- Braintree_Util::throwStatusCodeException($responseCode);
57
  }
58
  }
59
 
60
  private function _buildXml($params)
61
  {
62
- return empty($params) ? null : Braintree_Xml::buildXmlFromArray($params);
63
  }
64
 
65
  private function _getHeaders()
66
  {
67
- return array(
68
  'Accept: application/xml',
69
  'Content-Type: application/xml',
70
- );
71
  }
72
 
73
  private function _getAuthorization()
74
  {
75
  if ($this->_useClientCredentials) {
76
- return array(
77
  'user' => $this->_config->getClientId(),
78
  'password' => $this->_config->getClientSecret(),
79
- );
80
  } else if ($this->_config->isAccessToken()) {
81
- return array(
82
  'token' => $this->_config->getAccessToken(),
83
- );
84
  } else {
85
- return array(
86
  'user' => $this->_config->getPublicKey(),
87
  'password' => $this->_config->getPrivateKey(),
88
- );
89
  }
90
  }
91
 
@@ -108,8 +110,8 @@ class Braintree_Http
108
  curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
109
 
110
  $headers = $this->_getHeaders($curl);
111
- $headers[] = 'User-Agent: Braintree PHP Library ' . Braintree_Version::get();
112
- $headers[] = 'X-ApiVersion: ' . Braintree_Configuration::API_VERSION;
113
 
114
  $authorization = $this->_getAuthorization();
115
  if (isset($authorization['user'])) {
@@ -124,22 +126,57 @@ class Braintree_Http
124
  if ($this->_config->sslOn()) {
125
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
126
  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
127
- curl_setopt($curl, CURLOPT_CAINFO, $this->_config->caFile());
128
  }
129
 
130
  if(!empty($requestBody)) {
131
  curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
132
  }
133
 
 
 
 
 
 
 
 
 
 
 
134
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
135
  $response = curl_exec($curl);
136
  $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
137
  curl_close($curl);
138
  if ($this->_config->sslOn()) {
139
  if ($httpStatus == 0) {
140
- throw new Braintree_Exception_SSLCertificate();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
 
 
 
 
 
 
 
 
 
142
  }
143
- return array('status' => $httpStatus, 'body' => $response);
 
144
  }
145
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree HTTP Client
6
  * processes Http requests using curl
7
  *
8
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
9
  */
10
+ class Http
11
  {
12
  protected $_config;
13
  private $_useClientCredentials = false;
23
  if($response['status'] === 200) {
24
  return true;
25
  } else {
26
+ Util::throwStatusCodeException($response['status']);
27
  }
28
  }
29
 
30
  public function get($path)
31
  {
32
  $response = $this->_doRequest('GET', $path);
33
+ if ($response['status'] === 200) {
34
+ return Xml::buildArrayFromXml($response['body']);
35
  } else {
36
+ Util::throwStatusCodeException($response['status']);
37
  }
38
  }
39
 
42
  $response = $this->_doRequest('POST', $path, $this->_buildXml($params));
43
  $responseCode = $response['status'];
44
  if($responseCode === 200 || $responseCode === 201 || $responseCode === 422 || $responseCode == 400) {
45
+ return Xml::buildArrayFromXml($response['body']);
46
  } else {
47
+ Util::throwStatusCodeException($responseCode);
48
  }
49
  }
50
 
53
  $response = $this->_doRequest('PUT', $path, $this->_buildXml($params));
54
  $responseCode = $response['status'];
55
  if($responseCode === 200 || $responseCode === 201 || $responseCode === 422 || $responseCode == 400) {
56
+ return Xml::buildArrayFromXml($response['body']);
57
  } else {
58
+ Util::throwStatusCodeException($responseCode);
59
  }
60
  }
61
 
62
  private function _buildXml($params)
63
  {
64
+ return empty($params) ? null : Xml::buildXmlFromArray($params);
65
  }
66
 
67
  private function _getHeaders()
68
  {
69
+ return [
70
  'Accept: application/xml',
71
  'Content-Type: application/xml',
72
+ ];
73
  }
74
 
75
  private function _getAuthorization()
76
  {
77
  if ($this->_useClientCredentials) {
78
+ return [
79
  'user' => $this->_config->getClientId(),
80
  'password' => $this->_config->getClientSecret(),
81
+ ];
82
  } else if ($this->_config->isAccessToken()) {
83
+ return [
84
  'token' => $this->_config->getAccessToken(),
85
+ ];
86
  } else {
87
+ return [
88
  'user' => $this->_config->getPublicKey(),
89
  'password' => $this->_config->getPrivateKey(),
90
+ ];
91
  }
92
  }
93
 
110
  curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
111
 
112
  $headers = $this->_getHeaders($curl);
113
+ $headers[] = 'User-Agent: Braintree PHP Library ' . Version::get();
114
+ $headers[] = 'X-ApiVersion: ' . Configuration::API_VERSION;
115
 
116
  $authorization = $this->_getAuthorization();
117
  if (isset($authorization['user'])) {
126
  if ($this->_config->sslOn()) {
127
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
128
  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
129
+ curl_setopt($curl, CURLOPT_CAINFO, $this->getCaFile());
130
  }
131
 
132
  if(!empty($requestBody)) {
133
  curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
134
  }
135
 
136
+ if($this->_config->isUsingProxy()) {
137
+ $proxyHost = $this->_config->getProxyHost();
138
+ $proxyPort = $this->_config->getProxyPort();
139
+ $proxyType = $this->_config->getProxyType();
140
+ curl_setopt($curl, CURLOPT_PROXY, $proxyHost . ':' . $proxyPort);
141
+ if(!empty($proxyType)) {
142
+ curl_setopt($curl, CURLOPT_PROXYTYPE, $proxyType);
143
+ }
144
+ }
145
+
146
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
147
  $response = curl_exec($curl);
148
  $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
149
  curl_close($curl);
150
  if ($this->_config->sslOn()) {
151
  if ($httpStatus == 0) {
152
+ throw new Exception\SSLCertificate();
153
+ }
154
+ }
155
+ return ['status' => $httpStatus, 'body' => $response];
156
+ }
157
+
158
+ private function getCaFile()
159
+ {
160
+ static $memo;
161
+
162
+ if ($memo === null) {
163
+ $caFile = $this->_config->caFile();
164
+
165
+ if (substr($caFile, 0, 7) !== 'phar://') {
166
+ return $caFile;
167
  }
168
+
169
+ $extractedCaFile = sys_get_temp_dir() . '/api_braintreegateway_com.ca.crt';
170
+
171
+ if (!file_exists($extractedCaFile) || sha1_file($extractedCaFile) != sha1_file($caFile)) {
172
+ if (!copy($caFile, $extractedCaFile)) {
173
+ throw new Exception\SSLCaFileNotFound();
174
+ }
175
+ }
176
+ $memo = $extractedCaFile;
177
  }
178
+
179
+ return $memo;
180
  }
181
  }
182
+ class_alias('Braintree\Http', 'Braintree_Http');
braintree_sdk/lib/Braintree/Instance.php CHANGED
@@ -1,16 +1,19 @@
1
  <?php
 
 
2
  /**
3
  * Braintree Class Instance template
4
- * @package Braintree
5
- * @subpackage Utility
6
- * @copyright 2014 Braintree, a division of PayPal, Inc.
7
  * @abstract
8
  */
9
- abstract class Braintree_Instance
10
  {
 
 
11
  /**
12
  *
13
- * @param array $aAttribs
14
  */
15
  public function __construct($attributes)
16
  {
@@ -19,11 +22,10 @@ abstract class Braintree_Instance
19
  }
20
  }
21
 
22
-
23
  /**
24
  * returns private/nonexistent instance properties
25
  * @access public
26
- * @param var $name property name
27
  * @return mixed contents of instance properties
28
  */
29
  public function __get($name)
@@ -50,19 +52,19 @@ abstract class Braintree_Instance
50
  /**
51
  * create a printable representation of the object as:
52
  * ClassName[property=value, property=value]
53
- * @return var
54
  */
55
  public function __toString()
56
  {
57
- $objOutput = Braintree_Util::implodeAssociativeArray($this->_attributes);
58
- return get_class($this) .'['.$objOutput.']';
59
  }
60
  /**
61
  * initializes instance properties from the keys/values of an array
62
  * @ignore
63
  * @access protected
64
  * @param <type> $aAttribs array of properties to set - single level
65
- * @return none
66
  */
67
  private function _initializeFromArray($attributes)
68
  {
@@ -70,3 +72,4 @@ abstract class Braintree_Instance
70
  }
71
 
72
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree Class Instance template
6
+ *
7
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
 
8
  * @abstract
9
  */
10
+ abstract class Instance
11
  {
12
+ protected $_attributes = [];
13
+
14
  /**
15
  *
16
+ * @param array $attributes
17
  */
18
  public function __construct($attributes)
19
  {
22
  }
23
  }
24
 
 
25
  /**
26
  * returns private/nonexistent instance properties
27
  * @access public
28
+ * @param string $name property name
29
  * @return mixed contents of instance properties
30
  */
31
  public function __get($name)
52
  /**
53
  * create a printable representation of the object as:
54
  * ClassName[property=value, property=value]
55
+ * @return string
56
  */
57
  public function __toString()
58
  {
59
+ $objOutput = Util::implodeAssociativeArray($this->_attributes);
60
+ return get_class($this) .'[' . $objOutput . ']';
61
  }
62
  /**
63
  * initializes instance properties from the keys/values of an array
64
  * @ignore
65
  * @access protected
66
  * @param <type> $aAttribs array of properties to set - single level
67
+ * @return void
68
  */
69
  private function _initializeFromArray($attributes)
70
  {
72
  }
73
 
74
  }
75
+ class_alias('Braintree\Instance', 'Braintree_Instance');
braintree_sdk/lib/Braintree/IsNode.php CHANGED
@@ -1,21 +1,24 @@
1
  <?php
 
2
 
3
- class Braintree_IsNode
4
  {
5
- function __construct($name)
6
  {
7
  $this->name = $name;
8
- $this->searchTerms = array();
9
  }
10
 
11
- function is($value)
12
  {
13
  $this->searchTerms['is'] = strval($value);
 
14
  return $this;
15
  }
16
 
17
- function toParam()
18
  {
19
  return $this->searchTerms;
20
  }
21
  }
 
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');
braintree_sdk/lib/Braintree/KeyValueNode.php CHANGED
@@ -1,22 +1,23 @@
1
  <?php
 
2
 
3
- class Braintree_KeyValueNode
4
  {
5
- function __construct($name)
6
  {
7
  $this->name = $name;
8
  $this->searchTerm = True;
9
-
10
  }
11
 
12
- function is($value)
13
  {
14
  $this->searchTerm = $value;
15
  return $this;
16
  }
17
 
18
- function toParam()
19
  {
20
  return $this->searchTerm;
21
  }
22
  }
 
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');
braintree_sdk/lib/Braintree/Merchant.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
 
2
 
3
- final class Braintree_Merchant extends Braintree_Base
4
  {
5
  protected function _initialize($attribs)
6
  {
@@ -21,6 +22,7 @@ final class Braintree_Merchant extends Braintree_Base
21
  public function __toString()
22
  {
23
  return __CLASS__ . '[' .
24
- Braintree_Util::attributesToString($this->_attributes) .']';
25
  }
26
  }
 
1
  <?php
2
+ namespace Braintree;
3
 
4
+ final class Merchant extends Base
5
  {
6
  protected function _initialize($attribs)
7
  {
22
  public function __toString()
23
  {
24
  return __CLASS__ . '[' .
25
+ Util::attributesToString($this->_attributes) .']';
26
  }
27
  }
28
+ class_alias('Braintree\Merchant', 'Braintree_Merchant');
braintree_sdk/lib/Braintree/MerchantAccount.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
 
2
 
3
- final class Braintree_MerchantAccount extends Braintree_Base
4
  {
5
  const STATUS_ACTIVE = 'active';
6
  const STATUS_PENDING = 'pending';
@@ -23,22 +24,22 @@ final class Braintree_MerchantAccount extends Braintree_Base
23
 
24
  if (isset($merchantAccountAttribs['individual'])) {
25
  $individual = $merchantAccountAttribs['individual'];
26
- $this->_set('individualDetails', Braintree_MerchantAccount_IndividualDetails::Factory($individual));
27
  }
28
 
29
  if (isset($merchantAccountAttribs['business'])) {
30
  $business = $merchantAccountAttribs['business'];
31
- $this->_set('businessDetails', Braintree_MerchantAccount_BusinessDetails::Factory($business));
32
  }
33
 
34
  if (isset($merchantAccountAttribs['funding'])) {
35
  $funding = $merchantAccountAttribs['funding'];
36
- $this->_set('fundingDetails', new Braintree_MerchantAccount_FundingDetails($funding));
37
  }
38
 
39
  if (isset($merchantAccountAttribs['masterMerchantAccount'])) {
40
  $masterMerchantAccount = $merchantAccountAttribs['masterMerchantAccount'];
41
- $this->_set('masterMerchantAccount', Braintree_MerchantAccount::Factory($masterMerchantAccount));
42
  }
43
  }
44
 
@@ -47,16 +48,17 @@ final class Braintree_MerchantAccount extends Braintree_Base
47
 
48
  public static function create($attribs)
49
  {
50
- return Braintree_Configuration::gateway()->merchantAccount()->create($attribs);
51
  }
52
 
53
  public static function find($merchant_account_id)
54
  {
55
- return Braintree_Configuration::gateway()->merchantAccount()->find($merchant_account_id);
56
  }
57
 
58
  public static function update($merchant_account_id, $attributes)
59
  {
60
- return Braintree_Configuration::gateway()->merchantAccount()->update($merchant_account_id, $attributes);
61
  }
62
  }
 
1
  <?php
2
+ namespace Braintree;
3
 
4
+ final class MerchantAccount extends Base
5
  {
6
  const STATUS_ACTIVE = 'active';
7
  const STATUS_PENDING = 'pending';
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
 
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');
braintree_sdk/lib/Braintree/MerchantAccount/AddressDetails.php CHANGED
@@ -1,5 +1,10 @@
1
  <?php
 
2
 
3
- final class Braintree_MerchantAccount_AddressDetails extends Braintree_Instance {
4
- protected $_attributes = array();
 
 
 
5
  }
 
1
  <?php
2
+ namespace Braintree\MerchantAccount;
3
 
4
+ use Braintree\Instance;
5
+
6
+ final class AddressDetails extends Instance
7
+ {
8
+ protected $_attributes = [];
9
  }
10
+ class_alias('Braintree\MerchantAccount\AddressDetails', 'Braintree_MerchantAccount_AddressDetails');
braintree_sdk/lib/Braintree/MerchantAccount/BusinessDetails.php CHANGED
@@ -1,12 +1,15 @@
1
  <?php
 
2
 
3
- final class Braintree_MerchantAccount_BusinessDetails extends Braintree_Base
 
 
4
  {
5
  protected function _initialize($businessAttribs)
6
  {
7
  $this->_attributes = $businessAttribs;
8
  if (isset($businessAttribs['address'])) {
9
- $this->_set('addressDetails', new Braintree_MerchantAccount_AddressDetails($businessAttribs['address']));
10
  }
11
  }
12
 
@@ -17,3 +20,4 @@ final class Braintree_MerchantAccount_BusinessDetails extends Braintree_Base
17
  return $instance;
18
  }
19
  }
 
1
  <?php
2
+ namespace Braintree\MerchantAccount;
3
 
4
+ use Braintree\Base;
5
+
6
+ final 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
 
20
  return $instance;
21
  }
22
  }
23
+ class_alias('Braintree\MerchantAccount\BusinessDetails', 'Braintree_MerchantAccount_BusinessDetails');
braintree_sdk/lib/Braintree/MerchantAccount/FundingDetails.php CHANGED
@@ -1,6 +1,10 @@
1
  <?php
 
2
 
3
- final class Braintree_MerchantAccount_FundingDetails extends Braintree_Instance
 
 
4
  {
5
- protected $_attributes = array();
6
  }
 
1
  <?php
2
+ namespace Braintree\MerchantAccount;
3
 
4
+ use Braintree\Instance;
5
+
6
+ final class FundingDetails extends Instance
7
  {
8
+ protected $_attributes = [];
9
  }
10
+ class_alias('Braintree\MerchantAccount\FundingDetails', 'Braintree_MerchantAccount_FundingDetails');
braintree_sdk/lib/Braintree/MerchantAccount/IndividualDetails.php CHANGED
@@ -1,12 +1,15 @@
1
  <?php
 
2
 
3
- final class Braintree_MerchantAccount_IndividualDetails extends Braintree_Base
 
 
4
  {
5
  protected function _initialize($individualAttribs)
6
  {
7
  $this->_attributes = $individualAttribs;
8
  if (isset($individualAttribs['address'])) {
9
- $this->_set('addressDetails', new Braintree_MerchantAccount_AddressDetails($individualAttribs['address']));
10
  }
11
  }
12
 
@@ -17,3 +20,4 @@ final class Braintree_MerchantAccount_IndividualDetails extends Braintree_Base
17
  return $instance;
18
  }
19
  }
 
1
  <?php
2
+ namespace Braintree\MerchantAccount;
3
 
4
+ use Braintree\Base;
5
+
6
+ final 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
 
20
  return $instance;
21
  }
22
  }
23
+ class_alias('Braintree\MerchantAccount\IndividualDetails', 'Braintree_MerchantAccount_IndividualDetails');
braintree_sdk/lib/Braintree/MerchantAccountGateway.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
 
2
 
3
- final class Braintree_MerchantAccountGateway
4
  {
5
  private $_gateway;
6
  private $_config;
@@ -11,13 +12,13 @@ final class Braintree_MerchantAccountGateway
11
  $this->_gateway = $gateway;
12
  $this->_config = $gateway->config;
13
  $this->_config->assertHasAccessTokenOrKeys();
14
- $this->_http = new Braintree_Http($gateway->config);
15
  }
16
 
17
  public function create($attribs)
18
  {
19
- Braintree_Util::verifyKeys(self::detectSignature($attribs), $attribs);
20
- return $this->_doCreate('/merchant_accounts/create_via_api', array('merchant_account' => $attribs));
21
  }
22
 
23
  public function find($merchant_account_id)
@@ -25,16 +26,16 @@ final class Braintree_MerchantAccountGateway
25
  try {
26
  $path = $this->_config->merchantPath() . '/merchant_accounts/' . $merchant_account_id;
27
  $response = $this->_http->get($path);
28
- return Braintree_MerchantAccount::factory($response['merchantAccount']);
29
- } catch (Braintree_Exception_NotFound $e) {
30
- throw new Braintree_Exception_NotFound('merchant account with id ' . $merchant_account_id . ' not found');
31
  }
32
  }
33
 
34
  public function update($merchant_account_id, $attributes)
35
  {
36
- Braintree_Util::verifyKeys(self::updateSignature(), $attributes);
37
- return $this->_doUpdate('/merchant_accounts/' . $merchant_account_id . '/update_via_api', array('merchant_account' => $attributes));
38
  }
39
 
40
  public static function detectSignature($attribs)
@@ -56,47 +57,47 @@ final class Braintree_MerchantAccountGateway
56
 
57
  public static function createSignature()
58
  {
59
- $addressSignature = array('streetAddress', 'postalCode', 'locality', 'region');
60
- $individualSignature = array(
61
  'firstName',
62
  'lastName',
63
  'email',
64
  'phone',
65
  'dateOfBirth',
66
  'ssn',
67
- array('address' => $addressSignature)
68
- );
69
 
70
- $businessSignature = array(
71
  'dbaName',
72
  'legalName',
73
  'taxId',
74
- array('address' => $addressSignature)
75
- );
76
 
77
- $fundingSignature = array(
78
  'routingNumber',
79
  'accountNumber',
80
  'destination',
81
  'email',
82
  'mobilePhone',
83
  'descriptor',
84
- );
85
 
86
- return array(
87
  'id',
88
  'tosAccepted',
89
  'masterMerchantAccountId',
90
- array('individual' => $individualSignature),
91
- array('funding' => $fundingSignature),
92
- array('business' => $businessSignature)
93
- );
94
  }
95
 
96
  public static function createDeprecatedSignature()
97
  {
98
- $applicantDetailsAddressSignature = array('streetAddress', 'postalCode', 'locality', 'region');
99
- $applicantDetailsSignature = array(
100
  'companyName',
101
  'firstName',
102
  'lastName',
@@ -107,15 +108,15 @@ final class Braintree_MerchantAccountGateway
107
  'taxId',
108
  'routingNumber',
109
  'accountNumber',
110
- array('address' => $applicantDetailsAddressSignature)
111
- );
112
 
113
- return array(
114
- array('applicantDetails' => $applicantDetailsSignature),
115
  'id',
116
  'tosAccepted',
117
  'masterMerchantAccountId'
118
- );
119
  }
120
 
121
  public function _doCreate($subPath, $params)
@@ -137,16 +138,17 @@ final class Braintree_MerchantAccountGateway
137
  private function _verifyGatewayResponse($response)
138
  {
139
  if (isset($response['merchantAccount'])) {
140
- // return a populated instance of Braintree_merchantAccount
141
- return new Braintree_Result_Successful(
142
- Braintree_MerchantAccount::factory($response['merchantAccount'])
143
  );
144
  } else if (isset($response['apiErrorResponse'])) {
145
- return new Braintree_Result_Error($response['apiErrorResponse']);
146
  } else {
147
- throw new Braintree_Exception_Unexpected(
148
  "Expected merchant account or apiErrorResponse"
149
  );
150
  }
151
  }
152
  }
 
1
  <?php
2
+ namespace Braintree;
3
 
4
+ final class MerchantAccountGateway
5
  {
6
  private $_gateway;
7
  private $_config;
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)
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)
57
 
58
  public static function createSignature()
59
  {
60
+ $addressSignature = ['streetAddress', 'postalCode', 'locality', 'region'];
61
+ $individualSignature = [
62
  'firstName',
63
  'lastName',
64
  'email',
65
  'phone',
66
  'dateOfBirth',
67
  'ssn',
68
+ ['address' => $addressSignature]
69
+ ];
70
 
71
+ $businessSignature = [
72
  'dbaName',
73
  'legalName',
74
  'taxId',
75
+ ['address' => $addressSignature]
76
+ ];
77
 
78
+ $fundingSignature = [
79
  'routingNumber',
80
  'accountNumber',
81
  'destination',
82
  'email',
83
  'mobilePhone',
84
  'descriptor',
85
+ ];
86
 
87
+ return [
88
  'id',
89
  'tosAccepted',
90
  'masterMerchantAccountId',
91
+ ['individual' => $individualSignature],
92
+ ['funding' => $fundingSignature],
93
+ ['business' => $businessSignature]
94
+ ];
95
  }
96
 
97
  public static function createDeprecatedSignature()
98
  {
99
+ $applicantDetailsAddressSignature = ['streetAddress', 'postalCode', 'locality', 'region'];
100
+ $applicantDetailsSignature = [
101
  'companyName',
102
  'firstName',
103
  'lastName',
108
  'taxId',
109
  'routingNumber',
110
  'accountNumber',
111
+ ['address' => $applicantDetailsAddressSignature]
112
+ ];
113
 
114
+ return [
115
+ ['applicantDetails' => $applicantDetailsSignature],
116
  'id',
117
  'tosAccepted',
118
  'masterMerchantAccountId'
119
+ ];
120
  }
121
 
122
  public function _doCreate($subPath, $params)
138
  private function _verifyGatewayResponse($response)
139
  {
140
  if (isset($response['merchantAccount'])) {
141
+ // return a populated instance of merchantAccount
142
+ return new Result\Successful(
143
+ MerchantAccount::factory($response['merchantAccount'])
144
  );
145
  } else if (isset($response['apiErrorResponse'])) {
146
+ return new Result\Error($response['apiErrorResponse']);
147
  } else {
148
+ throw new Exception\Unexpected(
149
  "Expected merchant account or apiErrorResponse"
150
  );
151
  }
152
  }
153
  }
154
+ class_alias('Braintree\MerchantAccountGateway', 'Braintree_MerchantAccountGateway');
braintree_sdk/lib/Braintree/MerchantGateway.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
 
2
 
3
- final class Braintree_MerchantGateway
4
  {
5
  private $_gateway;
6
  private $_config;
@@ -11,30 +12,31 @@ final class Braintree_MerchantGateway
11
  $this->_gateway = $gateway;
12
  $this->_config = $gateway->config;
13
  $this->_config->assertHasClientCredentials();
14
- $this->_http = new Braintree_Http($gateway->config);
15
  $this->_http->useClientCredentials();
16
  }
17
 
18
  public function create($attribs)
19
  {
20
- $response = $this->_http->post('/merchants/create_via_api', array('merchant' => $attribs));
21
  return $this->_verifyGatewayResponse($response);
22
  }
23
 
24
  private function _verifyGatewayResponse($response)
25
  {
26
  if (isset($response['response']['merchant'])) {
27
- // return a populated instance of Braintree_merchant
28
- return new Braintree_Result_Successful(array(
29
- Braintree_Merchant::factory($response['response']['merchant']),
30
- Braintree_OAuthCredentials::factory($response['response']['credentials']),
31
- ));
32
  } else if (isset($response['apiErrorResponse'])) {
33
- return new Braintree_Result_Error($response['apiErrorResponse']);
34
  } else {
35
- throw new Braintree_Exception_Unexpected(
36
  "Expected merchant or apiErrorResponse"
37
  );
38
  }
39
  }
40
  }
 
1
  <?php
2
+ namespace Braintree;
3
 
4
+ final class MerchantGateway
5
  {
6
  private $_gateway;
7
  private $_config;
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');
braintree_sdk/lib/Braintree/Modification.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_Modification extends Braintree_Base
 
 
3
  {
4
  protected function _initialize($attributes)
5
  {
@@ -14,6 +16,7 @@ class Braintree_Modification extends Braintree_Base
14
  }
15
 
16
  public function __toString() {
17
- return get_called_class() . '[' . Braintree_Util::attributesToString($this->_attributes) . ']';
18
  }
19
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ class Modification extends Base
5
  {
6
  protected function _initialize($attributes)
7
  {
16
  }
17
 
18
  public function __toString() {
19
+ return get_called_class() . '[' . Util::attributesToString($this->_attributes) . ']';
20
  }
21
  }
22
+ class_alias('Braintree\Modification', 'Braintree_Modification');
braintree_sdk/lib/Braintree/MultipleValueNode.php CHANGED
@@ -1,15 +1,18 @@
1
  <?php
 
2
 
3
- class Braintree_MultipleValueNode
 
 
4
  {
5
- function __construct($name, $allowedValues = array())
6
  {
7
  $this->name = $name;
8
- $this->items = array();
9
  $this->allowedValues = $allowedValues;
10
  }
11
 
12
- function in($values)
13
  {
14
  $bad_values = array_diff($values, $this->allowedValues);
15
  if (count($this->allowedValues) > 0 && count($bad_values) > 0) {
@@ -25,13 +28,14 @@ class Braintree_MultipleValueNode
25
  return $this;
26
  }
27
 
28
- function is($value)
29
  {
30
- return $this->in(array($value));
31
  }
32
 
33
- function toParam()
34
  {
35
  return $this->items;
36
  }
37
  }
 
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) {
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');
braintree_sdk/lib/Braintree/MultipleValueOrTextNode.php CHANGED
@@ -1,45 +1,47 @@
1
  <?php
 
2
 
3
- class Braintree_MultipleValueOrTextNode extends Braintree_MultipleValueNode
4
  {
5
- function __construct($name)
6
  {
7
  parent::__construct($name);
8
- $this->textNode = new Braintree_TextNode($name);
9
  }
10
 
11
- function contains($value)
12
  {
13
  $this->textNode->contains($value);
14
  return $this;
15
  }
16
 
17
- function endsWith($value)
18
  {
19
  $this->textNode->endsWith($value);
20
  return $this;
21
  }
22
 
23
- function is($value)
24
  {
25
  $this->textNode->is($value);
26
  return $this;
27
  }
28
 
29
- function isNot($value)
30
  {
31
  $this->textNode->isNot($value);
32
  return $this;
33
  }
34
 
35
- function startsWith($value)
36
  {
37
  $this->textNode->startsWith($value);
38
  return $this;
39
  }
40
 
41
- function toParam()
42
  {
43
  return array_merge(parent::toParam(), $this->textNode->toParam());
44
  }
45
  }
 
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');
braintree_sdk/lib/Braintree/OAuthCredentials.php CHANGED
@@ -1,13 +1,15 @@
1
  <?php
 
 
2
  /**
3
  * Braintree OAuthCredentials module
4
  *
5
  * @package Braintree
6
  * @category Resources
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  *
9
  */
10
- class Braintree_OAuthCredentials extends Braintree_Base
11
  {
12
  protected function _initialize($attribs)
13
  {
@@ -25,9 +27,10 @@ class Braintree_OAuthCredentials extends Braintree_Base
25
  * returns a string representation of the access token
26
  * @return string
27
  */
28
- public function __toString()
29
  {
30
  return __CLASS__ . '[' .
31
- Braintree_Util::attributesToString($this->_attributes) .']';
32
  }
33
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree OAuthCredentials module
6
  *
7
  * @package Braintree
8
  * @category Resources
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  *
11
  */
12
+ class OAuthCredentials extends Base
13
  {
14
  protected function _initialize($attribs)
15
  {
27
  * returns a string representation of the access token
28
  * @return string
29
  */
30
+ public function __toString()
31
  {
32
  return __CLASS__ . '[' .
33
+ Util::attributesToString($this->_attributes) .']';
34
  }
35
  }
36
+ class_alias('Braintree\OAuthCredentials', 'Braintree_OAuthCredentials');
braintree_sdk/lib/Braintree/OAuthGateway.php CHANGED
@@ -1,13 +1,15 @@
1
  <?php
 
 
2
  /**
3
  * Braintree OAuthGateway module
4
  * PHP Version 5
5
  * Creates and manages Braintree Addresses
6
  *
7
  * @package Braintree
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  */
10
- class Braintree_OAuthGateway
11
  {
12
  private $_gateway;
13
  private $_config;
@@ -17,7 +19,7 @@ class Braintree_OAuthGateway
17
  {
18
  $this->_gateway = $gateway;
19
  $this->_config = $gateway->config;
20
- $this->_http = new Braintree_Http($gateway->config);
21
  $this->_http->useClientCredentials();
22
 
23
  $this->_config->assertHasClientCredentials();
@@ -37,7 +39,7 @@ class Braintree_OAuthGateway
37
 
38
  private function _createToken($params)
39
  {
40
- $params = array('credentials' => $params);
41
  $response = $this->_http->post('/oauth/access_tokens', $params);
42
  return $this->_verifyGatewayResponse($response);
43
  }
@@ -45,15 +47,15 @@ class Braintree_OAuthGateway
45
  private function _verifyGatewayResponse($response)
46
  {
47
  if (isset($response['credentials'])) {
48
- $result = new Braintree_Result_Successful(
49
- Braintree_OAuthCredentials::factory($response['credentials'])
50
  );
51
  return $this->_mapSuccess($result);
52
  } else if (isset($response['apiErrorResponse'])) {
53
- $result = new Braintree_Result_Error($response['apiErrorResponse']);
54
  return $this->_mapError($result);
55
  } else {
56
- throw new Braintree_Exception_Unexpected(
57
  "Expected credentials or apiErrorResponse"
58
  );
59
  }
@@ -63,11 +65,11 @@ class Braintree_OAuthGateway
63
  {
64
  $error = $result->errors->deepAll()[0];
65
 
66
- if ($error->code == Braintree_Error_Codes::OAUTH_INVALID_GRANT) {
67
  $result->error = 'invalid_grant';
68
- } else if ($error->code == Braintree_Error_Codes::OAUTH_INVALID_CREDENTIALS) {
69
  $result->error = 'invalid_credentials';
70
- } else if ($error->code == Braintree_Error_Codes::OAUTH_INVALID_SCOPE) {
71
  $result->error = 'invalid_scope';
72
  }
73
  $result->errorDescription = explode(': ', $error->message)[1];
@@ -84,9 +86,9 @@ class Braintree_OAuthGateway
84
  return $result;
85
  }
86
 
87
- public function connectUrl($params = array())
88
  {
89
- $query = Braintree_Util::camelCaseToDelimiterArray($params, '_');
90
  $query['client_id'] = $this->_config->getClientId();
91
  $queryString = preg_replace('/\%5B\d+\%5D/', '%5B%5D', http_build_query($query));
92
  $url = $this->_config->baseUrl() . '/oauth/connect?' . $queryString;
@@ -100,3 +102,4 @@ class Braintree_OAuthGateway
100
  return hash_hmac('sha256', $url, $key);
101
  }
102
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
11
  */
12
+ class OAuthGateway
13
  {
14
  private $_gateway;
15
  private $_config;
19
  {
20
  $this->_gateway = $gateway;
21
  $this->_config = $gateway->config;
22
+ $this->_http = new Http($gateway->config);
23
  $this->_http->useClientCredentials();
24
 
25
  $this->_config->assertHasClientCredentials();
39
 
40
  private function _createToken($params)
41
  {
42
+ $params = ['credentials' => $params];
43
  $response = $this->_http->post('/oauth/access_tokens', $params);
44
  return $this->_verifyGatewayResponse($response);
45
  }
47
  private function _verifyGatewayResponse($response)
48
  {
49
  if (isset($response['credentials'])) {
50
+ $result = new Result\Successful(
51
+ OAuthCredentials::factory($response['credentials'])
52
  );
53
  return $this->_mapSuccess($result);
54
  } else if (isset($response['apiErrorResponse'])) {
55
+ $result = new Result\Error($response['apiErrorResponse']);
56
  return $this->_mapError($result);
57
  } else {
58
+ throw new Exception\Unexpected(
59
  "Expected credentials or apiErrorResponse"
60
  );
61
  }
65
  {
66
  $error = $result->errors->deepAll()[0];
67
 
68
+ if ($error->code == Error\Codes::OAUTH_INVALID_GRANT) {
69
  $result->error = 'invalid_grant';
70
+ } else if ($error->code == Error\Codes::OAUTH_INVALID_CREDENTIALS) {
71
  $result->error = 'invalid_credentials';
72
+ } else if ($error->code == Error\Codes::OAUTH_INVALID_SCOPE) {
73
  $result->error = 'invalid_scope';
74
  }
75
  $result->errorDescription = explode(': ', $error->message)[1];
86
  return $result;
87
  }
88
 
89
+ public function connectUrl($params = [])
90
  {
91
+ $query = Util::camelCaseToDelimiterArray($params, '_');
92
  $query['client_id'] = $this->_config->getClientId();
93
  $queryString = preg_replace('/\%5B\d+\%5D/', '%5B%5D', http_build_query($query));
94
  $url = $this->_config->baseUrl() . '/oauth/connect?' . $queryString;
102
  return hash_hmac('sha256', $url, $key);
103
  }
104
  }
105
+ class_alias('Braintree\OAuthGateway', 'Braintree_OAuthGateway');
braintree_sdk/lib/Braintree/PartialMatchNode.php CHANGED
@@ -1,16 +1,18 @@
1
  <?php
 
2
 
3
- class Braintree_PartialMatchNode extends Braintree_EqualityNode
4
  {
5
- function startsWith($value)
6
  {
7
  $this->searchTerms["starts_with"] = strval($value);
8
  return $this;
9
  }
10
 
11
- function endsWith($value)
12
  {
13
  $this->searchTerms["ends_with"] = strval($value);
14
  return $this;
15
  }
16
  }
 
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');
braintree_sdk/lib/Braintree/PartnerMerchant.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  /**
3
  * Partner Merchant information that is generated when a partner is connected
4
  * to or disconnected from a user.
@@ -6,18 +8,17 @@
6
  * Creates an instance of PartnerMerchants
7
  *
8
  * @package Braintree
9
- * @copyright 2014 Braintree, a division of PayPal, Inc.
10
  *
11
  * @property-read string $merchantPublicId
12
  * @property-read string $publicKey
13
  * @property-read string $privateKey
14
  * @property-read string $clientSideEncryptionKey
15
  * @property-read string $partnerMerchantId
16
- * @uses Braintree_Instance inherits methods
17
  */
18
- class Braintree_PartnerMerchant extends Braintree_Base
19
  {
20
- protected $_attributes = array();
21
 
22
  /**
23
  * @ignore
@@ -38,3 +39,4 @@ class Braintree_PartnerMerchant extends Braintree_Base
38
  $this->_attributes = $attributes;
39
  }
40
  }
 
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.
8
  * Creates an instance of PartnerMerchants
9
  *
10
  * @package Braintree
11
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  *
13
  * @property-read string $merchantPublicId
14
  * @property-read string $publicKey
15
  * @property-read string $privateKey
16
  * @property-read string $clientSideEncryptionKey
17
  * @property-read string $partnerMerchantId
 
18
  */
19
+ class PartnerMerchant extends Base
20
  {
21
+ protected $_attributes = [];
22
 
23
  /**
24
  * @ignore
39
  $this->_attributes = $attributes;
40
  }
41
  }
42
+ class_alias('Braintree\PartnerMerchant', 'Braintree_PartnerMerchant');
braintree_sdk/lib/Braintree/PayPalAccount.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
 
 
2
  /**
3
  * Braintree PayPalAccount module
4
  *
5
  * @package Braintree
6
  * @category Resources
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -15,20 +17,21 @@
15
  *
16
  * @package Braintree
17
  * @category Resources
18
- * @copyright 2014 Braintree, a division of PayPal, Inc.
19
  *
 
20
  * @property-read string $email
21
  * @property-read string $token
22
  * @property-read string $imageUrl
23
  */
24
- class Braintree_PayPalAccount extends Braintree_Base
25
  {
26
  /**
27
- * factory method: returns an instance of Braintree_PayPalAccount
28
  * to the requesting method, with populated properties
29
  *
30
  * @ignore
31
- * @return object instance of Braintree_PayPalAccount
32
  */
33
  public static function factory($attributes)
34
  {
@@ -54,17 +57,17 @@ class Braintree_PayPalAccount extends Braintree_Base
54
  *
55
  * @access protected
56
  * @param array $paypalAccountAttribs array of paypalAccount data
57
- * @return none
58
  */
59
  protected function _initialize($paypalAccountAttribs)
60
  {
61
  // set the attributes
62
  $this->_attributes = $paypalAccountAttribs;
63
 
64
- $subscriptionArray = array();
65
  if (isset($paypalAccountAttribs['subscriptions'])) {
66
  foreach ($paypalAccountAttribs['subscriptions'] AS $subscription) {
67
- $subscriptionArray[] = Braintree_Subscription::factory($subscription);
68
  }
69
  }
70
 
@@ -79,7 +82,7 @@ class Braintree_PayPalAccount extends Braintree_Base
79
  public function __toString()
80
  {
81
  return __CLASS__ . '[' .
82
- Braintree_Util::attributesToString($this->_attributes) .']';
83
  }
84
 
85
 
@@ -87,21 +90,22 @@ class Braintree_PayPalAccount extends Braintree_Base
87
 
88
  public static function find($token)
89
  {
90
- return Braintree_Configuration::gateway()->payPalAccount()->find($token);
91
  }
92
 
93
  public static function update($token, $attributes)
94
  {
95
- return Braintree_Configuration::gateway()->payPalAccount()->update($token, $attributes);
96
  }
97
 
98
  public static function delete($token)
99
  {
100
- return Braintree_Configuration::gateway()->payPalAccount()->delete($token);
101
  }
102
 
103
  public static function sale($token, $transactionAttribs)
104
  {
105
- return Braintree_Configuration::gateway()->payPalAccount()->sale($token, $transactionAttribs);
106
  }
107
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree PayPalAccount module
6
  *
7
  * @package Braintree
8
  * @category Resources
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
 
12
  /**
17
  *
18
  * @package Braintree
19
  * @category Resources
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  *
22
+ * @property-read string $customerId
23
  * @property-read string $email
24
  * @property-read string $token
25
  * @property-read string $imageUrl
26
  */
27
+ class PayPalAccount extends Base
28
  {
29
  /**
30
+ * factory method: returns an instance of PayPalAccount
31
  * to the requesting method, with populated properties
32
  *
33
  * @ignore
34
+ * @return PayPalAccount
35
  */
36
  public static function factory($attributes)
37
  {
57
  *
58
  * @access protected
59
  * @param array $paypalAccountAttribs array of paypalAccount data
60
+ * @return void
61
  */
62
  protected function _initialize($paypalAccountAttribs)
63
  {
64
  // set the attributes
65
  $this->_attributes = $paypalAccountAttribs;
66
 
67
+ $subscriptionArray = [];
68
  if (isset($paypalAccountAttribs['subscriptions'])) {
69
  foreach ($paypalAccountAttribs['subscriptions'] AS $subscription) {
70
+ $subscriptionArray[] = Subscription::factory($subscription);
71
  }
72
  }
73
 
82
  public function __toString()
83
  {
84
  return __CLASS__ . '[' .
85
+ Util::attributesToString($this->_attributes) . ']';
86
  }
87
 
88
 
90
 
91
  public static function find($token)
92
  {
93
+ return Configuration::gateway()->payPalAccount()->find($token);
94
  }
95
 
96
  public static function update($token, $attributes)
97
  {
98
+ return Configuration::gateway()->payPalAccount()->update($token, $attributes);
99
  }
100
 
101
  public static function delete($token)
102
  {
103
+ return Configuration::gateway()->payPalAccount()->delete($token);
104
  }
105
 
106
  public static function sale($token, $transactionAttribs)
107
  {
108
+ return Configuration::gateway()->payPalAccount()->sale($token, $transactionAttribs);
109
  }
110
  }
111
+ class_alias('Braintree\PayPalAccount', 'Braintree_PayPalAccount');
braintree_sdk/lib/Braintree/PayPalAccountGateway.php CHANGED
@@ -1,10 +1,14 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Braintree PayPalAccountGateway module
4
  *
5
  * @package Braintree
6
  * @category Resources
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -15,9 +19,9 @@
15
  *
16
  * @package Braintree
17
  * @category Resources
18
- * @copyright 2014 Braintree, a division of PayPal, Inc.
19
  */
20
- class Braintree_PayPalAccountGateway
21
  {
22
  private $_gateway;
23
  private $_config;
@@ -28,7 +32,7 @@ class Braintree_PayPalAccountGateway
28
  $this->_gateway = $gateway;
29
  $this->_config = $gateway->config;
30
  $this->_config->assertHasAccessTokenOrKeys();
31
- $this->_http = new Braintree_Http($gateway->config);
32
  }
33
 
34
 
@@ -37,8 +41,8 @@ class Braintree_PayPalAccountGateway
37
  *
38
  * @access public
39
  * @param string $token paypal accountunique id
40
- * @return object Braintree_PayPalAccount
41
- * @throws Braintree_Exception_NotFound
42
  */
43
  public function find($token)
44
  {
@@ -46,9 +50,9 @@ class Braintree_PayPalAccountGateway
46
  try {
47
  $path = $this->_config->merchantPath() . '/payment_methods/paypal_account/' . $token;
48
  $response = $this->_http->get($path);
49
- return Braintree_PayPalAccount::factory($response['paypalAccount']);
50
- } catch (Braintree_Exception_NotFound $e) {
51
- throw new Braintree_Exception_NotFound(
52
  'paypal account with token ' . $token . ' not found'
53
  );
54
  }
@@ -64,13 +68,13 @@ class Braintree_PayPalAccountGateway
64
  * @access public
65
  * @param array $attributes
66
  * @param string $token (optional)
67
- * @return object Braintree_Result_Successful or Braintree_Result_Error
68
  */
69
  public function update($token, $attributes)
70
  {
71
- Braintree_Util::verifyKeys(self::updateSignature(), $attributes);
72
  $this->_validateId($token);
73
- return $this->_doUpdate('put', '/payment_methods/paypal_account/' . $token, array('paypalAccount' => $attributes));
74
  }
75
 
76
  public function delete($token)
@@ -78,7 +82,7 @@ class Braintree_PayPalAccountGateway
78
  $this->_validateId($token);
79
  $path = $this->_config->merchantPath() . '/payment_methods/paypal_account/' . $token;
80
  $this->_http->delete($path);
81
- return new Braintree_Result_Successful();
82
  }
83
 
84
  /**
@@ -86,26 +90,26 @@ class Braintree_PayPalAccountGateway
86
  *
87
  * @param string $token
88
  * @param array $transactionAttribs
89
- * @return object Braintree_Result_Successful or Braintree_Result_Error
90
- * @see Braintree_Transaction::sale()
91
  */
92
  public function sale($token, $transactionAttribs)
93
  {
94
  $this->_validateId($token);
95
- return Braintree_Transaction::sale(
96
  array_merge(
97
  $transactionAttribs,
98
- array('paymentMethodToken' => $token)
99
  )
100
  );
101
  }
102
 
103
  public static function updateSignature()
104
  {
105
- return array(
106
  'token',
107
- array('options' => array('makeDefault'))
108
- );
109
  }
110
 
111
  /**
@@ -126,27 +130,27 @@ class Braintree_PayPalAccountGateway
126
  /**
127
  * generic method for validating incoming gateway responses
128
  *
129
- * creates a new Braintree_PayPalAccount object and encapsulates
130
- * it inside a Braintree_Result_Successful object, or
131
- * encapsulates a Braintree_Errors object inside a Result_Error
132
  * alternatively, throws an Unexpected exception if the response is invalid.
133
  *
134
  * @ignore
135
  * @param array $response gateway response values
136
- * @return object Result_Successful or Result_Error
137
- * @throws Braintree_Exception_Unexpected
138
  */
139
  private function _verifyGatewayResponse($response)
140
  {
141
  if (isset($response['paypalAccount'])) {
142
- // return a populated instance of Braintree_PayPalAccount
143
- return new Braintree_Result_Successful(
144
- Braintree_PayPalAccount::factory($response['paypalAccount'])
145
  );
146
  } else if (isset($response['apiErrorResponse'])) {
147
- return new Braintree_Result_Error($response['apiErrorResponse']);
148
  } else {
149
- throw new Braintree_Exception_Unexpected(
150
  'Expected paypal account or apiErrorResponse'
151
  );
152
  }
@@ -173,3 +177,4 @@ class Braintree_PayPalAccountGateway
173
  }
174
  }
175
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
  /**
7
  * Braintree PayPalAccountGateway module
8
  *
9
  * @package Braintree
10
  * @category Resources
11
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
 
14
  /**
19
  *
20
  * @package Braintree
21
  * @category Resources
22
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
23
  */
24
+ class PayPalAccountGateway
25
  {
26
  private $_gateway;
27
  private $_config;
32
  $this->_gateway = $gateway;
33
  $this->_config = $gateway->config;
34
  $this->_config->assertHasAccessTokenOrKeys();
35
+ $this->_http = new Http($gateway->config);
36
  }
37
 
38
 
41
  *
42
  * @access public
43
  * @param string $token paypal accountunique id
44
+ * @return PayPalAccount
45
+ * @throws Exception\NotFound
46
  */
47
  public function find($token)
48
  {
50
  try {
51
  $path = $this->_config->merchantPath() . '/payment_methods/paypal_account/' . $token;
52
  $response = $this->_http->get($path);
53
+ return PayPalAccount::factory($response['paypalAccount']);
54
+ } catch (Exception\NotFound $e) {
55
+ throw new Exception\NotFound(
56
  'paypal account with token ' . $token . ' not found'
57
  );
58
  }
68
  * @access public
69
  * @param array $attributes
70
  * @param string $token (optional)
71
+ * @return Result\Successful or Result\Error
72
  */
73
  public function update($token, $attributes)
74
  {
75
+ Util::verifyKeys(self::updateSignature(), $attributes);
76
  $this->_validateId($token);
77
+ return $this->_doUpdate('put', '/payment_methods/paypal_account/' . $token, ['paypalAccount' => $attributes]);
78
  }
79
 
80
  public function delete($token)
82
  $this->_validateId($token);
83
  $path = $this->_config->merchantPath() . '/payment_methods/paypal_account/' . $token;
84
  $this->_http->delete($path);
85
+ return new Result\Successful();
86
  }
87
 
88
  /**
90
  *
91
  * @param string $token
92
  * @param array $transactionAttribs
93
+ * @return Result\Successful|Result\Error
94
+ * @see Transaction::sale()
95
  */
96
  public function sale($token, $transactionAttribs)
97
  {
98
  $this->_validateId($token);
99
+ return Transaction::sale(
100
  array_merge(
101
  $transactionAttribs,
102
+ ['paymentMethodToken' => $token]
103
  )
104
  );
105
  }
106
 
107
  public static function updateSignature()
108
  {
109
+ return [
110
  'token',
111
+ ['options' => ['makeDefault']]
112
+ ];
113
  }
114
 
115
  /**
130
  /**
131
  * generic method for validating incoming gateway responses
132
  *
133
+ * creates a new PayPalAccount object and encapsulates
134
+ * it inside a Result\Successful object, or
135
+ * encapsulates a Errors object inside a Result\Error
136
  * alternatively, throws an Unexpected exception if the response is invalid.
137
  *
138
  * @ignore
139
  * @param array $response gateway response values
140
+ * @return Result\Successful|Result\Error
141
+ * @throws Exception\Unexpected
142
  */
143
  private function _verifyGatewayResponse($response)
144
  {
145
  if (isset($response['paypalAccount'])) {
146
+ // return a populated instance of PayPalAccount
147
+ return new Result\Successful(
148
+ PayPalAccount::factory($response['paypalAccount'])
149
  );
150
  } else if (isset($response['apiErrorResponse'])) {
151
+ return new Result\Error($response['apiErrorResponse']);
152
  } else {
153
+ throw new Exception\Unexpected(
154
  'Expected paypal account or apiErrorResponse'
155
  );
156
  }
177
  }
178
  }
179
  }
180
+ class_alias('Braintree\PayPalAccountGateway', 'Braintree_PayPalAccountGateway');
braintree_sdk/lib/Braintree/PaymentInstrumentType.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
 
2
 
3
- final class Braintree_PaymentInstrumentType
4
  {
5
  const PAYPAL_ACCOUNT = 'paypal_account';
6
  const COINBASE_ACCOUNT = 'coinbase_account';
@@ -9,3 +10,4 @@ final class Braintree_PaymentInstrumentType
9
  const APPLE_PAY_CARD = 'apple_pay_card';
10
  const ANDROID_PAY_CARD = 'android_pay_card';
11
  }
 
1
  <?php
2
+ namespace Braintree;
3
 
4
+ final class PaymentInstrumentType
5
  {
6
  const PAYPAL_ACCOUNT = 'paypal_account';
7
  const COINBASE_ACCOUNT = 'coinbase_account';
10
  const APPLE_PAY_CARD = 'apple_pay_card';
11
  const ANDROID_PAY_CARD = 'android_pay_card';
12
  }
13
+ class_alias('Braintree\PaymentInstrumentType', 'Braintree_PaymentInstrumentType');
braintree_sdk/lib/Braintree/PaymentMethod.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
 
 
2
  /**
3
  * Braintree PaymentMethod module
4
  *
5
  * @package Braintree
6
  * @category Resources
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -15,30 +17,31 @@
15
  *
16
  * @package Braintree
17
  * @category Resources
18
- * @copyright 2014 Braintree, a division of PayPal, Inc.
19
  *
20
  */
21
- class Braintree_PaymentMethod extends Braintree_Base
22
  {
23
  // static methods redirecting to gateway
24
 
25
  public static function create($attribs)
26
  {
27
- return Braintree_Configuration::gateway()->paymentMethod()->create($attribs);
28
  }
29
 
30
  public static function find($token)
31
  {
32
- return Braintree_Configuration::gateway()->paymentMethod()->find($token);
33
  }
34
 
35
  public static function update($token, $attribs)
36
  {
37
- return Braintree_Configuration::gateway()->paymentMethod()->update($token, $attribs);
38
  }
39
 
40
  public static function delete($token)
41
  {
42
- return Braintree_Configuration::gateway()->paymentMethod()->delete($token);
43
  }
44
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree PaymentMethod module
6
  *
7
  * @package Braintree
8
  * @category Resources
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
 
12
  /**
17
  *
18
  * @package Braintree
19
  * @category Resources
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  *
22
  */
23
+ class PaymentMethod extends Base
24
  {
25
  // static methods redirecting to gateway
26
 
27
  public static function create($attribs)
28
  {
29
+ return Configuration::gateway()->paymentMethod()->create($attribs);
30
  }
31
 
32
  public static function find($token)
33
  {
34
+ return Configuration::gateway()->paymentMethod()->find($token);
35
  }
36
 
37
  public static function update($token, $attribs)
38
  {
39
+ return Configuration::gateway()->paymentMethod()->update($token, $attribs);
40
  }
41
 
42
  public static function delete($token)
43
  {
44
+ return Configuration::gateway()->paymentMethod()->delete($token);
45
  }
46
  }
47
+ class_alias('Braintree\PaymentMethod', 'Braintree_PaymentMethod');
braintree_sdk/lib/Braintree/PaymentMethodGateway.php CHANGED
@@ -1,10 +1,14 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Braintree PaymentMethodGateway module
4
  *
5
  * @package Braintree
6
  * @category Resources
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -15,10 +19,10 @@
15
  *
16
  * @package Braintree
17
  * @category Resources
18
- * @copyright 2014 Braintree, a division of PayPal, Inc.
19
  *
20
  */
21
- class Braintree_PaymentMethodGateway
22
  {
23
  private $_gateway;
24
  private $_config;
@@ -29,23 +33,22 @@ class Braintree_PaymentMethodGateway
29
  $this->_gateway = $gateway;
30
  $this->_config = $gateway->config;
31
  $this->_config->assertHasAccessTokenOrKeys();
32
- $this->_http = new Braintree_Http($gateway->config);
33
  }
34
 
35
 
36
  public function create($attribs)
37
  {
38
- Braintree_Util::verifyKeys(self::createSignature(), $attribs);
39
- return $this->_doCreate('/payment_methods', array('payment_method' => $attribs));
40
  }
41
 
42
  /**
43
  * find a PaymentMethod by token
44
  *
45
- * @access public
46
  * @param string $token payment method unique id
47
- * @return object Braintree_CreditCard or Braintree_PayPalAccount
48
- * @throws Braintree_Exception_NotFound
49
  */
50
  public function find($token)
51
  {
@@ -54,32 +57,35 @@ class Braintree_PaymentMethodGateway
54
  $path = $this->_config->merchantPath() . '/payment_methods/any/' . $token;
55
  $response = $this->_http->get($path);
56
  if (isset($response['creditCard'])) {
57
- return Braintree_CreditCard::factory($response['creditCard']);
58
  } else if (isset($response['paypalAccount'])) {
59
- return Braintree_PayPalAccount::factory($response['paypalAccount']);
60
  } else if (isset($response['coinbaseAccount'])) {
61
- return Braintree_CoinbaseAccount::factory($response['coinbaseAccount']);
62
  } else if (isset($response['applePayCard'])) {
63
- return Braintree_ApplePayCard::factory($response['applePayCard']);
64
  } else if (isset($response['androidPayCard'])) {
65
- return Braintree_AndroidPayCard::factory($response['androidPayCard']);
 
 
66
  } else if (isset($response['europeBankAccount'])) {
67
- return Braintree_EuropeBankAccount::factory($response['europeBankAccount']);
 
 
68
  } else if (is_array($response)) {
69
- return Braintree_UnknownPaymentMethod::factory($response);
70
  }
71
- } catch (Braintree_Exception_NotFound $e) {
72
- throw new Braintree_Exception_NotFound(
73
  'payment method with token ' . $token . ' not found'
74
  );
75
  }
76
-
77
  }
78
 
79
  public function update($token, $attribs)
80
  {
81
- Braintree_Util::verifyKeys(self::updateSignature(), $attribs);
82
- return $this->_doUpdate('/payment_methods/any/' . $token, array('payment_method' => $attribs));
83
  }
84
 
85
  public function delete($token)
@@ -87,19 +93,45 @@ class Braintree_PaymentMethodGateway
87
  $this->_validateId($token);
88
  $path = $this->_config->merchantPath() . '/payment_methods/any/' . $token;
89
  $this->_http->delete($path);
90
- return new Braintree_Result_Successful();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  }
92
 
93
  private static function baseSignature()
94
  {
95
- $billingAddressSignature = Braintree_AddressGateway::createSignature();
96
- $optionsSignature = array(
97
  'failOnDuplicatePaymentMethod',
98
  'makeDefault',
99
  'verificationMerchantAccountId',
100
- 'verifyCard'
101
- );
102
- return array(
 
103
  'billingAddressId',
104
  'cardholderName',
105
  'cvv',
@@ -110,31 +142,31 @@ class Braintree_PaymentMethodGateway
110
  'number',
111
  'paymentMethodNonce',
112
  'token',
113
- array('options' => $optionsSignature),
114
- array('billingAddress' => $billingAddressSignature)
115
- );
116
  }
117
 
118
  public static function createSignature()
119
  {
120
- $signature = array_merge(self::baseSignature(), array('customerId'));
121
  return $signature;
122
  }
123
 
124
  public static function updateSignature()
125
  {
126
- $billingAddressSignature = Braintree_AddressGateway::updateSignature();
127
- array_push($billingAddressSignature, array(
128
- 'options' => array(
129
  'updateExisting'
130
- )
131
- ));
132
- $signature = array_merge(self::baseSignature(), array(
133
  'deviceSessionId',
134
  'venmoSdkPaymentMethodCode',
135
  'fraudMerchantId',
136
- array('billingAddress' => $billingAddressSignature)
137
- ));
138
  return $signature;
139
  }
140
 
@@ -173,63 +205,72 @@ class Braintree_PaymentMethodGateway
173
  /**
174
  * generic method for validating incoming gateway responses
175
  *
176
- * creates a new Braintree_CreditCard or Braintree_PayPalAccount object
177
- * and encapsulates it inside a Braintree_Result_Successful object, or
178
- * encapsulates a Braintree_Errors object inside a Result_Error
179
  * alternatively, throws an Unexpected exception if the response is invalid.
180
  *
181
  * @ignore
182
  * @param array $response gateway response values
183
- * @return object Result_Successful or Result_Error
184
- * @throws Braintree_Exception_Unexpected
185
  */
186
  private function _verifyGatewayResponse($response)
187
  {
188
  if (isset($response['creditCard'])) {
189
- // return a populated instance of Braintree_CreditCard
190
- return new Braintree_Result_Successful(
191
- Braintree_CreditCard::factory($response['creditCard']),
192
- "paymentMethod"
193
  );
194
  } else if (isset($response['paypalAccount'])) {
195
- // return a populated instance of Braintree_PayPalAccount
196
- return new Braintree_Result_Successful(
197
- Braintree_PayPalAccount::factory($response['paypalAccount']),
198
  "paymentMethod"
199
  );
200
  } else if (isset($response['coinbaseAccount'])) {
201
- // return a populated instance of Braintree_CoinbaseAccount
202
- return new Braintree_Result_Successful(
203
- Braintree_CoinbaseAccount::factory($response['coinbaseAccount']),
204
  "paymentMethod"
205
  );
206
  } else if (isset($response['applePayCard'])) {
207
- // return a populated instance of Braintree_ApplePayCard
208
- return new Braintree_Result_Successful(
209
- Braintree_ApplePayCard::factory($response['applePayCard']),
210
  "paymentMethod"
211
  );
212
  } else if (isset($response['androidPayCard'])) {
213
- // return a populated instance of Braintree_AndroidPayCard
214
- return new Braintree_Result_Successful(
215
- Braintree_AndroidPayCard::factory($response['androidPayCard']),
 
 
 
 
216
  "paymentMethod"
217
  );
218
  } else if (isset($response['europeBankAccount'])) {
219
- // return a populated instance of Braintree_EuropeBankAccount
220
- return new Braintree_Result_Successful(
221
- Braintree_EuropeBankAccount::factory($response['europeBankAccount']),
 
 
 
 
222
  "paymentMethod"
223
  );
 
 
 
 
 
224
  } else if (isset($response['apiErrorResponse'])) {
225
- return new Braintree_Result_Error($response['apiErrorResponse']);
226
  } else if (is_array($response)) {
227
- return new Braintree_Result_Successful(
228
- Braintree_UnknownPaymentMethod::factory($response),
229
  "paymentMethod"
230
  );
231
  } else {
232
- throw new Braintree_Exception_Unexpected(
233
  'Expected payment method or apiErrorResponse'
234
  );
235
  }
@@ -256,3 +297,4 @@ class Braintree_PaymentMethodGateway
256
  }
257
  }
258
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
  /**
7
  * Braintree PaymentMethodGateway module
8
  *
9
  * @package Braintree
10
  * @category Resources
11
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
 
14
  /**
19
  *
20
  * @package Braintree
21
  * @category Resources
22
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
23
  *
24
  */
25
+ class PaymentMethodGateway
26
  {
27
  private $_gateway;
28
  private $_config;
33
  $this->_gateway = $gateway;
34
  $this->_config = $gateway->config;
35
  $this->_config->assertHasAccessTokenOrKeys();
36
+ $this->_http = new Http($gateway->config);
37
  }
38
 
39
 
40
  public function create($attribs)
41
  {
42
+ Util::verifyKeys(self::createSignature(), $attribs);
43
+ return $this->_doCreate('/payment_methods', ['payment_method' => $attribs]);
44
  }
45
 
46
  /**
47
  * find a PaymentMethod by token
48
  *
 
49
  * @param string $token payment method unique id
50
+ * @return CreditCard|PayPalAccount
51
+ * @throws Exception\NotFound
52
  */
53
  public function find($token)
54
  {
57
  $path = $this->_config->merchantPath() . '/payment_methods/any/' . $token;
58
  $response = $this->_http->get($path);
59
  if (isset($response['creditCard'])) {
60
+ return CreditCard::factory($response['creditCard']);
61
  } else if (isset($response['paypalAccount'])) {
62
+ return PayPalAccount::factory($response['paypalAccount']);
63
  } else if (isset($response['coinbaseAccount'])) {
64
+ return CoinbaseAccount::factory($response['coinbaseAccount']);
65
  } else if (isset($response['applePayCard'])) {
66
+ return ApplePayCard::factory($response['applePayCard']);
67
  } else if (isset($response['androidPayCard'])) {
68
+ return AndroidPayCard::factory($response['androidPayCard']);
69
+ } else if (isset($response['amexExpressCheckoutCard'])) {
70
+ return AmexExpressCheckoutCard::factory($response['amexExpressCheckoutCard']);
71
  } else if (isset($response['europeBankAccount'])) {
72
+ return EuropeBankAccount::factory($response['europeBankAccount']);
73
+ } else if (isset($response['venmoAccount'])) {
74
+ return VenmoAccount::factory($response['venmoAccount']);
75
  } else if (is_array($response)) {
76
+ return UnknownPaymentMethod::factory($response);
77
  }
78
+ } catch (Exception\NotFound $e) {
79
+ throw new Exception\NotFound(
80
  'payment method with token ' . $token . ' not found'
81
  );
82
  }
 
83
  }
84
 
85
  public function update($token, $attribs)
86
  {
87
+ Util::verifyKeys(self::updateSignature(), $attribs);
88
+ return $this->_doUpdate('/payment_methods/any/' . $token, ['payment_method' => $attribs]);
89
  }
90
 
91
  public function delete($token)
93
  $this->_validateId($token);
94
  $path = $this->_config->merchantPath() . '/payment_methods/any/' . $token;
95
  $this->_http->delete($path);
96
+ return new Result\Successful();
97
+ }
98
+
99
+ public function grant($sharedPaymentMethodToken, $allowVaulting)
100
+ {
101
+ return $this->_doCreate(
102
+ '/payment_methods/grant',
103
+ [
104
+ 'payment_method' => [
105
+ 'shared_payment_method_token' => $sharedPaymentMethodToken,
106
+ 'allow_vaulting' => $allowVaulting
107
+ ]
108
+ ]
109
+ );
110
+ }
111
+
112
+ public function revoke($sharedPaymentMethodToken)
113
+ {
114
+ return $this->_doCreate(
115
+ '/payment_methods/revoke',
116
+ [
117
+ 'payment_method' => [
118
+ 'shared_payment_method_token' => $sharedPaymentMethodToken
119
+ ]
120
+ ]
121
+ );
122
  }
123
 
124
  private static function baseSignature()
125
  {
126
+ $billingAddressSignature = AddressGateway::createSignature();
127
+ $optionsSignature = [
128
  'failOnDuplicatePaymentMethod',
129
  'makeDefault',
130
  'verificationMerchantAccountId',
131
+ 'verifyCard',
132
+ 'verificationAmount'
133
+ ];
134
+ return [
135
  'billingAddressId',
136
  'cardholderName',
137
  'cvv',
142
  'number',
143
  'paymentMethodNonce',
144
  'token',
145
+ ['options' => $optionsSignature],
146
+ ['billingAddress' => $billingAddressSignature]
147
+ ];
148
  }
149
 
150
  public static function createSignature()
151
  {
152
+ $signature = array_merge(self::baseSignature(), ['customerId']);
153
  return $signature;
154
  }
155
 
156
  public static function updateSignature()
157
  {
158
+ $billingAddressSignature = AddressGateway::updateSignature();
159
+ array_push($billingAddressSignature, [
160
+ 'options' => [
161
  'updateExisting'
162
+ ]
163
+ ]);
164
+ $signature = array_merge(self::baseSignature(), [
165
  'deviceSessionId',
166
  'venmoSdkPaymentMethodCode',
167
  'fraudMerchantId',
168
+ ['billingAddress' => $billingAddressSignature]
169
+ ]);
170
  return $signature;
171
  }
172
 
205
  /**
206
  * generic method for validating incoming gateway responses
207
  *
208
+ * creates a new CreditCard or PayPalAccount object
209
+ * and encapsulates it inside a Result\Successful object, or
210
+ * encapsulates a Errors object inside a Result\Error
211
  * alternatively, throws an Unexpected exception if the response is invalid.
212
  *
213
  * @ignore
214
  * @param array $response gateway response values
215
+ * @return Result\Successful|Result\Error
216
+ * @throws Exception\Unexpected
217
  */
218
  private function _verifyGatewayResponse($response)
219
  {
220
  if (isset($response['creditCard'])) {
221
+ return new Result\Successful(
222
+ CreditCard::factory($response['creditCard']),
223
+ 'paymentMethod'
 
224
  );
225
  } else if (isset($response['paypalAccount'])) {
226
+ return new Result\Successful(
227
+ PayPalAccount::factory($response['paypalAccount']),
 
228
  "paymentMethod"
229
  );
230
  } else if (isset($response['coinbaseAccount'])) {
231
+ return new Result\Successful(
232
+ CoinbaseAccount::factory($response['coinbaseAccount']),
 
233
  "paymentMethod"
234
  );
235
  } else if (isset($response['applePayCard'])) {
236
+ return new Result\Successful(
237
+ ApplePayCard::factory($response['applePayCard']),
 
238
  "paymentMethod"
239
  );
240
  } else if (isset($response['androidPayCard'])) {
241
+ return new Result\Successful(
242
+ AndroidPayCard::factory($response['androidPayCard']),
243
+ "paymentMethod"
244
+ );
245
+ } else if (isset($response['amexExpressCheckoutCard'])) {
246
+ return new Result\Successful(
247
+ AmexExpressCheckoutCard::factory($response['amexExpressCheckoutCard']),
248
  "paymentMethod"
249
  );
250
  } else if (isset($response['europeBankAccount'])) {
251
+ return new Result\Successful(
252
+ EuropeBankAccount::factory($response['europeBankAccount']),
253
+ "paymentMethod"
254
+ );
255
+ } else if (isset($response['venmoAccount'])) {
256
+ return new Result\Successful(
257
+ VenmoAccount::factory($response['venmoAccount']),
258
  "paymentMethod"
259
  );
260
+ } else if (isset($response['paymentMethodNonce'])) {
261
+ return new Result\Successful(
262
+ PaymentMethodNonce::factory($response['paymentMethodNonce']),
263
+ "paymentMethodNonce"
264
+ );
265
  } else if (isset($response['apiErrorResponse'])) {
266
+ return new Result\Error($response['apiErrorResponse']);
267
  } else if (is_array($response)) {
268
+ return new Result\Successful(
269
+ UnknownPaymentMethod::factory($response),
270
  "paymentMethod"
271
  );
272
  } else {
273
+ throw new Exception\Unexpected(
274
  'Expected payment method or apiErrorResponse'
275
  );
276
  }
297
  }
298
  }
299
  }
300
+ class_alias('Braintree\PaymentMethodGateway', 'Braintree_PaymentMethodGateway');
braintree_sdk/lib/Braintree/PaymentMethodNonce.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
 
 
2
  /**
3
  * Braintree PaymentMethodNonce module
4
  *
5
  * @package Braintree
6
  * @category Resources
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -15,21 +17,21 @@
15
  *
16
  * @package Braintree
17
  * @category Resources
18
- * @copyright 2014 Braintree, a division of PayPal, Inc.
19
  *
20
  */
21
- class Braintree_PaymentMethodNonce extends Braintree_Base
22
  {
23
  // static methods redirecting to gateway
24
 
25
  public static function create($token)
26
  {
27
- return Braintree_Configuration::gateway()->paymentMethodNonce()->create($token);
28
  }
29
 
30
  public static function find($nonce)
31
  {
32
- return Braintree_Configuration::gateway()->paymentMethodNonce()->find($nonce);
33
  }
34
 
35
  public static function factory($attributes)
@@ -46,7 +48,8 @@ class Braintree_PaymentMethodNonce extends Braintree_Base
46
  $this->_set('type', $nonceAttributes['type']);
47
 
48
  if(isset($nonceAttributes['threeDSecureInfo'])) {
49
- $this->_set('threeDSecureInfo', Braintree_ThreeDSecureInfo::factory($nonceAttributes['threeDSecureInfo']));
50
  }
51
  }
52
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree PaymentMethodNonce module
6
  *
7
  * @package Braintree
8
  * @category Resources
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
 
12
  /**
17
  *
18
  * @package Braintree
19
  * @category Resources
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  *
22
  */
23
+ class PaymentMethodNonce extends Base
24
  {
25
  // static methods redirecting to gateway
26
 
27
  public static function create($token)
28
  {
29
+ return Configuration::gateway()->paymentMethodNonce()->create($token);
30
  }
31
 
32
  public static function find($nonce)
33
  {
34
+ return Configuration::gateway()->paymentMethodNonce()->find($nonce);
35
  }
36
 
37
  public static function factory($attributes)
48
  $this->_set('type', $nonceAttributes['type']);
49
 
50
  if(isset($nonceAttributes['threeDSecureInfo'])) {
51
+ $this->_set('threeDSecureInfo', ThreeDSecureInfo::factory($nonceAttributes['threeDSecureInfo']));
52
  }
53
  }
54
  }
55
+ class_alias('Braintree\PaymentMethodNonce', 'Braintree_PaymentMethodNonce');
braintree_sdk/lib/Braintree/PaymentMethodNonceGateway.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
 
 
2
  /**
3
  * Braintree PaymentMethodNonceGateway module
4
  *
5
  * @package Braintree
6
  * @category Resources
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -15,10 +17,10 @@
15
  *
16
  * @package Braintree
17
  * @category Resources
18
- * @copyright 2014 Braintree, a division of PayPal, Inc.
19
  *
20
  */
21
- class Braintree_PaymentMethodNonceGateway
22
  {
23
  private $_gateway;
24
  private $_config;
@@ -28,7 +30,7 @@ class Braintree_PaymentMethodNonceGateway
28
  {
29
  $this->_gateway = $gateway;
30
  $this->_config = $gateway->config;
31
- $this->_http = new Braintree_Http($gateway->config);
32
  }
33
 
34
 
@@ -38,8 +40,8 @@ class Braintree_PaymentMethodNonceGateway
38
  $fullPath = $this->_config->merchantPath() . $subPath;
39
  $response = $this->_http->post($fullPath);
40
 
41
- return new Braintree_Result_Successful(
42
- Braintree_PaymentMethodNonce::factory($response['paymentMethodNonce']),
43
  "paymentMethodNonce"
44
  );
45
  }
@@ -53,12 +55,13 @@ class Braintree_PaymentMethodNonceGateway
53
  try {
54
  $path = $this->_config->merchantPath() . '/payment_method_nonces/' . $nonce;
55
  $response = $this->_http->get($path);
56
- return Braintree_PaymentMethodNonce::factory($response['paymentMethodNonce']);
57
- } catch (Braintree_Exception_NotFound $e) {
58
- throw new Braintree_Exception_NotFound(
59
  'payment method nonce with id ' . $nonce . ' not found'
60
  );
61
  }
62
 
63
  }
64
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree PaymentMethodNonceGateway module
6
  *
7
  * @package Braintree
8
  * @category Resources
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
 
12
  /**
17
  *
18
  * @package Braintree
19
  * @category Resources
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  *
22
  */
23
+ class PaymentMethodNonceGateway
24
  {
25
  private $_gateway;
26
  private $_config;
30
  {
31
  $this->_gateway = $gateway;
32
  $this->_config = $gateway->config;
33
+ $this->_http = new Http($gateway->config);
34
  }
35
 
36
 
40
  $fullPath = $this->_config->merchantPath() . $subPath;
41
  $response = $this->_http->post($fullPath);
42
 
43
+ return new Result\Successful(
44
+ PaymentMethodNonce::factory($response['paymentMethodNonce']),
45
  "paymentMethodNonce"
46
  );
47
  }
55
  try {
56
  $path = $this->_config->merchantPath() . '/payment_method_nonces/' . $nonce;
57
  $response = $this->_http->get($path);
58
+ return PaymentMethodNonce::factory($response['paymentMethodNonce']);
59
+ } catch (Exception\NotFound $e) {
60
+ throw new Exception\NotFound(
61
  'payment method nonce with id ' . $nonce . ' not found'
62
  );
63
  }
64
 
65
  }
66
  }
67
+ class_alias('Braintree\PaymentMethodNonceGateway', 'Braintree_PaymentMethodNonceGateway');
braintree_sdk/lib/Braintree/Plan.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_Plan extends Braintree_Base
 
 
3
  {
4
  public static function factory($attributes)
5
  {
@@ -13,26 +15,26 @@ class Braintree_Plan extends Braintree_Base
13
  {
14
  $this->_attributes = $attributes;
15
 
16
- $addOnArray = array();
17
  if (isset($attributes['addOns'])) {
18
  foreach ($attributes['addOns'] AS $addOn) {
19
- $addOnArray[] = Braintree_AddOn::factory($addOn);
20
  }
21
  }
22
  $this->_attributes['addOns'] = $addOnArray;
23
 
24
- $discountArray = array();
25
  if (isset($attributes['discounts'])) {
26
  foreach ($attributes['discounts'] AS $discount) {
27
- $discountArray[] = Braintree_Discount::factory($discount);
28
  }
29
  }
30
  $this->_attributes['discounts'] = $discountArray;
31
 
32
- $planArray = array();
33
  if (isset($attributes['plans'])) {
34
  foreach ($attributes['plans'] AS $plan) {
35
- $planArray[] = Braintree_Plan::factory($plan);
36
  }
37
  }
38
  $this->_attributes['plans'] = $planArray;
@@ -43,6 +45,7 @@ class Braintree_Plan extends Braintree_Base
43
 
44
  public static function all()
45
  {
46
- return Braintree_Configuration::gateway()->plan()->all();
47
  }
48
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ class Plan extends Base
5
  {
6
  public static function factory($attributes)
7
  {
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;
45
 
46
  public static function all()
47
  {
48
+ return Configuration::gateway()->plan()->all();
49
  }
50
  }
51
+ class_alias('Braintree\Plan', 'Braintree_Plan');
braintree_sdk/lib/Braintree/PlanGateway.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_PlanGateway
 
 
3
  {
4
  private $_gateway;
5
  private $_config;
@@ -10,7 +12,7 @@ class Braintree_PlanGateway
10
  $this->_gateway = $gateway;
11
  $this->_config = $gateway->config;
12
  $this->_config->assertHasAccessTokenOrKeys();
13
- $this->_http = new Braintree_Http($gateway->config);
14
  }
15
 
16
  public function all()
@@ -18,14 +20,15 @@ class Braintree_PlanGateway
18
  $path = $this->_config->merchantPath() . '/plans';
19
  $response = $this->_http->get($path);
20
  if (key_exists('plans', $response)){
21
- $plans = array("plan" => $response['plans']);
22
  } else {
23
- $plans = array("plan" => array());
24
  }
25
 
26
- return Braintree_Util::extractAttributeAsArray(
27
  $plans,
28
  'plan'
29
  );
30
  }
31
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ class PlanGateway
5
  {
6
  private $_gateway;
7
  private $_config;
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()
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');
braintree_sdk/lib/Braintree/RangeNode.php CHANGED
@@ -1,38 +1,40 @@
1
  <?php
 
2
 
3
- class Braintree_RangeNode
4
  {
5
- function __construct($name)
6
  {
7
  $this->name = $name;
8
- $this->searchTerms = array();
9
  }
10
 
11
- function greaterThanOrEqualTo($value)
12
  {
13
  $this->searchTerms['min'] = $value;
14
  return $this;
15
  }
16
 
17
- function lessThanOrEqualTo($value)
18
  {
19
  $this->searchTerms['max'] = $value;
20
  return $this;
21
  }
22
 
23
- function is($value)
24
  {
25
  $this->searchTerms['is'] = $value;
26
  return $this;
27
  }
28
 
29
- function between($min, $max)
30
  {
31
  return $this->greaterThanOrEqualTo($min)->lessThanOrEqualTo($max);
32
  }
33
 
34
- function toParam()
35
  {
36
  return $this->searchTerms;
37
  }
38
  }
 
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');
braintree_sdk/lib/Braintree/ResourceCollection.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Braintree ResourceCollection
4
  * ResourceCollection is a container object for result data
@@ -7,7 +11,7 @@
7
  *
8
  * example:
9
  * <code>
10
- * $result = Braintree_Customer::all();
11
  *
12
  * foreach($result as $transaction) {
13
  * print_r($transaction->id);
@@ -16,9 +20,9 @@
16
  *
17
  * @package Braintree
18
  * @subpackage Utility
19
- * @copyright 2014 Braintree, a division of PayPal, Inc.
20
  */
21
- class Braintree_ResourceCollection implements Iterator
22
  {
23
  private $_index;
24
  private $_batchIndex;
@@ -31,8 +35,8 @@ class Braintree_ResourceCollection implements Iterator
31
  *
32
  * expects an array of attributes with literal keys
33
  *
34
- * @param array $attributes
35
- * @param array $pagerAttribs
36
  */
37
  public function __construct($response, $pager)
38
  {
@@ -57,7 +61,7 @@ class Braintree_ResourceCollection implements Iterator
57
  public function firstItem()
58
  {
59
  $ids = $this->_ids;
60
- $page = $this->_getPage(array($ids[0]));
61
  return $page[0];
62
  }
63
 
@@ -108,7 +112,7 @@ class Braintree_ResourceCollection implements Iterator
108
  {
109
  if (empty($this->_ids))
110
  {
111
- $this->_items = array();
112
  }
113
  else
114
  {
@@ -121,21 +125,22 @@ class Braintree_ResourceCollection implements Iterator
121
  /**
122
  * requests the next page of results for the collection
123
  *
124
- * @return none
125
  */
126
  private function _getPage($ids)
127
  {
128
  $object = $this->_pager['object'];
129
  $method = $this->_pager['method'];
130
- $methodArgs = array();
131
  foreach ($this->_pager['methodArgs'] as $arg) {
132
  array_push($methodArgs, $arg);
133
  }
134
  array_push($methodArgs, $ids);
135
 
136
  return call_user_func_array(
137
- array($object, $method),
138
  $methodArgs
139
  );
140
  }
141
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ use Iterator;
5
+
6
  /**
7
  * Braintree ResourceCollection
8
  * ResourceCollection is a container object for result data
11
  *
12
  * example:
13
  * <code>
14
+ * $result = Customer::all();
15
  *
16
  * foreach($result as $transaction) {
17
  * print_r($transaction->id);
20
  *
21
  * @package Braintree
22
  * @subpackage Utility
23
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
24
  */
25
+ class ResourceCollection implements Iterator
26
  {
27
  private $_index;
28
  private $_batchIndex;
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
  {
61
  public function firstItem()
62
  {
63
  $ids = $this->_ids;
64
+ $page = $this->_getPage([$ids[0]]);
65
  return $page[0];
66
  }
67
 
112
  {
113
  if (empty($this->_ids))
114
  {
115
+ $this->_items = [];
116
  }
117
  else
118
  {
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
+ class_alias('Braintree\ResourceCollection', 'Braintree_ResourceCollection');
braintree_sdk/lib/Braintree/Result/CreditCardVerification.php CHANGED
@@ -1,4 +1,9 @@
1
  <?php
 
 
 
 
 
2
  /**
3
  * Braintree Credit Card Verification Result
4
  *
@@ -8,7 +13,7 @@
8
  *
9
  * @package Braintree
10
  * @subpackage Result
11
- * @copyright 2014 Braintree, a division of PayPal, Inc.
12
  *
13
  * @property-read string $avsErrorResponseCode
14
  * @property-read string $avsPostalCodeResponseCode
@@ -17,7 +22,7 @@
17
  * @property-read string $status
18
  *
19
  */
20
- class Braintree_Result_CreditCardVerification
21
  {
22
  // Status
23
  const FAILED = 'failed';
@@ -46,13 +51,13 @@ class Braintree_Result_CreditCardVerification
46
  * @ignore
47
  * @access protected
48
  * @param <type> $aAttribs array of properties to set - single level
49
- * @return none
50
  */
51
  private function _initializeFromArray($attributes)
52
  {
53
  if(isset($attributes['riskData']))
54
  {
55
- $attributes['riskData'] = Braintree_RiskData::factory($attributes['riskData']);
56
  }
57
 
58
  $this->_attributes = $attributes;
@@ -63,7 +68,6 @@ class Braintree_Result_CreditCardVerification
63
  }
64
 
65
  /**
66
- *
67
  * @ignore
68
  */
69
  public function __get($name)
@@ -79,16 +83,17 @@ class Braintree_Result_CreditCardVerification
79
  public function __toString()
80
  {
81
  return __CLASS__ . '[' .
82
- Braintree_Util::attributesToString($this->_attributes) .']';
83
  }
84
 
85
  public static function allStatuses()
86
  {
87
- return array(
88
- Braintree_Result_creditCardVerification::FAILED,
89
- Braintree_Result_creditCardVerification::GATEWAY_REJECTED,
90
- Braintree_Result_creditCardVerification::PROCESSOR_DECLINED,
91
- Braintree_Result_creditCardVerification::VERIFIED,
92
- );
93
  }
94
  }
 
1
  <?php
2
+ namespace Braintree\Result;
3
+
4
+ use Braintree\RiskData;
5
+ use Braintree\Util;
6
+
7
  /**
8
  * Braintree Credit Card Verification Result
9
  *
13
  *
14
  * @package Braintree
15
  * @subpackage Result
16
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
17
  *
18
  * @property-read string $avsErrorResponseCode
19
  * @property-read string $avsPostalCodeResponseCode
22
  * @property-read string $status
23
  *
24
  */
25
+ class CreditCardVerification
26
  {
27
  // Status
28
  const FAILED = 'failed';
51
  * @ignore
52
  * @access protected
53
  * @param <type> $aAttribs array of properties to set - single level
54
+ * @return void
55
  */
56
  private function _initializeFromArray($attributes)
57
  {
58
  if(isset($attributes['riskData']))
59
  {
60
+ $attributes['riskData'] = RiskData::factory($attributes['riskData']);
61
  }
62
 
63
  $this->_attributes = $attributes;
68
  }
69
 
70
  /**
 
71
  * @ignore
72
  */
73
  public function __get($name)
83
  public function __toString()
84
  {
85
  return __CLASS__ . '[' .
86
+ Util::attributesToString($this->_attributes) . ']';
87
  }
88
 
89
  public static function allStatuses()
90
  {
91
+ return [
92
+ CreditCardVerification::FAILED,
93
+ CreditCardVerification::GATEWAY_REJECTED,
94
+ CreditCardVerification::PROCESSOR_DECLINED,
95
+ CreditCardVerification::VERIFIED
96
+ ];
97
  }
98
  }
99
+ class_alias('Braintree\Result\CreditCardVerification', 'Braintree_Result_CreditCardVerification');
braintree_sdk/lib/Braintree/Result/Error.php CHANGED
@@ -1,4 +1,13 @@
1
  <?php
 
 
 
 
 
 
 
 
 
2
  /**
3
  * Braintree Error Result
4
  *
@@ -9,27 +18,26 @@
9
  * respond to the void request if it failed:
10
  *
11
  * <code>
12
- * $result = Braintree_Transaction::void('abc123');
13
  * if ($result->success) {
14
  * // Successful Result
15
  * } else {
16
- * // Braintree_Result_Error
17
  * }
18
  * </code>
19
  *
20
  * @package Braintree
21
  * @subpackage Result
22
- * @copyright 2014 Braintree, a division of PayPal, Inc.
23
  *
24
  * @property-read array $params original passed params
25
- * @property-read object $errors Braintree_Error_ErrorCollection
26
- * @property-read object $creditCardVerification credit card verification data
27
  */
28
- class Braintree_Result_Error extends Braintree_Base
29
  {
30
- /**
31
- *
32
- * @var boolean always false
33
  */
34
  public $success = false;
35
 
@@ -46,10 +54,10 @@ class Braintree_Result_Error extends Braintree_Base
46
  $pieces = preg_split("/[\[\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY);
47
  $params = $this->params;
48
  foreach(array_slice($pieces, 0, -1) as $key) {
49
- $params = $params[Braintree_Util::delimiterToCamelCase($key)];
50
  }
51
  if ($key != 'custom_fields') {
52
- $finalKey = Braintree_Util::delimiterToCamelCase(end($pieces));
53
  } else {
54
  $finalKey = end($pieces);
55
  }
@@ -65,45 +73,52 @@ class Braintree_Result_Error extends Braintree_Base
65
  public function __construct($response)
66
  {
67
  $this->_attributes = $response;
68
- $this->_set('errors', new Braintree_Error_ErrorCollection($response['errors']));
69
 
70
  if(isset($response['verification'])) {
71
- $this->_set('creditCardVerification', new Braintree_Result_CreditCardVerification($response['verification']));
72
  } else {
73
  $this->_set('creditCardVerification', null);
74
  }
75
 
76
  if(isset($response['transaction'])) {
77
- $this->_set('transaction', Braintree_Transaction::factory($response['transaction']));
78
  } else {
79
  $this->_set('transaction', null);
80
  }
81
 
82
  if(isset($response['subscription'])) {
83
- $this->_set('subscription', Braintree_Subscription::factory($response['subscription']));
84
  } else {
85
  $this->_set('subscription', null);
86
  }
87
 
88
  if(isset($response['merchantAccount'])) {
89
- $this->_set('merchantAccount', Braintree_MerchantAccount::factory($response['merchantAccount']));
90
  } else {
91
  $this->_set('merchantAccount', null);
92
  }
 
 
 
 
 
 
93
  }
94
 
95
  /**
96
  * create a printable representation of the object as:
97
  * ClassName[property=value, property=value]
98
  * @ignore
99
- * @return var
100
  */
101
  public function __toString()
102
  {
103
- $output = Braintree_Util::attributesToString($this->_attributes);
104
  if (isset($this->_creditCardVerification)) {
105
  $output .= sprintf('%s', $this->_creditCardVerification);
106
  }
107
- return __CLASS__ .'['.$output.']';
108
  }
109
  }
 
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
  *
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
32
  *
33
  * @property-read array $params original passed params
34
+ * @property-read Braintree\Error\ErrorCollection $errors
35
+ * @property-read Braintree\Result\CreditCardVerification $creditCardVerification credit card verification data
36
  */
37
+ class Error extends Base
38
  {
39
+ /**
40
+ * @var bool always false
 
41
  */
42
  public $success = false;
43
 
54
  $pieces = preg_split("/[\[\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY);
55
  $params = $this->params;
56
  foreach(array_slice($pieces, 0, -1) as $key) {
57
+ $params = $params[Util::delimiterToCamelCase($key)];
58
  }
59
  if ($key != 'custom_fields') {
60
+ $finalKey = Util::delimiterToCamelCase(end($pieces));
61
  } else {
62
  $finalKey = end($pieces);
63
  }
73
  public function __construct($response)
74
  {
75
  $this->_attributes = $response;
76
+ $this->_set('errors', new ErrorCollection($response['errors']));
77
 
78
  if(isset($response['verification'])) {
79
+ $this->_set('creditCardVerification', new CreditCardVerification($response['verification']));
80
  } else {
81
  $this->_set('creditCardVerification', null);
82
  }
83
 
84
  if(isset($response['transaction'])) {
85
+ $this->_set('transaction', Transaction::factory($response['transaction']));
86
  } else {
87
  $this->_set('transaction', null);
88
  }
89
 
90
  if(isset($response['subscription'])) {
91
+ $this->_set('subscription', Subscription::factory($response['subscription']));
92
  } else {
93
  $this->_set('subscription', null);
94
  }
95
 
96
  if(isset($response['merchantAccount'])) {
97
+ $this->_set('merchantAccount', MerchantAccount::factory($response['merchantAccount']));
98
  } else {
99
  $this->_set('merchantAccount', null);
100
  }
101
+
102
+ if(isset($response['verification'])) {
103
+ $this->_set('verification', new CreditCardVerification($response['verification']));
104
+ } else {
105
+ $this->_set('verification', null);
106
+ }
107
  }
108
 
109
  /**
110
  * create a printable representation of the object as:
111
  * ClassName[property=value, property=value]
112
  * @ignore
113
+ * @return string
114
  */
115
  public function __toString()
116
  {
117
+ $output = Util::attributesToString($this->_attributes);
118
  if (isset($this->_creditCardVerification)) {
119
  $output .= sprintf('%s', $this->_creditCardVerification);
120
  }
121
+ return __CLASS__ .'[' . $output . ']';
122
  }
123
  }
124
+ class_alias('Braintree\Result\Error', 'Braintree_Result_Error');
braintree_sdk/lib/Braintree/Result/Successful.php CHANGED
@@ -1,29 +1,34 @@
1
  <?php
 
 
 
 
 
2
  /**
3
  * Braintree Successful Result
4
  *
5
  * A Successful Result will be returned from gateway methods when
6
  * validations pass. It will provide access to the created resource.
7
  *
8
- * For example, when creating a customer, Braintree_Result_Successful will
9
  * respond to <b>customer</b> like so:
10
  *
11
  * <code>
12
- * $result = Braintree_Customer::create(array('first_name' => "John"));
13
  * if ($result->success) {
14
- * // Braintree_Result_Successful
15
  * echo "Created customer {$result->customer->id}";
16
  * } else {
17
- * // Braintree_Result_Error
18
  * }
19
  * </code>
20
  *
21
  *
22
  * @package Braintree
23
  * @subpackage Result
24
- * @copyright 2014 Braintree, a division of PayPal, Inc.
25
  */
26
- class Braintree_Result_Successful extends Braintree_Instance
27
  {
28
  /**
29
  *
@@ -38,17 +43,18 @@ class Braintree_Result_Successful extends Braintree_Instance
38
 
39
  /**
40
  * @ignore
41
- * @param string $classToReturn name of class to instantiate
 
42
  */
43
- public function __construct($objsToReturn = array(), $propertyNames = array())
44
  {
45
  // Sanitize arguments (preserves backwards compatibility)
46
- if (!is_array($objsToReturn)) { $objsToReturn = array($objsToReturn); }
47
- if (!is_array($propertyNames)) { $propertyNames = array($propertyNames); }
48
 
49
  $objects = $this->_mapPropertyNamesToObjsToReturn($propertyNames, $objsToReturn);
50
- $this->_attributes = array();
51
- $this->_returnObjectNames = array();
52
 
53
  foreach ($objects as $propertyName => $objToReturn) {
54
 
@@ -67,7 +73,7 @@ class Braintree_Result_Successful extends Braintree_Instance
67
  */
68
  public function __toString()
69
  {
70
- $objects = array();
71
  foreach ($this->_returnObjectNames as $returnObjectName) {
72
  array_push($objects, $this->$returnObjectName);
73
  }
@@ -76,11 +82,12 @@ class Braintree_Result_Successful extends Braintree_Instance
76
 
77
  private function _mapPropertyNamesToObjsToReturn($propertyNames, $objsToReturn) {
78
  if(count($objsToReturn) != count($propertyNames)) {
79
- $propertyNames = array();
80
  foreach ($objsToReturn as $obj) {
81
- array_push($propertyNames, Braintree_Util::cleanClassName(get_class($obj)));
82
  }
83
  }
84
  return array_combine($propertyNames, $objsToReturn);
85
  }
86
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
30
  */
31
+ class Successful extends Instance
32
  {
33
  /**
34
  *
43
 
44
  /**
45
  * @ignore
46
+ * @param array|null $objsToReturn
47
+ * @param array|null $propertyNames
48
  */
49
+ public function __construct($objsToReturn = [], $propertyNames = [])
50
  {
51
  // Sanitize arguments (preserves backwards compatibility)
52
+ if (!is_array($objsToReturn)) { $objsToReturn = [$objsToReturn]; }
53
+ if (!is_array($propertyNames)) { $propertyNames = [$propertyNames]; }
54
 
55
  $objects = $this->_mapPropertyNamesToObjsToReturn($propertyNames, $objsToReturn);
56
+ $this->_attributes = [];
57
+ $this->_returnObjectNames = [];
58
 
59
  foreach ($objects as $propertyName => $objToReturn) {
60
 
73
  */
74
  public function __toString()
75
  {
76
+ $objects = [];
77
  foreach ($this->_returnObjectNames as $returnObjectName) {
78
  array_push($objects, $this->$returnObjectName);
79
  }
82
 
83
  private function _mapPropertyNamesToObjsToReturn($propertyNames, $objsToReturn) {
84
  if(count($objsToReturn) != count($propertyNames)) {
85
+ $propertyNames = [];
86
  foreach ($objsToReturn as $obj) {
87
+ array_push($propertyNames, Util::cleanClassName(get_class($obj)));
88
  }
89
  }
90
  return array_combine($propertyNames, $objsToReturn);
91
  }
92
  }
93
+ class_alias('Braintree\Result\Successful', 'Braintree_Result_Successful');
braintree_sdk/lib/Braintree/RiskData.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_RiskData extends Braintree_Base
 
 
3
  {
4
  public static function factory($attributes)
5
  {
@@ -18,10 +20,11 @@ class Braintree_RiskData extends Braintree_Base
18
  * returns a string representation of the risk data
19
  * @return string
20
  */
21
- public function __toString()
22
  {
23
  return __CLASS__ . '[' .
24
- Braintree_Util::attributesToString($this->_attributes) .']';
25
  }
26
 
27
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ class RiskData extends Base
5
  {
6
  public static function factory($attributes)
7
  {
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');
braintree_sdk/lib/Braintree/SettlementBatchSummary.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
2
- class Braintree_SettlementBatchSummary extends Braintree_Base
 
 
3
  {
4
  /**
5
- *
6
  * @param array $attributes
7
- * @return Braintree_SettlementBatchSummary
8
  */
9
  public static function factory($attributes)
10
  {
@@ -30,13 +32,14 @@ class Braintree_SettlementBatchSummary extends Braintree_Base
30
 
31
  /**
32
  * static method redirecting to gateway
33
- *
34
  * @param string $settlement_date Date YYYY-MM-DD
35
  * @param string $groupByCustomField
36
- * @return Braintree_Result_Successful|Braintree_Result_Error
37
  */
38
  public static function generate($settlement_date, $groupByCustomField = NULL)
39
  {
40
- return Braintree_Configuration::gateway()->settlementBatchSummary()->generate($settlement_date, $groupByCustomField);
41
  }
42
  }
 
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
  {
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');
braintree_sdk/lib/Braintree/SettlementBatchSummaryGateway.php CHANGED
@@ -1,51 +1,52 @@
1
  <?php
 
2
 
3
- class Braintree_SettlementBatchSummaryGateway
4
  {
5
  /**
6
  *
7
- * @var Braintree_Gateway
8
  */
9
  private $_gateway;
10
-
11
  /**
12
  *
13
- * @var Braintree_Configuration
14
  */
15
  private $_config;
16
-
17
  /**
18
  *
19
- * @var Braintree_Http
20
  */
21
  private $_http;
22
 
23
  /**
24
- *
25
- * @param Braintree_Gateway $gateway
26
  */
27
  public function __construct($gateway)
28
  {
29
  $this->_gateway = $gateway;
30
  $this->_config = $gateway->config;
31
  $this->_config->assertHasAccessTokenOrKeys();
32
- $this->_http = new Braintree_Http($gateway->config);
33
  }
34
 
35
  /**
36
- *
37
  * @param string $settlement_date
38
  * @param string $groupByCustomField
39
- * @return Braintree_SettlementBatchSummary|Braintree_Result_Error
40
  */
41
  public function generate($settlement_date, $groupByCustomField = NULL)
42
  {
43
- $criteria = array('settlement_date' => $settlement_date);
44
  if (isset($groupByCustomField))
45
  {
46
  $criteria['group_by_custom_field'] = $groupByCustomField;
47
  }
48
- $params = array('settlement_batch_summary' => $criteria);
49
  $path = $this->_config->merchantPath() . '/settlement_batch_summary';
50
  $response = $this->_http->post($path, $params);
51
 
@@ -61,18 +62,18 @@ class Braintree_SettlementBatchSummaryGateway
61
  }
62
 
63
  /**
64
- *
65
  * @param string $groupByCustomField
66
  * @param array $records
67
- * @return array
68
  */
69
  private function _underscoreCustomField($groupByCustomField, $records)
70
  {
71
- $updatedRecords = array();
72
 
73
  foreach ($records as $record)
74
  {
75
- $camelized = Braintree_Util::delimiterToCamelCase($groupByCustomField);
76
  $record[$groupByCustomField] = $record[$camelized];
77
  unset($record[$camelized]);
78
  $updatedRecords[] = $record;
@@ -82,23 +83,24 @@ class Braintree_SettlementBatchSummaryGateway
82
  }
83
 
84
  /**
85
- *
86
  * @param array $response
87
- * @return \Braintree_Result_Successful|\Braintree_Result_Error
88
- * @throws Braintree_Exception_Unexpected
89
  */
90
  private function _verifyGatewayResponse($response)
91
  {
92
  if (isset($response['settlementBatchSummary'])) {
93
- return new Braintree_Result_Successful(
94
- Braintree_SettlementBatchSummary::factory($response['settlementBatchSummary'])
95
  );
96
  } else if (isset($response['apiErrorResponse'])) {
97
- return new Braintree_Result_Error($response['apiErrorResponse']);
98
  } else {
99
- throw new Braintree_Exception_Unexpected(
100
  "Expected settlementBatchSummary or apiErrorResponse"
101
  );
102
  }
103
  }
104
  }
 
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
 
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;
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');
braintree_sdk/lib/Braintree/SignatureService.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
 
2
 
3
- class Braintree_SignatureService
4
  {
5
 
6
  public function __construct($key, $digest)
@@ -20,3 +21,4 @@ class Braintree_SignatureService
20
  }
21
 
22
  }
 
1
  <?php
2
+ namespace Braintree;
3
 
4
+ class SignatureService
5
  {
6
 
7
  public function __construct($key, $digest)
21
  }
22
 
23
  }
24
+ class_alias('Braintree\SignatureService', 'Braintree_SignatureService');
braintree_sdk/lib/Braintree/Subscription.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  /**
3
  * Braintree Subscription module
4
  *
@@ -9,9 +11,9 @@
9
  * PHP Version 5
10
  *
11
  * @package Braintree
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  */
14
- class Braintree_Subscription extends Braintree_Base
15
  {
16
  const ACTIVE = 'Active';
17
  const CANCELED = 'Canceled';
@@ -42,38 +44,38 @@ class Braintree_Subscription extends Braintree_Base
42
  {
43
  $this->_attributes = $attributes;
44
 
45
- $addOnArray = array();
46
  if (isset($attributes['addOns'])) {
47
  foreach ($attributes['addOns'] AS $addOn) {
48
- $addOnArray[] = Braintree_AddOn::factory($addOn);
49
  }
50
  }
51
  $this->_attributes['addOns'] = $addOnArray;
52
 
53
- $discountArray = array();
54
  if (isset($attributes['discounts'])) {
55
  foreach ($attributes['discounts'] AS $discount) {
56
- $discountArray[] = Braintree_Discount::factory($discount);
57
  }
58
  }
59
  $this->_attributes['discounts'] = $discountArray;
60
 
61
  if (isset($attributes['descriptor'])) {
62
- $this->_set('descriptor', new Braintree_Descriptor($attributes['descriptor']));
63
  }
64
 
65
- $statusHistory = array();
66
  if (isset($attributes['statusHistory'])) {
67
  foreach ($attributes['statusHistory'] AS $history) {
68
- $statusHistory[] = new Braintree_Subscription_StatusDetails($history);
69
  }
70
  }
71
  $this->_attributes['statusHistory'] = $statusHistory;
72
 
73
- $transactionArray = array();
74
  if (isset($attributes['transactions'])) {
75
  foreach ($attributes['transactions'] AS $transaction) {
76
- $transactionArray[] = Braintree_Transaction::factory($transaction);
77
  }
78
  }
79
  $this->_attributes['transactions'] = $transactionArray;
@@ -85,9 +87,9 @@ class Braintree_Subscription extends Braintree_Base
85
  */
86
  public function __toString()
87
  {
88
- $excludedAttributes = array('statusHistory');
89
 
90
- $displayAttributes = array();
91
  foreach($this->_attributes as $key => $val) {
92
  if (!in_array($key, $excludedAttributes)) {
93
  $displayAttributes[$key] = $val;
@@ -95,7 +97,7 @@ class Braintree_Subscription extends Braintree_Base
95
  }
96
 
97
  return __CLASS__ . '[' .
98
- Braintree_Util::attributesToString($displayAttributes) .']';
99
  }
100
 
101
 
@@ -103,36 +105,37 @@ class Braintree_Subscription extends Braintree_Base
103
 
104
  public static function create($attributes)
105
  {
106
- return Braintree_Configuration::gateway()->subscription()->create($attributes);
107
  }
108
 
109
  public static function find($id)
110
  {
111
- return Braintree_Configuration::gateway()->subscription()->find($id);
112
  }
113
 
114
  public static function search($query)
115
  {
116
- return Braintree_Configuration::gateway()->subscription()->search($query);
117
  }
118
 
119
  public static function fetch($query, $ids)
120
  {
121
- return Braintree_Configuration::gateway()->subscription()->fetch($query, $ids);
122
  }
123
 
124
  public static function update($subscriptionId, $attributes)
125
  {
126
- return Braintree_Configuration::gateway()->subscription()->update($subscriptionId, $attributes);
127
  }
128
 
129
  public static function retryCharge($subscriptionId, $amount = null)
130
  {
131
- return Braintree_Configuration::gateway()->subscription()->retryCharge($subscriptionId, $amount);
132
  }
133
 
134
  public static function cancel($subscriptionId)
135
  {
136
- return Braintree_Configuration::gateway()->subscription()->cancel($subscriptionId);
137
  }
138
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree Subscription module
6
  *
11
  * PHP Version 5
12
  *
13
  * @package Braintree
14
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
  */
16
+ class Subscription extends Base
17
  {
18
  const ACTIVE = 'Active';
19
  const CANCELED = 'Canceled';
44
  {
45
  $this->_attributes = $attributes;
46
 
47
+ $addOnArray = [];
48
  if (isset($attributes['addOns'])) {
49
  foreach ($attributes['addOns'] AS $addOn) {
50
+ $addOnArray[] = AddOn::factory($addOn);
51
  }
52
  }
53
  $this->_attributes['addOns'] = $addOnArray;
54
 
55
+ $discountArray = [];
56
  if (isset($attributes['discounts'])) {
57
  foreach ($attributes['discounts'] AS $discount) {
58
+ $discountArray[] = Discount::factory($discount);
59
  }
60
  }
61
  $this->_attributes['discounts'] = $discountArray;
62
 
63
  if (isset($attributes['descriptor'])) {
64
+ $this->_set('descriptor', new Descriptor($attributes['descriptor']));
65
  }
66
 
67
+ $statusHistory = [];
68
  if (isset($attributes['statusHistory'])) {
69
  foreach ($attributes['statusHistory'] AS $history) {
70
+ $statusHistory[] = new Subscription\StatusDetails($history);
71
  }
72
  }
73
  $this->_attributes['statusHistory'] = $statusHistory;
74
 
75
+ $transactionArray = [];
76
  if (isset($attributes['transactions'])) {
77
  foreach ($attributes['transactions'] AS $transaction) {
78
+ $transactionArray[] = Transaction::factory($transaction);
79
  }
80
  }
81
  $this->_attributes['transactions'] = $transactionArray;
87
  */
88
  public function __toString()
89
  {
90
+ $excludedAttributes = ['statusHistory'];
91
 
92
+ $displayAttributes = [];
93
  foreach($this->_attributes as $key => $val) {
94
  if (!in_array($key, $excludedAttributes)) {
95
  $displayAttributes[$key] = $val;
97
  }
98
 
99
  return __CLASS__ . '[' .
100
+ Util::attributesToString($displayAttributes) .']';
101
  }
102
 
103
 
105
 
106
  public static function create($attributes)
107
  {
108
+ return Configuration::gateway()->subscription()->create($attributes);
109
  }
110
 
111
  public static function find($id)
112
  {
113
+ return Configuration::gateway()->subscription()->find($id);
114
  }
115
 
116
  public static function search($query)
117
  {
118
+ return Configuration::gateway()->subscription()->search($query);
119
  }
120
 
121
  public static function fetch($query, $ids)
122
  {
123
+ return Configuration::gateway()->subscription()->fetch($query, $ids);
124
  }
125
 
126
  public static function update($subscriptionId, $attributes)
127
  {
128
+ return Configuration::gateway()->subscription()->update($subscriptionId, $attributes);
129
  }
130
 
131
  public static function retryCharge($subscriptionId, $amount = null)
132
  {
133
+ return Configuration::gateway()->subscription()->retryCharge($subscriptionId, $amount);
134
  }
135
 
136
  public static function cancel($subscriptionId)
137
  {
138
+ return Configuration::gateway()->subscription()->cancel($subscriptionId);
139
  }
140
  }
141
+ class_alias('Braintree\Subscription', 'Braintree_Subscription');
braintree_sdk/lib/Braintree/Subscription/StatusDetails.php CHANGED
@@ -1,10 +1,14 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Status details from a subscription
4
  * Creates an instance of StatusDetails, as part of a subscription response
5
  *
6
  * @package Braintree
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  *
9
  * @property-read string $price
10
  * @property-read string $balance
@@ -12,8 +16,8 @@
12
  * @property-read string $timestamp
13
  * @property-read string $subscriptionSource
14
  * @property-read string $user
15
- * @uses Braintree_Instance inherits methods
16
  */
17
- class Braintree_Subscription_StatusDetails extends Braintree_Instance
18
  {
19
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  *
13
  * @property-read string $price
14
  * @property-read string $balance
16
  * @property-read string $timestamp
17
  * @property-read string $subscriptionSource
18
  * @property-read string $user
 
19
  */
20
+ class StatusDetails extends Instance
21
  {
22
  }
23
+ class_alias('Braintree\Subscription\StatusDetails', 'Braintree_Subscription_StatusDetails');
braintree_sdk/lib/Braintree/SubscriptionGateway.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Braintree SubscriptionGateway module
4
  *
@@ -9,9 +13,9 @@
9
  * PHP Version 5
10
  *
11
  * @package Braintree
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  */
14
- class Braintree_SubscriptionGateway
15
  {
16
  private $_gateway;
17
  private $_config;
@@ -22,14 +26,14 @@ class Braintree_SubscriptionGateway
22
  $this->_gateway = $gateway;
23
  $this->_config = $gateway->config;
24
  $this->_config->assertHasAccessTokenOrKeys();
25
- $this->_http = new Braintree_Http($gateway->config);
26
  }
27
 
28
  public function create($attributes)
29
  {
30
- Braintree_Util::verifyKeys(self::_createSignature(), $attributes);
31
  $path = $this->_config->merchantPath() . '/subscriptions';
32
- $response = $this->_http->post($path, array('subscription' => $attributes));
33
  return $this->_verifyGatewayResponse($response);
34
  }
35
 
@@ -40,43 +44,43 @@ class Braintree_SubscriptionGateway
40
  try {
41
  $path = $this->_config->merchantPath() . '/subscriptions/' . $id;
42
  $response = $this->_http->get($path);
43
- return Braintree_Subscription::factory($response['subscription']);
44
- } catch (Braintree_Exception_NotFound $e) {
45
- throw new Braintree_Exception_NotFound('subscription with id ' . $id . ' not found');
46
  }
47
 
48
  }
49
 
50
  public function search($query)
51
  {
52
- $criteria = array();
53
  foreach ($query as $term) {
54
  $criteria[$term->name] = $term->toparam();
55
  }
56
 
57
 
58
  $path = $this->_config->merchantPath() . '/subscriptions/advanced_search_ids';
59
- $response = $this->_http->post($path, array('search' => $criteria));
60
- $pager = array(
61
  'object' => $this,
62
  'method' => 'fetch',
63
- 'methodArgs' => array($query)
64
- );
65
 
66
- return new Braintree_ResourceCollection($response, $pager);
67
  }
68
 
69
  public function fetch($query, $ids)
70
  {
71
- $criteria = array();
72
  foreach ($query as $term) {
73
  $criteria[$term->name] = $term->toparam();
74
  }
75
- $criteria["ids"] = Braintree_SubscriptionSearch::ids()->in($ids)->toparam();
76
  $path = $this->_config->merchantPath() . '/subscriptions/advanced_search';
77
- $response = $this->_http->post($path, array('search' => $criteria));
78
 
79
- return Braintree_Util::extractAttributeAsArray(
80
  $response['subscriptions'],
81
  'subscription'
82
  );
@@ -84,22 +88,22 @@ class Braintree_SubscriptionGateway
84
 
85
  public function update($subscriptionId, $attributes)
86
  {
87
- Braintree_Util::verifyKeys(self::_updateSignature(), $attributes);
88
  $path = $this->_config->merchantPath() . '/subscriptions/' . $subscriptionId;
89
- $response = $this->_http->put($path, array('subscription' => $attributes));
90
  return $this->_verifyGatewayResponse($response);
91
  }
92
 
93
  public function retryCharge($subscriptionId, $amount = null)
94
  {
95
- $transaction_params = array('type' => Braintree_Transaction::SALE,
96
- 'subscriptionId' => $subscriptionId);
97
  if (isset($amount)) {
98
  $transaction_params['amount'] = $amount;
99
  }
100
 
101
  $path = $this->_config->merchantPath() . '/transactions';
102
- $response = $this->_http->post($path, array('transaction' => $transaction_params));
103
  return $this->_verifyGatewayResponse($response);
104
  }
105
 
@@ -113,7 +117,7 @@ class Braintree_SubscriptionGateway
113
  private static function _createSignature()
114
  {
115
  return array_merge(
116
- array(
117
  'billingDayOfMonth',
118
  'firstBillingDate',
119
  'createdAt',
@@ -129,9 +133,9 @@ class Braintree_SubscriptionGateway
129
  'trialDuration',
130
  'trialDurationUnit',
131
  'trialPeriod',
132
- array('descriptor' => array('name', 'phone', 'url')),
133
- array('options' => array('doNotInheritAddOnsOrDiscounts', 'startImmediately')),
134
- ),
135
  self::_addOnDiscountSignature()
136
  );
137
  }
@@ -139,34 +143,34 @@ class Braintree_SubscriptionGateway
139
  private static function _updateSignature()
140
  {
141
  return array_merge(
142
- array(
143
  'merchantAccountId', 'numberOfBillingCycles', 'paymentMethodToken', 'planId',
144
  'paymentMethodNonce', 'id', 'neverExpires', 'price',
145
- array('descriptor' => array('name', 'phone', 'url')),
146
- array('options' => array('prorateCharges', 'replaceAllAddOnsAndDiscounts', 'revertSubscriptionOnProrationFailure')),
147
- ),
148
  self::_addOnDiscountSignature()
149
  );
150
  }
151
 
152
  private static function _addOnDiscountSignature()
153
  {
154
- return array(
155
- array(
156
- 'addOns' => array(
157
- array('add' => array('amount', 'inheritedFromId', 'neverExpires', 'numberOfBillingCycles', 'quantity')),
158
- array('update' => array('amount', 'existingId', 'neverExpires', 'numberOfBillingCycles', 'quantity')),
159
- array('remove' => array('_anyKey_')),
160
- )
161
- ),
162
- array(
163
- 'discounts' => array(
164
- array('add' => array('amount', 'inheritedFromId', 'neverExpires', 'numberOfBillingCycles', 'quantity')),
165
- array('update' => array('amount', 'existingId', 'neverExpires', 'numberOfBillingCycles', 'quantity')),
166
- array('remove' => array('_anyKey_')),
167
- )
168
- )
169
- );
170
  }
171
 
172
  /**
@@ -191,20 +195,21 @@ class Braintree_SubscriptionGateway
191
  private function _verifyGatewayResponse($response)
192
  {
193
  if (isset($response['subscription'])) {
194
- return new Braintree_Result_Successful(
195
- Braintree_Subscription::factory($response['subscription'])
196
  );
197
  } else if (isset($response['transaction'])) {
198
- // return a populated instance of Braintree_Transaction, for subscription retryCharge
199
- return new Braintree_Result_Successful(
200
- Braintree_Transaction::factory($response['transaction'])
201
  );
202
  } else if (isset($response['apiErrorResponse'])) {
203
- return new Braintree_Result_Error($response['apiErrorResponse']);
204
  } else {
205
- throw new Braintree_Exception_Unexpected(
206
  "Expected subscription, transaction, or apiErrorResponse"
207
  );
208
  }
209
  }
210
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
  /**
7
  * Braintree SubscriptionGateway module
8
  *
13
  * PHP Version 5
14
  *
15
  * @package Braintree
16
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
17
  */
18
+ class SubscriptionGateway
19
  {
20
  private $_gateway;
21
  private $_config;
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($attributes)
33
  {
34
+ Util::verifyKeys(self::_createSignature(), $attributes);
35
  $path = $this->_config->merchantPath() . '/subscriptions';
36
+ $response = $this->_http->post($path, ['subscription' => $attributes]);
37
  return $this->_verifyGatewayResponse($response);
38
  }
39
 
44
  try {
45
  $path = $this->_config->merchantPath() . '/subscriptions/' . $id;
46
  $response = $this->_http->get($path);
47
+ return Subscription::factory($response['subscription']);
48
+ } catch (Exception\NotFound $e) {
49
+ throw new Exception\NotFound('subscription with id ' . $id . ' not found');
50
  }
51
 
52
  }
53
 
54
  public function search($query)
55
  {
56
+ $criteria = [];
57
  foreach ($query as $term) {
58
  $criteria[$term->name] = $term->toparam();
59
  }
60
 
61
 
62
  $path = $this->_config->merchantPath() . '/subscriptions/advanced_search_ids';
63
+ $response = $this->_http->post($path, ['search' => $criteria]);
64
+ $pager = [
65
  'object' => $this,
66
  'method' => 'fetch',
67
+ 'methodArgs' => [$query]
68
+ ];
69
 
70
+ return new ResourceCollection($response, $pager);
71
  }
72
 
73
  public function fetch($query, $ids)
74
  {
75
+ $criteria = [];
76
  foreach ($query as $term) {
77
  $criteria[$term->name] = $term->toparam();
78
  }
79
+ $criteria["ids"] = SubscriptionSearch::ids()->in($ids)->toparam();
80
  $path = $this->_config->merchantPath() . '/subscriptions/advanced_search';
81
+ $response = $this->_http->post($path, ['search' => $criteria]);
82
 
83
+ return Util::extractAttributeAsArray(
84
  $response['subscriptions'],
85
  'subscription'
86
  );
88
 
89
  public function update($subscriptionId, $attributes)
90
  {
91
+ Util::verifyKeys(self::_updateSignature(), $attributes);
92
  $path = $this->_config->merchantPath() . '/subscriptions/' . $subscriptionId;
93
+ $response = $this->_http->put($path, ['subscription' => $attributes]);
94
  return $this->_verifyGatewayResponse($response);
95
  }
96
 
97
  public function retryCharge($subscriptionId, $amount = null)
98
  {
99
+ $transaction_params = ['type' => Transaction::SALE,
100
+ 'subscriptionId' => $subscriptionId];
101
  if (isset($amount)) {
102
  $transaction_params['amount'] = $amount;
103
  }
104
 
105
  $path = $this->_config->merchantPath() . '/transactions';
106
+ $response = $this->_http->post($path, ['transaction' => $transaction_params]);
107
  return $this->_verifyGatewayResponse($response);
108
  }
109
 
117
  private static function _createSignature()
118
  {
119
  return array_merge(
120
+ [
121
  'billingDayOfMonth',
122
  'firstBillingDate',
123
  'createdAt',
133
  'trialDuration',
134
  'trialDurationUnit',
135
  'trialPeriod',
136
+ ['descriptor' => ['name', 'phone', 'url']],
137
+ ['options' => ['doNotInheritAddOnsOrDiscounts', 'startImmediately']],
138
+ ],
139
  self::_addOnDiscountSignature()
140
  );
141
  }
143
  private static function _updateSignature()
144
  {
145
  return array_merge(
146
+ [
147
  'merchantAccountId', 'numberOfBillingCycles', 'paymentMethodToken', 'planId',
148
  'paymentMethodNonce', 'id', 'neverExpires', 'price',
149
+ ['descriptor' => ['name', 'phone', 'url']],
150
+ ['options' => ['prorateCharges', 'replaceAllAddOnsAndDiscounts', 'revertSubscriptionOnProrationFailure']],
151
+ ],
152
  self::_addOnDiscountSignature()
153
  );
154
  }
155
 
156
  private static function _addOnDiscountSignature()
157
  {
158
+ return [
159
+ [
160
+ 'addOns' => [
161
+ ['add' => ['amount', 'inheritedFromId', 'neverExpires', 'numberOfBillingCycles', 'quantity']],
162
+ ['update' => ['amount', 'existingId', 'neverExpires', 'numberOfBillingCycles', 'quantity']],
163
+ ['remove' => ['_anyKey_']],
164
+ ]
165
+ ],
166
+ [
167
+ 'discounts' => [
168
+ ['add' => ['amount', 'inheritedFromId', 'neverExpires', 'numberOfBillingCycles', 'quantity']],
169
+ ['update' => ['amount', 'existingId', 'neverExpires', 'numberOfBillingCycles', 'quantity']],
170
+ ['remove' => ['_anyKey_']],
171
+ ]
172
+ ]
173
+ ];
174
  }
175
 
176
  /**
195
  private function _verifyGatewayResponse($response)
196
  {
197
  if (isset($response['subscription'])) {
198
+ return new Result\Successful(
199
+ Subscription::factory($response['subscription'])
200
  );
201
  } else if (isset($response['transaction'])) {
202
+ // return a populated instance of Transaction, for subscription retryCharge
203
+ return new Result\Successful(
204
+ Transaction::factory($response['transaction'])
205
  );
206
  } else if (isset($response['apiErrorResponse'])) {
207
+ return new Result\Error($response['apiErrorResponse']);
208
  } else {
209
+ throw new Exception\Unexpected(
210
  "Expected subscription, transaction, or apiErrorResponse"
211
  );
212
  }
213
  }
214
  }
215
+ class_alias('Braintree\SubscriptionGateway', 'Braintree_SubscriptionGateway');
braintree_sdk/lib/Braintree/SubscriptionSearch.php CHANGED
@@ -1,64 +1,67 @@
1
  <?php
2
- class Braintree_SubscriptionSearch
 
 
3
  {
4
- static function billingCyclesRemaining()
5
  {
6
- return new Braintree_RangeNode('billing_cycles_remaining');
7
  }
8
 
9
- static function daysPastDue()
10
  {
11
- return new Braintree_RangeNode('days_past_due');
12
  }
13
 
14
- static function id()
15
  {
16
- return new Braintree_TextNode('id');
17
  }
18
 
19
- static function inTrialPeriod()
20
  {
21
- return new Braintree_MultipleValueNode('in_trial_period', array(true, false));
22
  }
23
 
24
- static function merchantAccountId()
25
  {
26
- return new Braintree_MultipleValueNode('merchant_account_id');
27
  }
28
 
29
- static function nextBillingDate()
30
  {
31
- return new Braintree_RangeNode('next_billing_date');
32
  }
33
 
34
- static function planId()
35
  {
36
- return new Braintree_MultipleValueOrTextNode('plan_id');
37
  }
38
 
39
- static function price()
40
  {
41
- return new Braintree_RangeNode('price');
42
  }
43
 
44
- static function status()
45
  {
46
- return new Braintree_MultipleValueNode("status", array(
47
- Braintree_Subscription::ACTIVE,
48
- Braintree_Subscription::CANCELED,
49
- Braintree_Subscription::EXPIRED,
50
- Braintree_Subscription::PAST_DUE,
51
- Braintree_Subscription::PENDING
52
- ));
53
  }
54
 
55
- static function transactionId()
56
  {
57
- return new Braintree_TextNode('transaction_id');
58
  }
59
 
60
- static function ids()
61
  {
62
- return new Braintree_MultipleValueNode('ids');
63
  }
64
  }
 
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
+ class_alias('Braintree\SubscriptionSearch', 'Braintree_SubscriptionSearch');
braintree_sdk/lib/Braintree/Test/CreditCardNumbers.php CHANGED
@@ -1,61 +1,67 @@
1
  <?php
 
2
 
3
  /**
4
  * Credit card information used for testing purposes
5
  *
6
- * The constants contained in the Braintree_Test_CreditCardNumbers class provide
7
  * credit card numbers that should be used when working in the sandbox environment.
8
  * The sandbox will not accept any credit card numbers other than the ones listed below.
9
  *
10
  * @package Braintree
11
  * @subpackage Test
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  */
14
- class Braintree_Test_CreditCardNumbers
15
  {
16
- public static $amExes = array(
17
  '378282246310005',
18
  '371449635398431',
19
  '378734493671000',
20
- );
21
- public static $carteBlanches = array('30569309025904',);
22
- public static $dinersClubs = array('38520000023237',);
23
- public static $discoverCards = array(
24
  '6011111111111117',
25
  '6011000990139424',
26
- );
27
- public static $JCBs = array(
28
  '3530111333300000',
29
  '3566002020360505',
30
- );
31
 
32
  public static $masterCard = '5555555555554444';
33
  public static $masterCardInternational = '5105105105105100';
34
- public static $masterCards = array(
35
  '5105105105105100',
36
  '5555555555554444',
37
- );
38
 
39
  public static $visa = '4012888888881881';
40
  public static $visaInternational = '4009348888881881';
41
- public static $visas = array(
42
  '4009348888881881',
43
  '4012888888881881',
44
  '4111111111111111',
45
  '4000111111111115',
46
- );
47
 
48
- public static $unknowns = array(
49
  '1000000000000008',
50
- );
51
 
52
- public static $failsSandboxVerification = array(
53
  'AmEx' => '378734493671000',
54
  'Discover' => '6011000990139424',
55
  'MasterCard' => '5105105105105100',
56
  'Visa' => '4000111111111115',
57
- );
58
 
 
 
 
 
 
59
 
60
  public static function getAll()
61
  {
@@ -67,3 +73,4 @@ class Braintree_Test_CreditCardNumbers
67
  );
68
  }
69
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
14
  */
15
+ class CreditCardNumbers
16
  {
17
+ public static $amExes = [
18
  '378282246310005',
19
  '371449635398431',
20
  '378734493671000',
21
+ ];
22
+ public static $carteBlanches = ['30569309025904',];
23
+ public static $dinersClubs = ['38520000023237',];
24
+ public static $discoverCards = [
25
  '6011111111111117',
26
  '6011000990139424',
27
+ ];
28
+ public static $JCBs = [
29
  '3530111333300000',
30
  '3566002020360505',
31
+ ];
32
 
33
  public static $masterCard = '5555555555554444';
34
  public static $masterCardInternational = '5105105105105100';
35
+ public static $masterCards = [
36
  '5105105105105100',
37
  '5555555555554444',
38
+ ];
39
 
40
  public static $visa = '4012888888881881';
41
  public static $visaInternational = '4009348888881881';
42
+ public static $visas = [
43
  '4009348888881881',
44
  '4012888888881881',
45
  '4111111111111111',
46
  '4000111111111115',
47
+ ];
48
 
49
+ public static $unknowns = [
50
  '1000000000000008',
51
+ ];
52
 
53
+ public static $failsSandboxVerification = [
54
  'AmEx' => '378734493671000',
55
  'Discover' => '6011000990139424',
56
  'MasterCard' => '5105105105105100',
57
  'Visa' => '4000111111111115',
58
+ ];
59
 
60
+ public static $amexPayWithPoints = [
61
+ 'Success' => "371260714673002",
62
+ 'IneligibleCard' => "378267515471109",
63
+ 'InsufficientPoints' => "371544868764018",
64
+ ];
65
 
66
  public static function getAll()
67
  {
73
  );
74
  }
75
  }
76
+ class_alias('Braintree\Test\CreditCardNumbers', 'Braintree_Test_CreditCardNumbers');
braintree_sdk/lib/Braintree/Test/MerchantAccount.php CHANGED
@@ -1,12 +1,14 @@
1
  <?php
 
 
2
  /**
3
  * Merchant Account constants used for testing purposes
4
  *
5
  * @package Braintree
6
  * @subpackage Test
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Test_MerchantAccount
10
  {
11
  public static $approve = "approve_me";
12
 
@@ -17,3 +19,4 @@ class Braintree_Test_MerchantAccount
17
 
18
 
19
  }
 
1
  <?php
2
+ namespace Braintree\Test;
3
+
4
  /**
5
  * Merchant Account constants used for testing purposes
6
  *
7
  * @package Braintree
8
  * @subpackage Test
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
+ class MerchantAccount
12
  {
13
  public static $approve = "approve_me";
14
 
19
 
20
 
21
  }
22
+ class_alias('Braintree\Test\MerchantAccount', 'Braintree_Test_MerchantAccount');
braintree_sdk/lib/Braintree/Test/Nonces.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
 
 
2
  /**
3
  * Nonces used for testing purposes
4
  *
5
  * @package Braintree
6
  * @subpackage Test
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -15,9 +17,9 @@
15
  *
16
  * @package Braintree
17
  * @subpackage Test
18
- * @copyright 2014 Braintree, a division of PayPal, Inc.
19
  */
20
- class Braintree_Test_Nonces
21
  {
22
  public static $transactable = "fake-valid-nonce";
23
  public static $consumed = "fake-consumed-nonce";
@@ -32,6 +34,7 @@ class Braintree_Test_Nonces
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 $abstractTransactable = "fake-abstract-transactable-nonce";
36
  public static $europe = "fake-europe-bank-account-nonce";
37
  public static $coinbase = "fake-coinbase-nonce";
@@ -62,4 +65,6 @@ class Braintree_Test_Nonces
62
  public static $paypalFuturePaymentRefreshToken = "fake-paypal-future-refresh-token-nonce";
63
  public static $sepa = "fake-sepa-bank-account-nonce";
64
  public static $gatewayRejectedFraud = "fake-gateway-rejected-fraud-nonce";
 
65
  }
 
1
  <?php
2
+ namespace Braintree\Test;
3
+
4
  /**
5
  * Nonces used for testing purposes
6
  *
7
  * @package Braintree
8
  * @subpackage Test
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
 
12
  /**
17
  *
18
  * @package Braintree
19
  * @subpackage Test
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  */
22
+ class Nonces
23
  {
24
  public static $transactable = "fake-valid-nonce";
25
  public static $consumed = "fake-consumed-nonce";
34
  public static $androidPayVisa = "fake-android-pay-visa-nonce";
35
  public static $androidPayMasterCard = "fake-android-pay-mastercard-nonce";
36
  public static $androidPayAmEx = "fake-android-pay-amex-nonce";
37
+ public static $amexExpressCheckout = "fake-amex-express-checkout-nonce";
38
  public static $abstractTransactable = "fake-abstract-transactable-nonce";
39
  public static $europe = "fake-europe-bank-account-nonce";
40
  public static $coinbase = "fake-coinbase-nonce";
65
  public static $paypalFuturePaymentRefreshToken = "fake-paypal-future-refresh-token-nonce";
66
  public static $sepa = "fake-sepa-bank-account-nonce";
67
  public static $gatewayRejectedFraud = "fake-gateway-rejected-fraud-nonce";
68
+ public static $venmoAccount = "fake-venmo-account-nonce";
69
  }
70
+ class_alias('Braintree\Test\Nonces', 'Braintree_Test_Nonces');
braintree_sdk/lib/Braintree/Test/Transaction.php CHANGED
@@ -1,51 +1,64 @@
1
  <?php
2
- final class Braintree_Test_Transaction
 
 
 
 
 
 
 
 
 
 
 
 
3
  {
4
  /**
5
  * settle a transaction by id in sandbox
6
  *
7
  * @param string $id transaction id
8
- * @param Braintree_Configuration $config gateway config
9
- * @return object Braintree_Transaction
10
  */
11
  public static function settle($transactionId)
12
  {
13
- return Braintree_Configuration::gateway()->testing()->settle($transactionId);
14
  }
15
 
16
  /**
17
  * settlement confirm a transaction by id in sandbox
18
  *
19
  * @param string $id transaction id
20
- * @param Braintree_Configuration $config gateway config
21
- * @return object Braintree_Transaction
22
  */
23
  public static function settlementConfirm($transactionId)
24
  {
25
- return Braintree_Configuration::gateway()->testing()->settlementConfirm($transactionId);
26
  }
27
 
28
  /**
29
  * settlement decline a transaction by id in sandbox
30
  *
31
  * @param string $id transaction id
32
- * @param Braintree_Configuration $config gateway config
33
- * @return object Braintree_Transaction
34
  */
35
  public static function settlementDecline($transactionId)
36
  {
37
- return Braintree_Configuration::gateway()->testing()->settlementDecline($transactionId);
38
  }
39
 
40
  /**
41
  * settlement pending a transaction by id in sandbox
42
  *
43
  * @param string $id transaction id
44
- * @param Braintree_Configuration $config gateway config
45
- * @return object Braintree_Transaction
46
  */
47
  public static function settlementPending($transactionId)
48
  {
49
- return Braintree_Configuration::gateway()->testing()->settlementPending($transactionId);
50
  }
51
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
+ */
14
+ final class Transaction
15
  {
16
  /**
17
  * settle a transaction by id in sandbox
18
  *
19
  * @param string $id transaction id
20
+ * @param Configuration $config gateway config
21
+ * @return Transaction
22
  */
23
  public static function settle($transactionId)
24
  {
25
+ return Configuration::gateway()->testing()->settle($transactionId);
26
  }
27
 
28
  /**
29
  * settlement confirm a transaction by id in sandbox
30
  *
31
  * @param string $id transaction id
32
+ * @param Configuration $config gateway config
33
+ * @return Transaction
34
  */
35
  public static function settlementConfirm($transactionId)
36
  {
37
+ return Configuration::gateway()->testing()->settlementConfirm($transactionId);
38
  }
39
 
40
  /**
41
  * settlement decline a transaction by id in sandbox
42
  *
43
  * @param string $id transaction id
44
+ * @param Configuration $config gateway config
45
+ * @return Transaction
46
  */
47
  public static function settlementDecline($transactionId)
48
  {
49
+ return Configuration::gateway()->testing()->settlementDecline($transactionId);
50
  }
51
 
52
  /**
53
  * settlement pending a transaction by id in sandbox
54
  *
55
  * @param string $id transaction id
56
+ * @param Configuration $config gateway config
57
+ * @return Transaction
58
  */
59
  public static function settlementPending($transactionId)
60
  {
61
+ return Configuration::gateway()->testing()->settlementPending($transactionId);
62
  }
63
  }
64
+ class_alias('Braintree\Test\Transaction', 'Braintree_Test_Transaction');
braintree_sdk/lib/Braintree/Test/TransactionAmounts.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
 
3
  /**
4
  * Transaction amounts used for testing purposes
@@ -8,10 +9,11 @@
8
  *
9
  * @package Braintree
10
  * @subpackage Test
11
- * @copyright 2014 Braintree, a division of PayPal, Inc.
12
  */
13
- class Braintree_Test_TransactionAmounts
14
  {
15
  public static $authorize = '1000.00';
16
  public static $decline = '2000.00';
17
  }
 
1
  <?php
2
+ namespace Braintree\Test;
3
 
4
  /**
5
  * Transaction amounts used for testing purposes
9
  *
10
  * @package Braintree
11
  * @subpackage Test
12
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
  */
14
+ class TransactionAmounts
15
  {
16
  public static $authorize = '1000.00';
17
  public static $decline = '2000.00';
18
  }
19
+ class_alias('Braintree\Test\TransactionAmounts', 'Braintree_Test_TransactionAmounts');
braintree_sdk/lib/Braintree/Test/VenmoSdk.php CHANGED
@@ -1,12 +1,14 @@
1
  <?php
 
 
2
  /**
3
  * VenmoSdk payment method codes used for testing purposes
4
  *
5
  * @package Braintree
6
  * @subpackage Test
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- class Braintree_Test_VenmoSdk
10
  {
11
  public static $visaPaymentMethodCode = "stub-4111111111111111";
12
 
@@ -26,3 +28,4 @@ class Braintree_Test_VenmoSdk
26
  return "stub-invalid-session";
27
  }
28
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
+ class VenmoSdk
12
  {
13
  public static $visaPaymentMethodCode = "stub-4111111111111111";
14
 
28
  return "stub-invalid-session";
29
  }
30
  }
31
+ class_alias('Braintree\Test\VenmoSdk', 'Braintree_Test_VenmoSdk');
braintree_sdk/lib/Braintree/TestingGateway.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- final class Braintree_TestingGateway
 
 
3
  {
4
  private $_gateway;
5
  private $_config;
@@ -9,7 +11,7 @@ final class Braintree_TestingGateway
9
  {
10
  $this->_gateway = $gateway;
11
  $this->_config = $gateway->config;
12
- $this->_http = new Braintree_Http($this->_config);
13
  }
14
 
15
  public function settle($transactionId)
@@ -37,13 +39,14 @@ final class Braintree_TestingGateway
37
  self::_checkEnvironment();
38
  $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . $testPath;
39
  $response = $this->_http->put($path);
40
- return Braintree_Transaction::factory($response['transaction']);
41
  }
42
 
43
  private function _checkEnvironment()
44
  {
45
- if (Braintree_Configuration::$global->getEnvironment() == 'production') {
46
- throw new Braintree_Exception_TestOperationPerformedInProduction();
47
  }
48
  }
49
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ final class TestingGateway
5
  {
6
  private $_gateway;
7
  private $_config;
11
  {
12
  $this->_gateway = $gateway;
13
  $this->_config = $gateway->config;
14
+ $this->_http = new Http($this->_config);
15
  }
16
 
17
  public function settle($transactionId)
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');
braintree_sdk/lib/Braintree/TextNode.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
 
2
 
3
- class Braintree_TextNode extends Braintree_PartialMatchNode
4
  {
5
- function contains($value)
6
  {
7
  $this->searchTerms["contains"] = strval($value);
8
  return $this;
9
  }
10
  }
 
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');
braintree_sdk/lib/Braintree/ThreeDSecureInfo.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_ThreeDSecureInfo extends Braintree_Base
 
 
3
  {
4
  public static function factory($attributes)
5
  {
@@ -21,7 +23,8 @@ class Braintree_ThreeDSecureInfo extends Braintree_Base
21
  public function __toString()
22
  {
23
  return __CLASS__ . '[' .
24
- Braintree_Util::attributesToString($this->_attributes) .']';
25
  }
26
 
27
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ class ThreeDSecureInfo extends Base
5
  {
6
  public static function factory($attributes)
7
  {
23
  public function __toString()
24
  {
25
  return __CLASS__ . '[' .
26
+ Util::attributesToString($this->_attributes) .']';
27
  }
28
 
29
  }
30
+ class_alias('Braintree\ThreeDSecureInfo', 'Braintree_ThreeDSecureInfo');
braintree_sdk/lib/Braintree/Transaction.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
  /**
3
  * Braintree Transaction processor
4
  * Creates and manages transactions
@@ -8,7 +10,7 @@
8
  *
9
  * <b>Minimalistic example:</b>
10
  * <code>
11
- * Braintree_Transaction::saleNoValidate(array(
12
  * 'amount' => '100.00',
13
  * 'creditCard' => array(
14
  * 'number' => '5105105105105100',
@@ -19,7 +21,7 @@
19
  *
20
  * <b>Full example:</b>
21
  * <code>
22
- * Braintree_Transaction::saleNoValidate(array(
23
  * 'amount' => '100.00',
24
  * 'orderId' => '123',
25
  * 'channel' => 'MyShoppingCardProvider',
@@ -75,7 +77,7 @@
75
  * a transaction can be stored in the vault by setting
76
  * <i>transaction[options][storeInVault]</i> to true.
77
  * <code>
78
- * $transaction = Braintree_Transaction::saleNoValidate(array(
79
  * 'customer' => array(
80
  * 'firstName' => 'Adam',
81
  * 'lastName' => 'Williams'
@@ -98,7 +100,7 @@
98
  * To also store the billing address in the vault, pass the
99
  * <b>addBillingAddressToPaymentMethod</b> option.
100
  * <code>
101
- * Braintree_Transaction.saleNoValidate(array(
102
  * ...
103
  * 'options' => array(
104
  * 'storeInVault' => true
@@ -119,7 +121,7 @@
119
  * $transaction[options][submitForSettlement] to true.
120
  *
121
  * <code>
122
- * $transaction = Braintree_Transaction::saleNoValidate(array(
123
  * 'amount' => '100.00',
124
  * 'creditCard' => array(
125
  * 'number' => '5105105105105100',
@@ -137,7 +139,7 @@
137
  *
138
  * @package Braintree
139
  * @category Resources
140
- * @copyright 2014 Braintree, a division of PayPal, Inc.
141
  *
142
  *
143
  * @property-read string $avsErrorResponseCode
@@ -146,29 +148,30 @@
146
  * @property-read string $cvvResponseCode
147
  * @property-read string $id transaction id
148
  * @property-read string $amount transaction amount
149
- * @property-read object $billingDetails transaction billing address
150
  * @property-read string $createdAt transaction created timestamp
151
- * @property-read object $applePayCardDetails transaction Apple Pay card info
152
- * @property-read object $androidPayCardDetails transaction Android Pay card info
153
- * @property-read object $creditCardDetails transaction credit card info
154
- * @property-read object $coinbaseDetails transaction Coinbase account info
155
- * @property-read object $paypalDetails transaction paypal account info
156
- * @property-read object $customerDetails transaction customer info
 
 
157
  * @property-read array $customFields custom fields passed with the request
158
  * @property-read string $processorResponseCode gateway response code
159
  * @property-read string $additionalProcessorResponse raw response from processor
160
- * @property-read object $shippingDetails transaction shipping address
161
  * @property-read string $status transaction status
162
  * @property-read array $statusHistory array of StatusDetails objects
163
  * @property-read string $type transaction type
164
  * @property-read string $updatedAt transaction updated timestamp
165
- * @property-read object $disbursementDetails populated when transaction is disbursed
166
- * @property-read object $disputes populated when transaction is disputed
167
- * @property-read string $amexRewardsResponse AmEx Rewards response
168
  *
169
  */
170
 
171
- final class Braintree_Transaction extends Braintree_Base
172
  {
173
  // Transaction Status
174
  const AUTHORIZATION_EXPIRED = 'authorization_expired';
@@ -225,7 +228,7 @@ final class Braintree_Transaction extends Braintree_Base
225
  * @ignore
226
  * @access protected
227
  * @param array $transactionAttribs array of transaction data
228
- * @return none
229
  */
230
  protected function _initialize($transactionAttribs)
231
  {
@@ -233,7 +236,7 @@ final class Braintree_Transaction extends Braintree_Base
233
 
234
  if (isset($transactionAttribs['applePay'])) {
235
  $this->_set('applePayCardDetails',
236
- new Braintree_Transaction_ApplePayCardDetails(
237
  $transactionAttribs['applePay']
238
  )
239
  );
@@ -241,15 +244,31 @@ final class Braintree_Transaction extends Braintree_Base
241
 
242
  if (isset($transactionAttribs['androidPayCard'])) {
243
  $this->_set('androidPayCardDetails',
244
- new Braintree_Transaction_AndroidPayCardDetails(
245
  $transactionAttribs['androidPayCard']
246
  )
247
  );
248
  }
249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  if (isset($transactionAttribs['creditCard'])) {
251
  $this->_set('creditCardDetails',
252
- new Braintree_Transaction_CreditCardDetails(
253
  $transactionAttribs['creditCard']
254
  )
255
  );
@@ -257,7 +276,7 @@ final class Braintree_Transaction extends Braintree_Base
257
 
258
  if (isset($transactionAttribs['coinbaseAccount'])) {
259
  $this->_set('coinbaseDetails',
260
- new Braintree_Transaction_CoinbaseDetails(
261
  $transactionAttribs['coinbaseAccount']
262
  )
263
  );
@@ -265,7 +284,7 @@ final class Braintree_Transaction extends Braintree_Base
265
 
266
  if (isset($transactionAttribs['europeBankAccount'])) {
267
  $this->_set('europeBankAccount',
268
- new Braintree_Transaction_EuropeBankAccountDetails(
269
  $transactionAttribs['europeBankAccount']
270
  )
271
  );
@@ -273,7 +292,7 @@ final class Braintree_Transaction extends Braintree_Base
273
 
274
  if (isset($transactionAttribs['paypal'])) {
275
  $this->_set('paypalDetails',
276
- new Braintree_Transaction_PayPalDetails(
277
  $transactionAttribs['paypal']
278
  )
279
  );
@@ -281,7 +300,7 @@ final class Braintree_Transaction extends Braintree_Base
281
 
282
  if (isset($transactionAttribs['customer'])) {
283
  $this->_set('customerDetails',
284
- new Braintree_Transaction_CustomerDetails(
285
  $transactionAttribs['customer']
286
  )
287
  );
@@ -289,7 +308,7 @@ final class Braintree_Transaction extends Braintree_Base
289
 
290
  if (isset($transactionAttribs['billing'])) {
291
  $this->_set('billingDetails',
292
- new Braintree_Transaction_AddressDetails(
293
  $transactionAttribs['billing']
294
  )
295
  );
@@ -297,7 +316,7 @@ final class Braintree_Transaction extends Braintree_Base
297
 
298
  if (isset($transactionAttribs['shipping'])) {
299
  $this->_set('shippingDetails',
300
- new Braintree_Transaction_AddressDetails(
301
  $transactionAttribs['shipping']
302
  )
303
  );
@@ -305,7 +324,7 @@ final class Braintree_Transaction extends Braintree_Base
305
 
306
  if (isset($transactionAttribs['subscription'])) {
307
  $this->_set('subscriptionDetails',
308
- new Braintree_Transaction_SubscriptionDetails(
309
  $transactionAttribs['subscription']
310
  )
311
  );
@@ -313,7 +332,7 @@ final class Braintree_Transaction extends Braintree_Base
313
 
314
  if (isset($transactionAttribs['descriptor'])) {
315
  $this->_set('descriptor',
316
- new Braintree_Descriptor(
317
  $transactionAttribs['descriptor']
318
  )
319
  );
@@ -321,49 +340,52 @@ final class Braintree_Transaction extends Braintree_Base
321
 
322
  if (isset($transactionAttribs['disbursementDetails'])) {
323
  $this->_set('disbursementDetails',
324
- new Braintree_DisbursementDetails($transactionAttribs['disbursementDetails'])
325
  );
326
  }
327
 
328
- $disputes = array();
329
  if (isset($transactionAttribs['disputes'])) {
330
  foreach ($transactionAttribs['disputes'] AS $dispute) {
331
- $disputes[] = Braintree_Dispute::factory($dispute);
332
  }
333
  }
334
 
335
  $this->_set('disputes', $disputes);
336
 
337
- $statusHistory = array();
338
  if (isset($transactionAttribs['statusHistory'])) {
339
  foreach ($transactionAttribs['statusHistory'] AS $history) {
340
- $statusHistory[] = new Braintree_Transaction_StatusDetails($history);
341
  }
342
  }
343
 
344
  $this->_set('statusHistory', $statusHistory);
345
 
346
- $addOnArray = array();
347
  if (isset($transactionAttribs['addOns'])) {
348
  foreach ($transactionAttribs['addOns'] AS $addOn) {
349
- $addOnArray[] = Braintree_AddOn::factory($addOn);
350
  }
351
  }
352
  $this->_set('addOns', $addOnArray);
353
 
354
- $discountArray = array();
355
  if (isset($transactionAttribs['discounts'])) {
356
  foreach ($transactionAttribs['discounts'] AS $discount) {
357
- $discountArray[] = Braintree_Discount::factory($discount);
358
  }
359
  }
360
  $this->_set('discounts', $discountArray);
361
 
362
  if(isset($transactionAttribs['riskData'])) {
363
- $this->_set('riskData', Braintree_RiskData::factory($transactionAttribs['riskData']));
364
  }
365
  if(isset($transactionAttribs['threeDSecureInfo'])) {
366
- $this->_set('threeDSecureInfo', Braintree_ThreeDSecureInfo::factory($transactionAttribs['threeDSecureInfo']));
 
 
 
367
  }
368
  }
369
 
@@ -374,17 +396,17 @@ final class Braintree_Transaction extends Braintree_Base
374
  public function __toString()
375
  {
376
  // array of attributes to print
377
- $display = array(
378
  'id', 'type', 'amount', 'status',
379
  'createdAt', 'creditCardDetails', 'customerDetails'
380
- );
381
 
382
- $displayAttributes = array();
383
  foreach ($display AS $attrib) {
384
  $displayAttributes[$attrib] = $this->$attrib;
385
  }
386
  return __CLASS__ . '[' .
387
- Braintree_Util::attributesToString($displayAttributes) .']';
388
  }
389
 
390
  public function isEqual($otherTx)
@@ -399,10 +421,11 @@ final class Braintree_Transaction extends Braintree_Base
399
  return null;
400
  }
401
  else {
402
- return Braintree_CreditCard::find($token);
403
  }
404
  }
405
 
 
406
  public function vaultCustomer()
407
  {
408
  $customerId = $this->customerDetails->id;
@@ -410,20 +433,21 @@ final class Braintree_Transaction extends Braintree_Base
410
  return null;
411
  }
412
  else {
413
- return Braintree_Customer::find($customerId);
414
  }
415
  }
416
 
 
417
  public function isDisbursed() {
418
  return $this->disbursementDetails->isValid();
419
  }
420
 
421
  /**
422
- * factory method: returns an instance of Braintree_Transaction
423
  * to the requesting method, with populated properties
424
  *
425
  * @ignore
426
- * @return object instance of Braintree_Transaction
427
  */
428
  public static function factory($attributes)
429
  {
@@ -437,91 +461,97 @@ final class Braintree_Transaction extends Braintree_Base
437
 
438
  public static function cloneTransaction($transactionId, $attribs)
439
  {
440
- return Braintree_Configuration::gateway()->transaction()->cloneTransaction($transactionId, $attribs);
441
  }
442
 
443
  public static function createFromTransparentRedirect($queryString)
444
  {
445
- return Braintree_Configuration::gateway()->transaction()->createFromTransparentRedirect($queryString);
446
  }
447
 
448
  public static function createTransactionUrl()
449
  {
450
- return Braintree_Configuration::gateway()->transaction()->createTransactionUrl();
451
  }
452
 
453
  public static function credit($attribs)
454
  {
455
- return Braintree_Configuration::gateway()->transaction()->credit($attribs);
456
  }
457
 
458
  public static function creditNoValidate($attribs)
459
  {
460
- return Braintree_Configuration::gateway()->transaction()->creditNoValidate($attribs);
461
  }
462
 
463
  public static function find($id)
464
  {
465
- return Braintree_Configuration::gateway()->transaction()->find($id);
466
  }
467
 
468
  public static function sale($attribs)
469
  {
470
- return Braintree_Configuration::gateway()->transaction()->sale($attribs);
471
  }
472
 
473
  public static function saleNoValidate($attribs)
474
  {
475
- return Braintree_Configuration::gateway()->transaction()->saleNoValidate($attribs);
476
  }
477
 
478
  public static function search($query)
479
  {
480
- return Braintree_Configuration::gateway()->transaction()->search($query);
481
  }
482
 
483
  public static function fetch($query, $ids)
484
  {
485
- return Braintree_Configuration::gateway()->transaction()->fetch($query, $ids);
486
  }
487
 
488
  public static function void($transactionId)
489
  {
490
- return Braintree_Configuration::gateway()->transaction()->void($transactionId);
491
  }
492
 
493
  public static function voidNoValidate($transactionId)
494
  {
495
- return Braintree_Configuration::gateway()->transaction()->voidNoValidate($transactionId);
 
 
 
 
 
496
  }
497
 
498
- public static function submitForSettlement($transactionId, $amount = null)
499
  {
500
- return Braintree_Configuration::gateway()->transaction()->submitForSettlement($transactionId, $amount);
501
  }
502
 
503
- public static function submitForSettlementNoValidate($transactionId, $amount = null)
504
  {
505
- return Braintree_Configuration::gateway()->transaction()->submitForSettlementNoValidate($transactionId, $amount);
506
  }
507
 
508
  public static function holdInEscrow($transactionId)
509
  {
510
- return Braintree_Configuration::gateway()->transaction()->holdInEscrow($transactionId);
511
  }
512
 
513
  public static function releaseFromEscrow($transactionId)
514
  {
515
- return Braintree_Configuration::gateway()->transaction()->releaseFromEscrow($transactionId);
516
  }
517
 
518
  public static function cancelRelease($transactionId)
519
  {
520
- return Braintree_Configuration::gateway()->transaction()->cancelRelease($transactionId);
521
  }
522
 
523
  public static function refund($transactionId, $amount = null)
524
  {
525
- return Braintree_Configuration::gateway()->transaction()->refund($transactionId, $amount);
526
  }
527
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree Transaction processor
6
  * Creates and manages transactions
10
  *
11
  * <b>Minimalistic example:</b>
12
  * <code>
13
+ * Transaction::saleNoValidate(array(
14
  * 'amount' => '100.00',
15
  * 'creditCard' => array(
16
  * 'number' => '5105105105105100',
21
  *
22
  * <b>Full example:</b>
23
  * <code>
24
+ * Transaction::saleNoValidate(array(
25
  * 'amount' => '100.00',
26
  * 'orderId' => '123',
27
  * 'channel' => 'MyShoppingCardProvider',
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'
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
121
  * $transaction[options][submitForSettlement] to true.
122
  *
123
  * <code>
124
+ * $transaction = Transaction::saleNoValidate(array(
125
  * 'amount' => '100.00',
126
  * 'creditCard' => array(
127
  * 'number' => '5105105105105100',
139
  *
140
  * @package Braintree
141
  * @category Resources
142
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
143
  *
144
  *
145
  * @property-read string $avsErrorResponseCode
148
  * @property-read string $cvvResponseCode
149
  * @property-read string $id transaction id
150
  * @property-read string $amount transaction amount
151
+ * @property-read Braintree\Transaction\AddressDetails $billingDetails transaction billing address
152
  * @property-read string $createdAt transaction created timestamp
153
+ * @property-read Braintree\ApplePayCardDetails $applePayCardDetails transaction Apple Pay card info
154
+ * @property-read Braintree\AndroidPayCardDetails $androidPayCardDetails transaction Android Pay card info
155
+ * @property-read Braintree\AmexExpressCheckoutCardDetails $amexExpressCheckoutCardDetails transaction Amex Express Checkout card info
156
+ * @property-read Braintree\CreditCardDetails $creditCardDetails transaction credit card info
157
+ * @property-read Braintree\CoinbaseAccountDetails $coinbaseDetails transaction Coinbase account info
158
+ * @property-read Braintree\PayPalAccountDetails $paypalDetails transaction paypal account info
159
+ * @property-read Braintree\Customer $customerDetails transaction customer info
160
+ * @property-read Braintree\VenmoAccount $venmoAccountDetails transaction Venmo Account info
161
  * @property-read array $customFields custom fields passed with the request
162
  * @property-read string $processorResponseCode gateway response code
163
  * @property-read string $additionalProcessorResponse raw response from processor
164
+ * @property-read Braintree\Transaction\AddressDetails $shippingDetails transaction shipping address
165
  * @property-read string $status transaction status
166
  * @property-read array $statusHistory array of StatusDetails objects
167
  * @property-read string $type transaction type
168
  * @property-read string $updatedAt transaction updated timestamp
169
+ * @property-read Braintree\Disbursement $disbursementDetails populated when transaction is disbursed
170
+ * @property-read Braintree\Dispute $disputes populated when transaction is disputed
 
171
  *
172
  */
173
 
174
+ final class Transaction extends Base
175
  {
176
  // Transaction Status
177
  const AUTHORIZATION_EXPIRED = 'authorization_expired';
228
  * @ignore
229
  * @access protected
230
  * @param array $transactionAttribs array of transaction data
231
+ * @return void
232
  */
233
  protected function _initialize($transactionAttribs)
234
  {
236
 
237
  if (isset($transactionAttribs['applePay'])) {
238
  $this->_set('applePayCardDetails',
239
+ new Transaction\ApplePayCardDetails(
240
  $transactionAttribs['applePay']
241
  )
242
  );
244
 
245
  if (isset($transactionAttribs['androidPayCard'])) {
246
  $this->_set('androidPayCardDetails',
247
+ new Transaction\AndroidPayCardDetails(
248
  $transactionAttribs['androidPayCard']
249
  )
250
  );
251
  }
252
 
253
+ if (isset($transactionAttribs['amexExpressCheckoutCard'])) {
254
+ $this->_set('amexExpressCheckoutCardDetails',
255
+ new Transaction\AmexExpressCheckoutCardDetails(
256
+ $transactionAttribs['amexExpressCheckoutCard']
257
+ )
258
+ );
259
+ }
260
+
261
+ if (isset($transactionAttribs['venmoAccount'])) {
262
+ $this->_set('venmoAccountDetails',
263
+ new Transaction\VenmoAccountDetails(
264
+ $transactionAttribs['venmoAccount']
265
+ )
266
+ );
267
+ }
268
+
269
  if (isset($transactionAttribs['creditCard'])) {
270
  $this->_set('creditCardDetails',
271
+ new Transaction\CreditCardDetails(
272
  $transactionAttribs['creditCard']
273
  )
274
  );
276
 
277
  if (isset($transactionAttribs['coinbaseAccount'])) {
278
  $this->_set('coinbaseDetails',
279
+ new Transaction\CoinbaseDetails(
280
  $transactionAttribs['coinbaseAccount']
281
  )
282
  );
284
 
285
  if (isset($transactionAttribs['europeBankAccount'])) {
286
  $this->_set('europeBankAccount',
287
+ new Transaction\EuropeBankAccountDetails(
288
  $transactionAttribs['europeBankAccount']
289
  )
290
  );
292
 
293
  if (isset($transactionAttribs['paypal'])) {
294
  $this->_set('paypalDetails',
295
+ new Transaction\PayPalDetails(
296
  $transactionAttribs['paypal']
297
  )
298
  );
300
 
301
  if (isset($transactionAttribs['customer'])) {
302
  $this->_set('customerDetails',
303
+ new Transaction\CustomerDetails(
304
  $transactionAttribs['customer']
305
  )
306
  );
308
 
309
  if (isset($transactionAttribs['billing'])) {
310
  $this->_set('billingDetails',
311
+ new Transaction\AddressDetails(
312
  $transactionAttribs['billing']
313
  )
314
  );
316
 
317
  if (isset($transactionAttribs['shipping'])) {
318
  $this->_set('shippingDetails',
319
+ new Transaction\AddressDetails(
320
  $transactionAttribs['shipping']
321
  )
322
  );
324
 
325
  if (isset($transactionAttribs['subscription'])) {
326
  $this->_set('subscriptionDetails',
327
+ new Transaction\SubscriptionDetails(
328
  $transactionAttribs['subscription']
329
  )
330
  );
332
 
333
  if (isset($transactionAttribs['descriptor'])) {
334
  $this->_set('descriptor',
335
+ new Descriptor(
336
  $transactionAttribs['descriptor']
337
  )
338
  );
340
 
341
  if (isset($transactionAttribs['disbursementDetails'])) {
342
  $this->_set('disbursementDetails',
343
+ new DisbursementDetails($transactionAttribs['disbursementDetails'])
344
  );
345
  }
346
 
347
+ $disputes = [];
348
  if (isset($transactionAttribs['disputes'])) {
349
  foreach ($transactionAttribs['disputes'] AS $dispute) {
350
+ $disputes[] = Dispute::factory($dispute);
351
  }
352
  }
353
 
354
  $this->_set('disputes', $disputes);
355
 
356
+ $statusHistory = [];
357
  if (isset($transactionAttribs['statusHistory'])) {
358
  foreach ($transactionAttribs['statusHistory'] AS $history) {
359
+ $statusHistory[] = new Transaction\StatusDetails($history);
360
  }
361
  }
362
 
363
  $this->_set('statusHistory', $statusHistory);
364
 
365
+ $addOnArray = [];
366
  if (isset($transactionAttribs['addOns'])) {
367
  foreach ($transactionAttribs['addOns'] AS $addOn) {
368
+ $addOnArray[] = AddOn::factory($addOn);
369
  }
370
  }
371
  $this->_set('addOns', $addOnArray);
372
 
373
+ $discountArray = [];
374
  if (isset($transactionAttribs['discounts'])) {
375
  foreach ($transactionAttribs['discounts'] AS $discount) {
376
+ $discountArray[] = Discount::factory($discount);
377
  }
378
  }
379
  $this->_set('discounts', $discountArray);
380
 
381
  if(isset($transactionAttribs['riskData'])) {
382
+ $this->_set('riskData', RiskData::factory($transactionAttribs['riskData']));
383
  }
384
  if(isset($transactionAttribs['threeDSecureInfo'])) {
385
+ $this->_set('threeDSecureInfo', ThreeDSecureInfo::factory($transactionAttribs['threeDSecureInfo']));
386
+ }
387
+ if(isset($transactionAttribs['facilitatorDetails'])) {
388
+ $this->_set('facilitatorDetails', FacilitatorDetails::factory($transactionAttribs['facilitatorDetails']));
389
  }
390
  }
391
 
396
  public function __toString()
397
  {
398
  // array of attributes to print
399
+ $display = [
400
  'id', 'type', 'amount', 'status',
401
  'createdAt', 'creditCardDetails', 'customerDetails'
402
+ ];
403
 
404
+ $displayAttributes = [];
405
  foreach ($display AS $attrib) {
406
  $displayAttributes[$attrib] = $this->$attrib;
407
  }
408
  return __CLASS__ . '[' .
409
+ Util::attributesToString($displayAttributes) .']';
410
  }
411
 
412
  public function isEqual($otherTx)
421
  return null;
422
  }
423
  else {
424
+ return CreditCard::find($token);
425
  }
426
  }
427
 
428
+ /** @return void|Braintree\Customer */
429
  public function vaultCustomer()
430
  {
431
  $customerId = $this->customerDetails->id;
433
  return null;
434
  }
435
  else {
436
+ return Customer::find($customerId);
437
  }
438
  }
439
 
440
+ /** @return bool */
441
  public function isDisbursed() {
442
  return $this->disbursementDetails->isValid();
443
  }
444
 
445
  /**
446
+ * factory method: returns an instance of Transaction
447
  * to the requesting method, with populated properties
448
  *
449
  * @ignore
450
+ * @return Transaction
451
  */
452
  public static function factory($attributes)
453
  {
461
 
462
  public static function cloneTransaction($transactionId, $attribs)
463
  {
464
+ return Configuration::gateway()->transaction()->cloneTransaction($transactionId, $attribs);
465
  }
466
 
467
  public static function createFromTransparentRedirect($queryString)
468
  {
469
+ return Configuration::gateway()->transaction()->createFromTransparentRedirect($queryString);
470
  }
471
 
472
  public static function createTransactionUrl()
473
  {
474
+ return Configuration::gateway()->transaction()->createTransactionUrl();
475
  }
476
 
477
  public static function credit($attribs)
478
  {
479
+ return Configuration::gateway()->transaction()->credit($attribs);
480
  }
481
 
482
  public static function creditNoValidate($attribs)
483
  {
484
+ return Configuration::gateway()->transaction()->creditNoValidate($attribs);
485
  }
486
 
487
  public static function find($id)
488
  {
489
+ return Configuration::gateway()->transaction()->find($id);
490
  }
491
 
492
  public static function sale($attribs)
493
  {
494
+ return Configuration::gateway()->transaction()->sale($attribs);
495
  }
496
 
497
  public static function saleNoValidate($attribs)
498
  {
499
+ return Configuration::gateway()->transaction()->saleNoValidate($attribs);
500
  }
501
 
502
  public static function search($query)
503
  {
504
+ return Configuration::gateway()->transaction()->search($query);
505
  }
506
 
507
  public static function fetch($query, $ids)
508
  {
509
+ return Configuration::gateway()->transaction()->fetch($query, $ids);
510
  }
511
 
512
  public static function void($transactionId)
513
  {
514
+ return Configuration::gateway()->transaction()->void($transactionId);
515
  }
516
 
517
  public static function voidNoValidate($transactionId)
518
  {
519
+ return Configuration::gateway()->transaction()->voidNoValidate($transactionId);
520
+ }
521
+
522
+ public static function submitForSettlement($transactionId, $amount = null, $attribs = [])
523
+ {
524
+ return Configuration::gateway()->transaction()->submitForSettlement($transactionId, $amount, $attribs);
525
  }
526
 
527
+ public static function submitForSettlementNoValidate($transactionId, $amount = null, $attribs = [])
528
  {
529
+ return Configuration::gateway()->transaction()->submitForSettlementNoValidate($transactionId, $amount, $attribs);
530
  }
531
 
532
+ public static function submitForPartialSettlement($transactionId, $amount, $attribs = [])
533
  {
534
+ return Configuration::gateway()->transaction()->submitForPartialSettlement($transactionId, $amount, $attribs);
535
  }
536
 
537
  public static function holdInEscrow($transactionId)
538
  {
539
+ return Configuration::gateway()->transaction()->holdInEscrow($transactionId);
540
  }
541
 
542
  public static function releaseFromEscrow($transactionId)
543
  {
544
+ return Configuration::gateway()->transaction()->releaseFromEscrow($transactionId);
545
  }
546
 
547
  public static function cancelRelease($transactionId)
548
  {
549
+ return Configuration::gateway()->transaction()->cancelRelease($transactionId);
550
  }
551
 
552
  public static function refund($transactionId, $amount = null)
553
  {
554
+ return Configuration::gateway()->transaction()->refund($transactionId, $amount);
555
  }
556
  }
557
+ class_alias('Braintree\Transaction', 'Braintree_Transaction');
braintree_sdk/lib/Braintree/Transaction/AddressDetails.php CHANGED
@@ -1,11 +1,15 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Creates an instance of AddressDetails as returned from a transaction
4
  *
5
  *
6
  * @package Braintree
7
  * @subpackage Transaction
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  *
10
  * @property-read string $firstName
11
  * @property-read string $lastName
@@ -16,9 +20,9 @@
16
  * @property-read string $region
17
  * @property-read string $postalCode
18
  * @property-read string $countryName
19
- * @uses Braintree_Instance inherits methods
20
  */
21
- class Braintree_Transaction_AddressDetails extends Braintree_Instance
22
  {
23
- protected $_attributes = array();
24
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read string $firstName
15
  * @property-read string $lastName
20
  * @property-read string $region
21
  * @property-read string $postalCode
22
  * @property-read string $countryName
 
23
  */
24
+ class AddressDetails extends Instance
25
  {
26
+ protected $_attributes = [];
27
  }
28
+ class_alias('Braintree\Transaction\AddressDetails', 'Braintree_Transaction_AddressDetails');
braintree_sdk/lib/Braintree/Transaction/AmexExpressCheckoutCardDetails.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
11
+ */
12
+
13
+ /**
14
+ * creates an instance of AmexExpressCheckoutCardDetails
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @subpackage Transaction
19
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
20
+ *
21
+ * @property-read string $cardType
22
+ * @property-read string $bin
23
+ * @property-read string $cardMemberExpiryDate
24
+ * @property-read string $cardMemberNumber
25
+ * @property-read string $cardType
26
+ * @property-read string $sourceDescription
27
+ * @property-read string $token
28
+ * @property-read string $imageUrl
29
+ * @property-read string $expirationMonth
30
+ * @property-read string $expirationYear
31
+ * @uses Instance inherits methods
32
+ */
33
+ class AmexExpressCheckoutCardDetails extends Instance
34
+ {
35
+ protected $_attributes = [];
36
+
37
+ /**
38
+ * @ignore
39
+ */
40
+ public function __construct($attributes)
41
+ {
42
+ parent::__construct($attributes);
43
+ }
44
+ }
45
+ class_alias('Braintree\Transaction\AmexExpressCheckoutCardDetails', 'Braintree_Transaction_AmexExpressCheckoutCardDetails');
braintree_sdk/lib/Braintree/Transaction/AndroidPayCardDetails.php CHANGED
@@ -1,10 +1,14 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Android Pay card details from a transaction
4
  *
5
  * @package Braintree
6
  * @subpackage Transaction
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -13,7 +17,7 @@
13
  *
14
  * @package Braintree
15
  * @subpackage Transaction
16
- * @copyright 2014 Braintree, a division of PayPal, Inc.
17
  *
18
  * @property-read string $bin
19
  * @property-read string $default
@@ -27,11 +31,10 @@
27
  * @property-read string $token
28
  * @property-read string $virtualCardLast4
29
  * @property-read string $virtualCardType
30
- * @uses Braintree_Instance inherits methods
31
  */
32
- class Braintree_Transaction_AndroidPayCardDetails extends Braintree_Instance
33
  {
34
- protected $_attributes = array();
35
 
36
  /**
37
  * @ignore
@@ -43,3 +46,4 @@ class Braintree_Transaction_AndroidPayCardDetails extends Braintree_Instance
43
  $this->_attributes['last4'] = $this->virtualCardLast4;
44
  }
45
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
 
14
  /**
17
  *
18
  * @package Braintree
19
  * @subpackage Transaction
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  *
22
  * @property-read string $bin
23
  * @property-read string $default
31
  * @property-read string $token
32
  * @property-read string $virtualCardLast4
33
  * @property-read string $virtualCardType
 
34
  */
35
+ class AndroidPayCardDetails extends Instance
36
  {
37
+ protected $_attributes = [];
38
 
39
  /**
40
  * @ignore
46
  $this->_attributes['last4'] = $this->virtualCardLast4;
47
  }
48
  }
49
+ class_alias('Braintree\Transaction\AndroidPayCardDetails', 'Braintree_Transaction_AndroidPayCardDetails');
braintree_sdk/lib/Braintree/Transaction/ApplePayCardDetails.php CHANGED
@@ -1,10 +1,14 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Apple Pay card details from a transaction
4
  *
5
  * @package Braintree
6
  * @subpackage Transaction
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -13,7 +17,7 @@
13
  *
14
  * @package Braintree
15
  * @subpackage Transaction
16
- * @copyright 2014 Braintree, a division of PayPal, Inc.
17
  *
18
  * @property-read string $cardType
19
  * @property-read string $paymentInstrumentName
@@ -21,11 +25,10 @@
21
  * @property-read string $expirationYear
22
  * @property-read string $cardholderName
23
  * @property-read string $sourceDescription
24
- * @uses Braintree_Instance inherits methods
25
  */
26
- class Braintree_Transaction_ApplePayCardDetails extends Braintree_Instance
27
  {
28
- protected $_attributes = array();
29
 
30
  /**
31
  * @ignore
@@ -35,3 +38,4 @@ class Braintree_Transaction_ApplePayCardDetails extends Braintree_Instance
35
  parent::__construct($attributes);
36
  }
37
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
 
14
  /**
17
  *
18
  * @package Braintree
19
  * @subpackage Transaction
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  *
22
  * @property-read string $cardType
23
  * @property-read string $paymentInstrumentName
25
  * @property-read string $expirationYear
26
  * @property-read string $cardholderName
27
  * @property-read string $sourceDescription
 
28
  */
29
+ class ApplePayCardDetails extends Instance
30
  {
31
+ protected $_attributes = [];
32
 
33
  /**
34
  * @ignore
38
  parent::__construct($attributes);
39
  }
40
  }
41
+ class_alias('Braintree\Transaction\ApplePayCardDetails', 'Braintree_Transaction_ApplePayCardDetails');
braintree_sdk/lib/Braintree/Transaction/CoinbaseDetails.php CHANGED
@@ -1,10 +1,14 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Coinbase details from a transaction
4
  *
5
  * @package Braintree
6
  * @subpackage Transaction
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -13,18 +17,17 @@
13
  *
14
  * @package Braintree
15
  * @subpackage Transaction
16
- * @copyright 2014 Braintree, a division of PayPal, Inc.
17
  *
18
  * @property-read string $token
19
  * @property-read string $userId
20
  * @property-read string $userName
21
  * @property-read string $userEmail
22
  * @property-read string $imageUrl
23
- * @uses Braintree_Instance inherits methods
24
  */
25
- class Braintree_Transaction_CoinbaseDetails extends Braintree_Instance
26
  {
27
- protected $_attributes = array();
28
 
29
  /**
30
  * @ignore
@@ -34,3 +37,4 @@ class Braintree_Transaction_CoinbaseDetails extends Braintree_Instance
34
  parent::__construct($attributes);
35
  }
36
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
 
14
  /**
17
  *
18
  * @package Braintree
19
  * @subpackage Transaction
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  *
22
  * @property-read string $token
23
  * @property-read string $userId
24
  * @property-read string $userName
25
  * @property-read string $userEmail
26
  * @property-read string $imageUrl
 
27
  */
28
+ class CoinbaseDetails extends Instance
29
  {
30
+ protected $_attributes = [];
31
 
32
  /**
33
  * @ignore
37
  parent::__construct($attributes);
38
  }
39
  }
40
+ class_alias('Braintree\Transaction\CoinbaseDetails', 'Braintree_Transaction_CoinbaseDetails');
braintree_sdk/lib/Braintree/Transaction/CreditCardDetails.php CHANGED
@@ -1,11 +1,15 @@
1
  <?php
 
 
 
 
2
  /**
3
  * CreditCard details from a transaction
4
  * creates an instance of CreditCardDetails
5
  *
6
  * @package Braintree
7
  * @subpackage Transaction
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  *
10
  * @property-read string $bin
11
  * @property-read string $cardType
@@ -16,11 +20,10 @@
16
  * @property-read string $last4
17
  * @property-read string $maskedNumber
18
  * @property-read string $token
19
- * @uses Braintree_Instance inherits methods
20
  */
21
- class Braintree_Transaction_CreditCardDetails extends Braintree_Instance
22
  {
23
- protected $_attributes = array();
24
 
25
  /**
26
  * @ignore
@@ -33,3 +36,4 @@ class Braintree_Transaction_CreditCardDetails extends Braintree_Instance
33
 
34
  }
35
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read string $bin
15
  * @property-read string $cardType
20
  * @property-read string $last4
21
  * @property-read string $maskedNumber
22
  * @property-read string $token
 
23
  */
24
+ class CreditCardDetails extends Instance
25
  {
26
+ protected $_attributes = [];
27
 
28
  /**
29
  * @ignore
36
 
37
  }
38
  }
39
+ class_alias('Braintree\Transaction\CreditCardDetails', 'Braintree_Transaction_CreditCardDetails');
braintree_sdk/lib/Braintree/Transaction/CustomerDetails.php CHANGED
@@ -1,11 +1,15 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Customer details from a transaction
4
  * Creates an instance of customer details as returned from a transaction
5
  *
6
  * @package Braintree
7
  * @subpackage Transaction
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  *
10
  * @property-read string $company
11
  * @property-read string $email
@@ -15,8 +19,8 @@
15
  * @property-read string $lastName
16
  * @property-read string $phone
17
  * @property-read string $website
18
- * @uses Braintree_Instance inherits methods
19
  */
20
- class Braintree_Transaction_CustomerDetails extends Braintree_Instance
21
  {
22
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read string $company
15
  * @property-read string $email
19
  * @property-read string $lastName
20
  * @property-read string $phone
21
  * @property-read string $website
 
22
  */
23
+ class CustomerDetails extends Instance
24
  {
25
  }
26
+ class_alias('Braintree\Transaction\CustomerDetails', 'Braintree_Transaction_CustomerDetails');
braintree_sdk/lib/Braintree/Transaction/EuropeBankAccountDetails.php CHANGED
@@ -1,11 +1,15 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Europe bank account details from a transaction
4
  * Creates an instance of europe bank account details as returned from a transaction
5
  *
6
  * @package Braintree
7
  * @subpackage Transaction
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  *
10
  * @property-read string $accountHolderName
11
  * @property-read string $bic
@@ -14,8 +18,8 @@
14
  * @property-read string $mandateReferenceNumber
15
  * @property-read string $maskedIban
16
  * @property-read string $token
17
- * @uses Braintree_Instance inherits methods
18
  */
19
- class Braintree_Transaction_EuropeBankAccountDetails extends Braintree_Instance
20
  {
21
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read string $accountHolderName
15
  * @property-read string $bic
18
  * @property-read string $mandateReferenceNumber
19
  * @property-read string $maskedIban
20
  * @property-read string $token
 
21
  */
22
+ class EuropeBankAccountDetails extends Instance
23
  {
24
  }
25
+ class_alias('Braintree\Transaction\EuropeBankAccountDetails', 'Braintree_Transaction_EuropeBankAccountDetails');
braintree_sdk/lib/Braintree/Transaction/PayPalDetails.php CHANGED
@@ -1,10 +1,14 @@
1
  <?php
 
 
 
 
2
  /**
3
  * PayPal details from a transaction
4
  *
5
  * @package Braintree
6
  * @subpackage Transaction
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -13,7 +17,7 @@
13
  *
14
  * @package Braintree
15
  * @subpackage Transaction
16
- * @copyright 2014 Braintree, a division of PayPal, Inc.
17
  *
18
  * @property-read string $payerEmail
19
  * @property-read string $paymentId
@@ -23,11 +27,10 @@
23
  * @property-read string $transactionFeeAmount
24
  * @property-read string $transactionFeeCurrencyIsoCode
25
  * @property-read string $description
26
- * @uses Braintree_Instance inherits methods
27
  */
28
- class Braintree_Transaction_PayPalDetails extends Braintree_Instance
29
  {
30
- protected $_attributes = array();
31
 
32
  /**
33
  * @ignore
@@ -37,3 +40,4 @@ class Braintree_Transaction_PayPalDetails extends Braintree_Instance
37
  parent::__construct($attributes);
38
  }
39
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
 
14
  /**
17
  *
18
  * @package Braintree
19
  * @subpackage Transaction
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  *
22
  * @property-read string $payerEmail
23
  * @property-read string $paymentId
27
  * @property-read string $transactionFeeAmount
28
  * @property-read string $transactionFeeCurrencyIsoCode
29
  * @property-read string $description
 
30
  */
31
+ class PayPalDetails extends Instance
32
  {
33
+ protected $_attributes = [];
34
 
35
  /**
36
  * @ignore
40
  parent::__construct($attributes);
41
  }
42
  }
43
+ class_alias('Braintree\Transaction\PayPalDetails', 'Braintree_Transaction_PayPalDetails');
braintree_sdk/lib/Braintree/Transaction/StatusDetails.php CHANGED
@@ -1,18 +1,22 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Status details from a transaction
4
  * Creates an instance of StatusDetails, as part of a transaction response
5
  *
6
  * @package Braintree
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  *
9
  * @property-read string $amount
10
  * @property-read string $status
11
  * @property-read string $timestamp
12
  * @property-read string $transactionSource
13
  * @property-read string $user
14
- * @uses Braintree_Instance inherits methods
15
  */
16
- class Braintree_Transaction_StatusDetails extends Braintree_Instance
17
  {
18
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  *
13
  * @property-read string $amount
14
  * @property-read string $status
15
  * @property-read string $timestamp
16
  * @property-read string $transactionSource
17
  * @property-read string $user
 
18
  */
19
+ class StatusDetails extends Instance
20
  {
21
  }
22
+ class_alias('Braintree\Transaction\StatusDetails', 'Braintree_Transaction_StatusDetails');
braintree_sdk/lib/Braintree/Transaction/SubscriptionDetails.php CHANGED
@@ -1,15 +1,20 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Customer details from a transaction
4
  * Creates an instance of customer details as returned from a transaction
5
  *
6
  * @package Braintree
7
  * @subpackage Transaction
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  *
10
  * @property-read string $billing_period_start_date
11
  * @property-read string $billing_period_end_date
12
  */
13
- class Braintree_Transaction_SubscriptionDetails extends Braintree_Instance
14
  {
15
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
  *
14
  * @property-read string $billing_period_start_date
15
  * @property-read string $billing_period_end_date
16
  */
17
+ class SubscriptionDetails extends Instance
18
  {
19
  }
20
+ class_alias('Braintree\Transaction\SubscriptionDetails', 'Braintree_Transaction_SubscriptionDetails');
braintree_sdk/lib/Braintree/Transaction/VenmoAccountDetails.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
11
+ */
12
+
13
+ /**
14
+ * creates an instance of VenmoAccountDetails
15
+ *
16
+ *
17
+ * @package Braintree
18
+ * @subpackage Transaction
19
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
20
+ *
21
+ * @property-read string $sourceDescription
22
+ * @property-read string $token
23
+ * @property-read string $imageUrl
24
+ * @property-read string $username
25
+ * @property-read string $venmo_user_id
26
+ * @uses Instance inherits methods
27
+ */
28
+ class VenmoAccountDetails extends Instance
29
+ {
30
+ protected $_attributes = array();
31
+
32
+ /**
33
+ * @ignore
34
+ */
35
+ public function __construct($attributes)
36
+ {
37
+ parent::__construct($attributes);
38
+ }
39
+ }
40
+ class_alias('Braintree\Transaction\VenmoAccountDetails', 'Braintree_Transaction_VenmoAccountDetails');
braintree_sdk/lib/Braintree/TransactionGateway.php CHANGED
@@ -1,4 +1,8 @@
1
  <?php
 
 
 
 
2
  /**
3
  * Braintree TransactionGateway processor
4
  * Creates and manages transactions
@@ -10,10 +14,10 @@
10
  *
11
  * @package Braintree
12
  * @category Resources
13
- * @copyright 2014 Braintree, a division of PayPal, Inc.
14
  */
15
 
16
- final class Braintree_TransactionGateway
17
  {
18
  private $_gateway;
19
  private $_config;
@@ -24,13 +28,13 @@ final class Braintree_TransactionGateway
24
  $this->_gateway = $gateway;
25
  $this->_config = $gateway->config;
26
  $this->_config->assertHasAccessTokenOrKeys();
27
- $this->_http = new Braintree_Http($gateway->config);
28
  }
29
 
30
  public function cloneTransaction($transactionId, $attribs)
31
  {
32
- Braintree_Util::verifyKeys(self::cloneSignature(), $attribs);
33
- return $this->_doCreate('/transactions/' . $transactionId . '/clone', array('transactionClone' => $attribs));
34
  }
35
 
36
  /**
@@ -41,56 +45,57 @@ final class Braintree_TransactionGateway
41
  */
42
  private function create($attribs)
43
  {
44
- Braintree_Util::verifyKeys(self::createSignature(), $attribs);
45
- return $this->_doCreate('/transactions', array('transaction' => $attribs));
46
  }
47
 
48
  /**
49
- *
50
  * @ignore
51
  * @access private
52
  * @param array $attribs
53
  * @return object
54
- * @throws Braintree_Exception_ValidationError
55
  */
56
  private function createNoValidate($attribs)
57
  {
58
  $result = $this->create($attribs);
59
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
60
  }
61
  /**
62
  *
 
63
  * @access public
64
  * @param array $attribs
65
  * @return object
66
  */
67
  public function createFromTransparentRedirect($queryString)
68
  {
69
- trigger_error("DEPRECATED: Please use Braintree_TransparentRedirectRequest::confirm", E_USER_NOTICE);
70
- $params = Braintree_TransparentRedirect::parseAndValidateQueryString(
71
  $queryString
72
  );
73
  return $this->_doCreate(
74
  '/transactions/all/confirm_transparent_redirect_request',
75
- array('id' => $params['id'])
76
  );
77
  }
78
  /**
79
  *
 
80
  * @access public
81
  * @param none
82
  * @return string
83
  */
84
  public function createTransactionUrl()
85
  {
86
- trigger_error("DEPRECATED: Please use Braintree_TransparentRedirectRequest::url", E_USER_NOTICE);
87
  return $this->_config->baseUrl() . $this->_config->merchantPath() .
88
  '/transactions/all/create_via_transparent_redirect_request';
89
  }
90
 
91
  public static function cloneSignature()
92
  {
93
- return array('amount', 'channel', array('options' => array('submitForSettlement')));
94
  }
95
 
96
  /**
@@ -99,7 +104,7 @@ final class Braintree_TransactionGateway
99
  */
100
  public static function createSignature()
101
  {
102
- return array(
103
  'amount',
104
  'billingAddressId',
105
  'channel',
@@ -114,36 +119,40 @@ final class Braintree_TransactionGateway
114
  'purchaseOrderNumber',
115
  'recurring',
116
  'serviceFeeAmount',
 
 
 
 
117
  'shippingAddressId',
118
  'taxAmount',
119
  'taxExempt',
120
  'threeDSecureToken',
121
  'type',
122
  'venmoSdkPaymentMethodCode',
123
- array('creditCard' =>
124
- array('token', 'cardholderName', 'cvv', 'expirationDate', 'expirationMonth', 'expirationYear', 'number'),
125
- ),
126
- array('customer' =>
127
- array(
128
  'id', 'company', 'email', 'fax', 'firstName',
129
- 'lastName', 'phone', 'website'),
130
- ),
131
- array('billing' =>
132
- array(
133
  'firstName', 'lastName', 'company', 'countryName',
134
  'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric',
135
  'extendedAddress', 'locality', 'postalCode', 'region',
136
- 'streetAddress'),
137
- ),
138
- array('shipping' =>
139
- array(
140
  'firstName', 'lastName', 'company', 'countryName',
141
  'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric',
142
  'extendedAddress', 'locality', 'postalCode', 'region',
143
- 'streetAddress'),
144
- ),
145
- array('options' =>
146
- array(
147
  'holdInEscrow',
148
  'storeInVault',
149
  'storeInVaultOnSuccess',
@@ -152,35 +161,35 @@ final class Braintree_TransactionGateway
152
  'venmoSdkSession',
153
  'storeShippingAddressInVault',
154
  'payeeEmail',
155
- array('three_d_secure' =>
156
- array('required')
157
- ),
158
- array('paypal' =>
159
- array(
160
  'payeeEmail',
161
  'customField',
162
- 'description'
163
- )
164
- ),
165
- array('amexRewards' =>
166
- array(
 
167
  'requestId',
168
  'points',
169
  'currencyAmount',
170
  'currencyIsoCode'
171
- )
172
- )
173
- ),
174
- ),
175
- array('customFields' => array('_anyKey_')
176
- ),
177
- array('descriptor' => array('name', 'phone', 'url')),
178
- array('paypalAccount' => array('payeeEmail')),
179
- array('apple_pay_card' => array('number', 'cardholder_name', 'cryptogram', 'expiration_month', 'expiration_year')),
180
- array('industry' =>
181
- array('industryType',
182
- array('data' =>
183
- array(
184
  'folioNumber',
185
  'checkInDate',
186
  'checkOutDate',
@@ -190,41 +199,46 @@ final class Braintree_TransactionGateway
190
  'lodgingCheckOutDate',
191
  'lodgingName',
192
  'roomRate'
193
- )
194
- )
195
- )
196
- )
197
- );
 
 
 
 
 
198
  }
199
 
200
  /**
201
  *
202
  * @access public
203
  * @param array $attribs
204
- * @return object
205
  */
206
  public function credit($attribs)
207
  {
208
- return $this->create(array_merge($attribs, array('type' => Braintree_Transaction::CREDIT)));
209
  }
210
 
211
  /**
212
  *
213
  * @access public
214
  * @param array $attribs
215
- * @return object
216
- * @throws Braintree_Exception_ValidationError
217
  */
218
  public function creditNoValidate($attribs)
219
  {
220
  $result = $this->credit($attribs);
221
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
222
  }
223
 
224
-
225
  /**
226
  * @access public
227
- *
 
228
  */
229
  public function find($id)
230
  {
@@ -232,13 +246,12 @@ final class Braintree_TransactionGateway
232
  try {
233
  $path = $this->_config->merchantPath() . '/transactions/' . $id;
234
  $response = $this->_http->get($path);
235
- return Braintree_Transaction::factory($response['transaction']);
236
- } catch (Braintree_Exception_NotFound $e) {
237
- throw new Braintree_Exception_NotFound(
238
  'transaction with id ' . $id . ' not found'
239
  );
240
  }
241
-
242
  }
243
  /**
244
  * new sale
@@ -247,7 +260,7 @@ final class Braintree_TransactionGateway
247
  */
248
  public function sale($attribs)
249
  {
250
- return $this->create(array_merge(array('type' => Braintree_Transaction::SALE), $attribs));
251
  }
252
 
253
  /**
@@ -255,12 +268,12 @@ final class Braintree_TransactionGateway
255
  * @access public
256
  * @param array $attribs
257
  * @return array
258
- * @throws Braintree_Exception_ValidationsFailed
259
  */
260
  public function saleNoValidate($attribs)
261
  {
262
  $result = $this->sale($attribs);
263
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
264
  }
265
 
266
  /**
@@ -272,42 +285,42 @@ final class Braintree_TransactionGateway
272
  *
273
  * @param mixed $query search query
274
  * @param array $options options such as page number
275
- * @return object Braintree_ResourceCollection
276
  * @throws InvalidArgumentException
277
  */
278
  public function search($query)
279
  {
280
- $criteria = array();
281
  foreach ($query as $term) {
282
  $criteria[$term->name] = $term->toparam();
283
  }
284
 
285
  $path = $this->_config->merchantPath() . '/transactions/advanced_search_ids';
286
- $response = $this->_http->post($path, array('search' => $criteria));
287
  if (array_key_exists('searchResults', $response)) {
288
- $pager = array(
289
  'object' => $this,
290
  'method' => 'fetch',
291
- 'methodArgs' => array($query)
292
- );
293
 
294
- return new Braintree_ResourceCollection($response, $pager);
295
  } else {
296
- throw new Braintree_Exception_DownForMaintenance();
297
  }
298
  }
299
 
300
  public function fetch($query, $ids)
301
  {
302
- $criteria = array();
303
  foreach ($query as $term) {
304
  $criteria[$term->name] = $term->toparam();
305
  }
306
- $criteria["ids"] = Braintree_TransactionSearch::ids()->in($ids)->toparam();
307
  $path = $this->_config->merchantPath() . '/transactions/advanced_search';
308
- $response = $this->_http->post($path, array('search' => $criteria));
309
 
310
- return Braintree_Util::extractattributeasarray(
311
  $response['creditCardTransactions'],
312
  'transaction'
313
  );
@@ -317,7 +330,7 @@ final class Braintree_TransactionGateway
317
  * void a transaction by id
318
  *
319
  * @param string $id transaction id
320
- * @return object Braintree_Result_Successful|Braintree_Result_Error
321
  */
322
  public function void($transactionId)
323
  {
@@ -333,22 +346,35 @@ final class Braintree_TransactionGateway
333
  public function voidNoValidate($transactionId)
334
  {
335
  $result = $this->void($transactionId);
336
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
337
  }
338
 
339
- public function submitForSettlement($transactionId, $amount = null)
340
  {
341
  $this->_validateId($transactionId);
 
 
342
 
343
  $path = $this->_config->merchantPath() . '/transactions/'. $transactionId . '/submit_for_settlement';
344
- $response = $this->_http->put($path, array('transaction' => array('amount' => $amount)));
345
  return $this->_verifyGatewayResponse($response);
346
  }
347
 
348
- public function submitForSettlementNoValidate($transactionId, $amount = null)
349
  {
350
- $result = $this->submitForSettlement($transactionId, $amount);
351
- return Braintree_Util::returnObjectOrThrowException(__CLASS__, $result);
 
 
 
 
 
 
 
 
 
 
 
352
  }
353
 
354
  public function holdInEscrow($transactionId)
@@ -356,7 +382,7 @@ final class Braintree_TransactionGateway
356
  $this->_validateId($transactionId);
357
 
358
  $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/hold_in_escrow';
359
- $response = $this->_http->put($path, array());
360
  return $this->_verifyGatewayResponse($response);
361
  }
362
 
@@ -365,7 +391,7 @@ final class Braintree_TransactionGateway
365
  $this->_validateId($transactionId);
366
 
367
  $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/release_from_escrow';
368
- $response = $this->_http->put($path, array());
369
  return $this->_verifyGatewayResponse($response);
370
  }
371
 
@@ -374,7 +400,7 @@ final class Braintree_TransactionGateway
374
  $this->_validateId($transactionId);
375
 
376
  $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/cancel_release';
377
- $response = $this->_http->put($path, array());
378
  return $this->_verifyGatewayResponse($response);
379
  }
380
 
@@ -382,7 +408,7 @@ final class Braintree_TransactionGateway
382
  {
383
  self::_validateId($transactionId);
384
 
385
- $params = array('transaction' => array('amount' => $amount));
386
  $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/refund';
387
  $response = $this->_http->post($path, $params);
388
  return $this->_verifyGatewayResponse($response);
@@ -423,33 +449,33 @@ final class Braintree_TransactionGateway
423
  }
424
  }
425
 
426
-
427
  /**
428
  * generic method for validating incoming gateway responses
429
  *
430
- * creates a new Braintree_Transaction object and encapsulates
431
- * it inside a Braintree_Result_Successful object, or
432
- * encapsulates a Braintree_Errors object inside a Result_Error
433
  * alternatively, throws an Unexpected exception if the response is invalid.
434
  *
435
  * @ignore
436
  * @param array $response gateway response values
437
- * @return object Result_Successful or Result_Error
438
- * @throws Braintree_Exception_Unexpected
439
  */
440
  private function _verifyGatewayResponse($response)
441
  {
442
  if (isset($response['transaction'])) {
443
- // return a populated instance of Braintree_Transaction
444
- return new Braintree_Result_Successful(
445
- Braintree_Transaction::factory($response['transaction'])
446
  );
447
  } else if (isset($response['apiErrorResponse'])) {
448
- return new Braintree_Result_Error($response['apiErrorResponse']);
449
  } else {
450
- throw new Braintree_Exception_Unexpected(
451
  "Expected transaction or apiErrorResponse"
452
  );
453
  }
454
  }
455
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ use InvalidArgumentException;
5
+
6
  /**
7
  * Braintree TransactionGateway processor
8
  * Creates and manages transactions
14
  *
15
  * @package Braintree
16
  * @category Resources
17
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
18
  */
19
 
20
+ final class TransactionGateway
21
  {
22
  private $_gateway;
23
  private $_config;
28
  $this->_gateway = $gateway;
29
  $this->_config = $gateway->config;
30
  $this->_config->assertHasAccessTokenOrKeys();
31
+ $this->_http = new Http($gateway->config);
32
  }
33
 
34
  public function cloneTransaction($transactionId, $attribs)
35
  {
36
+ Util::verifyKeys(self::cloneSignature(), $attribs);
37
+ return $this->_doCreate('/transactions/' . $transactionId . '/clone', ['transactionClone' => $attribs]);
38
  }
39
 
40
  /**
45
  */
46
  private function create($attribs)
47
  {
48
+ Util::verifyKeys(self::createSignature(), $attribs);
49
+ return $this->_doCreate('/transactions', ['transaction' => $attribs]);
50
  }
51
 
52
  /**
 
53
  * @ignore
54
  * @access private
55
  * @param array $attribs
56
  * @return object
57
+ * @throws Exception\ValidationError
58
  */
59
  private function createNoValidate($attribs)
60
  {
61
  $result = $this->create($attribs);
62
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
63
  }
64
  /**
65
  *
66
+ * @deprecated since version 2.3.0
67
  * @access public
68
  * @param array $attribs
69
  * @return object
70
  */
71
  public function createFromTransparentRedirect($queryString)
72
  {
73
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::confirm", E_USER_NOTICE);
74
+ $params = TransparentRedirect::parseAndValidateQueryString(
75
  $queryString
76
  );
77
  return $this->_doCreate(
78
  '/transactions/all/confirm_transparent_redirect_request',
79
+ ['id' => $params['id']]
80
  );
81
  }
82
  /**
83
  *
84
+ * @deprecated since version 2.3.0
85
  * @access public
86
  * @param none
87
  * @return string
88
  */
89
  public function createTransactionUrl()
90
  {
91
+ trigger_error("DEPRECATED: Please use TransparentRedirectRequest::url", E_USER_NOTICE);
92
  return $this->_config->baseUrl() . $this->_config->merchantPath() .
93
  '/transactions/all/create_via_transparent_redirect_request';
94
  }
95
 
96
  public static function cloneSignature()
97
  {
98
+ return ['amount', 'channel', ['options' => ['submitForSettlement']]];
99
  }
100
 
101
  /**
104
  */
105
  public static function createSignature()
106
  {
107
+ return [
108
  'amount',
109
  'billingAddressId',
110
  'channel',
119
  'purchaseOrderNumber',
120
  'recurring',
121
  'serviceFeeAmount',
122
+ 'sharedPaymentMethodToken',
123
+ 'sharedCustomerId',
124
+ 'sharedShippingAddressId',
125
+ 'sharedBillingAddressId',
126
  'shippingAddressId',
127
  'taxAmount',
128
  'taxExempt',
129
  'threeDSecureToken',
130
  'type',
131
  'venmoSdkPaymentMethodCode',
132
+ ['creditCard' =>
133
+ ['token', 'cardholderName', 'cvv', 'expirationDate', 'expirationMonth', 'expirationYear', 'number'],
134
+ ],
135
+ ['customer' =>
136
+ [
137
  'id', 'company', 'email', 'fax', 'firstName',
138
+ 'lastName', 'phone', 'website'],
139
+ ],
140
+ ['billing' =>
141
+ [
142
  'firstName', 'lastName', 'company', 'countryName',
143
  'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric',
144
  'extendedAddress', 'locality', 'postalCode', 'region',
145
+ 'streetAddress'],
146
+ ],
147
+ ['shipping' =>
148
+ [
149
  'firstName', 'lastName', 'company', 'countryName',
150
  'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric',
151
  'extendedAddress', 'locality', 'postalCode', 'region',
152
+ 'streetAddress'],
153
+ ],
154
+ ['options' =>
155
+ [
156
  'holdInEscrow',
157
  'storeInVault',
158
  'storeInVaultOnSuccess',
161
  'venmoSdkSession',
162
  'storeShippingAddressInVault',
163
  'payeeEmail',
164
+ ['three_d_secure' =>
165
+ ['required']
166
+ ],
167
+ ['paypal' =>
168
+ [
169
  'payeeEmail',
170
  'customField',
171
+ 'description',
172
+ ['supplementaryData' => ['_anyKey_']],
173
+ ]
174
+ ],
175
+ ['amexRewards' =>
176
+ [
177
  'requestId',
178
  'points',
179
  'currencyAmount',
180
  'currencyIsoCode'
181
+ ]
182
+ ]
183
+ ],
184
+ ],
185
+ ['customFields' => ['_anyKey_']],
186
+ ['descriptor' => ['name', 'phone', 'url']],
187
+ ['paypalAccount' => ['payeeEmail']],
188
+ ['apple_pay_card' => ['number', 'cardholder_name', 'cryptogram', 'expiration_month', 'expiration_year']],
189
+ ['industry' =>
190
+ ['industryType',
191
+ ['data' =>
192
+ [
 
193
  'folioNumber',
194
  'checkInDate',
195
  'checkOutDate',
199
  'lodgingCheckOutDate',
200
  'lodgingName',
201
  'roomRate'
202
+ ]
203
+ ]
204
+ ]
205
+ ]
206
+ ];
207
+ }
208
+
209
+ public static function submitForSettlementSignature()
210
+ {
211
+ return ['orderId', ['descriptor' => ['name', 'phone', 'url']]];
212
  }
213
 
214
  /**
215
  *
216
  * @access public
217
  * @param array $attribs
218
+ * @return Result\Successful|Result\Error
219
  */
220
  public function credit($attribs)
221
  {
222
+ return $this->create(array_merge($attribs, ['type' => Transaction::CREDIT]));
223
  }
224
 
225
  /**
226
  *
227
  * @access public
228
  * @param array $attribs
229
+ * @return Result\Successful|Result\Error
230
+ * @throws Exception\ValidationError
231
  */
232
  public function creditNoValidate($attribs)
233
  {
234
  $result = $this->credit($attribs);
235
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
236
  }
237
 
 
238
  /**
239
  * @access public
240
+ * @param string id
241
+ * @return Transaction
242
  */
243
  public function find($id)
244
  {
246
  try {
247
  $path = $this->_config->merchantPath() . '/transactions/' . $id;
248
  $response = $this->_http->get($path);
249
+ return Transaction::factory($response['transaction']);
250
+ } catch (Exception\NotFound $e) {
251
+ throw new Exception\NotFound(
252
  'transaction with id ' . $id . ' not found'
253
  );
254
  }
 
255
  }
256
  /**
257
  * new sale
260
  */
261
  public function sale($attribs)
262
  {
263
+ return $this->create(array_merge(['type' => Transaction::SALE], $attribs));
264
  }
265
 
266
  /**
268
  * @access public
269
  * @param array $attribs
270
  * @return array
271
+ * @throws Exception\ValidationsFailed
272
  */
273
  public function saleNoValidate($attribs)
274
  {
275
  $result = $this->sale($attribs);
276
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
277
  }
278
 
279
  /**
285
  *
286
  * @param mixed $query search query
287
  * @param array $options options such as page number
288
+ * @return ResourceCollection
289
  * @throws InvalidArgumentException
290
  */
291
  public function search($query)
292
  {
293
+ $criteria = [];
294
  foreach ($query as $term) {
295
  $criteria[$term->name] = $term->toparam();
296
  }
297
 
298
  $path = $this->_config->merchantPath() . '/transactions/advanced_search_ids';
299
+ $response = $this->_http->post($path, ['search' => $criteria]);
300
  if (array_key_exists('searchResults', $response)) {
301
+ $pager = [
302
  'object' => $this,
303
  'method' => 'fetch',
304
+ 'methodArgs' => [$query]
305
+ ];
306
 
307
+ return new ResourceCollection($response, $pager);
308
  } else {
309
+ throw new Exception\DownForMaintenance();
310
  }
311
  }
312
 
313
  public function fetch($query, $ids)
314
  {
315
+ $criteria = [];
316
  foreach ($query as $term) {
317
  $criteria[$term->name] = $term->toparam();
318
  }
319
+ $criteria["ids"] = TransactionSearch::ids()->in($ids)->toparam();
320
  $path = $this->_config->merchantPath() . '/transactions/advanced_search';
321
+ $response = $this->_http->post($path, ['search' => $criteria]);
322
 
323
+ return Util::extractattributeasarray(
324
  $response['creditCardTransactions'],
325
  'transaction'
326
  );
330
  * void a transaction by id
331
  *
332
  * @param string $id transaction id
333
+ * @return Result\Successful|Result\Error
334
  */
335
  public function void($transactionId)
336
  {
346
  public function voidNoValidate($transactionId)
347
  {
348
  $result = $this->void($transactionId);
349
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
350
  }
351
 
352
+ public function submitForSettlement($transactionId, $amount = null, $attribs = [])
353
  {
354
  $this->_validateId($transactionId);
355
+ Util::verifyKeys(self::submitForSettlementSignature(), $attribs);
356
+ $attribs['amount'] = $amount;
357
 
358
  $path = $this->_config->merchantPath() . '/transactions/'. $transactionId . '/submit_for_settlement';
359
+ $response = $this->_http->put($path, ['transaction' => $attribs]);
360
  return $this->_verifyGatewayResponse($response);
361
  }
362
 
363
+ public function submitForSettlementNoValidate($transactionId, $amount = null, $attribs = [])
364
  {
365
+ $result = $this->submitForSettlement($transactionId, $amount, $attribs);
366
+ return Util::returnObjectOrThrowException(__CLASS__, $result);
367
+ }
368
+
369
+ public function submitForPartialSettlement($transactionId, $amount, $attribs = [])
370
+ {
371
+ $this->_validateId($transactionId);
372
+ Util::verifyKeys(self::submitForSettlementSignature(), $attribs);
373
+ $attribs['amount'] = $amount;
374
+
375
+ $path = $this->_config->merchantPath() . '/transactions/'. $transactionId . '/submit_for_partial_settlement';
376
+ $response = $this->_http->post($path, ['transaction' => $attribs]);
377
+ return $this->_verifyGatewayResponse($response);
378
  }
379
 
380
  public function holdInEscrow($transactionId)
382
  $this->_validateId($transactionId);
383
 
384
  $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/hold_in_escrow';
385
+ $response = $this->_http->put($path, []);
386
  return $this->_verifyGatewayResponse($response);
387
  }
388
 
391
  $this->_validateId($transactionId);
392
 
393
  $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/release_from_escrow';
394
+ $response = $this->_http->put($path, []);
395
  return $this->_verifyGatewayResponse($response);
396
  }
397
 
400
  $this->_validateId($transactionId);
401
 
402
  $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/cancel_release';
403
+ $response = $this->_http->put($path, []);
404
  return $this->_verifyGatewayResponse($response);
405
  }
406
 
408
  {
409
  self::_validateId($transactionId);
410
 
411
+ $params = ['transaction' => ['amount' => $amount]];
412
  $path = $this->_config->merchantPath() . '/transactions/' . $transactionId . '/refund';
413
  $response = $this->_http->post($path, $params);
414
  return $this->_verifyGatewayResponse($response);
449
  }
450
  }
451
 
 
452
  /**
453
  * generic method for validating incoming gateway responses
454
  *
455
+ * creates a new Transaction object and encapsulates
456
+ * it inside a Result\Successful object, or
457
+ * encapsulates a Errors object inside a Result\Error
458
  * alternatively, throws an Unexpected exception if the response is invalid.
459
  *
460
  * @ignore
461
  * @param array $response gateway response values
462
+ * @return Result\Successful|Result\Error
463
+ * @throws Exception\Unexpected
464
  */
465
  private function _verifyGatewayResponse($response)
466
  {
467
  if (isset($response['transaction'])) {
468
+ // return a populated instance of Transaction
469
+ return new Result\Successful(
470
+ Transaction::factory($response['transaction'])
471
  );
472
  } else if (isset($response['apiErrorResponse'])) {
473
+ return new Result\Error($response['apiErrorResponse']);
474
  } else {
475
+ throw new Exception\Unexpected(
476
  "Expected transaction or apiErrorResponse"
477
  );
478
  }
479
  }
480
  }
481
+ class_alias('Braintree\TransactionGateway', 'Braintree_TransactionGateway');
braintree_sdk/lib/Braintree/TransactionSearch.php CHANGED
@@ -1,130 +1,129 @@
1
  <?php
2
- class Braintree_TransactionSearch
 
 
3
  {
4
- static function amount() { return new Braintree_RangeNode("amount"); }
5
- static function authorizationExpiredAt() { return new Braintree_RangeNode("authorizationExpiredAt"); }
6
- static function authorizedAt() { return new Braintree_RangeNode("authorizedAt"); }
7
- static function billingCompany() { return new Braintree_TextNode('billing_company'); }
8
- static function billingCountryName() { return new Braintree_TextNode('billing_country_name'); }
9
- static function billingExtendedAddress() { return new Braintree_TextNode('billing_extended_address'); }
10
- static function billingFirstName() { return new Braintree_TextNode('billing_first_name'); }
11
- static function billingLastName() { return new Braintree_TextNode('billing_last_name'); }
12
- static function billingLocality() { return new Braintree_TextNode('billing_locality'); }
13
- static function billingPostalCode() { return new Braintree_TextNode('billing_postal_code'); }
14
- static function billingRegion() { return new Braintree_TextNode('billing_region'); }
15
- static function billingStreetAddress() { return new Braintree_TextNode('billing_street_address'); }
16
- static function createdAt() { return new Braintree_RangeNode("createdAt"); }
17
- static function creditCardCardholderName() { return new Braintree_TextNode('credit_card_cardholderName'); }
18
- static function creditCardExpirationDate() { return new Braintree_EqualityNode('credit_card_expiration_date'); }
19
- static function creditCardNumber() { return new Braintree_PartialMatchNode('credit_card_number'); }
20
- static function creditCardUniqueIdentifier() { return new Braintree_TextNode('credit_card_unique_identifier'); }
21
- static function customerCompany() { return new Braintree_TextNode('customer_company'); }
22
- static function customerEmail() { return new Braintree_TextNode('customer_email'); }
23
- static function customerFax() { return new Braintree_TextNode('customer_fax'); }
24
- static function customerFirstName() { return new Braintree_TextNode('customer_first_name'); }
25
- static function customerId() { return new Braintree_TextNode('customer_id'); }
26
- static function customerLastName() { return new Braintree_TextNode('customer_last_name'); }
27
- static function customerPhone() { return new Braintree_TextNode('customer_phone'); }
28
- static function customerWebsite() { return new Braintree_TextNode('customer_website'); }
29
- static function disbursementDate() { return new Braintree_RangeNode("disbursementDate"); }
30
- static function disputeDate() { return new Braintree_RangeNode("disputeDate"); }
31
- static function europeBankAccountIban() { return new Braintree_TextNode("europeBankAccountIban"); }
32
- static function failedAt() { return new Braintree_RangeNode("failedAt"); }
33
- static function gatewayRejectedAt() { return new Braintree_RangeNode("gatewayRejectedAt"); }
34
- static function id() { return new Braintree_TextNode('id'); }
35
- static function ids() { return new Braintree_MultipleValueNode('ids'); }
36
- static function merchantAccountId() { return new Braintree_MultipleValueNode("merchant_account_id"); }
37
- static function orderId() { return new Braintree_TextNode('order_id'); }
38
- static function paymentInstrumentType() { return new Braintree_MultipleValueNode('paymentInstrumentType'); }
39
- static function paymentMethodToken() { return new Braintree_TextNode('payment_method_token'); }
40
- static function paypalAuthorizationId() { return new Braintree_TextNode('paypal_authorization_id'); }
41
- static function paypalPayerEmail() { return new Braintree_TextNode('paypal_payer_email'); }
42
- static function paypalPaymentId() { return new Braintree_TextNode('paypal_payment_id'); }
43
- static function processorAuthorizationCode() { return new Braintree_TextNode('processor_authorization_code'); }
44
- static function processorDeclinedAt() { return new Braintree_RangeNode("processorDeclinedAt"); }
45
- static function refund() { return new Braintree_KeyValueNode("refund"); }
46
- static function settledAt() { return new Braintree_RangeNode("settledAt"); }
47
- static function settlementBatchId() { return new Braintree_TextNode('settlement_batch_id'); }
48
- static function shippingCompany() { return new Braintree_TextNode('shipping_company'); }
49
- static function shippingCountryName() { return new Braintree_TextNode('shipping_country_name'); }
50
- static function shippingExtendedAddress() { return new Braintree_TextNode('shipping_extended_address'); }
51
- static function shippingFirstName() { return new Braintree_TextNode('shipping_first_name'); }
52
- static function shippingLastName() { return new Braintree_TextNode('shipping_last_name'); }
53
- static function shippingLocality() { return new Braintree_TextNode('shipping_locality'); }
54
- static function shippingPostalCode() { return new Braintree_TextNode('shipping_postal_code'); }
55
- static function shippingRegion() { return new Braintree_TextNode('shipping_region'); }
56
- static function shippingStreetAddress() { return new Braintree_TextNode('shipping_street_address'); }
57
- static function submittedForSettlementAt() { return new Braintree_RangeNode("submittedForSettlementAt"); }
58
- static function user() { return new Braintree_MultipleValueNode('user'); }
59
- static function voidedAt() { return new Braintree_RangeNode("voidedAt"); }
60
 
61
- static function createdUsing()
62
  {
63
- return new Braintree_MultipleValueNode("created_using", array(
64
- Braintree_Transaction::FULL_INFORMATION,
65
- Braintree_Transaction::TOKEN
66
- ));
67
  }
68
 
69
- static function creditCardCardType()
70
  {
71
- return new Braintree_MultipleValueNode("credit_card_card_type", array(
72
- Braintree_CreditCard::AMEX,
73
- Braintree_CreditCard::CARTE_BLANCHE,
74
- Braintree_CreditCard::CHINA_UNION_PAY,
75
- Braintree_CreditCard::DINERS_CLUB_INTERNATIONAL,
76
- Braintree_CreditCard::DISCOVER,
77
- Braintree_CreditCard::JCB,
78
- Braintree_CreditCard::LASER,
79
- Braintree_CreditCard::MAESTRO,
80
- Braintree_CreditCard::MASTER_CARD,
81
- Braintree_CreditCard::SOLO,
82
- Braintree_CreditCard::SWITCH_TYPE,
83
- Braintree_CreditCard::VISA,
84
- Braintree_CreditCard::UNKNOWN
85
- ));
86
  }
87
 
88
- static function creditCardCustomerLocation()
89
  {
90
- return new Braintree_MultipleValueNode("credit_card_customer_location", array(
91
- Braintree_CreditCard::INTERNATIONAL,
92
- Braintree_CreditCard::US
93
- ));
94
  }
95
 
96
- static function source()
97
  {
98
- return new Braintree_MultipleValueNode("source", array(
99
- Braintree_Transaction::API,
100
- Braintree_Transaction::CONTROL_PANEL,
101
- Braintree_Transaction::RECURRING,
102
- ));
103
  }
104
 
105
- static function status()
106
  {
107
- return new Braintree_MultipleValueNode("status", array(
108
- Braintree_Transaction::AUTHORIZATION_EXPIRED,
109
- Braintree_Transaction::AUTHORIZING,
110
- Braintree_Transaction::AUTHORIZED,
111
- Braintree_Transaction::GATEWAY_REJECTED,
112
- Braintree_Transaction::FAILED,
113
- Braintree_Transaction::PROCESSOR_DECLINED,
114
- Braintree_Transaction::SETTLED,
115
- Braintree_Transaction::SETTLING,
116
- Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT,
117
- Braintree_Transaction::VOIDED,
118
- Braintree_Transaction::SETTLEMENT_DECLINED,
119
- Braintree_Transaction::SETTLEMENT_PENDING
120
- ));
121
  }
122
 
123
- static function type()
124
  {
125
- return new Braintree_MultipleValueNode("type", array(
126
- Braintree_Transaction::SALE,
127
- Braintree_Transaction::CREDIT
128
- ));
129
  }
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 customerCompany() { return new TextNode('customer_company'); }
24
+ public static function customerEmail() { return new TextNode('customer_email'); }
25
+ public static function customerFax() { return new TextNode('customer_fax'); }
26
+ public static function customerFirstName() { return new TextNode('customer_first_name'); }
27
+ public static function customerId() { return new TextNode('customer_id'); }
28
+ public static function customerLastName() { return new TextNode('customer_last_name'); }
29
+ public static function customerPhone() { return new TextNode('customer_phone'); }
30
+ public static function customerWebsite() { return new TextNode('customer_website'); }
31
+ public static function disbursementDate() { return new RangeNode("disbursementDate"); }
32
+ public static function disputeDate() { return new RangeNode("disputeDate"); }
33
+ public static function europeBankAccountIban() { return new TextNode("europeBankAccountIban"); }
34
+ public static function failedAt() { return new RangeNode("failedAt"); }
35
+ public static function gatewayRejectedAt() { return new RangeNode("gatewayRejectedAt"); }
36
+ public static function id() { return new TextNode('id'); }
37
+ public static function ids() { return new MultipleValueNode('ids'); }
38
+ public static function merchantAccountId() { return new MultipleValueNode("merchant_account_id"); }
39
+ public static function orderId() { return new TextNode('order_id'); }
40
+ public static function paymentInstrumentType() { return new MultipleValueNode('paymentInstrumentType'); }
41
+ public static function paymentMethodToken() { return new TextNode('payment_method_token'); }
42
+ public static function paypalAuthorizationId() { return new TextNode('paypal_authorization_id'); }
43
+ public static function paypalPayerEmail() { return new TextNode('paypal_payer_email'); }
44
+ public static function paypalPaymentId() { return new TextNode('paypal_payment_id'); }
45
+ public static function processorAuthorizationCode() { return new TextNode('processor_authorization_code'); }
46
+ public static function processorDeclinedAt() { return new RangeNode("processorDeclinedAt"); }
47
+ public static function refund() { return new KeyValueNode("refund"); }
48
+ public static function settledAt() { return new RangeNode("settledAt"); }
49
+ public static function settlementBatchId() { return new TextNode('settlement_batch_id'); }
50
+ public static function shippingCompany() { return new TextNode('shipping_company'); }
51
+ public static function shippingCountryName() { return new TextNode('shipping_country_name'); }
52
+ public static function shippingExtendedAddress() { return new TextNode('shipping_extended_address'); }
53
+ public static function shippingFirstName() { return new TextNode('shipping_first_name'); }
54
+ public static function shippingLastName() { return new TextNode('shipping_last_name'); }
55
+ public static function shippingLocality() { return new TextNode('shipping_locality'); }
56
+ public static function shippingPostalCode() { return new TextNode('shipping_postal_code'); }
57
+ public static function shippingRegion() { return new TextNode('shipping_region'); }
58
+ public static function shippingStreetAddress() { return new TextNode('shipping_street_address'); }
59
+ public static function submittedForSettlementAt() { return new RangeNode("submittedForSettlementAt"); }
60
+ public static function user() { return new MultipleValueNode('user'); }
61
+ public static function voidedAt() { return new RangeNode("voidedAt"); }
62
 
63
+ public static function createdUsing()
64
  {
65
+ return new MultipleValueNode('created_using', [
66
+ Transaction::FULL_INFORMATION,
67
+ Transaction::TOKEN
68
+ ]);
69
  }
70
 
71
+ public static function creditCardCardType()
72
  {
73
+ return new MultipleValueNode('credit_card_card_type', [
74
+ CreditCard::AMEX,
75
+ CreditCard::CARTE_BLANCHE,
76
+ CreditCard::CHINA_UNION_PAY,
77
+ CreditCard::DINERS_CLUB_INTERNATIONAL,
78
+ CreditCard::DISCOVER,
79
+ CreditCard::JCB,
80
+ CreditCard::LASER,
81
+ CreditCard::MAESTRO,
82
+ CreditCard::MASTER_CARD,
83
+ CreditCard::SOLO,
84
+ CreditCard::SWITCH_TYPE,
85
+ CreditCard::VISA,
86
+ CreditCard::UNKNOWN
87
+ ]);
88
  }
89
 
90
+ public static function creditCardCustomerLocation()
91
  {
92
+ return new MultipleValueNode('credit_card_customer_location', [
93
+ CreditCard::INTERNATIONAL,
94
+ CreditCard::US
95
+ ]);
96
  }
97
 
98
+ public static function source()
99
  {
100
+ return new MultipleValueNode('source', []);
 
 
 
 
101
  }
102
 
103
+ public static function status()
104
  {
105
+ return new MultipleValueNode('status', [
106
+ Transaction::AUTHORIZATION_EXPIRED,
107
+ Transaction::AUTHORIZING,
108
+ Transaction::AUTHORIZED,
109
+ Transaction::GATEWAY_REJECTED,
110
+ Transaction::FAILED,
111
+ Transaction::PROCESSOR_DECLINED,
112
+ Transaction::SETTLED,
113
+ Transaction::SETTLING,
114
+ Transaction::SUBMITTED_FOR_SETTLEMENT,
115
+ Transaction::VOIDED,
116
+ Transaction::SETTLEMENT_DECLINED,
117
+ Transaction::SETTLEMENT_PENDING
118
+ ]);
119
  }
120
 
121
+ public static function type()
122
  {
123
+ return new MultipleValueNode('type', [
124
+ Transaction::SALE,
125
+ Transaction::CREDIT
126
+ ]);
127
  }
128
  }
129
+ class_alias('Braintree\TransactionSearch', 'Braintree_TransactionSearch');
braintree_sdk/lib/Braintree/TransparentRedirect.php CHANGED
@@ -1,9 +1,9 @@
1
  <?php
2
-
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.
@@ -14,7 +14,7 @@
14
  * user the action is complete.
15
  *
16
  * <code>
17
- * $trData = Braintree_TransparentRedirect::createCustomerData(array(
18
  * 'redirectUrl => 'http://example.com/redirect_back_to_merchant_site',
19
  * ));
20
  * </code>
@@ -25,7 +25,7 @@
25
  * amount, include the amount in the trData.
26
  *
27
  * <code>
28
- * $trData = Braintree_TransparentRedirect::transactionData(array(
29
  * 'redirectUrl' => 'http://example.com/complete_transaction',
30
  * 'transaction' => array('amount' => '100.00'),
31
  * ));
@@ -34,9 +34,9 @@
34
  *
35
  * @package Braintree
36
  * @category Resources
37
- * @copyright 2014 Braintree, a division of PayPal, Inc.
38
  */
39
- class Braintree_TransparentRedirect
40
  {
41
  // Request Kinds
42
  const CREATE_TRANSACTION = 'create_transaction';
@@ -48,7 +48,7 @@ class Braintree_TransparentRedirect
48
  /**
49
  * @ignore
50
  * don't permit an explicit call of the constructor!
51
- * (like $t = new Braintree_TransparentRedirect())
52
  */
53
  protected function __construct()
54
  {
@@ -60,41 +60,42 @@ class Braintree_TransparentRedirect
60
 
61
  public static function confirm($queryString)
62
  {
63
- return Braintree_Configuration::gateway()->transparentRedirect()->confirm($queryString);
64
  }
65
 
66
  public static function createCreditCardData($params)
67
  {
68
- return Braintree_Configuration::gateway()->transparentRedirect()->createCreditCardData($params);
69
  }
70
 
71
  public static function createCustomerData($params)
72
  {
73
- return Braintree_Configuration::gateway()->transparentRedirect()->createCustomerData($params);
74
  }
75
 
76
  public static function url()
77
  {
78
- return Braintree_Configuration::gateway()->transparentRedirect()->url();
79
  }
80
 
81
  public static function transactionData($params)
82
  {
83
- return Braintree_Configuration::gateway()->transparentRedirect()->transactionData($params);
84
  }
85
 
86
  public static function updateCreditCardData($params)
87
  {
88
- return Braintree_Configuration::gateway()->transparentRedirect()->updateCreditCardData($params);
89
  }
90
 
91
  public static function updateCustomerData($params)
92
  {
93
- return Braintree_Configuration::gateway()->transparentRedirect()->updateCustomerData($params);
94
  }
95
 
96
  public static function parseAndValidateQueryString($queryString)
97
  {
98
- return Braintree_Configuration::gateway()->transparentRedirect()->parseAndValidateQueryString($queryString);
99
  }
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.
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>
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
  * ));
34
  *
35
  * @package Braintree
36
  * @category Resources
37
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
38
  */
39
+ class TransparentRedirect
40
  {
41
  // Request Kinds
42
  const CREATE_TRANSACTION = 'create_transaction';
48
  /**
49
  * @ignore
50
  * don't permit an explicit call of the constructor!
51
+ * (like $t = new TransparentRedirect())
52
  */
53
  protected function __construct()
54
  {
60
 
61
  public static function confirm($queryString)
62
  {
63
+ return Configuration::gateway()->transparentRedirect()->confirm($queryString);
64
  }
65
 
66
  public static function createCreditCardData($params)
67
  {
68
+ return Configuration::gateway()->transparentRedirect()->createCreditCardData($params);
69
  }
70
 
71
  public static function createCustomerData($params)
72
  {
73
+ return Configuration::gateway()->transparentRedirect()->createCustomerData($params);
74
  }
75
 
76
  public static function url()
77
  {
78
+ return Configuration::gateway()->transparentRedirect()->url();
79
  }
80
 
81
  public static function transactionData($params)
82
  {
83
+ return Configuration::gateway()->transparentRedirect()->transactionData($params);
84
  }
85
 
86
  public static function updateCreditCardData($params)
87
  {
88
+ return Configuration::gateway()->transparentRedirect()->updateCreditCardData($params);
89
  }
90
 
91
  public static function updateCustomerData($params)
92
  {
93
+ return Configuration::gateway()->transparentRedirect()->updateCustomerData($params);
94
  }
95
 
96
  public static function parseAndValidateQueryString($queryString)
97
  {
98
+ return Configuration::gateway()->transparentRedirect()->parseAndValidateQueryString($queryString);
99
  }
100
  }
101
+ class_alias('Braintree\TransparentRedirect', 'Braintree_TransparentRedirect');
braintree_sdk/lib/Braintree/TransparentRedirectGateway.php CHANGED
@@ -1,13 +1,19 @@
1
  <?php
 
 
 
 
 
 
2
  /**
3
  * Braintree Transparent Redirect Gateway module
4
  * Static class providing methods to build Transparent Redirect urls
5
  *
6
  * @package Braintree
7
  * @category Resources
8
- * @copyright 2014 Braintree, a division of PayPal, Inc.
9
  */
10
- class Braintree_TransparentRedirectGateway
11
  {
12
  private $_gateway;
13
  private $_config;
@@ -37,44 +43,44 @@ class Braintree_TransparentRedirectGateway
37
  public static function init()
38
  {
39
 
40
- self::$_createCustomerSignature = array(
41
  self::$_transparentRedirectKeys,
42
- array('customer' => Braintree_CustomerGateway::createSignature()),
43
- );
44
- self::$_updateCustomerSignature = array(
45
  self::$_transparentRedirectKeys,
46
  'customerId',
47
- array('customer' => Braintree_CustomerGateway::updateSignature()),
48
- );
49
- self::$_transactionSignature = array(
50
  self::$_transparentRedirectKeys,
51
- array('transaction' => Braintree_TransactionGateway::createSignature()),
52
- );
53
- self::$_createCreditCardSignature = array(
54
  self::$_transparentRedirectKeys,
55
- array('creditCard' => Braintree_CreditCardGateway::createSignature()),
56
- );
57
- self::$_updateCreditCardSignature = array(
58
  self::$_transparentRedirectKeys,
59
  'paymentMethodToken',
60
- array('creditCard' => Braintree_CreditCardGateway::updateSignature()),
61
- );
62
  }
63
 
64
  public function confirm($queryString)
65
  {
66
- $params = Braintree_TransparentRedirect::parseAndValidateQueryString(
67
  $queryString
68
  );
69
- $confirmationKlasses = array(
70
- Braintree_TransparentRedirect::CREATE_TRANSACTION => 'Braintree_TransactionGateway',
71
- Braintree_TransparentRedirect::CREATE_CUSTOMER => 'Braintree_CustomerGateway',
72
- Braintree_TransparentRedirect::UPDATE_CUSTOMER => 'Braintree_CustomerGateway',
73
- Braintree_TransparentRedirect::CREATE_PAYMENT_METHOD => 'Braintree_CreditCardGateway',
74
- Braintree_TransparentRedirect::UPDATE_PAYMENT_METHOD => 'Braintree_CreditCardGateway'
75
- );
76
  $confirmationGateway = new $confirmationKlasses[$params["kind"]]($this->_gateway);
77
- return $confirmationGateway->_doCreate('/transparent_redirect_requests/' . $params['id'] . '/confirm', array());
78
  }
79
 
80
  /**
@@ -84,11 +90,11 @@ class Braintree_TransparentRedirectGateway
84
  */
85
  public function createCreditCardData($params)
86
  {
87
- Braintree_Util::verifyKeys(
88
  self::$_createCreditCardSignature,
89
  $params
90
  );
91
- $params["kind"] = Braintree_TransparentRedirect::CREATE_PAYMENT_METHOD;
92
  return $this->_data($params);
93
  }
94
 
@@ -99,18 +105,18 @@ class Braintree_TransparentRedirectGateway
99
  */
100
  public function createCustomerData($params)
101
  {
102
- Braintree_Util::verifyKeys(
103
  self::$_createCustomerSignature,
104
  $params
105
  );
106
- $params["kind"] = Braintree_TransparentRedirect::CREATE_CUSTOMER;
107
  return $this->_data($params);
108
 
109
  }
110
 
111
  public function url()
112
  {
113
- return $this->_config->baseUrl() . $this->_config->merchantPath() . "/transparent_redirect_requests";
114
  }
115
 
116
  /**
@@ -120,15 +126,15 @@ class Braintree_TransparentRedirectGateway
120
  */
121
  public function transactionData($params)
122
  {
123
- Braintree_Util::verifyKeys(
124
  self::$_transactionSignature,
125
  $params
126
  );
127
- $params["kind"] = Braintree_TransparentRedirect::CREATE_TRANSACTION;
128
  $transactionType = isset($params['transaction']['type']) ?
129
  $params['transaction']['type'] :
130
  null;
131
- if ($transactionType != Braintree_Transaction::SALE && $transactionType != Braintree_Transaction::CREDIT) {
132
  throw new InvalidArgumentException(
133
  'expected transaction[type] of sale or credit, was: ' .
134
  $transactionType
@@ -144,7 +150,7 @@ class Braintree_TransparentRedirectGateway
144
  * The paymentMethodToken of the credit card to update is required.
145
  *
146
  * <code>
147
- * $trData = Braintree_TransparentRedirect::updateCreditCardData(array(
148
  * 'redirectUrl' => 'http://example.com/redirect_here',
149
  * 'paymentMethodToken' => 'token123',
150
  * ));
@@ -155,7 +161,7 @@ class Braintree_TransparentRedirectGateway
155
  */
156
  public function updateCreditCardData($params)
157
  {
158
- Braintree_Util::verifyKeys(
159
  self::$_updateCreditCardSignature,
160
  $params
161
  );
@@ -164,7 +170,7 @@ class Braintree_TransparentRedirectGateway
164
  'expected params to contain paymentMethodToken.'
165
  );
166
  }
167
- $params["kind"] = Braintree_TransparentRedirect::UPDATE_PAYMENT_METHOD;
168
  return $this->_data($params);
169
  }
170
 
@@ -174,7 +180,7 @@ class Braintree_TransparentRedirectGateway
174
  * The customerId of the customer to update is required.
175
  *
176
  * <code>
177
- * $trData = Braintree_TransparentRedirect::updateCustomerData(array(
178
  * 'redirectUrl' => 'http://example.com/redirect_here',
179
  * 'customerId' => 'customer123',
180
  * ));
@@ -185,7 +191,7 @@ class Braintree_TransparentRedirectGateway
185
  */
186
  public function updateCustomerData($params)
187
  {
188
- Braintree_Util::verifyKeys(
189
  self::$_updateCustomerSignature,
190
  $params
191
  );
@@ -194,7 +200,7 @@ class Braintree_TransparentRedirectGateway
194
  'expected params to contain customerId of customer to update'
195
  );
196
  }
197
- $params["kind"] = Braintree_TransparentRedirect::UPDATE_CUSTOMER;
198
  return $this->_data($params);
199
  }
200
 
@@ -204,7 +210,7 @@ class Braintree_TransparentRedirectGateway
204
  parse_str($queryString, $params);
205
  // remove the hash
206
  $queryStringWithoutHash = null;
207
- if(preg_match('/^(.*)&hash=[a-f0-9]+$/', $queryString, $match)) {
208
  $queryStringWithoutHash = $match[1];
209
  }
210
 
@@ -213,14 +219,14 @@ class Braintree_TransparentRedirectGateway
213
  if(array_key_exists('bt_message', $params)) {
214
  $message = $params['bt_message'];
215
  }
216
- Braintree_Util::throwStatusCodeException($params['http_status'], $message);
217
  }
218
 
219
  // recreate the hash and compare it
220
- if($this->_hash($queryStringWithoutHash) == $params['hash']) {
221
  return $params;
222
  } else {
223
- throw new Braintree_Exception_ForgedQueryString();
224
  }
225
  }
226
 
@@ -239,17 +245,17 @@ class Braintree_TransparentRedirectGateway
239
  $params = $this->_underscoreKeys($params);
240
  $now = new DateTime('now', new DateTimeZone('UTC'));
241
  $trDataParams = array_merge($params,
242
- array(
243
- 'api_version' => Braintree_Configuration::API_VERSION,
244
  'public_key' => $this->_config->publicKey(),
245
  'time' => $now->format('YmdHis'),
246
- )
247
  );
248
  ksort($trDataParams);
249
  $urlEncodedData = http_build_query($trDataParams, null, "&");
250
- $signatureService = new Braintree_SignatureService(
251
  $this->_config->privateKey(),
252
- "Braintree_Digest::hexDigestSha1"
253
  );
254
  return $signatureService->sign($urlEncodedData);
255
  }
@@ -258,7 +264,7 @@ class Braintree_TransparentRedirectGateway
258
  {
259
  foreach($array as $key=>$value)
260
  {
261
- $newKey = Braintree_Util::camelCaseToDelimiter($key, '_');
262
  unset($array[$key]);
263
  if (is_array($value))
264
  {
@@ -277,7 +283,8 @@ class Braintree_TransparentRedirectGateway
277
  */
278
  private function _hash($string)
279
  {
280
- return Braintree_Digest::hexDigestSha1($this->_config->privateKey(), $string);
281
  }
282
  }
283
- Braintree_TransparentRedirectGateway::init();
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
  */
16
+ class TransparentRedirectGateway
17
  {
18
  private $_gateway;
19
  private $_config;
43
  public static function init()
44
  {
45
 
46
+ self::$_createCustomerSignature = [
47
  self::$_transparentRedirectKeys,
48
+ ['customer' => CustomerGateway::createSignature()],
49
+ ];
50
+ self::$_updateCustomerSignature = [
51
  self::$_transparentRedirectKeys,
52
  'customerId',
53
+ ['customer' => CustomerGateway::updateSignature()],
54
+ ];
55
+ self::$_transactionSignature = [
56
  self::$_transparentRedirectKeys,
57
+ ['transaction' => TransactionGateway::createSignature()],
58
+ ];
59
+ self::$_createCreditCardSignature = [
60
  self::$_transparentRedirectKeys,
61
+ ['creditCard' => CreditCardGateway::createSignature()],
62
+ ];
63
+ self::$_updateCreditCardSignature = [
64
  self::$_transparentRedirectKeys,
65
  'paymentMethodToken',
66
+ ['creditCard' => CreditCardGateway::updateSignature()],
67
+ ];
68
  }
69
 
70
  public function confirm($queryString)
71
  {
72
+ $params = TransparentRedirect::parseAndValidateQueryString(
73
  $queryString
74
  );
75
+ $confirmationKlasses = [
76
+ TransparentRedirect::CREATE_TRANSACTION => 'Braintree\TransactionGateway',
77
+ TransparentRedirect::CREATE_CUSTOMER => 'Braintree\CustomerGateway',
78
+ TransparentRedirect::UPDATE_CUSTOMER => 'Braintree\CustomerGateway',
79
+ TransparentRedirect::CREATE_PAYMENT_METHOD => 'Braintree\CreditCardGateway',
80
+ TransparentRedirect::UPDATE_PAYMENT_METHOD => 'Braintree\CreditCardGateway',
81
+ ];
82
  $confirmationGateway = new $confirmationKlasses[$params["kind"]]($this->_gateway);
83
+ return $confirmationGateway->_doCreate('/transparent_redirect_requests/' . $params['id'] . '/confirm', []);
84
  }
85
 
86
  /**
90
  */
91
  public function createCreditCardData($params)
92
  {
93
+ Util::verifyKeys(
94
  self::$_createCreditCardSignature,
95
  $params
96
  );
97
+ $params["kind"] = TransparentRedirect::CREATE_PAYMENT_METHOD;
98
  return $this->_data($params);
99
  }
100
 
105
  */
106
  public function createCustomerData($params)
107
  {
108
+ Util::verifyKeys(
109
  self::$_createCustomerSignature,
110
  $params
111
  );
112
+ $params["kind"] = TransparentRedirect::CREATE_CUSTOMER;
113
  return $this->_data($params);
114
 
115
  }
116
 
117
  public function url()
118
  {
119
+ return $this->_config->baseUrl() . $this->_config->merchantPath() . '/transparent_redirect_requests';
120
  }
121
 
122
  /**
126
  */
127
  public function transactionData($params)
128
  {
129
+ Util::verifyKeys(
130
  self::$_transactionSignature,
131
  $params
132
  );
133
+ $params["kind"] = TransparentRedirect::CREATE_TRANSACTION;
134
  $transactionType = isset($params['transaction']['type']) ?
135
  $params['transaction']['type'] :
136
  null;
137
+ if ($transactionType != Transaction::SALE && $transactionType != Transaction::CREDIT) {
138
  throw new InvalidArgumentException(
139
  'expected transaction[type] of sale or credit, was: ' .
140
  $transactionType
150
  * The paymentMethodToken of the credit card to update is required.
151
  *
152
  * <code>
153
+ * $trData = TransparentRedirect::updateCreditCardData(array(
154
  * 'redirectUrl' => 'http://example.com/redirect_here',
155
  * 'paymentMethodToken' => 'token123',
156
  * ));
161
  */
162
  public function updateCreditCardData($params)
163
  {
164
+ Util::verifyKeys(
165
  self::$_updateCreditCardSignature,
166
  $params
167
  );
170
  'expected params to contain paymentMethodToken.'
171
  );
172
  }
173
+ $params["kind"] = TransparentRedirect::UPDATE_PAYMENT_METHOD;
174
  return $this->_data($params);
175
  }
176
 
180
  * The customerId of the customer to update is required.
181
  *
182
  * <code>
183
+ * $trData = TransparentRedirect::updateCustomerData(array(
184
  * 'redirectUrl' => 'http://example.com/redirect_here',
185
  * 'customerId' => 'customer123',
186
  * ));
191
  */
192
  public function updateCustomerData($params)
193
  {
194
+ Util::verifyKeys(
195
  self::$_updateCustomerSignature,
196
  $params
197
  );
200
  'expected params to contain customerId of customer to update'
201
  );
202
  }
203
+ $params["kind"] = TransparentRedirect::UPDATE_CUSTOMER;
204
  return $this->_data($params);
205
  }
206
 
210
  parse_str($queryString, $params);
211
  // remove the hash
212
  $queryStringWithoutHash = null;
213
+ if (preg_match('/^(.*)&hash=[a-f0-9]+$/', $queryString, $match)) {
214
  $queryStringWithoutHash = $match[1];
215
  }
216
 
219
  if(array_key_exists('bt_message', $params)) {
220
  $message = $params['bt_message'];
221
  }
222
+ Util::throwStatusCodeException(isset($params['http_status']) ? $params['http_status'] : null, $message);
223
  }
224
 
225
  // recreate the hash and compare it
226
+ if ($this->_hash($queryStringWithoutHash) == $params['hash']) {
227
  return $params;
228
  } else {
229
+ throw new Exception\ForgedQueryString();
230
  }
231
  }
232
 
245
  $params = $this->_underscoreKeys($params);
246
  $now = new DateTime('now', new DateTimeZone('UTC'));
247
  $trDataParams = array_merge($params,
248
+ [
249
+ 'api_version' => Configuration::API_VERSION,
250
  'public_key' => $this->_config->publicKey(),
251
  'time' => $now->format('YmdHis'),
252
+ ]
253
  );
254
  ksort($trDataParams);
255
  $urlEncodedData = http_build_query($trDataParams, null, "&");
256
+ $signatureService = new SignatureService(
257
  $this->_config->privateKey(),
258
+ "Braintree\Digest::hexDigestSha1"
259
  );
260
  return $signatureService->sign($urlEncodedData);
261
  }
264
  {
265
  foreach($array as $key=>$value)
266
  {
267
+ $newKey = Util::camelCaseToDelimiter($key, '_');
268
  unset($array[$key]);
269
  if (is_array($value))
270
  {
283
  */
284
  private function _hash($string)
285
  {
286
+ return Digest::hexDigestSha1($this->_config->privateKey(), $string);
287
  }
288
  }
289
+ TransparentRedirectGateway::init();
290
+ class_alias('Braintree\TransparentRedirectGateway', 'Braintree_TransparentRedirectGateway');
braintree_sdk/lib/Braintree/UnknownPaymentMethod.php CHANGED
@@ -1,10 +1,12 @@
1
  <?php
 
 
2
  /**
3
  * Braintree UnknownPaymentMethod module
4
  *
5
  * @package Braintree
6
  * @category Resources
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
 
10
  /**
@@ -15,21 +17,21 @@
15
  *
16
  * @package Braintree
17
  * @category Resources
18
- * @copyright 2014 Braintree, a division of PayPal, Inc.
19
  *
20
  * @property-read string $token
21
  * @property-read string $imageUrl
22
  */
23
- class Braintree_UnknownPaymentMethod extends Braintree_Base
24
  {
25
 
26
 
27
  /**
28
- * factory method: returns an instance of Braintree_UnknownPaymentMethod
29
  * to the requesting method, with populated properties
30
  *
31
  * @ignore
32
- * @return object instance of Braintree_UnknownPaymentMethod
33
  */
34
  public static function factory($attributes)
35
  {
@@ -56,7 +58,7 @@ class Braintree_UnknownPaymentMethod extends Braintree_Base
56
  *
57
  * @access protected
58
  * @param array $unknownPaymentMethodAttribs array of unknownPaymentMethod data
59
- * @return none
60
  */
61
  protected function _initialize($unknownPaymentMethodAttribs)
62
  {
@@ -66,3 +68,4 @@ class Braintree_UnknownPaymentMethod extends Braintree_Base
66
  }
67
 
68
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree UnknownPaymentMethod module
6
  *
7
  * @package Braintree
8
  * @category Resources
9
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
 
12
  /**
17
  *
18
  * @package Braintree
19
  * @category Resources
20
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
21
  *
22
  * @property-read string $token
23
  * @property-read string $imageUrl
24
  */
25
+ class UnknownPaymentMethod extends Base
26
  {
27
 
28
 
29
  /**
30
+ * factory method: returns an instance of UnknownPaymentMethod
31
  * to the requesting method, with populated properties
32
  *
33
  * @ignore
34
+ * @return UnknownPaymentMethod
35
  */
36
  public static function factory($attributes)
37
  {
58
  *
59
  * @access protected
60
  * @param array $unknownPaymentMethodAttribs array of unknownPaymentMethod data
61
+ * @return void
62
  */
63
  protected function _initialize($unknownPaymentMethodAttribs)
64
  {
68
  }
69
 
70
  }
71
+ class_alias('Braintree\UnknownPaymentMethod', 'Braintree_UnknownPaymentMethod');
braintree_sdk/lib/Braintree/Util.php CHANGED
@@ -1,28 +1,33 @@
1
  <?php
 
 
 
 
 
2
  /**
3
  * Braintree Utility methods
4
  * PHP version 5
5
  *
6
- * @copyright 2014 Braintree, a division of PayPal, Inc.
7
  */
8
 
9
- class Braintree_Util
10
  {
11
  /**
12
  * extracts an attribute and returns an array of objects
13
  *
14
  * extracts the requested element from an array, and converts the contents
15
- * of its child arrays to objects of type Braintree_$attributeName, or returns
16
  * an array with a single element containing the value of that array element
17
  *
18
- * @param array $attribArray attributes from a search response
19
  * @param string $attributeName indicates which element of the passed array to extract
20
- * @return array array of Braintree_$attributeName objects, or a single element array
21
  */
22
- public static function extractAttributeAsArray(& $attribArray, $attributeName)
23
  {
24
  if(!isset($attribArray[$attributeName])):
25
- return array();
26
  endif;
27
 
28
  // get what should be an array from the passed array
@@ -33,7 +38,7 @@ class Braintree_Util
33
  // create an object from the data in each element
34
  $objectArray = array_map($classFactory, $data);
35
  else:
36
- return array($data);
37
  endif;
38
 
39
  unset($attribArray[$attributeName]);
@@ -42,32 +47,33 @@ class Braintree_Util
42
  /**
43
  * throws an exception based on the type of error
44
  * @param string $statusCode HTTP status code to throw exception from
45
- * @throws Braintree_Exception multiple types depending on the error
46
- *
 
47
  */
48
  public static function throwStatusCodeException($statusCode, $message=null)
49
  {
50
  switch($statusCode) {
51
  case 401:
52
- throw new Braintree_Exception_Authentication();
53
  break;
54
  case 403:
55
- throw new Braintree_Exception_Authorization($message);
56
  break;
57
  case 404:
58
- throw new Braintree_Exception_NotFound();
59
  break;
60
  case 426:
61
- throw new Braintree_Exception_UpgradeRequired();
62
  break;
63
  case 500:
64
- throw new Braintree_Exception_ServerError();
65
  break;
66
  case 503:
67
- throw new Braintree_Exception_DownForMaintenance();
68
  break;
69
  default:
70
- throw new Braintree_Exception_Unexpected('Unexpected HTTP_RESPONSE #'.$statusCode);
71
  break;
72
  }
73
  }
@@ -77,82 +83,108 @@ class Braintree_Util
77
  * @param string $className
78
  * @param object $resultObj
79
  * @return object returns the passed object if successful
80
- * @throws Braintree_Exception_ValidationsFailed
81
  */
82
  public static function returnObjectOrThrowException($className, $resultObj)
83
  {
84
- $resultObjName = Braintree_Util::cleanClassName($className);
85
  if ($resultObj->success) {
86
  return $resultObj->$resultObjName;
87
  } else {
88
- throw new Braintree_Exception_ValidationsFailed();
89
  }
90
  }
91
 
92
  /**
93
- * removes the Braintree_ header from a classname
94
  *
95
- * @param string $name Braintree_ClassName
96
- * @return camelCased classname minus Braintree_ header
97
  */
98
  public static function cleanClassName($name)
99
  {
100
- $classNamesToResponseKeys = array(
101
- 'CreditCard' => 'creditCard',
102
- 'CreditCardGateway' => 'creditCard',
103
- 'Customer' => 'customer',
104
- 'CustomerGateway' => 'customer',
105
- 'Subscription' => 'subscription',
106
- 'SubscriptionGateway' => 'subscription',
107
- 'Transaction' => 'transaction',
108
- 'TransactionGateway' => 'transaction',
109
- 'CreditCardVerification' => 'verification',
110
- 'CreditCardVerificationGateway' => 'verification',
111
- 'AddOn' => 'addOn',
112
- 'AddOnGateway' => 'addOn',
113
- 'Discount' => 'discount',
114
- 'DiscountGateway' => 'discount',
115
- 'Plan' => 'plan',
116
- 'PlanGateway' => 'plan',
117
- 'Address' => 'address',
118
- 'AddressGateway' => 'address',
119
- 'SettlementBatchSummary' => 'settlementBatchSummary',
120
- 'SettlementBatchSummaryGateway' => 'settlementBatchSummary',
121
- 'Merchant' => 'merchant',
122
- 'MerchantGateway' => 'merchant',
123
- 'MerchantAccount' => 'merchantAccount',
124
- 'MerchantAccountGateway' => 'merchantAccount',
125
- 'OAuthCredentials' => 'credentials',
126
- 'PayPalAccount' => 'paypalAccount',
127
- 'PayPalAccountGateway' => 'paypalAccount'
128
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
- $name = str_replace('Braintree_', '', $name);
131
  return $classNamesToResponseKeys[$name];
132
  }
133
 
134
  /**
135
  *
136
  * @param string $name className
137
- * @return string Braintree_ClassName
138
  */
139
  public static function buildClassName($name)
140
  {
141
- $responseKeysToClassNames = array(
142
- 'creditCard' => 'CreditCard',
143
- 'customer' => 'Customer',
144
- 'subscription' => 'Subscription',
145
- 'transaction' => 'Transaction',
146
- 'verification' => 'CreditCardVerification',
147
- 'addOn' => 'AddOn',
148
- 'discount' => 'Discount',
149
- 'plan' => 'Plan',
150
- 'address' => 'Address',
151
- 'settlementBatchSummary' => 'SettlementBatchSummary',
152
- 'merchantAccount' => 'MerchantAccount'
153
- );
154
 
155
- return 'Braintree_' . $responseKeysToClassNames[$name];
156
  }
157
 
158
  /**
@@ -160,6 +192,7 @@ class Braintree_Util
160
  *
161
  * @access public
162
  * @param string $string
 
163
  * @return string modified string
164
  */
165
  public static function delimiterToCamelCase($string, $delimiter = '[\-\_]')
@@ -192,25 +225,18 @@ class Braintree_Util
192
  * find capitals and convert to delimiter + lowercase
193
  *
194
  * @access public
195
- * @param var $string
196
- * @return var modified string
 
197
  */
198
  public static function camelCaseToDelimiter($string, $delimiter = '-')
199
  {
200
- // php doesn't garbage collect functions created by create_function()
201
- // so use a static variable to avoid adding a new function to memory
202
- // every time this function is called.
203
- static $callbacks = array();
204
- if (!isset($callbacks[$delimiter])) {
205
- $callbacks[$delimiter] = create_function('$matches', "return '$delimiter' . strtolower(\$matches[1]);");
206
- }
207
-
208
- return preg_replace_callback('/([A-Z])/', $callbacks[$delimiter], $string);
209
  }
210
 
211
  public static function delimiterToCamelCaseArray($array, $delimiter = '[\-\_]')
212
  {
213
- $converted = array();
214
  foreach ($array as $key => $value) {
215
  if (is_string($key)) {
216
  $key = self::delimiterToCamelCase($key, $delimiter);
@@ -232,7 +258,7 @@ class Braintree_Util
232
 
233
  public static function camelCaseToDelimiterArray($array, $delimiter = '-')
234
  {
235
- $converted = array();
236
  foreach ($array as $key => $value) {
237
  if (is_string($key)) {
238
  $key = self::camelCaseToDelimiter($key, $delimiter);
@@ -247,7 +273,7 @@ class Braintree_Util
247
 
248
  public static function delimiterToUnderscoreArray($array)
249
  {
250
- $converted = array();
251
  foreach ($array as $key => $value) {
252
  $key = self::delimiterToUnderscore($key);
253
  $converted[$key] = $value;
@@ -260,6 +286,7 @@ class Braintree_Util
260
  * @param array $array associative array to implode
261
  * @param string $separator (optional, defaults to =)
262
  * @param string $glue (optional, defaults to ', ')
 
263
  */
264
  public static function implodeAssociativeArray($array, $separator = '=', $glue = ', ')
265
  {
@@ -276,10 +303,10 @@ class Braintree_Util
276
  }
277
 
278
  public static function attributesToString($attributes) {
279
- $printableAttribs = array();
280
  foreach ($attributes AS $key => $value) {
281
  if (is_array($value)) {
282
- $pAttrib = Braintree_Util::attributesToString($value);
283
  } else if ($value instanceof DateTime) {
284
  $pAttrib = $value->format(DateTime::RFC850);
285
  } else {
@@ -287,7 +314,7 @@ class Braintree_Util
287
  }
288
  $printableAttribs[$key] = sprintf('%s', $pAttrib);
289
  }
290
- return Braintree_Util::implodeAssociativeArray($printableAttribs);
291
  }
292
 
293
  /**
@@ -309,7 +336,7 @@ class Braintree_Util
309
  if(!empty($invalidKeys)) {
310
  asort($invalidKeys);
311
  $sortedList = join(', ', $invalidKeys);
312
- throw new InvalidArgumentException('invalid keys: '. $sortedList);
313
  }
314
  }
315
  /**
@@ -320,7 +347,7 @@ class Braintree_Util
320
  */
321
  private static function _flattenArray($keys, $namespace = null)
322
  {
323
- $flattenedArray = array();
324
  foreach($keys AS $key) {
325
  if(is_array($key)) {
326
  $theKeys = array_keys($key);
@@ -339,7 +366,7 @@ class Braintree_Util
339
 
340
  private static function _flattenUserKeys($keys, $namespace = null)
341
  {
342
- $flattenedArray = array();
343
 
344
  foreach($keys AS $key => $value) {
345
  $fullKey = empty($namespace) ? $key : $namespace;
@@ -381,3 +408,4 @@ class Braintree_Util
381
  return $invalidKeys;
382
  }
383
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
+ use DateTime;
5
+ use InvalidArgumentException;
6
+
7
  /**
8
  * Braintree Utility methods
9
  * PHP version 5
10
  *
11
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
12
  */
13
 
14
+ class Util
15
  {
16
  /**
17
  * extracts an attribute and returns an array of objects
18
  *
19
  * extracts the requested element from an array, and converts the contents
20
+ * of its child arrays to objects of type $attributeName, or returns
21
  * an array with a single element containing the value of that array element
22
  *
23
+ * @param array $attribArray attributes from a search response
24
  * @param string $attributeName indicates which element of the passed array to extract
25
+ * @return array array of $attributeName objects, or a single element array
26
  */
27
+ public static function extractAttributeAsArray(&$attribArray, $attributeName)
28
  {
29
  if(!isset($attribArray[$attributeName])):
30
+ return [];
31
  endif;
32
 
33
  // get what should be an array from the passed array
38
  // create an object from the data in each element
39
  $objectArray = array_map($classFactory, $data);
40
  else:
41
+ return [$data];
42
  endif;
43
 
44
  unset($attribArray[$attributeName]);
47
  /**
48
  * throws an exception based on the type of error
49
  * @param string $statusCode HTTP status code to throw exception from
50
+ * @param null|string $message
51
+ * @throws Exception multiple types depending on the error
52
+ * @return void
53
  */
54
  public static function throwStatusCodeException($statusCode, $message=null)
55
  {
56
  switch($statusCode) {
57
  case 401:
58
+ throw new Exception\Authentication();
59
  break;
60
  case 403:
61
+ throw new Exception\Authorization($message);
62
  break;
63
  case 404:
64
+ throw new Exception\NotFound();
65
  break;
66
  case 426:
67
+ throw new Exception\UpgradeRequired();
68
  break;
69
  case 500:
70
+ throw new Exception\ServerError();
71
  break;
72
  case 503:
73
+ throw new Exception\DownForMaintenance();
74
  break;
75
  default:
76
+ throw new Exception\Unexpected('Unexpected HTTP_RESPONSE #' . $statusCode);
77
  break;
78
  }
79
  }
83
  * @param string $className
84
  * @param object $resultObj
85
  * @return object returns the passed object if successful
86
+ * @throws Exception\ValidationsFailed
87
  */
88
  public static function returnObjectOrThrowException($className, $resultObj)
89
  {
90
+ $resultObjName = self::cleanClassName($className);
91
  if ($resultObj->success) {
92
  return $resultObj->$resultObjName;
93
  } else {
94
+ throw new Exception\ValidationsFailed();
95
  }
96
  }
97
 
98
  /**
99
+ * removes the header from a classname
100
  *
101
+ * @param string $name ClassName
102
+ * @return camelCased classname minus header
103
  */
104
  public static function cleanClassName($name)
105
  {
106
+ $classNamesToResponseKeys = [
107
+ 'Braintree\CreditCard' => 'creditCard',
108
+ 'Braintree_CreditCard' => 'creditCard',
109
+ 'Braintree\CreditCardGateway' => 'creditCard',
110
+ 'Braintree_CreditCardGateway' => 'creditCard',
111
+ 'Braintree\Customer' => 'customer',
112
+ 'Braintree_Customer' => 'customer',
113
+ 'Braintree\CustomerGateway' => 'customer',
114
+ 'Braintree_CustomerGateway' => 'customer',
115
+ 'Braintree\Subscription' => 'subscription',
116
+ 'Braintree_Subscription' => 'subscription',
117
+ 'Braintree\SubscriptionGateway' => 'subscription',
118
+ 'Braintree_SubscriptionGateway' => 'subscription',
119
+ 'Braintree\Transaction' => 'transaction',
120
+ 'Braintree_Transaction' => 'transaction',
121
+ 'Braintree\TransactionGateway' => 'transaction',
122
+ 'Braintree_TransactionGateway' => 'transaction',
123
+ 'Braintree\CreditCardVerification' => 'verification',
124
+ 'Braintree_CreditCardVerification' => 'verification',
125
+ 'Braintree\CreditCardVerificationGateway' => 'verification',
126
+ 'Braintree_CreditCardVerificationGateway' => 'verification',
127
+ 'Braintree\AddOn' => 'addOn',
128
+ 'Braintree_AddOn' => 'addOn',
129
+ 'Braintree\AddOnGateway' => 'addOn',
130
+ 'Braintree_AddOnGateway' => 'addOn',
131
+ 'Braintree\Discount' => 'discount',
132
+ 'Braintree_Discount' => 'discount',
133
+ 'Braintree\DiscountGateway' => 'discount',
134
+ 'Braintree_DiscountGateway' => 'discount',
135
+ 'Braintree\Plan' => 'plan',
136
+ 'Braintree_Plan' => 'plan',
137
+ 'Braintree\PlanGateway' => 'plan',
138
+ 'Braintree_PlanGateway' => 'plan',
139
+ 'Braintree\Address' => 'address',
140
+ 'Braintree_Address' => 'address',
141
+ 'Braintree\AddressGateway' => 'address',
142
+ 'Braintree_AddressGateway' => 'address',
143
+ 'Braintree\SettlementBatchSummary' => 'settlementBatchSummary',
144
+ 'Braintree_SettlementBatchSummary' => 'settlementBatchSummary',
145
+ 'Braintree\SettlementBatchSummaryGateway' => 'settlementBatchSummary',
146
+ 'Braintree_SettlementBatchSummaryGateway' => 'settlementBatchSummary',
147
+ 'Braintree\Merchant' => 'merchant',
148
+ 'Braintree_Merchant' => 'merchant',
149
+ 'Braintree\MerchantGateway' => 'merchant',
150
+ 'Braintree_MerchantGateway' => 'merchant',
151
+ 'Braintree\MerchantAccount' => 'merchantAccount',
152
+ 'Braintree_MerchantAccount' => 'merchantAccount',
153
+ 'Braintree\MerchantAccountGateway' => 'merchantAccount',
154
+ 'Braintree_MerchantAccountGateway' => 'merchantAccount',
155
+ 'Braintree\OAuthCredentials' => 'credentials',
156
+ 'Braintree_OAuthCredentials' => 'credentials',
157
+ 'Braintree\PayPalAccount' => 'paypalAccount',
158
+ 'Braintree_PayPalAccount' => 'paypalAccount',
159
+ 'Braintree\PayPalAccountGateway' => 'paypalAccount',
160
+ 'Braintree_PayPalAccountGateway' => 'paypalAccount',
161
+ ];
162
 
 
163
  return $classNamesToResponseKeys[$name];
164
  }
165
 
166
  /**
167
  *
168
  * @param string $name className
169
+ * @return string ClassName
170
  */
171
  public static function buildClassName($name)
172
  {
173
+ $responseKeysToClassNames = [
174
+ 'creditCard' => 'Braintree\CreditCard',
175
+ 'customer' => 'Braintree\Customer',
176
+ 'subscription' => 'Braintree\Subscription',
177
+ 'transaction' => 'Braintree\Transaction',
178
+ 'verification' => 'Braintree\CreditCardVerification',
179
+ 'addOn' => 'Braintree\AddOn',
180
+ 'discount' => 'Braintree\Discount',
181
+ 'plan' => 'Braintree\Plan',
182
+ 'address' => 'Braintree\Address',
183
+ 'settlementBatchSummary' => 'Braintree\SettlementBatchSummary',
184
+ 'merchantAccount' => 'Braintree\MerchantAccount',
185
+ ];
186
 
187
+ return (string) $responseKeysToClassNames[$name];
188
  }
189
 
190
  /**
192
  *
193
  * @access public
194
  * @param string $string
195
+ * @param null|string $delimiter
196
  * @return string modified string
197
  */
198
  public static function delimiterToCamelCase($string, $delimiter = '[\-\_]')
225
  * find capitals and convert to delimiter + lowercase
226
  *
227
  * @access public
228
+ * @param string $string
229
+ * @param null|string $delimiter
230
+ * @return string modified string
231
  */
232
  public static function camelCaseToDelimiter($string, $delimiter = '-')
233
  {
234
+ return strtolower(preg_replace('/([A-Z])/', "$delimiter\\1", $string));
 
 
 
 
 
 
 
 
235
  }
236
 
237
  public static function delimiterToCamelCaseArray($array, $delimiter = '[\-\_]')
238
  {
239
+ $converted = [];
240
  foreach ($array as $key => $value) {
241
  if (is_string($key)) {
242
  $key = self::delimiterToCamelCase($key, $delimiter);
258
 
259
  public static function camelCaseToDelimiterArray($array, $delimiter = '-')
260
  {
261
+ $converted = [];
262
  foreach ($array as $key => $value) {
263
  if (is_string($key)) {
264
  $key = self::camelCaseToDelimiter($key, $delimiter);
273
 
274
  public static function delimiterToUnderscoreArray($array)
275
  {
276
+ $converted = [];
277
  foreach ($array as $key => $value) {
278
  $key = self::delimiterToUnderscore($key);
279
  $converted[$key] = $value;
286
  * @param array $array associative array to implode
287
  * @param string $separator (optional, defaults to =)
288
  * @param string $glue (optional, defaults to ', ')
289
+ * @return bool
290
  */
291
  public static function implodeAssociativeArray($array, $separator = '=', $glue = ', ')
292
  {
303
  }
304
 
305
  public static function attributesToString($attributes) {
306
+ $printableAttribs = [];
307
  foreach ($attributes AS $key => $value) {
308
  if (is_array($value)) {
309
+ $pAttrib = self::attributesToString($value);
310
  } else if ($value instanceof DateTime) {
311
  $pAttrib = $value->format(DateTime::RFC850);
312
  } else {
314
  }
315
  $printableAttribs[$key] = sprintf('%s', $pAttrib);
316
  }
317
+ return self::implodeAssociativeArray($printableAttribs);
318
  }
319
 
320
  /**
336
  if(!empty($invalidKeys)) {
337
  asort($invalidKeys);
338
  $sortedList = join(', ', $invalidKeys);
339
+ throw new InvalidArgumentException('invalid keys: ' . $sortedList);
340
  }
341
  }
342
  /**
347
  */
348
  private static function _flattenArray($keys, $namespace = null)
349
  {
350
+ $flattenedArray = [];
351
  foreach($keys AS $key) {
352
  if(is_array($key)) {
353
  $theKeys = array_keys($key);
366
 
367
  private static function _flattenUserKeys($keys, $namespace = null)
368
  {
369
+ $flattenedArray = [];
370
 
371
  foreach($keys AS $key => $value) {
372
  $fullKey = empty($namespace) ? $key : $namespace;
408
  return $invalidKeys;
409
  }
410
  }
411
+ class_alias('Braintree\Util', 'Braintree_Util');
braintree_sdk/lib/Braintree/VenmoAccount.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
+ *
16
+ * @property-read string $createdAt
17
+ * @property-read string $default
18
+ * @property-read string $updatedAt
19
+ * @property-read string $customerId
20
+ * @property-read string $sourceDescription
21
+ * @property-read string $token
22
+ * @property-read string $imageUrl
23
+ * @property-read string $username
24
+ * @property-read string $venmoUserId
25
+ */
26
+ class VenmoAccount extends Base
27
+ {
28
+ /* instance methods */
29
+ /**
30
+ * returns false if default is null or false
31
+ *
32
+ * @return boolean
33
+ */
34
+ public function isDefault()
35
+ {
36
+ return $this->default;
37
+ }
38
+
39
+ /**
40
+ * factory method: returns an instance of VenmoAccount
41
+ * to the requesting method, with populated properties
42
+ *
43
+ * @ignore
44
+ * @return VenmoAccount
45
+ */
46
+ public static function factory($attributes)
47
+ {
48
+
49
+ $instance = new self();
50
+ $instance->_initialize($attributes);
51
+ return $instance;
52
+ }
53
+
54
+ /**
55
+ * sets instance properties from an array of values
56
+ *
57
+ * @access protected
58
+ * @param array $venmoAccountAttribs array of Venmo account properties
59
+ * @return void
60
+ */
61
+ protected function _initialize($venmoAccountAttribs)
62
+ {
63
+ $this->_attributes = $venmoAccountAttribs;
64
+
65
+ $subscriptionArray = array();
66
+ if (isset($venmoAccountAttribs['subscriptions'])) {
67
+ foreach ($venmoAccountAttribs['subscriptions'] AS $subscription) {
68
+ $subscriptionArray[] = Subscription::factory($subscription);
69
+ }
70
+ }
71
+
72
+ $this->_set('subscriptions', $subscriptionArray);
73
+ }
74
+ }
75
+ class_alias('Braintree\VenmoAccount', 'Braintree_VenmoAccount');
braintree_sdk/lib/Braintree/Version.php CHANGED
@@ -1,17 +1,19 @@
1
  <?php
 
 
2
  /**
3
  * Braintree Library Version
4
  * stores version information about the Braintree library
5
  *
6
- * @copyright 2014 Braintree, a division of PayPal, Inc.
7
  */
8
- final class Braintree_Version
9
  {
10
  /**
11
  * class constants
12
  */
13
  const MAJOR = 3;
14
- const MINOR = 5;
15
  const TINY = 0;
16
 
17
  /**
@@ -28,6 +30,7 @@ final class Braintree_Version
28
  */
29
  public static function get()
30
  {
31
- return self::MAJOR.'.'.self::MINOR.'.'.self::TINY;
32
  }
33
  }
 
1
  <?php
2
+ namespace Braintree;
3
+
4
  /**
5
  * Braintree Library Version
6
  * stores version information about the Braintree library
7
  *
8
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
9
  */
10
+ final class Version
11
  {
12
  /**
13
  * class constants
14
  */
15
  const MAJOR = 3;
16
+ const MINOR = 8;
17
  const TINY = 0;
18
 
19
  /**
30
  */
31
  public static function get()
32
  {
33
+ return self::MAJOR . '.' . self::MINOR . '.' . self::TINY;
34
  }
35
  }
36
+ class_alias('Braintree\Version', 'Braintree_Version');
braintree_sdk/lib/Braintree/WebhookNotification.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_WebhookNotification extends Braintree_Base
 
 
3
  {
4
  const SUBSCRIPTION_CANCELED = 'subscription_canceled';
5
  const SUBSCRIPTION_CHARGED_SUCCESSFULLY = 'subscription_charged_successfully';
@@ -19,29 +21,30 @@ class Braintree_WebhookNotification extends Braintree_Base
19
  const PARTNER_MERCHANT_CONNECTED = 'partner_merchant_connected';
20
  const PARTNER_MERCHANT_DISCONNECTED = 'partner_merchant_disconnected';
21
  const PARTNER_MERCHANT_DECLINED = 'partner_merchant_declined';
 
22
 
23
  public static function parse($signature, $payload)
24
  {
25
  if (preg_match("/[^A-Za-z0-9+=\/\n]/", $payload) === 1) {
26
- throw new Braintree_Exception_InvalidSignature("payload contains illegal characters");
27
  }
28
 
29
- Braintree_Configuration::assertGlobalHasAccessTokenOrKeys();
30
  self::_validateSignature($signature, $payload);
31
 
32
  $xml = base64_decode($payload);
33
- $attributes = Braintree_Xml::buildArrayFromXml($xml);
34
  return self::factory($attributes['notification']);
35
  }
36
 
37
  public static function verify($challenge)
38
  {
39
  if (!preg_match('/^[a-f0-9]{20,32}$/', $challenge)) {
40
- throw new Braintree_Exception_InvalidChallenge("challenge contains non-hex characters");
41
  }
42
- Braintree_Configuration::assertGlobalHasAccessTokenOrKeys();
43
- $publicKey = Braintree_Configuration::publicKey();
44
- $digest = Braintree_Digest::hexDigestSha1(Braintree_Configuration::privateKey(), $challenge);
45
  return "{$publicKey}|{$digest}";
46
  }
47
 
@@ -57,7 +60,7 @@ class Braintree_WebhookNotification extends Braintree_Base
57
  foreach ($signaturePairs as $pair)
58
  {
59
  $components = preg_split("/\|/", $pair);
60
- if ($components[0] == Braintree_Configuration::publicKey()) {
61
  return $components[1];
62
  }
63
  }
@@ -67,8 +70,8 @@ class Braintree_WebhookNotification extends Braintree_Base
67
 
68
  private static function _payloadMatches($signature, $payload)
69
  {
70
- $payloadSignature = Braintree_Digest::hexDigestSha1(Braintree_Configuration::privateKey(), $payload);
71
- return Braintree_Digest::secureCompare($signature, $payloadSignature);
72
  }
73
 
74
  private static function _validateSignature($signatureString, $payload)
@@ -76,11 +79,11 @@ class Braintree_WebhookNotification extends Braintree_Base
76
  $signaturePairs = preg_split("/&/", $signatureString);
77
  $signature = self::_matchingSignature($signaturePairs);
78
  if (!$signature) {
79
- throw new Braintree_Exception_InvalidSignature("no matching public key");
80
  }
81
 
82
  if (!(self::_payloadMatches($signature, $payload) || self::_payloadMatches($signature, $payload . "\n"))) {
83
- throw new Braintree_Exception_InvalidSignature("signature does not match payload - one has been modified");
84
  }
85
  }
86
 
@@ -95,32 +98,33 @@ class Braintree_WebhookNotification extends Braintree_Base
95
  }
96
 
97
  if (isset($wrapperNode['subscription'])) {
98
- $this->_set('subscription', Braintree_Subscription::factory($attributes['subject']['subscription']));
99
  }
100
 
101
  if (isset($wrapperNode['merchantAccount'])) {
102
- $this->_set('merchantAccount', Braintree_MerchantAccount::factory($wrapperNode['merchantAccount']));
103
  }
104
 
105
  if (isset($wrapperNode['transaction'])) {
106
- $this->_set('transaction', Braintree_Transaction::factory($wrapperNode['transaction']));
107
  }
108
 
109
  if (isset($wrapperNode['disbursement'])) {
110
- $this->_set('disbursement', Braintree_Disbursement::factory($wrapperNode['disbursement']));
111
  }
112
 
113
  if (isset($wrapperNode['partnerMerchant'])) {
114
- $this->_set('partnerMerchant', Braintree_PartnerMerchant::factory($wrapperNode['partnerMerchant']));
115
  }
116
 
117
  if (isset($wrapperNode['dispute'])) {
118
- $this->_set('dispute', Braintree_Dispute::factory($wrapperNode['dispute']));
119
  }
120
 
121
  if (isset($wrapperNode['errors'])) {
122
- $this->_set('errors', new Braintree_Error_ValidationErrorCollection($wrapperNode['errors']));
123
  $this->_set('message', $wrapperNode['message']);
124
  }
125
  }
126
  }
 
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';
21
  const PARTNER_MERCHANT_CONNECTED = 'partner_merchant_connected';
22
  const PARTNER_MERCHANT_DISCONNECTED = 'partner_merchant_disconnected';
23
  const PARTNER_MERCHANT_DECLINED = 'partner_merchant_declined';
24
+ const CHECK = 'check';
25
 
26
  public static function parse($signature, $payload)
27
  {
28
  if (preg_match("/[^A-Za-z0-9+=\/\n]/", $payload) === 1) {
29
+ throw new Exception\InvalidSignature("payload contains illegal characters");
30
  }
31
 
32
+ Configuration::assertGlobalHasAccessTokenOrKeys();
33
  self::_validateSignature($signature, $payload);
34
 
35
  $xml = base64_decode($payload);
36
+ $attributes = Xml::buildArrayFromXml($xml);
37
  return self::factory($attributes['notification']);
38
  }
39
 
40
  public static function verify($challenge)
41
  {
42
  if (!preg_match('/^[a-f0-9]{20,32}$/', $challenge)) {
43
+ throw new Exception\InvalidChallenge("challenge contains non-hex characters");
44
  }
45
+ Configuration::assertGlobalHasAccessTokenOrKeys();
46
+ $publicKey = Configuration::publicKey();
47
+ $digest = Digest::hexDigestSha1(Configuration::privateKey(), $challenge);
48
  return "{$publicKey}|{$digest}";
49
  }
50
 
60
  foreach ($signaturePairs as $pair)
61
  {
62
  $components = preg_split("/\|/", $pair);
63
+ if ($components[0] == Configuration::publicKey()) {
64
  return $components[1];
65
  }
66
  }
70
 
71
  private static function _payloadMatches($signature, $payload)
72
  {
73
+ $payloadSignature = Digest::hexDigestSha1(Configuration::privateKey(), $payload);
74
+ return Digest::secureCompare($signature, $payloadSignature);
75
  }
76
 
77
  private static function _validateSignature($signatureString, $payload)
79
  $signaturePairs = preg_split("/&/", $signatureString);
80
  $signature = self::_matchingSignature($signaturePairs);
81
  if (!$signature) {
82
+ throw new Exception\InvalidSignature("no matching public key");
83
  }
84
 
85
  if (!(self::_payloadMatches($signature, $payload) || self::_payloadMatches($signature, $payload . "\n"))) {
86
+ throw new Exception\InvalidSignature("signature does not match payload - one has been modified");
87
  }
88
  }
89
 
98
  }
99
 
100
  if (isset($wrapperNode['subscription'])) {
101
+ $this->_set('subscription', Subscription::factory($attributes['subject']['subscription']));
102
  }
103
 
104
  if (isset($wrapperNode['merchantAccount'])) {
105
+ $this->_set('merchantAccount', MerchantAccount::factory($wrapperNode['merchantAccount']));
106
  }
107
 
108
  if (isset($wrapperNode['transaction'])) {
109
+ $this->_set('transaction', Transaction::factory($wrapperNode['transaction']));
110
  }
111
 
112
  if (isset($wrapperNode['disbursement'])) {
113
+ $this->_set('disbursement', Disbursement::factory($wrapperNode['disbursement']));
114
  }
115
 
116
  if (isset($wrapperNode['partnerMerchant'])) {
117
+ $this->_set('partnerMerchant', PartnerMerchant::factory($wrapperNode['partnerMerchant']));
118
  }
119
 
120
  if (isset($wrapperNode['dispute'])) {
121
+ $this->_set('dispute', Dispute::factory($wrapperNode['dispute']));
122
  }
123
 
124
  if (isset($wrapperNode['errors'])) {
125
+ $this->_set('errors', new Error\ValidationErrorCollection($wrapperNode['errors']));
126
  $this->_set('message', $wrapperNode['message']);
127
  }
128
  }
129
  }
130
+ class_alias('Braintree\WebhookNotification', 'Braintree_WebhookNotification');
braintree_sdk/lib/Braintree/WebhookTesting.php CHANGED
@@ -1,53 +1,61 @@
1
  <?php
2
- class Braintree_WebhookTesting
 
 
3
  {
4
  public static function sampleNotification($kind, $id)
5
  {
6
  $payload = base64_encode(self::_sampleXml($kind, $id)) . "\n";
7
- $signature = Braintree_Configuration::publicKey() . "|" . Braintree_Digest::hexDigestSha1(Braintree_Configuration::privateKey(), $payload);
8
 
9
- return array(
10
  'bt_signature' => $signature,
11
  'bt_payload' => $payload
12
- );
13
  }
14
 
15
  private static function _sampleXml($kind, $id)
16
  {
17
  switch ($kind) {
18
- case Braintree_WebhookNotification::SUB_MERCHANT_ACCOUNT_APPROVED:
19
  $subjectXml = self::_merchantAccountApprovedSampleXml($id);
20
  break;
21
- case Braintree_WebhookNotification::SUB_MERCHANT_ACCOUNT_DECLINED:
22
  $subjectXml = self::_merchantAccountDeclinedSampleXml($id);
23
  break;
24
- case Braintree_WebhookNotification::TRANSACTION_DISBURSED:
25
  $subjectXml = self::_transactionDisbursedSampleXml($id);
26
  break;
27
- case Braintree_WebhookNotification::DISBURSEMENT_EXCEPTION:
28
  $subjectXml = self::_disbursementExceptionSampleXml($id);
29
  break;
30
- case Braintree_WebhookNotification::DISBURSEMENT:
31
  $subjectXml = self::_disbursementSampleXml($id);
32
  break;
33
- case Braintree_WebhookNotification::PARTNER_MERCHANT_CONNECTED:
34
  $subjectXml = self::_partnerMerchantConnectedSampleXml($id);
35
  break;
36
- case Braintree_WebhookNotification::PARTNER_MERCHANT_DISCONNECTED:
37
  $subjectXml = self::_partnerMerchantDisconnectedSampleXml($id);
38
  break;
39
- case Braintree_WebhookNotification::PARTNER_MERCHANT_DECLINED:
40
  $subjectXml = self::_partnerMerchantDeclinedSampleXml($id);
41
  break;
42
- case Braintree_WebhookNotification::DISPUTE_OPENED:
43
  $subjectXml = self::_disputeOpenedSampleXml($id);
44
  break;
45
- case Braintree_WebhookNotification::DISPUTE_LOST:
46
  $subjectXml = self::_disputeLostSampleXml($id);
47
  break;
48
- case Braintree_WebhookNotification::DISPUTE_WON:
49
  $subjectXml = self::_disputeWonSampleXml($id);
50
  break;
 
 
 
 
 
 
51
  default:
52
  $subjectXml = self::_subscriptionSampleXml($id);
53
  break;
@@ -176,6 +184,7 @@ class Braintree_WebhookTesting
176
  <currency-iso-code>USD</currency-iso-code>
177
  <received-date type=\"date\">2014-03-01</received-date>
178
  <reply-by-date type=\"date\">2014-03-21</reply-by-date>
 
179
  <status>open</status>
180
  <reason>fraud</reason>
181
  <id>${id}</id>
@@ -183,6 +192,7 @@ class Braintree_WebhookTesting
183
  <id>${id}</id>
184
  <amount>250.00</amount>
185
  </transaction>
 
186
  </dispute>
187
  ";
188
  }
@@ -195,6 +205,7 @@ class Braintree_WebhookTesting
195
  <currency-iso-code>USD</currency-iso-code>
196
  <received-date type=\"date\">2014-03-01</received-date>
197
  <reply-by-date type=\"date\">2014-03-21</reply-by-date>
 
198
  <status>lost</status>
199
  <reason>fraud</reason>
200
  <id>${id}</id>
@@ -202,6 +213,7 @@ class Braintree_WebhookTesting
202
  <id>${id}</id>
203
  <amount>250.00</amount>
204
  </transaction>
 
205
  </dispute>
206
  ";
207
  }
@@ -214,6 +226,7 @@ class Braintree_WebhookTesting
214
  <currency-iso-code>USD</currency-iso-code>
215
  <received-date type=\"date\">2014-03-01</received-date>
216
  <reply-by-date type=\"date\">2014-03-21</reply-by-date>
 
217
  <status>won</status>
218
  <reason>fraud</reason>
219
  <id>${id}</id>
@@ -221,6 +234,8 @@ class Braintree_WebhookTesting
221
  <id>${id}</id>
222
  <amount>250.00</amount>
223
  </transaction>
 
 
224
  </dispute>
225
  ";
226
  }
@@ -240,6 +255,32 @@ class Braintree_WebhookTesting
240
  ";
241
  }
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  private static function _partnerMerchantConnectedSampleXml($id)
244
  {
245
  return "
@@ -281,3 +322,4 @@ class Braintree_WebhookTesting
281
  return $timestamp;
282
  }
283
  }
 
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::DISBURSEMENT_EXCEPTION:
30
  $subjectXml = self::_disbursementExceptionSampleXml($id);
31
  break;
32
+ case WebhookNotification::DISBURSEMENT:
33
  $subjectXml = self::_disbursementSampleXml($id);
34
  break;
35
+ case WebhookNotification::PARTNER_MERCHANT_CONNECTED:
36
  $subjectXml = self::_partnerMerchantConnectedSampleXml($id);
37
  break;
38
+ case WebhookNotification::PARTNER_MERCHANT_DISCONNECTED:
39
  $subjectXml = self::_partnerMerchantDisconnectedSampleXml($id);
40
  break;
41
+ case WebhookNotification::PARTNER_MERCHANT_DECLINED:
42
  $subjectXml = self::_partnerMerchantDeclinedSampleXml($id);
43
  break;
44
+ case WebhookNotification::DISPUTE_OPENED:
45
  $subjectXml = self::_disputeOpenedSampleXml($id);
46
  break;
47
+ case WebhookNotification::DISPUTE_LOST:
48
  $subjectXml = self::_disputeLostSampleXml($id);
49
  break;
50
+ case WebhookNotification::DISPUTE_WON:
51
  $subjectXml = self::_disputeWonSampleXml($id);
52
  break;
53
+ case WebhookNotification::SUBSCRIPTION_CHARGED_SUCCESSFULLY:
54
+ $subjectXml = self::_subscriptionChargedSuccessfullySampleXml($id);
55
+ break;
56
+ case WebhookNotification::CHECK:
57
+ $subjectXml = self::_checkSampleXml();
58
+ break;
59
  default:
60
  $subjectXml = self::_subscriptionSampleXml($id);
61
  break;
184
  <currency-iso-code>USD</currency-iso-code>
185
  <received-date type=\"date\">2014-03-01</received-date>
186
  <reply-by-date type=\"date\">2014-03-21</reply-by-date>
187
+ <kind>chargeback</kind>
188
  <status>open</status>
189
  <reason>fraud</reason>
190
  <id>${id}</id>
192
  <id>${id}</id>
193
  <amount>250.00</amount>
194
  </transaction>
195
+ <date-opened type=\"date\">2014-03-21</date-opened>
196
  </dispute>
197
  ";
198
  }
205
  <currency-iso-code>USD</currency-iso-code>
206
  <received-date type=\"date\">2014-03-01</received-date>
207
  <reply-by-date type=\"date\">2014-03-21</reply-by-date>
208
+ <kind>chargeback</kind>
209
  <status>lost</status>
210
  <reason>fraud</reason>
211
  <id>${id}</id>
213
  <id>${id}</id>
214
  <amount>250.00</amount>
215
  </transaction>
216
+ <date-opened type=\"date\">2014-03-21</date-opened>
217
  </dispute>
218
  ";
219
  }
226
  <currency-iso-code>USD</currency-iso-code>
227
  <received-date type=\"date\">2014-03-01</received-date>
228
  <reply-by-date type=\"date\">2014-03-21</reply-by-date>
229
+ <kind>chargeback</kind>
230
  <status>won</status>
231
  <reason>fraud</reason>
232
  <id>${id}</id>
234
  <id>${id}</id>
235
  <amount>250.00</amount>
236
  </transaction>
237
+ <date-opened type=\"date\">2014-03-21</date-opened>
238
+ <date-won type=\"date\">2014-03-22</date-won>
239
  </dispute>
240
  ";
241
  }
255
  ";
256
  }
257
 
258
+ private static function _subscriptionChargedSuccessfullySampleXml($id)
259
+ {
260
+ return "
261
+ <subscription>
262
+ <id>{$id}</id>
263
+ <transactions type=\"array\">
264
+ <transaction>
265
+ <status>submitted_for_settlement</status>
266
+ <amount>49.99</amount>
267
+ </transaction>
268
+ </transactions>
269
+ <add_ons type=\"array\">
270
+ </add_ons>
271
+ <discounts type=\"array\">
272
+ </discounts>
273
+ </subscription>
274
+ ";
275
+ }
276
+
277
+ private static function _checkSampleXml()
278
+ {
279
+ return "
280
+ <check type=\"boolean\">true</check>
281
+ ";
282
+ }
283
+
284
  private static function _partnerMerchantConnectedSampleXml($id)
285
  {
286
  return "
322
  return $timestamp;
323
  }
324
  }
325
+ class_alias('Braintree\WebhookTesting', 'Braintree_WebhookTesting');
braintree_sdk/lib/Braintree/Xml.php CHANGED
@@ -1,12 +1,14 @@
1
  <?php
 
 
2
  /**
3
  * Braintree Xml parser and generator
4
  * PHP version 5
5
  * superclass for Braintree XML parsing and generation
6
  *
7
- * @copyright 2014 Braintree, a division of PayPal, Inc.
8
  */
9
- final class Braintree_Xml
10
  {
11
  /**
12
  * @ignore
@@ -23,7 +25,7 @@ final class Braintree_Xml
23
  */
24
  public static function buildArrayFromXml($xml)
25
  {
26
- return Braintree_Xml_Parser::arrayFromXml($xml);
27
  }
28
 
29
  /**
@@ -33,6 +35,7 @@ final class Braintree_Xml
33
  */
34
  public static function buildXmlFromArray($array)
35
  {
36
- return Braintree_Xml_Generator::arrayToXml($array);
37
  }
38
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
10
  */
11
+ final class Xml
12
  {
13
  /**
14
  * @ignore
25
  */
26
  public static function buildArrayFromXml($xml)
27
  {
28
+ return Xml\Parser::arrayFromXml($xml);
29
  }
30
 
31
  /**
35
  */
36
  public static function buildXmlFromArray($array)
37
  {
38
+ return Xml\Generator::arrayToXml($array);
39
  }
40
  }
41
+ class_alias('Braintree\Xml', 'Braintree_Xml');
braintree_sdk/lib/Braintree/Xml/Generator.php CHANGED
@@ -1,27 +1,34 @@
1
  <?php
 
 
 
 
 
 
 
2
  /**
3
  * PHP version 5
4
  *
5
- * @copyright 2014 Braintree, a division of PayPal, Inc.
6
  */
7
 
8
  /**
9
  * Generates XML output from arrays using PHP's
10
  * built-in XMLWriter
11
  *
12
- * @copyright 2014 Braintree, a division of PayPal, Inc.
13
  */
14
- class Braintree_Xml_Generator
15
  {
16
  /**
17
  * arrays passed to this method should have a single root element
18
  * with an array as its value
19
  * @param array $aData the array of data
20
- * @return var XML string
21
  */
22
  public static function arrayToXml($aData)
23
  {
24
- $aData = Braintree_Util::camelCaseToDelimiterArray($aData, '-');
25
  // set up the XMLWriter
26
  $writer = new XMLWriter();
27
  $writer->openMemory();
@@ -53,7 +60,7 @@ class Braintree_Xml_Generator
53
  * @static
54
  * @param object $writer XMLWriter object
55
  * @param array $aData contains attributes and values
56
- * @return none
57
  */
58
  private static function _createElementsFromArray(&$writer, $aData)
59
  {
@@ -103,23 +110,23 @@ class Braintree_Xml_Generator
103
  private static function _generateXmlAttribute($value)
104
  {
105
  if ($value instanceof DateTime) {
106
- return array('type', 'datetime', self::_dateTimeToXmlTimestamp($value));
107
  }
108
  if (is_int($value)) {
109
- return array('type', 'integer', $value);
110
  }
111
  if (is_bool($value)) {
112
- return array('type', 'boolean', ($value ? 'true' : 'false'));
113
  }
114
  if ($value === NULL) {
115
- return array('nil', 'true', $value);
116
  }
117
  }
118
  /**
119
  * converts datetime back to xml schema format
120
  * @access protected
121
  * @param object $dateTime
122
- * @return var XML schema formatted timestamp
123
  */
124
  private static function _dateTimeToXmlTimestamp($dateTime)
125
  {
@@ -141,3 +148,4 @@ class Braintree_Xml_Generator
141
  }
142
  }
143
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
13
  */
14
 
15
  /**
16
  * Generates XML output from arrays using PHP's
17
  * built-in XMLWriter
18
  *
19
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
20
  */
21
+ class Generator
22
  {
23
  /**
24
  * arrays passed to this method should have a single root element
25
  * with an array as its value
26
  * @param array $aData the array of data
27
+ * @return string XML string
28
  */
29
  public static function arrayToXml($aData)
30
  {
31
+ $aData = Util::camelCaseToDelimiterArray($aData, '-');
32
  // set up the XMLWriter
33
  $writer = new XMLWriter();
34
  $writer->openMemory();
60
  * @static
61
  * @param object $writer XMLWriter object
62
  * @param array $aData contains attributes and values
63
+ * @return void
64
  */
65
  private static function _createElementsFromArray(&$writer, $aData)
66
  {
110
  private static function _generateXmlAttribute($value)
111
  {
112
  if ($value instanceof DateTime) {
113
+ return ['type', 'datetime', self::_dateTimeToXmlTimestamp($value)];
114
  }
115
  if (is_int($value)) {
116
+ return ['type', 'integer', $value];
117
  }
118
  if (is_bool($value)) {
119
+ return ['type', 'boolean', ($value ? 'true' : 'false')];
120
  }
121
  if ($value === NULL) {
122
+ return ['nil', 'true', $value];
123
  }
124
  }
125
  /**
126
  * converts datetime back to xml schema format
127
  * @access protected
128
  * @param object $dateTime
129
+ * @return string XML schema formatted timestamp
130
  */
131
  private static function _dateTimeToXmlTimestamp($dateTime)
132
  {
148
  }
149
  }
150
  }
151
+ class_alias('Braintree\Xml\Generator', 'Braintree_Xml_Generator');
braintree_sdk/lib/Braintree/Xml/Parser.php CHANGED
@@ -1,11 +1,19 @@
1
  <?php
 
 
 
 
 
 
 
 
2
 
3
  /**
4
  * Braintree XML Parser
5
  *
6
- * @copyright 2014 Braintree, a division of PayPal, Inc.
7
  */
8
- class Braintree_Xml_Parser
9
  {
10
  /**
11
  * Converts an XML string into a multidimensional array
@@ -20,9 +28,9 @@ class Braintree_Xml_Parser
20
 
21
  $root = $document->documentElement->nodeName;
22
 
23
- return Braintree_Util::delimiterToCamelCaseArray(array(
24
  $root => self::_nodeToValue($document->childNodes->item(0)),
25
- ));
26
  }
27
 
28
  /**
@@ -40,7 +48,7 @@ class Braintree_Xml_Parser
40
 
41
  switch($type) {
42
  case 'array':
43
- $array = array();
44
  foreach ($node->childNodes as $child) {
45
  $value = self::_nodeToValue($child);
46
  if ($value !== null) {
@@ -49,19 +57,19 @@ class Braintree_Xml_Parser
49
  }
50
  return $array;
51
  case 'collection':
52
- $collection = array();
53
  foreach ($node->childNodes as $child) {
54
  $value = self::_nodetoValue($child);
55
  if ($value !== null) {
56
  if (!isset($collection[$child->nodeName])) {
57
- $collection[$child->nodeName] = array();
58
  }
59
  $collection[$child->nodeName][] = self::_nodeToValue($child);
60
  }
61
  }
62
  return $collection;
63
  default:
64
- $values = array();
65
  if ($node->childNodes->length === 1 && $node->childNodes->item(0) instanceof DOMText) {
66
  return $node->childNodes->item(0)->nodeValue;
67
  } else {
@@ -131,3 +139,4 @@ class Braintree_Xml_Parser
131
  return $dateTime;
132
  }
133
  }
 
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
+ * @copyright 2015 Braintree, a division of PayPal, Inc.
15
  */
16
+ class Parser
17
  {
18
  /**
19
  * Converts an XML string into a multidimensional array
28
 
29
  $root = $document->documentElement->nodeName;
30
 
31
+ return Util::delimiterToCamelCaseArray([
32
  $root => self::_nodeToValue($document->childNodes->item(0)),
33
+ ]);
34
  }
35
 
36
  /**
48
 
49
  switch($type) {
50
  case 'array':
51
+ $array = [];
52
  foreach ($node->childNodes as $child) {
53
  $value = self::_nodeToValue($child);
54
  if ($value !== null) {
57
  }
58
  return $array;
59
  case 'collection':
60
+ $collection = [];
61
  foreach ($node->childNodes as $child) {
62
  $value = self::_nodetoValue($child);
63
  if ($value !== null) {
64
  if (!isset($collection[$child->nodeName])) {
65
+ $collection[$child->nodeName] = [];
66
  }
67
  $collection[$child->nodeName][] = self::_nodeToValue($child);
68
  }
69
  }
70
  return $collection;
71
  default:
72
+ $values = [];
73
  if ($node->childNodes->length === 1 && $node->childNodes->item(0) instanceof DOMText) {
74
  return $node->childNodes->item(0)->nodeValue;
75
  } else {
139
  return $dateTime;
140
  }
141
  }
142
+ class_alias('Braintree\Xml\Parser', 'Braintree_Xml_Parser');
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
+ });
braintree_sdk/lib/ssl/api_braintreegateway_com.ca.crt CHANGED
@@ -1,68 +1,4 @@
1
  -----BEGIN CERTIFICATE-----
2
- MIIDAjCCAmsCEH3Z/gfPqB63EHln+6eJNMYwDQYJKoZIhvcNAQEFBQAwgcExCzAJ
3
- BgNVBAYTAlVTMRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xh
4
- c3MgMyBQdWJsaWMgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcy
5
- MTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3Jp
6
- emVkIHVzZSBvbmx5MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMB4X
7
- DTk4MDUxODAwMDAwMFoXDTI4MDgwMTIzNTk1OVowgcExCzAJBgNVBAYTAlVTMRcw
8
- FQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgMyBQdWJsaWMg
9
- UHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEo
10
- YykgMTk5OCBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5
11
- MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMIGfMA0GCSqGSIb3DQEB
12
- AQUAA4GNADCBiQKBgQDMXtERXVxp0KvTuWpMmR9ZmDCOFoUgRm1HP9SFIIThbbP4
13
- pO0M8RcPO/mn+SXXwc+EY/J8Y8+iR/LGWzOOZEAEaMGAuWQcRXfH2G71lSk8UOg0
14
- 13gfqLptQ5GVj0VXXn7F+8qkBOvqlzdUMG+7AUcyM83cV5tkaWH4mx0ciU9cZwID
15
- AQABMA0GCSqGSIb3DQEBBQUAA4GBAFFNzb5cy5gZnBWyATl4Lk0PZ3BwmcYQWpSk
16
- U01UbSuvDV1Ai2TT1+7eVmGSX6bEHRBhNtMsJzzoKQm5EWR0zLVznxxIqbxhAe7i
17
- F6YM40AIOw7n60RzKprxaZLvcRTDOaxxp5EJb+RxBrO6WVcmeQD2+A2iMzAo1KpY
18
- oJ2daZH9
19
- -----END CERTIFICATE-----
20
- -----BEGIN CERTIFICATE-----
21
- MIIEGjCCAwICEQCbfgZJoz5iudXukEhxKe9XMA0GCSqGSIb3DQEBBQUAMIHKMQsw
22
- CQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZl
23
- cmlTaWduIFRydXN0IE5ldHdvcmsxOjA4BgNVBAsTMShjKSAxOTk5IFZlcmlTaWdu
24
- LCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxRTBDBgNVBAMTPFZlcmlT
25
- aWduIENsYXNzIDMgUHVibGljIFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3Jp
26
- dHkgLSBHMzAeFw05OTEwMDEwMDAwMDBaFw0zNjA3MTYyMzU5NTlaMIHKMQswCQYD
27
- VQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlT
28
- aWduIFRydXN0IE5ldHdvcmsxOjA4BgNVBAsTMShjKSAxOTk5IFZlcmlTaWduLCBJ
29
- bmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxRTBDBgNVBAMTPFZlcmlTaWdu
30
- IENsYXNzIDMgUHVibGljIFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkg
31
- LSBHMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMu6nFL8eB8aHm8b
32
- N3O9+MlrlBIwT/A2R/XQkQr1F8ilYcEWQE37imGQ5XYgwREGfassbqb1EUGO+i2t
33
- KmFZpGcmTNDovFJbcCAEWNF6yaRpvIMXZK0Fi7zQWM6NjPXr8EJJC52XJ2cybuGu
34
- kxUccLwgTS8Y3pKI6GyFVxEa6X7jJhFUokWWVYPKMIno3Nij7SqAP395ZVc+FSBm
35
- CC+Vk7+qRy+oRpfwEuL+wgorUeZ25rdGt+INpsyow0xZVYnm6FNcHOqd8GIWC6fJ
36
- Xwzw3sJ2zq/3avL6QaaiMxTJ5Xpj055iN9WFZZ4O5lMkdBteHRJTW8cs54NJOxWu
37
- imi5V5cCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAERSWwauSCPc/L8my/uRan2Te
38
- 2yFPhpk0djZX3dAVL8WtfxUfN2JzPtTnX84XA9s1+ivbrmAJXx5fj267Cz3qWhMe
39
- DGBvtcC1IyIuBwvLqXTLR7sdwdela8wv0kL9Sd2nic9TutoAWii/gt/4uhMdUIaC
40
- /Y4wjylGsB49Ndo4YhYYSq3mtlFs3q9i6wHQHiT+eo8SGhJouPtmmRQURVyu565p
41
- F4ErWjfJXir0xuKhXFSbplQAz/DxwceYMBo7Nhbbo27q/a2ywtrvAkcTisDxszGt
42
- TxzhT5yvDwyd93gN2PQ1VoDat20Xj50egWTh/sVFuq1ruQp6Tk9LhO5L8X3dEQ==
43
- -----END CERTIFICATE-----
44
- -----BEGIN CERTIFICATE-----
45
- MIIDhDCCAwqgAwIBAgIQL4D+I4wOIg9IZxIokYesszAKBggqhkjOPQQDAzCByjEL
46
- MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZW
47
- ZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNyBWZXJpU2ln
48
- biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJp
49
- U2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9y
50
- aXR5IC0gRzQwHhcNMDcxMTA1MDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCByjELMAkG
51
- A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJp
52
- U2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNyBWZXJpU2lnbiwg
53
- SW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJpU2ln
54
- biBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5
55
- IC0gRzQwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAASnVnp8Utpkmw4tXNherJI9/gHm
56
- GUo9FANL+mAnINmDiWn6VMaaGF5VKmTeBvaNSjutEDxlPZCIBIngMGGzrl0Bp3ve
57
- fLK+ymVhAIau2o970ImtTR1ZmkGxvEeA3J5iw/mjgbIwga8wDwYDVR0TAQH/BAUw
58
- AwEB/zAOBgNVHQ8BAf8EBAMCAQYwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJ
59
- aW1hZ2UvZ2lmMCEwHzAHBgUrDgMCGgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYj
60
- aHR0cDovL2xvZ28udmVyaXNpZ24uY29tL3ZzbG9nby5naWYwHQYDVR0OBBYEFLMW
61
- kf3upm7ktS5Jj4d4gYDs5bG1MAoGCCqGSM49BAMDA2gAMGUCMGYhDBgmYFo4e1ZC
62
- 4Kf8NoRRkSAsdk1DPcQdhCPQrNZ8NQbOzWm9kA3bbEhCHQ6qQgIxAJw9SDkjOVga
63
- FRJZap7v1VmyHVIsmXHNxynfGyphe3HR3vPA5Q06Sqotp9iGKt0uEA==
64
- -----END CERTIFICATE-----
65
- -----BEGIN CERTIFICATE-----
66
  MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB
67
  yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
68
  ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp
@@ -91,20 +27,6 @@ WE9gyn6CagsCqiUXObXbf+eEZSqVir2G3l6BFoMtEMze/aiCKm0oHw0LxOXnGiYZ
91
  hnacRHr2lVz2XTIIM6RUthg/aFzyQkqFOFSDX9HoLPKsEdao7WNq
92
  -----END CERTIFICATE-----
93
  -----BEGIN CERTIFICATE-----
94
- MIICPDCCAaUCEDyRMcsf9tAbDpq40ES/Er4wDQYJKoZIhvcNAQEFBQAwXzELMAkG
95
- A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz
96
- cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2
97
- MDEyOTAwMDAwMFoXDTI4MDgwMjIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV
98
- BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt
99
- YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN
100
- ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE
101
- BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is
102
- I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G
103
- CSqGSIb3DQEBBQUAA4GBABByUqkFFBkyCEHwxWsKzH4PIRnN5GfcX6kb5sroc50i
104
- 2JhucwNhkcV8sEVAbkSdjbCxlnRhLQ2pRdKkkirWmnWXbj9T/UWZYB2oK0z5XqcJ
105
- 2HUw19JlYD1n1khVdWk/kfVIC0dpImmClr7JyDiGSnoscxlIaU5rfGW/D/xwzoiQ
106
- -----END CERTIFICATE-----
107
- -----BEGIN CERTIFICATE-----
108
  MIIDuDCCAqCgAwIBAgIQDPCOXAgWpa1Cf/DrJxhZ0DANBgkqhkiG9w0BAQUFADBI
109
  MQswCQYDVQQGEwJVUzEgMB4GA1UEChMXU2VjdXJlVHJ1c3QgQ29ycG9yYXRpb24x
110
  FzAVBgNVBAMTDlNlY3VyZVRydXN0IENBMB4XDTA2MTEwNzE5MzExOFoXDTI5MTIz
@@ -150,35 +72,71 @@ LPAvTK33sefOT6jEm0pUBsV/fdUID+Ic/n4XuKxe9tQWskMJDE32p2u0mYRlynqI
150
  4uJEvlz36hz1
151
  -----END CERTIFICATE-----
152
  -----BEGIN CERTIFICATE-----
153
- MIIFbDCCA1SgAwIBAgIBATANBgkqhkiG9w0BAQUFADBHMQswCQYDVQQGEwJVUzEW
154
- MBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEgMB4GA1UEAxMXR2VvVHJ1c3QgVW5pdmVy
155
- c2FsIENBIDIwHhcNMDQwMzA0MDUwMDAwWhcNMjkwMzA0MDUwMDAwWjBHMQswCQYD
156
- VQQGEwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEgMB4GA1UEAxMXR2VvVHJ1
157
- c3QgVW5pdmVyc2FsIENBIDIwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoIC
158
- AQCzVFLByT7y2dyxUxpZKeexw0Uo5dfR7cXFS6GqdHtXr0om/Nj1XqduGdt0DE81
159
- WzILAePb63p3NeqqWuDW6KFXlPCQo3RWlEQwAx5cTiuFJnSCegx2oG9NzkEtoBUG
160
- FF+3Qs17j1hhNNwqCPkuwwGmIkQcTAeC5lvO0Ep8BNMZcyfwqph/Lq9O64ceJHdq
161
- XbboW0W63MOhBW9Wjo8QJqVJwy7XQYci4E+GymC16qFjwAGXEHm9ADwSbSsVsaxL
162
- se4YuU6W3Nx2/zu+z18DwPw76L5GG//aQMJS9/7jOvdqdzXQ2o3rXhhqMcceujwb
163
- KNZrVMaqW9eiLBsZzKIC9ptZvTdrhrVtgrrY6slWvKk2WP0+GfPtDCapkzj4T8Fd
164
- IgbQl+rhrcZV4IErKIM6+vR7IVEAvlI4zs1meaj0gVbi0IMJR1FbUGrP20gaXT73
165
- y/Zl92zxlfgCOzJWgjl6W70viRu/obTo/3+NjN8D8WBOWBFM66M/ECuDmgFz2ZRt
166
- hAAnZqzwcEAJQpKtT5MNYQlRJNiS1QuUYbKHsu3/mjX/hVTK7URDrBs8FmtISgoc
167
- QIgfksILAAX/8sgCSqSqqcyZlpwvWOB94b67B9xfBHJcMTTD7F8t4D1kkCLm0ey4
168
- Lt1ZrtmhN79UNdxzMk+MBB4zsslG8dhcyFVQyWi9qLo2CQIDAQABo2MwYTAPBgNV
169
- HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR281Xh+qQ2+/CfXGJx7Tz0RzgQKzAfBgNV
170
- HSMEGDAWgBR281Xh+qQ2+/CfXGJx7Tz0RzgQKzAOBgNVHQ8BAf8EBAMCAYYwDQYJ
171
- KoZIhvcNAQEFBQADggIBAGbBxiPz2eAubl/oz66wsCVNK/g7WJtAJDday6sWSf+z
172
- dXkzoS9tcBc0kf5nfo/sm+VegqlVHy/c1FEHEv6sFj4sNcZj/NwQ6w2jqtB8zNHQ
173
- L1EuxBRa3ugZ4T7GzKQp5y6EqgYweHZUcyiYWTjgAA1i00J9IZ+uPTqM1fp3DRgr
174
- Fg5fNuH8KrUwJM/gYwx7WBr+mbpCErGR9Hxo4sjoryzqyX6uuyo9DRXcNJW2GHSo
175
- ag/HtPQTxORb7QrSpJdMKu0vbBKJPfEncKpqA1Ihn0CoZ1Dy81of398j9tx4TuaY
176
- T1U6U+Pv8vSfx3zYWK8pIpe44L2RLrB27FcRz+8pRPPphXpgY+RdM4kX2TGq2tbz
177
- GDVyz4crL2MjhF2EjD9XoIj8mZEoJmmZ1I+XRL6O1UixpCgp8RW04eWe3fiPpm8m
178
- 1wk8OhwRDqZsN/etRIcsKMfYdIKz0G9KV7s1KSegi+ghp4dkNl3M2Basx7InQJJV
179
- OCiNUW7dFGdTbHFcJoRNdVq2fmBWqU2t+5sel/MN2dKXVHfaPRK34B7vCAas+YWH
180
- 6aLcr34YEoP9VhdBLtUpgn2Z9DH2canPLAEnpQW5qrJITirvn5NSUZU8UnOOVkwX
181
- QMAJKOSLakhT2+zNVVXxxvjpoixMptEmX36vWkzaH6byHCx+rgIW0lbQL1dTR+iS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  -----END CERTIFICATE-----
183
  -----BEGIN CERTIFICATE-----
184
  MIIFaDCCA1CgAwIBAgIBATANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJVUzEW
@@ -212,27 +170,6 @@ DF4JbAiXfKM9fJP/P6EUp8+1Xevb2xzEdt+Iub1FBZUbrvxGakyvSOPOrg/Sfuvm
212
  bJxPgWp6ZKy7PtXny3YuxadIwVyQD8vIP/rmMuGNG2+k5o7Y+SlIis5z/iw=
213
  -----END CERTIFICATE-----
214
  -----BEGIN CERTIFICATE-----
215
- MIIDZjCCAk6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBEMQswCQYDVQQGEwJVUzEW
216
- MBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEdMBsGA1UEAxMUR2VvVHJ1c3QgR2xvYmFs
217
- IENBIDIwHhcNMDQwMzA0MDUwMDAwWhcNMTkwMzA0MDUwMDAwWjBEMQswCQYDVQQG
218
- EwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjEdMBsGA1UEAxMUR2VvVHJ1c3Qg
219
- R2xvYmFsIENBIDIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDvPE1A
220
- PRDfO1MA4Wf+lGAVPoWI8YkNkMgoI5kF6CsgncbzYEbYwbLVjDHZ3CB5JIG/NTL8
221
- Y2nbsSpr7iFY8gjpeMtvy/wWUsiRxP89c96xPqfCfWbB9X5SJBri1WeR0IIQ13hL
222
- TytCOb1kLUCgsBDTOEhGiKEMuzozKmKY+wCdE1l/bztyqu6mD4b5BWHqZ38MN5aL
223
- 5mkWRxHCJ1kDs6ZgwiFAVvqgx306E+PsV8ez1q6diYD3Aecs9pYrEw15LNnA5IZ7
224
- S4wMcoKK+xfNAGw6EzywhIdLFnopsk/bHdQL82Y3vdj2V7teJHq4PIu5+pIaGoSe
225
- 2HSPqht/XvT+RSIhAgMBAAGjYzBhMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYE
226
- FHE4NvICMVNHK266ZUapEBVYIAUJMB8GA1UdIwQYMBaAFHE4NvICMVNHK266ZUap
227
- EBVYIAUJMA4GA1UdDwEB/wQEAwIBhjANBgkqhkiG9w0BAQUFAAOCAQEAA/e1K6td
228
- EPx7srJerJsOflN4WT5CBP51o62sgU7XAotexC3IUnbHLB/8gTKY0UvGkpMzNTEv
229
- /NgdRN3ggX+d6YvhZJFiCzkIjKx0nVnZellSlxG5FntvRdOW2TF9AjYPnDtuzywN
230
- A0ZF66D0f0hExghAzN4bcLUprbqLOzRldRtxIR0sFAqwlpW41uryZfspuk/qkZN0
231
- abby/+Ea0AzRdoXLiiW9l14sbxWZJue2Kf8i7MkCx1YAzUm5s2x7UwQa4qjJqhIF
232
- I8LO57sEAszAR6LkxCkvW0VXiVHuPOtSCP8HNR6fNWpHSlaY0VqFH4z1Ir+rzoPz
233
- 4iIprn2DQKi6bA==
234
- -----END CERTIFICATE-----
235
- -----BEGIN CERTIFICATE-----
236
  MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
237
  MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i
238
  YWwgQ0EwHhcNMDIwNTIxMDQwMDAwWhcNMjIwNTIxMDQwMDAwWjBCMQswCQYDVQQG
@@ -252,100 +189,3 @@ PseKUgzbFbS9bZvlxrFUaKnjaZC2mqUPuLk/IH2uSrW4nOQdtqvmlKXBx4Ot2/Un
252
  hw4EbNX/3aBd7YdStysVAq45pmp06drE57xNNB6pXE0zX5IJL4hmXXeXxx12E6nV
253
  5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3CBWaAocvmMw==
254
  -----END CERTIFICATE-----
255
- -----BEGIN CERTIFICATE-----
256
- MIIDuDCCAqCgAwIBAgIQDPCOXAgWpa1Cf/DrJxhZ0DANBgkqhkiG9w0BAQUFADBI
257
- MQswCQYDVQQGEwJVUzEgMB4GA1UEChMXU2VjdXJlVHJ1c3QgQ29ycG9yYXRpb24x
258
- FzAVBgNVBAMTDlNlY3VyZVRydXN0IENBMB4XDTA2MTEwNzE5MzExOFoXDTI5MTIz
259
- MTE5NDA1NVowSDELMAkGA1UEBhMCVVMxIDAeBgNVBAoTF1NlY3VyZVRydXN0IENv
260
- cnBvcmF0aW9uMRcwFQYDVQQDEw5TZWN1cmVUcnVzdCBDQTCCASIwDQYJKoZIhvcN
261
- AQEBBQADggEPADCCAQoCggEBAKukgeWVzfX2FI7CT8rU4niVWJxB4Q2ZQCQXOZEz
262
- Zum+4YOvYlyJ0fwkW2Gz4BERQRwdbvC4u/jep4G6pkjGnx29vo6pQT64lO0pGtSO
263
- 0gMdA+9tDWccV9cGrcrI9f4Or2YlSASWC12juhbDCE/RRvgUXPLIXgGZbf2IzIao
264
- wW8xQmxSPmjL8xk037uHGFaAJsTQ3MBv396gwpEWoGQRS0S8Hvbn+mPeZqx2pHGj
265
- 7DaUaHp3pLHnDi+BeuK1cobvomuL8A/b01k/unK8RCSc43Oz969XL0Imnal0ugBS
266
- 8kvNU3xHCzaFDmapCJcWNFfBZveA4+1wVMeT4C4oFVmHursCAwEAAaOBnTCBmjAT
267
- BgkrBgEEAYI3FAIEBh4EAEMAQTALBgNVHQ8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB
268
- /zAdBgNVHQ4EFgQUQjK2FvoE/f5dS3rD/fdMQB1aQ68wNAYDVR0fBC0wKzApoCeg
269
- JYYjaHR0cDovL2NybC5zZWN1cmV0cnVzdC5jb20vU1RDQS5jcmwwEAYJKwYBBAGC
270
- NxUBBAMCAQAwDQYJKoZIhvcNAQEFBQADggEBADDtT0rhWDpSclu1pqNlGKa7UTt3
271
- 6Z3q059c4EVlew3KW+JwULKUBRSuSceNQQcSc5R+DCMh/bwQf2AQWnL1mA6s7Ll/
272
- 3XpvXdMc9P+IBWlCqQVxyLesJugutIxq/3HcuLHfmbx8IVQr5Fiiu1cprp6poxkm
273
- D5kuCLDv/WnPmRoJjeOnnyvJNjR7JLN4TJUXpAYmHrZkUjZfYGfZnMUFdAvnZyPS
274
- CPyI6a6Lf+Ew9Dd+/cYy2i2eRDAwbO4H3tI0/NL/QPZL9GZGBlSm8jIKYyYwa5vR
275
- 3ItHuuG51WLQoqD0ZwV4KWMabwTW+MZMo5qxN7SN5ShLHZ4swrhovO0C7jE=
276
- -----END CERTIFICATE-----
277
- -----BEGIN CERTIFICATE-----
278
- MIICiDCCAg2gAwIBAgIQNfwmXNmET8k9Jj1Xm67XVjAKBggqhkjOPQQDAzCBhDEL
279
- MAkGA1UEBhMCVVMxFTATBgNVBAoTDHRoYXd0ZSwgSW5jLjE4MDYGA1UECxMvKGMp
280
- IDIwMDcgdGhhd3RlLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxJDAi
281
- BgNVBAMTG3RoYXd0ZSBQcmltYXJ5IFJvb3QgQ0EgLSBHMjAeFw0wNzExMDUwMDAw
282
- MDBaFw0zODAxMTgyMzU5NTlaMIGEMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMdGhh
283
- d3RlLCBJbmMuMTgwNgYDVQQLEy8oYykgMjAwNyB0aGF3dGUsIEluYy4gLSBGb3Ig
284
- YXV0aG9yaXplZCB1c2Ugb25seTEkMCIGA1UEAxMbdGhhd3RlIFByaW1hcnkgUm9v
285
- dCBDQSAtIEcyMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEotWcgnuVnfFSeIf+iha/
286
- BebfowJPDQfGAFG6DAJSLSKkQjnE/o/qycG+1E3/n3qe4rF8mq2nhglzh9HnmuN6
287
- papu+7qzcMBniKI11KOasf2twu8x+qi58/sIxpHR+ymVo0IwQDAPBgNVHRMBAf8E
288
- BTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUmtgAMADna3+FGO6Lts6K
289
- DPgR4bswCgYIKoZIzj0EAwMDaQAwZgIxAN344FdHW6fmCsO99YCKlzUNG4k8VIZ3
290
- KMqh9HneteY4sPBlcIx/AlTCv//YoT7ZzwIxAMSNlPzcU9LcnXgWHxUzI1NS41ox
291
- XZ3Krr0TKUQNJ1uo52icEvdYPy5yAlejj6EULg==
292
- -----END CERTIFICATE-----
293
- -----BEGIN CERTIFICATE-----
294
- MIIEIDCCAwigAwIBAgIQNE7VVyDV7exJ9C/ON9srbTANBgkqhkiG9w0BAQUFADCB
295
- qTELMAkGA1UEBhMCVVMxFTATBgNVBAoTDHRoYXd0ZSwgSW5jLjEoMCYGA1UECxMf
296
- Q2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjE4MDYGA1UECxMvKGMpIDIw
297
- MDYgdGhhd3RlLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxHzAdBgNV
298
- BAMTFnRoYXd0ZSBQcmltYXJ5IFJvb3QgQ0EwHhcNMDYxMTE3MDAwMDAwWhcNMzYw
299
- NzE2MjM1OTU5WjCBqTELMAkGA1UEBhMCVVMxFTATBgNVBAoTDHRoYXd0ZSwgSW5j
300
- LjEoMCYGA1UECxMfQ2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjE4MDYG
301
- A1UECxMvKGMpIDIwMDYgdGhhd3RlLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNl
302
- IG9ubHkxHzAdBgNVBAMTFnRoYXd0ZSBQcmltYXJ5IFJvb3QgQ0EwggEiMA0GCSqG
303
- SIb3DQEBAQUAA4IBDwAwggEKAoIBAQCsoPD7gFnUnMekz52hWXMJEEUMDSxuaPFs
304
- W0hoSVk3/AszGcJ3f8wQLZU0HObrTQmnHNK4yZc2AreJ1CRfBsDMRJSUjQJib+ta
305
- 3RGNKJpchJAQeg29dGYvajig4tVUROsdB58Hum/u6f1OCyn1PoSgAfGcq/gcfomk
306
- 6KHYcWUNo1F77rzSImANuVud37r8UVsLr5iy6S7pBOhih94ryNdOwUxkHt3Ph1i6
307
- Sk/KaAcdHJ1KxtUvkcx8cXIcxcBn6zL9yZJclNqFwJu/U30rCfSMnZEfl2pSy94J
308
- NqR32HuHUETVPm4pafs5SSYeCaWAe0At6+gnhcn+Yf1+5nyXHdWdAgMBAAGjQjBA
309
- MA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBR7W0XP
310
- r87Lev0xkhpqtvNG61dIUDANBgkqhkiG9w0BAQUFAAOCAQEAeRHAS7ORtvzw6WfU
311
- DW5FvlXok9LOAz/t2iWwHVfLHjp2oEzsUHboZHIMpKnxuIvW1oeEuzLlQRHAd9mz
312
- YJ3rG9XRbkREqaYB7FViHXe4XI5ISXycO1cRrK1zN44veFyQaEfZYGDm/Ac9IiAX
313
- xPcW6cTYcvnIc3zfFi8VqT79aie2oetaupgf1eNNZAqdE8hhuvU5HIe6uL17In/2
314
- /qxAeeWsEG89jxt5dovEN7MhGITlNgDrYyCZuen+MwS7QcjBAvlEYyCegc5C09Y/
315
- LHbTY5xZ3Y+m4Q6gLkH3LpVHz7z9M/P2C2F+fpErgUfCJzDupxBdN49cOSvkBPB7
316
- jVaMaA==
317
- -----END CERTIFICATE-----
318
- -----BEGIN CERTIFICATE-----
319
- MIICiDCCAg2gAwIBAgIQNfwmXNmET8k9Jj1Xm67XVjAKBggqhkjOPQQDAzCBhDEL
320
- MAkGA1UEBhMCVVMxFTATBgNVBAoTDHRoYXd0ZSwgSW5jLjE4MDYGA1UECxMvKGMp
321
- IDIwMDcgdGhhd3RlLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxJDAi
322
- BgNVBAMTG3RoYXd0ZSBQcmltYXJ5IFJvb3QgQ0EgLSBHMjAeFw0wNzExMDUwMDAw
323
- MDBaFw0zODAxMTgyMzU5NTlaMIGEMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMdGhh
324
- d3RlLCBJbmMuMTgwNgYDVQQLEy8oYykgMjAwNyB0aGF3dGUsIEluYy4gLSBGb3Ig
325
- YXV0aG9yaXplZCB1c2Ugb25seTEkMCIGA1UEAxMbdGhhd3RlIFByaW1hcnkgUm9v
326
- dCBDQSAtIEcyMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEotWcgnuVnfFSeIf+iha/
327
- BebfowJPDQfGAFG6DAJSLSKkQjnE/o/qycG+1E3/n3qe4rF8mq2nhglzh9HnmuN6
328
- papu+7qzcMBniKI11KOasf2twu8x+qi58/sIxpHR+ymVo0IwQDAPBgNVHRMBAf8E
329
- BTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUmtgAMADna3+FGO6Lts6K
330
- DPgR4bswCgYIKoZIzj0EAwMDaQAwZgIxAN344FdHW6fmCsO99YCKlzUNG4k8VIZ3
331
- KMqh9HneteY4sPBlcIx/AlTCv//YoT7ZzwIxAMSNlPzcU9LcnXgWHxUzI1NS41ox
332
- XZ3Krr0TKUQNJ1uo52icEvdYPy5yAlejj6EULg==
333
- -----END CERTIFICATE-----
334
- -----BEGIN CERTIFICATE-----
335
- MIIC5zCCAlACAQEwDQYJKoZIhvcNAQEFBQAwgbsxJDAiBgNVBAcTG1ZhbGlDZXJ0
336
- IFZhbGlkYXRpb24gTmV0d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNTAz
337
- BgNVBAsTLFZhbGlDZXJ0IENsYXNzIDIgUG9saWN5IFZhbGlkYXRpb24gQXV0aG9y
338
- aXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZhbGljZXJ0LmNvbS8xIDAeBgkqhkiG
339
- 9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMB4XDTk5MDYyNjAwMTk1NFoXDTE5MDYy
340
- NjAwMTk1NFowgbsxJDAiBgNVBAcTG1ZhbGlDZXJ0IFZhbGlkYXRpb24gTmV0d29y
341
- azEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENs
342
- YXNzIDIgUG9saWN5IFZhbGlkYXRpb24gQXV0aG9yaXR5MSEwHwYDVQQDExhodHRw
343
- Oi8vd3d3LnZhbGljZXJ0LmNvbS8xIDAeBgkqhkiG9w0BCQEWEWluZm9AdmFsaWNl
344
- cnQuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOOnHK5avIWZJV16vY
345
- dA757tn2VUdZZUcOBVXc65g2PFxTXdMwzzjsvUGJ7SVCCSRrCl6zfN1SLUzm1NZ9
346
- WlmpZdRJEy0kTRxQb7XBhVQ7/nHk01xC+YDgkRoKWzk2Z/M/VXwbP7RfZHM047QS
347
- v4dk+NoS/zcnwbNDu+97bi5p9wIDAQABMA0GCSqGSIb3DQEBBQUAA4GBADt/UG9v
348
- UJSZSWI4OB9L+KXIPqeCgfYrx+jFzug6EILLGACOTb2oWH+heQC1u+mNr0HZDzTu
349
- IYEZoDJJKPTEjlbVUjP9UNV+mWwD5MlM/Mtsq2azSiGM5bUMMj4QssxsodyamEwC
350
- W/POuZ6lcg5Ktz885hZo+L7tdEy8W9ViH0Pd
351
- -----END CERTIFICATE-----
1
  -----BEGIN CERTIFICATE-----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB
3
  yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
4
  ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp
27
  hnacRHr2lVz2XTIIM6RUthg/aFzyQkqFOFSDX9HoLPKsEdao7WNq
28
  -----END CERTIFICATE-----
29
  -----BEGIN CERTIFICATE-----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  MIIDuDCCAqCgAwIBAgIQDPCOXAgWpa1Cf/DrJxhZ0DANBgkqhkiG9w0BAQUFADBI
31
  MQswCQYDVQQGEwJVUzEgMB4GA1UEChMXU2VjdXJlVHJ1c3QgQ29ycG9yYXRpb24x
32
  FzAVBgNVBAMTDlNlY3VyZVRydXN0IENBMB4XDTA2MTEwNzE5MzExOFoXDTI5MTIz
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
170
  bJxPgWp6ZKy7PtXny3YuxadIwVyQD8vIP/rmMuGNG2+k5o7Y+SlIis5z/iw=
171
  -----END CERTIFICATE-----
172
  -----BEGIN CERTIFICATE-----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  MIIDVDCCAjygAwIBAgIDAjRWMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT
174
  MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i
175
  YWwgQ0EwHhcNMDIwNTIxMDQwMDAwWhcNMjIwNTIxMDQwMDAwWjBCMQswCQYDVQQG
189
  hw4EbNX/3aBd7YdStysVAq45pmp06drE57xNNB6pXE0zX5IJL4hmXXeXxx12E6nV
190
  5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3CBWaAocvmMw==
191
  -----END CERTIFICATE-----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
braintree_sdk/phpunit.xml.dist CHANGED
@@ -1,6 +1,7 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
  <phpunit backupGlobals="false"
3
  backupStaticAttributes="false"
 
4
  convertErrorsToExceptions="true"
5
  convertNoticesToExceptions="true"
6
  convertWarningsToExceptions="true"
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"
braintree_sdk/tests/Braintree/CreditCardDefaults.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
 
3
  class CreditCardDefaults
4
  {
1
  <?php
2
+ namespace Test\Braintree;
3
 
4
  class CreditCardDefaults
5
  {
braintree_sdk/tests/Braintree/CreditCardNumbers/CardTypeIndicators.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
- class Braintree_CreditCardNumbers_CardTypeIndicators {
 
 
3
  const PREPAID = "4111111111111210";
4
  const COMMERCIAL = "4111111111131010";
5
  const PAYROLL = "4111111114101010";
1
  <?php
2
+ namespace Test\Braintree\CreditCardNumbers;
3
+
4
+ class CardTypeIndicators {
5
  const PREPAID = "4111111111111210";
6
  const COMMERCIAL = "4111111111131010";
7
  const PAYROLL = "4111111114101010";
braintree_sdk/tests/Braintree/OAuthTestHelper.php CHANGED
@@ -1,31 +1,34 @@
1
  <?php
 
2
 
3
- class Braintree_OAuthTestHelper
 
 
4
  {
5
  public static function createGrant($gateway, $params)
6
  {
7
- $http = new Braintree_Http($gateway->config);
8
  $http->useClientCredentials();
9
- $response = $http->post('/oauth_testing/grants', array('grant' => $params));
10
  return $response['grant']['code'];
11
  }
12
 
13
  public static function createCredentials($params)
14
  {
15
- $gateway = new Braintree_Gateway(array(
16
  'clientId' => $params['clientId'],
17
  'clientSecret' => $params['clientSecret']
18
- ));
19
 
20
- $code = Braintree_OAuthTestHelper::createGrant($gateway, array(
21
  'merchant_public_id' => $params['merchantId'],
22
  'scope' => 'read_write'
23
- ));
24
 
25
- $credentials = $gateway->oauth()->createTokenFromCode(array(
26
  'code' => $code,
27
  'scope' => 'read_write',
28
- ));
29
 
30
  return $credentials;
31
  }
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
  }
braintree_sdk/tests/Braintree/fixtures/composer_implementation.php DELETED
@@ -1,5 +0,0 @@
1
- <?php
2
-
3
- require_once __DIR__ . '/../../../vendor/autoload.php';
4
-
5
- class_exists("Braintree_Modification");
 
 
 
 
 
braintree_sdk/tests/{TestHelper.php → Helper.php} RENAMED
@@ -1,38 +1,24 @@
1
  <?php
 
2
 
3
- set_include_path(
4
- get_include_path() . PATH_SEPARATOR .
5
- realpath(dirname(__FILE__)) . '/../lib'
6
- );
7
 
8
- require_once "Braintree.php";
9
- require_once "Braintree/CreditCardNumbers/CardTypeIndicators.php";
10
- require_once "Braintree/CreditCardDefaults.php";
11
- require_once "Braintree/OAuthTestHelper.php";
12
- require_once "Braintree/PaymentInstrumentType.php";
13
 
14
- function integrationMerchantConfig()
15
  {
16
- Braintree_Configuration::environment('development');
17
- Braintree_Configuration::merchantId('integration_merchant_id');
18
- Braintree_Configuration::publicKey('integration_public_key');
19
- Braintree_Configuration::privateKey('integration_private_key');
20
- }
21
-
22
- function testMerchantConfig()
23
- {
24
- Braintree_Configuration::environment('development');
25
- Braintree_Configuration::merchantId('test_merchant_id');
26
- Braintree_Configuration::publicKey('test_public_key');
27
- Braintree_Configuration::privateKey('test_private_key');
28
- }
29
-
30
- integrationMerchantConfig();
31
 
32
- date_default_timezone_set("UTC");
 
 
 
 
33
 
34
- class Braintree_TestHelper
35
- {
36
  public static function defaultMerchantAccountId()
37
  {
38
  return 'sandbox_credit_card';
@@ -53,13 +39,23 @@ class Braintree_TestHelper
53
  return 'three_d_secure_merchant_account';
54
  }
55
 
 
 
 
 
 
 
 
 
 
 
56
  public static function createViaTr($regularParams, $trParams)
57
  {
58
- $trData = Braintree_TransparentRedirect::transactionData(
59
- array_merge($trParams, array("redirectUrl" => "http://www.example.com"))
60
  );
61
- return Braintree_TestHelper::submitTrRequest(
62
- TransparentRedirect::url(),
63
  $regularParams,
64
  $trData
65
  );
@@ -73,10 +69,10 @@ class Braintree_TestHelper
73
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
74
  curl_setopt($curl, CURLOPT_HEADER, true);
75
  // curl_setopt($curl, CURLOPT_VERBOSE, true);
76
- curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array_merge($regularParams, array('tr_data' => $trData))));
77
- curl_setopt($curl, CURLOPT_HTTPHEADER, array(
78
  'Content-Type: application/x-www-form-urlencoded'
79
- ));
80
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
81
  $response = curl_exec($curl);
82
  curl_close($curl);
@@ -86,10 +82,10 @@ class Braintree_TestHelper
86
 
87
  public static function suppressDeprecationWarnings()
88
  {
89
- set_error_handler("Braintree_TestHelper::_errorHandler", E_USER_NOTICE);
90
  }
91
 
92
- static function _errorHandler($errno, $errstr, $errfile, $errline)
93
  {
94
  if (preg_match('/^DEPRECATED/', $errstr) == 0) {
95
  trigger_error('Unknown error received: ' . $errstr, E_USER_ERROR);
@@ -113,16 +109,16 @@ class Braintree_TestHelper
113
 
114
  public static function escrow($transactionId)
115
  {
116
- $http = new Braintree_Http(Braintree_Configuration::$global);
117
- $path = Braintree_Configuration::$global->merchantPath() . '/transactions/' . $transactionId . '/escrow';
118
  $http->put($path);
119
  }
120
 
121
  public static function create3DSVerification($merchantAccountId, $params)
122
  {
123
- $http = new Braintree_Http(Braintree_Configuration::$global);
124
- $path = Braintree_Configuration::$global->merchantPath() . '/three_d_secure/create_verification/' . $merchantAccountId;
125
- $response = $http->post($path, array('threeDSecureVerification' => $params));
126
  return $response['threeDSecureVerification']['threeDSecureToken'];
127
  }
128
 
@@ -133,8 +129,8 @@ class Braintree_TestHelper
133
  return $now->format('Y-m-d');
134
  }
135
 
136
- public static function decodedClientToken($params=array()) {
137
- $encodedClientToken = Braintree_ClientToken::generate($params);
138
  return base64_decode($encodedClientToken);
139
  }
140
  }
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 function testMerchantConfig()
13
+ {
14
+ Braintree\Configuration::reset();
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ Braintree\Configuration::environment('development');
17
+ Braintree\Configuration::merchantId('test_merchant_id');
18
+ Braintree\Configuration::publicKey('test_public_key');
19
+ Braintree\Configuration::privateKey('test_private_key');
20
+ }
21
 
 
 
22
  public static function defaultMerchantAccountId()
23
  {
24
  return 'sandbox_credit_card';
39
  return 'three_d_secure_merchant_account';
40
  }
41
 
42
+ public static function fakeAmexDirectMerchantAccountId()
43
+ {
44
+ return 'fake_amex_direct_usd';
45
+ }
46
+
47
+ public static function fakeVenmoAccountMerchantAccountId()
48
+ {
49
+ return 'fake_first_data_venmo_account';
50
+ }
51
+
52
  public static function createViaTr($regularParams, $trParams)
53
  {
54
+ $trData = Braintree\TransparentRedirect::transactionData(
55
+ array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
56
  );
57
+ return self::submitTrRequest(
58
+ Braintree\TransparentRedirect::url(),
59
  $regularParams,
60
  $trData
61
  );
69
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
70
  curl_setopt($curl, CURLOPT_HEADER, true);
71
  // curl_setopt($curl, CURLOPT_VERBOSE, true);
72
+ curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array_merge($regularParams, ['tr_data' => $trData])));
73
+ curl_setopt($curl, CURLOPT_HTTPHEADER, [
74
  'Content-Type: application/x-www-form-urlencoded'
75
+ ]);
76
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
77
  $response = curl_exec($curl);
78
  curl_close($curl);
82
 
83
  public static function suppressDeprecationWarnings()
84
  {
85
+ set_error_handler("Test\Helper::_errorHandler", E_USER_NOTICE);
86
  }
87
 
88
+ public static function _errorHandler($errno, $errstr, $errfile, $errline)
89
  {
90
  if (preg_match('/^DEPRECATED/', $errstr) == 0) {
91
  trigger_error('Unknown error received: ' . $errstr, E_USER_ERROR);
109
 
110
  public static function escrow($transactionId)
111
  {
112
+ $http = new Braintree\Http(Braintree\Configuration::$global);
113
+ $path = Braintree\Configuration::$global->merchantPath() . '/transactions/' . $transactionId . '/escrow';
114
  $http->put($path);
115
  }
116
 
117
  public static function create3DSVerification($merchantAccountId, $params)
118
  {
119
+ $http = new Braintree\Http(Braintree\Configuration::$global);
120
+ $path = Braintree\Configuration::$global->merchantPath() . '/three_d_secure/create_verification/' . $merchantAccountId;
121
+ $response = $http->post($path, ['threeDSecureVerification' => $params]);
122
  return $response['threeDSecureVerification']['threeDSecureToken'];
123
  }
124
 
129
  return $now->format('Y-m-d');
130
  }
131
 
132
+ public static function decodedClientToken($params=[]) {
133
+ $encodedClientToken = Braintree\ClientToken::generate($params);
134
  return base64_decode($encodedClientToken);
135
  }
136
  }
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
+ }
braintree_sdk/tests/integration/AddOnsTest.php CHANGED
@@ -1,13 +1,18 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_AddOnTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
5
  {
6
- function testAll_returnsAllAddOns()
7
  {
8
  $newId = strval(rand());
9
 
10
- $addOnParams = array (
11
  "amount" => "100.00",
12
  "description" => "some description",
13
  "id" => $newId,
@@ -15,13 +20,13 @@ class Braintree_AddOnTest extends PHPUnit_Framework_TestCase
15
  "name" => "php_add_on",
16
  "neverExpires" => "false",
17
  "numberOfBillingCycles" => "1"
18
- );
19
 
20
- $http = new Braintree_Http(Braintree_Configuration::$global);
21
- $path = Braintree_Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
22
- $http->post($path, array("modification" => $addOnParams));
23
 
24
- $addOns = Braintree_AddOn::all();
25
 
26
  foreach ($addOns as $addOn)
27
  {
@@ -41,11 +46,11 @@ class Braintree_AddOnTest extends PHPUnit_Framework_TestCase
41
  $this->assertEquals($addOnParams["numberOfBillingCycles"], $actualAddOn->numberOfBillingCycles);
42
  }
43
 
44
- function testGatewayAll_returnsAllAddOns()
45
  {
46
  $newId = strval(rand());
47
 
48
- $addOnParams = array (
49
  "amount" => "100.00",
50
  "description" => "some description",
51
  "id" => $newId,
@@ -53,18 +58,18 @@ class Braintree_AddOnTest extends PHPUnit_Framework_TestCase
53
  "name" => "php_add_on",
54
  "neverExpires" => "false",
55
  "numberOfBillingCycles" => "1"
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, array("modification" => $addOnParams));
61
 
62
- $gateway = new Braintree_Gateway(array(
63
  'environment' => 'development',
64
  'merchantId' => 'integration_merchant_id',
65
  'publicKey' => 'integration_public_key',
66
  'privateKey' => 'integration_private_key'
67
- ));
68
  $addOns = $gateway->addOn()->all();
69
 
70
  foreach ($addOns as $addOn)
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,
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
  {
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,
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)
braintree_sdk/tests/integration/AddressTest.php CHANGED
@@ -1,12 +1,17 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_AddressTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
5
  {
6
- function testCreate()
7
  {
8
- $customer = Braintree_Customer::createNoValidate();
9
- $result = Braintree_Address::create(array(
10
  'customerId' => $customer->id,
11
  'firstName' => 'Dan',
12
  'lastName' => 'Smith',
@@ -20,7 +25,7 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
20
  'countryCodeAlpha2' => 'VA',
21
  'countryCodeAlpha3' => 'VAT',
22
  'countryCodeNumeric' => '336'
23
- ));
24
  $this->assertTrue($result->success);
25
  $address = $result->address;
26
  $this->assertEquals('Dan', $address->firstName);
@@ -37,23 +42,23 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
37
  $this->assertEquals('336', $address->countryCodeNumeric);
38
  }
39
 
40
- function testGatewayCreate()
41
  {
42
- $customer = Braintree_Customer::createNoValidate();
43
 
44
- $gateway = new Braintree_Gateway(array(
45
  'environment' => 'development',
46
  'merchantId' => 'integration_merchant_id',
47
  'publicKey' => 'integration_public_key',
48
  'privateKey' => 'integration_private_key'
49
- ));
50
- $result = $gateway->address()->create(array(
51
  'customerId' => $customer->id,
52
  'streetAddress' => '1 E Main St',
53
  'locality' => 'Chicago',
54
  'region' => 'IL',
55
  'postalCode' => '60622',
56
- ));
57
 
58
  $this->assertTrue($result->success);
59
  $address = $result->address;
@@ -63,34 +68,34 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
63
  $this->assertEquals('60622', $address->postalCode);
64
  }
65
 
66
- function testCreate_withValidationErrors()
67
  {
68
- $customer = Braintree_Customer::createNoValidate();
69
- $result = Braintree_Address::create(array(
70
  'customerId' => $customer->id,
71
  'countryName' => 'Invalid States of America'
72
- ));
73
  $this->assertFalse($result->success);
74
  $countryErrors = $result->errors->forKey('address')->onAttribute('countryName');
75
- $this->assertEquals(Braintree_Error_Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, $countryErrors[0]->code);
76
  }
77
 
78
- function testCreate_withValidationErrors_onCountryCodes()
79
  {
80
- $customer = Braintree_Customer::createNoValidate();
81
- $result = Braintree_Address::create(array(
82
  'customerId' => $customer->id,
83
  'countryCodeAlpha2' => 'ZZ'
84
- ));
85
  $this->assertFalse($result->success);
86
  $countryErrors = $result->errors->forKey('address')->onAttribute('countryCodeAlpha2');
87
- $this->assertEquals(Braintree_Error_Codes::ADDRESS_COUNTRY_CODE_ALPHA2_IS_NOT_ACCEPTED, $countryErrors[0]->code);
88
  }
89
 
90
- function testCreateNoValidate()
91
  {
92
- $customer = Braintree_Customer::createNoValidate();
93
- $address = Braintree_Address::createNoValidate(array(
94
  'customerId' => $customer->id,
95
  'firstName' => 'Dan',
96
  'lastName' => 'Smith',
@@ -101,7 +106,7 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
101
  'region' => 'IL',
102
  'postalCode' => '60622',
103
  'countryName' => 'United States of America'
104
- ));
105
  $this->assertEquals('Dan', $address->firstName);
106
  $this->assertEquals('Smith', $address->lastName);
107
  $this->assertEquals('Braintree', $address->company);
@@ -113,33 +118,33 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
113
  $this->assertEquals('United States of America', $address->countryName);
114
  }
115
 
116
- function testCreateNoValidate_withValidationErrors()
117
  {
118
- $customer = Braintree_Customer::createNoValidate();
119
- $this->setExpectedException('Braintree_Exception_ValidationsFailed');
120
- Braintree_Address::createNoValidate(array(
121
  'customerId' => $customer->id,
122
  'countryName' => 'Invalid States of America'
123
- ));
124
  }
125
 
126
- function testDelete()
127
  {
128
- $customer = Braintree_Customer::createNoValidate();
129
- $address = Braintree_Address::createNoValidate(array(
130
  'customerId' => $customer->id,
131
  'streetAddress' => '1 E Main St'
132
- ));
133
- Braintree_Address::find($customer->id, $address->id);
134
- Braintree_Address::delete($customer->id, $address->id);
135
- $this->setExpectedException('Braintree_Exception_NotFound');
136
- Braintree_Address::find($customer->id, $address->id);
137
  }
138
 
139
- function testFind()
140
  {
141
- $customer = Braintree_Customer::createNoValidate();
142
- $result = Braintree_Address::create(array(
143
  'customerId' => $customer->id,
144
  'firstName' => 'Dan',
145
  'lastName' => 'Smith',
@@ -150,9 +155,9 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
150
  'region' => 'IL',
151
  'postalCode' => '60622',
152
  'countryName' => 'United States of America'
153
- ));
154
  $this->assertTrue($result->success);
155
- $address = Braintree_Address::find($customer->id, $result->address->id);
156
  $this->assertEquals('Dan', $address->firstName);
157
  $this->assertEquals('Smith', $address->lastName);
158
  $this->assertEquals('Braintree', $address->company);
@@ -164,17 +169,17 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
164
  $this->assertEquals('United States of America', $address->countryName);
165
  }
166
 
167
- function testFind_whenNotFound()
168
  {
169
- $customer = Braintree_Customer::createNoValidate();
170
- $this->setExpectedException('Braintree_Exception_NotFound');
171
- Braintree_Address::find($customer->id, 'does-not-exist');
172
  }
173
 
174
- function testUpdate()
175
  {
176
- $customer = Braintree_Customer::createNoValidate();
177
- $address = Braintree_Address::createNoValidate(array(
178
  'customerId' => $customer->id,
179
  'firstName' => 'Old First',
180
  'lastName' => 'Old Last',
@@ -188,8 +193,8 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
188
  'countryCodeAlpha2' => 'US',
189
  'countryCodeAlpha3' => 'USA',
190
  'countryCodeNumeric' => '840'
191
- ));
192
- $result = Braintree_Address::update($customer->id, $address->id, array(
193
  'firstName' => 'New First',
194
  'lastName' => 'New Last',
195
  'company' => 'New Company',
@@ -202,7 +207,7 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
202
  'countryCodeAlpha2' => 'MX',
203
  'countryCodeAlpha3' => 'MEX',
204
  'countryCodeNumeric' => '484'
205
- ));
206
  $this->assertTrue($result->success);
207
  $address = $result->address;
208
  $this->assertEquals('New First', $address->firstName);
@@ -219,50 +224,50 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
219
  $this->assertEquals('484', $address->countryCodeNumeric);
220
  }
221
 
222
- function testUpdate_withValidationErrors()
223
  {
224
- $customer = Braintree_Customer::createNoValidate();
225
- $address = Braintree_Address::createNoValidate(array(
226
  'customerId' => $customer->id,
227
  'streetAddress' => '1 E Main St'
228
- ));
229
- $result = Braintree_Address::update(
230
  $customer->id,
231
  $address->id,
232
- array(
233
  'countryName' => 'Invalid States of America'
234
- )
235
  );
236
  $this->assertFalse($result->success);
237
  $countryErrors = $result->errors->forKey('address')->onAttribute('countryName');
238
- $this->assertEquals(Braintree_Error_Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, $countryErrors[0]->code);
239
  }
240
 
241
- function testUpdate_withValidationErrors_onCountry()
242
  {
243
- $customer = Braintree_Customer::createNoValidate();
244
- $address = Braintree_Address::createNoValidate(array(
245
  'customerId' => $customer->id,
246
  'streetAddress' => '1 E Main St'
247
- ));
248
- $result = Braintree_Address::update(
249
  $customer->id,
250
  $address->id,
251
- array(
252
  'countryCodeAlpha2' => 'MU',
253
  'countryCodeAlpha3' => 'MYT'
254
- )
255
  );
256
  $this->assertFalse($result->success);
257
  $countryErrors = $result->errors->forKey('address')->onAttribute('base');
258
- $this->assertEquals(Braintree_Error_Codes::ADDRESS_INCONSISTENT_COUNTRY, $countryErrors[0]->code);
259
  }
260
 
261
 
262
- function testUpdateNoValidate()
263
  {
264
- $customer = Braintree_Customer::createNoValidate();
265
- $createdAddress = Braintree_Address::createNoValidate(array(
266
  'customerId' => $customer->id,
267
  'firstName' => 'Old First',
268
  'lastName' => 'Old Last',
@@ -273,8 +278,8 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
273
  'region' => 'Old Region',
274
  'postalCode' => 'Old Postal',
275
  'countryName' => 'United States of America'
276
- ));
277
- $address = Braintree_Address::updateNoValidate($customer->id, $createdAddress->id, array(
278
  'firstName' => 'New First',
279
  'lastName' => 'New Last',
280
  'company' => 'New Company',
@@ -284,7 +289,7 @@ class Braintree_AddressTest extends PHPUnit_Framework_TestCase
284
  'region' => 'New Region',
285
  'postalCode' => 'New Postal',
286
  'countryName' => 'Mexico'
287
- ));
288
  $this->assertEquals('New First', $address->firstName);
289
  $this->assertEquals('New Last', $address->lastName);
290
  $this->assertEquals('New Company', $address->company);
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',
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);
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;
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 testCreateNoValidate()
96
  {
97
+ $customer = Braintree\Customer::createNoValidate();
98
+ $address = Braintree\Address::createNoValidate([
99
  'customerId' => $customer->id,
100
  'firstName' => 'Dan',
101
  'lastName' => 'Smith',
106
  'region' => 'IL',
107
  'postalCode' => '60622',
108
  'countryName' => 'United States of America'
109
+ ]);
110
  $this->assertEquals('Dan', $address->firstName);
111
  $this->assertEquals('Smith', $address->lastName);
112
  $this->assertEquals('Braintree', $address->company);
118
  $this->assertEquals('United States of America', $address->countryName);
119
  }
120
 
121
+ public function testCreateNoValidate_withValidationErrors()
122
  {
123
+ $customer = Braintree\Customer::createNoValidate();
124
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
125
+ Braintree\Address::createNoValidate([
126
  'customerId' => $customer->id,
127
  'countryName' => 'Invalid States of America'
128
+ ]);
129
  }
130
 
131
+ public function testDelete()
132
  {
133
+ $customer = Braintree\Customer::createNoValidate();
134
+ $address = Braintree\Address::createNoValidate([
135
  'customerId' => $customer->id,
136
  'streetAddress' => '1 E Main St'
137
+ ]);
138
+ Braintree\Address::find($customer->id, $address->id);
139
+ Braintree\Address::delete($customer->id, $address->id);
140
+ $this->setExpectedException('Braintree\Exception\NotFound');
141
+ Braintree\Address::find($customer->id, $address->id);
142
  }
143
 
144
+ public function testFind()
145
  {
146
+ $customer = Braintree\Customer::createNoValidate();
147
+ $result = Braintree\Address::create([
148
  'customerId' => $customer->id,
149
  'firstName' => 'Dan',
150
  'lastName' => 'Smith',
155
  'region' => 'IL',
156
  'postalCode' => '60622',
157
  'countryName' => 'United States of America'
158
+ ]);
159
  $this->assertTrue($result->success);
160
+ $address = Braintree\Address::find($customer->id, $result->address->id);
161
  $this->assertEquals('Dan', $address->firstName);
162
  $this->assertEquals('Smith', $address->lastName);
163
  $this->assertEquals('Braintree', $address->company);
169
  $this->assertEquals('United States of America', $address->countryName);
170
  }
171
 
172
+ public function testFind_whenNotFound()
173
  {
174
+ $customer = Braintree\Customer::createNoValidate();
175
+ $this->setExpectedException('Braintree\Exception\NotFound');
176
+ Braintree\Address::find($customer->id, 'does-not-exist');
177
  }
178
 
179
+ public function testUpdate()
180
  {
181
+ $customer = Braintree\Customer::createNoValidate();
182
+ $address = Braintree\Address::createNoValidate([
183
  'customerId' => $customer->id,
184
  'firstName' => 'Old First',
185
  'lastName' => 'Old Last',
193
  'countryCodeAlpha2' => 'US',
194
  'countryCodeAlpha3' => 'USA',
195
  'countryCodeNumeric' => '840'
196
+ ]);
197
+ $result = Braintree\Address::update($customer->id, $address->id, [
198
  'firstName' => 'New First',
199
  'lastName' => 'New Last',
200
  'company' => 'New Company',
207
  'countryCodeAlpha2' => 'MX',
208
  'countryCodeAlpha3' => 'MEX',
209
  'countryCodeNumeric' => '484'
210
+ ]);
211
  $this->assertTrue($result->success);
212
  $address = $result->address;
213
  $this->assertEquals('New First', $address->firstName);
224
  $this->assertEquals('484', $address->countryCodeNumeric);
225
  }
226
 
227
+ public function testUpdate_withValidationErrors()
228
  {
229
+ $customer = Braintree\Customer::createNoValidate();
230
+ $address = Braintree\Address::createNoValidate([
231
  'customerId' => $customer->id,
232
  'streetAddress' => '1 E Main St'
233
+ ]);
234
+ $result = Braintree\Address::update(
235
  $customer->id,
236
  $address->id,
237
+ [
238
  'countryName' => 'Invalid States of America'
239
+ ]
240
  );
241
  $this->assertFalse($result->success);
242
  $countryErrors = $result->errors->forKey('address')->onAttribute('countryName');
243
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, $countryErrors[0]->code);
244
  }
245
 
246
+ public function testUpdate_withValidationErrors_onCountry()
247
  {
248
+ $customer = Braintree\Customer::createNoValidate();
249
+ $address = Braintree\Address::createNoValidate([
250
  'customerId' => $customer->id,
251
  'streetAddress' => '1 E Main St'
252
+ ]);
253
+ $result = Braintree\Address::update(
254
  $customer->id,
255
  $address->id,
256
+ [
257
  'countryCodeAlpha2' => 'MU',
258
  'countryCodeAlpha3' => 'MYT'
259
+ ]
260
  );
261
  $this->assertFalse($result->success);
262
  $countryErrors = $result->errors->forKey('address')->onAttribute('base');
263
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_INCONSISTENT_COUNTRY, $countryErrors[0]->code);
264
  }
265
 
266
 
267
+ public function testUpdateNoValidate()
268
  {
269
+ $customer = Braintree\Customer::createNoValidate();
270
+ $createdAddress = Braintree\Address::createNoValidate([
271
  'customerId' => $customer->id,
272
  'firstName' => 'Old First',
273
  'lastName' => 'Old Last',
278
  'region' => 'Old Region',
279
  'postalCode' => 'Old Postal',
280
  'countryName' => 'United States of America'
281
+ ]);
282
+ $address = Braintree\Address::updateNoValidate($customer->id, $createdAddress->id, [
283
  'firstName' => 'New First',
284
  'lastName' => 'New Last',
285
  'company' => 'New Company',
289
  'region' => 'New Region',
290
  'postalCode' => 'New Postal',
291
  'countryName' => 'Mexico'
292
+ ]);
293
  $this->assertEquals('New First', $address->firstName);
294
  $this->assertEquals('New Last', $address->lastName);
295
  $this->assertEquals('New Company', $address->company);
braintree_sdk/tests/integration/ClientTokenTest.php CHANGED
@@ -1,159 +1,164 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/HttpClientApi.php';
4
 
5
- class Braintree_ClientTokenTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
6
  {
7
- function test_ClientTokenAuthorizesRequest()
8
  {
9
- $clientToken = Braintree_TestHelper::decodedClientToken();
10
  $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
11
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
12
- $response = $http->get_cards(array(
13
  "authorization_fingerprint" => $authorizationFingerprint,
14
  "shared_customer_identifier" => "fake_identifier",
15
- "shared_customer_identifier_type" => "testing"
16
- ));
17
 
18
  $this->assertEquals(200, $response["status"]);
19
  }
20
 
21
- function test_VersionOptionSupported()
22
  {
23
- $clientToken = Braintree_ClientToken::generate(array("version" => 1));
24
  $version = json_decode($clientToken)->version;
25
  $this->assertEquals(1, $version);
26
  }
27
 
28
- function test_VersionDefaultsToTwo()
29
  {
30
- $encodedClientToken = Braintree_ClientToken::generate();
31
  $clientToken = base64_decode($encodedClientToken);
32
  $version = json_decode($clientToken)->version;
33
  $this->assertEquals(2, $version);
34
  }
35
 
36
- function testGateway_VersionDefaultsToTwo()
37
  {
38
- $gateway = new Braintree_Gateway(array(
39
  'environment' => 'development',
40
  'merchantId' => 'integration_merchant_id',
41
  'publicKey' => 'integration_public_key',
42
- 'privateKey' => 'integration_private_key'
43
- ));
44
  $encodedClientToken = $gateway->clientToken()->generate();
45
  $clientToken = base64_decode($encodedClientToken);
46
  $version = json_decode($clientToken)->version;
47
  $this->assertEquals(2, $version);
48
  }
49
 
50
- function test_GatewayRespectsVerifyCard()
51
  {
52
- $result = Braintree_Customer::create();
53
  $this->assertTrue($result->success);
54
  $customerId = $result->customer->id;
55
 
56
- $clientToken = Braintree_TestHelper::decodedClientToken(array(
57
  "customerId" => $customerId,
58
- "options" => array(
59
  "verifyCard" => true
60
- )
61
- ));
62
  $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
63
 
64
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
65
- $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode(array(
66
- "credit_card" => array(
67
  "number" => "4000111111111115",
68
  "expirationDate" => "11/2099"
69
- ),
70
  "authorization_fingerprint" => $authorizationFingerprint,
71
  "shared_customer_identifier" => "fake_identifier",
72
  "shared_customer_identifier_type" => "testing"
73
- )));
74
 
75
  $this->assertEquals(422, $response["status"]);
76
  }
77
 
78
- function test_GatewayRespectsFailOnDuplicatePaymentMethod()
79
  {
80
- $result = Braintree_Customer::create();
81
  $this->assertTrue($result->success);
82
  $customerId = $result->customer->id;
83
 
84
- $clientToken = Braintree_TestHelper::decodedClientToken(array(
85
  "customerId" => $customerId,
86
- ));
87
  $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
88
 
89
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
90
- $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode(array(
91
- "credit_card" => array(
92
  "number" => "4242424242424242",
93
  "expirationDate" => "11/2099"
94
- ),
95
  "authorization_fingerprint" => $authorizationFingerprint,
96
  "shared_customer_identifier" => "fake_identifier",
97
  "shared_customer_identifier_type" => "testing"
98
- )));
99
  $this->assertEquals(201, $response["status"]);
100
 
101
- $clientToken = Braintree_TestHelper::decodedClientToken(array(
102
  "customerId" => $customerId,
103
- "options" => array(
104
  "failOnDuplicatePaymentMethod" => true
105
- )
106
- ));
107
  $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
108
 
109
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
110
- $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode(array(
111
- "credit_card" => array(
112
  "number" => "4242424242424242",
113
  "expirationDate" => "11/2099"
114
- ),
115
  "authorization_fingerprint" => $authorizationFingerprint,
116
  "shared_customer_identifier" => "fake_identifier",
117
  "shared_customer_identifier_type" => "testing"
118
- )));
119
  $this->assertEquals(422, $response["status"]);
120
  }
121
 
122
- function test_GatewayRespectsMakeDefault()
123
  {
124
- $result = Braintree_Customer::create();
125
  $this->assertTrue($result->success);
126
  $customerId = $result->customer->id;
127
 
128
- $result = Braintree_CreditCard::create(array(
129
  'customerId' => $customerId,
130
  'number' => '4111111111111111',
131
  'expirationDate' => '11/2099'
132
- ));
133
  $this->assertTrue($result->success);
134
 
135
- $clientToken = Braintree_TestHelper::decodedClientToken(array(
136
  "customerId" => $customerId,
137
- "options" => array(
138
  "makeDefault" => true
139
- )
140
- ));
141
  $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
142
 
143
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
144
- $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode(array(
145
- "credit_card" => array(
146
  "number" => "4242424242424242",
147
  "expirationDate" => "11/2099"
148
- ),
149
  "authorization_fingerprint" => $authorizationFingerprint,
150
  "shared_customer_identifier" => "fake_identifier",
151
  "shared_customer_identifier_type" => "testing"
152
- )));
153
 
154
  $this->assertEquals(201, $response["status"]);
155
 
156
- $customer = Braintree_Customer::find($customerId);
157
  $this->assertEquals(2, count($customer->creditCards));
158
  foreach ($customer->creditCards as $creditCard) {
159
  if ($creditCard->last4 == "4242") {
@@ -162,22 +167,22 @@ class Braintree_ClientTokenTest extends PHPUnit_Framework_TestCase
162
  }
163
  }
164
 
165
- function test_ClientTokenAcceptsMerchantAccountId()
166
  {
167
- $clientToken = Braintree_TestHelper::decodedClientToken(array(
168
  'merchantAccountId' => 'my_merchant_account'
169
- ));
170
  $merchantAccountId = json_decode($clientToken)->merchantAccountId;
171
 
172
  $this->assertEquals('my_merchant_account', $merchantAccountId);
173
  }
174
 
175
- function test_GenerateRaisesExceptionOnGateway422()
176
  {
177
  $this->setExpectedException('InvalidArgumentException', 'customer_id');
178
 
179
- Braintree_ClientToken::generate(array(
180
  "customerId" => "not_a_customer"
181
- ));
182
  }
183
  }
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") {
167
  }
168
  }
169
 
170
+ public function test_ClientTokenAcceptsMerchantAccountId()
171
  {
172
+ $clientToken = Test\Helper::decodedClientToken([
173
  'merchantAccountId' => 'my_merchant_account'
174
+ ]);
175
  $merchantAccountId = json_decode($clientToken)->merchantAccountId;
176
 
177
  $this->assertEquals('my_merchant_account', $merchantAccountId);
178
  }
179
 
180
+ public function test_GenerateRaisesExceptionOnGateway422()
181
  {
182
  $this->setExpectedException('InvalidArgumentException', 'customer_id');
183
 
184
+ Braintree\ClientToken::generate([
185
  "customerId" => "not_a_customer"
186
+ ]);
187
  }
188
  }
braintree_sdk/tests/integration/CreditCardTest.php CHANGED
@@ -1,18 +1,24 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/HttpClientApi.php';
4
 
5
- class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
 
6
  {
7
- function testCreate()
8
  {
9
- $customer = Braintree_Customer::createNoValidate();
10
- $result = Braintree_CreditCard::create(array(
11
  'customerId' => $customer->id,
12
  'cardholderName' => 'Cardholder',
13
  'number' => '5105105105105100',
14
  'expirationDate' => '05/12'
15
- ));
16
  $this->assertTrue($result->success);
17
  $this->assertEquals($customer->id, $result->creditCard->customerId);
18
  $this->assertEquals('510510', $result->creditCard->bin);
@@ -24,22 +30,22 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
24
  $this->assertEquals(1, preg_match('/png/', $result->creditCard->imageUrl));
25
  }
26
 
27
- function testGatewayCreate()
28
  {
29
- $customer = Braintree_Customer::createNoValidate();
30
 
31
- $gateway = new Braintree_Gateway(array(
32
  'environment' => 'development',
33
  'merchantId' => 'integration_merchant_id',
34
  'publicKey' => 'integration_public_key',
35
  'privateKey' => 'integration_private_key'
36
- ));
37
- $result = $gateway->creditCard()->create(array(
38
  'customerId' => $customer->id,
39
  'cardholderName' => 'Cardholder',
40
  'number' => '5105105105105100',
41
  'expirationDate' => '05/12'
42
- ));
43
 
44
  $this->assertTrue($result->success);
45
  $this->assertEquals($customer->id, $result->creditCard->customerId);
@@ -49,79 +55,103 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
49
  $this->assertEquals('05/2012', $result->creditCard->expirationDate);
50
  }
51
 
52
- function testCreate_withDefault()
53
  {
54
- $customer = Braintree_Customer::createNoValidate();
55
- $card1 = Braintree_CreditCard::create(array(
56
  'customerId' => $customer->id,
57
  'cardholderName' => 'Cardholder',
58
  'number' => '5105105105105100',
59
  'expirationDate' => '05/12'
60
- ))->creditCard;
61
  $this->assertTrue($card1->isDefault());
62
 
63
- $card2 = Braintree_CreditCard::create(array(
64
  'customerId' => $customer->id,
65
  'cardholderName' => 'Cardholder',
66
  'number' => '5105105105105100',
67
  'expirationDate' => '05/12',
68
- 'options' => array(
69
  'makeDefault' => true
70
- )
71
- ))->creditCard;
72
 
73
- $card1 = Braintree_CreditCard::find($card1->token);
74
  $this->assertFalse($card1->isDefault());
75
  $this->assertTrue($card2->isDefault());
76
  }
77
 
78
- function testAddCardToExistingCustomerUsingNonce()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  {
80
- $customer = Braintree_Customer::createNoValidate();
81
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
82
- $nonce = $http->nonce_for_new_card(array(
83
- "credit_card" => array(
84
  "number" => "4111111111111111",
85
  "expirationMonth" => "11",
86
  "expirationYear" => "2099"
87
- ),
88
  "share" => true
89
- ));
90
 
91
- $result = Braintree_CreditCard::create(array(
92
  'customerId' => $customer->id,
93
  'paymentMethodNonce' => $nonce
94
- ));
95
 
96
  $this->assertSame("411111", $result->creditCard->bin);
97
  $this->assertSame("1111", $result->creditCard->last4);
98
  }
99
 
100
- function testCreate_withSecurityParams()
101
  {
102
- $customer = Braintree_Customer::createNoValidate();
103
- $result = Braintree_CreditCard::create(array(
104
  'customerId' => $customer->id,
105
  'deviceSessionId' => 'abc_123',
106
  'fraudMerchantId' => '456',
107
  'cardholderName' => 'Cardholder',
108
  'number' => '5105105105105100',
109
  'expirationDate' => '05/12'
110
- ));
111
 
112
  $this->assertTrue($result->success);
113
  }
114
 
115
- function testCreate_withExpirationMonthAndYear()
116
  {
117
- $customer = Braintree_Customer::createNoValidate();
118
- $result = Braintree_CreditCard::create(array(
119
  'customerId' => $customer->id,
120
  'cardholderName' => 'Cardholder',
121
  'number' => '5105105105105100',
122
  'expirationMonth' => '05',
123
  'expirationYear' => '2011'
124
- ));
125
  $this->assertTrue($result->success);
126
  $this->assertEquals($customer->id, $result->creditCard->customerId);
127
  $this->assertEquals('510510', $result->creditCard->bin);
@@ -130,105 +160,105 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
130
  $this->assertEquals('05/2011', $result->creditCard->expirationDate);
131
  }
132
 
133
- function testCreate_withSpecifyingToken()
134
  {
135
  $token = strval(rand());
136
- $customer = Braintree_Customer::createNoValidate();
137
- $result = Braintree_CreditCard::create(array(
138
  'customerId' => $customer->id,
139
  'number' => '5105105105105100',
140
  'expirationDate' => '05/2011',
141
  'token' => $token
142
- ));
143
  $this->assertTrue($result->success);
144
  $this->assertEquals($token, $result->creditCard->token);
145
- $this->assertEquals($token, Braintree_CreditCard::find($token)->token);
146
  }
147
 
148
- function testCreate_withDuplicateCardCheck()
149
  {
150
- $customer = Braintree_Customer::createNoValidate();
151
 
152
- $attributes = array(
153
  'customerId' => $customer->id,
154
  'number' => '5105105105105100',
155
  'expirationDate' => '05/2011',
156
- 'options' => array('failOnDuplicatePaymentMethod' => true)
157
- );
158
- Braintree_CreditCard::create($attributes);
159
 
160
- $result = Braintree_CreditCard::create($attributes);
161
  $this->assertFalse($result->success);
162
  $errors = $result->errors->forKey('creditCard')->onAttribute('number');
163
- $this->assertEquals(Braintree_Error_Codes::CREDIT_CARD_DUPLICATE_CARD_EXISTS, $errors[0]->code);
164
  $this->assertEquals(1, preg_match('/Duplicate card exists in the vault\./', $result->message));
165
  }
166
 
167
- function testCreate_withCardVerification()
168
  {
169
- $customer = Braintree_Customer::createNoValidate();
170
- $result = Braintree_CreditCard::create(array(
171
  'customerId' => $customer->id,
172
  'number' => '5105105105105100',
173
  'expirationDate' => '05/2011',
174
- 'options' => array('verifyCard' => true)
175
- ));
176
  $this->assertFalse($result->success);
177
- $this->assertEquals(Braintree_Result_CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
178
  $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
179
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
180
  $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
181
  $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
182
  $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
183
  $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
184
- $this->assertEquals(Braintree_CreditCard::PREPAID_UNKNOWN, $result->creditCardVerification->creditCard["prepaid"]);
185
  }
186
 
187
- function testCreate_withCardVerificationReturnsVerificationWithRiskData()
188
  {
189
- $customer = Braintree_Customer::createNoValidate();
190
- $result = Braintree_CreditCard::create(array(
191
  'customerId' => $customer->id,
192
  'number' => '4111111111111111',
193
  'expirationDate' => '05/2011',
194
- 'options' => array('verifyCard' => true)
195
- ));
196
  $this->assertTrue($result->success);
197
  $this->assertNotNull($result->creditCard->verification->riskData);
198
  $this->assertNotNull($result->creditCard->verification->riskData->decision);
199
  }
200
 
201
- function testCreate_withCardVerificationAndOverriddenAmount()
202
  {
203
- $customer = Braintree_Customer::createNoValidate();
204
- $result = Braintree_CreditCard::create(array(
205
  'customerId' => $customer->id,
206
  'number' => '5105105105105100',
207
  'expirationDate' => '05/2011',
208
- 'options' => array('verifyCard' => true, 'verificationAmount' => '1.02')
209
- ));
210
  $this->assertFalse($result->success);
211
- $this->assertEquals(Braintree_Result_CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
212
  $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
213
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
214
  $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
215
  $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
216
  $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
217
  $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
218
- $this->assertEquals(Braintree_CreditCard::PREPAID_UNKNOWN, $result->creditCardVerification->creditCard["prepaid"]);
219
  }
220
 
221
- function testCreate_withCardVerificationAndSpecificMerchantAccount()
222
  {
223
- $customer = Braintree_Customer::createNoValidate();
224
- $result = Braintree_CreditCard::create(array(
225
  'customerId' => $customer->id,
226
  'number' => '5105105105105100',
227
  'expirationDate' => '05/2011',
228
- 'options' => array('verificationMerchantAccountId' => Braintree_TestHelper::nonDefaultMerchantAccountId(), 'verifyCard' => true)
229
- ));
230
  $this->assertFalse($result->success);
231
- $this->assertEquals(Braintree_Result_CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
232
  $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
233
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
234
  $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
@@ -237,15 +267,15 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
237
  $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
238
  }
239
 
240
- function testCreate_withBillingAddress()
241
  {
242
- $customer = Braintree_Customer::createNoValidate();
243
- $result = Braintree_CreditCard::create(array(
244
  'customerId' => $customer->id,
245
  'cardholderName' => 'Peter Tomlin',
246
  'number' => '5105105105105100',
247
  'expirationDate' => '05/12',
248
- 'billingAddress' => array(
249
  'firstName' => 'Drew',
250
  'lastName' => 'Smith',
251
  'company' => 'Smith Co.',
@@ -258,8 +288,8 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
258
  'countryCodeAlpha2' => 'FM',
259
  'countryCodeAlpha3' => 'FSM',
260
  'countryCodeNumeric' => '583'
261
- )
262
- ));
263
  $this->assertTrue($result->success);
264
  $this->assertEquals($customer->id, $result->creditCard->customerId);
265
  $this->assertEquals('510510', $result->creditCard->bin);
@@ -281,119 +311,119 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
281
  $this->assertEquals('583', $address->countryCodeNumeric);
282
  }
283
 
284
- function testCreate_withExistingBillingAddress()
285
  {
286
- $customer = Braintree_Customer::createNoValidate();
287
- $existingAddress = Braintree_Address::createNoValidate(array(
288
  'customerId' => $customer->id,
289
  'firstName' => 'John'
290
- ));
291
- $result = Braintree_CreditCard::create(array(
292
  'customerId' => $customer->id,
293
  'number' => '5105105105105100',
294
  'expirationDate' => '05/12',
295
  'billingAddressId' => $existingAddress->id
296
- ));
297
  $this->assertTrue($result->success);
298
  $address = $result->creditCard->billingAddress;
299
  $this->assertEquals($existingAddress->id, $address->id);
300
  $this->assertEquals('John', $address->firstName);
301
  }
302
 
303
- function testCreate_withValidationErrors()
304
  {
305
- $customer = Braintree_Customer::createNoValidate();
306
- $result = Braintree_CreditCard::create(array(
307
  'expirationDate' => 'invalid',
308
- 'billingAddress' => array(
309
  'countryName' => 'Tuvalu',
310
  'countryCodeAlpha2' => 'US'
311
- )
312
- ));
313
  $this->assertFalse($result->success);
314
  $errors = $result->errors->forKey('creditCard')->onAttribute('expirationDate');
315
- $this->assertEquals(Braintree_Error_Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID, $errors[0]->code);
316
  $this->assertEquals(1, preg_match('/Credit card number is required\./', $result->message));
317
  $this->assertEquals(1, preg_match('/Customer ID is required\./', $result->message));
318
  $this->assertEquals(1, preg_match('/Expiration date is invalid\./', $result->message));
319
 
320
  $errors = $result->errors->forKey('creditCard')->forKey('billingAddress')->onAttribute('base');
321
- $this->assertEquals(Braintree_Error_Codes::ADDRESS_INCONSISTENT_COUNTRY, $errors[0]->code);
322
  }
323
 
324
- function testCreate_withVenmoSdkPaymentMethodCode()
325
  {
326
- $customer = Braintree_Customer::createNoValidate();
327
- $result = Braintree_CreditCard::create(array(
328
  'customerId' => $customer->id,
329
- 'venmoSdkPaymentMethodCode' => Braintree_Test_VenmoSdk::generateTestPaymentMethodCode("378734493671000")
330
- ));
331
  $this->assertTrue($result->success);
332
  $this->assertEquals("378734", $result->creditCard->bin);
333
  }
334
 
335
- function testCreate_with_invalid_venmoSdkPaymentMethodCode()
336
  {
337
- $customer = Braintree_Customer::createNoValidate();
338
- $result = Braintree_CreditCard::create(array(
339
  'customerId' => $customer->id,
340
- 'venmoSdkPaymentMethodCode' => Braintree_Test_VenmoSdk::getInvalidPaymentMethodCode()
341
- ));
342
  $this->assertFalse($result->success);
343
  $errors = $result->errors->forKey('creditCard')->onAttribute('venmoSdkPaymentMethodCode');
344
- $this->assertEquals($errors[0]->code, Braintree_Error_Codes::CREDIT_CARD_INVALID_VENMO_SDK_PAYMENT_METHOD_CODE);
345
 
346
  }
347
 
348
- function testCreate_with_venmoSdkSession()
349
  {
350
- $customer = Braintree_Customer::createNoValidate();
351
- $result = Braintree_CreditCard::create(array(
352
  'customerId' => $customer->id,
353
  'number' => '5105105105105100',
354
  'expirationDate' => '05/12',
355
- 'options' => array(
356
- 'venmoSdkSession' => Braintree_Test_VenmoSdk::getTestSession()
357
- )
358
- ));
359
  $this->assertTrue($result->success);
360
  $this->assertTrue($result->creditCard->isVenmoSdk());
361
  }
362
 
363
- function testCreate_with_invalidVenmoSdkSession()
364
  {
365
- $customer = Braintree_Customer::createNoValidate();
366
- $result = Braintree_CreditCard::create(array(
367
  'customerId' => $customer->id,
368
  'number' => '5105105105105100',
369
  'expirationDate' => '05/12',
370
- 'options' => array(
371
- 'venmoSdkSession' => Braintree_Test_VenmoSdk::getInvalidTestSession()
372
- )
373
- ));
374
  $this->assertTrue($result->success);
375
  $this->assertFalse($result->creditCard->isVenmoSdk());
376
  }
377
 
378
- function testCreateNoValidate_throwsIfValidationsFail()
379
  {
380
 
381
- $this->setExpectedException('Braintree_Exception_ValidationsFailed');
382
- $customer = Braintree_Customer::createNoValidate();
383
- Braintree_CreditCard::createNoValidate(array(
384
  'expirationDate' => 'invalid',
385
- ));
386
  }
387
 
388
- function testCreateNoValidate_returnsCreditCardIfValid()
389
  {
390
- $customer = Braintree_Customer::createNoValidate();
391
- $creditCard = Braintree_CreditCard::createNoValidate(array(
392
  'customerId' => $customer->id,
393
  'cardholderName' => 'Cardholder',
394
  'number' => '5105105105105100',
395
  'expirationDate' => '05/12'
396
- ));
397
  $this->assertEquals($customer->id, $creditCard->customerId);
398
  $this->assertEquals('510510', $creditCard->bin);
399
  $this->assertEquals('5100', $creditCard->last4);
@@ -401,114 +431,114 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
401
  $this->assertEquals('05/2012', $creditCard->expirationDate);
402
  }
403
 
404
- function testCreateFromTransparentRedirect()
405
  {
406
- Braintree_TestHelper::suppressDeprecationWarnings();
407
- $customer = Braintree_Customer::createNoValidate();
408
  $queryString = $this->createCreditCardViaTr(
409
- array(
410
- 'credit_card' => array(
411
  'number' => '5105105105105100',
412
  'expiration_date' => '05/12'
413
- )
414
- ),
415
- array(
416
- 'creditCard' => array(
417
  'customerId' => $customer->id
418
- )
419
- )
420
  );
421
- $result = Braintree_CreditCard::createFromTransparentRedirect($queryString);
422
  $this->assertTrue($result->success);
423
  $this->assertEquals('510510', $result->creditCard->bin);
424
  $this->assertEquals('5100', $result->creditCard->last4);
425
  $this->assertEquals('05/2012', $result->creditCard->expirationDate);
426
  }
427
 
428
- function testCreateFromTransparentRedirect_withDefault()
429
  {
430
- Braintree_TestHelper::suppressDeprecationWarnings();
431
- $customer = Braintree_Customer::createNoValidate();
432
  $queryString = $this->createCreditCardViaTr(
433
- array(
434
- 'credit_card' => array(
435
  'number' => '5105105105105100',
436
  'expiration_date' => '05/12',
437
- 'options' => array('make_default' => true)
438
- )
439
- ),
440
- array(
441
- 'creditCard' => array(
442
  'customerId' => $customer->id
443
- )
444
- )
445
  );
446
- $result = Braintree_CreditCard::createFromTransparentRedirect($queryString);
447
  $this->assertTrue($result->creditCard->isDefault());
448
  }
449
 
450
- function testUpdateFromTransparentRedirect()
451
  {
452
- $customer = Braintree_Customer::createNoValidate();
453
- $creditCard = Braintree_CreditCard::createNoValidate(array(
454
  'customerId' => $customer->id,
455
  'number' => '5105105105105100',
456
  'expirationDate' => '05/12'
457
- ));
458
  $queryString = $this->updateCreditCardViaTr(
459
- array(
460
- 'credit_card' => array(
461
  'number' => '4111111111111111',
462
  'expiration_date' => '01/11'
463
- )
464
- ),
465
- array('paymentMethodToken' => $creditCard->token)
466
  );
467
- $result = Braintree_CreditCard::updateFromTransparentRedirect($queryString);
468
  $this->assertTrue($result->success);
469
  $this->assertEquals('411111', $result->creditCard->bin);
470
  $this->assertEquals('1111', $result->creditCard->last4);
471
  $this->assertEquals('01/2011', $result->creditCard->expirationDate);
472
  }
473
 
474
- function testUpdateFromTransparentRedirect_withDefault()
475
  {
476
- $customer = Braintree_Customer::createNoValidate();
477
- $card1 = Braintree_CreditCard::createNoValidate(array(
478
  'customerId' => $customer->id,
479
  'number' => '5105105105105100',
480
  'expirationDate' => '05/12'
481
- ));
482
- $card2 = Braintree_CreditCard::createNoValidate(array(
483
  'customerId' => $customer->id,
484
  'number' => '5105105105105100',
485
  'expirationDate' => '05/12'
486
- ));
487
  $this->assertFalse($card2->isDefault());
488
 
489
  $queryString = $this->updateCreditCardViaTr(
490
- array(
491
- 'credit_card' => array(
492
- 'options' => array(
493
  'make_default' => true
494
- )
495
- )
496
- ),
497
- array('paymentMethodToken' => $card2->token)
498
  );
499
- $result = Braintree_CreditCard::updateFromTransparentRedirect($queryString);
500
- $this->assertFalse(Braintree_CreditCard::find($card1->token)->isDefault());
501
- $this->assertTrue(Braintree_CreditCard::find($card2->token)->isDefault());
502
  }
503
 
504
- function testUpdateFromTransparentRedirect_andUpdateExistingBillingAddress()
505
  {
506
- $customer = Braintree_Customer::createNoValidate();
507
- $card = Braintree_CreditCard::createNoValidate(array(
508
  'customerId' => $customer->id,
509
  'number' => '5105105105105100',
510
  'expirationDate' => '05/12',
511
- 'billingAddress' => array(
512
  'firstName' => 'Drew',
513
  'lastName' => 'Smith',
514
  'company' => 'Smith Co.',
@@ -518,165 +548,165 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
518
  'region' => 'IL',
519
  'postalCode' => '60622',
520
  'countryName' => 'United States of America'
521
- )
522
- ));
523
 
524
  $queryString = $this->updateCreditCardViaTr(
525
- array(),
526
- array(
527
  'paymentMethodToken' => $card->token,
528
- 'creditCard' => array(
529
- 'billingAddress' => array(
530
  'streetAddress' => '123 New St',
531
  'locality' => 'St. Louis',
532
  'region' => 'MO',
533
  'postalCode' => '63119',
534
- 'options' => array(
535
  'updateExisting' => True
536
- )
537
- )
538
- )
539
- )
540
  );
541
- $result = Braintree_CreditCard::updateFromTransparentRedirect($queryString);
542
  $this->assertTrue($result->success);
543
  $card = $result->creditCard;
544
- $this->assertEquals(1, sizeof(Braintree_Customer::find($customer->id)->addresses));
545
  $this->assertEquals('123 New St', $card->billingAddress->streetAddress);
546
  $this->assertEquals('St. Louis', $card->billingAddress->locality);
547
  $this->assertEquals('MO', $card->billingAddress->region);
548
  $this->assertEquals('63119', $card->billingAddress->postalCode);
549
  }
550
 
551
- function testSale_createsASaleUsingGivenToken()
552
  {
553
- $customer = Braintree_Customer::createNoValidate(array(
554
- 'creditCard' => array(
555
  'number' => '5105105105105100',
556
  'expirationDate' => '05/12'
557
- )
558
- ));
559
  $creditCard = $customer->creditCards[0];
560
- $result = Braintree_CreditCard::sale($creditCard->token, array(
561
  'amount' => '100.00'
562
- ));
563
  $this->assertTrue($result->success);
564
  $this->assertEquals('100.00', $result->transaction->amount);
565
  $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
566
  $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
567
  }
568
 
569
- function testSaleNoValidate_createsASaleUsingGivenToken()
570
  {
571
- $customer = Braintree_Customer::createNoValidate(array(
572
- 'creditCard' => array(
573
  'number' => '5105105105105100',
574
  'expirationDate' => '05/12'
575
- )
576
- ));
577
  $creditCard = $customer->creditCards[0];
578
- $transaction = Braintree_CreditCard::saleNoValidate($creditCard->token, array(
579
  'amount' => '100.00'
580
- ));
581
  $this->assertEquals('100.00', $transaction->amount);
582
  $this->assertEquals($customer->id, $transaction->customerDetails->id);
583
  $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
584
  }
585
 
586
- function testSaleNoValidate_createsASaleUsingGivenTokenAndCvv()
587
  {
588
- $customer = Braintree_Customer::createNoValidate(array(
589
- 'creditCard' => array(
590
  'number' => '5105105105105100',
591
  'expirationDate' => '05/12'
592
- )
593
- ));
594
  $creditCard = $customer->creditCards[0];
595
- $transaction = Braintree_CreditCard::saleNoValidate($creditCard->token, array(
596
  'amount' => '100.00',
597
- 'creditCard' => array(
598
  'cvv' => '301'
599
- )
600
- ));
601
  $this->assertEquals('100.00', $transaction->amount);
602
  $this->assertEquals($customer->id, $transaction->customerDetails->id);
603
  $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
604
  $this->assertEquals('S', $transaction->cvvResponseCode);
605
  }
606
 
607
- function testSaleNoValidate_throwsIfInvalid()
608
  {
609
- $customer = Braintree_Customer::createNoValidate(array(
610
- 'creditCard' => array(
611
  'number' => '5105105105105100',
612
  'expirationDate' => '05/12'
613
- )
614
- ));
615
  $creditCard = $customer->creditCards[0];
616
- $this->setExpectedException('Braintree_Exception_ValidationsFailed');
617
- Braintree_CreditCard::saleNoValidate($creditCard->token, array(
618
  'amount' => 'invalid'
619
- ));
620
  }
621
 
622
- function testCredit_createsACreditUsingGivenToken()
623
  {
624
- $customer = Braintree_Customer::createNoValidate(array(
625
- 'creditCard' => array(
626
  'number' => '5105105105105100',
627
  'expirationDate' => '05/12'
628
- )
629
- ));
630
  $creditCard = $customer->creditCards[0];
631
- $result = Braintree_CreditCard::credit($creditCard->token, array(
632
  'amount' => '100.00'
633
- ));
634
  $this->assertTrue($result->success);
635
  $this->assertEquals('100.00', $result->transaction->amount);
636
- $this->assertEquals(Braintree_Transaction::CREDIT, $result->transaction->type);
637
  $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
638
  $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
639
  }
640
 
641
- function testCreditNoValidate_createsACreditUsingGivenToken()
642
  {
643
- $customer = Braintree_Customer::createNoValidate(array(
644
- 'creditCard' => array(
645
  'number' => '5105105105105100',
646
  'expirationDate' => '05/12'
647
- )
648
- ));
649
  $creditCard = $customer->creditCards[0];
650
- $transaction = Braintree_CreditCard::creditNoValidate($creditCard->token, array(
651
  'amount' => '100.00'
652
- ));
653
  $this->assertEquals('100.00', $transaction->amount);
654
- $this->assertEquals(Braintree_Transaction::CREDIT, $transaction->type);
655
  $this->assertEquals($customer->id, $transaction->customerDetails->id);
656
  $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
657
  }
658
 
659
- function testCreditNoValidate_throwsIfInvalid()
660
  {
661
- $customer = Braintree_Customer::createNoValidate(array(
662
- 'creditCard' => array(
663
  'number' => '5105105105105100',
664
  'expirationDate' => '05/12'
665
- )
666
- ));
667
  $creditCard = $customer->creditCards[0];
668
- $this->setExpectedException('Braintree_Exception_ValidationsFailed');
669
- Braintree_CreditCard::creditNoValidate($creditCard->token, array(
670
  'amount' => 'invalid'
671
- ));
672
  }
673
 
674
- function testExpired()
675
  {
676
- $collection = Braintree_CreditCard::expired();
677
  $this->assertTrue($collection->maximumCount() > 1);
678
 
679
- $arr = array();
680
  foreach($collection as $creditCard) {
681
  $this->assertTrue($creditCard->isExpired());
682
  array_push($arr, $creditCard->token);
@@ -686,15 +716,15 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
686
  }
687
 
688
 
689
- function testExpiringBetween()
690
  {
691
- $collection = Braintree_CreditCard::expiringBetween(
692
  mktime(0, 0, 0, 1, 1, 2010),
693
  mktime(23, 59, 59, 12, 31, 2010)
694
  );
695
  $this->assertTrue($collection->maximumCount() > 1);
696
 
697
- $arr = array();
698
  foreach($collection as $creditCard) {
699
  $this->assertEquals('2010', $creditCard->expirationYear);
700
  array_push($arr, $creditCard->token);
@@ -703,9 +733,9 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
703
  $this->assertEquals($collection->maximumCount(), count($uniqueCreditCardTokens));
704
  }
705
 
706
- function testExpiringBetween_parsesCreditCardDetailsUnderTransactionsCorrectly()
707
  {
708
- $collection = Braintree_CreditCard::expiringBetween(
709
  mktime(0, 0, 0, 1, 1, 2010),
710
  mktime(23, 59, 59, 12, 31, 2010)
711
  );
@@ -720,34 +750,34 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
720
  }
721
  }
722
 
723
- function testFind()
724
  {
725
- $customer = Braintree_Customer::createNoValidate();
726
- $result = Braintree_CreditCard::create(array(
727
  'customerId' => $customer->id,
728
  'cardholderName' => 'Cardholder',
729
  'number' => '5105105105105100',
730
  'expirationDate' => '05/12'
731
- ));
732
  $this->assertTrue($result->success);
733
- $creditCard = Braintree_CreditCard::find($result->creditCard->token);
734
  $this->assertEquals($customer->id, $creditCard->customerId);
735
  $this->assertEquals('510510', $creditCard->bin);
736
  $this->assertEquals('5100', $creditCard->last4);
737
  $this->assertEquals('Cardholder', $creditCard->cardholderName);
738
  $this->assertEquals('05/2012', $creditCard->expirationDate);
739
- $this->assertEquals(array(), $creditCard->subscriptions);
740
  }
741
 
742
- function testFindReturnsAssociatedSubscriptions()
743
  {
744
- $customer = Braintree_Customer::createNoValidate();
745
- $result = Braintree_CreditCard::create(array(
746
  'customerId' => $customer->id,
747
  'cardholderName' => 'Cardholder',
748
  'number' => '5105105105105100',
749
  'expirationDate' => '05/12',
750
- 'billingAddress' => array(
751
  'firstName' => 'Drew',
752
  'lastName' => 'Smith',
753
  'company' => 'Smith Co.',
@@ -757,107 +787,107 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
757
  'region' => 'IL',
758
  'postalCode' => '60622',
759
  'countryName' => 'United States of America'
760
- )
761
- ));
762
  $id = strval(rand());
763
- Braintree_Subscription::create(array(
764
  'id' => $id,
765
  'paymentMethodToken' => $result->creditCard->token,
766
  'planId' => 'integration_trialless_plan',
767
  'price' => '1.00'
768
- ));
769
- $creditCard = Braintree_CreditCard::find($result->creditCard->token);
770
  $this->assertEquals($id, $creditCard->subscriptions[0]->id);
771
  $this->assertEquals('integration_trialless_plan', $creditCard->subscriptions[0]->planId);
772
  $this->assertEquals('1.00', $creditCard->subscriptions[0]->price);
773
  }
774
 
775
- function testFind_throwsIfCannotBeFound()
776
  {
777
- $this->setExpectedException('Braintree_Exception_NotFound');
778
- Braintree_CreditCard::find('invalid-token');
779
  }
780
 
781
- function testFind_throwsUsefulErrorMessagesWhenEmpty()
782
  {
783
  $this->setExpectedException('InvalidArgumentException', 'expected credit card id to be set');
784
- Braintree_CreditCard::find('');
785
  }
786
 
787
- function testFind_throwsUsefulErrorMessagesWhenInvalid()
788
  {
789
  $this->setExpectedException('InvalidArgumentException', '@ is an invalid credit card token');
790
- Braintree_CreditCard::find('@');
791
  }
792
 
793
- function testFromNonce()
794
  {
795
- $customer = Braintree_Customer::createNoValidate();
796
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
797
- $nonce = $http->nonce_for_new_card(array(
798
- "credit_card" => array(
799
  "number" => "4009348888881881",
800
  "expirationMonth" => "11",
801
  "expirationYear" => "2099"
802
- ),
803
  "customerId" => $customer->id
804
- ));
805
 
806
- $creditCard = Braintree_CreditCard::fromNonce($nonce);
807
 
808
- $customer = Braintree_Customer::find($customer->id);
809
  $this->assertEquals($customer->creditCards[0], $creditCard);
810
  }
811
 
812
- function testFromNonce_ReturnsErrorWhenNoncePointsToSharedCard()
813
  {
814
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
815
- $nonce = $http->nonce_for_new_card(array(
816
- "credit_card" => array(
817
  "number" => "4009348888881881",
818
  "expirationMonth" => "11",
819
  "expirationYear" => "2099"
820
- ),
821
  "share" => true
822
- ));
823
 
824
- $this->setExpectedException('Braintree_Exception_NotFound', "not found");
825
- Braintree_CreditCard::fromNonce($nonce);
826
  }
827
 
828
- function testFromNonce_ReturnsErrorWhenNonceIsConsumed()
829
  {
830
- $customer = Braintree_Customer::createNoValidate();
831
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
832
- $nonce = $http->nonce_for_new_card(array(
833
- "credit_card" => array(
834
  "number" => "4009348888881881",
835
  "expirationMonth" => "11",
836
  "expirationYear" => "2099"
837
- ),
838
  "customerId" => $customer->id
839
- ));
840
 
841
- Braintree_CreditCard::fromNonce($nonce);
842
- $this->setExpectedException('Braintree_Exception_NotFound', "consumed");
843
- Braintree_CreditCard::fromNonce($nonce);
844
  }
845
 
846
- function testUpdate()
847
  {
848
- $customer = Braintree_Customer::createNoValidate();
849
- $createResult = Braintree_CreditCard::create(array(
850
  'customerId' => $customer->id,
851
  'cardholderName' => 'Old Cardholder',
852
  'number' => '5105105105105100',
853
  'expirationDate' => '05/12'
854
- ));
855
  $this->assertTrue($createResult->success);
856
- $updateResult = Braintree_CreditCard::update($createResult->creditCard->token, array(
857
  'cardholderName' => 'New Cardholder',
858
  'number' => '4111111111111111',
859
  'expirationDate' => '07/14'
860
- ));
861
  $this->assertEquals($customer->id, $updateResult->creditCard->customerId);
862
  $this->assertEquals('411111', $updateResult->creditCard->bin);
863
  $this->assertEquals('1111', $updateResult->creditCard->last4);
@@ -865,103 +895,103 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
865
  $this->assertEquals('07/2014', $updateResult->creditCard->expirationDate);
866
  }
867
 
868
- function testUpdate_withCardVerification()
869
  {
870
- $customer = Braintree_Customer::createNoValidate();
871
- $initialCreditCard = Braintree_CreditCard::create(array(
872
  'customerId' => $customer->id,
873
  'number' => '5105105105105100',
874
  'expirationDate' => '05/12'
875
- ))->creditCard;
876
 
877
- $result = Braintree_CreditCard::update($initialCreditCard->token, array(
878
- 'billingAddress' => array(
879
  'region' => 'IL'
880
- ),
881
- 'options' => array('verifyCard' => true)
882
- ));
883
  $this->assertFalse($result->success);
884
- $this->assertEquals(Braintree_Result_CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
885
  $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
886
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
887
  $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
888
  $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
889
  $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
890
  $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
891
- $this->assertEquals(Braintree_TestHelper::defaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
892
  }
893
 
894
- function testUpdate_withCardVerificationAndSpecificMerchantAccount()
895
  {
896
- $customer = Braintree_Customer::createNoValidate();
897
- $initialCreditCard = Braintree_CreditCard::create(array(
898
  'customerId' => $customer->id,
899
  'number' => '5105105105105100',
900
  'expirationDate' => '05/12'
901
- ))->creditCard;
902
 
903
- $result = Braintree_CreditCard::update($initialCreditCard->token, array(
904
- 'billingAddress' => array(
905
  'region' => 'IL'
906
- ),
907
- 'options' => array(
908
- 'verificationMerchantAccountId' => Braintree_TestHelper::nonDefaultMerchantAccountId(),
909
  'verifyCard' => true
910
- )
911
- ));
912
  $this->assertFalse($result->success);
913
- $this->assertEquals(Braintree_Result_CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
914
- $this->assertEquals(Braintree_TestHelper::nonDefaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
915
  }
916
 
917
- function testUpdate_createsNewBillingAddressByDefault()
918
  {
919
- $customer = Braintree_Customer::createNoValidate();
920
- $initialCreditCard = Braintree_CreditCard::create(array(
921
  'customerId' => $customer->id,
922
  'number' => '5105105105105100',
923
  'expirationDate' => '05/12',
924
- 'billingAddress' => array(
925
  'streetAddress' => '123 Nigeria Ave'
926
- )
927
- ))->creditCard;
928
 
929
- $updatedCreditCard = Braintree_CreditCard::update($initialCreditCard->token, array(
930
- 'billingAddress' => array(
931
  'region' => 'IL'
932
- )
933
- ))->creditCard;
934
  $this->assertEquals('IL', $updatedCreditCard->billingAddress->region);
935
  $this->assertNull($updatedCreditCard->billingAddress->streetAddress);
936
  $this->assertNotEquals($initialCreditCard->billingAddress->id, $updatedCreditCard->billingAddress->id);
937
  }
938
 
939
- function testUpdate_updatesExistingBillingAddressIfUpdateExistingOptionIsTrue()
940
  {
941
- $customer = Braintree_Customer::createNoValidate();
942
- $initialCreditCard = Braintree_CreditCard::create(array(
943
  'customerId' => $customer->id,
944
  'number' => '5105105105105100',
945
  'expirationDate' => '05/12',
946
- 'billingAddress' => array(
947
  'countryName' => 'Turkey',
948
  'countryCodeAlpha2' => 'TR',
949
  'countryCodeAlpha3' => 'TUR',
950
  'countryCodeNumeric' => '792',
951
- )
952
- ))->creditCard;
953
 
954
- $updatedCreditCard = Braintree_CreditCard::update($initialCreditCard->token, array(
955
- 'billingAddress' => array(
956
  'countryName' => 'Thailand',
957
  'countryCodeAlpha2' => 'TH',
958
  'countryCodeAlpha3' => 'THA',
959
  'countryCodeNumeric' => '764',
960
- 'options' => array(
961
  'updateExisting' => True
962
- )
963
- )
964
- ))->creditCard;
965
  $this->assertEquals('Thailand', $updatedCreditCard->billingAddress->countryName);
966
  $this->assertEquals('TH', $updatedCreditCard->billingAddress->countryCodeAlpha2);
967
  $this->assertEquals('THA', $updatedCreditCard->billingAddress->countryCodeAlpha3);
@@ -969,41 +999,41 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
969
  $this->assertEquals($initialCreditCard->billingAddress->id, $updatedCreditCard->billingAddress->id);
970
  }
971
 
972
- function testUpdate_canChangeToken()
973
  {
974
  $oldToken = strval(rand());
975
  $newToken = strval(rand());
976
 
977
- $customer = Braintree_Customer::createNoValidate();
978
- $createResult = Braintree_CreditCard::create(array(
979
  'customerId' => $customer->id,
980
  'token' => $oldToken,
981
  'number' => '5105105105105100',
982
  'expirationDate' => '05/12'
983
- ));
984
  $this->assertTrue($createResult->success);
985
- $updateResult = Braintree_CreditCard::update($oldToken, array(
986
  'token' => $newToken
987
- ));
988
  $this->assertEquals($customer->id, $updateResult->creditCard->customerId);
989
  $this->assertEquals($newToken, $updateResult->creditCard->token);
990
- $this->assertEquals($newToken, Braintree_CreditCard::find($newToken)->token);
991
  }
992
 
993
- function testUpdateNoValidate()
994
  {
995
- $customer = Braintree_Customer::createNoValidate();
996
- $creditCard = Braintree_CreditCard::createNoValidate(array(
997
  'customerId' => $customer->id,
998
  'cardholderName' => 'Old Cardholder',
999
  'number' => '5105105105105100',
1000
  'expirationDate' => '05/12'
1001
- ));
1002
- $updatedCard = Braintree_CreditCard::updateNoValidate($creditCard->token, array(
1003
  'cardholderName' => 'New Cardholder',
1004
  'number' => '4111111111111111',
1005
  'expirationDate' => '07/14'
1006
- ));
1007
  $this->assertEquals($customer->id, $updatedCard->customerId);
1008
  $this->assertEquals('411111', $updatedCard->bin);
1009
  $this->assertEquals('1111', $updatedCard->last4);
@@ -1011,279 +1041,279 @@ class Braintree_CreditCardTest extends PHPUnit_Framework_TestCase
1011
  $this->assertEquals('07/2014', $updatedCard->expirationDate);
1012
  }
1013
 
1014
- function testUpdateNoValidate_throwsIfInvalid()
1015
  {
1016
- $customer = Braintree_Customer::createNoValidate();
1017
- $creditCard = Braintree_CreditCard::createNoValidate(array(
1018
  'customerId' => $customer->id,
1019
  'cardholderName' => 'Old Cardholder',
1020
  'number' => '5105105105105100',
1021
  'expirationDate' => '05/12'
1022
- ));
1023
- $this->setExpectedException('Braintree_Exception_ValidationsFailed');
1024
- Braintree_CreditCard::updateNoValidate($creditCard->token, array(
1025
  'number' => 'invalid',
1026
- ));
1027
  }
1028
 
1029
- function testUpdate_withDefault()
1030
  {
1031
- $customer = Braintree_Customer::createNoValidate();
1032
- $card1 = Braintree_CreditCard::create(array(
1033
  'customerId' => $customer->id,
1034
  'cardholderName' => 'Cardholder',
1035
  'number' => '5105105105105100',
1036
  'expirationDate' => '05/12'
1037
- ))->creditCard;
1038
- $card2 = Braintree_CreditCard::create(array(
1039
  'customerId' => $customer->id,
1040
  'cardholderName' => 'Cardholder',
1041
  'number' => '5105105105105100',
1042
  'expirationDate' => '05/12'
1043
- ))->creditCard;
1044
 
1045
  $this->assertTrue($card1->isDefault());
1046
  $this->assertFalse($card2->isDefault());
1047
 
1048
- Braintree_CreditCard::update($card2->token, array(
1049
- 'options' => array('makeDefault' => true)
1050
- ))->creditCard;
1051
 
1052
- $this->assertFalse(Braintree_CreditCard::find($card1->token)->isDefault());
1053
- $this->assertTrue(Braintree_CreditCard::find($card2->token)->isDefault());
1054
  }
1055
 
1056
- function testDelete_deletesThePaymentMethod()
1057
  {
1058
- $customer = Braintree_Customer::createNoValidate(array());
1059
- $creditCard = Braintree_CreditCard::createNoValidate(array(
1060
  'customerId' => $customer->id,
1061
  'number' => '5105105105105100',
1062
  'expirationDate' => '05/12'
1063
- ));
1064
- Braintree_CreditCard::find($creditCard->token);
1065
- Braintree_CreditCard::delete($creditCard->token);
1066
- $this->setExpectedException('Braintree_Exception_NotFound');
1067
- Braintree_CreditCard::find($creditCard->token);
1068
  }
1069
 
1070
- function testGatewayRejectionOnCVV()
1071
  {
1072
- $old_merchant_id = Braintree_Configuration::merchantId();
1073
- $old_public_key = Braintree_Configuration::publicKey();
1074
- $old_private_key = Braintree_Configuration::privateKey();
1075
 
1076
- Braintree_Configuration::merchantId('processing_rules_merchant_id');
1077
- Braintree_Configuration::publicKey('processing_rules_public_key');
1078
- Braintree_Configuration::privateKey('processing_rules_private_key');
1079
 
1080
- $customer = Braintree_Customer::createNoValidate();
1081
- $result = Braintree_CreditCard::create(array(
1082
  'customerId' => $customer->id,
1083
  'number' => '4111111111111111',
1084
  'expirationDate' => '05/2011',
1085
  'cvv' => '200',
1086
- 'options' => array('verifyCard' => true)
1087
- ));
1088
 
1089
- Braintree_Configuration::merchantId($old_merchant_id);
1090
- Braintree_Configuration::publicKey($old_public_key);
1091
- Braintree_Configuration::privateKey($old_private_key);
1092
 
1093
  $this->assertFalse($result->success);
1094
- $this->assertEquals(Braintree_Transaction::CVV, $result->creditCardVerification->gatewayRejectionReason);
1095
  }
1096
 
1097
- function testGatewayRejectionIsNullOnProcessorDecline()
1098
  {
1099
- $old_merchant_id = Braintree_Configuration::merchantId();
1100
- $old_public_key = Braintree_Configuration::publicKey();
1101
- $old_private_key = Braintree_Configuration::privateKey();
1102
 
1103
- Braintree_Configuration::merchantId('processing_rules_merchant_id');
1104
- Braintree_Configuration::publicKey('processing_rules_public_key');
1105
- Braintree_Configuration::privateKey('processing_rules_private_key');
1106
 
1107
- $customer = Braintree_Customer::createNoValidate();
1108
- $result = Braintree_CreditCard::create(array(
1109
  'customerId' => $customer->id,
1110
  'number' => '5105105105105100',
1111
  'expirationDate' => '05/2011',
1112
  'cvv' => '200',
1113
- 'options' => array('verifyCard' => true)
1114
- ));
1115
 
1116
- Braintree_Configuration::merchantId($old_merchant_id);
1117
- Braintree_Configuration::publicKey($old_public_key);
1118
- Braintree_Configuration::privateKey($old_private_key);
1119
 
1120
  $this->assertFalse($result->success);
1121
  $this->assertNull($result->creditCardVerification->gatewayRejectionReason);
1122
  }
1123
 
1124
- function createCreditCardViaTr($regularParams, $trParams)
1125
  {
1126
- $trData = Braintree_TransparentRedirect::createCreditCardData(
1127
- array_merge($trParams, array("redirectUrl" => "http://www.example.com"))
1128
  );
1129
- return Braintree_TestHelper::submitTrRequest(
1130
- Braintree_CreditCard::createCreditCardUrl(),
1131
  $regularParams,
1132
  $trData
1133
  );
1134
  }
1135
 
1136
- function updateCreditCardViaTr($regularParams, $trParams)
1137
  {
1138
- $trData = Braintree_TransparentRedirect::updateCreditCardData(
1139
- array_merge($trParams, array("redirectUrl" => "http://www.example.com"))
1140
  );
1141
- return Braintree_TestHelper::submitTrRequest(
1142
- Braintree_CreditCard::updateCreditCardUrl(),
1143
  $regularParams,
1144
  $trData
1145
  );
1146
  }
1147
 
1148
- function testPrepaidCard()
1149
  {
1150
- $customer = Braintree_Customer::createNoValidate();
1151
- $result = Braintree_CreditCard::create(array(
1152
  'customerId' => $customer->id,
1153
  'cardholderName' => 'Cardholder',
1154
- 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::PREPAID,
1155
  'expirationDate' => '05/12',
1156
- 'options' => array('verifyCard' => true)
1157
- ));
1158
- $this->assertEquals(Braintree_CreditCard::PREPAID_YES, $result->creditCard->prepaid);
1159
  }
1160
 
1161
- function testCommercialCard()
1162
  {
1163
- $customer = Braintree_Customer::createNoValidate();
1164
- $result = Braintree_CreditCard::create(array(
1165
  'customerId' => $customer->id,
1166
  'cardholderName' => 'Cardholder',
1167
- 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::COMMERCIAL,
1168
  'expirationDate' => '05/12',
1169
- 'options' => array('verifyCard' => true)
1170
- ));
1171
- $this->assertEquals(Braintree_CreditCard::COMMERCIAL_YES, $result->creditCard->commercial);
1172
  }
1173
 
1174
- function testDebitCard()
1175
  {
1176
- $customer = Braintree_Customer::createNoValidate();
1177
- $result = Braintree_CreditCard::create(array(
1178
  'customerId' => $customer->id,
1179
  'cardholderName' => 'Cardholder',
1180
- 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::DEBIT,
1181
  'expirationDate' => '05/12',
1182
- 'options' => array('verifyCard' => true)
1183
- ));
1184
- $this->assertEquals(Braintree_CreditCard::DEBIT_YES, $result->creditCard->debit);
1185
  }
1186
 
1187
- function testPayrollCard()
1188
  {
1189
- $customer = Braintree_Customer::createNoValidate();
1190
- $result = Braintree_CreditCard::create(array(
1191
  'customerId' => $customer->id,
1192
  'cardholderName' => 'Cardholder',
1193
- 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::PAYROLL,
1194
  'expirationDate' => '05/12',
1195
- 'options' => array('verifyCard' => true)
1196
- ));
1197
- $this->assertEquals(Braintree_CreditCard::PAYROLL_YES, $result->creditCard->payroll);
1198
  }
1199
 
1200
- function testHealthCareCard()
1201
  {
1202
- $customer = Braintree_Customer::createNoValidate();
1203
- $result = Braintree_CreditCard::create(array(
1204
  'customerId' => $customer->id,
1205
  'cardholderName' => 'Cardholder',
1206
- 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::HEALTHCARE,
1207
  'expirationDate' => '05/12',
1208
- 'options' => array('verifyCard' => true)
1209
- ));
1210
- $this->assertEquals(Braintree_CreditCard::HEALTHCARE_YES, $result->creditCard->healthcare);
1211
  }
1212
 
1213
- function testDurbinRegulatedCard()
1214
  {
1215
- $customer = Braintree_Customer::createNoValidate();
1216
- $result = Braintree_CreditCard::create(array(
1217
  'customerId' => $customer->id,
1218
  'cardholderName' => 'Cardholder',
1219
- 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::DURBIN_REGULATED,
1220
  'expirationDate' => '05/12',
1221
- 'options' => array('verifyCard' => true)
1222
- ));
1223
- $this->assertEquals(Braintree_CreditCard::DURBIN_REGULATED_YES, $result->creditCard->durbinRegulated);
1224
  }
1225
 
1226
- function testCountryOfIssuanceCard()
1227
  {
1228
- $customer = Braintree_Customer::createNoValidate();
1229
- $result = Braintree_CreditCard::create(array(
1230
  'customerId' => $customer->id,
1231
  'cardholderName' => 'Cardholder',
1232
- 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::COUNTRY_OF_ISSUANCE,
1233
  'expirationDate' => '05/12',
1234
- 'options' => array('verifyCard' => true)
1235
- ));
1236
  $this->assertEquals("USA", $result->creditCard->countryOfIssuance);
1237
  }
1238
 
1239
- function testIssuingBankCard()
1240
  {
1241
- $customer = Braintree_Customer::createNoValidate();
1242
- $result = Braintree_CreditCard::create(array(
1243
  'customerId' => $customer->id,
1244
  'cardholderName' => 'Cardholder',
1245
- 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::ISSUING_BANK,
1246
  'expirationDate' => '05/12',
1247
- 'options' => array('verifyCard' => true)
1248
- ));
1249
  $this->assertEquals("NETWORK ONLY", $result->creditCard->issuingBank);
1250
  }
1251
 
1252
- function testNegativeCardTypeIndicators()
1253
  {
1254
- $customer = Braintree_Customer::createNoValidate();
1255
- $result = Braintree_CreditCard::create(array(
1256
  'customerId' => $customer->id,
1257
  'cardholderName' => 'Cardholder',
1258
- 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::NO,
1259
  'expirationDate' => '05/12',
1260
- 'options' => array('verifyCard' => true)
1261
- ));
1262
- $this->assertEquals(Braintree_CreditCard::PREPAID_NO, $result->creditCard->prepaid);
1263
- $this->assertEquals(Braintree_CreditCard::DURBIN_REGULATED_NO, $result->creditCard->durbinRegulated);
1264
- $this->assertEquals(Braintree_CreditCard::PAYROLL_NO, $result->creditCard->payroll);
1265
- $this->assertEquals(Braintree_CreditCard::DEBIT_NO, $result->creditCard->debit);
1266
- $this->assertEquals(Braintree_CreditCard::HEALTHCARE_NO, $result->creditCard->healthcare);
1267
- $this->assertEquals(Braintree_CreditCard::COMMERCIAL_NO, $result->creditCard->commercial);
1268
  }
1269
 
1270
- function testUnknownCardTypeIndicators()
1271
  {
1272
- $customer = Braintree_Customer::createNoValidate();
1273
- $result = Braintree_CreditCard::create(array(
1274
  'customerId' => $customer->id,
1275
  'cardholderName' => 'Cardholder',
1276
- 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::UNKNOWN,
1277
  'expirationDate' => '05/12',
1278
- 'options' => array('verifyCard' => true)
1279
- ));
1280
- $this->assertEquals(Braintree_CreditCard::PREPAID_UNKNOWN, $result->creditCard->prepaid);
1281
- $this->assertEquals(Braintree_CreditCard::DURBIN_REGULATED_UNKNOWN, $result->creditCard->durbinRegulated);
1282
- $this->assertEquals(Braintree_CreditCard::PAYROLL_UNKNOWN, $result->creditCard->payroll);
1283
- $this->assertEquals(Braintree_CreditCard::DEBIT_UNKNOWN, $result->creditCard->debit);
1284
- $this->assertEquals(Braintree_CreditCard::HEALTHCARE_UNKNOWN, $result->creditCard->healthcare);
1285
- $this->assertEquals(Braintree_CreditCard::COMMERCIAL_UNKNOWN, $result->creditCard->commercial);
1286
- $this->assertEquals(Braintree_CreditCard::COUNTRY_OF_ISSUANCE_UNKNOWN, $result->creditCard->countryOfIssuance);
1287
- $this->assertEquals(Braintree_CreditCard::ISSUING_BANK_UNKNOWN, $result->creditCard->issuingBank);
1288
  }
1289
  }
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);
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);
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);
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('2000', $result->creditCardVerification->processorResponseCode);
243
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
244
  $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
245
  $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
246
  $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
247
  $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
248
+ $this->assertEquals(Braintree\CreditCard::PREPAID_UNKNOWN, $result->creditCardVerification->creditCard['prepaid']);
249
  }
250
 
251
+ public function testCreate_withCardVerificationAndSpecificMerchantAccount()
252
  {
253
+ $customer = Braintree\Customer::createNoValidate();
254
+ $result = Braintree\CreditCard::create([
255
  'customerId' => $customer->id,
256
  'number' => '5105105105105100',
257
  'expirationDate' => '05/2011',
258
+ 'options' => ['verificationMerchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(), 'verifyCard' => true],
259
+ ]);
260
  $this->assertFalse($result->success);
261
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
262
  $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
263
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
264
  $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
267
  $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
268
  }
269
 
270
+ public function testCreate_withBillingAddress()
271
  {
272
+ $customer = Braintree\Customer::createNoValidate();
273
+ $result = Braintree\CreditCard::create([
274
  'customerId' => $customer->id,
275
  'cardholderName' => 'Peter Tomlin',
276
  'number' => '5105105105105100',
277
  'expirationDate' => '05/12',
278
+ 'billingAddress' => [
279
  'firstName' => 'Drew',
280
  'lastName' => 'Smith',
281
  'company' => 'Smith Co.',
288
  'countryCodeAlpha2' => 'FM',
289
  'countryCodeAlpha3' => 'FSM',
290
  'countryCodeNumeric' => '583'
291
+ ]
292
+ ]);
293
  $this->assertTrue($result->success);
294
  $this->assertEquals($customer->id, $result->creditCard->customerId);
295
  $this->assertEquals('510510', $result->creditCard->bin);
311
  $this->assertEquals('583', $address->countryCodeNumeric);
312
  }
313
 
314
+ public function testCreate_withExistingBillingAddress()
315
  {
316
+ $customer = Braintree\Customer::createNoValidate();
317
+ $existingAddress = Braintree\Address::createNoValidate([
318
  'customerId' => $customer->id,
319
  'firstName' => 'John'
320
+ ]);
321
+ $result = Braintree\CreditCard::create([
322
  'customerId' => $customer->id,
323
  'number' => '5105105105105100',
324
  'expirationDate' => '05/12',
325
  'billingAddressId' => $existingAddress->id
326
+ ]);
327
  $this->assertTrue($result->success);
328
  $address = $result->creditCard->billingAddress;
329
  $this->assertEquals($existingAddress->id, $address->id);
330
  $this->assertEquals('John', $address->firstName);
331
  }
332
 
333
+ public function testCreate_withValidationErrors()
334
  {
335
+ $customer = Braintree\Customer::createNoValidate();
336
+ $result = Braintree\CreditCard::create([
337
  'expirationDate' => 'invalid',
338
+ 'billingAddress' => [
339
  'countryName' => 'Tuvalu',
340
  'countryCodeAlpha2' => 'US'
341
+ ]
342
+ ]);
343
  $this->assertFalse($result->success);
344
  $errors = $result->errors->forKey('creditCard')->onAttribute('expirationDate');
345
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID, $errors[0]->code);
346
  $this->assertEquals(1, preg_match('/Credit card number is required\./', $result->message));
347
  $this->assertEquals(1, preg_match('/Customer ID is required\./', $result->message));
348
  $this->assertEquals(1, preg_match('/Expiration date is invalid\./', $result->message));
349
 
350
  $errors = $result->errors->forKey('creditCard')->forKey('billingAddress')->onAttribute('base');
351
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_INCONSISTENT_COUNTRY, $errors[0]->code);
352
  }
353
 
354
+ public function testCreate_withVenmoSdkPaymentMethodCode()
355
  {
356
+ $customer = Braintree\Customer::createNoValidate();
357
+ $result = Braintree\CreditCard::create([
358
  'customerId' => $customer->id,
359
+ 'venmoSdkPaymentMethodCode' => Braintree\Test\VenmoSdk::generateTestPaymentMethodCode('378734493671000')
360
+ ]);
361
  $this->assertTrue($result->success);
362
  $this->assertEquals("378734", $result->creditCard->bin);
363
  }
364
 
365
+ public function testCreate_with_invalid_venmoSdkPaymentMethodCode()
366
  {
367
+ $customer = Braintree\Customer::createNoValidate();
368
+ $result = Braintree\CreditCard::create([
369
  'customerId' => $customer->id,
370
+ 'venmoSdkPaymentMethodCode' => Braintree\Test\VenmoSdk::getInvalidPaymentMethodCode(),
371
+ ]);
372
  $this->assertFalse($result->success);
373
  $errors = $result->errors->forKey('creditCard')->onAttribute('venmoSdkPaymentMethodCode');
374
+ $this->assertEquals($errors[0]->code, Braintree\Error\Codes::CREDIT_CARD_INVALID_VENMO_SDK_PAYMENT_METHOD_CODE);
375
 
376
  }
377
 
378
+ public function testCreate_with_venmoSdkSession()
379
  {
380
+ $customer = Braintree\Customer::createNoValidate();
381
+ $result = Braintree\CreditCard::create([
382
  'customerId' => $customer->id,
383
  'number' => '5105105105105100',
384
  'expirationDate' => '05/12',
385
+ 'options' => [
386
+ 'venmoSdkSession' => Braintree\Test\VenmoSdk::getTestSession()
387
+ ]
388
+ ]);
389
  $this->assertTrue($result->success);
390
  $this->assertTrue($result->creditCard->isVenmoSdk());
391
  }
392
 
393
+ public function testCreate_with_invalidVenmoSdkSession()
394
  {
395
+ $customer = Braintree\Customer::createNoValidate();
396
+ $result = Braintree\CreditCard::create([
397
  'customerId' => $customer->id,
398
  'number' => '5105105105105100',
399
  'expirationDate' => '05/12',
400
+ 'options' => [
401
+ 'venmoSdkSession' => Braintree\Test\VenmoSdk::getInvalidTestSession(),
402
+ ]
403
+ ]);
404
  $this->assertTrue($result->success);
405
  $this->assertFalse($result->creditCard->isVenmoSdk());
406
  }
407
 
408
+ public function testCreateNoValidate_throwsIfValidationsFail()
409
  {
410
 
411
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
412
+ $customer = Braintree\Customer::createNoValidate();
413
+ Braintree\CreditCard::createNoValidate([
414
  'expirationDate' => 'invalid',
415
+ ]);
416
  }
417
 
418
+ public function testCreateNoValidate_returnsCreditCardIfValid()
419
  {
420
+ $customer = Braintree\Customer::createNoValidate();
421
+ $creditCard = Braintree\CreditCard::createNoValidate([
422
  'customerId' => $customer->id,
423
  'cardholderName' => 'Cardholder',
424
  'number' => '5105105105105100',
425
  'expirationDate' => '05/12'
426
+ ]);
427
  $this->assertEquals($customer->id, $creditCard->customerId);
428
  $this->assertEquals('510510', $creditCard->bin);
429
  $this->assertEquals('5100', $creditCard->last4);
431
  $this->assertEquals('05/2012', $creditCard->expirationDate);
432
  }
433
 
434
+ public function testCreateFromTransparentRedirect()
435
  {
436
+ Test\Helper::suppressDeprecationWarnings();
437
+ $customer = Braintree\Customer::createNoValidate();
438
  $queryString = $this->createCreditCardViaTr(
439
+ [
440
+ 'credit_card' => [
441
  'number' => '5105105105105100',
442
  'expiration_date' => '05/12'
443
+ ]
444
+ ],
445
+ [
446
+ 'creditCard' => [
447
  'customerId' => $customer->id
448
+ ]
449
+ ]
450
  );
451
+ $result = Braintree\CreditCard::createFromTransparentRedirect($queryString);
452
  $this->assertTrue($result->success);
453
  $this->assertEquals('510510', $result->creditCard->bin);
454
  $this->assertEquals('5100', $result->creditCard->last4);
455
  $this->assertEquals('05/2012', $result->creditCard->expirationDate);
456
  }
457
 
458
+ public function testCreateFromTransparentRedirect_withDefault()
459
  {
460
+ Test\Helper::suppressDeprecationWarnings();
461
+ $customer = Braintree\Customer::createNoValidate();
462
  $queryString = $this->createCreditCardViaTr(
463
+ [
464
+ 'credit_card' => [
465
  'number' => '5105105105105100',
466
  'expiration_date' => '05/12',
467
+ 'options' => ['make_default' => true]
468
+ ]
469
+ ],
470
+ [
471
+ 'creditCard' => [
472
  'customerId' => $customer->id
473
+ ]
474
+ ]
475
  );
476
+ $result = Braintree\CreditCard::createFromTransparentRedirect($queryString);
477
  $this->assertTrue($result->creditCard->isDefault());
478
  }
479
 
480
+ public function testUpdateFromTransparentRedirect()
481
  {
482
+ $customer = Braintree\Customer::createNoValidate();
483
+ $creditCard = Braintree\CreditCard::createNoValidate([
484
  'customerId' => $customer->id,
485
  'number' => '5105105105105100',
486
  'expirationDate' => '05/12'
487
+ ]);
488
  $queryString = $this->updateCreditCardViaTr(
489
+ [
490
+ 'credit_card' => [
491
  'number' => '4111111111111111',
492
  'expiration_date' => '01/11'
493
+ ]
494
+ ],
495
+ ['paymentMethodToken' => $creditCard->token]
496
  );
497
+ $result = Braintree\CreditCard::updateFromTransparentRedirect($queryString);
498
  $this->assertTrue($result->success);
499
  $this->assertEquals('411111', $result->creditCard->bin);
500
  $this->assertEquals('1111', $result->creditCard->last4);
501
  $this->assertEquals('01/2011', $result->creditCard->expirationDate);
502
  }
503
 
504
+ public function testUpdateFromTransparentRedirect_withDefault()
505
  {
506
+ $customer = Braintree\Customer::createNoValidate();
507
+ $card1 = Braintree\CreditCard::createNoValidate([
508
  'customerId' => $customer->id,
509
  'number' => '5105105105105100',
510
  'expirationDate' => '05/12'
511
+ ]);
512
+ $card2 = Braintree\CreditCard::createNoValidate([
513
  'customerId' => $customer->id,
514
  'number' => '5105105105105100',
515
  'expirationDate' => '05/12'
516
+ ]);
517
  $this->assertFalse($card2->isDefault());
518
 
519
  $queryString = $this->updateCreditCardViaTr(
520
+ [
521
+ 'credit_card' => [
522
+ 'options' => [
523
  'make_default' => true
524
+ ]
525
+ ]
526
+ ],
527
+ ['paymentMethodToken' => $card2->token]
528
  );
529
+ $result = Braintree\CreditCard::updateFromTransparentRedirect($queryString);
530
+ $this->assertFalse(Braintree\CreditCard::find($card1->token)->isDefault());
531
+ $this->assertTrue(Braintree\CreditCard::find($card2->token)->isDefault());
532
  }
533
 
534
+ public function testUpdateFromTransparentRedirect_andUpdateExistingBillingAddress()
535
  {
536
+ $customer = Braintree\Customer::createNoValidate();
537
+ $card = Braintree\CreditCard::createNoValidate([
538
  'customerId' => $customer->id,
539
  'number' => '5105105105105100',
540
  'expirationDate' => '05/12',
541
+ 'billingAddress' => [
542
  'firstName' => 'Drew',
543
  'lastName' => 'Smith',
544
  'company' => 'Smith Co.',
548
  'region' => 'IL',
549
  'postalCode' => '60622',
550
  'countryName' => 'United States of America'
551
+ ]
552
+ ]);
553
 
554
  $queryString = $this->updateCreditCardViaTr(
555
+ [],
556
+ [
557
  'paymentMethodToken' => $card->token,
558
+ 'creditCard' => [
559
+ 'billingAddress' => [
560
  'streetAddress' => '123 New St',
561
  'locality' => 'St. Louis',
562
  'region' => 'MO',
563
  'postalCode' => '63119',
564
+ 'options' => [
565
  'updateExisting' => True
566
+ ]
567
+ ]
568
+ ]
569
+ ]
570
  );
571
+ $result = Braintree\CreditCard::updateFromTransparentRedirect($queryString);
572
  $this->assertTrue($result->success);
573
  $card = $result->creditCard;
574
+ $this->assertEquals(1, sizeof(Braintree\Customer::find($customer->id)->addresses));
575
  $this->assertEquals('123 New St', $card->billingAddress->streetAddress);
576
  $this->assertEquals('St. Louis', $card->billingAddress->locality);
577
  $this->assertEquals('MO', $card->billingAddress->region);
578
  $this->assertEquals('63119', $card->billingAddress->postalCode);
579
  }
580
 
581
+ public function testSale_createsASaleUsingGivenToken()
582
  {
583
+ $customer = Braintree\Customer::createNoValidate([
584
+ 'creditCard' => [
585
  'number' => '5105105105105100',
586
  'expirationDate' => '05/12'
587
+ ]
588
+ ]);
589
  $creditCard = $customer->creditCards[0];
590
+ $result = Braintree\CreditCard::sale($creditCard->token, [
591
  'amount' => '100.00'
592
+ ]);
593
  $this->assertTrue($result->success);
594
  $this->assertEquals('100.00', $result->transaction->amount);
595
  $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
596
  $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
597
  }
598
 
599
+ public function testSaleNoValidate_createsASaleUsingGivenToken()
600
  {
601
+ $customer = Braintree\Customer::createNoValidate([
602
+ 'creditCard' => [
603
  'number' => '5105105105105100',
604
  'expirationDate' => '05/12'
605
+ ]
606
+ ]);
607
  $creditCard = $customer->creditCards[0];
608
+ $transaction = Braintree\CreditCard::saleNoValidate($creditCard->token, [
609
  'amount' => '100.00'
610
+ ]);
611
  $this->assertEquals('100.00', $transaction->amount);
612
  $this->assertEquals($customer->id, $transaction->customerDetails->id);
613
  $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
614
  }
615
 
616
+ public function testSaleNoValidate_createsASaleUsingGivenTokenAndCvv()
617
  {
618
+ $customer = Braintree\Customer::createNoValidate([
619
+ 'creditCard' => [
620
  'number' => '5105105105105100',
621
  'expirationDate' => '05/12'
622
+ ]
623
+ ]);
624
  $creditCard = $customer->creditCards[0];
625
+ $transaction = Braintree\CreditCard::saleNoValidate($creditCard->token, [
626
  'amount' => '100.00',
627
+ 'creditCard' => [
628
  'cvv' => '301'
629
+ ]
630
+ ]);
631
  $this->assertEquals('100.00', $transaction->amount);
632
  $this->assertEquals($customer->id, $transaction->customerDetails->id);
633
  $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
634
  $this->assertEquals('S', $transaction->cvvResponseCode);
635
  }
636
 
637
+ public function testSaleNoValidate_throwsIfInvalid()
638
  {
639
+ $customer = Braintree\Customer::createNoValidate([
640
+ 'creditCard' => [
641
  'number' => '5105105105105100',
642
  'expirationDate' => '05/12'
643
+ ]
644
+ ]);
645
  $creditCard = $customer->creditCards[0];
646
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
647
+ Braintree\CreditCard::saleNoValidate($creditCard->token, [
648
  'amount' => 'invalid'
649
+ ]);
650
  }
651
 
652
+ public function testCredit_createsACreditUsingGivenToken()
653
  {
654
+ $customer = Braintree\Customer::createNoValidate([
655
+ 'creditCard' => [
656
  'number' => '5105105105105100',
657
  'expirationDate' => '05/12'
658
+ ]
659
+ ]);
660
  $creditCard = $customer->creditCards[0];
661
+ $result = Braintree\CreditCard::credit($creditCard->token, [
662
  'amount' => '100.00'
663
+ ]);
664
  $this->assertTrue($result->success);
665
  $this->assertEquals('100.00', $result->transaction->amount);
666
+ $this->assertEquals(Braintree\Transaction::CREDIT, $result->transaction->type);
667
  $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
668
  $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
669
  }
670
 
671
+ public function testCreditNoValidate_createsACreditUsingGivenToken()
672
  {
673
+ $customer = Braintree\Customer::createNoValidate([
674
+ 'creditCard' => [
675
  'number' => '5105105105105100',
676
  'expirationDate' => '05/12'
677
+ ]
678
+ ]);
679
  $creditCard = $customer->creditCards[0];
680
+ $transaction = Braintree\CreditCard::creditNoValidate($creditCard->token, [
681
  'amount' => '100.00'
682
+ ]);
683
  $this->assertEquals('100.00', $transaction->amount);
684
+ $this->assertEquals(Braintree\Transaction::CREDIT, $transaction->type);
685
  $this->assertEquals($customer->id, $transaction->customerDetails->id);
686
  $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
687
  }
688
 
689
+ public function testCreditNoValidate_throwsIfInvalid()
690
  {
691
+ $customer = Braintree\Customer::createNoValidate([
692
+ 'creditCard' => [
693
  'number' => '5105105105105100',
694
  'expirationDate' => '05/12'
695
+ ]
696
+ ]);
697
  $creditCard = $customer->creditCards[0];
698
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
699
+ Braintree\CreditCard::creditNoValidate($creditCard->token, [
700
  'amount' => 'invalid'
701
+ ]);
702
  }
703
 
704
+ public function testExpired()
705
  {
706
+ $collection = Braintree\CreditCard::expired();
707
  $this->assertTrue($collection->maximumCount() > 1);
708
 
709
+ $arr = [];
710
  foreach($collection as $creditCard) {
711
  $this->assertTrue($creditCard->isExpired());
712
  array_push($arr, $creditCard->token);
716
  }
717
 
718
 
719
+ public function testExpiringBetween()
720
  {
721
+ $collection = Braintree\CreditCard::expiringBetween(
722
  mktime(0, 0, 0, 1, 1, 2010),
723
  mktime(23, 59, 59, 12, 31, 2010)
724
  );
725
  $this->assertTrue($collection->maximumCount() > 1);
726
 
727
+ $arr = [];
728
  foreach($collection as $creditCard) {
729
  $this->assertEquals('2010', $creditCard->expirationYear);
730
  array_push($arr, $creditCard->token);
733
  $this->assertEquals($collection->maximumCount(), count($uniqueCreditCardTokens));
734
  }
735
 
736
+ public function testExpiringBetween_parsesCreditCardDetailsUnderTransactionsCorrectly()
737
  {
738
+ $collection = Braintree\CreditCard::expiringBetween(
739
  mktime(0, 0, 0, 1, 1, 2010),
740
  mktime(23, 59, 59, 12, 31, 2010)
741
  );
750
  }
751
  }
752
 
753
+ public function testFind()
754
  {
755
+ $customer = Braintree\Customer::createNoValidate();
756
+ $result = Braintree\CreditCard::create([
757
  'customerId' => $customer->id,
758
  'cardholderName' => 'Cardholder',
759
  'number' => '5105105105105100',
760
  'expirationDate' => '05/12'
761
+ ]);
762
  $this->assertTrue($result->success);
763
+ $creditCard = Braintree\CreditCard::find($result->creditCard->token);
764
  $this->assertEquals($customer->id, $creditCard->customerId);
765
  $this->assertEquals('510510', $creditCard->bin);
766
  $this->assertEquals('5100', $creditCard->last4);
767
  $this->assertEquals('Cardholder', $creditCard->cardholderName);
768
  $this->assertEquals('05/2012', $creditCard->expirationDate);
769
+ $this->assertEquals([], $creditCard->subscriptions);
770
  }
771
 
772
+ public function testFindReturnsAssociatedSubscriptions()
773
  {
774
+ $customer = Braintree\Customer::createNoValidate();
775
+ $result = Braintree\CreditCard::create([
776
  'customerId' => $customer->id,
777
  'cardholderName' => 'Cardholder',
778
  'number' => '5105105105105100',
779
  'expirationDate' => '05/12',
780
+ 'billingAddress' => [
781
  'firstName' => 'Drew',
782
  'lastName' => 'Smith',
783
  'company' => 'Smith Co.',
787
  'region' => 'IL',
788
  'postalCode' => '60622',
789
  'countryName' => 'United States of America'
790
+ ]
791
+ ]);
792
  $id = strval(rand());
793
+ Braintree\Subscription::create([
794
  'id' => $id,
795
  'paymentMethodToken' => $result->creditCard->token,
796
  'planId' => 'integration_trialless_plan',
797
  'price' => '1.00'
798
+ ]);
799
+ $creditCard = Braintree\CreditCard::find($result->creditCard->token);
800
  $this->assertEquals($id, $creditCard->subscriptions[0]->id);
801
  $this->assertEquals('integration_trialless_plan', $creditCard->subscriptions[0]->planId);
802
  $this->assertEquals('1.00', $creditCard->subscriptions[0]->price);
803
  }
804
 
805
+ public function testFind_throwsIfCannotBeFound()
806
  {
807
+ $this->setExpectedException('Braintree\Exception\NotFound');
808
+ Braintree\CreditCard::find('invalid-token');
809
  }
810
 
811
+ public function testFind_throwsUsefulErrorMessagesWhenEmpty()
812
  {
813
  $this->setExpectedException('InvalidArgumentException', 'expected credit card id to be set');
814
+ Braintree\CreditCard::find('');
815
  }
816
 
817
+ public function testFind_throwsUsefulErrorMessagesWhenInvalid()
818
  {
819
  $this->setExpectedException('InvalidArgumentException', '@ is an invalid credit card token');
820
+ Braintree\CreditCard::find('@');
821
  }
822
 
823
+ public function testFromNonce()
824
  {
825
+ $customer = Braintree\Customer::createNoValidate();
826
+ $http = new HttpClientApi(Braintree\Configuration::$global);
827
+ $nonce = $http->nonce_for_new_card([
828
+ "credit_card" => [
829
  "number" => "4009348888881881",
830
  "expirationMonth" => "11",
831
  "expirationYear" => "2099"
832
+ ],
833
  "customerId" => $customer->id
834
+ ]);
835
 
836
+ $creditCard = Braintree\CreditCard::fromNonce($nonce);
837
 
838
+ $customer = Braintree\Customer::find($customer->id);
839
  $this->assertEquals($customer->creditCards[0], $creditCard);
840
  }
841
 
842
+ public function testFromNonce_ReturnsErrorWhenNoncePointsToSharedCard()
843
  {
844
+ $http = new HttpClientApi(Braintree\Configuration::$global);
845
+ $nonce = $http->nonce_for_new_card([
846
+ "credit_card" => [
847
  "number" => "4009348888881881",
848
  "expirationMonth" => "11",
849
  "expirationYear" => "2099"
850
+ ],
851
  "share" => true
852
+ ]);
853
 
854
+ $this->setExpectedException('Braintree\Exception\NotFound', "not found");
855
+ Braintree\CreditCard::fromNonce($nonce);
856
  }
857
 
858
+ public function testFromNonce_ReturnsErrorWhenNonceIsConsumed()
859
  {
860
+ $customer = Braintree\Customer::createNoValidate();
861
+ $http = new HttpClientApi(Braintree\Configuration::$global);
862
+ $nonce = $http->nonce_for_new_card([
863
+ "credit_card" => [
864
  "number" => "4009348888881881",
865
  "expirationMonth" => "11",
866
  "expirationYear" => "2099"
867
+ ],
868
  "customerId" => $customer->id
869
+ ]);
870
 
871
+ Braintree\CreditCard::fromNonce($nonce);
872
+ $this->setExpectedException('Braintree\Exception\NotFound', "consumed");
873
+ Braintree\CreditCard::fromNonce($nonce);
874
  }
875
 
876
+ public function testUpdate()
877
  {
878
+ $customer = Braintree\Customer::createNoValidate();
879
+ $createResult = Braintree\CreditCard::create([
880
  'customerId' => $customer->id,
881
  'cardholderName' => 'Old Cardholder',
882
  'number' => '5105105105105100',
883
  'expirationDate' => '05/12'
884
+ ]);
885
  $this->assertTrue($createResult->success);
886
+ $updateResult = Braintree\CreditCard::update($createResult->creditCard->token, [
887
  'cardholderName' => 'New Cardholder',
888
  'number' => '4111111111111111',
889
  'expirationDate' => '07/14'
890
+ ]);
891
  $this->assertEquals($customer->id, $updateResult->creditCard->customerId);
892
  $this->assertEquals('411111', $updateResult->creditCard->bin);
893
  $this->assertEquals('1111', $updateResult->creditCard->last4);
895
  $this->assertEquals('07/2014', $updateResult->creditCard->expirationDate);
896
  }
897
 
898
+ public function testUpdate_withCardVerification()
899
  {
900
+ $customer = Braintree\Customer::createNoValidate();
901
+ $initialCreditCard = Braintree\CreditCard::create([
902
  'customerId' => $customer->id,
903
  'number' => '5105105105105100',
904
  'expirationDate' => '05/12'
905
+ ])->creditCard;
906
 
907
+ $result = Braintree\CreditCard::update($initialCreditCard->token, [
908
+ 'billingAddress' => [
909
  'region' => 'IL'
910
+ ],
911
+ 'options' => ['verifyCard' => true]
912
+ ]);
913
  $this->assertFalse($result->success);
914
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
915
  $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
916
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
917
  $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
918
  $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
919
  $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
920
  $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
921
+ $this->assertEquals(Test\Helper::defaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
922
  }
923
 
924
+ public function testUpdate_withCardVerificationAndSpecificMerchantAccount()
925
  {
926
+ $customer = Braintree\Customer::createNoValidate();
927
+ $initialCreditCard = Braintree\CreditCard::create([
928
  'customerId' => $customer->id,
929
  'number' => '5105105105105100',
930
  'expirationDate' => '05/12'
931
+ ])->creditCard;
932
 
933
+ $result = Braintree\CreditCard::update($initialCreditCard->token, [
934
+ 'billingAddress' => [
935
  'region' => 'IL'
936
+ ],
937
+ 'options' => [
938
+ 'verificationMerchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(),
939
  'verifyCard' => true
940
+ ]
941
+ ]);
942
  $this->assertFalse($result->success);
943
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
944
+ $this->assertEquals(Test\Helper::nonDefaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
945
  }
946
 
947
+ public function testUpdate_createsNewBillingAddressByDefault()
948
  {
949
+ $customer = Braintree\Customer::createNoValidate();
950
+ $initialCreditCard = Braintree\CreditCard::create([
951
  'customerId' => $customer->id,
952
  'number' => '5105105105105100',
953
  'expirationDate' => '05/12',
954
+ 'billingAddress' => [
955
  'streetAddress' => '123 Nigeria Ave'
956
+ ]
957
+ ])->creditCard;
958
 
959
+ $updatedCreditCard = Braintree\CreditCard::update($initialCreditCard->token, [
960
+ 'billingAddress' => [
961
  'region' => 'IL'
962
+ ]
963
+ ])->creditCard;
964
  $this->assertEquals('IL', $updatedCreditCard->billingAddress->region);
965
  $this->assertNull($updatedCreditCard->billingAddress->streetAddress);
966
  $this->assertNotEquals($initialCreditCard->billingAddress->id, $updatedCreditCard->billingAddress->id);
967
  }
968
 
969
+ public function testUpdate_updatesExistingBillingAddressIfUpdateExistingOptionIsTrue()
970
  {
971
+ $customer = Braintree\Customer::createNoValidate();
972
+ $initialCreditCard = Braintree\CreditCard::create([
973
  'customerId' => $customer->id,
974
  'number' => '5105105105105100',
975
  'expirationDate' => '05/12',
976
+ 'billingAddress' => [
977
  'countryName' => 'Turkey',
978
  'countryCodeAlpha2' => 'TR',
979
  'countryCodeAlpha3' => 'TUR',
980
  'countryCodeNumeric' => '792',
981
+ ]
982
+ ])->creditCard;
983
 
984
+ $updatedCreditCard = Braintree\CreditCard::update($initialCreditCard->token, [
985
+ 'billingAddress' => [
986
  'countryName' => 'Thailand',
987
  'countryCodeAlpha2' => 'TH',
988
  'countryCodeAlpha3' => 'THA',
989
  'countryCodeNumeric' => '764',
990
+ 'options' => [
991
  'updateExisting' => True
992
+ ]
993
+ ]
994
+ ])->creditCard;
995
  $this->assertEquals('Thailand', $updatedCreditCard->billingAddress->countryName);
996
  $this->assertEquals('TH', $updatedCreditCard->billingAddress->countryCodeAlpha2);
997
  $this->assertEquals('THA', $updatedCreditCard->billingAddress->countryCodeAlpha3);
999
  $this->assertEquals($initialCreditCard->billingAddress->id, $updatedCreditCard->billingAddress->id);
1000
  }
1001
 
1002
+ public function testUpdate_canChangeToken()
1003
  {
1004
  $oldToken = strval(rand());
1005
  $newToken = strval(rand());
1006
 
1007
+ $customer = Braintree\Customer::createNoValidate();
1008
+ $createResult = Braintree\CreditCard::create([
1009
  'customerId' => $customer->id,
1010
  'token' => $oldToken,
1011
  'number' => '5105105105105100',
1012
  'expirationDate' => '05/12'
1013
+ ]);
1014
  $this->assertTrue($createResult->success);
1015
+ $updateResult = Braintree\CreditCard::update($oldToken, [
1016
  'token' => $newToken
1017
+ ]);
1018
  $this->assertEquals($customer->id, $updateResult->creditCard->customerId);
1019
  $this->assertEquals($newToken, $updateResult->creditCard->token);
1020
+ $this->assertEquals($newToken, Braintree\CreditCard::find($newToken)->token);
1021
  }
1022
 
1023
+ public function testUpdateNoValidate()
1024
  {
1025
+ $customer = Braintree\Customer::createNoValidate();
1026
+ $creditCard = Braintree\CreditCard::createNoValidate([
1027
  'customerId' => $customer->id,
1028
  'cardholderName' => 'Old Cardholder',
1029
  'number' => '5105105105105100',
1030
  'expirationDate' => '05/12'
1031
+ ]);
1032
+ $updatedCard = Braintree\CreditCard::updateNoValidate($creditCard->token, [
1033
  'cardholderName' => 'New Cardholder',
1034
  'number' => '4111111111111111',
1035
  'expirationDate' => '07/14'
1036
+ ]);
1037
  $this->assertEquals($customer->id, $updatedCard->customerId);
1038
  $this->assertEquals('411111', $updatedCard->bin);
1039
  $this->assertEquals('1111', $updatedCard->last4);
1041
  $this->assertEquals('07/2014', $updatedCard->expirationDate);
1042
  }
1043
 
1044
+ public function testUpdateNoValidate_throwsIfInvalid()
1045
  {
1046
+ $customer = Braintree\Customer::createNoValidate();
1047
+ $creditCard = Braintree\CreditCard::createNoValidate([
1048
  'customerId' => $customer->id,
1049
  'cardholderName' => 'Old Cardholder',
1050
  'number' => '5105105105105100',
1051
  'expirationDate' => '05/12'
1052
+ ]);
1053
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
1054
+ Braintree\CreditCard::updateNoValidate($creditCard->token, [
1055
  'number' => 'invalid',
1056
+ ]);
1057
  }
1058
 
1059
+ public function testUpdate_withDefault()
1060
  {
1061
+ $customer = Braintree\Customer::createNoValidate();
1062
+ $card1 = Braintree\CreditCard::create([
1063
  'customerId' => $customer->id,
1064
  'cardholderName' => 'Cardholder',
1065
  'number' => '5105105105105100',
1066
  'expirationDate' => '05/12'
1067
+ ])->creditCard;
1068
+ $card2 = Braintree\CreditCard::create([
1069
  'customerId' => $customer->id,
1070
  'cardholderName' => 'Cardholder',
1071
  'number' => '5105105105105100',
1072
  'expirationDate' => '05/12'
1073
+ ])->creditCard;
1074
 
1075
  $this->assertTrue($card1->isDefault());
1076
  $this->assertFalse($card2->isDefault());
1077
 
1078
+ Braintree\CreditCard::update($card2->token, [
1079
+ 'options' => ['makeDefault' => true]
1080
+ ])->creditCard;
1081
 
1082
+ $this->assertFalse(Braintree\CreditCard::find($card1->token)->isDefault());
1083
+ $this->assertTrue(Braintree\CreditCard::find($card2->token)->isDefault());
1084
  }
1085
 
1086
+ public function testDelete_deletesThePaymentMethod()
1087
  {
1088
+ $customer = Braintree\Customer::createNoValidate([]);
1089
+ $creditCard = Braintree\CreditCard::createNoValidate([
1090
  'customerId' => $customer->id,
1091
  'number' => '5105105105105100',
1092
  'expirationDate' => '05/12'
1093
+ ]);
1094
+ Braintree\CreditCard::find($creditCard->token);
1095
+ Braintree\CreditCard::delete($creditCard->token);
1096
+ $this->setExpectedException('Braintree\Exception\NotFound');
1097
+ Braintree\CreditCard::find($creditCard->token);
1098
  }
1099
 
1100
+ public function testGatewayRejectionOnCVV()
1101
  {
1102
+ $old_merchant_id = Braintree\Configuration::merchantId();
1103
+ $old_public_key = Braintree\Configuration::publicKey();
1104
+ $old_private_key = Braintree\Configuration::privateKey();
1105
 
1106
+ Braintree\Configuration::merchantId('processing_rules_merchant_id');
1107
+ Braintree\Configuration::publicKey('processing_rules_public_key');
1108
+ Braintree\Configuration::privateKey('processing_rules_private_key');
1109
 
1110
+ $customer = Braintree\Customer::createNoValidate();
1111
+ $result = Braintree\CreditCard::create([
1112
  'customerId' => $customer->id,
1113
  'number' => '4111111111111111',
1114
  'expirationDate' => '05/2011',
1115
  'cvv' => '200',
1116
+ 'options' => ['verifyCard' => true]
1117
+ ]);
1118
 
1119
+ Braintree\Configuration::merchantId($old_merchant_id);
1120
+ Braintree\Configuration::publicKey($old_public_key);
1121
+ Braintree\Configuration::privateKey($old_private_key);
1122
 
1123
  $this->assertFalse($result->success);
1124
+ $this->assertEquals(Braintree\Transaction::CVV, $result->creditCardVerification->gatewayRejectionReason);
1125
  }
1126
 
1127
+ public function testGatewayRejectionIsNullOnProcessorDecline()
1128
  {
1129
+ $old_merchant_id = Braintree\Configuration::merchantId();
1130
+ $old_public_key = Braintree\Configuration::publicKey();
1131
+ $old_private_key = Braintree\Configuration::privateKey();
1132
 
1133
+ Braintree\Configuration::merchantId('processing_rules_merchant_id');
1134
+ Braintree\Configuration::publicKey('processing_rules_public_key');
1135
+ Braintree\Configuration::privateKey('processing_rules_private_key');
1136
 
1137
+ $customer = Braintree\Customer::createNoValidate();
1138
+ $result = Braintree\CreditCard::create([
1139
  'customerId' => $customer->id,
1140
  'number' => '5105105105105100',
1141
  'expirationDate' => '05/2011',
1142
  'cvv' => '200',
1143
+ 'options' => ['verifyCard' => true]
1144
+ ]);
1145
 
1146
+ Braintree\Configuration::merchantId($old_merchant_id);
1147
+ Braintree\Configuration::publicKey($old_public_key);
1148
+ Braintree\Configuration::privateKey($old_private_key);
1149
 
1150
  $this->assertFalse($result->success);
1151
  $this->assertNull($result->creditCardVerification->gatewayRejectionReason);
1152
  }
1153
 
1154
+ public function createCreditCardViaTr($regularParams, $trParams)
1155
  {
1156
+ $trData = Braintree\TransparentRedirect::createCreditCardData(
1157
+ array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
1158
  );
1159
+ return Test\Helper::submitTrRequest(
1160
+ Braintree\CreditCard::createCreditCardUrl(),
1161
  $regularParams,
1162
  $trData
1163
  );
1164
  }
1165
 
1166
+ public function updateCreditCardViaTr($regularParams, $trParams)
1167
  {
1168
+ $trData = Braintree\TransparentRedirect::updateCreditCardData(
1169
+ array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
1170
  );
1171
+ return Test\Helper::submitTrRequest(
1172
+ Braintree\CreditCard::updateCreditCardUrl(),
1173
  $regularParams,
1174
  $trData
1175
  );
1176
  }
1177
 
1178
+ public function testPrepaidCard()
1179
  {
1180
+ $customer = Braintree\Customer::createNoValidate();
1181
+ $result = Braintree\CreditCard::create([
1182
  'customerId' => $customer->id,
1183
  'cardholderName' => 'Cardholder',
1184
+ 'number' => CardTypeIndicators::PREPAID,
1185
  'expirationDate' => '05/12',
1186
+ 'options' => ['verifyCard' => true]
1187
+ ]);
1188
+ $this->assertEquals(Braintree\CreditCard::PREPAID_YES, $result->creditCard->prepaid);
1189
  }
1190
 
1191
+ public function testCommercialCard()
1192
  {
1193
+ $customer = Braintree\Customer::createNoValidate();
1194
+ $result = Braintree\CreditCard::create([
1195
  'customerId' => $customer->id,
1196
  'cardholderName' => 'Cardholder',
1197
+ 'number' => CardTypeIndicators::COMMERCIAL,
1198
  'expirationDate' => '05/12',
1199
+ 'options' => ['verifyCard' => true]
1200
+ ]);
1201
+ $this->assertEquals(Braintree\CreditCard::COMMERCIAL_YES, $result->creditCard->commercial);
1202
  }
1203
 
1204
+ public function testDebitCard()
1205
  {
1206
+ $customer = Braintree\Customer::createNoValidate();
1207
+ $result = Braintree\CreditCard::create([
1208
  'customerId' => $customer->id,
1209
  'cardholderName' => 'Cardholder',
1210
+ 'number' => CardTypeIndicators::DEBIT,
1211
  'expirationDate' => '05/12',
1212
+ 'options' => ['verifyCard' => true]
1213
+ ]);
1214
+ $this->assertEquals(Braintree\CreditCard::DEBIT_YES, $result->creditCard->debit);
1215
  }
1216
 
1217
+ public function testPayrollCard()
1218
  {
1219
+ $customer = Braintree\Customer::createNoValidate();
1220
+ $result = Braintree\CreditCard::create([
1221
  'customerId' => $customer->id,
1222
  'cardholderName' => 'Cardholder',
1223
+ 'number' => CardTypeIndicators::PAYROLL,
1224
  'expirationDate' => '05/12',
1225
+ 'options' => ['verifyCard' => true]
1226
+ ]);
1227
+ $this->assertEquals(Braintree\CreditCard::PAYROLL_YES, $result->creditCard->payroll);
1228
  }
1229
 
1230
+ public function testHealthCareCard()
1231
  {
1232
+ $customer = Braintree\Customer::createNoValidate();
1233
+ $result = Braintree\CreditCard::create([
1234
  'customerId' => $customer->id,
1235
  'cardholderName' => 'Cardholder',
1236
+ 'number' => CardTypeIndicators::HEALTHCARE,
1237
  'expirationDate' => '05/12',
1238
+ 'options' => ['verifyCard' => true]
1239
+ ]);
1240
+ $this->assertEquals(Braintree\CreditCard::HEALTHCARE_YES, $result->creditCard->healthcare);
1241
  }
1242
 
1243
+ public function testDurbinRegulatedCard()
1244
  {
1245
+ $customer = Braintree\Customer::createNoValidate();
1246
+ $result = Braintree\CreditCard::create([
1247
  'customerId' => $customer->id,
1248
  'cardholderName' => 'Cardholder',
1249
+ 'number' => CardTypeIndicators::DURBIN_REGULATED,
1250
  'expirationDate' => '05/12',
1251
+ 'options' => ['verifyCard' => true]
1252
+ ]);
1253
+ $this->assertEquals(Braintree\CreditCard::DURBIN_REGULATED_YES, $result->creditCard->durbinRegulated);
1254
  }
1255
 
1256
+ public function testCountryOfIssuanceCard()
1257
  {
1258
+ $customer = Braintree\Customer::createNoValidate();
1259
+ $result = Braintree\CreditCard::create([
1260
  'customerId' => $customer->id,
1261
  'cardholderName' => 'Cardholder',
1262
+ 'number' => CardTypeIndicators::COUNTRY_OF_ISSUANCE,
1263
  'expirationDate' => '05/12',
1264
+ 'options' => ['verifyCard' => true]
1265
+ ]);
1266
  $this->assertEquals("USA", $result->creditCard->countryOfIssuance);
1267
  }
1268
 
1269
+ public function testIssuingBankCard()
1270
  {
1271
+ $customer = Braintree\Customer::createNoValidate();
1272
+ $result = Braintree\CreditCard::create([
1273
  'customerId' => $customer->id,
1274
  'cardholderName' => 'Cardholder',
1275
+ 'number' => CardTypeIndicators::ISSUING_BANK,
1276
  'expirationDate' => '05/12',
1277
+ 'options' => ['verifyCard' => true]
1278
+ ]);
1279
  $this->assertEquals("NETWORK ONLY", $result->creditCard->issuingBank);
1280
  }
1281
 
1282
+ public function testNegativeCardTypeIndicators()
1283
  {
1284
+ $customer = Braintree\Customer::createNoValidate();
1285
+ $result = Braintree\CreditCard::create([
1286
  'customerId' => $customer->id,
1287
  'cardholderName' => 'Cardholder',
1288
+ 'number' => CardTypeIndicators::NO,
1289
  'expirationDate' => '05/12',
1290
+ 'options' => ['verifyCard' => true]
1291
+ ]);
1292
+ $this->assertEquals(Braintree\CreditCard::PREPAID_NO, $result->creditCard->prepaid);
1293
+ $this->assertEquals(Braintree\CreditCard::DURBIN_REGULATED_NO, $result->creditCard->durbinRegulated);
1294
+ $this->assertEquals(Braintree\CreditCard::PAYROLL_NO, $result->creditCard->payroll);
1295
+ $this->assertEquals(Braintree\CreditCard::DEBIT_NO, $result->creditCard->debit);
1296
+ $this->assertEquals(Braintree\CreditCard::HEALTHCARE_NO, $result->creditCard->healthcare);
1297
+ $this->assertEquals(Braintree\CreditCard::COMMERCIAL_NO, $result->creditCard->commercial);
1298
  }
1299
 
1300
+ public function testUnknownCardTypeIndicators()
1301
  {
1302
+ $customer = Braintree\Customer::createNoValidate();
1303
+ $result = Braintree\CreditCard::create([
1304
  'customerId' => $customer->id,
1305
  'cardholderName' => 'Cardholder',
1306
+ 'number' => CardTypeIndicators::UNKNOWN,
1307
  'expirationDate' => '05/12',
1308
+ 'options' => ['verifyCard' => true]
1309
+ ]);
1310
+ $this->assertEquals(Braintree\CreditCard::PREPAID_UNKNOWN, $result->creditCard->prepaid);
1311
+ $this->assertEquals(Braintree\CreditCard::DURBIN_REGULATED_UNKNOWN, $result->creditCard->durbinRegulated);
1312
+ $this->assertEquals(Braintree\CreditCard::PAYROLL_UNKNOWN, $result->creditCard->payroll);
1313
+ $this->assertEquals(Braintree\CreditCard::DEBIT_UNKNOWN, $result->creditCard->debit);
1314
+ $this->assertEquals(Braintree\CreditCard::HEALTHCARE_UNKNOWN, $result->creditCard->healthcare);
1315
+ $this->assertEquals(Braintree\CreditCard::COMMERCIAL_UNKNOWN, $result->creditCard->commercial);
1316
+ $this->assertEquals(Braintree\CreditCard::COUNTRY_OF_ISSUANCE_UNKNOWN, $result->creditCard->countryOfIssuance);
1317
+ $this->assertEquals(Braintree\CreditCard::ISSUING_BANK_UNKNOWN, $result->creditCard->issuingBank);
1318
  }
1319
  }
braintree_sdk/tests/integration/CreditCardVerificationAdvancedSearchTest.php CHANGED
@@ -1,121 +1,127 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_CreditCardVerificationAdvancedSearchTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
5
  {
6
- function test_searchOnTextFields()
7
  {
8
- $searchCriteria = array(
9
  'creditCardCardholderName' => 'Tim Toole',
10
  'creditCardExpirationDate' => '05/2010',
11
- 'creditCardNumber' => Braintree_Test_CreditCardNumbers::$failsSandboxVerification['Visa'],
12
  'billingAddressDetailsPostalCode' => '90210',
13
- );
14
- $result = Braintree_Customer::create(array(
15
- 'creditCard' => array(
16
  'cardholderName' => $searchCriteria['creditCardCardholderName'],
17
  'number' => $searchCriteria['creditCardNumber'],
18
  'expirationDate' => $searchCriteria['creditCardExpirationDate'],
19
- 'billingAddress' => array(
20
  'postalCode' => $searchCriteria['billingAddressDetailsPostalCode']
21
- ),
22
- 'options' => array('verifyCard' => true),
23
- ),
24
- ));
25
  $verification = $result->creditCardVerification;
26
 
27
- $query = array(Braintree_CreditCardVerificationSearch::id()->is($verification->id));
28
  foreach ($searchCriteria AS $criterion => $value) {
29
- $query[] = Braintree_CreditCardVerificationSearch::$criterion()->is($value);
30
  }
31
 
32
- $collection = Braintree_CreditCardVerification::search($query);
33
  $this->assertEquals(1, $collection->maximumCount());
34
  $this->assertEquals($result->creditCardVerification->id, $collection->firstItem()->id);
35
 
36
  foreach ($searchCriteria AS $criterion => $value) {
37
- $collection = Braintree_CreditCardVerification::search(array(
38
- Braintree_CreditCardVerificationSearch::$criterion()->is($value),
39
- Braintree_CreditCardVerificationSearch::id()->is($result->creditCardVerification->id)
40
- ));
41
  $this->assertEquals(1, $collection->maximumCount());
42
  $this->assertEquals($result->creditCardVerification->id, $collection->firstItem()->id);
43
 
44
- $collection = Braintree_CreditCardVerification::search(array(
45
- Braintree_CreditCardVerificationSearch::$criterion()->is('invalid_attribute'),
46
- Braintree_CreditCardVerificationSearch::id()->is($result->creditCardVerification->id)
47
- ));
48
  $this->assertEquals(0, $collection->maximumCount());
49
  }
50
  }
51
 
52
- function test_searchOnSuccessfulCustomerAndPaymentFields()
53
  {
54
  $customerId = uniqid();
55
- $searchCriteria = array(
56
  'customerId' => $customerId,
57
  'customerEmail' => $customerId . 'sandworm@example.com',
58
  'paymentMethodToken' => $customerId . 'token',
59
- );
60
- $result = Braintree_Customer::create(array(
61
  'id' => $customerId,
62
  'email' => $searchCriteria['customerEmail'],
63
- 'creditCard' => array(
64
  'token' => $searchCriteria['paymentMethodToken'],
65
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
66
  'expirationDate' => '05/2017',
67
- 'options' => array('verifyCard' => true)
68
- )
69
- ));
70
  $customer = $result->customer;
71
 
72
- $query = array();
73
  foreach ($searchCriteria AS $criterion => $value) {
74
- $query[] = Braintree_CreditCardVerificationSearch::$criterion()->is($value);
75
  }
76
 
77
- $collection = Braintree_CreditCardVerification::search($query);
78
  $this->assertEquals(1, $collection->maximumCount());
79
 
80
  foreach ($searchCriteria AS $criterion => $value) {
81
- $collection = Braintree_CreditCardVerification::search(array(
82
- Braintree_CreditCardVerificationSearch::$criterion()->is($value),
83
- ));
84
  $this->assertEquals(1, $collection->maximumCount());
85
 
86
- $collection = Braintree_CreditCardVerification::search(array(
87
- Braintree_CreditCardVerificationSearch::$criterion()->is('invalid_attribute'),
88
- ));
89
  $this->assertEquals(0, $collection->maximumCount());
90
  }
91
  }
92
 
93
- function testGateway_searchEmpty()
94
  {
95
- $query = array();
96
- $query[] = Braintree_CreditCardVerificationSearch::creditCardCardholderName()->is('Not Found');
97
 
98
- $gateway = new Braintree_Gateway(array(
99
  'environment' => 'development',
100
  'merchantId' => 'integration_merchant_id',
101
  'publicKey' => 'integration_public_key',
102
  'privateKey' => 'integration_private_key'
103
- ));
104
  $collection = $gateway->creditCardVerification()->search($query);
105
 
106
  $this->assertEquals(0, $collection->maximumCount());
107
  }
108
 
109
- function test_createdAt()
110
  {
111
- $result = Braintree_Customer::create(array(
112
- 'creditCard' => array(
113
  'cardholderName' => 'Joe Smith',
114
  'number' => '4000111111111115',
115
  'expirationDate' => '12/2016',
116
- 'options' => array('verifyCard' => true),
117
- ),
118
- ));
119
 
120
  $verification = $result->creditCardVerification;
121
 
@@ -124,130 +130,130 @@ class Braintree_CreditCardVerificationAdvancedSearchTest extends PHPUnit_Framewo
124
  $future = clone $verification->createdAt;
125
  $future->modify('+1 hour');
126
 
127
- $collection = Braintree_CreditCardVerification::search(array(
128
- Braintree_CreditCardVerificationSearch::id()->is($verification->id),
129
- Braintree_CreditCardVerificationSearch::createdAt()->between($past, $future)
130
- ));
131
  $this->assertEquals(1, $collection->maximumCount());
132
  $this->assertEquals($verification->id, $collection->firstItem()->id);
133
 
134
- $collection = Braintree_CreditCardVerification::search(array(
135
- Braintree_CreditCardVerificationSearch::id()->is($verification->id),
136
- Braintree_CreditCardVerificationSearch::createdAt()->lessThanOrEqualTo($future)
137
- ));
138
  $this->assertEquals(1, $collection->maximumCount());
139
  $this->assertEquals($verification->id, $collection->firstItem()->id);
140
 
141
- $collection = Braintree_CreditCardVerification::search(array(
142
- Braintree_CreditCardVerificationSearch::id()->is($verification->id),
143
- Braintree_CreditCardVerificationSearch::createdAt()->greaterThanOrEqualTo($past)
144
- ));
145
  $this->assertEquals(1, $collection->maximumCount());
146
  $this->assertEquals($verification->id, $collection->firstItem()->id);
147
  }
148
 
149
- function test_multipleValueNode_ids()
150
  {
151
- $result = Braintree_Customer::create(array(
152
- 'creditCard' => array(
153
  'cardholderName' => 'Joe Smith',
154
  'number' => '4000111111111115',
155
  'expirationDate' => '12/2016',
156
- 'options' => array('verifyCard' => true),
157
- ),
158
- ));
159
 
160
  $creditCardVerification = $result->creditCardVerification;
161
 
162
- $collection = Braintree_CreditCardVerification::search(array(
163
- Braintree_CreditCardVerificationSearch::ids()->is($creditCardVerification->id)
164
- ));
165
  $this->assertEquals(1, $collection->maximumCount());
166
  $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
167
 
168
- $collection = Braintree_CreditCardVerification::search(array(
169
- Braintree_CreditCardVerificationSearch::ids()->in(
170
- array($creditCardVerification->id,'1234')
171
  )
172
- ));
173
  $this->assertEquals(1, $collection->maximumCount());
174
  $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
175
 
176
- $collection = Braintree_CreditCardVerification::search(array(
177
- Braintree_CreditCardVerificationSearch::ids()->is('1234')
178
- ));
179
  $this->assertEquals(0, $collection->maximumCount());
180
  }
181
 
182
- function test_multipleValueNode_creditCardType()
183
  {
184
- $result = Braintree_Customer::create(array(
185
- 'creditCard' => array(
186
  'cardholderName' => 'Joe Smith',
187
  'number' => '4000111111111115',
188
  'expirationDate' => '12/2016',
189
- 'options' => array('verifyCard' => true),
190
- ),
191
- ));
192
 
193
  $creditCardVerification = $result->creditCardVerification;
194
 
195
- $collection = Braintree_CreditCardVerification::search(array(
196
- Braintree_CreditCardVerificationSearch::id()->is($creditCardVerification->id),
197
- Braintree_CreditCardVerificationSearch::creditCardCardType()->is($creditCardVerification->creditCard['cardType'])
198
- ));
199
  $this->assertEquals(1, $collection->maximumCount());
200
  $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
201
 
202
- $collection = Braintree_CreditCardVerification::search(array(
203
- Braintree_CreditCardVerificationSearch::id()->is($creditCardVerification->id),
204
- Braintree_CreditCardVerificationSearch::creditCardCardType()->in(
205
- array($creditCardVerification->creditCard['cardType'], Braintree_CreditCard::CHINA_UNION_PAY)
206
  )
207
- ));
208
  $this->assertEquals(1, $collection->maximumCount());
209
  $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
210
 
211
- $collection = Braintree_CreditCardVerification::search(array(
212
- Braintree_CreditCardVerificationSearch::id()->is($creditCardVerification->id),
213
- Braintree_CreditCardVerificationSearch::creditCardCardType()->is(Braintree_CreditCard::CHINA_UNION_PAY)
214
- ));
215
  $this->assertEquals(0, $collection->maximumCount());
216
  }
217
 
218
- function test_multipleValueNode_status()
219
  {
220
- $result = Braintree_Customer::create(array(
221
- 'creditCard' => array(
222
  'cardholderName' => 'Joe Smith',
223
  'number' => '4000111111111115',
224
  'expirationDate' => '12/2016',
225
- 'options' => array('verifyCard' => true),
226
- ),
227
- ));
228
 
229
  $creditCardVerification = $result->creditCardVerification;
230
 
231
- $collection = Braintree_CreditCardVerification::search(array(
232
- Braintree_CreditCardVerificationSearch::id()->is($creditCardVerification->id),
233
- Braintree_CreditCardVerificationSearch::status()->is($creditCardVerification->status)
234
- ));
235
  $this->assertEquals(1, $collection->maximumCount());
236
  $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
237
 
238
- $collection = Braintree_CreditCardVerification::search(array(
239
- Braintree_CreditCardVerificationSearch::id()->is($creditCardVerification->id),
240
- Braintree_CreditCardVerificationSearch::status()->in(
241
- array($creditCardVerification->status, Braintree_Result_creditCardVerification::VERIFIED)
242
  )
243
- ));
244
  $this->assertEquals(1, $collection->maximumCount());
245
  $this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
246
 
247
- $collection = Braintree_CreditCardVerification::search(array(
248
- Braintree_CreditCardVerificationSearch::id()->is($creditCardVerification->id),
249
- Braintree_CreditCardVerificationSearch::status()->is(Braintree_Result_creditCardVerification::VERIFIED)
250
- ));
251
  $this->assertEquals(0, $collection->maximumCount());
252
  }
253
  }
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
 
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
  }
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
+ }
braintree_sdk/tests/integration/CustomerAdvancedSearchTest.php CHANGED
@@ -1,24 +1,28 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/HttpClientApi.php';
4
 
5
- class Braintree_CustomerAdvancedSearchTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
6
  {
7
- function test_noMatches()
8
  {
9
- $collection = Braintree_Customer::search(array(
10
- Braintree_CustomerSearch::company()->is('badname')
11
- ));
12
 
13
  $this->assertEquals(0, $collection->maximumCount());
14
  }
15
 
16
- function test_noRequestsWhenIterating()
17
  {
18
  $resultsReturned = false;
19
- $collection = Braintree_Customer::search(array(
20
- Braintree_CustomerSearch::firstName()->is('badname')
21
- ));
22
 
23
  foreach($collection as $customer) {
24
  $resultsReturned = true;
@@ -29,17 +33,17 @@ class Braintree_CustomerAdvancedSearchTest extends PHPUnit_Framework_TestCase
29
  $this->assertEquals(false, $resultsReturned);
30
  }
31
 
32
- function test_findDuplicateCardsGivenPaymentMethodToken()
33
  {
34
- $creditCardRequest = array('number' => '63049580000009', 'expirationDate' => '05/2012');
35
 
36
- $jim = Braintree_Customer::create(array('firstName' => 'Jim', 'creditCard' => $creditCardRequest))->customer;
37
- $joe = Braintree_Customer::create(array('firstName' => 'Joe', 'creditCard' => $creditCardRequest))->customer;
38
 
39
- $query = array(Braintree_CustomerSearch::paymentMethodTokenWithDuplicates()->is($jim->creditCards[0]->token));
40
- $collection = Braintree_Customer::search($query);
41
 
42
- $customerIds = array();
43
  foreach($collection as $customer)
44
  {
45
  $customerIds[] = $customer->id;
@@ -49,11 +53,11 @@ class Braintree_CustomerAdvancedSearchTest extends PHPUnit_Framework_TestCase
49
  $this->assertTrue(in_array($joe->id, $customerIds));
50
  }
51
 
52
- function test_searchOnTextFields()
53
  {
54
  $token = 'cctoken' . rand();
55
 
56
- $search_criteria = array(
57
  'firstName' => 'Timmy',
58
  'lastName' => 'OToole',
59
  'company' => 'OToole and Son(s)' . rand(),
@@ -73,9 +77,9 @@ class Braintree_CustomerAdvancedSearchTest extends PHPUnit_Framework_TestCase
73
  'addressRegion' => 'Illinois',
74
  'addressPostalCode' => '60622',
75
  'addressCountryName' => 'United States of America'
76
- );
77
 
78
- $customer = Braintree_Customer::createNoValidate(array(
79
  'firstName' => $search_criteria['firstName'],
80
  'lastName' => $search_criteria['lastName'],
81
  'company' => $search_criteria['company'],
@@ -83,12 +87,12 @@ class Braintree_CustomerAdvancedSearchTest extends PHPUnit_Framework_TestCase
83
  'fax' => $search_criteria['fax'],
84
  'phone' => $search_criteria['phone'],
85
  'website' => $search_criteria['website'],
86
- 'creditCard' => array(
87
  'cardholderName' => 'Tim Toole',
88
  'number' => '4111111111111111',
89
  'expirationDate' => $search_criteria['creditCardExpirationDate'],
90
  'token' => $token,
91
- 'billingAddress' => array(
92
  'firstName' => $search_criteria['addressFirstName'],
93
  'lastName' => $search_criteria['addressLastName'],
94
  'streetAddress' => $search_criteria['addressStreetAddress'],
@@ -97,99 +101,99 @@ class Braintree_CustomerAdvancedSearchTest extends PHPUnit_Framework_TestCase
97
  'region' => $search_criteria['addressRegion'],
98
  'postalCode' => $search_criteria['addressPostalCode'],
99
  'countryName' => 'United States of America'
100
- )
101
- )
102
- ));
103
 
104
- $query = array(Braintree_CustomerSearch::id()->is($customer->id));
105
  foreach ($search_criteria AS $criterion => $value) {
106
- $query[] = Braintree_CustomerSearch::$criterion()->is($value);
107
  }
108
 
109
- $collection = Braintree_Customer::search($query);
110
 
111
  $this->assertEquals(1, $collection->maximumCount());
112
  $this->assertEquals($customer->id, $collection->firstItem()->id);
113
 
114
  foreach ($search_criteria AS $criterion => $value) {
115
- $collection = Braintree_Customer::search(array(
116
- Braintree_CustomerSearch::$criterion()->is($value),
117
- Braintree_CustomerSearch::id()->is($customer->id)
118
- ));
119
  $this->assertEquals(1, $collection->maximumCount());
120
  $this->assertEquals($customer->id, $collection->firstItem()->id);
121
 
122
- $collection = Braintree_Customer::search(array(
123
- Braintree_CustomerSearch::$criterion()->is('invalid_attribute'),
124
- Braintree_CustomerSearch::id()->is($customer->id)
125
- ));
126
  $this->assertEquals(0, $collection->maximumCount());
127
  }
128
  }
129
 
130
- function test_createdAt()
131
  {
132
- $customer = Braintree_Customer::createNoValidate();
133
 
134
  $past = clone $customer->createdAt;
135
  $past->modify("-1 hour");
136
  $future = clone $customer->createdAt;
137
  $future->modify("+1 hour");
138
 
139
- $collection = Braintree_Customer::search(array(
140
- Braintree_CustomerSearch::id()->is($customer->id),
141
- Braintree_CustomerSearch::createdAt()->between($past, $future)
142
- ));
143
  $this->assertEquals(1, $collection->maximumCount());
144
  $this->assertEquals($customer->id, $collection->firstItem()->id);
145
 
146
- $collection = Braintree_Customer::search(array(
147
- Braintree_CustomerSearch::id()->is($customer->id),
148
- Braintree_CustomerSearch::createdAt()->lessThanOrEqualTo($future)
149
- ));
150
  $this->assertEquals(1, $collection->maximumCount());
151
  $this->assertEquals($customer->id, $collection->firstItem()->id);
152
 
153
- $collection = Braintree_Customer::search(array(
154
- Braintree_CustomerSearch::id()->is($customer->id),
155
- Braintree_CustomerSearch::createdAt()->greaterThanOrEqualTo($past)
156
- ));
157
  $this->assertEquals(1, $collection->maximumCount());
158
  $this->assertEquals($customer->id, $collection->firstItem()->id);
159
  }
160
 
161
- function test_paypalAccountEmail()
162
  {
163
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
164
- $nonce = $http->nonceForPayPalAccount(array(
165
- 'paypal_account' => array(
166
  'consent_code' => 'PAYPAL_CONSENT_CODE',
167
- )
168
- ));
169
 
170
  $customerId = 'UNIQUE_CUSTOMER_ID-' . strval(rand());
171
- $customerResult = Braintree_Customer::create(array(
172
  'paymentMethodNonce' => $nonce,
173
  'id' => $customerId
174
- ));
175
 
176
  $this->assertTrue($customerResult->success);
177
 
178
  $customer = $customerResult->customer;
179
 
180
- $collection = Braintree_Customer::search(array(
181
- Braintree_CustomerSearch::id()->is($customer->id),
182
- Braintree_CustomerSearch::paypalAccountEmail()->is('jane.doe@example.com')
183
- ));
184
  $this->assertEquals(1, $collection->maximumCount());
185
  $this->assertEquals($customer->id, $collection->firstItem()->id);
186
  }
187
 
188
- function test_throwsIfNoOperatorNodeGiven()
189
  {
190
  $this->setExpectedException('InvalidArgumentException', 'Operator must be provided');
191
- Braintree_Customer::search(array(
192
- Braintree_CustomerSearch::creditCardExpirationDate()
193
- ));
194
  }
195
  }
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;
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;
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(),
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'],
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'],
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
  }
braintree_sdk/tests/integration/CustomerTest.php CHANGED
@@ -1,28 +1,33 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/HttpClientApi.php';
4
 
5
- class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
6
  {
7
- function testAll_smokeTest()
8
  {
9
- $all = Braintree_Customer::all();
10
  $this->assertTrue($all->maximumCount() > 0);
11
  }
12
 
13
- function testAllWithManyResults()
14
  {
15
- $collection = Braintree_Customer::all();
16
  $this->assertTrue($collection->maximumCount() > 1);
17
  $customer = $collection->firstItem();
18
 
19
  $this->assertTrue(strlen($customer->id) > 0);
20
- $this->assertTrue($customer instanceof Braintree_Customer);
21
  }
22
 
23
- function testCreate()
24
  {
25
- $result = Braintree_Customer::create(array(
26
  'firstName' => 'Mike',
27
  'lastName' => 'Jones',
28
  'company' => 'Jones Co.',
@@ -30,7 +35,7 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
30
  'phone' => '419.555.1234',
31
  'fax' => '419.555.1235',
32
  'website' => 'http://example.com'
33
- ));
34
  $this->assertEquals(true, $result->success);
35
  $customer = $result->customer;
36
  $this->assertEquals('Mike', $customer->firstName);
@@ -43,33 +48,33 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
43
  $this->assertNotNull($customer->merchantId);
44
  }
45
 
46
- function testCreateWithIdOfZero()
47
  {
48
- $result = Braintree_Customer::create(array(
49
  'id' => '0'
50
- ));
51
 
52
  $this->assertEquals(true, $result->success);
53
  $this->assertEquals($result->customer->id, '0');
54
- $customer = Braintree_Customer::find('0');
55
 
56
  $this->assertEquals('0', $customer->id);
57
 
58
- Braintree_Customer::delete('0');
59
  }
60
 
61
- function testGatewayCreate()
62
  {
63
- $gateway = new Braintree_Gateway(array(
64
  'environment' => 'development',
65
  'merchantId' => 'integration_merchant_id',
66
  'publicKey' => 'integration_public_key',
67
  'privateKey' => 'integration_private_key'
68
- ));
69
- $result = $gateway->customer()->create(array(
70
  'firstName' => 'Mike',
71
  'lastName' => 'Jones',
72
- ));
73
  $this->assertEquals(true, $result->success);
74
  $customer = $result->customer;
75
  $this->assertEquals('Mike', $customer->firstName);
@@ -77,22 +82,22 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
77
  $this->assertNotNull($customer->merchantId);
78
  }
79
 
80
- function testCreateWithAccessToken()
81
  {
82
- $credentials = Braintree_OAuthTestHelper::createCredentials(array(
83
  'clientId' => 'client_id$development$integration_client_id',
84
  'clientSecret' => 'client_secret$development$integration_client_secret',
85
  'merchantId' => 'integration_merchant_id',
86
- ));
87
 
88
- $gateway = new Braintree_Gateway(array(
89
  'accessToken' => $credentials->accessToken,
90
- ));
91
 
92
- $result = $gateway->customer()->create(array(
93
  'firstName' => 'Mike',
94
  'lastName' => 'Jones',
95
- ));
96
  $this->assertEquals(true, $result->success);
97
  $customer = $result->customer;
98
  $this->assertEquals('Mike', $customer->firstName);
@@ -100,81 +105,114 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
100
  $this->assertNotNull($customer->merchantId);
101
  }
102
 
103
- function testCreateCustomerWithCardUsingNonce()
104
  {
105
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
106
- $nonce = $http->nonce_for_new_card(array(
107
- "creditCard" => array(
108
  "number" => "4111111111111111",
109
  "expirationMonth" => "11",
110
  "expirationYear" => "2099"
111
- ),
112
  "share" => true
113
- ));
114
 
115
- $result = Braintree_Customer::create(array(
116
- 'creditCard' => array(
117
  'paymentMethodNonce' => $nonce
118
- )
119
- ));
120
 
121
  $this->assertTrue($result->success);
122
  $this->assertSame("411111", $result->customer->creditCards[0]->bin);
123
  $this->assertSame("1111", $result->customer->creditCards[0]->last4);
124
  }
125
 
126
- function testCreateCustomerWithApplePayCard()
127
  {
128
- $nonce = Braintree_Test_Nonces::$applePayVisa;
129
- $result = Braintree_Customer::create(array(
130
  'paymentMethodNonce' => $nonce
131
- ));
132
  $this->assertTrue($result->success);
133
  $customer = $result->customer;
134
  $this->assertNotNull($customer->applePayCards[0]);
135
  $this->assertNotNull($customer->paymentMethods[0]);
136
  }
137
 
138
- function testCreateCustomerWithAndroidPayProxyCard()
139
  {
140
- $nonce = Braintree_Test_Nonces::$androidPayDiscover;
141
- $result = Braintree_Customer::create(array(
142
  'paymentMethodNonce' => $nonce
143
- ));
144
  $this->assertTrue($result->success);
145
  $customer = $result->customer;
146
  $this->assertNotNull($customer->androidPayCards[0]);
147
  $this->assertNotNull($customer->paymentMethods[0]);
148
  $androidPayCard = $customer->androidPayCards[0];
149
- $this->assertTrue($androidPayCard instanceof Braintree_AndroidPayCard);
150
  $this->assertNotNull($androidPayCard->token);
151
  $this->assertNotNull($androidPayCard->expirationYear);
152
  }
153
 
154
- function testCreateCustomerWithAndroidPayNetworkToken()
155
  {
156
- $nonce = Braintree_Test_Nonces::$androidPayMasterCard;
157
- $result = Braintree_Customer::create(array(
158
  'paymentMethodNonce' => $nonce
159
- ));
160
  $this->assertTrue($result->success);
161
  $customer = $result->customer;
162
  $this->assertNotNull($customer->androidPayCards[0]);
163
  $this->assertNotNull($customer->paymentMethods[0]);
164
  $androidPayCard = $customer->androidPayCards[0];
165
- $this->assertTrue($androidPayCard instanceof Braintree_AndroidPayCard);
166
  $this->assertNotNull($androidPayCard->token);
167
  $this->assertNotNull($androidPayCard->expirationYear);
168
  }
169
 
170
- function testCreateCustomerWithCoinbase()
171
  {
172
- $nonce = Braintree_Test_Nonces::$coinbase;
173
- $result = Braintree_Customer::create(array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
  'paymentMethodNonce' => $nonce
175
  ));
176
  $this->assertTrue($result->success);
177
  $customer = $result->customer;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  $this->assertNotNull($customer->coinbaseAccounts[0]);
179
  $this->assertNotNull($customer->coinbaseAccounts[0]->userId);
180
  $this->assertNotNull($customer->coinbaseAccounts[0]->userName);
@@ -182,9 +220,9 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
182
  $this->assertNotNull($customer->paymentMethods[0]);
183
  }
184
 
185
- function testCreate_withUnicode()
186
  {
187
- $result = Braintree_Customer::create(array(
188
  'firstName' => "Здравствуйте",
189
  'lastName' => 'Jones',
190
  'company' => 'Jones Co.',
@@ -192,7 +230,7 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
192
  'phone' => '419.555.1234',
193
  'fax' => '419.555.1235',
194
  'website' => 'http://example.com'
195
- ));
196
  $this->assertEquals(true, $result->success);
197
  $customer = $result->customer;
198
  $this->assertEquals("Здравствуйте", $customer->firstName);
@@ -205,22 +243,22 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
205
  $this->assertNotNull($customer->merchantId);
206
  }
207
 
208
- function testCreate_withCountry()
209
  {
210
- $result = Braintree_Customer::create(array(
211
  'firstName' => 'Bat',
212
  'lastName' => 'Manderson',
213
- 'creditCard' => array(
214
  'number' => '5105105105105100',
215
  'expirationDate' => '05/12',
216
- 'billingAddress' => array(
217
  'countryName' => 'Gabon',
218
  'countryCodeAlpha2' => 'GA',
219
  'countryCodeAlpha3' => 'GAB',
220
  'countryCodeNumeric' => '266'
221
- )
222
- )
223
- ));
224
  $this->assertEquals(true, $result->success);
225
  $customer = $result->customer;
226
  $this->assertEquals('Gabon', $customer->creditCards[0]->billingAddress->countryName);
@@ -230,88 +268,88 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
230
  $this->assertEquals(1, preg_match('/\A\w{32}\z/', $customer->creditCards[0]->uniqueNumberIdentifier));
231
  }
232
 
233
- function testCreate_withVenmoSdkSession()
234
  {
235
- $result = Braintree_Customer::create(array(
236
  'firstName' => 'Bat',
237
  'lastName' => 'Manderson',
238
- 'creditCard' => array(
239
  'number' => '5105105105105100',
240
  'expirationDate' => '05/12',
241
- 'options' => array(
242
- 'venmoSdkSession' => Braintree_Test_VenmoSdk::getTestSession()
243
- )
244
- )
245
- ));
246
  $this->assertEquals(true, $result->success);
247
  $customer = $result->customer;
248
  $this->assertEquals(true, $customer->creditCards[0]->venmoSdk);
249
  }
250
 
251
- function testCreate_withVenmoSdkPaymentMethodCode()
252
  {
253
- $result = Braintree_Customer::create(array(
254
  'firstName' => 'Bat',
255
  'lastName' => 'Manderson',
256
- 'creditCard' => array(
257
- 'venmoSdkPaymentMethodCode' => Braintree_Test_VenmoSdk::$visaPaymentMethodCode
258
- )
259
- ));
260
  $this->assertEquals(true, $result->success);
261
  $customer = $result->customer;
262
  $this->assertEquals("411111", $customer->creditCards[0]->bin);
263
  }
264
 
265
- function testCreate_blankCustomer()
266
  {
267
- $result = Braintree_Customer::create();
268
  $this->assertEquals(true, $result->success);
269
  $this->assertNotNull($result->customer->id);
270
 
271
- $result = Braintree_Customer::create(array());
272
  $this->assertEquals(true, $result->success);
273
  $this->assertNotNull($result->customer->id);
274
  }
275
 
276
- function testCreate_withSpecialChars()
277
  {
278
- $result = Braintree_Customer::create(array('firstName' => '<>&"\''));
279
  $this->assertEquals(true, $result->success);
280
  $this->assertEquals('<>&"\'', $result->customer->firstName);
281
  }
282
 
283
- function testCreate_withCustomFields()
284
  {
285
- $result = Braintree_Customer::create(array(
286
  'firstName' => 'Mike',
287
- 'customFields' => array(
288
  'store_me' => 'some custom value'
289
- )
290
- ));
291
  $this->assertEquals(true, $result->success);
292
  $customFields = $result->customer->customFields;
293
  $this->assertEquals('some custom value', $customFields['store_me']);
294
  }
295
 
296
- function testCreate_withFraudParams()
297
  {
298
- $result = Braintree_Customer::create(array(
299
  'firstName' => 'Mike',
300
- 'creditCard' => array(
301
  'number' => '5105105105105100',
302
  'expirationDate' => '05/12',
303
  'cvv' => '123',
304
  'cardholderName' => 'Mike Jones',
305
  'deviceSessionId' => 'abc123',
306
  'fraudMerchantId' => '456'
307
- )
308
- ));
309
  $this->assertEquals(true, $result->success);
310
  }
311
 
312
- function testCreate_withCreditCard()
313
  {
314
- $result = Braintree_Customer::create(array(
315
  'firstName' => 'Mike',
316
  'lastName' => 'Jones',
317
  'company' => 'Jones Co.',
@@ -319,13 +357,13 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
319
  'phone' => '419.555.1234',
320
  'fax' => '419.555.1235',
321
  'website' => 'http://example.com',
322
- 'creditCard' => array(
323
  'number' => '5105105105105100',
324
  'expirationDate' => '05/12',
325
  'cvv' => '123',
326
  'cardholderName' => 'Mike Jones'
327
- )
328
- ));
329
  $this->assertEquals(true, $result->success);
330
  $customer = $result->customer;
331
  $this->assertEquals('Mike', $customer->firstName);
@@ -344,11 +382,11 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
344
  $this->assertEquals('2012', $creditCard->expirationYear);
345
  }
346
 
347
- function testCreate_withDuplicateCardCheck()
348
  {
349
- $customer = Braintree_Customer::createNoValidate();
350
 
351
- $attributes = array(
352
  'firstName' => 'Mike',
353
  'lastName' => 'Jones',
354
  'company' => 'Jones Co.',
@@ -356,28 +394,28 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
356
  'phone' => '419.555.1234',
357
  'fax' => '419.555.1235',
358
  'website' => 'http://example.com',
359
- 'creditCard' => array(
360
  'number' => '5105105105105100',
361
  'expirationDate' => '05/12',
362
  'cvv' => '123',
363
  'cardholderName' => 'Mike Jones',
364
- 'options' => array(
365
  'failOnDuplicatePaymentMethod' => true
366
- )
367
- )
368
- );
369
- Braintree_Customer::create($attributes);
370
- $result = Braintree_Customer::create($attributes);
371
 
372
  $this->assertFalse($result->success);
373
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('number');
374
- $this->assertEquals(Braintree_Error_Codes::CREDIT_CARD_DUPLICATE_CARD_EXISTS, $errors[0]->code);
375
  $this->assertEquals(1, preg_match('/Duplicate card exists in the vault\./', $result->message));
376
  }
377
 
378
- function testCreate_withCreditCardAndSpecificVerificationMerchantAccount()
379
  {
380
- $result = Braintree_Customer::create(array(
381
  'firstName' => 'Mike',
382
  'lastName' => 'Jones',
383
  'company' => 'Jones Co.',
@@ -385,20 +423,20 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
385
  'phone' => '419.555.1234',
386
  'fax' => '419.555.1235',
387
  'website' => 'http://example.com',
388
- 'creditCard' => array(
389
  'number' => '5105105105105100',
390
  'expirationDate' => '05/12',
391
  'cvv' => '123',
392
  'cardholderName' => 'Mike Jones',
393
- 'options' => array(
394
- 'verificationMerchantAccountId' => Braintree_TestHelper::nonDefaultMerchantAccountId(),
395
  'verifyCard' => true
396
- )
397
- )
398
- ));
399
- Braintree_TestHelper::assertPrintable($result);
400
  $this->assertFalse($result->success);
401
- $this->assertEquals(Braintree_Result_CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
402
  $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
403
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
404
  $this->assertEquals('M', $result->creditCardVerification->cvvResponseCode);
@@ -407,9 +445,9 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
407
  $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
408
  }
409
 
410
- function testCreate_withCreditCardAndBillingAddress()
411
  {
412
- $result = Braintree_Customer::create(array(
413
  'firstName' => 'Mike',
414
  'lastName' => 'Jones',
415
  'company' => 'Jones Co.',
@@ -417,12 +455,12 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
417
  'phone' => '419.555.1234',
418
  'fax' => '419.555.1235',
419
  'website' => 'http://example.com',
420
- 'creditCard' => array(
421
  'number' => '5105105105105100',
422
  'expirationDate' => '05/12',
423
  'cvv' => '123',
424
  'cardholderName' => 'Mike Jones',
425
- 'billingAddress' => array(
426
  'firstName' => 'Drew',
427
  'lastName' => 'Smith',
428
  'company' => 'Smith Co.',
@@ -432,10 +470,10 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
432
  'region' => 'IL',
433
  'postalCode' => '60622',
434
  'countryName' => 'United States of America'
435
- )
436
- )
437
- ));
438
- Braintree_TestHelper::assertPrintable($result);
439
  $this->assertEquals(true, $result->success);
440
  $customer = $result->customer;
441
  $this->assertEquals('Mike', $customer->firstName);
@@ -465,95 +503,95 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
465
  $this->assertEquals('United States of America', $address->countryName);
466
  }
467
 
468
- function testCreate_withValidationErrors()
469
  {
470
- $result = Braintree_Customer::create(array(
471
  'email' => 'invalid',
472
- 'creditCard' => array(
473
  'number' => 'invalid',
474
- 'billingAddress' => array(
475
  'streetAddress' => str_repeat('x', 256)
476
- )
477
- )
478
- ));
479
- Braintree_TestHelper::assertPrintable($result);
480
  $this->assertEquals(false, $result->success);
481
  $errors = $result->errors->forKey('customer')->onAttribute('email');
482
- $this->assertEquals(Braintree_Error_Codes::CUSTOMER_EMAIL_IS_INVALID, $errors[0]->code);
483
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('number');
484
- $this->assertEquals(Braintree_Error_Codes::CREDIT_CARD_NUMBER_INVALID_LENGTH, $errors[0]->code);
485
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->forKey('billingAddress')->onAttribute('streetAddress');
486
- $this->assertEquals(Braintree_Error_Codes::ADDRESS_STREET_ADDRESS_IS_TOO_LONG, $errors[0]->code);
487
  }
488
 
489
- function testCreate_countryValidations_inconsistency()
490
  {
491
- $result = Braintree_Customer::create(array(
492
- 'creditCard' => array(
493
- 'billingAddress' => array(
494
  'countryName' => 'Georgia',
495
  'countryCodeAlpha2' => 'TF'
496
- )
497
- )
498
- ));
499
  $this->assertEquals(false, $result->success);
500
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->forKey('billingAddress')->onAttribute('base');
501
- $this->assertEquals(Braintree_Error_Codes::ADDRESS_INCONSISTENT_COUNTRY, $errors[0]->code);
502
  }
503
 
504
- function testCreateNoValidate_returnsCustomer()
505
  {
506
- $customer = Braintree_Customer::createNoValidate(array(
507
  'firstName' => 'Paul',
508
  'lastName' => 'Martin'
509
- ));
510
  $this->assertEquals('Paul', $customer->firstName);
511
  $this->assertEquals('Martin', $customer->lastName);
512
  }
513
 
514
- function testCreateNoValidate_throwsIfInvalid()
515
  {
516
- $this->setExpectedException('Braintree_Exception_ValidationsFailed');
517
- $customer = Braintree_Customer::createNoValidate(array('email' => 'invalid'));
518
  }
519
 
520
- function testCreate_worksWithFuturePayPalNonce()
521
  {
522
- $nonce = Braintree_Test_Nonces::$paypalFuturePayment;
523
 
524
- $result = Braintree_Customer::create(array(
525
  'paymentMethodNonce' => $nonce
526
- ));
527
 
528
  $this->assertTrue($result->success);
529
  }
530
 
531
- function testCreate_doesNotWorkWithOnetimePayPalNonce()
532
  {
533
- $nonce = Braintree_Test_Nonces::$paypalOneTimePayment;
534
 
535
- $result = Braintree_Customer::create(array(
536
  'paymentMethodNonce' => $nonce
537
- ));
538
 
539
  $this->assertFalse($result->success);
540
  $errors = $result->errors->forKey('customer')->forKey('paypalAccount')->errors;
541
- $this->assertEquals(Braintree_Error_Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
542
  }
543
 
544
- function testDelete_deletesTheCustomer()
545
  {
546
- $result = Braintree_Customer::create(array());
547
  $this->assertEquals(true, $result->success);
548
- Braintree_Customer::find($result->customer->id);
549
- Braintree_Customer::delete($result->customer->id);
550
- $this->setExpectedException('Braintree_Exception_NotFound');
551
- Braintree_Customer::find($result->customer->id);
552
  }
553
 
554
- function testFind()
555
  {
556
- $result = Braintree_Customer::create(array(
557
  'firstName' => 'Mike',
558
  'lastName' => 'Jones',
559
  'company' => 'Jones Co.',
@@ -561,9 +599,9 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
561
  'phone' => '419.555.1234',
562
  'fax' => '419.555.1235',
563
  'website' => 'http://example.com'
564
- ));
565
  $this->assertEquals(true, $result->success);
566
- $customer = Braintree_Customer::find($result->customer->id);
567
  $this->assertEquals('Mike', $customer->firstName);
568
  $this->assertEquals('Jones', $customer->lastName);
569
  $this->assertEquals('Jones Co.', $customer->company);
@@ -573,15 +611,15 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
573
  $this->assertEquals('http://example.com', $customer->website);
574
  }
575
 
576
- function testFind_throwsExceptionIfNotFound()
577
  {
578
- $this->setExpectedException('Braintree_Exception_NotFound');
579
- Braintree_Customer::find("does-not-exist");
580
  }
581
 
582
- function testUpdate()
583
  {
584
- $result = Braintree_Customer::create(array(
585
  'firstName' => 'Old First',
586
  'lastName' => 'Old Last',
587
  'company' => 'Old Company',
@@ -589,10 +627,10 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
589
  'phone' => 'old phone',
590
  'fax' => 'old fax',
591
  'website' => 'http://old.example.com'
592
- ));
593
  $this->assertEquals(true, $result->success);
594
  $customer = $result->customer;
595
- $updateResult = Braintree_Customer::update($customer->id, array(
596
  'firstName' => 'New First',
597
  'lastName' => 'New Last',
598
  'company' => 'New Company',
@@ -600,7 +638,7 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
600
  'phone' => 'new phone',
601
  'fax' => 'new fax',
602
  'website' => 'http://new.example.com'
603
- ));
604
  $this->assertEquals(true, $updateResult->success);
605
  $this->assertEquals('New First', $updateResult->customer->firstName);
606
  $this->assertEquals('New Last', $updateResult->customer->lastName);
@@ -611,41 +649,41 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
611
  $this->assertEquals('http://new.example.com', $updateResult->customer->website);
612
  }
613
 
614
- function testUpdate_withCountry()
615
  {
616
- $customer = Braintree_Customer::create(array(
617
  'firstName' => 'Bat',
618
  'lastName' => 'Manderson',
619
- 'creditCard' => array(
620
  'number' => '5105105105105100',
621
  'expirationDate' => '05/12',
622
- 'billingAddress' => array(
623
  'countryName' => 'United States of America',
624
  'countryCodeAlpha2' => 'US',
625
  'countryCodeAlpha3' => 'USA',
626
  'countryCodeNumeric' => '840'
627
- )
628
- )
629
- ))->customer;
630
 
631
- $result = Braintree_Customer::update($customer->id, array(
632
  'firstName' => 'Bat',
633
  'lastName' => 'Manderson',
634
- 'creditCard' => array(
635
- 'options' => array(
636
  'updateExistingToken' => $customer->creditCards[0]->token
637
- ),
638
- 'billingAddress' => array(
639
  'countryName' => 'Gabon',
640
  'countryCodeAlpha2' => 'GA',
641
  'countryCodeAlpha3' => 'GAB',
642
  'countryCodeNumeric' => '266',
643
- 'options' => array(
644
  'updateExisting' => true
645
- )
646
- )
647
- )
648
- ));
649
 
650
  $this->assertEquals(true, $result->success);
651
  $updatedCustomer = $result->customer;
@@ -655,33 +693,33 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
655
  $this->assertEquals('266', $updatedCustomer->creditCards[0]->billingAddress->countryCodeNumeric);
656
  }
657
 
658
- function testUpdate_withUpdatingExistingCreditCard()
659
  {
660
- $create_result = Braintree_Customer::create(array(
661
  'firstName' => 'Old First',
662
  'lastName' => 'Old Last',
663
  'website' => 'http://old.example.com',
664
- 'creditCard' => array(
665
  'number' => '5105105105105100',
666
  'expirationDate' => '05/12',
667
  'cardholderName' => 'Old Cardholder'
668
- )
669
- ));
670
  $this->assertEquals(true, $create_result->success);
671
  $customer = $create_result->customer;
672
  $creditCard = $customer->creditCards[0];
673
- $result = Braintree_Customer::update($customer->id, array(
674
  'firstName' => 'New First',
675
  'lastName' => 'New Last',
676
- 'creditCard' => array(
677
  'number' => '4111111111111111',
678
  'expirationDate' => '11/14',
679
  'cardholderName' => 'New Cardholder',
680
- 'options' => array(
681
  'updateExistingToken' => $creditCard->token
682
- )
683
- )
684
- ));
685
  $this->assertEquals(true, $result->success);
686
  $this->assertEquals('New First', $result->customer->firstName);
687
  $this->assertEquals('New Last', $result->customer->lastName);
@@ -692,43 +730,43 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
692
  $this->assertEquals('New Cardholder', $creditCard->cardholderName);
693
  }
694
 
695
- function testUpdate_forBillingAddressAndExistingCreditCardAndCustomerDetailsTogether()
696
  {
697
- $create_result = Braintree_Customer::create(array(
698
  'firstName' => 'Old First',
699
  'lastName' => 'Old Last',
700
- 'creditCard' => array(
701
  'number' => '5105105105105100',
702
  'expirationDate' => '05/12',
703
  'cvv' => '123',
704
  'cardholderName' => 'Old Cardholder',
705
- 'billingAddress' => array(
706
  'firstName' => 'Drew',
707
  'lastName' => 'Smith'
708
- )
709
- )
710
- ));
711
  $this->assertEquals(true, $create_result->success);
712
  $customer = $create_result->customer;
713
  $creditCard = $customer->creditCards[0];
714
- $result = Braintree_Customer::update($customer->id, array(
715
  'firstName' => 'New Customer First',
716
  'lastName' => 'New Customer Last',
717
- 'creditCard' => array(
718
  'number' => '4111111111111111',
719
  'expirationDate' => '11/14',
720
- 'options' => array(
721
  'updateExistingToken' => $creditCard->token
722
- ),
723
- 'billingAddress' => array(
724
  'firstName' => 'New Billing First',
725
  'lastName' => 'New Billing Last',
726
- 'options' => array(
727
  'updateExisting' => true
728
- )
729
- )
730
- )
731
- ));
732
  $this->assertEquals(true, $result->success);
733
  $this->assertEquals('New Customer First', $result->customer->firstName);
734
  $this->assertEquals('New Customer Last', $result->customer->lastName);
@@ -744,95 +782,95 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
744
  $this->assertEquals('New Billing Last', $billingAddress->lastName);
745
  }
746
 
747
- function testUpdate_withNewCreditCardAndExistingBillingAddress()
748
  {
749
- $customer = Braintree_Customer::create()->customer;
750
- $address = Braintree_Address::create(array(
751
  'customerId' => $customer->id,
752
  'firstName' => 'Dan'
753
- ))->address;
754
 
755
- $result = Braintree_Customer::update($customer->id, array(
756
- 'creditCard' => array(
757
  'number' => '4111111111111111',
758
  'expirationDate' => '11/14',
759
  'billingAddressId' => $address->id
760
- )
761
- ));
762
 
763
  $billingAddress = $result->customer->creditCards[0]->billingAddress;
764
  $this->assertEquals($address->id, $billingAddress->id);
765
  $this->assertEquals('Dan', $billingAddress->firstName);
766
  }
767
 
768
- function testUpdate_worksWithFuturePayPalNonce()
769
  {
770
- $customerResult = Braintree_Customer::create(array(
771
- 'creditCard' => array(
772
  'number' => '5105105105105100',
773
  'expirationDate' => '05/12',
774
- 'options' => array(
775
  'makeDefault' => true
776
- )
777
- )
778
- ));
779
  $paypalAccountToken = 'PAYPALToken-' . strval(rand());
780
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
781
- $nonce = $http->nonceForPayPalAccount(array(
782
- 'paypal_account' => array(
783
  'consent_code' => 'PAYPAL_CONSENT_CODE',
784
  'token' => $paypalAccountToken,
785
- 'options' => array(
786
  'makeDefault' => true
787
- )
788
- )
789
- ));
790
 
791
- $result = Braintree_Customer::update($customerResult->customer->id, array(
792
  'paymentMethodNonce' => $nonce
793
- ));
794
 
795
  $this->assertTrue($result->success);
796
  $this->assertEquals($result->customer->defaultPaymentMethod()->token, $paypalAccountToken);
797
 
798
  }
799
 
800
- function testUpdate_doesNotWorkWithOnetimePayPalNonce()
801
  {
802
- $customerResult = Braintree_Customer::create(array(
803
- 'creditCard' => array(
804
  'number' => '5105105105105100',
805
  'expirationDate' => '05/12',
806
- 'options' => array(
807
  'makeDefault' => true
808
- )
809
- )
810
- ));
811
  $paypalAccountToken = 'PAYPALToken-' . strval(rand());
812
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
813
- $nonce = $http->nonceForPayPalAccount(array(
814
- 'paypal_account' => array(
815
  'access_token' => 'PAYPAL_ACCESS_TOKEN',
816
  'token' => $paypalAccountToken,
817
- 'options' => array(
818
  'makeDefault' => true
819
- )
820
- )
821
- ));
822
 
823
- $result = Braintree_Customer::update($customerResult->customer->id, array(
824
  'paymentMethodNonce' => $nonce
825
- ));
826
 
827
  $this->assertFalse($result->success);
828
  $errors = $result->errors->forKey('customer')->forKey('paypalAccount')->errors;
829
- $this->assertEquals(Braintree_Error_Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
830
 
831
  }
832
 
833
- function testUpdateNoValidate()
834
  {
835
- $result = Braintree_Customer::create(array(
836
  'firstName' => 'Old First',
837
  'lastName' => 'Old Last',
838
  'company' => 'Old Company',
@@ -840,10 +878,10 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
840
  'phone' => 'old phone',
841
  'fax' => 'old fax',
842
  'website' => 'http://old.example.com'
843
- ));
844
  $this->assertEquals(true, $result->success);
845
  $customer = $result->customer;
846
- $updated = Braintree_Customer::updateNoValidate($customer->id, array(
847
  'firstName' => 'New First',
848
  'lastName' => 'New Last',
849
  'company' => 'New Company',
@@ -851,7 +889,7 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
851
  'phone' => 'new phone',
852
  'fax' => 'new fax',
853
  'website' => 'http://new.example.com'
854
- ));
855
  $this->assertEquals('New First', $updated->firstName);
856
  $this->assertEquals('New Last', $updated->lastName);
857
  $this->assertEquals('New Company', $updated->company);
@@ -861,24 +899,24 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
861
  $this->assertEquals('http://new.example.com', $updated->website);
862
  }
863
 
864
- function testCreateFromTransparentRedirect()
865
  {
866
- Braintree_TestHelper::suppressDeprecationWarnings();
867
  $queryString = $this->createCustomerViaTr(
868
- array(
869
- 'customer' => array(
870
  'first_name' => 'Joe',
871
  'last_name' => 'Martin',
872
- 'credit_card' => array(
873
  'number' => '5105105105105100',
874
  'expiration_date' => '05/12'
875
- )
876
- )
877
- ),
878
- array(
879
- )
880
  );
881
- $result = Braintree_Customer::createFromTransparentRedirect($queryString);
882
  $this->assertTrue($result->success);
883
  $this->assertEquals('Joe', $result->customer->firstName);
884
  $this->assertEquals('Martin', $result->customer->lastName);
@@ -888,24 +926,24 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
888
  $this->assertEquals('05/2012', $creditCard->expirationDate);
889
  }
890
 
891
- function testCreateFromTransparentRedirect_withParamsInTrData()
892
  {
893
- Braintree_TestHelper::suppressDeprecationWarnings();
894
  $queryString = $this->createCustomerViaTr(
895
- array(
896
- ),
897
- array(
898
- 'customer' => array(
899
  'firstName' => 'Joe',
900
  'lastName' => 'Martin',
901
- 'creditCard' => array(
902
  'number' => '5105105105105100',
903
  'expirationDate' => '05/12'
904
- )
905
- )
906
- )
907
  );
908
- $result = Braintree_Customer::createFromTransparentRedirect($queryString);
909
  $this->assertTrue($result->success);
910
  $this->assertEquals('Joe', $result->customer->firstName);
911
  $this->assertEquals('Martin', $result->customer->lastName);
@@ -915,161 +953,161 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
915
  $this->assertEquals('05/2012', $creditCard->expirationDate);
916
  }
917
 
918
- function testCreateFromTransparentRedirect_withValidationErrors()
919
  {
920
- Braintree_TestHelper::suppressDeprecationWarnings();
921
  $queryString = $this->createCustomerViaTr(
922
- array(
923
- 'customer' => array(
924
  'first_name' => str_repeat('x', 256),
925
- 'credit_card' => array(
926
  'number' => 'invalid',
927
  'expiration_date' => ''
928
- )
929
- )
930
- ),
931
- array(
932
- )
933
  );
934
- $result = Braintree_Customer::createFromTransparentRedirect($queryString);
935
  $this->assertFalse($result->success);
936
  $errors = $result->errors->forKey('customer')->onAttribute('firstName');
937
- $this->assertEquals(Braintree_Error_Codes::CUSTOMER_FIRST_NAME_IS_TOO_LONG, $errors[0]->code);
938
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('number');
939
- $this->assertEquals(Braintree_Error_Codes::CREDIT_CARD_NUMBER_INVALID_LENGTH, $errors[0]->code);
940
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('expirationDate');
941
- $this->assertEquals(Braintree_Error_Codes::CREDIT_CARD_EXPIRATION_DATE_IS_REQUIRED, $errors[0]->code);
942
  }
943
 
944
- function testCreateWithInvalidUTF8Bytes()
945
  {
946
- $result = Braintree_Customer::create(array(
947
- 'firstName' => "Jos\xe8 Maria",
948
- ));
949
  $this->assertEquals(true, $result->success);
950
  $customer = $result->customer;
951
  $this->assertEquals("Jos\xc3\xa8 Maria", $customer->firstName);
952
  }
953
 
954
- function testCreateWithValidUTF8Bytes()
955
  {
956
- $result = Braintree_Customer::create(array(
957
- 'firstName' => "Jos\303\251",
958
- ));
959
  $this->assertEquals(true, $result->success);
960
  $customer = $result->customer;
961
  $this->assertEquals("Jos\303\251", $customer->firstName);
962
  }
963
 
964
- function testUpdateFromTransparentRedirect()
965
  {
966
- Braintree_TestHelper::suppressDeprecationWarnings();
967
- $customer = Braintree_Customer::createNoValidate();
968
  $queryString = $this->updateCustomerViaTr(
969
- array(
970
- 'customer' => array(
971
  'first_name' => 'Joe',
972
  'last_name' => 'Martin',
973
  'email' => 'joe.martin@example.com'
974
- )
975
- ),
976
- array(
977
  'customerId' => $customer->id
978
- )
979
  );
980
- $result = Braintree_Customer::updateFromTransparentRedirect($queryString);
981
  $this->assertTrue($result->success);
982
  $this->assertEquals('Joe', $result->customer->firstName);
983
  $this->assertEquals('Martin', $result->customer->lastName);
984
  $this->assertEquals('joe.martin@example.com', $result->customer->email);
985
  }
986
 
987
- function testUpdateFromTransparentRedirect_withParamsInTrData()
988
  {
989
- Braintree_TestHelper::suppressDeprecationWarnings();
990
- $customer = Braintree_Customer::createNoValidate();
991
  $queryString = $this->updateCustomerViaTr(
992
- array(
993
- ),
994
- array(
995
  'customerId' => $customer->id,
996
- 'customer' => array(
997
  'firstName' => 'Joe',
998
  'lastName' => 'Martin',
999
  'email' => 'joe.martin@example.com'
1000
- )
1001
- )
1002
  );
1003
- $result = Braintree_Customer::updateFromTransparentRedirect($queryString);
1004
  $this->assertTrue($result->success);
1005
  $this->assertEquals('Joe', $result->customer->firstName);
1006
  $this->assertEquals('Martin', $result->customer->lastName);
1007
  $this->assertEquals('joe.martin@example.com', $result->customer->email);
1008
  }
1009
 
1010
- function testUpdateFromTransparentRedirect_withValidationErrors()
1011
  {
1012
- Braintree_TestHelper::suppressDeprecationWarnings();
1013
- $customer = Braintree_Customer::createNoValidate();
1014
  $queryString = $this->updateCustomerViaTr(
1015
- array(
1016
- 'customer' => array(
1017
  'first_name' => str_repeat('x', 256),
1018
- )
1019
- ),
1020
- array(
1021
  'customerId' => $customer->id
1022
- )
1023
  );
1024
- $result = Braintree_Customer::updateFromTransparentRedirect($queryString);
1025
  $this->assertFalse($result->success);
1026
  $errors = $result->errors->forKey('customer')->onAttribute('firstName');
1027
- $this->assertEquals(Braintree_Error_Codes::CUSTOMER_FIRST_NAME_IS_TOO_LONG, $errors[0]->code);
1028
  }
1029
 
1030
- function testUpdateFromTransparentRedirect_withUpdateExisting()
1031
  {
1032
- Braintree_TestHelper::suppressDeprecationWarnings();
1033
- $customer = Braintree_Customer::create(array(
1034
  'firstName' => 'Mike',
1035
  'lastName' => 'Jones',
1036
- 'creditCard' => array(
1037
  'number' => '5105105105105100',
1038
  'expirationDate' => '05/12',
1039
  'cardholderName' => 'Mike Jones',
1040
- 'billingAddress' => array(
1041
  'firstName' => 'Drew',
1042
  'lastName' => 'Smith'
1043
- )
1044
- )
1045
- ))->customer;
1046
 
1047
  $queryString = $this->updateCustomerViaTr(
1048
- array(),
1049
- array(
1050
  'customerId' => $customer->id,
1051
- 'customer' => array(
1052
  'firstName' => 'New First',
1053
  'lastName' => 'New Last',
1054
- 'creditCard' => array(
1055
  'number' => '4111111111111111',
1056
  'expirationDate' => '05/13',
1057
  'cardholderName' => 'New Cardholder',
1058
- 'options' => array(
1059
  'updateExistingToken' => $customer->creditCards[0]->token
1060
- ),
1061
- 'billingAddress' => array(
1062
  'firstName' => 'New First Billing',
1063
  'lastName' => 'New Last Billing',
1064
- 'options' => array(
1065
  'updateExisting' => true
1066
- )
1067
- )
1068
- )
1069
- )
1070
- )
1071
  );
1072
- $result = Braintree_Customer::updateFromTransparentRedirect($queryString);
1073
  $this->assertTrue($result->success);
1074
 
1075
  $this->assertEquals(true, $result->success);
@@ -1091,129 +1129,129 @@ class Braintree_CustomerTest extends PHPUnit_Framework_TestCase
1091
  $this->assertEquals('New Last Billing', $address->lastName);
1092
  }
1093
 
1094
- function testSale_createsASaleUsingGivenToken()
1095
  {
1096
- $customer = Braintree_Customer::createNoValidate(array(
1097
- 'creditCard' => array(
1098
  'number' => '5105105105105100',
1099
  'expirationDate' => '05/12'
1100
- )
1101
- ));
1102
  $creditCard = $customer->creditCards[0];
1103
- $result = Braintree_Customer::sale($customer->id, array(
1104
  'amount' => '100.00'
1105
- ));
1106
  $this->assertTrue($result->success);
1107
  $this->assertEquals('100.00', $result->transaction->amount);
1108
  $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
1109
  $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
1110
  }
1111
 
1112
- function testSaleNoValidate_createsASaleUsingGivenToken()
1113
  {
1114
- $customer = Braintree_Customer::createNoValidate(array(
1115
- 'creditCard' => array(
1116
  'number' => '5105105105105100',
1117
  'expirationDate' => '05/12'
1118
- )
1119
- ));
1120
  $creditCard = $customer->creditCards[0];
1121
- $transaction = Braintree_Customer::saleNoValidate($customer->id, array(
1122
  'amount' => '100.00'
1123
- ));
1124
  $this->assertEquals('100.00', $transaction->amount);
1125
  $this->assertEquals($customer->id, $transaction->customerDetails->id);
1126
  $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
1127
  }
1128
 
1129
- function testSaleNoValidate_throwsIfInvalid()
1130
  {
1131
- $customer = Braintree_Customer::createNoValidate(array(
1132
- 'creditCard' => array(
1133
  'number' => '5105105105105100',
1134
  'expirationDate' => '05/12'
1135
- )
1136
- ));
1137
  $creditCard = $customer->creditCards[0];
1138
- $this->setExpectedException('Braintree_Exception_ValidationsFailed');
1139
- Braintree_Customer::saleNoValidate($customer->id, array(
1140
  'amount' => 'invalid'
1141
- ));
1142
  }
1143
 
1144
- function testCredit_createsACreditUsingGivenCustomerId()
1145
  {
1146
- $customer = Braintree_Customer::createNoValidate(array(
1147
- 'creditCard' => array(
1148
  'number' => '5105105105105100',
1149
  'expirationDate' => '05/12'
1150
- )
1151
- ));
1152
  $creditCard = $customer->creditCards[0];
1153
- $result = Braintree_Customer::credit($customer->id, array(
1154
  'amount' => '100.00'
1155
- ));
1156
  $this->assertTrue($result->success);
1157
  $this->assertEquals('100.00', $result->transaction->amount);
1158
- $this->assertEquals(Braintree_Transaction::CREDIT, $result->transaction->type);
1159
  $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
1160
  $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
1161
  }
1162
 
1163
- function testCreditNoValidate_createsACreditUsingGivenId()
1164
  {
1165
- $customer = Braintree_Customer::createNoValidate(array(
1166
- 'creditCard' => array(
1167
  'number' => '5105105105105100',
1168
  'expirationDate' => '05/12'
1169
- )
1170
- ));
1171
  $creditCard = $customer->creditCards[0];
1172
- $transaction = Braintree_Customer::creditNoValidate($customer->id, array(
1173
  'amount' => '100.00'
1174
- ));
1175
  $this->assertEquals('100.00', $transaction->amount);
1176
- $this->assertEquals(Braintree_Transaction::CREDIT, $transaction->type);
1177
  $this->assertEquals($customer->id, $transaction->customerDetails->id);
1178
  $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
1179
  }
1180
 
1181
- function testCreditNoValidate_throwsIfInvalid()
1182
  {
1183
- $customer = Braintree_Customer::createNoValidate(array(
1184
- 'creditCard' => array(
1185
  'number' => '5105105105105100',
1186
  'expirationDate' => '05/12'
1187
- )
1188
- ));
1189
  $creditCard = $customer->creditCards[0];
1190
- $this->setExpectedException('Braintree_Exception_ValidationsFailed');
1191
- Braintree_Customer::creditNoValidate($customer->id, array(
1192
  'amount' => 'invalid'
1193
- ));
1194
  }
1195
 
1196
- function createCustomerViaTr($regularParams, $trParams)
1197
  {
1198
- Braintree_TestHelper::suppressDeprecationWarnings();
1199
- $trData = Braintree_TransparentRedirect::createCustomerData(
1200
- array_merge($trParams, array("redirectUrl" => "http://www.example.com"))
1201
  );
1202
- return Braintree_TestHelper::submitTrRequest(
1203
- Braintree_Customer::createCustomerUrl(),
1204
  $regularParams,
1205
  $trData
1206
  );
1207
  }
1208
 
1209
- function updateCustomerViaTr($regularParams, $trParams)
1210
  {
1211
- Braintree_TestHelper::suppressDeprecationWarnings();
1212
- $trData = Braintree_TransparentRedirect::updateCustomerData(
1213
- array_merge($trParams, array("redirectUrl" => "http://www.example.com"))
1214
  );
1215
- return Braintree_TestHelper::submitTrRequest(
1216
- Braintree_Customer::updateCustomerUrl(),
1217
  $regularParams,
1218
  $trData
1219
  );
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.',
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);
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);
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);
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);
220
  $this->assertNotNull($customer->paymentMethods[0]);
221
  }
222
 
223
+ public function testCreate_withUnicode()
224
  {
225
+ $result = Braintree\Customer::create([
226
  'firstName' => "Здравствуйте",
227
  'lastName' => 'Jones',
228
  'company' => 'Jones Co.',
230
  'phone' => '419.555.1234',
231
  'fax' => '419.555.1235',
232
  'website' => 'http://example.com'
233
+ ]);
234
  $this->assertEquals(true, $result->success);
235
  $customer = $result->customer;
236
  $this->assertEquals("Здравствуйте", $customer->firstName);
243
  $this->assertNotNull($customer->merchantId);
244
  }
245
 
246
+ public function testCreate_withCountry()
247
  {
248
+ $result = Braintree\Customer::create([
249
  'firstName' => 'Bat',
250
  'lastName' => 'Manderson',
251
+ 'creditCard' => [
252
  'number' => '5105105105105100',
253
  'expirationDate' => '05/12',
254
+ 'billingAddress' => [
255
  'countryName' => 'Gabon',
256
  'countryCodeAlpha2' => 'GA',
257
  'countryCodeAlpha3' => 'GAB',
258
  'countryCodeNumeric' => '266'
259
+ ]
260
+ ]
261
+ ]);
262
  $this->assertEquals(true, $result->success);
263
  $customer = $result->customer;
264
  $this->assertEquals('Gabon', $customer->creditCards[0]->billingAddress->countryName);
268
  $this->assertEquals(1, preg_match('/\A\w{32}\z/', $customer->creditCards[0]->uniqueNumberIdentifier));
269
  }
270
 
271
+ public function testCreate_withVenmoSdkSession()
272
  {
273
+ $result = Braintree\Customer::create([
274
  'firstName' => 'Bat',
275
  'lastName' => 'Manderson',
276
+ 'creditCard' => [
277
  'number' => '5105105105105100',
278
  'expirationDate' => '05/12',
279
+ 'options' => [
280
+ 'venmoSdkSession' => Braintree\Test\VenmoSdk::getTestSession()
281
+ ]
282
+ ]
283
+ ]);
284
  $this->assertEquals(true, $result->success);
285
  $customer = $result->customer;
286
  $this->assertEquals(true, $customer->creditCards[0]->venmoSdk);
287
  }
288
 
289
+ public function testCreate_withVenmoSdkPaymentMethodCode()
290
  {
291
+ $result = Braintree\Customer::create([
292
  'firstName' => 'Bat',
293
  'lastName' => 'Manderson',
294
+ 'creditCard' => [
295
+ 'venmoSdkPaymentMethodCode' => Braintree\Test\VenmoSdk::$visaPaymentMethodCode
296
+ ],
297
+ ]);
298
  $this->assertEquals(true, $result->success);
299
  $customer = $result->customer;
300
  $this->assertEquals("411111", $customer->creditCards[0]->bin);
301
  }
302
 
303
+ public function testCreate_blankCustomer()
304
  {
305
+ $result = Braintree\Customer::create();
306
  $this->assertEquals(true, $result->success);
307
  $this->assertNotNull($result->customer->id);
308
 
309
+ $result = Braintree\Customer::create([]);
310
  $this->assertEquals(true, $result->success);
311
  $this->assertNotNull($result->customer->id);
312
  }
313
 
314
+ public function testCreate_withSpecialChars()
315
  {
316
+ $result = Braintree\Customer::create(['firstName' => '<>&"\'']);
317
  $this->assertEquals(true, $result->success);
318
  $this->assertEquals('<>&"\'', $result->customer->firstName);
319
  }
320
 
321
+ public function testCreate_withCustomFields()
322
  {
323
+ $result = Braintree\Customer::create([
324
  'firstName' => 'Mike',
325
+ 'customFields' => [
326
  'store_me' => 'some custom value'
327
+ ]
328
+ ]);
329
  $this->assertEquals(true, $result->success);
330
  $customFields = $result->customer->customFields;
331
  $this->assertEquals('some custom value', $customFields['store_me']);
332
  }
333
 
334
+ public function testCreate_withFraudParams()
335
  {
336
+ $result = Braintree\Customer::create([
337
  'firstName' => 'Mike',
338
+ 'creditCard' => [
339
  'number' => '5105105105105100',
340
  'expirationDate' => '05/12',
341
  'cvv' => '123',
342
  'cardholderName' => 'Mike Jones',
343
  'deviceSessionId' => 'abc123',
344
  'fraudMerchantId' => '456'
345
+ ]
346
+ ]);
347
  $this->assertEquals(true, $result->success);
348
  }
349
 
350
+ public function testCreate_withCreditCard()
351
  {
352
+ $result = Braintree\Customer::create([
353
  'firstName' => 'Mike',
354
  'lastName' => 'Jones',
355
  'company' => 'Jones Co.',
357
  'phone' => '419.555.1234',
358
  'fax' => '419.555.1235',
359
  'website' => 'http://example.com',
360
+ 'creditCard' => [
361
  'number' => '5105105105105100',
362
  'expirationDate' => '05/12',
363
  'cvv' => '123',
364
  'cardholderName' => 'Mike Jones'
365
+ ]
366
+ ]);
367
  $this->assertEquals(true, $result->success);
368
  $customer = $result->customer;
369
  $this->assertEquals('Mike', $customer->firstName);
382
  $this->assertEquals('2012', $creditCard->expirationYear);
383
  }
384
 
385
+ public function testCreate_withDuplicateCardCheck()
386
  {
387
+ $customer = Braintree\Customer::createNoValidate();
388
 
389
+ $attributes = [
390
  'firstName' => 'Mike',
391
  'lastName' => 'Jones',
392
  'company' => 'Jones Co.',
394
  'phone' => '419.555.1234',
395
  'fax' => '419.555.1235',
396
  'website' => 'http://example.com',
397
+ 'creditCard' => [
398
  'number' => '5105105105105100',
399
  'expirationDate' => '05/12',
400
  'cvv' => '123',
401
  'cardholderName' => 'Mike Jones',
402
+ 'options' => [
403
  'failOnDuplicatePaymentMethod' => true
404
+ ]
405
+ ]
406
+ ];
407
+ Braintree\Customer::create($attributes);
408
+ $result = Braintree\Customer::create($attributes);
409
 
410
  $this->assertFalse($result->success);
411
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('number');
412
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_DUPLICATE_CARD_EXISTS, $errors[0]->code);
413
  $this->assertEquals(1, preg_match('/Duplicate card exists in the vault\./', $result->message));
414
  }
415
 
416
+ public function testCreate_withCreditCardAndSpecificVerificationMerchantAccount()
417
  {
418
+ $result = Braintree\Customer::create([
419
  'firstName' => 'Mike',
420
  'lastName' => 'Jones',
421
  'company' => 'Jones Co.',
423
  'phone' => '419.555.1234',
424
  'fax' => '419.555.1235',
425
  'website' => 'http://example.com',
426
+ 'creditCard' => [
427
  'number' => '5105105105105100',
428
  'expirationDate' => '05/12',
429
  'cvv' => '123',
430
  'cardholderName' => 'Mike Jones',
431
+ 'options' => [
432
+ 'verificationMerchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(),
433
  'verifyCard' => true
434
+ ]
435
+ ]
436
+ ]);
437
+ Test\Helper::assertPrintable($result);
438
  $this->assertFalse($result->success);
439
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
440
  $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
441
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
442
  $this->assertEquals('M', $result->creditCardVerification->cvvResponseCode);
445
  $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
446
  }
447
 
448
+ public function testCreate_withCreditCardAndBillingAddress()
449
  {
450
+ $result = Braintree\Customer::create([
451
  'firstName' => 'Mike',
452
  'lastName' => 'Jones',
453
  'company' => 'Jones Co.',
455
  'phone' => '419.555.1234',
456
  'fax' => '419.555.1235',
457
  'website' => 'http://example.com',
458
+ 'creditCard' => [
459
  'number' => '5105105105105100',
460
  'expirationDate' => '05/12',
461
  'cvv' => '123',
462
  'cardholderName' => 'Mike Jones',
463
+ 'billingAddress' => [
464
  'firstName' => 'Drew',
465
  'lastName' => 'Smith',
466
  'company' => 'Smith Co.',
470
  'region' => 'IL',
471
  'postalCode' => '60622',
472
  'countryName' => 'United States of America'
473
+ ]
474
+ ]
475
+ ]);
476
+ Test\Helper::assertPrintable($result);
477
  $this->assertEquals(true, $result->success);
478
  $customer = $result->customer;
479
  $this->assertEquals('Mike', $customer->firstName);
503
  $this->assertEquals('United States of America', $address->countryName);
504
  }
505
 
506
+ public function testCreate_withValidationErrors()
507
  {
508
+ $result = Braintree\Customer::create([
509
  'email' => 'invalid',
510
+ 'creditCard' => [
511
  'number' => 'invalid',
512
+ 'billingAddress' => [
513
  'streetAddress' => str_repeat('x', 256)
514
+ ]
515
+ ]
516
+ ]);
517
+ Test\Helper::assertPrintable($result);
518
  $this->assertEquals(false, $result->success);
519
  $errors = $result->errors->forKey('customer')->onAttribute('email');
520
+ $this->assertEquals(Braintree\Error\Codes::CUSTOMER_EMAIL_IS_INVALID, $errors[0]->code);
521
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('number');
522
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_NUMBER_INVALID_LENGTH, $errors[0]->code);
523
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->forKey('billingAddress')->onAttribute('streetAddress');
524
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_STREET_ADDRESS_IS_TOO_LONG, $errors[0]->code);
525
  }
526
 
527
+ public function testCreate_countryValidations_inconsistency()
528
  {
529
+ $result = Braintree\Customer::create([
530
+ 'creditCard' => [
531
+ 'billingAddress' => [
532
  'countryName' => 'Georgia',
533
  'countryCodeAlpha2' => 'TF'
534
+ ]
535
+ ]
536
+ ]);
537
  $this->assertEquals(false, $result->success);
538
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->forKey('billingAddress')->onAttribute('base');
539
+ $this->assertEquals(Braintree\Error\Codes::ADDRESS_INCONSISTENT_COUNTRY, $errors[0]->code);
540
  }
541
 
542
+ public function testCreateNoValidate_returnsCustomer()
543
  {
544
+ $customer = Braintree\Customer::createNoValidate([
545
  'firstName' => 'Paul',
546
  'lastName' => 'Martin'
547
+ ]);
548
  $this->assertEquals('Paul', $customer->firstName);
549
  $this->assertEquals('Martin', $customer->lastName);
550
  }
551
 
552
+ public function testCreateNoValidate_throwsIfInvalid()
553
  {
554
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
555
+ $customer = Braintree\Customer::createNoValidate(['email' => 'invalid']);
556
  }
557
 
558
+ public function testCreate_worksWithFuturePayPalNonce()
559
  {
560
+ $nonce = Braintree\Test\Nonces::$paypalFuturePayment;
561
 
562
+ $result = Braintree\Customer::create([
563
  'paymentMethodNonce' => $nonce
564
+ ]);
565
 
566
  $this->assertTrue($result->success);
567
  }
568
 
569
+ public function testCreate_doesNotWorkWithOnetimePayPalNonce()
570
  {
571
+ $nonce = Braintree\Test\Nonces::$paypalOneTimePayment;
572
 
573
+ $result = Braintree\Customer::create([
574
  'paymentMethodNonce' => $nonce
575
+ ]);
576
 
577
  $this->assertFalse($result->success);
578
  $errors = $result->errors->forKey('customer')->forKey('paypalAccount')->errors;
579
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
580
  }
581
 
582
+ public function testDelete_deletesTheCustomer()
583
  {
584
+ $result = Braintree\Customer::create([]);
585
  $this->assertEquals(true, $result->success);
586
+ Braintree\Customer::find($result->customer->id);
587
+ Braintree\Customer::delete($result->customer->id);
588
+ $this->setExpectedException('Braintree\Exception\NotFound');
589
+ Braintree\Customer::find($result->customer->id);
590
  }
591
 
592
+ public function testFind()
593
  {
594
+ $result = Braintree\Customer::create([
595
  'firstName' => 'Mike',
596
  'lastName' => 'Jones',
597
  'company' => 'Jones Co.',
599
  'phone' => '419.555.1234',
600
  'fax' => '419.555.1235',
601
  'website' => 'http://example.com'
602
+ ]);
603
  $this->assertEquals(true, $result->success);
604
+ $customer = Braintree\Customer::find($result->customer->id);
605
  $this->assertEquals('Mike', $customer->firstName);
606
  $this->assertEquals('Jones', $customer->lastName);
607
  $this->assertEquals('Jones Co.', $customer->company);
611
  $this->assertEquals('http://example.com', $customer->website);
612
  }
613
 
614
+ public function testFind_throwsExceptionIfNotFound()
615
  {
616
+ $this->setExpectedException('Braintree\Exception\NotFound');
617
+ Braintree\Customer::find("does-not-exist");
618
  }
619
 
620
+ public function testUpdate()
621
  {
622
+ $result = Braintree\Customer::create([
623
  'firstName' => 'Old First',
624
  'lastName' => 'Old Last',
625
  'company' => 'Old Company',
627
  'phone' => 'old phone',
628
  'fax' => 'old fax',
629
  'website' => 'http://old.example.com'
630
+ ]);
631
  $this->assertEquals(true, $result->success);
632
  $customer = $result->customer;
633
+ $updateResult = Braintree\Customer::update($customer->id, [
634
  'firstName' => 'New First',
635
  'lastName' => 'New Last',
636
  'company' => 'New Company',
638
  'phone' => 'new phone',
639
  'fax' => 'new fax',
640
  'website' => 'http://new.example.com'
641
+ ]);
642
  $this->assertEquals(true, $updateResult->success);
643
  $this->assertEquals('New First', $updateResult->customer->firstName);
644
  $this->assertEquals('New Last', $updateResult->customer->lastName);
649
  $this->assertEquals('http://new.example.com', $updateResult->customer->website);
650
  }
651
 
652
+ public function testUpdate_withCountry()
653
  {
654
+ $customer = Braintree\Customer::create([
655
  'firstName' => 'Bat',
656
  'lastName' => 'Manderson',
657
+ 'creditCard' => [
658
  'number' => '5105105105105100',
659
  'expirationDate' => '05/12',
660
+ 'billingAddress' => [
661
  'countryName' => 'United States of America',
662
  'countryCodeAlpha2' => 'US',
663
  'countryCodeAlpha3' => 'USA',
664
  'countryCodeNumeric' => '840'
665
+ ]
666
+ ]
667
+ ])->customer;
668
 
669
+ $result = Braintree\Customer::update($customer->id, [
670
  'firstName' => 'Bat',
671
  'lastName' => 'Manderson',
672
+ 'creditCard' => [
673
+ 'options' => [
674
  'updateExistingToken' => $customer->creditCards[0]->token
675
+ ],
676
+ 'billingAddress' => [
677
  'countryName' => 'Gabon',
678
  'countryCodeAlpha2' => 'GA',
679
  'countryCodeAlpha3' => 'GAB',
680
  'countryCodeNumeric' => '266',
681
+ 'options' => [
682
  'updateExisting' => true
683
+ ]
684
+ ]
685
+ ]
686
+ ]);
687
 
688
  $this->assertEquals(true, $result->success);
689
  $updatedCustomer = $result->customer;
693
  $this->assertEquals('266', $updatedCustomer->creditCards[0]->billingAddress->countryCodeNumeric);
694
  }
695
 
696
+ public function testUpdate_withUpdatingExistingCreditCard()
697
  {
698
+ $create_result = Braintree\Customer::create([
699
  'firstName' => 'Old First',
700
  'lastName' => 'Old Last',
701
  'website' => 'http://old.example.com',
702
+ 'creditCard' => [
703
  'number' => '5105105105105100',
704
  'expirationDate' => '05/12',
705
  'cardholderName' => 'Old Cardholder'
706
+ ]
707
+ ]);
708
  $this->assertEquals(true, $create_result->success);
709
  $customer = $create_result->customer;
710
  $creditCard = $customer->creditCards[0];
711
+ $result = Braintree\Customer::update($customer->id, [
712
  'firstName' => 'New First',
713
  'lastName' => 'New Last',
714
+ 'creditCard' => [
715
  'number' => '4111111111111111',
716
  'expirationDate' => '11/14',
717
  'cardholderName' => 'New Cardholder',
718
+ 'options' => [
719
  'updateExistingToken' => $creditCard->token
720
+ ]
721
+ ]
722
+ ]);
723
  $this->assertEquals(true, $result->success);
724
  $this->assertEquals('New First', $result->customer->firstName);
725
  $this->assertEquals('New Last', $result->customer->lastName);
730
  $this->assertEquals('New Cardholder', $creditCard->cardholderName);
731
  }
732
 
733
+ public function testUpdate_forBillingAddressAndExistingCreditCardAndCustomerDetailsTogether()
734
  {
735
+ $create_result = Braintree\Customer::create([
736
  'firstName' => 'Old First',
737
  'lastName' => 'Old Last',
738
+ 'creditCard' => [
739
  'number' => '5105105105105100',
740
  'expirationDate' => '05/12',
741
  'cvv' => '123',
742
  'cardholderName' => 'Old Cardholder',
743
+ 'billingAddress' => [
744
  'firstName' => 'Drew',
745
  'lastName' => 'Smith'
746
+ ]
747
+ ]
748
+ ]);
749
  $this->assertEquals(true, $create_result->success);
750
  $customer = $create_result->customer;
751
  $creditCard = $customer->creditCards[0];
752
+ $result = Braintree\Customer::update($customer->id, [
753
  'firstName' => 'New Customer First',
754
  'lastName' => 'New Customer Last',
755
+ 'creditCard' => [
756
  'number' => '4111111111111111',
757
  'expirationDate' => '11/14',
758
+ 'options' => [
759
  'updateExistingToken' => $creditCard->token
760
+ ],
761
+ 'billingAddress' => [
762
  'firstName' => 'New Billing First',
763
  'lastName' => 'New Billing Last',
764
+ 'options' => [
765
  'updateExisting' => true
766
+ ]
767
+ ]
768
+ ]
769
+ ]);
770
  $this->assertEquals(true, $result->success);
771
  $this->assertEquals('New Customer First', $result->customer->firstName);
772
  $this->assertEquals('New Customer Last', $result->customer->lastName);
782
  $this->assertEquals('New Billing Last', $billingAddress->lastName);
783
  }
784
 
785
+ public function testUpdate_withNewCreditCardAndExistingBillingAddress()
786
  {
787
+ $customer = Braintree\Customer::create()->customer;
788
+ $address = Braintree\Address::create([
789
  'customerId' => $customer->id,
790
  'firstName' => 'Dan'
791
+ ])->address;
792
 
793
+ $result = Braintree\Customer::update($customer->id, [
794
+ 'creditCard' => [
795
  'number' => '4111111111111111',
796
  'expirationDate' => '11/14',
797
  'billingAddressId' => $address->id
798
+ ]
799
+ ]);
800
 
801
  $billingAddress = $result->customer->creditCards[0]->billingAddress;
802
  $this->assertEquals($address->id, $billingAddress->id);
803
  $this->assertEquals('Dan', $billingAddress->firstName);
804
  }
805
 
806
+ public function testUpdate_worksWithFuturePayPalNonce()
807
  {
808
+ $customerResult = Braintree\Customer::create([
809
+ 'creditCard' => [
810
  'number' => '5105105105105100',
811
  'expirationDate' => '05/12',
812
+ 'options' => [
813
  'makeDefault' => true
814
+ ]
815
+ ]
816
+ ]);
817
  $paypalAccountToken = 'PAYPALToken-' . strval(rand());
818
+ $http = new HttpClientApi(Braintree\Configuration::$global);
819
+ $nonce = $http->nonceForPayPalAccount([
820
+ 'paypal_account' => [
821
  'consent_code' => 'PAYPAL_CONSENT_CODE',
822
  'token' => $paypalAccountToken,
823
+ 'options' => [
824
  'makeDefault' => true
825
+ ]
826
+ ]
827
+ ]);
828
 
829
+ $result = Braintree\Customer::update($customerResult->customer->id, [
830
  'paymentMethodNonce' => $nonce
831
+ ]);
832
 
833
  $this->assertTrue($result->success);
834
  $this->assertEquals($result->customer->defaultPaymentMethod()->token, $paypalAccountToken);
835
 
836
  }
837
 
838
+ public function testUpdate_doesNotWorkWithOnetimePayPalNonce()
839
  {
840
+ $customerResult = Braintree\Customer::create([
841
+ 'creditCard' => [
842
  'number' => '5105105105105100',
843
  'expirationDate' => '05/12',
844
+ 'options' => [
845
  'makeDefault' => true
846
+ ]
847
+ ]
848
+ ]);
849
  $paypalAccountToken = 'PAYPALToken-' . strval(rand());
850
+ $http = new HttpClientApi(Braintree\Configuration::$global);
851
+ $nonce = $http->nonceForPayPalAccount([
852
+ 'paypal_account' => [
853
  'access_token' => 'PAYPAL_ACCESS_TOKEN',
854
  'token' => $paypalAccountToken,
855
+ 'options' => [
856
  'makeDefault' => true
857
+ ]
858
+ ]
859
+ ]);
860
 
861
+ $result = Braintree\Customer::update($customerResult->customer->id, [
862
  'paymentMethodNonce' => $nonce
863
+ ]);
864
 
865
  $this->assertFalse($result->success);
866
  $errors = $result->errors->forKey('customer')->forKey('paypalAccount')->errors;
867
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
868
 
869
  }
870
 
871
+ public function testUpdateNoValidate()
872
  {
873
+ $result = Braintree\Customer::create([
874
  'firstName' => 'Old First',
875
  'lastName' => 'Old Last',
876
  'company' => 'Old Company',
878
  'phone' => 'old phone',
879
  'fax' => 'old fax',
880
  'website' => 'http://old.example.com'
881
+ ]);
882
  $this->assertEquals(true, $result->success);
883
  $customer = $result->customer;
884
+ $updated = Braintree\Customer::updateNoValidate($customer->id, [
885
  'firstName' => 'New First',
886
  'lastName' => 'New Last',
887
  'company' => 'New Company',
889
  'phone' => 'new phone',
890
  'fax' => 'new fax',
891
  'website' => 'http://new.example.com'
892
+ ]);
893
  $this->assertEquals('New First', $updated->firstName);
894
  $this->assertEquals('New Last', $updated->lastName);
895
  $this->assertEquals('New Company', $updated->company);
899
  $this->assertEquals('http://new.example.com', $updated->website);
900
  }
901
 
902
+ public function testCreateFromTransparentRedirect()
903
  {
904
+ Test\Helper::suppressDeprecationWarnings();
905
  $queryString = $this->createCustomerViaTr(
906
+ [
907
+ 'customer' => [
908
  'first_name' => 'Joe',
909
  'last_name' => 'Martin',
910
+ 'credit_card' => [
911
  'number' => '5105105105105100',
912
  'expiration_date' => '05/12'
913
+ ]
914
+ ]
915
+ ],
916
+ [
917
+ ]
918
  );
919
+ $result = Braintree\Customer::createFromTransparentRedirect($queryString);
920
  $this->assertTrue($result->success);
921
  $this->assertEquals('Joe', $result->customer->firstName);
922
  $this->assertEquals('Martin', $result->customer->lastName);
926
  $this->assertEquals('05/2012', $creditCard->expirationDate);
927
  }
928
 
929
+ public function testCreateFromTransparentRedirect_withParamsInTrData()
930
  {
931
+ Test\Helper::suppressDeprecationWarnings();
932
  $queryString = $this->createCustomerViaTr(
933
+ [
934
+ ],
935
+ [
936
+ 'customer' => [
937
  'firstName' => 'Joe',
938
  'lastName' => 'Martin',
939
+ 'creditCard' => [
940
  'number' => '5105105105105100',
941
  'expirationDate' => '05/12'
942
+ ]
943
+ ]
944
+ ]
945
  );
946
+ $result = Braintree\Customer::createFromTransparentRedirect($queryString);
947
  $this->assertTrue($result->success);
948
  $this->assertEquals('Joe', $result->customer->firstName);
949
  $this->assertEquals('Martin', $result->customer->lastName);
953
  $this->assertEquals('05/2012', $creditCard->expirationDate);
954
  }
955
 
956
+ public function testCreateFromTransparentRedirect_withValidationErrors()
957
  {
958
+ Test\Helper::suppressDeprecationWarnings();
959
  $queryString = $this->createCustomerViaTr(
960
+ [
961
+ 'customer' => [
962
  'first_name' => str_repeat('x', 256),
963
+ 'credit_card' => [
964
  'number' => 'invalid',
965
  'expiration_date' => ''
966
+ ]
967
+ ]
968
+ ],
969
+ [
970
+ ]
971
  );
972
+ $result = Braintree\Customer::createFromTransparentRedirect($queryString);
973
  $this->assertFalse($result->success);
974
  $errors = $result->errors->forKey('customer')->onAttribute('firstName');
975
+ $this->assertEquals(Braintree\Error\Codes::CUSTOMER_FIRST_NAME_IS_TOO_LONG, $errors[0]->code);
976
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('number');
977
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_NUMBER_INVALID_LENGTH, $errors[0]->code);
978
  $errors = $result->errors->forKey('customer')->forKey('creditCard')->onAttribute('expirationDate');
979
+ $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_EXPIRATION_DATE_IS_REQUIRED, $errors[0]->code);
980
  }
981
 
982
+ public function testCreateWithInvalidUTF8Bytes()
983
  {
984
+ $result = Braintree\Customer::create([
985
+ 'firstName' => "Jos\xe8 Maria"
986
+ ]);
987
  $this->assertEquals(true, $result->success);
988
  $customer = $result->customer;
989
  $this->assertEquals("Jos\xc3\xa8 Maria", $customer->firstName);
990
  }
991
 
992
+ public function testCreateWithValidUTF8Bytes()
993
  {
994
+ $result = Braintree\Customer::create([
995
+ 'firstName' => "Jos\303\251"
996
+ ]);
997
  $this->assertEquals(true, $result->success);
998
  $customer = $result->customer;
999
  $this->assertEquals("Jos\303\251", $customer->firstName);
1000
  }
1001
 
1002
+ public function testUpdateFromTransparentRedirect()
1003
  {
1004
+ Test\Helper::suppressDeprecationWarnings();
1005
+ $customer = Braintree\Customer::createNoValidate();
1006
  $queryString = $this->updateCustomerViaTr(
1007
+ [
1008
+ 'customer' => [
1009
  'first_name' => 'Joe',
1010
  'last_name' => 'Martin',
1011
  'email' => 'joe.martin@example.com'
1012
+ ]
1013
+ ],
1014
+ [
1015
  'customerId' => $customer->id
1016
+ ]
1017
  );
1018
+ $result = Braintree\Customer::updateFromTransparentRedirect($queryString);
1019
  $this->assertTrue($result->success);
1020
  $this->assertEquals('Joe', $result->customer->firstName);
1021
  $this->assertEquals('Martin', $result->customer->lastName);
1022
  $this->assertEquals('joe.martin@example.com', $result->customer->email);
1023
  }
1024
 
1025
+ public function testUpdateFromTransparentRedirect_withParamsInTrData()
1026
  {
1027
+ Test\Helper::suppressDeprecationWarnings();
1028
+ $customer = Braintree\Customer::createNoValidate();
1029
  $queryString = $this->updateCustomerViaTr(
1030
+ [
1031
+ ],
1032
+ [
1033
  'customerId' => $customer->id,
1034
+ 'customer' => [
1035
  'firstName' => 'Joe',
1036
  'lastName' => 'Martin',
1037
  'email' => 'joe.martin@example.com'
1038
+ ]
1039
+ ]
1040
  );
1041
+ $result = Braintree\Customer::updateFromTransparentRedirect($queryString);
1042
  $this->assertTrue($result->success);
1043
  $this->assertEquals('Joe', $result->customer->firstName);
1044
  $this->assertEquals('Martin', $result->customer->lastName);
1045
  $this->assertEquals('joe.martin@example.com', $result->customer->email);
1046
  }
1047
 
1048
+ public function testUpdateFromTransparentRedirect_withValidationErrors()
1049
  {
1050
+ Test\Helper::suppressDeprecationWarnings();
1051
+ $customer = Braintree\Customer::createNoValidate();
1052
  $queryString = $this->updateCustomerViaTr(
1053
+ [
1054
+ 'customer' => [
1055
  'first_name' => str_repeat('x', 256),
1056
+ ]
1057
+ ],
1058
+ [
1059
  'customerId' => $customer->id
1060
+ ]
1061
  );
1062
+ $result = Braintree\Customer::updateFromTransparentRedirect($queryString);
1063
  $this->assertFalse($result->success);
1064
  $errors = $result->errors->forKey('customer')->onAttribute('firstName');
1065
+ $this->assertEquals(Braintree\Error\Codes::CUSTOMER_FIRST_NAME_IS_TOO_LONG, $errors[0]->code);
1066
  }
1067
 
1068
+ public function testUpdateFromTransparentRedirect_withUpdateExisting()
1069
  {
1070
+ Test\Helper::suppressDeprecationWarnings();
1071
+ $customer = Braintree\Customer::create([
1072
  'firstName' => 'Mike',
1073
  'lastName' => 'Jones',
1074
+ 'creditCard' => [
1075
  'number' => '5105105105105100',
1076
  'expirationDate' => '05/12',
1077
  'cardholderName' => 'Mike Jones',
1078
+ 'billingAddress' => [
1079
  'firstName' => 'Drew',
1080
  'lastName' => 'Smith'
1081
+ ]
1082
+ ]
1083
+ ])->customer;
1084
 
1085
  $queryString = $this->updateCustomerViaTr(
1086
+ [],
1087
+ [
1088
  'customerId' => $customer->id,
1089
+ 'customer' => [
1090
  'firstName' => 'New First',
1091
  'lastName' => 'New Last',
1092
+ 'creditCard' => [
1093
  'number' => '4111111111111111',
1094
  'expirationDate' => '05/13',
1095
  'cardholderName' => 'New Cardholder',
1096
+ 'options' => [
1097
  'updateExistingToken' => $customer->creditCards[0]->token
1098
+ ],
1099
+ 'billingAddress' => [
1100
  'firstName' => 'New First Billing',
1101
  'lastName' => 'New Last Billing',
1102
+ 'options' => [
1103
  'updateExisting' => true
1104
+ ]
1105
+ ]
1106
+ ]
1107
+ ]
1108
+ ]
1109
  );
1110
+ $result = Braintree\Customer::updateFromTransparentRedirect($queryString);
1111
  $this->assertTrue($result->success);
1112
 
1113
  $this->assertEquals(true, $result->success);
1129
  $this->assertEquals('New Last Billing', $address->lastName);
1130
  }
1131
 
1132
+ public function testSale_createsASaleUsingGivenToken()
1133
  {
1134
+ $customer = Braintree\Customer::createNoValidate([
1135
+ 'creditCard' => [
1136
  'number' => '5105105105105100',
1137
  'expirationDate' => '05/12'
1138
+ ]
1139
+ ]);
1140
  $creditCard = $customer->creditCards[0];
1141
+ $result = Braintree\Customer::sale($customer->id, [
1142
  'amount' => '100.00'
1143
+ ]);
1144
  $this->assertTrue($result->success);
1145
  $this->assertEquals('100.00', $result->transaction->amount);
1146
  $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
1147
  $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
1148
  }
1149
 
1150
+ public function testSaleNoValidate_createsASaleUsingGivenToken()
1151
  {
1152
+ $customer = Braintree\Customer::createNoValidate([
1153
+ 'creditCard' => [
1154
  'number' => '5105105105105100',
1155
  'expirationDate' => '05/12'
1156
+ ]
1157
+ ]);
1158
  $creditCard = $customer->creditCards[0];
1159
+ $transaction = Braintree\Customer::saleNoValidate($customer->id, [
1160
  'amount' => '100.00'
1161
+ ]);
1162
  $this->assertEquals('100.00', $transaction->amount);
1163
  $this->assertEquals($customer->id, $transaction->customerDetails->id);
1164
  $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
1165
  }
1166
 
1167
+ public function testSaleNoValidate_throwsIfInvalid()
1168
  {
1169
+ $customer = Braintree\Customer::createNoValidate([
1170
+ 'creditCard' => [
1171
  'number' => '5105105105105100',
1172
  'expirationDate' => '05/12'
1173
+ ]
1174
+ ]);
1175
  $creditCard = $customer->creditCards[0];
1176
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
1177
+ Braintree\Customer::saleNoValidate($customer->id, [
1178
  'amount' => 'invalid'
1179
+ ]);
1180
  }
1181
 
1182
+ public function testCredit_createsACreditUsingGivenCustomerId()
1183
  {
1184
+ $customer = Braintree\Customer::createNoValidate([
1185
+ 'creditCard' => [
1186
  'number' => '5105105105105100',
1187
  'expirationDate' => '05/12'
1188
+ ]
1189
+ ]);
1190
  $creditCard = $customer->creditCards[0];
1191
+ $result = Braintree\Customer::credit($customer->id, [
1192
  'amount' => '100.00'
1193
+ ]);
1194
  $this->assertTrue($result->success);
1195
  $this->assertEquals('100.00', $result->transaction->amount);
1196
+ $this->assertEquals(Braintree\Transaction::CREDIT, $result->transaction->type);
1197
  $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
1198
  $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
1199
  }
1200
 
1201
+ public function testCreditNoValidate_createsACreditUsingGivenId()
1202
  {
1203
+ $customer = Braintree\Customer::createNoValidate([
1204
+ 'creditCard' => [
1205
  'number' => '5105105105105100',
1206
  'expirationDate' => '05/12'
1207
+ ]
1208
+ ]);
1209
  $creditCard = $customer->creditCards[0];
1210
+ $transaction = Braintree\Customer::creditNoValidate($customer->id, [
1211
  'amount' => '100.00'
1212
+ ]);
1213
  $this->assertEquals('100.00', $transaction->amount);
1214
+ $this->assertEquals(Braintree\Transaction::CREDIT, $transaction->type);
1215
  $this->assertEquals($customer->id, $transaction->customerDetails->id);
1216
  $this->assertEquals($creditCard->token, $transaction->creditCardDetails->token);
1217
  }
1218
 
1219
+ public function testCreditNoValidate_throwsIfInvalid()
1220
  {
1221
+ $customer = Braintree\Customer::createNoValidate([
1222
+ 'creditCard' => [
1223
  'number' => '5105105105105100',
1224
  'expirationDate' => '05/12'
1225
+ ]
1226
+ ]);
1227
  $creditCard = $customer->creditCards[0];
1228
+ $this->setExpectedException('Braintree\Exception\ValidationsFailed');
1229
+ Braintree\Customer::creditNoValidate($customer->id, [
1230
  'amount' => 'invalid'
1231
+ ]);
1232
  }
1233
 
1234
+ public function createCustomerViaTr($regularParams, $trParams)
1235
  {
1236
+ Test\Helper::suppressDeprecationWarnings();
1237
+ $trData = Braintree\TransparentRedirect::createCustomerData(
1238
+ array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
1239
  );
1240
+ return Test\Helper::submitTrRequest(
1241
+ Braintree\Customer::createCustomerUrl(),
1242
  $regularParams,
1243
  $trData
1244
  );
1245
  }
1246
 
1247
+ public function updateCustomerViaTr($regularParams, $trParams)
1248
  {
1249
+ Test\Helper::suppressDeprecationWarnings();
1250
+ $trData = Braintree\TransparentRedirect::updateCustomerData(
1251
+ array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
1252
  );
1253
+ return Test\Helper::submitTrRequest(
1254
+ Braintree\Customer::updateCustomerUrl(),
1255
  $regularParams,
1256
  $trData
1257
  );
braintree_sdk/tests/integration/DisbursementTest.php CHANGED
@@ -1,28 +1,34 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_DisbursementTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
5
  {
6
- function testTransactions()
7
  {
8
- $disbursement = Braintree_Disbursement::factory(array(
9
  "id" => "123456",
10
- "merchantAccount" => array(
11
  "id" => "sandbox_sub_merchant_account",
12
- "masterMerchantAccount" => array(
13
  "id" => "sandbox_master_merchant_account",
14
  "status" => "active"
15
- ),
16
  "status" => "active"
17
- ),
18
- "transactionIds" => array("sub_merchant_transaction"),
19
  "exceptionMessage" => "invalid_account_number",
20
  "amount" => "100.00",
21
  "disbursementDate" => new DateTime("2013-04-10"),
22
  "followUpAction" => "update",
23
  "retry" => false,
24
  "success" => false
25
- ));
26
 
27
  $transactions = $disbursement->transactions();
28
 
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
 
braintree_sdk/tests/integration/DiscountTest.php CHANGED
@@ -1,13 +1,18 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_DiscountTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
5
  {
6
- function testAll_returnsAllDiscounts()
7
  {
8
  $newId = strval(rand());
9
 
10
- $discountParams = array (
11
  "amount" => "100.00",
12
  "description" => "some description",
13
  "id" => $newId,
@@ -15,13 +20,13 @@ class Braintree_DiscountTest extends PHPUnit_Framework_TestCase
15
  "name" => "php_discount",
16
  "neverExpires" => "false",
17
  "numberOfBillingCycles" => "1"
18
- );
19
 
20
- $http = new Braintree_Http(Braintree_Configuration::$global);
21
- $path = Braintree_Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
22
- $http->post($path, array("modification" => $discountParams));
23
 
24
- $discounts = Braintree_Discount::all();
25
 
26
  foreach ($discounts as $discount)
27
  {
@@ -41,11 +46,11 @@ class Braintree_DiscountTest extends PHPUnit_Framework_TestCase
41
  $this->assertEquals($discountParams["numberOfBillingCycles"], $actualDiscount->numberOfBillingCycles);
42
  }
43
 
44
- function testGatewayAll_returnsAllDiscounts()
45
  {
46
  $newId = strval(rand());
47
 
48
- $discountParams = array (
49
  "amount" => "100.00",
50
  "description" => "some description",
51
  "id" => $newId,
@@ -53,18 +58,18 @@ class Braintree_DiscountTest extends PHPUnit_Framework_TestCase
53
  "name" => "php_discount",
54
  "neverExpires" => "false",
55
  "numberOfBillingCycles" => "1"
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, array("modification" => $discountParams));
61
 
62
- $gateway = new Braintree_Gateway(array(
63
  'environment' => 'development',
64
  'merchantId' => 'integration_merchant_id',
65
  'publicKey' => 'integration_public_key',
66
  'privateKey' => 'integration_private_key'
67
- ));
68
  $discounts = $gateway->discount()->all();
69
 
70
  foreach ($discounts as $discount)
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,
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
  {
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,
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)
braintree_sdk/tests/integration/Error/ErrorCollectionTest.php CHANGED
@@ -1,75 +1,80 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../../TestHelper.php';
3
 
4
- class Braintree_Error_ErrorCollectionTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
5
  {
6
- function testDeepSize_withNestedErrors()
7
  {
8
- $result = Braintree_Customer::create(array(
9
  'email' => 'invalid',
10
- 'creditCard' => array(
11
  'number' => 'invalid',
12
  'expirationDate' => 'invalid',
13
- 'billingAddress' => array(
14
  'countryName' => 'invaild'
15
- )
16
- )
17
- ));
18
  $this->assertEquals(false, $result->success);
19
  $this->assertEquals(4, $result->errors->deepSize());
20
  }
21
 
22
- function testOnHtmlField()
23
  {
24
- $result = Braintree_Customer::create(array(
25
  'email' => 'invalid',
26
- 'creditCard' => array(
27
  'number' => 'invalid',
28
  'expirationDate' => 'invalid',
29
- 'billingAddress' => array(
30
  'countryName' => 'invaild'
31
- )
32
- )
33
- ));
34
  $this->assertEquals(false, $result->success);
35
  $errors = $result->errors->onHtmlField('customer[email]');
36
- $this->assertEquals(Braintree_Error_Codes::CUSTOMER_EMAIL_IS_INVALID, $errors[0]->code);
37
  $errors = $result->errors->onHtmlField('customer[credit_card][number]');
38
- $this->assertEquals(Braintree_Error_Codes::CREDIT_CARD_NUMBER_INVALID_LENGTH, $errors[0]->code);
39
  $errors = $result->errors->onHtmlField('customer[credit_card][billing_address][country_name]');
40
- $this->assertEquals(Braintree_Error_Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, $errors[0]->code);
41
  }
42
 
43
- function testOnHtmlField_returnsEmptyArrayIfNone()
44
  {
45
- $result = Braintree_Customer::create(array(
46
  'email' => 'invalid',
47
- 'creditCard' => array(
48
  'number' => '5105105105105100',
49
  'expirationDate' => '05/12',
50
- 'billingAddress' => array(
51
  'streetAddress' => '1 E Main St'
52
- )
53
- )
54
- ));
55
  $this->assertEquals(false, $result->success);
56
  $errors = $result->errors->onHtmlField('customer[email]');
57
- $this->assertEquals(Braintree_Error_Codes::CUSTOMER_EMAIL_IS_INVALID, $errors[0]->code);
58
- $this->assertEquals(array(), $result->errors->onHtmlField('customer[credit_card][number]'));
59
- $this->assertEquals(array(), $result->errors->onHtmlField('customer[credit_card][billing_address][country_name]'));
60
  }
61
 
62
- function testOnHtmlField_returnsEmptyForCustomFieldsIfNoErrors()
63
  {
64
- $result = Braintree_Customer::create(array(
65
  'email' => 'invalid',
66
- 'creditCard' => array(
67
  'number' => '5105105105105100',
68
  'expirationDate' => '05/12',
69
- ),
70
- 'customFields' => array('storeMe' => 'value')
71
- ));
72
  $this->assertEquals(false, $result->success);
73
- $this->assertEquals(array(), $result->errors->onHtmlField('customer[custom_fields][store_me]'));
74
  }
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 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
  }
braintree_sdk/tests/integration/Error/ValidationErrorCollectionTest.php CHANGED
@@ -1,70 +1,74 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../../TestHelper.php';
3
 
4
- class Braintree_Error_ValidationErrorCollectionTest extends PHPUnit_Framework_TestCase
5
- {
 
 
6
 
7
- function mapValidationErrorsToCodes($validationErrors)
 
 
8
  {
9
  $codes = array_map(create_function('$validationError', 'return $validationError->code;'), $validationErrors);
10
  sort($codes);
11
  return $codes;
12
  }
13
 
14
- function test_shallowAll_givesAllErrorsShallowly()
15
  {
16
- $result = Braintree_Customer::create(array(
17
  'email' => 'invalid',
18
- 'creditCard' => array(
19
  'number' => '1234123412341234',
20
  'expirationDate' => 'invalid',
21
- 'billingAddress' => array(
22
  'countryName' => 'invalid'
23
- )
24
- )
25
- ));
26
 
27
- $this->assertEquals(array(), $result->errors->shallowAll());
28
 
29
- $expectedCustomerErrors = array(Braintree_Error_Codes::CUSTOMER_EMAIL_IS_INVALID);
30
  $actualCustomerErrors = $result->errors->forKey('customer')->shallowAll();
31
  $this->assertEquals($expectedCustomerErrors, self::mapValidationErrorsToCodes($actualCustomerErrors));
32
 
33
- $expectedCreditCardErrors = array(
34
- Braintree_Error_Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID,
35
- Braintree_Error_Codes::CREDIT_CARD_NUMBER_IS_INVALID
36
- );
37
  $actualCreditCardErrors = $result->errors->forKey('customer')->forKey('creditCard')->shallowAll();
38
  $this->assertEquals($expectedCreditCardErrors, self::mapValidationErrorsToCodes($actualCreditCardErrors));
39
  }
40
 
41
- function test_deepAll_givesAllErrorsDeeply()
42
  {
43
- $result = Braintree_Customer::create(array(
44
  'email' => 'invalid',
45
- 'creditCard' => array(
46
  'number' => '1234123412341234',
47
  'expirationDate' => 'invalid',
48
- 'billingAddress' => array(
49
  'countryName' => 'invalid'
50
- )
51
- )
52
- ));
53
 
54
- $expectedErrors = array(
55
- Braintree_Error_Codes::CUSTOMER_EMAIL_IS_INVALID,
56
- Braintree_Error_Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID,
57
- Braintree_Error_Codes::CREDIT_CARD_NUMBER_IS_INVALID,
58
- Braintree_Error_Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED
59
- );
60
  $actualErrors = $result->errors->deepAll();
61
  $this->assertEquals($expectedErrors, self::mapValidationErrorsToCodes($actualErrors));
62
 
63
- $expectedErrors = array(
64
- Braintree_Error_Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID,
65
- Braintree_Error_Codes::CREDIT_CARD_NUMBER_IS_INVALID,
66
- Braintree_Error_Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED
67
- );
68
  $actualErrors = $result->errors->forKey('customer')->forKey('creditCard')->deepAll();
69
  $this->assertEquals($expectedErrors, self::mapValidationErrorsToCodes($actualErrors));
70
  }
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
  }
braintree_sdk/tests/integration/EuropeBankAccountTest.php CHANGED
@@ -1,31 +1,34 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/HttpClientApi.php';
4
 
5
- class Braintree_EuropeBankAccountTest extends PHPUnit_Framework_TestCase
6
- {
 
 
7
 
8
- function testCanExchangeNonceForEuropeBankAccount()
 
 
9
  {
10
- $gateway = new Braintree_Gateway(array(
11
  'environment' => 'development',
12
  'merchantId' => 'altpay_merchant',
13
  'publicKey' => 'altpay_merchant_public_key',
14
  'privateKey' => 'altpay_merchant_private_key'
15
- ));
16
 
17
  $result = $gateway->customer()->create();
18
  $this->assertTrue($result->success);
19
  $customer = $result->customer;
20
- $clientApi = new Braintree_HttpClientApi($gateway->config);
21
- $nonce = $clientApi->nonceForNewEuropeanBankAccount(array(
22
  "customerId" => $customer->id,
23
- "sepa_mandate" => array(
24
  "locale" => "de-DE",
25
  "bic" => "DEUTDEFF",
26
  "iban" => "DE89370400440532013000",
27
  "accountHolderName" => "Bob Holder",
28
- "billingAddress" => array(
29
  "streetAddress" => "123 Currywurst Way",
30
  "extendedAddress" => "Lager Suite",
31
  "firstName" => "Wilhelm",
@@ -34,13 +37,13 @@ class Braintree_EuropeBankAccountTest extends PHPUnit_Framework_TestCase
34
  "postalCode" => "60001",
35
  "countryCodeAlpha2" => "DE",
36
  "region" => "Hesse"
37
- )
38
- )
39
- ));
40
- $result = $gateway->paymentMethod()->create(array(
41
  "customerId" => $customer->id,
42
  "paymentMethodNonce" => $nonce
43
- ));
44
 
45
  $this->assertTrue($result->success);
46
  $paymentMethod = $result->paymentMethod;
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",
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;
braintree_sdk/tests/integration/HttpClientApi.php CHANGED
@@ -1,8 +1,13 @@
1
  <?php
 
2
 
3
- class Braintree_HttpClientApi extends Braintree_Http
4
- {
 
 
5
 
 
 
6
  protected function _doRequest($httpVerb, $path, $requestBody = null)
7
  {
8
  return $this->_doUrlRequest($httpVerb, $this->_config->baseUrl() . "/merchants/" . $this->_config->getMerchantId() . $path, $requestBody);
@@ -24,10 +29,10 @@ class Braintree_HttpClientApi extends Braintree_Http
24
  curl_setopt($curl, CURLOPT_TIMEOUT, 60);
25
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $httpVerb);
26
  curl_setopt($curl, CURLOPT_URL, $url);
27
- curl_setopt($curl, CURLOPT_HTTPHEADER, array(
28
  'Content-Type: application/json',
29
- 'X-ApiVersion: ' . Braintree_Configuration::API_VERSION
30
- ));
31
  curl_setopt($curl, CURLOPT_USERPWD, $this->_config->publicKey() . ':' . $this->_config->privateKey());
32
 
33
  if(!empty($requestBody)) {
@@ -38,7 +43,7 @@ class Braintree_HttpClientApi extends Braintree_Http
38
  $response = curl_exec($curl);
39
  $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
40
  curl_close($curl);
41
- return array('status' => $httpStatus, 'body' => $response);
42
  }
43
 
44
  public function get_cards($options) {
@@ -52,13 +57,13 @@ class Braintree_HttpClientApi extends Braintree_Http
52
  }
53
 
54
  public function nonce_for_new_card($options) {
55
- $clientTokenOptions = array();
56
  if (array_key_exists("customerId", $options)) {
57
  $clientTokenOptions["customerId"] = $options["customerId"];
58
  unset($options["customerId"]);
59
  }
60
 
61
- $clientToken = json_decode(Braintree_TestHelper::decodedClientToken($clientTokenOptions));
62
 
63
  $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
64
  $options["shared_customer_identifier"] = "fake_identifier_" . rand();
@@ -73,17 +78,17 @@ class Braintree_HttpClientApi extends Braintree_Http
73
  }
74
 
75
  public function nonceForNewEuropeanBankAccount($options) {
76
- $clientTokenOptions = array(
77
  'sepaMandateType' => 'business',
78
  'sepaMandateAcceptanceLocation' => 'Rostock, Germany'
79
- );
80
 
81
  if (array_key_exists("customerId", $options)) {
82
  $clientTokenOptions["customerId"] = $options["customerId"];
83
  unset($options["customerId"]);
84
  }
85
 
86
- $gateway = new Braintree_Gateway($this->_config);
87
 
88
  $clientToken = json_decode(base64_decode($gateway->clientToken()->generate($clientTokenOptions)));
89
  $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
@@ -98,7 +103,7 @@ class Braintree_HttpClientApi extends Braintree_Http
98
  }
99
 
100
  public function nonceForPayPalAccount($options) {
101
- $clientToken = json_decode(Braintree_TestHelper::decodedClientToken());
102
  $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
103
  $response = $this->post('/client_api/v1/payment_methods/paypal_accounts.json', json_encode($options));
104
  if ($response["status"] == 201 || $response["status"] == 202) {
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);
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)) {
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_cards($options) {
57
  }
58
 
59
  public function nonce_for_new_card($options) {
60
+ $clientTokenOptions = [];
61
  if (array_key_exists("customerId", $options)) {
62
  $clientTokenOptions["customerId"] = $options["customerId"];
63
  unset($options["customerId"]);
64
  }
65
 
66
+ $clientToken = json_decode(Test\Helper::decodedClientToken($clientTokenOptions));
67
 
68
  $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
69
  $options["shared_customer_identifier"] = "fake_identifier_" . rand();
78
  }
79
 
80
  public function nonceForNewEuropeanBankAccount($options) {
81
+ $clientTokenOptions = [
82
  'sepaMandateType' => 'business',
83
  'sepaMandateAcceptanceLocation' => 'Rostock, Germany'
84
+ ];
85
 
86
  if (array_key_exists("customerId", $options)) {
87
  $clientTokenOptions["customerId"] = $options["customerId"];
88
  unset($options["customerId"]);
89
  }
90
 
91
+ $gateway = new Braintree\Gateway($this->_config);
92
 
93
  $clientToken = json_decode(base64_decode($gateway->clientToken()->generate($clientTokenOptions)));
94
  $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
103
  }
104
 
105
  public function nonceForPayPalAccount($options) {
106
+ $clientToken = json_decode(Test\Helper::decodedClientToken());
107
  $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
108
  $response = $this->post('/client_api/v1/payment_methods/paypal_accounts.json', json_encode($options));
109
  if ($response["status"] == 201 || $response["status"] == 202) {
braintree_sdk/tests/integration/HttpTest.php CHANGED
@@ -1,61 +1,66 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_HttpTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
5
  {
6
- function testProductionSSL()
7
  {
8
  try {
9
- Braintree_Configuration::environment('production');
10
- $this->setExpectedException('Braintree_Exception_Authentication');
11
- $http = new Braintree_Http(Braintree_Configuration::$global);
12
  $http->get('/');
13
- } catch (Exception $e) {
14
- Braintree_Configuration::environment('development');
15
  throw $e;
16
  }
17
- Braintree_Configuration::environment('development');
18
  }
19
 
20
- function testSandboxSSL()
21
  {
22
  try {
23
- Braintree_Configuration::environment('sandbox');
24
- $this->setExpectedException('Braintree_Exception_Authentication');
25
- $http = new Braintree_Http(Braintree_Configuration::$global);
26
  $http->get('/');
27
- } catch (Exception $e) {
28
- Braintree_Configuration::environment('development');
29
  throw $e;
30
  }
31
- Braintree_Configuration::environment('development');
32
  }
33
 
34
- function testSslError()
35
  {
36
  try {
37
- Braintree_Configuration::environment('sandbox');
38
- $this->setExpectedException('Braintree_Exception_SSLCertificate');
39
- $http = new Braintree_Http(Braintree_Configuration::$global);
40
  //ip address of api.braintreegateway.com
41
  $http->_doUrlRequest('get', '204.109.13.121');
42
- } catch (Exception $e) {
43
- Braintree_Configuration::environment('development');
44
  throw $e;
45
  }
46
- Braintree_Configuration::environment('development');
47
  }
48
 
49
- function testAuthorizationWithConfig()
50
  {
51
- $config = new Braintree_Configuration(array(
52
  'environment' => 'development',
53
  'merchant_id' => 'integration_merchant_id',
54
  'publicKey' => 'badPublicKey',
55
  'privateKey' => 'badPrivateKey'
56
- ));
57
 
58
- $http = new Braintree_Http($config);
59
  $result = $http->_doUrlRequest('GET', $config->baseUrl() . '/merchants/integration_merchant_id/customers');
60
  $this->assertEquals(401, $result['status']);
61
  }
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 testSslError()
40
  {
41
  try {
42
+ Braintree\Configuration::environment('sandbox');
43
+ $this->setExpectedException('Braintree\Exception\SSLCertificate');
44
+ $http = new Braintree\Http(Braintree\Configuration::$global);
45
  //ip address of api.braintreegateway.com
46
  $http->_doUrlRequest('get', '204.109.13.121');
47
+ } catch (Braintree\Exception $e) {
48
+ Braintree\Configuration::environment('development');
49
  throw $e;
50
  }
51
+ Braintree\Configuration::environment('development');
52
  }
53
 
54
+ public function testAuthorizationWithConfig()
55
  {
56
+ $config = new Braintree\Configuration([
57
  'environment' => 'development',
58
  'merchant_id' => 'integration_merchant_id',
59
  'publicKey' => 'badPublicKey',
60
  'privateKey' => 'badPrivateKey'
61
+ ]);
62
 
63
+ $http = new Braintree\Http($config);
64
  $result = $http->_doUrlRequest('GET', $config->baseUrl() . '/merchants/integration_merchant_id/customers');
65
  $this->assertEquals(401, $result['status']);
66
  }
braintree_sdk/tests/integration/MerchantAccountTest.php CHANGED
@@ -1,162 +1,174 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_MerchantAccountTest extends PHPUnit_Framework_TestCase
5
- {
 
 
 
6
 
7
- private static $deprecatedValidParams = array(
8
- 'applicantDetails' => array(
 
 
9
  'companyName' => "Robot City",
10
  'firstName' => "Joe",
11
  'lastName' => "Bloggs",
12
  'email' => "joe@bloggs.com",
13
  'phone' => "555-555-5555",
14
- 'address' => array(
15
  'streetAddress' => "123 Credibility St.",
16
  'postalCode' => "60606",
17
  'locality' => "Chicago",
18
  'region' => "IL",
19
- ),
20
  'dateOfBirth' => "10/9/1980",
21
  'ssn' => "123-00-1234",
22
  'taxId' => "123456789",
23
  'routingNumber' => "122100024",
24
  'accountNumber' => "43759348798"
25
- ),
26
  'tosAccepted' => true,
27
  'masterMerchantAccountId' => "sandbox_master_merchant_account"
28
- );
29
 
30
- private static $validParams = array(
31
- 'individual' => array(
32
  'firstName' => "Joe",
33
  'lastName' => "Bloggs",
34
  'email' => "joe@bloggs.com",
35
  'phone' => "555-555-5555",
36
- 'address' => array(
37
  'streetAddress' => "123 Credibility St.",
38
  'postalCode' => "60606",
39
  'locality' => "Chicago",
40
  'region' => "IL",
41
- ),
42
  'dateOfBirth' => "10/9/1980",
43
  'ssn' => "123-00-1234",
44
- ),
45
- 'business' => array(
46
  'dbaName' => "Robot City",
47
  'legalName' => "Robot City INC",
48
  'taxId' => "123456789",
49
- ),
50
- 'funding' => array(
51
  'routingNumber' => "122100024",
52
  'accountNumber' => "43759348798",
53
- 'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK,
54
  'descriptor' => 'Joes Bloggs MI',
55
- ),
56
  'tosAccepted' => true,
57
  'masterMerchantAccountId' => "sandbox_master_merchant_account"
58
- );
59
 
60
- function testCreate()
61
  {
62
- $result = Braintree_MerchantAccount::create(self::$validParams);
63
  $this->assertEquals(true, $result->success);
64
  $merchantAccount = $result->merchantAccount;
65
- $this->assertEquals(Braintree_MerchantAccount::STATUS_PENDING, $merchantAccount->status);
66
  $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
67
  }
68
 
69
- function testGatewayCreate()
70
  {
71
- $gateway = new Braintree_Gateway(array(
72
  'environment' => 'development',
73
  'merchantId' => 'integration_merchant_id',
74
  'publicKey' => 'integration_public_key',
75
  'privateKey' => 'integration_private_key'
76
- ));
77
  $result = $gateway->merchantAccount()->create(self::$validParams);
78
  $this->assertEquals(true, $result->success);
79
  $merchantAccount = $result->merchantAccount;
80
- $this->assertEquals(Braintree_MerchantAccount::STATUS_PENDING, $merchantAccount->status);
81
  $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
82
  }
83
 
84
- function testCreateWithDeprecatedParameters()
85
  {
86
- Braintree_TestHelper::suppressDeprecationWarnings();
87
- $result = Braintree_MerchantAccount::create(self::$deprecatedValidParams);
88
  $this->assertEquals(true, $result->success);
89
  $merchantAccount = $result->merchantAccount;
90
- $this->assertEquals(Braintree_MerchantAccount::STATUS_PENDING, $merchantAccount->status);
91
  $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
92
  }
93
 
94
- function testCreateWithId()
95
  {
96
  $rand = rand(1, 1000);
97
  $subMerchantAccountId = "sub_merchant_account_id" + $rand;
98
- $validParamsWithId = array_merge(array(), self::$validParams);
99
  $validParamsWithId['id'] = $subMerchantAccountId;
100
- $result = Braintree_MerchantAccount::create($validParamsWithId);
101
  $this->assertEquals(true, $result->success);
102
  $merchantAccount = $result->merchantAccount;
103
- $this->assertEquals(Braintree_MerchantAccount::STATUS_PENDING, $merchantAccount->status);
104
  $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
105
  $this->assertEquals("sub_merchant_account_id" + $rand, $merchantAccount->id);
106
  }
107
 
108
- function testFailedCreate()
109
  {
110
- $result = Braintree_MerchantAccount::create(array());
111
  $this->assertEquals(false, $result->success);
112
  $errors = $result->errors->forKey('merchantAccount')->onAttribute('masterMerchantAccountId');
113
- $this->assertEquals(Braintree_Error_Codes::MERCHANT_ACCOUNT_MASTER_MERCHANT_ACCOUNT_ID_IS_REQUIRED, $errors[0]->code);
114
  }
115
 
116
- function testCreateWithFundingDestination()
117
  {
118
- $params = array_merge(array(), self::$validParams);
119
- $params['funding']['destination'] = Braintree_MerchantAccount::FUNDING_DESTINATION_BANK;
120
- $result = Braintree_MerchantAccount::create($params);
121
  $this->assertEquals(true, $result->success);
122
 
123
- $params = array_merge(array(), self::$validParams);
124
- $params['funding']['destination'] = Braintree_MerchantAccount::FUNDING_DESTINATION_EMAIL;
125
  $params['funding']['email'] = "billgates@outlook.com";
126
- $result = Braintree_MerchantAccount::create($params);
127
  $this->assertEquals(true, $result->success);
128
 
129
- $params = array_merge(array(), self::$validParams);
130
- $params['funding']['destination'] = Braintree_MerchantAccount::FUNDING_DESTINATION_MOBILE_PHONE;
131
  $params['funding']['mobilePhone'] = "1112224444";
132
- $result = Braintree_MerchantAccount::create($params);
133
  $this->assertEquals(true, $result->success);
134
  }
135
 
136
- function testFind()
137
  {
138
- $params = array_merge(array(), self::$validParams);
139
- $result = Braintree_MerchantAccount::create(self::$validParams);
140
  $this->assertEquals(true, $result->success);
141
- $this->assertEquals(Braintree_MerchantAccount::STATUS_PENDING, $result->merchantAccount->status);
142
 
143
  $id = $result->merchantAccount->id;
144
- $merchantAccount = Braintree_MerchantAccount::find($id);
145
 
146
- $this->assertEquals(Braintree_MerchantAccount::STATUS_ACTIVE, $merchantAccount->status);
147
  $this->assertEquals($params['individual']['firstName'], $merchantAccount->individualDetails->firstName);
148
  $this->assertEquals($params['individual']['lastName'], $merchantAccount->individualDetails->lastName);
149
  }
150
 
151
- function testFind_throwsIfNotFound()
 
 
 
 
 
 
 
152
  {
153
- $this->setExpectedException('Braintree_Exception_NotFound', 'merchant account with id does-not-exist not found');
154
- Braintree_MerchantAccount::find('does-not-exist');
155
  }
156
 
157
- function testUpdate()
158
  {
159
- $params = array_merge(array(), self::$validParams);
160
  unset($params["tosAccepted"]);
161
  unset($params["masterMerchantAccountId"]);
162
  $params["individual"]["firstName"] = "John";
@@ -179,10 +191,10 @@ class Braintree_MerchantAccountTest extends PHPUnit_Framework_TestCase
179
  $params["funding"]["routingNumber"] = "071000013";
180
  $params["funding"]["email"] = "check@this.com";
181
  $params["funding"]["mobilePhone"] = "1234567890";
182
- $params["funding"]["destination"] = Braintree_MerchantAccount::FUNDING_DESTINATION_BANK;
183
  $params["funding"]["descriptor"] = "Joes Bloggs FL";
184
 
185
- $result = Braintree_MerchantAccount::update("sandbox_sub_merchant_account", $params);
186
  $this->assertEquals(true, $result->success);
187
 
188
  $updatedMerchantAccount = $result->merchantAccount;
@@ -209,211 +221,211 @@ class Braintree_MerchantAccountTest extends PHPUnit_Framework_TestCase
209
  $this->assertEquals("071000013", $updatedMerchantAccount->fundingDetails->routingNumber);
210
  $this->assertEquals("check@this.com", $updatedMerchantAccount->fundingDetails->email);
211
  $this->assertEquals("1234567890", $updatedMerchantAccount->fundingDetails->mobilePhone);
212
- $this->assertEquals(Braintree_MerchantAccount::FUNDING_DESTINATION_BANK, $updatedMerchantAccount->fundingDetails->destination);
213
  $this->assertEquals("Joes Bloggs FL", $updatedMerchantAccount->fundingDetails->descriptor);
214
  }
215
 
216
- function testUpdateDoesNotRequireAllFields()
217
  {
218
- $params = array(
219
- 'individual' => array(
220
  'firstName' => "Joe"
221
- )
222
- );
223
- $result = Braintree_MerchantAccount::update("sandbox_sub_merchant_account", $params);
224
  $this->assertEquals(true, $result->success);
225
  }
226
 
227
- function testUpdateWithBlankFields()
228
  {
229
- $params = array(
230
- 'individual' => array(
231
  'firstName' => "",
232
  'lastName' => "",
233
  'email' => "",
234
  'phone' => "",
235
- 'address' => array(
236
  'streetAddress' => "",
237
  'postalCode' => "",
238
  'locality' => "",
239
  'region' => "",
240
- ),
241
  'dateOfBirth' => "",
242
  'ssn' => "",
243
- ),
244
- 'business' => array(
245
  'dbaName' => "",
246
  'legalName' => "",
247
  'taxId' => "",
248
- ),
249
- 'funding' => array(
250
  'routingNumber' => "",
251
  'accountNumber' => "",
252
  'destination' => "",
253
- ),
254
- );
255
 
256
- $result = Braintree_MerchantAccount::update("sandbox_sub_merchant_account", $params);
257
  $this->assertEquals(false, $result->success);
258
 
259
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("firstName");
260
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_REQUIRED);
261
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("lastName");
262
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_REQUIRED);
263
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("dateOfBirth");
264
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_DATE_OF_BIRTH_IS_REQUIRED);
265
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("email");
266
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_REQUIRED);
267
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("streetAddress");
268
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_REQUIRED);
269
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("postalCode");
270
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_REQUIRED);
271
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("locality");
272
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_LOCALITY_IS_REQUIRED);
273
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("region");
274
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_REQUIRED);
275
  $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("destination");
276
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_REQUIRED);
277
  }
278
 
279
- function testUpdateWithInvalidFields()
280
  {
281
- $params = array(
282
- "individual" => array(
283
  "firstName" => "<>",
284
  "lastName" => "<>",
285
  "email" => "bad",
286
  "phone" => "999",
287
- "address" => array(
288
  "streetAddress" => "nope",
289
  "postalCode" => "1",
290
  "region" => "QQ",
291
- ),
292
  "dateOfBirth" => "hah",
293
  "ssn" => "12345",
294
- ),
295
- "business" => array(
296
  "legalName" => "``{}",
297
  "dbaName" => "{}``",
298
  "taxId" => "bad",
299
- "address" => array(
300
  "streetAddress" => "nope",
301
  "postalCode" => "1",
302
  "region" => "QQ",
303
- ),
304
- ),
305
- "funding" => array(
306
  "destination" => "MY WALLET",
307
  "routingNumber" => "LEATHER",
308
  "accountNumber" => "BACK POCKET",
309
  "email" => "BILLFOLD",
310
  "mobilePhone" => "TRIFOLD"
311
- ),
312
- );
313
 
314
 
315
- $result = Braintree_MerchantAccount::update("sandbox_sub_merchant_account", $params);
316
  $this->assertEquals(false, $result->success);
317
 
318
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("firstName");
319
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_FIRST_NAME_IS_INVALID);
320
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("lastName");
321
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_LAST_NAME_IS_INVALID);
322
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("email");
323
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_EMAIL_IS_INVALID);
324
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("phone");
325
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_PHONE_IS_INVALID);
326
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("streetAddress");
327
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_STREET_ADDRESS_IS_INVALID);
328
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("postalCode");
329
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_POSTAL_CODE_IS_INVALID);
330
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->forKey("address")->onAttribute("region");
331
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_ADDRESS_REGION_IS_INVALID);
332
  $error = $result->errors->forKey("merchantAccount")->forKey("individual")->onAttribute("ssn");
333
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_INDIVIDUAL_SSN_IS_INVALID);
334
  ;
335
  $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("legalName");
336
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_BUSINESS_LEGAL_NAME_IS_INVALID);
337
  $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("dbaName");
338
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_BUSINESS_DBA_NAME_IS_INVALID);
339
  $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("taxId");
340
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_BUSINESS_TAX_ID_IS_INVALID);
341
  $error = $result->errors->forKey("merchantAccount")->forKey("business")->forKey("address")->onAttribute("streetAddress");
342
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_BUSINESS_ADDRESS_STREET_ADDRESS_IS_INVALID);
343
  $error = $result->errors->forKey("merchantAccount")->forKey("business")->forKey("address")->onAttribute("postalCode");
344
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_BUSINESS_ADDRESS_POSTAL_CODE_IS_INVALID);
345
  $error = $result->errors->forKey("merchantAccount")->forKey("business")->forKey("address")->onAttribute("region");
346
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_BUSINESS_ADDRESS_REGION_IS_INVALID);
347
 
348
  $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("destination");
349
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_FUNDING_DESTINATION_IS_INVALID);
350
  $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("routingNumber");
351
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_FUNDING_ROUTING_NUMBER_IS_INVALID);
352
  $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("accountNumber");
353
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_FUNDING_ACCOUNT_NUMBER_IS_INVALID);
354
  $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("email");
355
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_FUNDING_EMAIL_IS_INVALID);
356
  $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("mobilePhone");
357
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_FUNDING_MOBILE_PHONE_IS_INVALID);
358
  }
359
 
360
- function testUpdateWithInvalidBusinessFields()
361
  {
362
- $params = array(
363
- "business" => array(
364
  "legalName" => "",
365
  "taxId" => "111223333",
366
- )
367
- );
368
 
369
- $result = Braintree_MerchantAccount::update("sandbox_sub_merchant_account", $params);
370
  $this->assertEquals(false, $result->success);
371
 
372
  $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("legalName");
373
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_BUSINESS_LEGAL_NAME_IS_REQUIRED_WITH_TAX_ID);
374
  $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("taxId");
375
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_BUSINESS_TAX_ID_MUST_BE_BLANK);
376
 
377
- $params = array(
378
- "business" => array(
379
  "legalName" => "legal name",
380
  "taxId" => "",
381
- )
382
- );
383
 
384
- $result = Braintree_MerchantAccount::update("sandbox_sub_merchant_account", $params);
385
  $this->assertEquals(false, $result->success);
386
 
387
  $error = $result->errors->forKey("merchantAccount")->forKey("business")->onAttribute("taxId");
388
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_BUSINESS_TAX_ID_IS_REQUIRED_WITH_LEGAL_NAME);
389
  }
390
 
391
- function testUpdateWithInvalidFundingFields()
392
  {
393
- $params = array(
394
- "funding" => array(
395
- "destination" => Braintree_MerchantAccount::FUNDING_DESTINATION_EMAIL,
396
  "email" => "",
397
- )
398
- );
399
 
400
- $result = Braintree_MerchantAccount::update("sandbox_sub_merchant_account", $params);
401
  $this->assertEquals(false, $result->success);
402
 
403
  $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("email");
404
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_FUNDING_EMAIL_IS_REQUIRED);
405
 
406
- $params = array(
407
- "funding" => array(
408
- "destination" => Braintree_MerchantAccount::FUNDING_DESTINATION_MOBILE_PHONE,
409
  "mobilePhone" => "",
410
- )
411
- );
412
 
413
- $result = Braintree_MerchantAccount::update("sandbox_sub_merchant_account", $params);
414
  $this->assertEquals(false, $result->success);
415
 
416
  $error = $result->errors->forKey("merchantAccount")->forKey("funding")->onAttribute("mobilePhone");
417
- $this->assertEquals($error[0]->code, Braintree_Error_Codes::MERCHANT_ACCOUNT_FUNDING_MOBILE_PHONE_IS_REQUIRED);
418
  }
419
  }
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";
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;
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
  }
braintree_sdk/tests/integration/MerchantTest.php CHANGED
@@ -1,19 +1,25 @@
1
  <?php
2
- require_once __DIR__ . '/../TestHelper.php';
3
 
4
- class Braintree_MerchantTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
5
  {
6
- function testCreateMerchant()
7
  {
8
- $gateway = new Braintree_Gateway(array(
9
  'clientId' => 'client_id$development$integration_client_id',
10
  'clientSecret' => 'client_secret$development$integration_client_secret',
11
- ));
12
- $result = $gateway->merchant()->create(array(
13
  'email' => 'name@email.com',
14
  'countryCodeAlpha3' => 'USA',
15
  'paymentMethods' => ['credit_card', 'paypal'],
16
- ));
17
 
18
  $this->assertEquals(true, $result->success);
19
  $merchant = $result->merchant;
@@ -23,34 +29,34 @@ class Braintree_MerchantTest extends PHPUnit_Framework_TestCase
23
  }
24
 
25
  /**
26
- * @expectedException Braintree_Exception_Configuration
27
- * @expectedExceptionMessage clientId needs to be passed to Braintree_Gateway.
28
  */
29
- function testAssertsHasCredentials()
30
  {
31
- $gateway = new Braintree_Gateway(array(
32
  'clientSecret' => 'client_secret$development$integration_client_secret',
33
- ));
34
- $gateway->merchant()->create(array(
35
  'email' => 'name@email.com',
36
  'countryCodeAlpha3' => 'USA',
37
- ));
38
  }
39
 
40
- function testBadPaymentMethods()
41
  {
42
- $gateway = new Braintree_Gateway(array(
43
  'clientId' => 'client_id$development$integration_client_id',
44
  'clientSecret' => 'client_secret$development$integration_client_secret',
45
- ));
46
- $result = $gateway->merchant()->create(array(
47
  'email' => 'name@email.com',
48
  'countryCodeAlpha3' => 'USA',
49
  'paymentMethods' => ['fake_money'],
50
- ));
51
 
52
  $this->assertEquals(false, $result->success);
53
  $errors = $result->errors->forKey('merchant')->onAttribute('paymentMethods');
54
- $this->assertEquals(Braintree_Error_Codes::MERCHANT_ACCOUNT_PAYMENT_METHODS_ARE_INVALID, $errors[0]->code);
55
  }
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 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;
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
  }
braintree_sdk/tests/integration/MultipleValueNodeTest.php CHANGED
@@ -1,89 +1,94 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/SubscriptionTestHelper.php';
4
 
5
- class Braintree_MultipleValueNodeTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
6
  {
7
- function testIn_singleValue()
8
  {
9
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
10
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
11
 
12
- $activeSubscription = Braintree_Subscription::create(array(
13
  'paymentMethodToken' => $creditCard->token,
14
  'planId' => $triallessPlan['id'],
15
  'price' => '3'
16
- ))->subscription;
17
 
18
- $canceledSubscription = Braintree_Subscription::create(array(
19
  'paymentMethodToken' => $creditCard->token,
20
  'planId' => $triallessPlan['id'],
21
  'price' => '3'
22
- ))->subscription;
23
- Braintree_Subscription::cancel($canceledSubscription->id);
24
 
25
- $collection = Braintree_Subscription::search(array(
26
- Braintree_SubscriptionSearch::status()->in(array(Braintree_Subscription::ACTIVE)),
27
- Braintree_SubscriptionSearch::price()->is('3')
28
- ));
29
  foreach ($collection AS $item) {
30
- $this->assertEquals(Braintree_Subscription::ACTIVE, $item->status);
31
  }
32
 
33
- $this->assertTrue(Braintree_TestHelper::includes($collection, $activeSubscription));
34
- $this->assertFalse(Braintree_TestHelper::includes($collection, $canceledSubscription));
35
  }
36
 
37
- function testIs()
38
  {
39
  $found = false;
40
- $collection = Braintree_Subscription::search(array(
41
- Braintree_SubscriptionSearch::status()->is(Braintree_Subscription::PAST_DUE)
42
- ));
43
  foreach ($collection AS $item) {
44
  $found = true;
45
- $this->assertEquals(Braintree_Subscription::PAST_DUE, $item->status);
46
  }
47
  $this->assertTrue($found);
48
  }
49
 
50
- function testSearch_statusIsExpired()
51
  {
52
  $found = false;
53
- $collection = Braintree_Subscription::search(array(
54
- Braintree_SubscriptionSearch::status()->in(array(Braintree_Subscription::EXPIRED))
55
- ));
56
  foreach ($collection AS $item) {
57
  $found = true;
58
- $this->assertEquals(Braintree_Subscription::EXPIRED, $item->status);
59
  }
60
  $this->assertTrue($found);
61
  }
62
 
63
- function testIn_multipleValues()
64
  {
65
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
66
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
67
 
68
- $activeSubscription = Braintree_Subscription::create(array(
69
  'paymentMethodToken' => $creditCard->token,
70
  'planId' => $triallessPlan['id'],
71
  'price' => '4'
72
- ))->subscription;
73
 
74
- $canceledSubscription = Braintree_Subscription::create(array(
75
  'paymentMethodToken' => $creditCard->token,
76
  'planId' => $triallessPlan['id'],
77
  'price' => '4'
78
- ))->subscription;
79
- Braintree_Subscription::cancel($canceledSubscription->id);
80
 
81
- $collection = Braintree_Subscription::search(array(
82
- Braintree_SubscriptionSearch::status()->in(array(Braintree_Subscription::ACTIVE, Braintree_Subscription::CANCELED)),
83
- Braintree_SubscriptionSearch::price()->is('4')
84
- ));
85
 
86
- $this->assertTrue(Braintree_TestHelper::includes($collection, $activeSubscription));
87
- $this->assertTrue(Braintree_TestHelper::includes($collection, $canceledSubscription));
88
  }
89
  }
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
  }
braintree_sdk/tests/integration/OAuthTest.php CHANGED
@@ -1,36 +1,28 @@
1
  <?php
2
- require_once __DIR__ . '/../TestHelper.php';
3
 
4
- class Braintree_OAuthTest extends PHPUnit_Framework_TestCase
5
- {
6
- /**
7
- * @expectedException Braintree_Exception_Configuration
8
- * @expectedExceptionMessage clientSecret needs to be passed to Braintree_Gateway.
9
- */
10
- public function testAssertsHasCredentials()
11
- {
12
- $gateway = new Braintree_Gateway(array(
13
- 'clientId' => 'client_id$development$integration_client_id'
14
- ));
15
- $gateway->oauth()->createTokenFromCode(array(
16
- 'code' => 'integration_oauth_auth_code_' . rand(0,299)
17
- ));
18
- }
19
 
 
 
 
 
 
 
20
  public function testCreateTokenFromCode()
21
  {
22
- $gateway = new Braintree_Gateway(array(
23
  'clientId' => 'client_id$development$integration_client_id',
24
  'clientSecret' => 'client_secret$development$integration_client_secret'
25
- ));
26
- $code = Braintree_OAuthTestHelper::createGrant($gateway, array(
27
  'merchant_public_id' => 'integration_merchant_id',
28
  'scope' => 'read_write'
29
- ));
30
- $result = $gateway->oauth()->createTokenFromCode(array(
31
  'code' => $code,
32
  'scope' => 'read_write',
33
- ));
34
 
35
  $this->assertEquals(true, $result->success);
36
  $credentials = $result->credentials;
@@ -40,21 +32,36 @@ class Braintree_OAuthTest extends PHPUnit_Framework_TestCase
40
  $this->assertNotNull($credentials->expiresAt);
41
  }
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  public function testCreateTokenFromCodeWithMixedCredentials()
44
  {
45
- $gateway = new Braintree_Gateway(array(
46
  'clientId' => 'client_id$development$integration_client_id',
47
  'clientSecret' => 'client_secret$development$integration_client_secret',
48
  'accessToken' => 'access_token$development$integration_merchant_id$f9ac33b3dd',
49
- ));
50
- $code = Braintree_OAuthTestHelper::createGrant($gateway, array(
51
  'merchant_public_id' => 'integration_merchant_id',
52
  'scope' => 'read_write'
53
- ));
54
- $result = $gateway->oauth()->createTokenFromCode(array(
55
  'code' => $code,
56
  'scope' => 'read_write',
57
- ));
58
 
59
  $this->assertEquals(true, $result->success);
60
  $credentials = $result->credentials;
@@ -66,18 +73,18 @@ class Braintree_OAuthTest extends PHPUnit_Framework_TestCase
66
 
67
  public function testCreateTokenFromCode_JsonAPI()
68
  {
69
- $gateway = new Braintree_Gateway(array(
70
  'clientId' => 'client_id$development$integration_client_id',
71
  'clientSecret' => 'client_secret$development$integration_client_secret'
72
- ));
73
- $code = Braintree_OAuthTestHelper::createGrant($gateway, array(
74
  'merchant_public_id' => 'integration_merchant_id',
75
  'scope' => 'read_write'
76
- ));
77
- $result = $gateway->oauth()->createTokenFromCode(array(
78
  'code' => $code,
79
  'scope' => 'read_write',
80
- ));
81
 
82
  $this->assertEquals(true, $result->success);
83
  $this->assertNotNull($result->accessToken);
@@ -88,31 +95,31 @@ class Braintree_OAuthTest extends PHPUnit_Framework_TestCase
88
 
89
  public function testCreateTokenFromCode_ValidationErrorTest()
90
  {
91
- $gateway = new Braintree_Gateway(array(
92
  'clientId' => 'client_id$development$integration_client_id',
93
  'clientSecret' => 'client_secret$development$integration_client_secret'
94
- ));
95
- $result = $gateway->oauth()->createTokenFromCode(array(
96
  'code' => 'bad_code',
97
  'scope' => 'read_write',
98
- ));
99
 
100
  $this->assertEquals(false, $result->success);
101
  $errors = $result->errors->forKey('credentials')->onAttribute('code');
102
- $this->assertEquals(Braintree_Error_Codes::OAUTH_INVALID_GRANT, $errors[0]->code);
103
  $this->assertEquals(1, preg_match('/Invalid grant: code not found/', $result->message));
104
  }
105
 
106
  public function testCreateTokenFromCode_OldError()
107
  {
108
- $gateway = new Braintree_Gateway(array(
109
  'clientId' => 'client_id$development$integration_client_id',
110
  'clientSecret' => 'client_secret$development$integration_client_secret'
111
- ));
112
- $result = $gateway->oauth()->createTokenFromCode(array(
113
  'code' => 'bad_code',
114
  'scope' => 'read_write',
115
- ));
116
 
117
  $this->assertEquals(false, $result->success);
118
  $this->assertEquals('invalid_grant', $result->error);
@@ -121,23 +128,23 @@ class Braintree_OAuthTest extends PHPUnit_Framework_TestCase
121
 
122
  public function testCreateTokenFromRefreshToken()
123
  {
124
- $gateway = new Braintree_Gateway(array(
125
  'clientId' => 'client_id$development$integration_client_id',
126
  'clientSecret' => 'client_secret$development$integration_client_secret'
127
- ));
128
- $code = Braintree_OAuthTestHelper::createGrant($gateway, array(
129
  'merchant_public_id' => 'integration_merchant_id',
130
  'scope' => 'read_write'
131
- ));
132
- $refreshToken = $gateway->oauth()->createTokenFromCode(array(
133
  'code' => $code,
134
  'scope' => 'read_write',
135
- ))->credentials->refreshToken;
136
 
137
- $result = $gateway->oauth()->createTokenFromRefreshToken(array(
138
  'refreshToken' => $refreshToken,
139
  'scope' => 'read_write',
140
- ));
141
 
142
  $this->assertEquals(true, $result->success);
143
  $credentials = $result->credentials;
@@ -150,16 +157,16 @@ class Braintree_OAuthTest extends PHPUnit_Framework_TestCase
150
 
151
  public function testBuildConnectUrl()
152
  {
153
- $gateway = new Braintree_Gateway(array(
154
  'clientId' => 'client_id$development$integration_client_id',
155
  'clientSecret' => 'client_secret$development$integration_client_secret'
156
- ));
157
- $url = $gateway->oauth()->connectUrl(array(
158
  'merchantId' => 'integration_merchant_id',
159
  'redirectUri' => 'http://bar.example.com',
160
  'scope' => 'read_write',
161
  'state' => 'baz_state',
162
- 'user' => array(
163
  'country' => 'USA',
164
  'email' => 'foo@example.com',
165
  'firstName' => 'Bob',
@@ -172,8 +179,8 @@ class Braintree_OAuthTest extends PHPUnit_Framework_TestCase
172
  'locality' => 'Chicago',
173
  'region' => 'IL',
174
  'postalCode' => '60606',
175
- ),
176
- 'business' => array(
177
  'name' => '14 Ladders',
178
  'registeredAs' => '14.0 Ladders',
179
  'industry' => 'Ladders',
@@ -190,9 +197,9 @@ class Braintree_OAuthTest extends PHPUnit_Framework_TestCase
190
  'fulfillmentCompletedIn' => 7,
191
  'currency' => 'USD',
192
  'website' => 'http://example.com',
193
- ),
194
  'paymentMethods' => ['credit_card'],
195
- ));
196
 
197
  $components = parse_url($url);
198
  $queryString = $components['query'];
@@ -245,10 +252,10 @@ class Braintree_OAuthTest extends PHPUnit_Framework_TestCase
245
 
246
  public function testBuildConnectUrlWithoutOptionalParams()
247
  {
248
- $gateway = new Braintree_Gateway(array(
249
  'clientId' => 'client_id$development$integration_client_id',
250
  'clientSecret' => 'client_secret$development$integration_client_secret'
251
- ));
252
  $url = $gateway->oauth()->connectUrl();
253
 
254
  $queryString = parse_url($url)['query'];
@@ -262,26 +269,26 @@ class Braintree_OAuthTest extends PHPUnit_Framework_TestCase
262
 
263
  public function testBuildConnectUrlWithPaymentMethods()
264
  {
265
- $gateway = new Braintree_Gateway(array(
266
  'clientId' => 'client_id$development$integration_client_id',
267
  'clientSecret' => 'client_secret$development$integration_client_secret'
268
- ));
269
- $url = $gateway->oauth()->connectUrl(array(
270
- 'paymentMethods' => array('credit_card', 'paypal')
271
- ));
272
 
273
  $queryString = parse_url($url)['query'];
274
  parse_str($queryString, $query);
275
 
276
- $this->assertEquals(array('credit_card', 'paypal'), $query['payment_methods']);
277
  }
278
 
279
  public function testComputeSignature()
280
  {
281
- $gateway = new Braintree_Gateway(array(
282
  'clientId' => 'client_id$development$integration_client_id',
283
  'clientSecret' => 'client_secret$development$integration_client_secret'
284
- ));
285
  $urlToSign = 'http://localhost:3000/oauth/connect?business%5Bname%5D=We+Like+Spaces&client_id=client_id%24development%24integration_client_id';
286
 
287
  $signature = $gateway->oauth()->computeSignature($urlToSign);
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;
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
+
50
  public function testCreateTokenFromCodeWithMixedCredentials()
51
  {
52
+ $gateway = new Braintree\Gateway([
53
  'clientId' => 'client_id$development$integration_client_id',
54
  'clientSecret' => 'client_secret$development$integration_client_secret',
55
  'accessToken' => 'access_token$development$integration_merchant_id$f9ac33b3dd',
56
+ ]);
57
+ $code = Test\Braintree\OAuthTestHelper::createGrant($gateway, [
58
  'merchant_public_id' => 'integration_merchant_id',
59
  'scope' => 'read_write'
60
+ ]);
61
+ $result = $gateway->oauth()->createTokenFromCode([
62
  'code' => $code,
63
  'scope' => 'read_write',
64
+ ]);
65
 
66
  $this->assertEquals(true, $result->success);
67
  $credentials = $result->credentials;
73
 
74
  public function testCreateTokenFromCode_JsonAPI()
75
  {
76
+ $gateway = new Braintree\Gateway([
77
  'clientId' => 'client_id$development$integration_client_id',
78
  'clientSecret' => 'client_secret$development$integration_client_secret'
79
+ ]);
80
+ $code = Test\Braintree\OAuthTestHelper::createGrant($gateway, [
81
  'merchant_public_id' => 'integration_merchant_id',
82
  'scope' => 'read_write'
83
+ ]);
84
+ $result = $gateway->oauth()->createTokenFromCode([
85
  'code' => $code,
86
  'scope' => 'read_write',
87
+ ]);
88
 
89
  $this->assertEquals(true, $result->success);
90
  $this->assertNotNull($result->accessToken);
95
 
96
  public function testCreateTokenFromCode_ValidationErrorTest()
97
  {
98
+ $gateway = new Braintree\Gateway([
99
  'clientId' => 'client_id$development$integration_client_id',
100
  'clientSecret' => 'client_secret$development$integration_client_secret'
101
+ ]);
102
+ $result = $gateway->oauth()->createTokenFromCode([
103
  'code' => 'bad_code',
104
  'scope' => 'read_write',
105
+ ]);
106
 
107
  $this->assertEquals(false, $result->success);
108
  $errors = $result->errors->forKey('credentials')->onAttribute('code');
109
+ $this->assertEquals(Braintree\Error\Codes::OAUTH_INVALID_GRANT, $errors[0]->code);
110
  $this->assertEquals(1, preg_match('/Invalid grant: code not found/', $result->message));
111
  }
112
 
113
  public function testCreateTokenFromCode_OldError()
114
  {
115
+ $gateway = new Braintree\Gateway([
116
  'clientId' => 'client_id$development$integration_client_id',
117
  'clientSecret' => 'client_secret$development$integration_client_secret'
118
+ ]);
119
+ $result = $gateway->oauth()->createTokenFromCode([
120
  'code' => 'bad_code',
121
  'scope' => 'read_write',
122
+ ]);
123
 
124
  $this->assertEquals(false, $result->success);
125
  $this->assertEquals('invalid_grant', $result->error);
128
 
129
  public function testCreateTokenFromRefreshToken()
130
  {
131
+ $gateway = new Braintree\Gateway([
132
  'clientId' => 'client_id$development$integration_client_id',
133
  'clientSecret' => 'client_secret$development$integration_client_secret'
134
+ ]);
135
+ $code = Test\Braintree\OAuthTestHelper::createGrant($gateway, [
136
  'merchant_public_id' => 'integration_merchant_id',
137
  'scope' => 'read_write'
138
+ ]);
139
+ $refreshToken = $gateway->oauth()->createTokenFromCode([
140
  'code' => $code,
141
  'scope' => 'read_write',
142
+ ])->credentials->refreshToken;
143
 
144
+ $result = $gateway->oauth()->createTokenFromRefreshToken([
145
  'refreshToken' => $refreshToken,
146
  'scope' => 'read_write',
147
+ ]);
148
 
149
  $this->assertEquals(true, $result->success);
150
  $credentials = $result->credentials;
157
 
158
  public function testBuildConnectUrl()
159
  {
160
+ $gateway = new Braintree\Gateway([
161
  'clientId' => 'client_id$development$integration_client_id',
162
  'clientSecret' => 'client_secret$development$integration_client_secret'
163
+ ]);
164
+ $url = $gateway->oauth()->connectUrl([
165
  'merchantId' => 'integration_merchant_id',
166
  'redirectUri' => 'http://bar.example.com',
167
  'scope' => 'read_write',
168
  'state' => 'baz_state',
169
+ 'user' => [
170
  'country' => 'USA',
171
  'email' => 'foo@example.com',
172
  'firstName' => 'Bob',
179
  'locality' => 'Chicago',
180
  'region' => 'IL',
181
  'postalCode' => '60606',
182
+ ],
183
+ 'business' => [
184
  'name' => '14 Ladders',
185
  'registeredAs' => '14.0 Ladders',
186
  'industry' => 'Ladders',
197
  'fulfillmentCompletedIn' => 7,
198
  'currency' => 'USD',
199
  'website' => 'http://example.com',
200
+ ],
201
  'paymentMethods' => ['credit_card'],
202
+ ]);
203
 
204
  $components = parse_url($url);
205
  $queryString = $components['query'];
252
 
253
  public function testBuildConnectUrlWithoutOptionalParams()
254
  {
255
+ $gateway = new Braintree\Gateway([
256
  'clientId' => 'client_id$development$integration_client_id',
257
  'clientSecret' => 'client_secret$development$integration_client_secret'
258
+ ]);
259
  $url = $gateway->oauth()->connectUrl();
260
 
261
  $queryString = parse_url($url)['query'];
269
 
270
  public function testBuildConnectUrlWithPaymentMethods()
271
  {
272
+ $gateway = new Braintree\Gateway([
273
  'clientId' => 'client_id$development$integration_client_id',
274
  'clientSecret' => 'client_secret$development$integration_client_secret'
275
+ ]);
276
+ $url = $gateway->oauth()->connectUrl([
277
+ 'paymentMethods' => ['credit_card', 'paypal']
278
+ ]);
279
 
280
  $queryString = parse_url($url)['query'];
281
  parse_str($queryString, $query);
282
 
283
+ $this->assertEquals(['credit_card', 'paypal'], $query['payment_methods']);
284
  }
285
 
286
  public function testComputeSignature()
287
  {
288
+ $gateway = new Braintree\Gateway([
289
  'clientId' => 'client_id$development$integration_client_id',
290
  'clientSecret' => 'client_secret$development$integration_client_secret'
291
+ ]);
292
  $urlToSign = 'http://localhost:3000/oauth/connect?business%5Bname%5D=We+Like+Spaces&client_id=client_id%24development%24integration_client_id';
293
 
294
  $signature = $gateway->oauth()->computeSignature($urlToSign);
braintree_sdk/tests/integration/PayPalAccountTest.php CHANGED
@@ -1,57 +1,60 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/SubscriptionTestHelper.php';
4
- require_once realpath(dirname(__FILE__)) . '/HttpClientApi.php';
5
 
6
- class Braintree_PayPalAccountTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
7
  {
8
- function testFind()
9
  {
10
  $paymentMethodToken = 'PAYPALToken-' . strval(rand());
11
- $customer = Braintree_Customer::createNoValidate();
12
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
13
- $nonce = $http->nonceForPayPalAccount(array(
14
- 'paypal_account' => array(
15
  'consent_code' => 'PAYPAL_CONSENT_CODE',
16
  'token' => $paymentMethodToken
17
- )
18
- ));
19
 
20
- Braintree_PaymentMethod::create(array(
21
  'customerId' => $customer->id,
22
  'paymentMethodNonce' => $nonce
23
- ));
24
 
25
- $foundPayPalAccount = Braintree_PayPalAccount::find($paymentMethodToken);
26
 
27
  $this->assertSame('jane.doe@example.com', $foundPayPalAccount->email);
28
  $this->assertSame($paymentMethodToken, $foundPayPalAccount->token);
29
  $this->assertNotNull($foundPayPalAccount->imageUrl);
30
  }
31
 
32
- function testGatewayFind()
33
  {
34
  $paymentMethodToken = 'PAYPALToken-' . strval(rand());
35
- $customer = Braintree_Customer::createNoValidate();
36
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
37
- $nonce = $http->nonceForPayPalAccount(array(
38
- 'paypal_account' => array(
39
  'consent_code' => 'PAYPAL_CONSENT_CODE',
40
  'token' => $paymentMethodToken
41
- )
42
- ));
43
 
44
- Braintree_PaymentMethod::create(array(
45
  'customerId' => $customer->id,
46
  'paymentMethodNonce' => $nonce
47
- ));
48
 
49
- $gateway = new Braintree_Gateway(array(
50
  'environment' => 'development',
51
  'merchantId' => 'integration_merchant_id',
52
  'publicKey' => 'integration_public_key',
53
  'privateKey' => 'integration_private_key'
54
- ));
55
  $foundPayPalAccount = $gateway->paypalAccount()->find($paymentMethodToken);
56
 
57
  $this->assertSame('jane.doe@example.com', $foundPayPalAccount->email);
@@ -59,245 +62,245 @@ class Braintree_PayPalAccountTest extends PHPUnit_Framework_TestCase
59
  $this->assertNotNull($foundPayPalAccount->imageUrl);
60
  }
61
 
62
- function testFind_doesNotReturnIncorrectPaymentMethodType()
63
  {
64
  $creditCardToken = 'creditCardToken-' . strval(rand());
65
- $customer = Braintree_Customer::createNoValidate();
66
- $result = Braintree_CreditCard::create(array(
67
  'customerId' => $customer->id,
68
  'cardholderName' => 'Cardholder',
69
  'number' => '5105105105105100',
70
  'expirationDate' => '05/12',
71
  'token' => $creditCardToken
72
- ));
73
  $this->assertTrue($result->success);
74
 
75
- $this->setExpectedException('Braintree_Exception_NotFound');
76
- Braintree_PayPalAccount::find($creditCardToken);
77
  }
78
 
79
- function test_PayPalAccountExposesTimestamps()
80
  {
81
- $customer = Braintree_Customer::createNoValidate();
82
- $result = Braintree_PaymentMethod::create(array(
83
  'customerId' => $customer->id,
84
- 'paymentMethodNonce' => Braintree_Test_Nonces::$paypalFuturePayment
85
- ));
86
  $this->assertTrue($result->success);
87
 
88
  $this->assertNotNull($result->paymentMethod->createdAt);
89
  $this->assertNotNull($result->paymentMethod->updatedAt);
90
  }
91
 
92
- function test_PayPalAccountExposesBillingAgreementId()
93
  {
94
- $customer = Braintree_Customer::createNoValidate();
95
- $result = Braintree_PaymentMethod::create(array(
96
  'customerId' => $customer->id,
97
- 'paymentMethodNonce' => Braintree_Test_Nonces::$paypalBillingAgreement
98
- ));
99
  $this->assertTrue($result->success);
100
 
101
- $foundPayPalAccount = Braintree_PayPalAccount::find($result->paymentMethod->token);
102
 
103
  $this->assertNotNull($foundPayPalAccount->billingAgreementId);
104
  }
105
 
106
- function testFind_throwsIfCannotBeFound()
107
  {
108
- $this->setExpectedException('Braintree_Exception_NotFound');
109
- Braintree_PayPalAccount::find('invalid-token');
110
  }
111
 
112
- function testFind_throwsUsefulErrorMessagesWhenEmpty()
113
  {
114
  $this->setExpectedException('InvalidArgumentException', 'expected paypal account id to be set');
115
- Braintree_PayPalAccount::find('');
116
  }
117
 
118
- function testFind_throwsUsefulErrorMessagesWhenInvalid()
119
  {
120
  $this->setExpectedException('InvalidArgumentException', '@ is an invalid paypal account token');
121
- Braintree_PayPalAccount::find('@');
122
  }
123
 
124
- function testFind_returnsSubscriptionsAssociatedWithAPaypalAccount()
125
  {
126
- $customer = Braintree_Customer::createNoValidate();
127
  $paymentMethodToken = 'paypal-account-' . strval(rand());
128
 
129
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
130
- $nonce = $http->nonceForPayPalAccount(array(
131
- 'paypal_account' => array(
132
  'consent_code' => 'consent-code',
133
  'token' => $paymentMethodToken
134
- )
135
- ));
136
 
137
- $result = Braintree_PaymentMethod::create(array(
138
  'paymentMethodNonce' => $nonce,
139
  'customerId' => $customer->id
140
- ));
141
  $this->assertTrue($result->success);
142
 
143
  $token = $result->paymentMethod->token;
144
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
145
 
146
- $subscription1 = Braintree_Subscription::create(array(
147
  'paymentMethodToken' => $token,
148
  'planId' => $triallessPlan['id']
149
- ))->subscription;
150
 
151
- $subscription2 = Braintree_Subscription::create(array(
152
  'paymentMethodToken' => $token,
153
  'planId' => $triallessPlan['id']
154
- ))->subscription;
155
 
156
- $paypalAccount = Braintree_PayPalAccount::find($token);
157
  $getIds = function($sub) { return $sub->id; };
158
  $subIds = array_map($getIds, $paypalAccount->subscriptions);
159
  $this->assertTrue(in_array($subscription1->id, $subIds));
160
  $this->assertTrue(in_array($subscription2->id, $subIds));
161
  }
162
 
163
- function testUpdate()
164
  {
165
  $originalToken = 'ORIGINAL_PAYPALToken-' . strval(rand());
166
- $customer = Braintree_Customer::createNoValidate();
167
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
168
- $nonce = $http->nonceForPayPalAccount(array(
169
- 'paypal_account' => array(
170
  'consent_code' => 'PAYPAL_CONSENT_CODE',
171
  'token' => $originalToken
172
- )
173
- ));
174
 
175
- $createResult = Braintree_PaymentMethod::create(array(
176
  'customerId' => $customer->id,
177
  'paymentMethodNonce' => $nonce
178
- ));
179
  $this->assertTrue($createResult->success);
180
 
181
  $newToken = 'NEW_PAYPALToken-' . strval(rand());
182
- $updateResult = Braintree_PayPalAccount::update($originalToken, array(
183
  'token' => $newToken
184
- ));
185
 
186
  $this->assertTrue($updateResult->success);
187
  $this->assertEquals($newToken, $updateResult->paypalAccount->token);
188
 
189
- $this->setExpectedException('Braintree_Exception_NotFound');
190
- Braintree_PayPalAccount::find($originalToken);
191
 
192
  }
193
 
194
- function testUpdateAndMakeDefault()
195
  {
196
- $customer = Braintree_Customer::createNoValidate();
197
 
198
- $creditCardResult = Braintree_CreditCard::create(array(
199
  'customerId' => $customer->id,
200
  'number' => '5105105105105100',
201
  'expirationDate' => '05/12'
202
- ));
203
  $this->assertTrue($creditCardResult->success);
204
 
205
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
206
- $nonce = $http->nonceForPayPalAccount(array(
207
- 'paypal_account' => array(
208
  'consent_code' => 'PAYPAL_CONSENT_CODE'
209
- )
210
- ));
211
 
212
- $createResult = Braintree_PaymentMethod::create(array(
213
  'customerId' => $customer->id,
214
  'paymentMethodNonce' => $nonce
215
- ));
216
  $this->assertTrue($createResult->success);
217
 
218
- $updateResult = Braintree_PayPalAccount::update($createResult->paymentMethod->token, array(
219
- 'options' => array('makeDefault' => true)
220
- ));
221
 
222
  $this->assertTrue($updateResult->success);
223
  $this->assertTrue($updateResult->paypalAccount->isDefault());
224
  }
225
 
226
- function testUpdate_handleErrors()
227
  {
228
- $customer = Braintree_Customer::createNoValidate();
229
 
230
  $firstToken = 'FIRST_PAYPALToken-' . strval(rand());
231
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
232
- $firstNonce = $http->nonceForPayPalAccount(array(
233
- 'paypal_account' => array(
234
  'consent_code' => 'PAYPAL_CONSENT_CODE',
235
  'token' => $firstToken
236
- )
237
- ));
238
- $firstPaypalAccount = Braintree_PaymentMethod::create(array(
239
  'customerId' => $customer->id,
240
  'paymentMethodNonce' => $firstNonce
241
- ));
242
  $this->assertTrue($firstPaypalAccount->success);
243
 
244
  $secondToken = 'SECOND_PAYPALToken-' . strval(rand());
245
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
246
- $secondNonce = $http->nonceForPayPalAccount(array(
247
- 'paypal_account' => array(
248
  'consent_code' => 'PAYPAL_CONSENT_CODE',
249
  'token' => $secondToken
250
- )
251
- ));
252
- $secondPaypalAccount = Braintree_PaymentMethod::create(array(
253
  'customerId' => $customer->id,
254
  'paymentMethodNonce' => $secondNonce
255
- ));
256
  $this->assertTrue($secondPaypalAccount->success);
257
 
258
- $updateResult = Braintree_PayPalAccount::update($firstToken, array(
259
  'token' => $secondToken
260
- ));
261
 
262
  $this->assertFalse($updateResult->success);
263
  $errors = $updateResult->errors->forKey('paypalAccount')->errors;
264
- $this->assertEquals(Braintree_Error_Codes::PAYPAL_ACCOUNT_TOKEN_IS_IN_USE, $errors[0]->code);
265
  }
266
 
267
- function testDelete()
268
  {
269
  $paymentMethodToken = 'PAYPALToken-' . strval(rand());
270
- $customer = Braintree_Customer::createNoValidate();
271
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
272
- $nonce = $http->nonceForPayPalAccount(array(
273
- 'paypal_account' => array(
274
  'consent_code' => 'PAYPAL_CONSENT_CODE',
275
  'token' => $paymentMethodToken
276
- )
277
- ));
278
 
279
- Braintree_PaymentMethod::create(array(
280
  'customerId' => $customer->id,
281
  'paymentMethodNonce' => $nonce
282
- ));
283
 
284
- Braintree_PayPalAccount::delete($paymentMethodToken);
285
 
286
- $this->setExpectedException('Braintree_Exception_NotFound');
287
- Braintree_PayPalAccount::find($paymentMethodToken);
288
  }
289
 
290
- function testSale_createsASaleUsingGivenToken()
291
  {
292
- $nonce = Braintree_Test_Nonces::$paypalFuturePayment;
293
- $customer = Braintree_Customer::createNoValidate(array(
294
  'paymentMethodNonce' => $nonce
295
- ));
296
  $paypalAccount = $customer->paypalAccounts[0];
297
 
298
- $result = Braintree_PayPalAccount::sale($paypalAccount->token, array(
299
  'amount' => '100.00'
300
- ));
301
  $this->assertTrue($result->success);
302
  $this->assertEquals('100.00', $result->transaction->amount);
303
  $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
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);
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);
braintree_sdk/tests/integration/PaymentMethodNonceTest.php CHANGED
@@ -1,35 +1,39 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/HttpClientApi.php';
4
 
5
- class Braintree_PaymentMethodNonceTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
6
  {
7
- function testCreate_fromPaymentMethodToken()
8
  {
9
- $customer = Braintree_Customer::createNoValidate();
10
- $card = Braintree_CreditCard::create(array(
11
  'customerId' => $customer->id,
12
  'cardholderName' => 'Cardholder',
13
  'number' => '5105105105105100',
14
- 'expirationDate' => '05/12'
15
- ))->creditCard;
16
 
17
- $result = Braintree_PaymentMethodNonce::create($card->token);
18
 
19
  $this->assertTrue($result->success);
20
  $this->assertNotNull($result->paymentMethodNonce);
21
  $this->assertNotNull($result->paymentMethodNonce->nonce);
22
  }
23
 
24
- function testCreate_fromNonExistentPaymentMethodToken()
25
  {
26
- $this->setExpectedException('Braintree_Exception_NotFound');
27
- Braintree_PaymentMethodNonce::create('not_a_token');
28
  }
29
 
30
- function testFind_exposesThreeDSecureInfo()
31
  {
32
- $nonce = Braintree_PaymentMethodNonce::find('threedsecurednonce');
33
  $info = $nonce->threeDSecureInfo;
34
 
35
  $this->assertEquals('threedsecurednonce', $nonce->nonce);
@@ -40,27 +44,27 @@ class Braintree_PaymentMethodNonceTest extends PHPUnit_Framework_TestCase
40
  $this->assertTrue($info->liabilityShiftPossible);
41
  }
42
 
43
- function testFind_exposesNullThreeDSecureInfoIfNoneExists()
44
  {
45
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
46
- $nonce = $http->nonce_for_new_card(array(
47
- "creditCard" => array(
48
  "number" => "4111111111111111",
49
  "expirationMonth" => "11",
50
  "expirationYear" => "2099"
51
- )
52
- ));
53
 
54
- $foundNonce = Braintree_PaymentMethodNonce::find($nonce);
55
  $info = $foundNonce->threeDSecureInfo;
56
 
57
  $this->assertEquals($nonce, $foundNonce->nonce);
58
  $this->assertNull($info);
59
  }
60
 
61
- function testFind_nonExistantNonce()
62
  {
63
- $this->setExpectedException('Braintree_Exception_NotFound');
64
- Braintree_PaymentMethodNonce::find('not_a_nonce');
65
  }
66
  }
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 PaymentMethodNonceTest extends Setup
10
  {
11
+ public function testCreate_fromPaymentMethodToken()
12
  {
13
+ $customer = Braintree\Customer::createNoValidate();
14
+ $card = Braintree\CreditCard::create([
15
  'customerId' => $customer->id,
16
  'cardholderName' => 'Cardholder',
17
  'number' => '5105105105105100',
18
+ 'expirationDate' => '05/12',
19
+ ])->creditCard;
20
 
21
+ $result = Braintree\PaymentMethodNonce::create($card->token);
22
 
23
  $this->assertTrue($result->success);
24
  $this->assertNotNull($result->paymentMethodNonce);
25
  $this->assertNotNull($result->paymentMethodNonce->nonce);
26
  }
27
 
28
+ public function testCreate_fromNonExistentPaymentMethodToken()
29
  {
30
+ $this->setExpectedException('Braintree\Exception\NotFound');
31
+ Braintree\PaymentMethodNonce::create('not_a_token');
32
  }
33
 
34
+ public function testFind_exposesThreeDSecureInfo()
35
  {
36
+ $nonce = Braintree\PaymentMethodNonce::find('threedsecurednonce');
37
  $info = $nonce->threeDSecureInfo;
38
 
39
  $this->assertEquals('threedsecurednonce', $nonce->nonce);
44
  $this->assertTrue($info->liabilityShiftPossible);
45
  }
46
 
47
+ public function testFind_exposesNullThreeDSecureInfoIfNoneExists()
48
  {
49
+ $http = new HttpClientApi(Braintree\Configuration::$global);
50
+ $nonce = $http->nonce_for_new_card([
51
+ "creditCard" => [
52
  "number" => "4111111111111111",
53
  "expirationMonth" => "11",
54
  "expirationYear" => "2099"
55
+ ]
56
+ ]);
57
 
58
+ $foundNonce = Braintree\PaymentMethodNonce::find($nonce);
59
  $info = $foundNonce->threeDSecureInfo;
60
 
61
  $this->assertEquals($nonce, $foundNonce->nonce);
62
  $this->assertNull($info);
63
  }
64
 
65
+ public function testFind_nonExistantNonce()
66
  {
67
+ $this->setExpectedException('Braintree\Exception\NotFound');
68
+ Braintree\PaymentMethodNonce::find('not_a_nonce');
69
  }
70
  }
braintree_sdk/tests/integration/PaymentMethodTest.php CHANGED
@@ -1,578 +1,640 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/HttpClientApi.php';
4
 
5
- class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
6
  {
7
- function testCreate_fromVaultedCreditCardNonce()
8
  {
9
- $customer = Braintree_Customer::createNoValidate();
10
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
11
- $nonce = $http->nonce_for_new_card(array(
12
- 'credit_card' => array(
13
  'number' => '4111111111111111',
14
  'expirationMonth' => '11',
15
  'expirationYear' => '2099'
16
- ),
17
  'share' => true
18
- ));
19
 
20
- $result = Braintree_PaymentMethod::create(array(
21
  'customerId' => $customer->id,
22
  'paymentMethodNonce' => $nonce
23
- ));
24
 
25
  $this->assertSame('411111', $result->paymentMethod->bin);
26
  $this->assertSame('1111', $result->paymentMethod->last4);
27
  $this->assertNotNull($result->paymentMethod->token);
28
  $this->assertNotNull($result->paymentMethod->imageUrl);
 
29
  }
30
 
31
- function testGatewayCreate_fromVaultedCreditCardNonce()
32
  {
33
- $customer = Braintree_Customer::createNoValidate();
34
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
35
- $nonce = $http->nonce_for_new_card(array(
36
- 'credit_card' => array(
37
  'number' => '4111111111111111',
38
  'expirationMonth' => '11',
39
  'expirationYear' => '2099'
40
- ),
41
  'share' => true
42
- ));
43
 
44
- $gateway = new Braintree_Gateway(array(
45
  'environment' => 'development',
46
  'merchantId' => 'integration_merchant_id',
47
  'publicKey' => 'integration_public_key',
48
  'privateKey' => 'integration_private_key'
49
- ));
50
- $result = $gateway->paymentMethod()->create(array(
51
  'customerId' => $customer->id,
52
  'paymentMethodNonce' => $nonce
53
- ));
54
 
55
  $this->assertSame('411111', $result->paymentMethod->bin);
56
  $this->assertSame('1111', $result->paymentMethod->last4);
57
  $this->assertNotNull($result->paymentMethod->token);
58
  $this->assertNotNull($result->paymentMethod->imageUrl);
 
59
  }
60
 
61
- function testCreate_fromFakeApplePayNonce()
62
  {
63
- $customer = Braintree_Customer::createNoValidate();
64
- $result = Braintree_PaymentMethod::create(array(
65
  'customerId' => $customer->id,
66
- 'paymentMethodNonce' => Braintree_Test_Nonces::$applePayVisa
67
- ));
68
 
69
  $this->assertTrue($result->success);
70
  $applePayCard = $result->paymentMethod;
71
  $this->assertNotNull($applePayCard->token);
72
- $this->assertSame(Braintree_ApplePayCard::VISA, $applePayCard->cardType);
73
  $this->assertContains("Visa ", $applePayCard->paymentInstrumentName);
74
  $this->assertContains("Visa ", $applePayCard->sourceDescription);
75
  $this->assertTrue($applePayCard->default);
76
  $this->assertContains('apple_pay', $applePayCard->imageUrl);
77
  $this->assertTrue(intval($applePayCard->expirationMonth) > 0);
78
  $this->assertTrue(intval($applePayCard->expirationYear) > 0);
 
79
  }
80
 
81
- function testCreate_fromFakeAndroidPayProxyCardNonce()
82
  {
83
- $customer = Braintree_Customer::createNoValidate();
84
- $result = Braintree_PaymentMethod::create(array(
85
  'customerId' => $customer->id,
86
- 'paymentMethodNonce' => Braintree_Test_Nonces::$androidPayDiscover
87
- ));
88
 
89
  $this->assertTrue($result->success);
90
  $androidPayCard = $result->paymentMethod;
91
  $this->assertNotNull($androidPayCard->token);
92
- $this->assertSame(Braintree_CreditCard::DISCOVER, $androidPayCard->virtualCardType);
93
- $this->assertSame(Braintree_CreditCard::DISCOVER, $androidPayCard->cardType);
94
  $this->assertSame("1117", $androidPayCard->virtualCardLast4);
95
  $this->assertSame("1117", $androidPayCard->last4);
96
- $this->assertSame(Braintree_CreditCard::VISA, $androidPayCard->sourceCardType);
97
  $this->assertSame("1111", $androidPayCard->sourceCardLast4);
98
  $this->assertSame("Visa 1111", $androidPayCard->sourceDescription);
99
  $this->assertTrue($androidPayCard->default);
100
  $this->assertContains('android_pay', $androidPayCard->imageUrl);
101
  $this->assertTrue(intval($androidPayCard->expirationMonth) > 0);
102
  $this->assertTrue(intval($androidPayCard->expirationYear) > 0);
 
103
  }
104
 
105
- function testCreate_fromFakeAndroidPayNetworkTokenNonce()
106
  {
107
- $customer = Braintree_Customer::createNoValidate();
108
- $result = Braintree_PaymentMethod::create(array(
109
  'customerId' => $customer->id,
110
- 'paymentMethodNonce' => Braintree_Test_Nonces::$androidPayMasterCard
111
- ));
112
 
113
  $this->assertTrue($result->success);
114
  $androidPayCard = $result->paymentMethod;
115
  $this->assertNotNull($androidPayCard->token);
116
- $this->assertSame(Braintree_CreditCard::MASTER_CARD, $androidPayCard->virtualCardType);
117
- $this->assertSame(Braintree_CreditCard::MASTER_CARD, $androidPayCard->cardType);
118
  $this->assertSame("4444", $androidPayCard->virtualCardLast4);
119
  $this->assertSame("4444", $androidPayCard->last4);
120
- $this->assertSame(Braintree_CreditCard::MASTER_CARD, $androidPayCard->sourceCardType);
121
  $this->assertSame("4444", $androidPayCard->sourceCardLast4);
122
  $this->assertSame("MasterCard 4444", $androidPayCard->sourceDescription);
123
  $this->assertTrue($androidPayCard->default);
124
  $this->assertContains('android_pay', $androidPayCard->imageUrl);
125
  $this->assertTrue(intval($androidPayCard->expirationMonth) > 0);
126
  $this->assertTrue(intval($androidPayCard->expirationYear) > 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  }
128
 
129
- function testCreate_fromUnvalidatedCreditCardNonce()
130
  {
131
- $customer = Braintree_Customer::createNoValidate();
132
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
133
- $nonce = $http->nonce_for_new_card(array(
134
- 'credit_card' => array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  'number' => '4111111111111111',
136
  'expirationMonth' => '11',
137
  'expirationYear' => '2099',
138
- 'options' => array(
139
  'validate' => false
140
- )
141
- )
142
- ));
143
 
144
- $result = Braintree_PaymentMethod::create(array(
145
  'customerId' => $customer->id,
146
  'paymentMethodNonce' => $nonce
147
- ));
148
 
149
  $this->assertSame('411111', $result->paymentMethod->bin);
150
  $this->assertSame('1111', $result->paymentMethod->last4);
 
151
  $this->assertNotNull($result->paymentMethod->token);
152
  }
153
 
154
- function testCreate_fromUnvalidatedFuturePaypalAccountNonce()
155
  {
156
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
157
- $customer = Braintree_Customer::createNoValidate();
158
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
159
- $nonce = $http->nonceForPayPalAccount(array(
160
- 'paypal_account' => array(
161
  'consent_code' => 'PAYPAL_CONSENT_CODE',
162
  'token' => $paymentMethodToken
163
- )
164
- ));
165
 
166
- $result = Braintree_PaymentMethod::create(array(
167
  'customerId' => $customer->id,
168
  'paymentMethodNonce' => $nonce
169
- ));
170
 
171
  $this->assertSame('jane.doe@example.com', $result->paymentMethod->email);
172
  $this->assertSame($paymentMethodToken, $result->paymentMethod->token);
 
173
  }
174
 
175
- function testCreate_fromAbstractPaymentMethodNonce()
176
  {
177
- $customer = Braintree_Customer::createNoValidate();
178
 
179
- $result = Braintree_PaymentMethod::create(array(
180
  'customerId' => $customer->id,
181
- 'paymentMethodNonce' => Braintree_Test_Nonces::$abstractTransactable
182
- ));
183
 
184
  $this->assertTrue($result->success);
185
  $this->assertNotNull($result->paymentMethod->token);
 
186
  }
187
 
188
- function testCreate_doesNotWorkForUnvalidatedOnetimePaypalAccountNonce()
189
  {
190
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
191
- $customer = Braintree_Customer::createNoValidate();
192
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
193
- $nonce = $http->nonceForPayPalAccount(array(
194
- 'paypal_account' => array(
195
  'access_token' => 'PAYPAL_ACCESS_TOKEN',
196
  'token' => $paymentMethodToken
197
- )
198
- ));
199
 
200
- $result = Braintree_PaymentMethod::create(array(
201
  'customerId' => $customer->id,
202
  'paymentMethodNonce' => $nonce
203
- ));
204
 
205
  $this->assertFalse($result->success);
206
  $errors = $result->errors->forKey('paypalAccount')->errors;
207
- $this->assertEquals(Braintree_Error_Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
208
  }
209
 
210
- function testCreate_handlesValidationErrorsForPayPalAccounts()
211
  {
212
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
213
- $customer = Braintree_Customer::createNoValidate();
214
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
215
- $nonce = $http->nonceForPayPalAccount(array(
216
- 'paypal_account' => array(
217
  'token' => $paymentMethodToken
218
- )
219
- ));
220
 
221
- $result = Braintree_PaymentMethod::create(array(
222
  'customerId' => $customer->id,
223
  'paymentMethodNonce' => $nonce
224
- ));
225
 
226
  $this->assertFalse($result->success);
227
  $errors = $result->errors->forKey('paypalAccount')->errors;
228
- $this->assertEquals(Braintree_Error_Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
229
- $this->assertEquals(Braintree_Error_Codes::PAYPAL_ACCOUNT_CONSENT_CODE_OR_ACCESS_TOKEN_IS_REQUIRED, $errors[1]->code);
230
  }
231
 
232
- function testCreate_allowsPassingDefaultOptionWithNonce()
233
  {
234
- $customer = Braintree_Customer::createNoValidate();
235
- $card1 = Braintree_CreditCard::create(array(
236
  'customerId' => $customer->id,
237
  'cardholderName' => 'Cardholder',
238
  'number' => '5105105105105100',
239
  'expirationDate' => '05/12'
240
- ))->creditCard;
241
 
242
  $this->assertTrue($card1->isDefault());
243
 
244
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
245
- $nonce = $http->nonce_for_new_card(array(
246
- 'credit_card' => array(
247
  'number' => '4111111111111111',
248
  'expirationMonth' => '11',
249
  'expirationYear' => '2099',
250
- 'options' => array(
251
  'validate' => false
252
- )
253
- )
254
- ));
255
 
256
- $result = Braintree_PaymentMethod::create(array(
257
  'customerId' => $customer->id,
258
  'paymentMethodNonce' => $nonce,
259
- 'options' => array(
260
  'makeDefault' => true
261
- )
262
- ));
263
 
264
  $card2 = $result->paymentMethod;
265
- $card1 = Braintree_CreditCard::find($card1->token);
266
  $this->assertFalse($card1->isDefault());
267
  $this->assertTrue($card2->isDefault());
268
  }
269
 
270
- function testCreate_overridesNonceToken()
271
  {
272
- $customer = Braintree_Customer::createNoValidate();
273
  $firstToken = 'FIRST_TOKEN-' . strval(rand());
274
  $secondToken = 'SECOND_TOKEN-' . strval(rand());
275
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
276
- $nonce = $http->nonce_for_new_card(array(
277
- 'credit_card' => array(
278
  'token' => $firstToken,
279
  'number' => '4111111111111111',
280
  'expirationMonth' => '11',
281
  'expirationYear' => '2099',
282
- 'options' => array(
283
  'validate' => false
284
- )
285
- )
286
- ));
287
 
288
- $result = Braintree_PaymentMethod::create(array(
289
  'customerId' => $customer->id,
290
  'paymentMethodNonce' => $nonce,
291
  'token' => $secondToken
292
- ));
293
 
294
  $card = $result->paymentMethod;
295
  $this->assertEquals($secondToken, $card->token);
296
  }
297
 
298
- function testCreate_respectsVerifyCardAndVerificationMerchantAccountIdWhenIncludedOutsideOfTheNonce()
299
  {
300
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
301
- $nonce = $http->nonce_for_new_card(array(
302
- 'credit_card' => array(
303
  'number' => '4000111111111115',
304
  'expirationMonth' => '11',
305
  'expirationYear' => '2099',
306
- )
307
- ));
308
- $customer = Braintree_Customer::createNoValidate();
309
- $result = Braintree_PaymentMethod::create(array(
310
  'paymentMethodNonce' => $nonce,
311
  'customerId' => $customer->id,
312
- 'options' => array(
313
  'verifyCard' => 'true',
314
- 'verificationMerchantAccountId' => Braintree_TestHelper::nonDefaultMerchantAccountId()
315
- )
316
- ));
317
 
318
  $this->assertFalse($result->success);
319
- $this->assertEquals(Braintree_Result_CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
320
  $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
321
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
322
- $this->assertEquals(Braintree_TestHelper::nonDefaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
323
  }
324
 
325
- function testCreate_respectsFailOnDuplicatePaymentMethodWhenIncludedOutsideTheNonce()
326
  {
327
- $customer = Braintree_Customer::createNoValidate();
328
- $result = Braintree_CreditCard::create(array(
329
  'customerId' => $customer->id,
330
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
331
  'expirationDate' => "05/2012"
332
- ));
333
  $this->assertTrue($result->success);
334
 
335
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
336
- $nonce = $http->nonce_for_new_card(array(
337
- 'credit_card' => array(
338
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
339
  'expirationDate' => "05/2012"
340
- )
341
- ));
342
- $updateResult = Braintree_PaymentMethod::create(array(
343
  'paymentMethodNonce' => $nonce,
344
  'customerId' => $customer->id,
345
- 'options' => array(
346
  'failOnDuplicatePaymentMethod' => 'true',
347
- )
348
- ));
349
 
350
  $this->assertFalse($updateResult->success);
351
  $resultErrors = $updateResult->errors->deepAll();
352
  $this->assertEquals("81724", $resultErrors[0]->code);
353
  }
354
 
355
- function testCreate_allowsPassingABillingAddressOutsideOfTheNonce()
356
  {
357
- $customer = Braintree_Customer::createNoValidate();
358
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
359
- $nonce = $http->nonce_for_new_card(array(
360
- 'credit_card' => array(
361
  'number' => '4111111111111111',
362
  'expirationMonth' => '12',
363
  'expirationYear' => '2020',
364
- 'options' => array(
365
  'validate' => false
366
- )
367
- )
368
- ));
369
 
370
- $result = Braintree_PaymentMethod::create(array(
371
  'paymentMethodNonce' => $nonce,
372
  'customerId' => $customer->id,
373
- 'billingAddress' => array(
374
  'streetAddress' => '123 Abc Way'
375
- )
376
- ));
377
 
378
  $this->assertTrue($result->success);
379
- $this->assertTrue(is_a($result->paymentMethod,'Braintree_CreditCard'));
380
  $token = $result->paymentMethod->token;
381
 
382
- $foundCreditCard = Braintree_CreditCard::find($token);
383
  $this->assertTrue(NULL != $foundCreditCard);
384
  $this->assertEquals('123 Abc Way', $foundCreditCard->billingAddress->streetAddress);
385
  }
386
 
387
- function testCreate_overridesTheBillingAddressInTheNonce()
388
  {
389
- $customer = Braintree_Customer::createNoValidate();
390
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
391
- $nonce = $http->nonce_for_new_card(array(
392
- 'credit_card' => array(
393
  'number' => '4111111111111111',
394
  'expirationMonth' => '12',
395
  'expirationYear' => '2020',
396
- 'options' => array(
397
  'validate' => false
398
- ),
399
- 'billingAddress' => array(
400
  'streetAddress' => '456 Xyz Way'
401
- )
402
- )
403
- ));
404
 
405
- $result = Braintree_PaymentMethod::create(array(
406
  'paymentMethodNonce' => $nonce,
407
  'customerId' => $customer->id,
408
- 'billingAddress' => array(
409
  'streetAddress' => '123 Abc Way'
410
- )
411
- ));
412
 
413
  $this->assertTrue($result->success);
414
- $this->assertTrue(is_a($result->paymentMethod,'Braintree_CreditCard'));
415
  $token = $result->paymentMethod->token;
416
 
417
- $foundCreditCard = Braintree_CreditCard::find($token);
418
  $this->assertTrue(NULL != $foundCreditCard);
419
  $this->assertEquals('123 Abc Way', $foundCreditCard->billingAddress->streetAddress);
420
  }
421
 
422
- function testCreate_doesNotOverrideTheBillingAddressForAVaultedCreditCard()
423
  {
424
- $customer = Braintree_Customer::createNoValidate();
425
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
426
- $nonce = $http->nonce_for_new_card(array(
427
  'customerId' => $customer->id,
428
- 'credit_card' => array(
429
  'number' => '4111111111111111',
430
  'expirationMonth' => '12',
431
  'expirationYear' => '2020',
432
- 'billingAddress' => array(
433
  'streetAddress' => '456 Xyz Way'
434
- )
435
- )
436
- ));
437
 
438
- $result = Braintree_PaymentMethod::create(array(
439
  'paymentMethodNonce' => $nonce,
440
  'customerId' => $customer->id,
441
- 'billingAddress' => array(
442
  'streetAddress' => '123 Abc Way'
443
- )
444
- ));
445
 
446
  $this->assertTrue($result->success);
447
- $this->assertTrue(is_a($result->paymentMethod,'Braintree_CreditCard'));
448
  $token = $result->paymentMethod->token;
449
 
450
- $foundCreditCard = Braintree_CreditCard::find($token);
451
  $this->assertTrue(NULL != $foundCreditCard);
452
  $this->assertEquals('456 Xyz Way', $foundCreditCard->billingAddress->streetAddress);
453
  }
454
 
455
- function testCreate_allowsPassingABillingAddressIdOutsideOfTheNonce()
456
  {
457
- $customer = Braintree_Customer::createNoValidate();
458
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
459
- $nonce = $http->nonce_for_new_card(array(
460
- 'credit_card' => array(
461
  'number' => '4111111111111111',
462
  'expirationMonth' => '12',
463
  'expirationYear' => '2020',
464
- 'options' => array(
465
  'validate' => false
466
- )
467
- )
468
- ));
469
 
470
- $address = Braintree_Address::create(array(
471
  'customerId' => $customer->id,
472
  'firstName' => 'Bobby',
473
  'lastName' => 'Tables'
474
- ))->address;
475
- $result = Braintree_PaymentMethod::create(array(
476
  'paymentMethodNonce' => $nonce,
477
  'customerId' => $customer->id,
478
  'billingAddressId' => $address->id
479
- ));
480
 
481
  $this->assertTrue($result->success);
482
- $this->assertTrue(is_a($result->paymentMethod,'Braintree_CreditCard'));
483
  $token = $result->paymentMethod->token;
484
 
485
- $foundCreditCard = Braintree_CreditCard::find($token);
486
  $this->assertTrue(NULL != $foundCreditCard);
487
  $this->assertEquals('Bobby', $foundCreditCard->billingAddress->firstName);
488
  $this->assertEquals('Tables', $foundCreditCard->billingAddress->lastName);
489
  }
490
 
491
- function testCreate_doesNotReturnAnErrorIfCreditCardOptionsArePresentForAPaypalNonce()
492
  {
493
- $customer = Braintree_Customer::createNoValidate();
494
  $originalToken = 'paypal-account-' . strval(rand());
495
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
496
- $nonce = $http->nonceForPaypalAccount(array(
497
- 'paypalAccount' => array(
498
  'consentCode' => 'consent-code',
499
  'token' => $originalToken
500
- )
501
- ));
502
 
503
- $result = Braintree_PaymentMethod::create(array(
504
  'paymentMethodNonce' => $nonce,
505
  'customerId' => $customer->id,
506
- 'options' => array(
507
  'verifyCard' => 'true',
508
  'failOnDuplicatePaymentMethod' => 'true',
509
  'verificationMerchantAccountId' => 'Not a Real Merchant Account Id'
510
- )
511
- ));
512
 
513
  $this->assertTrue($result->success);
514
  }
515
 
516
- function testCreate_ignoresPassedBillingAddressParamsForPaypalAccount()
517
  {
518
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
519
- $nonce = $http->nonceForPaypalAccount(array(
520
- 'paypalAccount' => array(
521
  'consentCode' => 'PAYPAL_CONSENT_CODE',
522
- )
523
- ));
524
- $customer = Braintree_Customer::createNoValidate();
525
- $result = Braintree_PaymentMethod::create(array(
526
  'paymentMethodNonce' => $nonce,
527
  'customerId' => $customer->id,
528
- 'billingAddress' => array(
529
  'streetAddress' => '123 Abc Way'
530
- )
531
- ));
532
 
533
  $this->assertTrue($result->success);
534
- $this->assertTrue(is_a($result->paymentMethod,'Braintree_PaypalAccount'));
535
  $token = $result->paymentMethod->token;
536
 
537
- $foundPaypalAccount = Braintree_PaypalAccount::find($token);
538
  $this->assertTrue(NULL != $foundPaypalAccount);
539
  }
540
 
541
- function testCreate_ignoresPassedBillingAddressIdForPaypalAccount()
542
  {
543
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
544
- $nonce = $http->nonceForPaypalAccount(array(
545
- 'paypalAccount' => array(
546
  'consentCode' => 'PAYPAL_CONSENT_CODE',
547
- )
548
- ));
549
- $customer = Braintree_Customer::createNoValidate();
550
- $result = Braintree_PaymentMethod::create(array(
551
  'paymentMethodNonce' => $nonce,
552
  'customerId' => $customer->id,
553
  'billingAddressId' => 'address_id'
554
- ));
555
 
556
  $this->assertTrue($result->success);
557
- $this->assertTrue(is_a($result->paymentMethod,'Braintree_PaypalAccount'));
558
  $token = $result->paymentMethod->token;
559
 
560
- $foundPaypalAccount = Braintree_PaypalAccount::find($token);
561
  $this->assertTrue(NULL != $foundPaypalAccount);
562
  }
563
 
564
- function testCreate_acceptsNumberAndOtherCreditCardParameters()
565
  {
566
- $customer = Braintree_Customer::createNoValidate();
567
- $result = Braintree_PaymentMethod::create(array(
568
  'customerId' => $customer->id,
569
- 'paymentMethodNonce' => Braintree_Test_Nonces::$transactable,
570
  'cardholderName' => 'Jane Doe',
571
  'cvv' => '123',
572
  'expirationMonth' => '10',
573
  'expirationYear' => '24',
574
  'number' => '4242424242424242'
575
- ));
576
 
577
  $this->assertTrue($result->success);
578
  $this->assertTrue('Jane Doe' == $result->paymentMethod->cardholderName);
@@ -582,19 +644,19 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
582
  $this->assertTrue('4242' == $result->paymentMethod->last4);
583
  }
584
 
585
- function testFind_returnsCreditCards()
586
  {
587
  $paymentMethodToken = 'CREDIT_CARD_TOKEN-' . strval(rand());
588
- $customer = Braintree_Customer::createNoValidate();
589
- $creditCardResult = Braintree_CreditCard::create(array(
590
  'customerId' => $customer->id,
591
  'number' => '5105105105105100',
592
  'expirationDate' => '05/2011',
593
  'token' => $paymentMethodToken
594
- ));
595
  $this->assertTrue($creditCardResult->success);
596
 
597
- $foundCreditCard = Braintree_PaymentMethod::find($creditCardResult->creditCard->token);
598
 
599
  $this->assertEquals($paymentMethodToken, $foundCreditCard->token);
600
  $this->assertEquals('510510', $foundCreditCard->bin);
@@ -602,186 +664,188 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
602
  $this->assertEquals('05/2011', $foundCreditCard->expirationDate);
603
  }
604
 
605
- function testFind_returnsCreditCardsWithSubscriptions()
606
  {
607
- $customer = Braintree_Customer::createNoValidate();
608
- $creditCardResult = Braintree_CreditCard::create(array(
609
  'customerId' => $customer->id,
610
  'number' => '5105105105105100',
611
  'expirationDate' => '05/2011',
612
- ));
613
  $this->assertTrue($creditCardResult->success);
614
 
615
  $subscriptionId = strval(rand());
616
- Braintree_Subscription::create(array(
617
  'id' => $subscriptionId,
618
  'paymentMethodToken' => $creditCardResult->creditCard->token,
619
  'planId' => 'integration_trialless_plan',
620
  'price' => '1.00'
621
- ));
622
 
623
- $foundCreditCard = Braintree_PaymentMethod::find($creditCardResult->creditCard->token);
624
  $this->assertEquals($subscriptionId, $foundCreditCard->subscriptions[0]->id);
625
  $this->assertEquals('integration_trialless_plan', $foundCreditCard->subscriptions[0]->planId);
626
  $this->assertEquals('1.00', $foundCreditCard->subscriptions[0]->price);
627
  }
628
 
629
- function testFind_returnsPayPalAccounts()
630
  {
631
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
632
- $customer = Braintree_Customer::createNoValidate();
633
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
634
- $nonce = $http->nonceForPayPalAccount(array(
635
- 'paypal_account' => array(
636
  'consent_code' => 'PAYPAL_CONSENT_CODE',
637
  'token' => $paymentMethodToken
638
- )
639
- ));
640
 
641
- Braintree_PaymentMethod::create(array(
642
  'customerId' => $customer->id,
643
  'paymentMethodNonce' => $nonce
644
- ));
645
 
646
- $foundPayPalAccount = Braintree_PaymentMethod::find($paymentMethodToken);
647
 
648
  $this->assertSame('jane.doe@example.com', $foundPayPalAccount->email);
649
  $this->assertSame($paymentMethodToken, $foundPayPalAccount->token);
650
  }
651
 
652
- function testFind_returnsApplePayCards()
653
  {
654
  $paymentMethodToken = 'APPLE_PAY-' . strval(rand());
655
- $customer = Braintree_Customer::createNoValidate();
656
- $nonce = Braintree_Test_Nonces::$applePayVisa;
657
- Braintree_PaymentMethod::create(array(
658
  'customerId' => $customer->id,
659
  'paymentMethodNonce' => $nonce,
660
  'token' => $paymentMethodToken
661
- ));
662
 
663
- $foundApplePayCard = Braintree_PaymentMethod::find($paymentMethodToken);
664
 
665
  $this->assertSame($paymentMethodToken, $foundApplePayCard->token);
666
- $this->assertInstanceOf('Braintree_ApplePayCard', $foundApplePayCard);
667
  $this->assertTrue(intval($foundApplePayCard->expirationMonth) > 0);
668
  $this->assertTrue(intval($foundApplePayCard->expirationYear) > 0);
669
  }
670
 
671
- function testFind_returnsAndroidPayCards()
672
  {
673
  $paymentMethodToken = 'ANDROID-PAY-' . strval(rand());
674
- $customer = Braintree_Customer::createNoValidate();
675
- $nonce = Braintree_Test_Nonces::$androidPay;
676
- Braintree_PaymentMethod::create(array(
677
  'customerId' => $customer->id,
678
  'paymentMethodNonce' => $nonce,
679
  'token' => $paymentMethodToken
680
- ));
681
 
682
- $foundAndroidPayCard = Braintree_PaymentMethod::find($paymentMethodToken);
683
 
684
  $this->assertSame($paymentMethodToken, $foundAndroidPayCard->token);
685
- $this->assertInstanceOf('Braintree_AndroidPayCard', $foundAndroidPayCard);
686
- $this->assertSame(Braintree_CreditCard::DISCOVER, $foundAndroidPayCard->virtualCardType);
687
  $this->assertSame("1117", $foundAndroidPayCard->virtualCardLast4);
688
- $this->assertSame(Braintree_CreditCard::VISA, $foundAndroidPayCard->sourceCardType);
689
  $this->assertSame("1111", $foundAndroidPayCard->sourceCardLast4);
 
690
  $this->assertTrue($foundAndroidPayCard->default);
691
  $this->assertContains('android_pay', $foundAndroidPayCard->imageUrl);
692
  $this->assertTrue(intval($foundAndroidPayCard->expirationMonth) > 0);
693
  $this->assertTrue(intval($foundAndroidPayCard->expirationYear) > 0);
694
  }
695
 
696
- function testFind_returnsCoinbaseAccounts()
697
  {
698
- $customer = Braintree_Customer::createNoValidate();
699
- $result = Braintree_PaymentMethod::create(array(
700
  'customerId' => $customer->id,
701
- 'paymentMethodNonce' => Braintree_Test_Nonces::$coinbase
702
- ));
703
 
704
  $this->assertTrue($result->success);
705
  $coinbaseAccount = $result->paymentMethod;
706
  $this->assertNotNull($coinbaseAccount->token);
707
- $foundCoinbaseAccount = Braintree_PaymentMethod::find($coinbaseAccount->token);
708
- $this->assertInstanceOf('Braintree_CoinbaseAccount', $foundCoinbaseAccount);
709
  $this->assertNotNull($foundCoinbaseAccount->userId);
710
  $this->assertNotNull($foundCoinbaseAccount->userName);
711
  $this->assertNotNull($foundCoinbaseAccount->userEmail);
 
712
  }
713
 
714
 
715
- function testFind_returnsAbstractPaymentMethods()
716
  {
717
  $paymentMethodToken = 'ABSTRACT-' . strval(rand());
718
- $customer = Braintree_Customer::createNoValidate();
719
- $nonce = Braintree_test_Nonces::$abstractTransactable;
720
- Braintree_PaymentMethod::create(array(
721
  'customerId' => $customer->id,
722
  'paymentMethodNonce' => $nonce,
723
  'token' => $paymentMethodToken
724
- ));
725
 
726
- $foundPaymentMethod = Braintree_PaymentMethod::find($paymentMethodToken);
727
 
728
  $this->assertSame($paymentMethodToken, $foundPaymentMethod-> token);
729
  }
730
 
731
- function testFind_throwsIfCannotBeFound()
732
  {
733
- $this->setExpectedException('Braintree_Exception_NotFound');
734
- Braintree_PaymentMethod::find('NON_EXISTENT_TOKEN');
735
  }
736
 
737
- function testUpdate_updatesTheCreditCard()
738
  {
739
- $customer = Braintree_Customer::createNoValidate();
740
- $creditCardResult = Braintree_CreditCard::create(array(
741
  'cardholderName' => 'Original Holder',
742
  'customerId' => $customer->id,
743
  'cvv' => '123',
744
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
745
  'expirationDate' => "05/2012"
746
- ));
747
  $this->assertTrue($creditCardResult->success);
748
  $creditCard = $creditCardResult->creditCard;
749
 
750
- $updateResult = Braintree_PaymentMethod::update($creditCard->token, array(
751
  'cardholderName' => 'New Holder',
752
  'cvv' => '456',
753
- 'number' => Braintree_Test_CreditCardNumbers::$masterCard,
754
  'expirationDate' => "06/2013"
755
- ));
756
 
757
  $this->assertTrue($updateResult->success);
758
  $this->assertSame($updateResult->paymentMethod->token, $creditCard->token);
759
  $updatedCreditCard = $updateResult->paymentMethod;
760
  $this->assertSame("New Holder", $updatedCreditCard->cardholderName);
761
- $this->assertSame(substr(Braintree_Test_CreditCardNumbers::$masterCard, 0, 6), $updatedCreditCard->bin);
762
- $this->assertSame(substr(Braintree_Test_CreditCardNumbers::$masterCard, -4), $updatedCreditCard->last4);
763
  $this->assertSame("06/2013", $updatedCreditCard->expirationDate);
764
  }
765
 
766
- function testUpdate_createsANewBillingAddressByDefault()
767
  {
768
- $customer = Braintree_Customer::createNoValidate();
769
- $creditCardResult = Braintree_CreditCard::create(array(
770
  'customerId' => $customer->id,
771
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
772
  'expirationDate' => "05/2012",
773
- 'billingAddress' => array(
774
  'streetAddress' => '123 Nigeria Ave'
775
- )
776
- ));
777
  $this->assertTrue($creditCardResult->success);
778
  $creditCard = $creditCardResult->creditCard;
779
 
780
- $updateResult = Braintree_PaymentMethod::update($creditCard->token, array(
781
- 'billingAddress' => array(
782
  'region' => 'IL'
783
- )
784
- ));
785
 
786
  $this->assertTrue($updateResult->success);
787
  $updatedCreditCard = $updateResult->paymentMethod;
@@ -790,28 +854,28 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
790
  $this->assertFalse($creditCard->billingAddress->id == $updatedCreditCard->billingAddress->id);
791
  }
792
 
793
- function testUpdate_updatesTheBillingAddressIfOptionIsSpecified()
794
  {
795
- $customer = Braintree_Customer::createNoValidate();
796
- $creditCardResult = Braintree_CreditCard::create(array(
797
  'customerId' => $customer->id,
798
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
799
  'expirationDate' => "05/2012",
800
- 'billingAddress' => array(
801
  'streetAddress' => '123 Nigeria Ave'
802
- )
803
- ));
804
  $this->assertTrue($creditCardResult->success);
805
  $creditCard = $creditCardResult->creditCard;
806
 
807
- $updateResult = Braintree_PaymentMethod::update($creditCard->token, array(
808
- 'billingAddress' => array(
809
  'region' => 'IL',
810
- 'options' => array(
811
  'updateExisting' => 'true'
812
- )
813
- ),
814
- ));
815
 
816
  $this->assertTrue($updateResult->success);
817
  $updatedCreditCard = $updateResult->paymentMethod;
@@ -820,31 +884,31 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
820
  $this->assertTrue($creditCard->billingAddress->id == $updatedCreditCard->billingAddress->id);
821
  }
822
 
823
- function testUpdate_updatesTheCountryViaCodes()
824
  {
825
- $customer = Braintree_Customer::createNoValidate();
826
- $creditCardResult = Braintree_CreditCard::create(array(
827
  'customerId' => $customer->id,
828
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
829
  'expirationDate' => "05/2012",
830
- 'billingAddress' => array(
831
  'streetAddress' => '123 Nigeria Ave'
832
- )
833
- ));
834
  $this->assertTrue($creditCardResult->success);
835
  $creditCard = $creditCardResult->creditCard;
836
 
837
- $updateResult = Braintree_PaymentMethod::update($creditCard->token, array(
838
- 'billingAddress' => array(
839
  'countryName' => 'American Samoa',
840
  'countryCodeAlpha2' => 'AS',
841
  'countryCodeAlpha3' => 'ASM',
842
  'countryCodeNumeric' => '016',
843
- 'options' => array(
844
  'updateExisting' => 'true'
845
- )
846
- ),
847
- ));
848
 
849
  $this->assertTrue($updateResult->success);
850
  $updatedCreditCard = $updateResult->paymentMethod;
@@ -854,22 +918,22 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
854
  $this->assertSame("016", $updatedCreditCard->billingAddress->countryCodeNumeric);
855
  }
856
 
857
- function testUpdate_canPassExpirationMonthAndExpirationYear()
858
  {
859
- $customer = Braintree_Customer::createNoValidate();
860
- $creditCardResult = Braintree_CreditCard::create(array(
861
  'customerId' => $customer->id,
862
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
863
  'expirationDate' => "05/2012"
864
- ));
865
  $this->assertTrue($creditCardResult->success);
866
  $creditCard = $creditCardResult->creditCard;
867
 
868
- $updateResult = Braintree_PaymentMethod::update($creditCard->token, array(
869
- 'number' => Braintree_Test_CreditCardNumbers::$masterCard,
870
  'expirationMonth' => "07",
871
  'expirationYear' => "2011"
872
- ));
873
 
874
  $this->assertTrue($updateResult->success);
875
  $this->assertSame($updateResult->paymentMethod->token, $creditCard->token);
@@ -879,44 +943,44 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
879
  $this->assertSame("07/2011", $updatedCreditCard->expirationDate);
880
  }
881
 
882
- function testUpdate_verifiesTheUpdateIfOptionsVerifyCardIsTrue()
883
  {
884
- $customer = Braintree_Customer::createNoValidate();
885
- $creditCardResult = Braintree_CreditCard::create(array(
886
  'cardholderName' => 'Original Holder',
887
  'customerId' => $customer->id,
888
  'cvv' => '123',
889
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
890
  'expirationDate' => "05/2012"
891
- ));
892
  $this->assertTrue($creditCardResult->success);
893
  $creditCard = $creditCardResult->creditCard;
894
 
895
- $updateResult = Braintree_PaymentMethod::update($creditCard->token, array(
896
  'cardholderName' => 'New Holder',
897
  'cvv' => '456',
898
- 'number' => Braintree_Test_CreditCardNumbers::$failsSandboxVerification['MasterCard'],
899
  'expirationDate' => "06/2013",
900
- 'options' => array(
901
  'verifyCard' => 'true'
902
- )
903
- ));
904
 
905
  $this->assertFalse($updateResult->success);
906
- $this->assertEquals(Braintree_Result_CreditCardVerification::PROCESSOR_DECLINED, $updateResult->creditCardVerification->status);
907
  $this->assertEquals(NULL, $updateResult->creditCardVerification->gatewayRejectionReason);
908
  }
909
 
910
- function testUpdate_canUpdateTheBillingAddress()
911
  {
912
- $customer = Braintree_Customer::createNoValidate();
913
- $creditCardResult = Braintree_CreditCard::create(array(
914
  'cardholderName' => 'Original Holder',
915
  'customerId' => $customer->id,
916
  'cvv' => '123',
917
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
918
  'expirationDate' => '05/2012',
919
- 'billingAddress' => array(
920
  'firstName' => 'Old First Name',
921
  'lastName' => 'Old Last Name',
922
  'company' => 'Old Company',
@@ -926,13 +990,13 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
926
  'region' => 'Old State',
927
  'postalCode' => '12345',
928
  'countryName' => 'Canada'
929
- )
930
- ));
931
  $this->assertTrue($creditCardResult->success);
932
  $creditCard = $creditCardResult->creditCard;
933
 
934
- $updateResult = Braintree_PaymentMethod::update($creditCard->token, array(
935
- 'billingAddress' => array(
936
  'firstName' => 'New First Name',
937
  'lastName' => 'New Last Name',
938
  'company' => 'New Company',
@@ -942,8 +1006,8 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
942
  'region' => 'New State',
943
  'postalCode' => '56789',
944
  'countryName' => 'United States of America'
945
- )
946
- ));
947
 
948
  $this->assertTrue($updateResult->success);
949
  $address = $updateResult->paymentMethod->billingAddress;
@@ -958,46 +1022,46 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
958
  $this->assertSame('United States of America', $address->countryName);
959
  }
960
 
961
- function testUpdate_returnsAnErrorIfInvalid()
962
  {
963
- $customer = Braintree_Customer::createNoValidate();
964
- $creditCardResult = Braintree_CreditCard::create(array(
965
  'cardholderName' => 'Original Holder',
966
  'customerId' => $customer->id,
967
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
968
  'expirationDate' => "05/2012"
969
- ));
970
  $this->assertTrue($creditCardResult->success);
971
  $creditCard = $creditCardResult->creditCard;
972
 
973
- $updateResult = Braintree_PaymentMethod::update($creditCard->token, array(
974
  'cardholderName' => 'New Holder',
975
  'number' => 'invalid',
976
  'expirationDate' => "05/2014",
977
- ));
978
 
979
  $this->assertFalse($updateResult->success);
980
  $numberErrors = $updateResult->errors->forKey('creditCard')->onAttribute('number');
981
  $this->assertEquals("Credit card number must be 12-19 digits.", $numberErrors[0]->message);
982
  }
983
 
984
- function testUpdate_canUpdateTheDefault()
985
  {
986
- $customer = Braintree_Customer::createNoValidate();
987
 
988
- $creditCardResult1 = Braintree_CreditCard::create(array(
989
  'customerId' => $customer->id,
990
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
991
  'expirationDate' => "05/2009"
992
- ));
993
  $this->assertTrue($creditCardResult1->success);
994
  $creditCard1 = $creditCardResult1->creditCard;
995
 
996
- $creditCardResult2 = Braintree_CreditCard::create(array(
997
  'customerId' => $customer->id,
998
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
999
  'expirationDate' => "05/2009"
1000
- ));
1001
  $this->assertTrue($creditCardResult2->success);
1002
  $creditCard2 = $creditCardResult2->creditCard;
1003
 
@@ -1005,128 +1069,128 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
1005
  $this->assertFalse($creditCard2->default);
1006
 
1007
 
1008
- $updateResult = Braintree_PaymentMethod::update($creditCard2->token, array(
1009
- 'options' => array(
1010
  'makeDefault' => 'true'
1011
- )
1012
- ));
1013
  $this->assertTrue($updateResult->success);
1014
 
1015
- $this->assertFalse(Braintree_PaymentMethod::find($creditCard1->token)->default);
1016
- $this->assertTrue(Braintree_PaymentMethod::find($creditCard2->token)->default);
1017
  }
1018
 
1019
- function testUpdate_updatesAPaypalAccountsToken()
1020
  {
1021
- $customer = Braintree_Customer::createNoValidate();
1022
  $originalToken = 'paypal-account-' . strval(rand());
1023
- $customer = Braintree_Customer::createNoValidate();
1024
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
1025
- $nonce = $http->nonceForPayPalAccount(array(
1026
- 'paypal_account' => array(
1027
  'consent_code' => 'consent-code',
1028
  'token' => $originalToken
1029
- )
1030
- ));
1031
 
1032
- $originalResult = Braintree_PaymentMethod::create(array(
1033
  'paymentMethodNonce' => $nonce,
1034
  'customerId' => $customer->id
1035
- ));
1036
  $this->assertTrue($originalResult->success);
1037
 
1038
  $originalPaypalAccount = $originalResult->paymentMethod;
1039
 
1040
  $updatedToken = 'UPDATED_TOKEN-' . strval(rand());
1041
- $updateResult = Braintree_PaymentMethod::update($originalPaypalAccount->token, array(
1042
  'token' => $updatedToken
1043
- ));
1044
  $this->assertTrue($updateResult->success);
1045
 
1046
- $updatedPaypalAccount = Braintree_PaymentMethod::find($updatedToken);
1047
  $this->assertEquals($originalPaypalAccount->email, $updatedPaypalAccount->email);
1048
 
1049
- $this->setExpectedException('Braintree_Exception_NotFound', 'payment method with token ' . $originalToken . ' not found');
1050
- Braintree_PaymentMethod::find($originalToken);
1051
 
1052
  }
1053
 
1054
- function testUpdate_canMakeAPaypalAccountTheDefaultPaymentMethod()
1055
  {
1056
- $customer = Braintree_Customer::createNoValidate();
1057
- $creditCardResult = Braintree_CreditCard::create(array(
1058
  'customerId' => $customer->id,
1059
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
1060
- 'expirationDate' => "05/2009",
1061
- 'options' => array(
1062
  'makeDefault' => 'true'
1063
- )
1064
- ));
1065
  $this->assertTrue($creditCardResult->success);
1066
  $creditCard = $creditCardResult->creditCard;
1067
 
1068
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
1069
- $nonce = $http->nonceForPayPalAccount(array(
1070
- 'paypal_account' => array(
1071
  'consent_code' => 'consent-code',
1072
- )
1073
- ));
1074
 
1075
- $originalToken = Braintree_PaymentMethod::create(array(
1076
  'paymentMethodNonce' => $nonce,
1077
  'customerId' => $customer->id
1078
- ))->paymentMethod->token;
1079
 
1080
- $updateResult = Braintree_PaymentMethod::update($originalToken, array(
1081
- 'options' => array(
1082
  'makeDefault' => 'true'
1083
- )
1084
- ));
1085
  $this->assertTrue($updateResult->success);
1086
 
1087
- $updatedPaypalAccount = Braintree_PaymentMethod::find($originalToken);
1088
  $this->assertTrue($updatedPaypalAccount->default);
1089
 
1090
  }
1091
 
1092
- function testUpdate_returnsAnErrorIfATokenForAccountIsUsedToAttemptAnUpdate()
1093
  {
1094
- $customer = Braintree_Customer::createNoValidate();
1095
  $firstToken = 'paypal-account-' . strval(rand());
1096
  $secondToken = 'paypal-account-' . strval(rand());
1097
 
1098
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
1099
- $firstNonce = $http->nonceForPayPalAccount(array(
1100
- 'paypal_account' => array(
1101
  'consent_code' => 'consent-code',
1102
  'token' => $firstToken
1103
- )
1104
- ));
1105
- $firstResult = Braintree_PaymentMethod::create(array(
1106
  'paymentMethodNonce' => $firstNonce,
1107
  'customerId' => $customer->id
1108
- ));
1109
  $this->assertTrue($firstResult->success);
1110
  $firstPaypalAccount = $firstResult->paymentMethod;
1111
 
1112
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
1113
- $secondNonce = $http->nonceForPayPalAccount(array(
1114
- 'paypal_account' => array(
1115
  'consent_code' => 'consent-code',
1116
  'token' => $secondToken
1117
- )
1118
- ));
1119
- $secondResult = Braintree_PaymentMethod::create(array(
1120
  'paymentMethodNonce' => $secondNonce,
1121
  'customerId' => $customer->id
1122
- ));
1123
  $this->assertTrue($secondResult->success);
1124
  $secondPaypalAccount = $firstResult->paymentMethod;
1125
 
1126
 
1127
- $updateResult = Braintree_PaymentMethod::update($firstToken, array(
1128
  'token' => $secondToken
1129
- ));
1130
 
1131
  $this->assertFalse($updateResult->success);
1132
  $resultErrors = $updateResult->errors->deepAll();
@@ -1134,47 +1198,299 @@ class Braintree_PaymentMethodTest extends PHPUnit_Framework_TestCase
1134
 
1135
  }
1136
 
1137
- function testDelete_worksWithCreditCards()
1138
  {
1139
  $paymentMethodToken = 'CREDIT_CARD_TOKEN-' . strval(rand());
1140
- $customer = Braintree_Customer::createNoValidate();
1141
- $creditCardResult = Braintree_CreditCard::create(array(
1142
  'customerId' => $customer->id,
1143
  'number' => '5105105105105100',
1144
  'expirationDate' => '05/2011',
1145
  'token' => $paymentMethodToken
1146
- ));
1147
  $this->assertTrue($creditCardResult->success);
1148
 
1149
- Braintree_PaymentMethod::delete($paymentMethodToken);
1150
 
1151
- $this->setExpectedException('Braintree_Exception_NotFound');
1152
- Braintree_PaymentMethod::find($paymentMethodToken);
1153
- integrationMerchantConfig();
1154
  }
1155
 
1156
- function testDelete_worksWithPayPalAccounts()
1157
  {
1158
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
1159
- $customer = Braintree_Customer::createNoValidate();
1160
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
1161
- $nonce = $http->nonceForPayPalAccount(array(
1162
- 'paypal_account' => array(
1163
  'consent_code' => 'PAYPAL_CONSENT_CODE',
1164
  'token' => $paymentMethodToken
1165
- )
1166
- ));
1167
 
1168
- $paypalAccountResult = Braintree_PaymentMethod::create(array(
1169
  'customerId' => $customer->id,
1170
  'paymentMethodNonce' => $nonce
1171
- ));
1172
  $this->assertTrue($paypalAccountResult->success);
1173
 
1174
- Braintree_PaymentMethod::delete($paymentMethodToken);
1175
 
1176
- $this->setExpectedException('Braintree_Exception_NotFound');
1177
- Braintree_PaymentMethod::find($paymentMethodToken);
1178
  }
1179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1180
  }
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_fromAbstractPaymentMethodNonce()
237
  {
238
+ $customer = Braintree\Customer::createNoValidate();
239
 
240
+ $result = Braintree\PaymentMethod::create([
241
  'customerId' => $customer->id,
242
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$abstractTransactable,
243
+ ]);
244
 
245
  $this->assertTrue($result->success);
246
  $this->assertNotNull($result->paymentMethod->token);
247
+ $this->assertSame($customer->id, $result->paymentMethod->customerId);
248
  }
249
 
250
+ public function testCreate_doesNotWorkForUnvalidatedOnetimePaypalAccountNonce()
251
  {
252
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
253
+ $customer = Braintree\Customer::createNoValidate();
254
+ $http = new HttpClientApi(Braintree\Configuration::$global);
255
+ $nonce = $http->nonceForPayPalAccount([
256
+ 'paypal_account' => [
257
  'access_token' => 'PAYPAL_ACCESS_TOKEN',
258
  'token' => $paymentMethodToken
259
+ ]
260
+ ]);
261
 
262
+ $result = Braintree\PaymentMethod::create([
263
  'customerId' => $customer->id,
264
  'paymentMethodNonce' => $nonce
265
+ ]);
266
 
267
  $this->assertFalse($result->success);
268
  $errors = $result->errors->forKey('paypalAccount')->errors;
269
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
270
  }
271
 
272
+ public function testCreate_handlesValidationErrorsForPayPalAccounts()
273
  {
274
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
275
+ $customer = Braintree\Customer::createNoValidate();
276
+ $http = new HttpClientApi(Braintree\Configuration::$global);
277
+ $nonce = $http->nonceForPayPalAccount([
278
+ 'paypal_account' => [
279
  'token' => $paymentMethodToken
280
+ ]
281
+ ]);
282
 
283
+ $result = Braintree\PaymentMethod::create([
284
  'customerId' => $customer->id,
285
  'paymentMethodNonce' => $nonce
286
+ ]);
287
 
288
  $this->assertFalse($result->success);
289
  $errors = $result->errors->forKey('paypalAccount')->errors;
290
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
291
+ $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CONSENT_CODE_OR_ACCESS_TOKEN_IS_REQUIRED, $errors[1]->code);
292
  }
293
 
294
+ public function testCreate_allowsPassingDefaultOptionWithNonce()
295
  {
296
+ $customer = Braintree\Customer::createNoValidate();
297
+ $card1 = Braintree\CreditCard::create([
298
  'customerId' => $customer->id,
299
  'cardholderName' => 'Cardholder',
300
  'number' => '5105105105105100',
301
  'expirationDate' => '05/12'
302
+ ])->creditCard;
303
 
304
  $this->assertTrue($card1->isDefault());
305
 
306
+ $http = new HttpClientApi(Braintree\Configuration::$global);
307
+ $nonce = $http->nonce_for_new_card([
308
+ 'credit_card' => [
309
  'number' => '4111111111111111',
310
  'expirationMonth' => '11',
311
  'expirationYear' => '2099',
312
+ 'options' => [
313
  'validate' => false
314
+ ]
315
+ ]
316
+ ]);
317
 
318
+ $result = Braintree\PaymentMethod::create([
319
  'customerId' => $customer->id,
320
  'paymentMethodNonce' => $nonce,
321
+ 'options' => [
322
  'makeDefault' => true
323
+ ]
324
+ ]);
325
 
326
  $card2 = $result->paymentMethod;
327
+ $card1 = Braintree\CreditCard::find($card1->token);
328
  $this->assertFalse($card1->isDefault());
329
  $this->assertTrue($card2->isDefault());
330
  }
331
 
332
+ public function testCreate_overridesNonceToken()
333
  {
334
+ $customer = Braintree\Customer::createNoValidate();
335
  $firstToken = 'FIRST_TOKEN-' . strval(rand());
336
  $secondToken = 'SECOND_TOKEN-' . strval(rand());
337
+ $http = new HttpClientApi(Braintree\Configuration::$global);
338
+ $nonce = $http->nonce_for_new_card([
339
+ 'credit_card' => [
340
  'token' => $firstToken,
341
  'number' => '4111111111111111',
342
  'expirationMonth' => '11',
343
  'expirationYear' => '2099',
344
+ 'options' => [
345
  'validate' => false
346
+ ]
347
+ ]
348
+ ]);
349
 
350
+ $result = Braintree\PaymentMethod::create([
351
  'customerId' => $customer->id,
352
  'paymentMethodNonce' => $nonce,
353
  'token' => $secondToken
354
+ ]);
355
 
356
  $card = $result->paymentMethod;
357
  $this->assertEquals($secondToken, $card->token);
358
  }
359
 
360
+ public function testCreate_respectsVerifyCardAndVerificationMerchantAccountIdWhenIncludedOutsideOfTheNonce()
361
  {
362
+ $http = new HttpClientApi(Braintree\Configuration::$global);
363
+ $nonce = $http->nonce_for_new_card([
364
+ 'credit_card' => [
365
  'number' => '4000111111111115',
366
  'expirationMonth' => '11',
367
  'expirationYear' => '2099',
368
+ ]
369
+ ]);
370
+ $customer = Braintree\Customer::createNoValidate();
371
+ $result = Braintree\PaymentMethod::create([
372
  'paymentMethodNonce' => $nonce,
373
  'customerId' => $customer->id,
374
+ 'options' => [
375
  'verifyCard' => 'true',
376
+ 'verificationMerchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(),
377
+ ]
378
+ ]);
379
 
380
  $this->assertFalse($result->success);
381
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
382
  $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
383
  $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
384
+ $this->assertEquals(Test\Helper::nonDefaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
385
  }
386
 
387
+ public function testCreate_respectsFailOnDuplicatePaymentMethodWhenIncludedOutsideTheNonce()
388
  {
389
+ $customer = Braintree\Customer::createNoValidate();
390
+ $result = Braintree\CreditCard::create([
391
  'customerId' => $customer->id,
392
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
393
  'expirationDate' => "05/2012"
394
+ ]);
395
  $this->assertTrue($result->success);
396
 
397
+ $http = new HttpClientApi(Braintree\Configuration::$global);
398
+ $nonce = $http->nonce_for_new_card([
399
+ 'credit_card' => [
400
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
401
  'expirationDate' => "05/2012"
402
+ ]
403
+ ]);
404
+ $updateResult = Braintree\PaymentMethod::create([
405
  'paymentMethodNonce' => $nonce,
406
  'customerId' => $customer->id,
407
+ 'options' => [
408
  'failOnDuplicatePaymentMethod' => 'true',
409
+ ]
410
+ ]);
411
 
412
  $this->assertFalse($updateResult->success);
413
  $resultErrors = $updateResult->errors->deepAll();
414
  $this->assertEquals("81724", $resultErrors[0]->code);
415
  }
416
 
417
+ public function testCreate_allowsPassingABillingAddressOutsideOfTheNonce()
418
  {
419
+ $customer = Braintree\Customer::createNoValidate();
420
+ $http = new HttpClientApi(Braintree\Configuration::$global);
421
+ $nonce = $http->nonce_for_new_card([
422
+ 'credit_card' => [
423
  'number' => '4111111111111111',
424
  'expirationMonth' => '12',
425
  'expirationYear' => '2020',
426
+ 'options' => [
427
  'validate' => false
428
+ ]
429
+ ]
430
+ ]);
431
 
432
+ $result = Braintree\PaymentMethod::create([
433
  'paymentMethodNonce' => $nonce,
434
  'customerId' => $customer->id,
435
+ 'billingAddress' => [
436
  'streetAddress' => '123 Abc Way'
437
+ ]
438
+ ]);
439
 
440
  $this->assertTrue($result->success);
441
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
442
  $token = $result->paymentMethod->token;
443
 
444
+ $foundCreditCard = Braintree\CreditCard::find($token);
445
  $this->assertTrue(NULL != $foundCreditCard);
446
  $this->assertEquals('123 Abc Way', $foundCreditCard->billingAddress->streetAddress);
447
  }
448
 
449
+ public function testCreate_overridesTheBillingAddressInTheNonce()
450
  {
451
+ $customer = Braintree\Customer::createNoValidate();
452
+ $http = new HttpClientApi(Braintree\Configuration::$global);
453
+ $nonce = $http->nonce_for_new_card([
454
+ 'credit_card' => [
455
  'number' => '4111111111111111',
456
  'expirationMonth' => '12',
457
  'expirationYear' => '2020',
458
+ 'options' => [
459
  'validate' => false
460
+ ],
461
+ 'billingAddress' => [
462
  'streetAddress' => '456 Xyz Way'
463
+ ]
464
+ ]
465
+ ]);
466
 
467
+ $result = Braintree\PaymentMethod::create([
468
  'paymentMethodNonce' => $nonce,
469
  'customerId' => $customer->id,
470
+ 'billingAddress' => [
471
  'streetAddress' => '123 Abc Way'
472
+ ]
473
+ ]);
474
 
475
  $this->assertTrue($result->success);
476
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
477
  $token = $result->paymentMethod->token;
478
 
479
+ $foundCreditCard = Braintree\CreditCard::find($token);
480
  $this->assertTrue(NULL != $foundCreditCard);
481
  $this->assertEquals('123 Abc Way', $foundCreditCard->billingAddress->streetAddress);
482
  }
483
 
484
+ public function testCreate_doesNotOverrideTheBillingAddressForAVaultedCreditCard()
485
  {
486
+ $customer = Braintree\Customer::createNoValidate();
487
+ $http = new HttpClientApi(Braintree\Configuration::$global);
488
+ $nonce = $http->nonce_for_new_card([
489
  'customerId' => $customer->id,
490
+ 'credit_card' => [
491
  'number' => '4111111111111111',
492
  'expirationMonth' => '12',
493
  'expirationYear' => '2020',
494
+ 'billingAddress' => [
495
  'streetAddress' => '456 Xyz Way'
496
+ ]
497
+ ]
498
+ ]);
499
 
500
+ $result = Braintree\PaymentMethod::create([
501
  'paymentMethodNonce' => $nonce,
502
  'customerId' => $customer->id,
503
+ 'billingAddress' => [
504
  'streetAddress' => '123 Abc Way'
505
+ ]
506
+ ]);
507
 
508
  $this->assertTrue($result->success);
509
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
510
  $token = $result->paymentMethod->token;
511
 
512
+ $foundCreditCard = Braintree\CreditCard::find($token);
513
  $this->assertTrue(NULL != $foundCreditCard);
514
  $this->assertEquals('456 Xyz Way', $foundCreditCard->billingAddress->streetAddress);
515
  }
516
 
517
+ public function testCreate_allowsPassingABillingAddressIdOutsideOfTheNonce()
518
  {
519
+ $customer = Braintree\Customer::createNoValidate();
520
+ $http = new HttpClientApi(Braintree\Configuration::$global);
521
+ $nonce = $http->nonce_for_new_card([
522
+ 'credit_card' => [
523
  'number' => '4111111111111111',
524
  'expirationMonth' => '12',
525
  'expirationYear' => '2020',
526
+ 'options' => [
527
  'validate' => false
528
+ ]
529
+ ]
530
+ ]);
531
 
532
+ $address = Braintree\Address::create([
533
  'customerId' => $customer->id,
534
  'firstName' => 'Bobby',
535
  'lastName' => 'Tables'
536
+ ])->address;
537
+ $result = Braintree\PaymentMethod::create([
538
  'paymentMethodNonce' => $nonce,
539
  'customerId' => $customer->id,
540
  'billingAddressId' => $address->id
541
+ ]);
542
 
543
  $this->assertTrue($result->success);
544
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
545
  $token = $result->paymentMethod->token;
546
 
547
+ $foundCreditCard = Braintree\CreditCard::find($token);
548
  $this->assertTrue(NULL != $foundCreditCard);
549
  $this->assertEquals('Bobby', $foundCreditCard->billingAddress->firstName);
550
  $this->assertEquals('Tables', $foundCreditCard->billingAddress->lastName);
551
  }
552
 
553
+ public function testCreate_doesNotReturnAnErrorIfCreditCardOptionsArePresentForAPaypalNonce()
554
  {
555
+ $customer = Braintree\Customer::createNoValidate();
556
  $originalToken = 'paypal-account-' . strval(rand());
557
+ $http = new HttpClientApi(Braintree\Configuration::$global);
558
+ $nonce = $http->nonceForPaypalAccount([
559
+ 'paypalAccount' => [
560
  'consentCode' => 'consent-code',
561
  'token' => $originalToken
562
+ ]
563
+ ]);
564
 
565
+ $result = Braintree\PaymentMethod::create([
566
  'paymentMethodNonce' => $nonce,
567
  'customerId' => $customer->id,
568
+ 'options' => [
569
  'verifyCard' => 'true',
570
  'failOnDuplicatePaymentMethod' => 'true',
571
  'verificationMerchantAccountId' => 'Not a Real Merchant Account Id'
572
+ ]
573
+ ]);
574
 
575
  $this->assertTrue($result->success);
576
  }
577
 
578
+ public function testCreate_ignoresPassedBillingAddressParamsForPaypalAccount()
579
  {
580
+ $http = new HttpClientApi(Braintree\Configuration::$global);
581
+ $nonce = $http->nonceForPaypalAccount([
582
+ 'paypalAccount' => [
583
  'consentCode' => 'PAYPAL_CONSENT_CODE',
584
+ ]
585
+ ]);
586
+ $customer = Braintree\Customer::createNoValidate();
587
+ $result = Braintree\PaymentMethod::create([
588
  'paymentMethodNonce' => $nonce,
589
  'customerId' => $customer->id,
590
+ 'billingAddress' => [
591
  'streetAddress' => '123 Abc Way'
592
+ ]
593
+ ]);
594
 
595
  $this->assertTrue($result->success);
596
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\PaypalAccount'));
597
  $token = $result->paymentMethod->token;
598
 
599
+ $foundPaypalAccount = Braintree\PaypalAccount::find($token);
600
  $this->assertTrue(NULL != $foundPaypalAccount);
601
  }
602
 
603
+ public function testCreate_ignoresPassedBillingAddressIdForPaypalAccount()
604
  {
605
+ $http = new HttpClientApi(Braintree\Configuration::$global);
606
+ $nonce = $http->nonceForPaypalAccount([
607
+ 'paypalAccount' => [
608
  'consentCode' => 'PAYPAL_CONSENT_CODE',
609
+ ]
610
+ ]);
611
+ $customer = Braintree\Customer::createNoValidate();
612
+ $result = Braintree\PaymentMethod::create([
613
  'paymentMethodNonce' => $nonce,
614
  'customerId' => $customer->id,
615
  'billingAddressId' => 'address_id'
616
+ ]);
617
 
618
  $this->assertTrue($result->success);
619
+ $this->assertTrue(is_a($result->paymentMethod, 'Braintree\PaypalAccount'));
620
  $token = $result->paymentMethod->token;
621
 
622
+ $foundPaypalAccount = Braintree\PaypalAccount::find($token);
623
  $this->assertTrue(NULL != $foundPaypalAccount);
624
  }
625
 
626
+ public function testCreate_acceptsNumberAndOtherCreditCardParameters()
627
  {
628
+ $customer = Braintree\Customer::createNoValidate();
629
+ $result = Braintree\PaymentMethod::create([
630
  'customerId' => $customer->id,
631
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$transactable,
632
  'cardholderName' => 'Jane Doe',
633
  'cvv' => '123',
634
  'expirationMonth' => '10',
635
  'expirationYear' => '24',
636
  'number' => '4242424242424242'
637
+ ]);
638
 
639
  $this->assertTrue($result->success);
640
  $this->assertTrue('Jane Doe' == $result->paymentMethod->cardholderName);
644
  $this->assertTrue('4242' == $result->paymentMethod->last4);
645
  }
646
 
647
+ public function testFind_returnsCreditCards()
648
  {
649
  $paymentMethodToken = 'CREDIT_CARD_TOKEN-' . strval(rand());
650
+ $customer = Braintree\Customer::createNoValidate();
651
+ $creditCardResult = Braintree\CreditCard::create([
652
  'customerId' => $customer->id,
653
  'number' => '5105105105105100',
654
  'expirationDate' => '05/2011',
655
  'token' => $paymentMethodToken
656
+ ]);
657
  $this->assertTrue($creditCardResult->success);
658
 
659
+ $foundCreditCard = Braintree\PaymentMethod::find($creditCardResult->creditCard->token);
660
 
661
  $this->assertEquals($paymentMethodToken, $foundCreditCard->token);
662
  $this->assertEquals('510510', $foundCreditCard->bin);
664
  $this->assertEquals('05/2011', $foundCreditCard->expirationDate);
665
  }
666
 
667
+ public function testFind_returnsCreditCardsWithSubscriptions()
668
  {
669
+ $customer = Braintree\Customer::createNoValidate();
670
+ $creditCardResult = Braintree\CreditCard::create([
671
  'customerId' => $customer->id,
672
  'number' => '5105105105105100',
673
  'expirationDate' => '05/2011',
674
+ ]);
675
  $this->assertTrue($creditCardResult->success);
676
 
677
  $subscriptionId = strval(rand());
678
+ Braintree\Subscription::create([
679
  'id' => $subscriptionId,
680
  'paymentMethodToken' => $creditCardResult->creditCard->token,
681
  'planId' => 'integration_trialless_plan',
682
  'price' => '1.00'
683
+ ]);
684
 
685
+ $foundCreditCard = Braintree\PaymentMethod::find($creditCardResult->creditCard->token);
686
  $this->assertEquals($subscriptionId, $foundCreditCard->subscriptions[0]->id);
687
  $this->assertEquals('integration_trialless_plan', $foundCreditCard->subscriptions[0]->planId);
688
  $this->assertEquals('1.00', $foundCreditCard->subscriptions[0]->price);
689
  }
690
 
691
+ public function testFind_returnsPayPalAccounts()
692
  {
693
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
694
+ $customer = Braintree\Customer::createNoValidate();
695
+ $http = new HttpClientApi(Braintree\Configuration::$global);
696
+ $nonce = $http->nonceForPayPalAccount([
697
+ 'paypal_account' => [
698
  'consent_code' => 'PAYPAL_CONSENT_CODE',
699
  'token' => $paymentMethodToken
700
+ ]
701
+ ]);
702
 
703
+ Braintree\PaymentMethod::create([
704
  'customerId' => $customer->id,
705
  'paymentMethodNonce' => $nonce
706
+ ]);
707
 
708
+ $foundPayPalAccount = Braintree\PaymentMethod::find($paymentMethodToken);
709
 
710
  $this->assertSame('jane.doe@example.com', $foundPayPalAccount->email);
711
  $this->assertSame($paymentMethodToken, $foundPayPalAccount->token);
712
  }
713
 
714
+ public function testFind_returnsApplePayCards()
715
  {
716
  $paymentMethodToken = 'APPLE_PAY-' . strval(rand());
717
+ $customer = Braintree\Customer::createNoValidate();
718
+ $nonce = Braintree\Test\Nonces::$applePayVisa;
719
+ Braintree\PaymentMethod::create([
720
  'customerId' => $customer->id,
721
  'paymentMethodNonce' => $nonce,
722
  'token' => $paymentMethodToken
723
+ ]);
724
 
725
+ $foundApplePayCard = Braintree\PaymentMethod::find($paymentMethodToken);
726
 
727
  $this->assertSame($paymentMethodToken, $foundApplePayCard->token);
728
+ $this->assertInstanceOf('Braintree\ApplePayCard', $foundApplePayCard);
729
  $this->assertTrue(intval($foundApplePayCard->expirationMonth) > 0);
730
  $this->assertTrue(intval($foundApplePayCard->expirationYear) > 0);
731
  }
732
 
733
+ public function testFind_returnsAndroidPayCards()
734
  {
735
  $paymentMethodToken = 'ANDROID-PAY-' . strval(rand());
736
+ $customer = Braintree\Customer::createNoValidate();
737
+ $nonce = Braintree\Test\Nonces::$androidPay;
738
+ Braintree\PaymentMethod::create([
739
  'customerId' => $customer->id,
740
  'paymentMethodNonce' => $nonce,
741
  'token' => $paymentMethodToken
742
+ ]);
743
 
744
+ $foundAndroidPayCard = Braintree\PaymentMethod::find($paymentMethodToken);
745
 
746
  $this->assertSame($paymentMethodToken, $foundAndroidPayCard->token);
747
+ $this->assertInstanceOf('Braintree\AndroidPayCard', $foundAndroidPayCard);
748
+ $this->assertSame(Braintree\CreditCard::DISCOVER, $foundAndroidPayCard->virtualCardType);
749
  $this->assertSame("1117", $foundAndroidPayCard->virtualCardLast4);
750
+ $this->assertSame(Braintree\CreditCard::VISA, $foundAndroidPayCard->sourceCardType);
751
  $this->assertSame("1111", $foundAndroidPayCard->sourceCardLast4);
752
+ $this->assertSame($customer->id, $foundAndroidPayCard->customerId);
753
  $this->assertTrue($foundAndroidPayCard->default);
754
  $this->assertContains('android_pay', $foundAndroidPayCard->imageUrl);
755
  $this->assertTrue(intval($foundAndroidPayCard->expirationMonth) > 0);
756
  $this->assertTrue(intval($foundAndroidPayCard->expirationYear) > 0);
757
  }
758
 
759
+ public function testFind_returnsCoinbaseAccounts()
760
  {
761
+ $customer = Braintree\Customer::createNoValidate();
762
+ $result = Braintree\PaymentMethod::create([
763
  'customerId' => $customer->id,
764
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$coinbase
765
+ ]);
766
 
767
  $this->assertTrue($result->success);
768
  $coinbaseAccount = $result->paymentMethod;
769
  $this->assertNotNull($coinbaseAccount->token);
770
+ $foundCoinbaseAccount = Braintree\PaymentMethod::find($coinbaseAccount->token);
771
+ $this->assertInstanceOf('Braintree\CoinbaseAccount', $foundCoinbaseAccount);
772
  $this->assertNotNull($foundCoinbaseAccount->userId);
773
  $this->assertNotNull($foundCoinbaseAccount->userName);
774
  $this->assertNotNull($foundCoinbaseAccount->userEmail);
775
+ $this->assertNotNull($foundCoinbaseAccount->customerId);
776
  }
777
 
778
 
779
+ public function testFind_returnsAbstractPaymentMethods()
780
  {
781
  $paymentMethodToken = 'ABSTRACT-' . strval(rand());
782
+ $customer = Braintree\Customer::createNoValidate();
783
+ $nonce = Braintree\Test\Nonces::$abstractTransactable;
784
+ Braintree\PaymentMethod::create([
785
  'customerId' => $customer->id,
786
  'paymentMethodNonce' => $nonce,
787
  'token' => $paymentMethodToken
788
+ ]);
789
 
790
+ $foundPaymentMethod = Braintree\PaymentMethod::find($paymentMethodToken);
791
 
792
  $this->assertSame($paymentMethodToken, $foundPaymentMethod-> token);
793
  }
794
 
795
+ public function testFind_throwsIfCannotBeFound()
796
  {
797
+ $this->setExpectedException('Braintree\Exception\NotFound');
798
+ Braintree\PaymentMethod::find('NON_EXISTENT_TOKEN');
799
  }
800
 
801
+ public function testUpdate_updatesTheCreditCard()
802
  {
803
+ $customer = Braintree\Customer::createNoValidate();
804
+ $creditCardResult = Braintree\CreditCard::create([
805
  'cardholderName' => 'Original Holder',
806
  'customerId' => $customer->id,
807
  'cvv' => '123',
808
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
809
  'expirationDate' => "05/2012"
810
+ ]);
811
  $this->assertTrue($creditCardResult->success);
812
  $creditCard = $creditCardResult->creditCard;
813
 
814
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
815
  'cardholderName' => 'New Holder',
816
  'cvv' => '456',
817
+ 'number' => Braintree\Test\CreditCardNumbers::$masterCard,
818
  'expirationDate' => "06/2013"
819
+ ]);
820
 
821
  $this->assertTrue($updateResult->success);
822
  $this->assertSame($updateResult->paymentMethod->token, $creditCard->token);
823
  $updatedCreditCard = $updateResult->paymentMethod;
824
  $this->assertSame("New Holder", $updatedCreditCard->cardholderName);
825
+ $this->assertSame(substr(Braintree\Test\CreditCardNumbers::$masterCard, 0, 6), $updatedCreditCard->bin);
826
+ $this->assertSame(substr(Braintree\Test\CreditCardNumbers::$masterCard, -4), $updatedCreditCard->last4);
827
  $this->assertSame("06/2013", $updatedCreditCard->expirationDate);
828
  }
829
 
830
+ public function testUpdate_createsANewBillingAddressByDefault()
831
  {
832
+ $customer = Braintree\Customer::createNoValidate();
833
+ $creditCardResult = Braintree\CreditCard::create([
834
  'customerId' => $customer->id,
835
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
836
  'expirationDate' => "05/2012",
837
+ 'billingAddress' => [
838
  'streetAddress' => '123 Nigeria Ave'
839
+ ]
840
+ ]);
841
  $this->assertTrue($creditCardResult->success);
842
  $creditCard = $creditCardResult->creditCard;
843
 
844
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
845
+ 'billingAddress' => [
846
  'region' => 'IL'
847
+ ]
848
+ ]);
849
 
850
  $this->assertTrue($updateResult->success);
851
  $updatedCreditCard = $updateResult->paymentMethod;
854
  $this->assertFalse($creditCard->billingAddress->id == $updatedCreditCard->billingAddress->id);
855
  }
856
 
857
+ public function testUpdate_updatesTheBillingAddressIfOptionIsSpecified()
858
  {
859
+ $customer = Braintree\Customer::createNoValidate();
860
+ $creditCardResult = Braintree\CreditCard::create([
861
  'customerId' => $customer->id,
862
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
863
  'expirationDate' => "05/2012",
864
+ 'billingAddress' => [
865
  'streetAddress' => '123 Nigeria Ave'
866
+ ]
867
+ ]);
868
  $this->assertTrue($creditCardResult->success);
869
  $creditCard = $creditCardResult->creditCard;
870
 
871
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
872
+ 'billingAddress' => [
873
  'region' => 'IL',
874
+ 'options' => [
875
  'updateExisting' => 'true'
876
+ ]
877
+ ],
878
+ ]);
879
 
880
  $this->assertTrue($updateResult->success);
881
  $updatedCreditCard = $updateResult->paymentMethod;
884
  $this->assertTrue($creditCard->billingAddress->id == $updatedCreditCard->billingAddress->id);
885
  }
886
 
887
+ public function testUpdate_updatesTheCountryViaCodes()
888
  {
889
+ $customer = Braintree\Customer::createNoValidate();
890
+ $creditCardResult = Braintree\CreditCard::create([
891
  'customerId' => $customer->id,
892
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
893
  'expirationDate' => "05/2012",
894
+ 'billingAddress' => [
895
  'streetAddress' => '123 Nigeria Ave'
896
+ ]
897
+ ]);
898
  $this->assertTrue($creditCardResult->success);
899
  $creditCard = $creditCardResult->creditCard;
900
 
901
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
902
+ 'billingAddress' => [
903
  'countryName' => 'American Samoa',
904
  'countryCodeAlpha2' => 'AS',
905
  'countryCodeAlpha3' => 'ASM',
906
  'countryCodeNumeric' => '016',
907
+ 'options' => [
908
  'updateExisting' => 'true'
909
+ ]
910
+ ],
911
+ ]);
912
 
913
  $this->assertTrue($updateResult->success);
914
  $updatedCreditCard = $updateResult->paymentMethod;
918
  $this->assertSame("016", $updatedCreditCard->billingAddress->countryCodeNumeric);
919
  }
920
 
921
+ public function testUpdate_canPassExpirationMonthAndExpirationYear()
922
  {
923
+ $customer = Braintree\Customer::createNoValidate();
924
+ $creditCardResult = Braintree\CreditCard::create([
925
  'customerId' => $customer->id,
926
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
927
  'expirationDate' => "05/2012"
928
+ ]);
929
  $this->assertTrue($creditCardResult->success);
930
  $creditCard = $creditCardResult->creditCard;
931
 
932
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
933
+ 'number' => Braintree\Test\CreditCardNumbers::$masterCard,
934
  'expirationMonth' => "07",
935
  'expirationYear' => "2011"
936
+ ]);
937
 
938
  $this->assertTrue($updateResult->success);
939
  $this->assertSame($updateResult->paymentMethod->token, $creditCard->token);
943
  $this->assertSame("07/2011", $updatedCreditCard->expirationDate);
944
  }
945
 
946
+ public function testUpdate_verifiesTheUpdateIfOptionsVerifyCardIsTrue()
947
  {
948
+ $customer = Braintree\Customer::createNoValidate();
949
+ $creditCardResult = Braintree\CreditCard::create([
950
  'cardholderName' => 'Original Holder',
951
  'customerId' => $customer->id,
952
  'cvv' => '123',
953
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
954
  'expirationDate' => "05/2012"
955
+ ]);
956
  $this->assertTrue($creditCardResult->success);
957
  $creditCard = $creditCardResult->creditCard;
958
 
959
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
960
  'cardholderName' => 'New Holder',
961
  'cvv' => '456',
962
+ 'number' => Braintree\Test\CreditCardNumbers::$failsSandboxVerification['MasterCard'],
963
  'expirationDate' => "06/2013",
964
+ 'options' => [
965
  'verifyCard' => 'true'
966
+ ]
967
+ ]);
968
 
969
  $this->assertFalse($updateResult->success);
970
+ $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $updateResult->creditCardVerification->status);
971
  $this->assertEquals(NULL, $updateResult->creditCardVerification->gatewayRejectionReason);
972
  }
973
 
974
+ public function testUpdate_canUpdateTheBillingAddress()
975
  {
976
+ $customer = Braintree\Customer::createNoValidate();
977
+ $creditCardResult = Braintree\CreditCard::create([
978
  'cardholderName' => 'Original Holder',
979
  'customerId' => $customer->id,
980
  'cvv' => '123',
981
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
982
  'expirationDate' => '05/2012',
983
+ 'billingAddress' => [
984
  'firstName' => 'Old First Name',
985
  'lastName' => 'Old Last Name',
986
  'company' => 'Old Company',
990
  'region' => 'Old State',
991
  'postalCode' => '12345',
992
  'countryName' => 'Canada'
993
+ ]
994
+ ]);
995
  $this->assertTrue($creditCardResult->success);
996
  $creditCard = $creditCardResult->creditCard;
997
 
998
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
999
+ 'billingAddress' => [
1000
  'firstName' => 'New First Name',
1001
  'lastName' => 'New Last Name',
1002
  'company' => 'New Company',
1006
  'region' => 'New State',
1007
  'postalCode' => '56789',
1008
  'countryName' => 'United States of America'
1009
+ ]
1010
+ ]);
1011
 
1012
  $this->assertTrue($updateResult->success);
1013
  $address = $updateResult->paymentMethod->billingAddress;
1022
  $this->assertSame('United States of America', $address->countryName);
1023
  }
1024
 
1025
+ public function testUpdate_returnsAnErrorIfInvalid()
1026
  {
1027
+ $customer = Braintree\Customer::createNoValidate();
1028
+ $creditCardResult = Braintree\CreditCard::create([
1029
  'cardholderName' => 'Original Holder',
1030
  'customerId' => $customer->id,
1031
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1032
  'expirationDate' => "05/2012"
1033
+ ]);
1034
  $this->assertTrue($creditCardResult->success);
1035
  $creditCard = $creditCardResult->creditCard;
1036
 
1037
+ $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
1038
  'cardholderName' => 'New Holder',
1039
  'number' => 'invalid',
1040
  'expirationDate' => "05/2014",
1041
+ ]);
1042
 
1043
  $this->assertFalse($updateResult->success);
1044
  $numberErrors = $updateResult->errors->forKey('creditCard')->onAttribute('number');
1045
  $this->assertEquals("Credit card number must be 12-19 digits.", $numberErrors[0]->message);
1046
  }
1047
 
1048
+ public function testUpdate_canUpdateTheDefault()
1049
  {
1050
+ $customer = Braintree\Customer::createNoValidate();
1051
 
1052
+ $creditCardResult1 = Braintree\CreditCard::create([
1053
  'customerId' => $customer->id,
1054
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1055
  'expirationDate' => "05/2009"
1056
+ ]);
1057
  $this->assertTrue($creditCardResult1->success);
1058
  $creditCard1 = $creditCardResult1->creditCard;
1059
 
1060
+ $creditCardResult2 = Braintree\CreditCard::create([
1061
  'customerId' => $customer->id,
1062
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1063
  'expirationDate' => "05/2009"
1064
+ ]);
1065
  $this->assertTrue($creditCardResult2->success);
1066
  $creditCard2 = $creditCardResult2->creditCard;
1067
 
1069
  $this->assertFalse($creditCard2->default);
1070
 
1071
 
1072
+ $updateResult = Braintree\PaymentMethod::update($creditCard2->token, [
1073
+ 'options' => [
1074
  'makeDefault' => 'true'
1075
+ ]
1076
+ ]);
1077
  $this->assertTrue($updateResult->success);
1078
 
1079
+ $this->assertFalse(Braintree\PaymentMethod::find($creditCard1->token)->default);
1080
+ $this->assertTrue(Braintree\PaymentMethod::find($creditCard2->token)->default);
1081
  }
1082
 
1083
+ public function testUpdate_updatesAPaypalAccountsToken()
1084
  {
1085
+ $customer = Braintree\Customer::createNoValidate();
1086
  $originalToken = 'paypal-account-' . strval(rand());
1087
+ $customer = Braintree\Customer::createNoValidate();
1088
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1089
+ $nonce = $http->nonceForPayPalAccount([
1090
+ 'paypal_account' => [
1091
  'consent_code' => 'consent-code',
1092
  'token' => $originalToken
1093
+ ]
1094
+ ]);
1095
 
1096
+ $originalResult = Braintree\PaymentMethod::create([
1097
  'paymentMethodNonce' => $nonce,
1098
  'customerId' => $customer->id
1099
+ ]);
1100
  $this->assertTrue($originalResult->success);
1101
 
1102
  $originalPaypalAccount = $originalResult->paymentMethod;
1103
 
1104
  $updatedToken = 'UPDATED_TOKEN-' . strval(rand());
1105
+ $updateResult = Braintree\PaymentMethod::update($originalPaypalAccount->token, [
1106
  'token' => $updatedToken
1107
+ ]);
1108
  $this->assertTrue($updateResult->success);
1109
 
1110
+ $updatedPaypalAccount = Braintree\PaymentMethod::find($updatedToken);
1111
  $this->assertEquals($originalPaypalAccount->email, $updatedPaypalAccount->email);
1112
 
1113
+ $this->setExpectedException('Braintree\Exception\NotFound', 'payment method with token ' . $originalToken . ' not found');
1114
+ Braintree\PaymentMethod::find($originalToken);
1115
 
1116
  }
1117
 
1118
+ public function testUpdate_canMakeAPaypalAccountTheDefaultPaymentMethod()
1119
  {
1120
+ $customer = Braintree\Customer::createNoValidate();
1121
+ $creditCardResult = Braintree\CreditCard::create([
1122
  'customerId' => $customer->id,
1123
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
1124
+ 'expirationDate' => '05/2009',
1125
+ 'options' => [
1126
  'makeDefault' => 'true'
1127
+ ]
1128
+ ]);
1129
  $this->assertTrue($creditCardResult->success);
1130
  $creditCard = $creditCardResult->creditCard;
1131
 
1132
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1133
+ $nonce = $http->nonceForPayPalAccount([
1134
+ 'paypal_account' => [
1135
  'consent_code' => 'consent-code',
1136
+ ]
1137
+ ]);
1138
 
1139
+ $originalToken = Braintree\PaymentMethod::create([
1140
  'paymentMethodNonce' => $nonce,
1141
  'customerId' => $customer->id
1142
+ ])->paymentMethod->token;
1143
 
1144
+ $updateResult = Braintree\PaymentMethod::update($originalToken, [
1145
+ 'options' => [
1146
  'makeDefault' => 'true'
1147
+ ]
1148
+ ]);
1149
  $this->assertTrue($updateResult->success);
1150
 
1151
+ $updatedPaypalAccount = Braintree\PaymentMethod::find($originalToken);
1152
  $this->assertTrue($updatedPaypalAccount->default);
1153
 
1154
  }
1155
 
1156
+ public function testUpdate_returnsAnErrorIfATokenForAccountIsUsedToAttemptAnUpdate()
1157
  {
1158
+ $customer = Braintree\Customer::createNoValidate();
1159
  $firstToken = 'paypal-account-' . strval(rand());
1160
  $secondToken = 'paypal-account-' . strval(rand());
1161
 
1162
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1163
+ $firstNonce = $http->nonceForPayPalAccount([
1164
+ 'paypal_account' => [
1165
  'consent_code' => 'consent-code',
1166
  'token' => $firstToken
1167
+ ]
1168
+ ]);
1169
+ $firstResult = Braintree\PaymentMethod::create([
1170
  'paymentMethodNonce' => $firstNonce,
1171
  'customerId' => $customer->id
1172
+ ]);
1173
  $this->assertTrue($firstResult->success);
1174
  $firstPaypalAccount = $firstResult->paymentMethod;
1175
 
1176
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1177
+ $secondNonce = $http->nonceForPayPalAccount([
1178
+ 'paypal_account' => [
1179
  'consent_code' => 'consent-code',
1180
  'token' => $secondToken
1181
+ ]
1182
+ ]);
1183
+ $secondResult = Braintree\PaymentMethod::create([
1184
  'paymentMethodNonce' => $secondNonce,
1185
  'customerId' => $customer->id
1186
+ ]);
1187
  $this->assertTrue($secondResult->success);
1188
  $secondPaypalAccount = $firstResult->paymentMethod;
1189
 
1190
 
1191
+ $updateResult = Braintree\PaymentMethod::update($firstToken, [
1192
  'token' => $secondToken
1193
+ ]);
1194
 
1195
  $this->assertFalse($updateResult->success);
1196
  $resultErrors = $updateResult->errors->deepAll();
1198
 
1199
  }
1200
 
1201
+ public function testDelete_worksWithCreditCards()
1202
  {
1203
  $paymentMethodToken = 'CREDIT_CARD_TOKEN-' . strval(rand());
1204
+ $customer = Braintree\Customer::createNoValidate();
1205
+ $creditCardResult = Braintree\CreditCard::create([
1206
  'customerId' => $customer->id,
1207
  'number' => '5105105105105100',
1208
  'expirationDate' => '05/2011',
1209
  'token' => $paymentMethodToken
1210
+ ]);
1211
  $this->assertTrue($creditCardResult->success);
1212
 
1213
+ Braintree\PaymentMethod::delete($paymentMethodToken);
1214
 
1215
+ $this->setExpectedException('Braintree\Exception\NotFound');
1216
+ Braintree\PaymentMethod::find($paymentMethodToken);
1217
+ self::integrationMerchantConfig();
1218
  }
1219
 
1220
+ public function testDelete_worksWithPayPalAccounts()
1221
  {
1222
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
1223
+ $customer = Braintree\Customer::createNoValidate();
1224
+ $http = new HttpClientApi(Braintree\Configuration::$global);
1225
+ $nonce = $http->nonceForPayPalAccount([
1226
+ 'paypal_account' => [
1227
  'consent_code' => 'PAYPAL_CONSENT_CODE',
1228
  'token' => $paymentMethodToken
1229
+ ]
1230
+ ]);
1231
 
1232
+ $paypalAccountResult = Braintree\PaymentMethod::create([
1233
  'customerId' => $customer->id,
1234
  'paymentMethodNonce' => $nonce
1235
+ ]);
1236
  $this->assertTrue($paypalAccountResult->success);
1237
 
1238
+ Braintree\PaymentMethod::delete($paymentMethodToken);
1239
 
1240
+ $this->setExpectedException('Braintree\Exception\NotFound');
1241
+ Braintree\PaymentMethod::find($paymentMethodToken);
1242
  }
1243
 
1244
+ public function testGrant_returnsASingleUseNonce()
1245
+ {
1246
+ $partnerMerchantGateway = new Braintree\Gateway([
1247
+ 'environment' => 'development',
1248
+ 'merchantId' => 'integration_merchant_public_id',
1249
+ 'publicKey' => 'oauth_app_partner_user_public_key',
1250
+ 'privateKey' => 'oauth_app_partner_user_private_key'
1251
+ ]);
1252
+
1253
+ $customer = $partnerMerchantGateway->customer()->create([
1254
+ 'firstName' => 'Joe',
1255
+ 'lastName' => 'Brown'
1256
+ ])->customer;
1257
+ $creditCard = $partnerMerchantGateway->creditCard()->create([
1258
+ 'customerId' => $customer->id,
1259
+ 'cardholderName' => 'Adam Davis',
1260
+ 'number' => '4111111111111111',
1261
+ 'expirationDate' => '05/2009'
1262
+ ])->creditCard;
1263
+
1264
+ $oauthAppGateway = new Braintree\Gateway([
1265
+ 'clientId' => 'client_id$development$integration_client_id',
1266
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1267
+ ]);
1268
+
1269
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1270
+ 'merchant_public_id' => 'integration_merchant_id',
1271
+ 'scope' => 'grant_payment_method'
1272
+ ]);
1273
+
1274
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1275
+ 'code' => $code,
1276
+ ]);
1277
+
1278
+ $grantingGateway = new Braintree\Gateway([
1279
+ 'accessToken' => $credentials->accessToken
1280
+ ]);
1281
+
1282
+ $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, false);
1283
+ $this->assertTrue($grantResult->success);
1284
+
1285
+ $result = Braintree\Transaction::sale([
1286
+ 'amount' => '100.00',
1287
+ 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
1288
+ ]);
1289
+ $this->assertTrue($result->success);
1290
+
1291
+ $secondResult = Braintree\Transaction::sale([
1292
+ 'amount' => '100.00',
1293
+ 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
1294
+ ]);
1295
+ $this->assertFalse($secondResult->success);
1296
+ }
1297
+
1298
+ public function testGrant_returnsANonceThatIsNotVaultable()
1299
+ {
1300
+ $partnerMerchantGateway = new Braintree\Gateway([
1301
+ 'environment' => 'development',
1302
+ 'merchantId' => 'integration_merchant_public_id',
1303
+ 'publicKey' => 'oauth_app_partner_user_public_key',
1304
+ 'privateKey' => 'oauth_app_partner_user_private_key'
1305
+ ]);
1306
+
1307
+ $customer = $partnerMerchantGateway->customer()->create([
1308
+ 'firstName' => 'Joe',
1309
+ 'lastName' => 'Brown'
1310
+ ])->customer;
1311
+ $creditCard = $partnerMerchantGateway->creditCard()->create([
1312
+ 'customerId' => $customer->id,
1313
+ 'cardholderName' => 'Adam Davis',
1314
+ 'number' => '4111111111111111',
1315
+ 'expirationDate' => '05/2009'
1316
+ ])->creditCard;
1317
+
1318
+ $oauthAppGateway = new Braintree\Gateway([
1319
+ 'clientId' => 'client_id$development$integration_client_id',
1320
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1321
+ ]);
1322
+
1323
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1324
+ 'merchant_public_id' => 'integration_merchant_id',
1325
+ 'scope' => 'grant_payment_method'
1326
+ ]);
1327
+
1328
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1329
+ 'code' => $code,
1330
+ ]);
1331
+
1332
+ $grantingGateway = new Braintree\Gateway([
1333
+ 'accessToken' => $credentials->accessToken
1334
+ ]);
1335
+
1336
+ $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, false);
1337
+
1338
+ $customer = $partnerMerchantGateway->customer()->create([
1339
+ 'firstName' => 'Bob',
1340
+ 'lastName' => 'Rob'
1341
+ ])->customer;
1342
+ $result = Braintree\PaymentMethod::create([
1343
+ 'customerId' => $customer->id,
1344
+ 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
1345
+ ]);
1346
+ $this->assertFalse($result->success);
1347
+ }
1348
+
1349
+ public function testGrant_returnsANonceThatIsVaultable()
1350
+ {
1351
+ $partnerMerchantGateway = new Braintree\Gateway([
1352
+ 'environment' => 'development',
1353
+ 'merchantId' => 'integration_merchant_public_id',
1354
+ 'publicKey' => 'oauth_app_partner_user_public_key',
1355
+ 'privateKey' => 'oauth_app_partner_user_private_key'
1356
+ ]);
1357
+
1358
+ $customer = $partnerMerchantGateway->customer()->create([
1359
+ 'firstName' => 'Joe',
1360
+ 'lastName' => 'Brown'
1361
+ ])->customer;
1362
+ $creditCard = $partnerMerchantGateway->creditCard()->create([
1363
+ 'customerId' => $customer->id,
1364
+ 'cardholderName' => 'Adam Davis',
1365
+ 'number' => '4111111111111111',
1366
+ 'expirationDate' => '05/2009'
1367
+ ])->creditCard;
1368
+
1369
+ $oauthAppGateway = new Braintree\Gateway([
1370
+ 'clientId' => 'client_id$development$integration_client_id',
1371
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1372
+ ]);
1373
+
1374
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1375
+ 'merchant_public_id' => 'integration_merchant_id',
1376
+ 'scope' => 'grant_payment_method'
1377
+ ]);
1378
+
1379
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1380
+ 'code' => $code,
1381
+ ]);
1382
+
1383
+ $grantingGateway = new Braintree\Gateway([
1384
+ 'accessToken' => $credentials->accessToken
1385
+ ]);
1386
+
1387
+ $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, true);
1388
+
1389
+ $customer = Braintree\Customer::create([
1390
+ 'firstName' => 'Bob',
1391
+ 'lastName' => 'Rob'
1392
+ ])->customer;
1393
+ $result = Braintree\PaymentMethod::create([
1394
+ 'customerId' => $customer->id,
1395
+ 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
1396
+ ]);
1397
+ $this->assertTrue($result->success);
1398
+ }
1399
+
1400
+ public function testGrant_raisesAnErrorIfTokenIsNotFound()
1401
+ {
1402
+ $oauthAppGateway = new Braintree\Gateway([
1403
+ 'clientId' => 'client_id$development$integration_client_id',
1404
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1405
+ ]);
1406
+
1407
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1408
+ 'merchant_public_id' => 'integration_merchant_id',
1409
+ 'scope' => 'grant_payment_method'
1410
+ ]);
1411
+
1412
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1413
+ 'code' => $code,
1414
+ ]);
1415
+
1416
+ $grantingGateway = new Braintree\Gateway([
1417
+ 'accessToken' => $credentials->accessToken
1418
+ ]);
1419
+
1420
+ $this->setExpectedException('Braintree\Exception\NotFound');
1421
+ $grantResult = $grantingGateway->paymentMethod()->grant("not_a_real_token", false);
1422
+ }
1423
+
1424
+ public function testRevoke_rendersANonceUnusable()
1425
+ {
1426
+ $partnerMerchantGateway = new Braintree\Gateway([
1427
+ 'environment' => 'development',
1428
+ 'merchantId' => 'integration_merchant_public_id',
1429
+ 'publicKey' => 'oauth_app_partner_user_public_key',
1430
+ 'privateKey' => 'oauth_app_partner_user_private_key'
1431
+ ]);
1432
+
1433
+ $customer = $partnerMerchantGateway->customer()->create([
1434
+ 'firstName' => 'Joe',
1435
+ 'lastName' => 'Brown'
1436
+ ])->customer;
1437
+ $creditCard = $partnerMerchantGateway->creditCard()->create([
1438
+ 'customerId' => $customer->id,
1439
+ 'cardholderName' => 'Adam Davis',
1440
+ 'number' => '4111111111111111',
1441
+ 'expirationDate' => '05/2009'
1442
+ ])->creditCard;
1443
+
1444
+ $oauthAppGateway = new Braintree\Gateway([
1445
+ 'clientId' => 'client_id$development$integration_client_id',
1446
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1447
+ ]);
1448
+
1449
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1450
+ 'merchant_public_id' => 'integration_merchant_id',
1451
+ 'scope' => 'grant_payment_method'
1452
+ ]);
1453
+
1454
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1455
+ 'code' => $code,
1456
+ ]);
1457
+
1458
+ $grantingGateway = new Braintree\Gateway([
1459
+ 'accessToken' => $credentials->accessToken
1460
+ ]);
1461
+
1462
+ $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, false);
1463
+ $revokeResult = $grantingGateway->paymentMethod()->revoke($creditCard->token);
1464
+ $this->assertTrue($revokeResult->success);
1465
+
1466
+ $result = Braintree\Transaction::sale([
1467
+ 'amount' => '100.00',
1468
+ 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
1469
+ ]);
1470
+ $this->assertFalse($result->success);
1471
+ }
1472
+
1473
+ public function testRevoke_raisesAnErrorIfTokenIsNotFound()
1474
+ {
1475
+ $oauthAppGateway = new Braintree\Gateway([
1476
+ 'clientId' => 'client_id$development$integration_client_id',
1477
+ 'clientSecret' => 'client_secret$development$integration_client_secret'
1478
+ ]);
1479
+
1480
+ $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
1481
+ 'merchant_public_id' => 'integration_merchant_id',
1482
+ 'scope' => 'grant_payment_method'
1483
+ ]);
1484
+
1485
+ $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
1486
+ 'code' => $code,
1487
+ ]);
1488
+
1489
+ $grantingGateway = new Braintree\Gateway([
1490
+ 'accessToken' => $credentials->accessToken
1491
+ ]);
1492
+
1493
+ $this->setExpectedException('Braintree\Exception\NotFound');
1494
+ $grantResult = $grantingGateway->paymentMethod()->revoke("not_a_real_token");
1495
+ }
1496
  }
braintree_sdk/tests/integration/PlanTest.php CHANGED
@@ -1,21 +1,27 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_PlanTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
5
  {
6
- function testAll_withNoPlans_returnsEmptyArray()
7
  {
8
- testMerchantConfig();
9
- $plans = Braintree_Plan::all();
10
- $this->assertEquals($plans, array());
11
- integrationMerchantConfig();
12
 
13
  }
14
 
15
- function testAll_returnsAllPlans()
16
  {
17
  $newId = strval(rand());
18
- $params = array (
19
  "id" => $newId,
20
  "billingDayOfMonth" => "1",
21
  "billingFrequency" => "1",
@@ -25,35 +31,35 @@ class Braintree_PlanTest extends PHPUnit_Framework_TestCase
25
  "numberOfBillingCycles" => "1",
26
  "price" => "1.00",
27
  "trialPeriod" => "false"
28
- );
29
 
30
- $http = new Braintree_Http(Braintree_Configuration::$global);
31
- $path = Braintree_Configuration::$global->merchantPath() . "/plans/create_plan_for_tests";
32
- $http->post($path, array("plan" => $params));
33
 
34
- $addOnParams = array (
35
  "kind" => "add_on",
36
  "plan_id" => $newId,
37
  "amount" => "1.00",
38
  "name" => "add_on_name"
39
- );
40
 
41
- $http = new Braintree_Http(Braintree_Configuration::$global);
42
- $path = Braintree_Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
43
- $http->post($path, array("modification" => $addOnParams));
44
 
45
- $discountParams = array (
46
  "kind" => "discount",
47
  "plan_id" => $newId,
48
  "amount" => "1.00",
49
  "name" => "discount_name"
50
- );
51
 
52
- $http = new Braintree_Http(Braintree_Configuration::$global);
53
- $path = Braintree_Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
54
- $http->post($path, array("modification" => $discountParams));
55
 
56
- $plans = Braintree_Plan::all();
57
 
58
  foreach ($plans as $plan)
59
  {
@@ -79,10 +85,10 @@ class Braintree_PlanTest extends PHPUnit_Framework_TestCase
79
  $this->assertEquals($discountParams["name"], $discount->name);
80
  }
81
 
82
- function testGatewayAll_returnsAllPlans()
83
  {
84
  $newId = strval(rand());
85
- $params = array (
86
  "id" => $newId,
87
  "billingDayOfMonth" => "1",
88
  "billingFrequency" => "1",
@@ -92,18 +98,18 @@ class Braintree_PlanTest extends PHPUnit_Framework_TestCase
92
  "numberOfBillingCycles" => "1",
93
  "price" => "1.00",
94
  "trialPeriod" => "false"
95
- );
96
 
97
- $http = new Braintree_Http(Braintree_Configuration::$global);
98
- $path = Braintree_Configuration::$global->merchantPath() . "/plans/create_plan_for_tests";
99
- $http->post($path, array("plan" => $params));
100
 
101
- $gateway = new Braintree_Gateway(array(
102
  'environment' => 'development',
103
  'merchantId' => 'integration_merchant_id',
104
  'publicKey' => 'integration_public_key',
105
  'privateKey' => 'integration_private_key'
106
- ));
107
  $plans = $gateway->plan()->all();
108
 
109
  foreach ($plans as $plan)
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",
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
  {
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",
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)
braintree_sdk/tests/integration/Result/ErrorTest.php CHANGED
@@ -1,23 +1,28 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../../TestHelper.php';
3
 
4
- class Braintree_Result_ErrorTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
5
  {
6
- function testValueForHtmlField()
7
  {
8
- $result = Braintree_Customer::create(array(
9
  'email' => 'invalid-email',
10
- 'creditCard' => array(
11
  'number' => 'invalid-number',
12
  'expirationDate' => 'invalid-exp',
13
- 'billingAddress' => array(
14
  'countryName' => 'invalid-country'
15
- )
16
- ),
17
- 'customFields' => array(
18
  'store_me' => 'some custom value'
19
- )
20
- ));
21
  $this->assertEquals(false, $result->success);
22
  $this->assertEquals('invalid-email', $result->valueForHtmlField('customer[email]'));
23
  $this->assertEquals('', $result->valueForHtmlField('customer[credit_card][number]'));
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]'));
braintree_sdk/tests/integration/SettlementBatchSummaryTest.php CHANGED
@@ -1,85 +1,92 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_SettlementBatchSummaryTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
 
5
  {
6
- function isMasterCard($record)
7
  {
8
- return $record['cardType'] == Braintree_CreditCard::MASTER_CARD;
9
  }
10
 
11
- function testGenerate_returnsAnEmptyCollectionWhenThereIsNoData()
12
  {
13
- $result = Braintree_SettlementBatchSummary::generate('2000-01-01');
14
 
15
  $this->assertTrue($result->success);
16
  $this->assertEquals(0, count($result->settlementBatchSummary->records));
17
  }
18
 
19
- function testGatewayGenerate_returnsAnEmptyCollectionWhenThereIsNoData()
20
  {
21
- $gateway = new Braintree_Gateway(array(
22
  'environment' => 'development',
23
  'merchantId' => 'integration_merchant_id',
24
  'publicKey' => 'integration_public_key',
25
  'privateKey' => 'integration_private_key'
26
- ));
27
  $result = $gateway->settlementBatchSummary()->generate('2000-01-01');
28
 
29
  $this->assertTrue($result->success);
30
  $this->assertEquals(0, count($result->settlementBatchSummary->records));
31
  }
32
 
33
- function testGenerate_returnsAnErrorIfTheDateCanNotBeParsed()
34
  {
35
- $result = Braintree_SettlementBatchSummary::generate('OMG NOT A DATE');
36
 
37
  $this->assertFalse($result->success);
38
  $errors = $result->errors->forKey('settlementBatchSummary')->onAttribute('settlementDate');
39
- $this->assertEquals(Braintree_Error_Codes::SETTLEMENT_BATCH_SUMMARY_SETTLEMENT_DATE_IS_INVALID, $errors[0]->code);
40
  }
41
 
42
- function testGenerate_returnsTransactionsSettledOnAGivenDay()
43
  {
44
- $transaction = Braintree_Transaction::saleNoValidate(array(
45
  'amount' => '100.00',
46
- 'creditCard' => array(
47
  'number' => '5105105105105100',
48
  'expirationDate' => '05/12'
49
- ),
50
- 'options' => array('submitForSettlement' => true)
51
- ));
52
- Braintree_Test_Transaction::settle($transaction->id);
53
 
54
  $today = new Datetime;
55
- $result = Braintree_SettlementBatchSummary::generate(Braintree_TestHelper::nowInEastern());
56
 
57
  $this->assertTrue($result->success);
58
  $masterCardRecords = array_filter($result->settlementBatchSummary->records, 'self::isMasterCard');
59
  $masterCardKeys = array_keys($masterCardRecords);
60
  $masterCardIndex = $masterCardKeys[0];
61
  $this->assertTrue(count($masterCardRecords) > 0);
62
- $this->assertEquals(Braintree_CreditCard::MASTER_CARD, $masterCardRecords[$masterCardIndex]['cardType']);
63
  }
64
 
65
- function testGenerate_canBeGroupedByACustomField()
66
  {
67
- $transaction = Braintree_Transaction::saleNoValidate(array(
68
  'amount' => '100.00',
69
- 'creditCard' => array(
70
  'number' => '5105105105105100',
71
  'expirationDate' => '05/12'
72
- ),
73
- 'customFields' => array(
74
  'store_me' => 'custom value'
75
- ),
76
- 'options' => array('submitForSettlement' => true)
77
- ));
78
 
79
- Braintree_Test_Transaction::settle($transaction->id);
80
 
81
  $today = new Datetime;
82
- $result = Braintree_SettlementBatchSummary::generate(Braintree_TestHelper::nowInEastern(), 'store_me');
83
 
84
  $this->assertTrue($result->success);
85
  $this->assertTrue(count($result->settlementBatchSummary->records) > 0);
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);
braintree_sdk/tests/integration/{SubscriptionTestHelper.php → SubscriptionHelper.php} RENAMED
@@ -1,34 +1,36 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_SubscriptionTestHelper
 
 
5
  {
6
- static function addOnDiscountPlan()
7
  {
8
- return array(
9
  'description' => "Plan for integration tests -- with add-ons and discounts",
10
  'id' => "integration_plan_with_add_ons_and_discounts",
11
  'price' => '9.99',
12
  'trial_period' => true,
13
  'trial_duration' => 2,
14
  'trial_duration_unit' => 'day'
15
- );
16
  }
17
 
18
- static function billingDayOfMonthPlan()
19
  {
20
- return array(
21
  'description' => 'Plan for integration tests -- with billing day of month',
22
  'id' => 'integration_plan_with_billing_day_of_month',
23
  'numberOfBillingCycles' => 5,
24
  'price' => '8.88',
25
  'trial_period' => false
26
- );
27
  }
28
 
29
- static function trialPlan()
30
  {
31
- return array(
32
  'description' => 'Plan for integration tests -- with trial',
33
  'id' => 'integration_trial_plan',
34
  'numberOfBillingCycles' => 12,
@@ -36,49 +38,49 @@ class Braintree_SubscriptionTestHelper
36
  'trial_period' => true,
37
  'trial_duration' => 2,
38
  'trial_duration_unit' => 'day'
39
- );
40
  }
41
 
42
- static function triallessPlan()
43
  {
44
- return array(
45
  'description' => 'Plan for integration tests -- without a trial',
46
  'id' => 'integration_trialless_plan',
47
  'numberOfBillingCycles' => 12,
48
  'price' => '12.34',
49
  'trial_period' => false
50
- );
51
  }
52
 
53
- static function createCreditCard()
54
  {
55
- $customer = Braintree_Customer::createNoValidate(array(
56
- 'creditCard' => array(
57
  'number' => '5105105105105100',
58
  'expirationDate' => '05/2010'
59
- )
60
- ));
61
  return $customer->creditCards[0];
62
  }
63
 
64
- static function createSubscription()
65
  {
66
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
67
- $result = Braintree_Subscription::create(array(
68
- 'paymentMethodToken' => Braintree_SubscriptionTestHelper::createCreditCard()->token,
69
  'price' => '54.99',
70
  'planId' => $plan['id']
71
- ));
72
  return $result->subscription;
73
  }
74
 
75
- static function compareModificationsById($left, $right)
76
  {
77
  return strcmp($left->id, $right->id);
78
  }
79
 
80
- static function sortModificationsById(&$modifications)
81
  {
82
- usort($modifications, array("Braintree_SubscriptionTestHelper", "compareModificationsById"));
83
  }
84
  }
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,
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
  }
braintree_sdk/tests/integration/SubscriptionSearchTest.php CHANGED
@@ -1,44 +1,50 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/SubscriptionTestHelper.php';
4
 
5
- class Braintree_SubscriptionSearchTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
 
6
  {
7
- function testSearch_planIdIs()
8
  {
9
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
10
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
11
- $trialPlan = Braintree_SubscriptionTestHelper::trialPlan();
12
 
13
- $trialSubscription = Braintree_Subscription::create(array(
14
  'paymentMethodToken' => $creditCard->token,
15
  'planId' => $trialPlan['id'],
16
  'price' => '1'
17
- ))->subscription;
18
 
19
- $triallessSubscription = Braintree_Subscription::create(array(
20
  'paymentMethodToken' => $creditCard->token,
21
  'planId' => $triallessPlan['id'],
22
  'price' => '1'
23
- ))->subscription;
24
 
25
- $collection = Braintree_Subscription::search(array(
26
- Braintree_SubscriptionSearch::planId()->is('integration_trial_plan'),
27
- Braintree_SubscriptionSearch::price()->is('1')
28
- ));
29
 
30
- $this->assertTrue(Braintree_TestHelper::includes($collection, $trialSubscription));
31
- $this->assertFalse(Braintree_TestHelper::includes($collection, $triallessSubscription));
32
  }
33
 
34
- function test_noRequestsWhenIterating()
35
  {
36
  $resultsReturned = false;
37
- $collection = Braintree_Subscription::search(array(
38
- Braintree_SubscriptionSearch::planId()->is('imaginary')
39
- ));
40
 
41
- foreach($collection as $transaction) {
42
  $resultsReturned = true;
43
  break;
44
  }
@@ -47,204 +53,204 @@ class Braintree_SubscriptionSearchTest extends PHPUnit_Framework_TestCase
47
  $this->assertEquals(false, $resultsReturned);
48
  }
49
 
50
- function testSearch_inTrialPeriod()
51
  {
52
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
53
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
54
- $trialPlan = Braintree_SubscriptionTestHelper::trialPlan();
55
 
56
- $trialSubscription = Braintree_Subscription::create(array(
57
  'paymentMethodToken' => $creditCard->token,
58
  'planId' => $trialPlan['id'],
59
  'price' => '1'
60
- ))->subscription;
61
 
62
- $triallessSubscription = Braintree_Subscription::create(array(
63
  'paymentMethodToken' => $creditCard->token,
64
  'planId' => $triallessPlan['id'],
65
  'price' => '1'
66
- ))->subscription;
67
 
68
- $subscriptions_in_trial = Braintree_Subscription::search(array(
69
- Braintree_SubscriptionSearch::inTrialPeriod()->is(true)
70
- ));
71
 
72
- $this->assertTrue(Braintree_TestHelper::includes($subscriptions_in_trial, $trialSubscription));
73
- $this->assertFalse(Braintree_TestHelper::includes($subscriptions_in_trial, $triallessSubscription));
74
 
75
- $subscriptions_not_in_trial = Braintree_Subscription::search(array(
76
- Braintree_SubscriptionSearch::inTrialPeriod()->is(false)
77
- ));
78
 
79
- $this->assertTrue(Braintree_TestHelper::includes($subscriptions_not_in_trial, $triallessSubscription));
80
- $this->assertFalse(Braintree_TestHelper::includes($subscriptions_not_in_trial, $trialSubscription));
81
  }
82
 
83
- function testSearch_statusIsPastDue()
84
  {
85
  $found = false;
86
- $collection = Braintree_Subscription::search(array(
87
- Braintree_SubscriptionSearch::status()->in(array(Braintree_Subscription::PAST_DUE))
88
- ));
89
  foreach ($collection AS $item) {
90
  $found = true;
91
- $this->assertEquals(Braintree_Subscription::PAST_DUE, $item->status);
92
  }
93
  $this->assertTrue($found);
94
  }
95
 
96
- function testSearch_statusIsExpired()
97
  {
98
  $found = false;
99
- $collection = Braintree_Subscription::search(array(
100
- Braintree_SubscriptionSearch::status()->in(array(Braintree_Subscription::EXPIRED))
101
- ));
102
- foreach ($collection AS $item) {
103
  $found = true;
104
- $this->assertEquals(Braintree_Subscription::EXPIRED, $item->status);
105
  }
106
  $this->assertTrue($found);
107
  }
108
 
109
- function testSearch_billingCyclesRemaing()
110
  {
111
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
112
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
113
 
114
- $subscription_4 = Braintree_Subscription::create(array(
115
  'paymentMethodToken' => $creditCard->token,
116
  'planId' => $triallessPlan['id'],
117
  'numberOfBillingCycles' => 4
118
- ))->subscription;
119
 
120
- $subscription_8 = Braintree_Subscription::create(array(
121
  'paymentMethodToken' => $creditCard->token,
122
  'planId' => $triallessPlan['id'],
123
  'numberOfBillingCycles' => 8
124
- ))->subscription;
125
 
126
- $subscription_10 = Braintree_Subscription::create(array(
127
  'paymentMethodToken' => $creditCard->token,
128
  'planId' => $triallessPlan['id'],
129
  'numberOfBillingCycles' => 10
130
- ))->subscription;
131
 
132
- $collection = Braintree_Subscription::search(array(
133
- Braintree_SubscriptionSearch::billingCyclesRemaining()->between(5, 10)
134
- ));
135
 
136
- $this->assertFalse(Braintree_TestHelper::includes($collection, $subscription_4));
137
- $this->assertTrue(Braintree_TestHelper::includes($collection, $subscription_8));
138
- $this->assertTrue(Braintree_TestHelper::includes($collection, $subscription_10));
139
  }
140
 
141
- function testSearch_subscriptionId()
142
  {
143
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
144
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
145
 
146
  $rand_id = strval(rand());
147
 
148
- $subscription_1 = Braintree_Subscription::create(array(
149
  'paymentMethodToken' => $creditCard->token,
150
  'planId' => $triallessPlan['id'],
151
  'id' => 'subscription_123_id_' . $rand_id
152
- ))->subscription;
153
 
154
- $subscription_2 = Braintree_Subscription::create(array(
155
  'paymentMethodToken' => $creditCard->token,
156
  'planId' => $triallessPlan['id'],
157
  'id' => 'subscription_23_id_' . $rand_id
158
- ))->subscription;
159
 
160
- $subscription_3 = Braintree_Subscription::create(array(
161
  'paymentMethodToken' => $creditCard->token,
162
  'planId' => $triallessPlan['id'],
163
  'id' => 'subscription_3_id_' . $rand_id
164
- ))->subscription;
165
 
166
- $collection = Braintree_Subscription::search(array(
167
- Braintree_SubscriptionSearch::id()->contains("23_id_")
168
- ));
169
 
170
- $this->assertTrue(Braintree_TestHelper::includes($collection, $subscription_1));
171
- $this->assertTrue(Braintree_TestHelper::includes($collection, $subscription_2));
172
- $this->assertFalse(Braintree_TestHelper::includes($collection, $subscription_3));
173
  }
174
 
175
- function testSearch_merchantAccountId()
176
  {
177
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
178
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
179
 
180
  $rand_id = strval(rand());
181
 
182
- $subscription_1 = Braintree_Subscription::create(array(
183
  'paymentMethodToken' => $creditCard->token,
184
  'planId' => $triallessPlan['id'],
185
  'id' => strval(rand()) . '_subscription_' . $rand_id,
186
  'price' => '2'
187
- ))->subscription;
188
 
189
- $subscription_2 = Braintree_Subscription::create(array(
190
  'paymentMethodToken' => $creditCard->token,
191
  'planId' => $triallessPlan['id'],
192
  'id' => strval(rand()) . '_subscription_' . $rand_id,
193
- 'merchantAccountId' => Braintree_TestHelper::nonDefaultMerchantAccountId(),
194
  'price' => '2'
195
- ))->subscription;
196
 
197
- $collection = Braintree_Subscription::search(array(
198
- Braintree_SubscriptionSearch::id()->endsWith('subscription_' . $rand_id),
199
- Braintree_SubscriptionSearch::merchantAccountId()->in(array(Braintree_TestHelper::nonDefaultMerchantAccountId())),
200
- Braintree_SubscriptionSearch::price()->is('2')
201
- ));
202
 
203
- $this->assertFalse(Braintree_TestHelper::includes($collection, $subscription_1));
204
- $this->assertTrue(Braintree_TestHelper::includes($collection, $subscription_2));
205
  }
206
 
207
- function testSearch_bogusMerchantAccountId()
208
  {
209
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
210
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
211
 
212
  $rand_id = strval(rand());
213
 
214
- $subscription = Braintree_Subscription::create(array(
215
  'paymentMethodToken' => $creditCard->token,
216
  'planId' => $triallessPlan['id'],
217
  'id' => strval(rand()) . '_subscription_' . $rand_id,
218
  'price' => '11.38'
219
- ))->subscription;
220
 
221
- $collection = Braintree_Subscription::search(array(
222
- Braintree_SubscriptionSearch::id()->endsWith('subscription_' . $rand_id),
223
- Braintree_SubscriptionSearch::merchantAccountId()->in(array("bogus_merchant_account")),
224
- Braintree_SubscriptionSearch::price()->is('11.38')
225
- ));
226
 
227
- $this->assertFalse(Braintree_TestHelper::includes($collection, $subscription));
228
  }
229
 
230
- function testSearch_daysPastDue()
231
  {
232
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
233
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
234
 
235
- $subscription = Braintree_Subscription::create(array(
236
  'paymentMethodToken' => $creditCard->token,
237
  'planId' => $triallessPlan['id']
238
- ))->subscription;
239
 
240
- $http = new Braintree_Http(Braintree_Configuration::$global);
241
- $path = Braintree_Configuration::$global->merchantPath() . '/subscriptions/' . $subscription->id . '/make_past_due';
242
- $http->put($path, array('daysPastDue' => 5));
243
 
244
  $found = false;
245
- $collection = Braintree_Subscription::search(array(
246
- Braintree_SubscriptionSearch::daysPastDue()->between(2, 10)
247
- ));
248
  foreach ($collection AS $item) {
249
  $found = true;
250
  $this->assertTrue($item->daysPastDue <= 10);
@@ -253,85 +259,85 @@ class Braintree_SubscriptionSearchTest extends PHPUnit_Framework_TestCase
253
  $this->assertTrue($found);
254
  }
255
 
256
- function testSearch_price()
257
  {
258
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
259
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
260
 
261
- $subscription_850 = Braintree_Subscription::create(array(
262
  'paymentMethodToken' => $creditCard->token,
263
  'planId' => $triallessPlan['id'],
264
  'price' => '8.50'
265
- ))->subscription;
266
 
267
- $subscription_851 = Braintree_Subscription::create(array(
268
  'paymentMethodToken' => $creditCard->token,
269
  'planId' => $triallessPlan['id'],
270
  'price' => '8.51'
271
- ))->subscription;
272
 
273
- $subscription_852 = Braintree_Subscription::create(array(
274
  'paymentMethodToken' => $creditCard->token,
275
  'planId' => $triallessPlan['id'],
276
  'price' => '8.52'
277
- ))->subscription;
278
 
279
- $collection = Braintree_Subscription::search(array(
280
- Braintree_SubscriptionSearch::price()->between('8.51', '8.52')
281
- ));
282
 
283
- $this->assertTrue(Braintree_TestHelper::includes($collection, $subscription_851));
284
- $this->assertTrue(Braintree_TestHelper::includes($collection, $subscription_852));
285
- $this->assertFalse(Braintree_TestHelper::includes($collection, $subscription_850));
286
  }
287
 
288
- function testSearch_nextBillingDate()
289
  {
290
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
291
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
292
- $trialPlan = Braintree_SubscriptionTestHelper::trialPlan();
293
 
294
- $triallessSubscription = Braintree_Subscription::create(array(
295
  'paymentMethodToken' => $creditCard->token,
296
  'planId' => $triallessPlan['id'],
297
- ))->subscription;
298
 
299
- $trialSubscription = Braintree_Subscription::create(array(
300
  'paymentMethodToken' => $creditCard->token,
301
  'planId' => $trialPlan['id'],
302
- ))->subscription;
303
 
304
  $fiveDaysFromNow = new DateTime();
305
  $fiveDaysFromNow->modify("+5 days");
306
 
307
- $collection = Braintree_Subscription::search(array(
308
- Braintree_SubscriptionSearch::nextBillingDate()->greaterThanOrEqualTo($fiveDaysFromNow)
309
- ));
310
 
311
- $this->assertTrue(Braintree_TestHelper::includes($collection, $triallessSubscription));
312
- $this->assertFalse(Braintree_TestHelper::includes($collection, $trialSubscription));
313
  }
314
 
315
- function testSearch_transactionId()
316
  {
317
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
318
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
319
 
320
- $matchingSubscription = Braintree_Subscription::create(array(
321
  'paymentMethodToken' => $creditCard->token,
322
  'planId' => $triallessPlan['id'],
323
- ))->subscription;
324
 
325
- $nonMatchingSubscription = Braintree_Subscription::create(array(
326
  'paymentMethodToken' => $creditCard->token,
327
  'planId' => $triallessPlan['id'],
328
- ))->subscription;
329
 
330
- $collection = Braintree_Subscription::search(array(
331
- Braintree_SubscriptionSearch::transactionId()->is($matchingSubscription->transactions[0]->id)
332
- ));
333
 
334
- $this->assertTrue(Braintree_TestHelper::includes($collection, $matchingSubscription));
335
- $this->assertFalse(Braintree_TestHelper::includes($collection, $nonMatchingSubscription));
336
  }
337
  }
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 SubscriptionSearchTest extends Setup
12
  {
13
+ public function testSearch_planIdIs()
14
  {
15
+ $creditCard = SubscriptionHelper::createCreditCard();
16
+ $triallessPlan = SubscriptionHelper::triallessPlan();
17
+ $trialPlan = SubscriptionHelper::trialPlan();
18
 
19
+ $trialSubscription = Braintree\Subscription::create([
20
  'paymentMethodToken' => $creditCard->token,
21
  'planId' => $trialPlan['id'],
22
  'price' => '1'
23
+ ])->subscription;
24
 
25
+ $triallessSubscription = Braintree\Subscription::create([
26
  'paymentMethodToken' => $creditCard->token,
27
  'planId' => $triallessPlan['id'],
28
  'price' => '1'
29
+ ])->subscription;
30
 
31
+ $collection = Braintree\Subscription::search([
32
+ Braintree\SubscriptionSearch::planId()->is('integration_trial_plan'),
33
+ Braintree\SubscriptionSearch::price()->is('1')
34
+ ]);
35
 
36
+ $this->assertTrue(Test\Helper::includes($collection, $trialSubscription));
37
+ $this->assertFalse(Test\Helper::includes($collection, $triallessSubscription));
38
  }
39
 
40
+ public function test_noRequestsWhenIterating()
41
  {
42
  $resultsReturned = false;
43
+ $collection = Braintree\Subscription::search([
44
+ Braintree\SubscriptionSearch::planId()->is('imaginary')
45
+ ]);
46
 
47
+ foreach ($collection as $transaction) {
48
  $resultsReturned = true;
49
  break;
50
  }
53
  $this->assertEquals(false, $resultsReturned);
54
  }
55
 
56
+ public function testSearch_inTrialPeriod()
57
  {
58
+ $creditCard = SubscriptionHelper::createCreditCard();
59
+ $triallessPlan = SubscriptionHelper::triallessPlan();
60
+ $trialPlan = SubscriptionHelper::trialPlan();
61
 
62
+ $trialSubscription = Braintree\Subscription::create([
63
  'paymentMethodToken' => $creditCard->token,
64
  'planId' => $trialPlan['id'],
65
  'price' => '1'
66
+ ])->subscription;
67
 
68
+ $triallessSubscription = Braintree\Subscription::create([
69
  'paymentMethodToken' => $creditCard->token,
70
  'planId' => $triallessPlan['id'],
71
  'price' => '1'
72
+ ])->subscription;
73
 
74
+ $subscriptions_in_trial = Braintree\Subscription::search([
75
+ Braintree\SubscriptionSearch::inTrialPeriod()->is(true)
76
+ ]);
77
 
78
+ $this->assertTrue(Test\Helper::includes($subscriptions_in_trial, $trialSubscription));
79
+ $this->assertFalse(Test\Helper::includes($subscriptions_in_trial, $triallessSubscription));
80
 
81
+ $subscriptions_not_in_trial = Braintree\Subscription::search([
82
+ Braintree\SubscriptionSearch::inTrialPeriod()->is(false)
83
+ ]);
84
 
85
+ $this->assertTrue(Test\Helper::includes($subscriptions_not_in_trial, $triallessSubscription));
86
+ $this->assertFalse(Test\Helper::includes($subscriptions_not_in_trial, $trialSubscription));
87
  }
88
 
89
+ public function testSearch_statusIsPastDue()
90
  {
91
  $found = false;
92
+ $collection = Braintree\Subscription::search([
93
+ Braintree\SubscriptionSearch::status()->in([Braintree\Subscription::PAST_DUE])
94
+ ]);
95
  foreach ($collection AS $item) {
96
  $found = true;
97
+ $this->assertEquals(Braintree\Subscription::PAST_DUE, $item->status);
98
  }
99
  $this->assertTrue($found);
100
  }
101
 
102
+ public function testSearch_statusIsExpired()
103
  {
104
  $found = false;
105
+ $collection = Braintree\Subscription::search([
106
+ Braintree\SubscriptionSearch::status()->in([Braintree\Subscription::EXPIRED])
107
+ ]);
108
+ foreach ($collection as $item) {
109
  $found = true;
110
+ $this->assertEquals(Braintree\Subscription::EXPIRED, $item->status);
111
  }
112
  $this->assertTrue($found);
113
  }
114
 
115
+ public function testSearch_billingCyclesRemaing()
116
  {
117
+ $creditCard = SubscriptionHelper::createCreditCard();
118
+ $triallessPlan = SubscriptionHelper::triallessPlan();
119
 
120
+ $subscription_4 = Braintree\Subscription::create([
121
  'paymentMethodToken' => $creditCard->token,
122
  'planId' => $triallessPlan['id'],
123
  'numberOfBillingCycles' => 4
124
+ ])->subscription;
125
 
126
+ $subscription_8 = Braintree\Subscription::create([
127
  'paymentMethodToken' => $creditCard->token,
128
  'planId' => $triallessPlan['id'],
129
  'numberOfBillingCycles' => 8
130
+ ])->subscription;
131
 
132
+ $subscription_10 = Braintree\Subscription::create([
133
  'paymentMethodToken' => $creditCard->token,
134
  'planId' => $triallessPlan['id'],
135
  'numberOfBillingCycles' => 10
136
+ ])->subscription;
137
 
138
+ $collection = Braintree\Subscription::search([
139
+ Braintree\SubscriptionSearch::billingCyclesRemaining()->between(5, 10)
140
+ ]);
141
 
142
+ $this->assertFalse(Test\Helper::includes($collection, $subscription_4));
143
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_8));
144
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_10));
145
  }
146
 
147
+ public function testSearch_subscriptionId()
148
  {
149
+ $creditCard = SubscriptionHelper::createCreditCard();
150
+ $triallessPlan = SubscriptionHelper::triallessPlan();
151
 
152
  $rand_id = strval(rand());
153
 
154
+ $subscription_1 = Braintree\Subscription::create([
155
  'paymentMethodToken' => $creditCard->token,
156
  'planId' => $triallessPlan['id'],
157
  'id' => 'subscription_123_id_' . $rand_id
158
+ ])->subscription;
159
 
160
+ $subscription_2 = Braintree\Subscription::create([
161
  'paymentMethodToken' => $creditCard->token,
162
  'planId' => $triallessPlan['id'],
163
  'id' => 'subscription_23_id_' . $rand_id
164
+ ])->subscription;
165
 
166
+ $subscription_3 = Braintree\Subscription::create([
167
  'paymentMethodToken' => $creditCard->token,
168
  'planId' => $triallessPlan['id'],
169
  'id' => 'subscription_3_id_' . $rand_id
170
+ ])->subscription;
171
 
172
+ $collection = Braintree\Subscription::search([
173
+ Braintree\SubscriptionSearch::id()->contains('23_id_')
174
+ ]);
175
 
176
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_1));
177
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_2));
178
+ $this->assertFalse(Test\Helper::includes($collection, $subscription_3));
179
  }
180
 
181
+ public function testSearch_merchantAccountId()
182
  {
183
+ $creditCard = SubscriptionHelper::createCreditCard();
184
+ $triallessPlan = SubscriptionHelper::triallessPlan();
185
 
186
  $rand_id = strval(rand());
187
 
188
+ $subscription_1 = Braintree\Subscription::create([
189
  'paymentMethodToken' => $creditCard->token,
190
  'planId' => $triallessPlan['id'],
191
  'id' => strval(rand()) . '_subscription_' . $rand_id,
192
  'price' => '2'
193
+ ])->subscription;
194
 
195
+ $subscription_2 = Braintree\Subscription::create([
196
  'paymentMethodToken' => $creditCard->token,
197
  'planId' => $triallessPlan['id'],
198
  'id' => strval(rand()) . '_subscription_' . $rand_id,
199
+ 'merchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(),
200
  'price' => '2'
201
+ ])->subscription;
202
 
203
+ $collection = Braintree\Subscription::search([
204
+ Braintree\SubscriptionSearch::id()->endsWith('subscription_' . $rand_id),
205
+ Braintree\SubscriptionSearch::merchantAccountId()->in([Test\Helper::nonDefaultMerchantAccountId()]),
206
+ Braintree\SubscriptionSearch::price()->is('2')
207
+ ]);
208
 
209
+ $this->assertFalse(Test\Helper::includes($collection, $subscription_1));
210
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_2));
211
  }
212
 
213
+ public function testSearch_bogusMerchantAccountId()
214
  {
215
+ $creditCard = SubscriptionHelper::createCreditCard();
216
+ $triallessPlan = SubscriptionHelper::triallessPlan();
217
 
218
  $rand_id = strval(rand());
219
 
220
+ $subscription = Braintree\Subscription::create([
221
  'paymentMethodToken' => $creditCard->token,
222
  'planId' => $triallessPlan['id'],
223
  'id' => strval(rand()) . '_subscription_' . $rand_id,
224
  'price' => '11.38'
225
+ ])->subscription;
226
 
227
+ $collection = Braintree\Subscription::search([
228
+ Braintree\SubscriptionSearch::id()->endsWith('subscription_' . $rand_id),
229
+ Braintree\SubscriptionSearch::merchantAccountId()->in(['bogus_merchant_account']),
230
+ Braintree\SubscriptionSearch::price()->is('11.38')
231
+ ]);
232
 
233
+ $this->assertFalse(Test\Helper::includes($collection, $subscription));
234
  }
235
 
236
+ public function testSearch_daysPastDue()
237
  {
238
+ $creditCard = SubscriptionHelper::createCreditCard();
239
+ $triallessPlan = SubscriptionHelper::triallessPlan();
240
 
241
+ $subscription = Braintree\Subscription::create([
242
  'paymentMethodToken' => $creditCard->token,
243
  'planId' => $triallessPlan['id']
244
+ ])->subscription;
245
 
246
+ $http = new Braintree\Http(Braintree\Configuration::$global);
247
+ $path = Braintree\Configuration::$global->merchantPath() . '/subscriptions/' . $subscription->id . '/make_past_due';
248
+ $http->put($path, ['daysPastDue' => 5]);
249
 
250
  $found = false;
251
+ $collection = Braintree\Subscription::search([
252
+ Braintree\SubscriptionSearch::daysPastDue()->between(2, 10)
253
+ ]);
254
  foreach ($collection AS $item) {
255
  $found = true;
256
  $this->assertTrue($item->daysPastDue <= 10);
259
  $this->assertTrue($found);
260
  }
261
 
262
+ public function testSearch_price()
263
  {
264
+ $creditCard = SubscriptionHelper::createCreditCard();
265
+ $triallessPlan = SubscriptionHelper::triallessPlan();
266
 
267
+ $subscription_850 = Braintree\Subscription::create([
268
  'paymentMethodToken' => $creditCard->token,
269
  'planId' => $triallessPlan['id'],
270
  'price' => '8.50'
271
+ ])->subscription;
272
 
273
+ $subscription_851 = Braintree\Subscription::create([
274
  'paymentMethodToken' => $creditCard->token,
275
  'planId' => $triallessPlan['id'],
276
  'price' => '8.51'
277
+ ])->subscription;
278
 
279
+ $subscription_852 = Braintree\Subscription::create([
280
  'paymentMethodToken' => $creditCard->token,
281
  'planId' => $triallessPlan['id'],
282
  'price' => '8.52'
283
+ ])->subscription;
284
 
285
+ $collection = Braintree\Subscription::search([
286
+ Braintree\SubscriptionSearch::price()->between('8.51', '8.52')
287
+ ]);
288
 
289
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_851));
290
+ $this->assertTrue(Test\Helper::includes($collection, $subscription_852));
291
+ $this->assertFalse(Test\Helper::includes($collection, $subscription_850));
292
  }
293
 
294
+ public function testSearch_nextBillingDate()
295
  {
296
+ $creditCard = SubscriptionHelper::createCreditCard();
297
+ $triallessPlan = SubscriptionHelper::triallessPlan();
298
+ $trialPlan = SubscriptionHelper::trialPlan();
299
 
300
+ $triallessSubscription = Braintree\Subscription::create([
301
  'paymentMethodToken' => $creditCard->token,
302
  'planId' => $triallessPlan['id'],
303
+ ])->subscription;
304
 
305
+ $trialSubscription = Braintree\Subscription::create([
306
  'paymentMethodToken' => $creditCard->token,
307
  'planId' => $trialPlan['id'],
308
+ ])->subscription;
309
 
310
  $fiveDaysFromNow = new DateTime();
311
  $fiveDaysFromNow->modify("+5 days");
312
 
313
+ $collection = Braintree\Subscription::search([
314
+ Braintree\SubscriptionSearch::nextBillingDate()->greaterThanOrEqualTo($fiveDaysFromNow),
315
+ ]);
316
 
317
+ $this->assertTrue(Test\Helper::includes($collection, $triallessSubscription));
318
+ $this->assertFalse(Test\Helper::includes($collection, $trialSubscription));
319
  }
320
 
321
+ public function testSearch_transactionId()
322
  {
323
+ $creditCard = SubscriptionHelper::createCreditCard();
324
+ $triallessPlan = SubscriptionHelper::triallessPlan();
325
 
326
+ $matchingSubscription = Braintree\Subscription::create([
327
  'paymentMethodToken' => $creditCard->token,
328
  'planId' => $triallessPlan['id'],
329
+ ])->subscription;
330
 
331
+ $nonMatchingSubscription = Braintree\Subscription::create([
332
  'paymentMethodToken' => $creditCard->token,
333
  'planId' => $triallessPlan['id'],
334
+ ])->subscription;
335
 
336
+ $collection = Braintree\Subscription::search([
337
+ Braintree\SubscriptionSearch::transactionId()->is($matchingSubscription->transactions[0]->id),
338
+ ]);
339
 
340
+ $this->assertTrue(Test\Helper::includes($collection, $matchingSubscription));
341
+ $this->assertFalse(Test\Helper::includes($collection, $nonMatchingSubscription));
342
  }
343
  }
braintree_sdk/tests/integration/SubscriptionTest.php CHANGED
@@ -1,35 +1,40 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/SubscriptionTestHelper.php';
4
- require_once realpath(dirname(__FILE__)) . '/HttpClientApi.php';
5
 
6
- class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
 
7
  {
8
- function testCreate_doesNotAcceptBadAttributes()
9
  {
10
  $this->setExpectedException('InvalidArgumentException', 'invalid keys: bad');
11
- $result = Braintree_Subscription::create(array(
12
  'bad' => 'value'
13
- ));
14
  }
15
 
16
- function testCreate_whenSuccessful()
17
  {
18
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
19
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
20
- $result = Braintree_Subscription::create(array(
21
  'paymentMethodToken' => $creditCard->token,
22
  'planId' => $plan['id']
23
 
24
- ));
25
- Braintree_TestHelper::assertPrintable($result);
26
  $this->assertTrue($result->success);
27
  $subscription = $result->subscription;
28
  $this->assertEquals($creditCard->token, $subscription->paymentMethodToken);
29
  $this->assertEquals(0, $subscription->failureCount);
30
  $this->assertEquals($plan['id'], $subscription->planId);
31
- $this->assertEquals(Braintree_TestHelper::defaultMerchantAccountId(), $subscription->merchantAccountId);
32
- $this->assertEquals(Braintree_Subscription::ACTIVE, $subscription->status);
33
  $this->assertEquals('12.34', $subscription->nextBillAmount);
34
  $this->assertEquals('12.34', $subscription->nextBillingPeriodAmount);
35
  $this->assertEquals('0.00', $subscription->balance);
@@ -44,54 +49,54 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
44
 
45
  $this->assertEquals('12.34', $subscription->statusHistory[0]->price);
46
  $this->assertEquals('0.00', $subscription->statusHistory[0]->balance);
47
- $this->assertEquals(Braintree_Subscription::ACTIVE, $subscription->statusHistory[0]->status);
48
- $this->assertEquals(Braintree_Subscription::API, $subscription->statusHistory[0]->subscriptionSource);
49
  }
50
 
51
- function testGatewayCreate_whenSuccessful()
52
  {
53
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
54
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
55
 
56
- $gateway = new Braintree_Gateway(array(
57
  'environment' => 'development',
58
  'merchantId' => 'integration_merchant_id',
59
  'publicKey' => 'integration_public_key',
60
  'privateKey' => 'integration_private_key'
61
- ));
62
- $result = $gateway->subscription()->create(array(
63
  'paymentMethodToken' => $creditCard->token,
64
  'planId' => $plan['id']
65
 
66
- ));
67
- Braintree_TestHelper::assertPrintable($result);
68
  $this->assertTrue($result->success);
69
  $subscription = $result->subscription;
70
  $this->assertEquals($creditCard->token, $subscription->paymentMethodToken);
71
  $this->assertEquals(0, $subscription->failureCount);
72
  $this->assertEquals($plan['id'], $subscription->planId);
73
- $this->assertEquals(Braintree_TestHelper::defaultMerchantAccountId(), $subscription->merchantAccountId);
74
- $this->assertEquals(Braintree_Subscription::ACTIVE, $subscription->status);
75
  }
76
 
77
- function testCreate_withPaymentMethodNonce()
78
  {
79
- $customerId = Braintree_Customer::create()->customer->id;
80
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
81
- $nonce = $http->nonce_for_new_card(array(
82
- "creditCard" => array(
83
  "number" => "4111111111111111",
84
  "expirationMonth" => "11",
85
  "expirationYear" => "2099"
86
- ),
87
  "customerId" => $customerId,
88
  "share" => true
89
- ));
90
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
91
- $result = Braintree_Subscription::create(array(
92
  'paymentMethodNonce' => $nonce,
93
  'planId' => $plan['id']
94
- ));
95
 
96
  $this->assertTrue($result->success);
97
 
@@ -100,309 +105,309 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
100
  $this->assertEquals("1111", $transaction->creditCardDetails->last4);
101
  }
102
 
103
- function testCreate_returnsTransactionWhenTransactionFails()
104
  {
105
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
106
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
107
- $result = Braintree_Subscription::create(array(
108
  'paymentMethodToken' => $creditCard->token,
109
  'planId' => $plan['id'],
110
- 'price' => Braintree_Test_TransactionAmounts::$decline
111
 
112
- ));
113
- Braintree_TestHelper::assertPrintable($result);
114
  $this->assertFalse($result->success);
115
- $this->assertEquals(Braintree_Transaction::PROCESSOR_DECLINED, $result->transaction->status);
116
  }
117
 
118
- function testCreate_canSetTheId()
119
  {
120
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
121
  $newId = strval(rand());
122
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
123
- $result = Braintree_Subscription::create(array(
124
  'paymentMethodToken' => $creditCard->token,
125
  'planId' => $plan['id'],
126
  'id' => $newId
127
- ));
128
 
129
  $this->assertTrue($result->success);
130
  $subscription = $result->subscription;
131
  $this->assertEquals($newId, $subscription->id);
132
  }
133
 
134
- function testCreate_canSetTheMerchantAccountId()
135
  {
136
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
137
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
138
- $result = Braintree_Subscription::create(array(
139
  'paymentMethodToken' => $creditCard->token,
140
  'planId' => $plan['id'],
141
- 'merchantAccountId' => Braintree_TestHelper::nonDefaultMerchantAccountId()
142
- ));
143
 
144
  $this->assertTrue($result->success);
145
  $subscription = $result->subscription;
146
- $this->assertEquals(Braintree_TestHelper::nonDefaultMerchantAccountId(), $subscription->merchantAccountId);
147
  }
148
 
149
- function testCreate_trialPeriodDefaultsToPlanWithoutTrial()
150
  {
151
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
152
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
153
- $result = Braintree_Subscription::create(array(
154
  'paymentMethodToken' => $creditCard->token,
155
  'planId' => $plan['id'],
156
- ));
157
  $subscription = $result->subscription;
158
  $this->assertFalse($subscription->trialPeriod);
159
  $this->assertNull($subscription->trialDuration);
160
  $this->assertNull($subscription->trialDurationUnit);
161
  }
162
 
163
- function testCreate_trialPeriondDefaultsToPlanWithTrial()
164
  {
165
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
166
- $plan = Braintree_SubscriptionTestHelper::trialPlan();
167
- $result = Braintree_Subscription::create(array(
168
  'paymentMethodToken' => $creditCard->token,
169
  'planId' => $plan['id'],
170
- ));
171
  $subscription = $result->subscription;
172
  $this->assertTrue($subscription->trialPeriod);
173
  $this->assertEquals(2, $subscription->trialDuration);
174
  $this->assertEquals('day', $subscription->trialDurationUnit);
175
  }
176
 
177
- function testCreate_alterPlanTrialPeriod()
178
  {
179
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
180
- $plan = Braintree_SubscriptionTestHelper::trialPlan();
181
- $result = Braintree_Subscription::create(array(
182
  'paymentMethodToken' => $creditCard->token,
183
  'planId' => $plan['id'],
184
  'trialDuration' => 5,
185
  'trialDurationUnit' => 'month'
186
- ));
187
  $subscription = $result->subscription;
188
  $this->assertTrue($subscription->trialPeriod);
189
  $this->assertEquals(5, $subscription->trialDuration);
190
  $this->assertEquals('month', $subscription->trialDurationUnit);
191
  }
192
 
193
- function testCreate_removePlanTrialPeriod()
194
  {
195
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
196
- $plan = Braintree_SubscriptionTestHelper::trialPlan();
197
- $result = Braintree_Subscription::create(array(
198
  'paymentMethodToken' => $creditCard->token,
199
  'planId' => $plan['id'],
200
  'trialPeriod' => false,
201
- ));
202
  $subscription = $result->subscription;
203
  $this->assertFalse($subscription->trialPeriod);
204
  }
205
 
206
- function testCreate_createsATransactionIfNoTrialPeriod()
207
  {
208
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
209
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
210
- $result = Braintree_Subscription::create(array(
211
  'paymentMethodToken' => $creditCard->token,
212
  'planId' => $plan['id'],
213
- ));
214
  $subscription = $result->subscription;
215
  $this->assertEquals(1, sizeof($subscription->transactions));
216
  $transaction = $subscription->transactions[0];
217
- $this->assertInstanceOf('Braintree_Transaction', $transaction);
218
  $this->assertEquals($plan['price'], $transaction->amount);
219
- $this->assertEquals(Braintree_Transaction::SALE, $transaction->type);
220
  $this->assertEquals($subscription->id, $transaction->subscriptionId);
221
  }
222
 
223
- function testCreate_doesNotCreateTransactionIfTrialPeriod()
224
  {
225
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
226
- $plan = Braintree_SubscriptionTestHelper::trialPlan();
227
- $result = Braintree_Subscription::create(array(
228
  'paymentMethodToken' => $creditCard->token,
229
  'planId' => $plan['id'],
230
- ));
231
  $subscription = $result->subscription;
232
  $this->assertEquals(0, sizeof($subscription->transactions));
233
  }
234
 
235
- function testCreate_returnsATransactionWithSubscriptionBillingPeriod()
236
  {
237
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
238
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
239
- $result = Braintree_Subscription::create(array(
240
  'paymentMethodToken' => $creditCard->token,
241
  'planId' => $plan['id'],
242
- ));
243
  $subscription = $result->subscription;
244
  $transaction = $subscription->transactions[0];
245
  $this->assertEquals($subscription->billingPeriodStartDate, $transaction->subscriptionDetails->billingPeriodStartDate);
246
  $this->assertEquals($subscription->billingPeriodEndDate, $transaction->subscriptionDetails->billingPeriodEndDate);
247
  }
248
 
249
- function testCreate_priceCanBeOverriden()
250
  {
251
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
252
- $plan = Braintree_SubscriptionTestHelper::trialPlan();
253
- $result = Braintree_Subscription::create(array(
254
  'paymentMethodToken' => $creditCard->token,
255
  'planId' => $plan['id'],
256
  'price' => '2.00'
257
- ));
258
  $subscription = $result->subscription;
259
  $this->assertEquals('2.00', $subscription->price);
260
  }
261
 
262
- function testCreate_billingDayOfMonthIsInheritedFromPlan()
263
  {
264
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
265
- $plan = Braintree_SubscriptionTestHelper::billingDayOfMonthPlan();
266
- $result = Braintree_Subscription::create(array(
267
  'paymentMethodToken' => $creditCard->token,
268
  'planId' => $plan['id']
269
- ));
270
  $subscription = $result->subscription;
271
  $this->assertEquals(5, $subscription->billingDayOfMonth);
272
  }
273
 
274
- function testCreate_billingDayOfMonthCanBeOverriden()
275
  {
276
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
277
- $plan = Braintree_SubscriptionTestHelper::billingDayOfMonthPlan();
278
- $result = Braintree_Subscription::create(array(
279
  'paymentMethodToken' => $creditCard->token,
280
  'planId' => $plan['id'],
281
  'billingDayOfMonth' => 14
282
- ));
283
  $subscription = $result->subscription;
284
  $this->assertEquals(14, $subscription->billingDayOfMonth);
285
  }
286
 
287
- function testCreate_billingDayOfMonthCanBeOverridenWithStartImmediately()
288
  {
289
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
290
- $plan = Braintree_SubscriptionTestHelper::billingDayOfMonthPlan();
291
- $result = Braintree_Subscription::create(array(
292
  'paymentMethodToken' => $creditCard->token,
293
  'planId' => $plan['id'],
294
- 'options' => array('startImmediately' => true)
295
- ));
296
  $subscription = $result->subscription;
297
  $this->assertEquals(1, sizeof($subscription->transactions));
298
  }
299
 
300
- function testCreate_firstBillingDateCanBeSet()
301
  {
302
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
303
- $plan = Braintree_SubscriptionTestHelper::billingDayOfMonthPlan();
304
 
305
  $tomorrow = new DateTime("now + 1 day");
306
  $tomorrow->setTime(0,0,0);
307
 
308
- $result = Braintree_Subscription::create(array(
309
  'paymentMethodToken' => $creditCard->token,
310
  'planId' => $plan['id'],
311
  'firstBillingDate' => $tomorrow
312
- ));
313
 
314
  $subscription = $result->subscription;
315
  $this->assertEquals($tomorrow, $subscription->firstBillingDate);
316
- $this->assertEquals(Braintree_Subscription::PENDING, $result->subscription->status);
317
  }
318
 
319
- function testCreate_firstBillingDateInThePast()
320
  {
321
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
322
- $plan = Braintree_SubscriptionTestHelper::billingDayOfMonthPlan();
323
 
324
  $past = new DateTime("now - 3 days");
325
  $past->setTime(0,0,0);
326
 
327
- $result = Braintree_Subscription::create(array(
328
  'paymentMethodToken' => $creditCard->token,
329
  'planId' => $plan['id'],
330
  'firstBillingDate' => $past
331
- ));
332
 
333
  $this->assertFalse($result->success);
334
  $errors = $result->errors->forKey('subscription')->onAttribute('firstBillingDate');
335
- $this->assertEquals(Braintree_Error_Codes::SUBSCRIPTION_FIRST_BILLING_DATE_CANNOT_BE_IN_THE_PAST, $errors[0]->code);
336
  }
337
 
338
- function testCreate_numberOfBillingCyclesCanBeOverridden()
339
  {
340
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
341
- $plan = Braintree_SubscriptionTestHelper::trialPlan();
342
- $result = Braintree_Subscription::create(array(
343
  'paymentMethodToken' => $creditCard->token,
344
  'planId' => $plan['id']
345
- ));
346
  $subscription = $result->subscription;
347
  $this->assertEquals($plan['numberOfBillingCycles'], $subscription->numberOfBillingCycles);
348
 
349
- $result = Braintree_Subscription::create(array(
350
  'numberOfBillingCycles' => '10',
351
  'paymentMethodToken' => $creditCard->token,
352
  'planId' => $plan['id']
353
- ));
354
  $subscription = $result->subscription;
355
  $this->assertEquals(10, $subscription->numberOfBillingCycles);
356
  $this->assertFalse($subscription->neverExpires);
357
  }
358
 
359
- function testCreate_numberOfBillingCyclesCanBeOverriddenToNeverExpire()
360
  {
361
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
362
- $plan = Braintree_SubscriptionTestHelper::trialPlan();
363
- $result = Braintree_Subscription::create(array(
364
  'paymentMethodToken' => $creditCard->token,
365
  'planId' => $plan['id']
366
- ));
367
  $subscription = $result->subscription;
368
  $this->assertEquals($plan['numberOfBillingCycles'], $subscription->numberOfBillingCycles);
369
 
370
- $result = Braintree_Subscription::create(array(
371
  'neverExpires' => true,
372
  'paymentMethodToken' => $creditCard->token,
373
  'planId' => $plan['id']
374
- ));
375
  $subscription = $result->subscription;
376
  $this->assertNull($subscription->numberOfBillingCycles);
377
  $this->assertTrue($subscription->neverExpires);
378
  }
379
 
380
- function testCreate_doesNotInheritAddOnsAndDiscountsWhenDoNotInheritAddOnsOrDiscountsIsSet()
381
  {
382
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
383
- $plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
384
- $result = Braintree_Subscription::create(array(
385
  'paymentMethodToken' => $creditCard->token,
386
  'planId' => $plan['id'],
387
- 'options' => array('doNotInheritAddOnsOrDiscounts' => true)
388
- ));
389
  $subscription = $result->subscription;
390
  $this->assertEquals(0, sizeof($subscription->addOns));
391
  $this->assertEquals(0, sizeof($subscription->discounts));
392
  }
393
 
394
- function testCreate_inheritsAddOnsAndDiscountsFromPlanByDefault()
395
  {
396
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
397
- $plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
398
- $result = Braintree_Subscription::create(array(
399
  'paymentMethodToken' => $creditCard->token,
400
  'planId' => $plan['id'],
401
- ));
402
  $subscription = $result->subscription;
403
  $this->assertEquals(2, sizeof($subscription->addOns));
404
  $addOns = $subscription->addOns;
405
- Braintree_SubscriptionTestHelper::sortModificationsById($addOns);
406
 
407
  $this->assertEquals($addOns[0]->amount, "10.00");
408
  $this->assertEquals($addOns[0]->quantity, 1);
@@ -418,7 +423,7 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
418
 
419
  $this->assertEquals(2, sizeof($subscription->discounts));
420
  $discounts = $subscription->discounts;
421
- Braintree_SubscriptionTestHelper::sortModificationsById($discounts);
422
 
423
  $this->assertEquals($discounts[0]->amount, "11.00");
424
  $this->assertEquals($discounts[0]->quantity, 1);
@@ -433,44 +438,44 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
433
  $this->assertEquals($discounts[1]->currentBillingCycle, 0);
434
  }
435
 
436
- function testCreate_allowsOverridingInheritedAddOnsAndDiscounts()
437
  {
438
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
439
- $plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
440
- $result = Braintree_Subscription::create(array(
441
  'paymentMethodToken' => $creditCard->token,
442
  'planId' => $plan['id'],
443
- 'addOns' => array(
444
- 'update' => array(
445
- array(
446
  'amount' => '50.00',
447
  'existingId' => 'increase_10',
448
  'quantity' => 2,
449
  'numberOfBillingCycles' => 5
450
- ),
451
- array(
452
  'amount' => '60.00',
453
  'existingId' => 'increase_20',
454
  'quantity' => 4,
455
  'numberOfBillingCycles' => 9
456
- )
457
- ),
458
- ),
459
- 'discounts' => array(
460
- 'update' => array(
461
- array(
462
  'amount' => '15.00',
463
  'existingId' => 'discount_7',
464
  'quantity' => 2,
465
  'neverExpires' => true
466
- )
467
- )
468
- )
469
- ));
470
  $subscription = $result->subscription;
471
  $this->assertEquals(2, sizeof($subscription->addOns));
472
  $addOns = $subscription->addOns;
473
- Braintree_SubscriptionTestHelper::sortModificationsById($addOns);
474
 
475
  $this->assertEquals($addOns[0]->amount, "50.00");
476
  $this->assertEquals($addOns[0]->quantity, 2);
@@ -486,7 +491,7 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
486
 
487
  $this->assertEquals(2, sizeof($subscription->discounts));
488
  $discounts = $subscription->discounts;
489
- Braintree_SubscriptionTestHelper::sortModificationsById($discounts);
490
 
491
  $this->assertEquals($discounts[0]->amount, "11.00");
492
  $this->assertEquals($discounts[0]->quantity, 1);
@@ -501,20 +506,20 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
501
  $this->assertEquals($discounts[1]->currentBillingCycle, 0);
502
  }
503
 
504
- function testCreate_allowsRemovalOfInheritedAddOnsAndDiscounts()
505
  {
506
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
507
- $plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
508
- $result = Braintree_Subscription::create(array(
509
  'paymentMethodToken' => $creditCard->token,
510
  'planId' => $plan['id'],
511
- 'addOns' => array(
512
- 'remove' => array('increase_10', 'increase_20')
513
- ),
514
- 'discounts' => array(
515
- 'remove' => array('discount_7')
516
- )
517
- ));
518
  $subscription = $result->subscription;
519
  $this->assertEquals(0, sizeof($subscription->addOns));
520
 
@@ -527,39 +532,39 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
527
  $this->assertEquals($subscription->discounts[0]->currentBillingCycle, 0);
528
  }
529
 
530
- function testCreate_allowsAddingNewAddOnsAndDiscounts()
531
  {
532
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
533
- $plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
534
- $result = Braintree_Subscription::create(array(
535
  'paymentMethodToken' => $creditCard->token,
536
  'planId' => $plan['id'],
537
- 'addOns' => array(
538
- 'add' => array(
539
- array(
540
  'inheritedFromId' => 'increase_30',
541
  'amount' => '35.00',
542
  'neverExpires' => true,
543
  'quantity' => 2
544
- ),
545
- ),
546
- ),
547
- 'discounts' => array(
548
- 'add' => array(
549
- array(
550
  'inheritedFromId' => 'discount_15',
551
  'amount' => '15.50',
552
  'numberOfBillingCycles' => 10,
553
  'quantity' => 3
554
- )
555
- )
556
- )
557
- ));
558
 
559
  $subscription = $result->subscription;
560
  $this->assertEquals(3, sizeof($subscription->addOns));
561
  $addOns = $subscription->addOns;
562
- Braintree_SubscriptionTestHelper::sortModificationsById($addOns);
563
 
564
  $this->assertEquals($addOns[0]->amount, "10.00");
565
  $this->assertEquals($addOns[1]->amount, "20.00");
@@ -573,7 +578,7 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
573
 
574
  $this->assertEquals(3, sizeof($subscription->discounts));
575
  $discounts = $subscription->discounts;
576
- Braintree_SubscriptionTestHelper::sortModificationsById($discounts);
577
 
578
  $this->assertEquals($discounts[0]->amount, "11.00");
579
 
@@ -587,47 +592,47 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
587
  $this->assertEquals($discounts[2]->amount, "7.00");
588
  }
589
 
590
- function testCreate_properlyParsesValidationErrorsForArrays()
591
  {
592
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
593
- $plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
594
- $result = Braintree_Subscription::create(array(
595
  'paymentMethodToken' => $creditCard->token,
596
  'planId' => $plan['id'],
597
- 'addOns' => array(
598
- 'update' => array(
599
- array(
600
  'existingId' => 'increase_10',
601
  'amount' => 'invalid',
602
- ),
603
- array(
604
  'existingId' => 'increase_20',
605
  'quantity' => -10,
606
- )
607
- )
608
- )
609
- ));
610
 
611
  $this->assertFalse($result->success);
612
  $errors = $result->errors->forKey('subscription')->forKey('addOns')->forKey('update')->forIndex(0)->onAttribute('amount');
613
- $this->assertEquals(Braintree_Error_Codes::SUBSCRIPTION_MODIFICATION_AMOUNT_IS_INVALID, $errors[0]->code);
614
  $errors = $result->errors->forKey('subscription')->forKey('addOns')->forKey('update')->forIndex(1)->onAttribute('quantity');
615
- $this->assertEquals(Braintree_Error_Codes::SUBSCRIPTION_MODIFICATION_QUANTITY_IS_INVALID, $errors[0]->code);
616
  }
617
 
618
- function testCreate_withDescriptor()
619
  {
620
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
621
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
622
- $result = Braintree_Subscription::create(array(
623
  'paymentMethodToken' => $creditCard->token,
624
  'planId' => $plan['id'],
625
- 'descriptor' => array(
626
  'name' => '123*123456789012345678',
627
  'phone' => '3334445555',
628
  'url' => 'ebay.com'
629
- )
630
- ));
631
  $this->assertTrue($result->success);
632
  $subscription = $result->subscription;
633
  $this->assertEquals('123*123456789012345678', $subscription->descriptor->name);
@@ -639,359 +644,359 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
639
  $this->assertEquals('ebay.com', $transaction->descriptor->url);
640
  }
641
 
642
- function testCreate_withDescriptorValidation()
643
  {
644
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
645
- $plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
646
- $result = Braintree_Subscription::create(array(
647
  'paymentMethodToken' => $creditCard->token,
648
  'planId' => $plan['id'],
649
- 'descriptor' => array(
650
  'name' => 'xxxxxx',
651
  'phone' => 'xxxx',
652
  'url' => '12345678901234'
653
- )
654
- ));
655
  $this->assertFalse($result->success);
656
  $subscription = $result->subscription;
657
 
658
  $errors = $result->errors->forKey('subscription')->forKey('descriptor')->onAttribute('name');
659
- $this->assertEquals(Braintree_Error_Codes::DESCRIPTOR_NAME_FORMAT_IS_INVALID, $errors[0]->code);
660
 
661
  $errors = $result->errors->forKey('subscription')->forKey('descriptor')->onAttribute('phone');
662
- $this->assertEquals(Braintree_Error_Codes::DESCRIPTOR_PHONE_FORMAT_IS_INVALID, $errors[0]->code);
663
 
664
  $errors = $result->errors->forKey('subscription')->forKey('descriptor')->onAttribute('url');
665
- $this->assertEquals(Braintree_Error_Codes::DESCRIPTOR_URL_FORMAT_IS_INVALID, $errors[0]->code);
666
  }
667
 
668
- function testCreate_fromPayPalACcount()
669
  {
670
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
671
- $customer = Braintree_Customer::createNoValidate();
672
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
673
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
674
- $nonce = $http->nonceForPayPalAccount(array(
675
- 'paypal_account' => array(
676
  'consent_code' => 'PAYPAL_CONSENT_CODE',
677
  'token' => $paymentMethodToken
678
- )
679
- ));
680
 
681
- $paypalResult = Braintree_PaymentMethod::create(array(
682
  'customerId' => $customer->id,
683
  'paymentMethodNonce' => $nonce
684
- ));
685
 
686
- $subscriptionResult = Braintree_Subscription::create(array(
687
  'paymentMethodToken' => $paymentMethodToken,
688
  'planId' => $plan['id']
689
 
690
- ));
691
  $this->assertTrue($subscriptionResult->success);
692
  $transaction = $subscriptionResult->subscription->transactions[0];
693
  $this->assertEquals('payer@example.com', $transaction->paypalDetails->payerEmail);
694
  }
695
 
696
- function testCreate_fromPayPalACcountDoesNotWorkWithFutureNonce()
697
  {
698
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
699
- $nonce = Braintree_Test_Nonces::$paypalFuturePayment;
700
 
701
- $subscriptionResult = Braintree_Subscription::create(array(
702
  'paymentMethodNonce' => $nonce,
703
  'planId' => $plan['id']
704
 
705
- ));
706
  $this->assertFalse($subscriptionResult->success);
707
  $errors = $subscriptionResult->errors->forKey('subscription')->errors;
708
- $this->assertEquals(Braintree_Error_Codes::SUBSCRIPTION_PAYMENT_METHOD_NONCE_IS_INVALID, $errors[0]->code);
709
  }
710
 
711
- function testCreate_fromPayPalACcountDoesNotWorkWithOnetimeNonce()
712
  {
713
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
714
- $nonce = Braintree_Test_Nonces::$paypalOneTimePayment;
715
 
716
- $subscriptionResult = Braintree_Subscription::create(array(
717
  'paymentMethodNonce' => $nonce,
718
  'planId' => $plan['id']
719
 
720
- ));
721
  $this->assertFalse($subscriptionResult->success);
722
  $errors = $subscriptionResult->errors->forKey('subscription')->errors;
723
- $this->assertEquals(Braintree_Error_Codes::SUBSCRIPTION_PAYMENT_METHOD_NONCE_IS_INVALID, $errors[0]->code);
724
  }
725
 
726
- function testValidationErrors_hasValidationErrorsOnId()
727
  {
728
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
729
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
730
- $result = Braintree_Subscription::create(array(
731
  'paymentMethodToken' => $creditCard->token,
732
  'planId' => $plan['id'],
733
  'id' => 'invalid token'
734
- ));
735
  $this->assertFalse($result->success);
736
  $errors = $result->errors->forKey('subscription')->onAttribute('id');
737
- $this->assertEquals(Braintree_Error_Codes::SUBSCRIPTION_TOKEN_FORMAT_IS_INVALID, $errors[0]->code);
738
  }
739
 
740
- function testFind()
741
  {
742
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
743
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
744
- $result = Braintree_Subscription::create(array(
745
  'paymentMethodToken' => $creditCard->token,
746
  'planId' => $plan['id']
747
- ));
748
  $this->assertTrue($result->success);
749
- $subscription = Braintree_Subscription::find($result->subscription->id);
750
  $this->assertEquals($result->subscription->id, $subscription->id);
751
  $this->assertEquals($plan['id'], $subscription->planId);
752
  }
753
 
754
- function testFind_throwsIfNotFound()
755
  {
756
- $this->setExpectedException('Braintree_Exception_NotFound', 'subscription with id does-not-exist not found');
757
- Braintree_Subscription::find('does-not-exist');
758
 
759
  }
760
 
761
- function testUpdate_whenSuccessful()
762
  {
763
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
764
  $newId = strval(rand());
765
- $newPlan = Braintree_SubscriptionTestHelper::trialPlan();
766
- $result = Braintree_Subscription::update($subscription->id, array(
767
  'id' => $newId,
768
  'price' => '999.99',
769
  'planId' => $newPlan['id']
770
- ));
771
  $this->assertTrue($result->success);
772
  $this->assertEquals($newId, $result->subscription->id);
773
  $this->assertEquals($newPlan['id'], $result->subscription->planId);
774
  $this->assertEquals('999.99', $result->subscription->price);
775
  }
776
 
777
- function testUpdate_doesNotAcceptBadAttributes()
778
  {
779
  $this->setExpectedException('InvalidArgumentException', 'invalid keys: bad');
780
- $result = Braintree_Subscription::update('id', array(
781
  'bad' => 'value'
782
- ));
783
  }
784
 
785
- function testUpdate_canUpdateNumberOfBillingCycles()
786
  {
787
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
788
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
789
  $this->assertEquals($plan['numberOfBillingCycles'], $subscription->numberOfBillingCycles);
790
 
791
- $updatedSubscription = Braintree_Subscription::update($subscription->id, array(
792
  'numberOfBillingCycles' => 15
793
- ))->subscription;
794
  $this->assertEquals(15, $updatedSubscription->numberOfBillingCycles);
795
  }
796
 
797
- function testUpdate_canUpdateNumberOfBillingCyclesToNeverExpire()
798
  {
799
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
800
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
801
  $this->assertEquals($plan['numberOfBillingCycles'], $subscription->numberOfBillingCycles);
802
 
803
- $updatedSubscription = Braintree_Subscription::update($subscription->id, array(
804
  'neverExpires' => true
805
- ))->subscription;
806
  $this->assertNull($updatedSubscription->numberOfBillingCycles);
807
  }
808
 
809
- function testUpdate_createsTransactionOnProration()
810
  {
811
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
812
- $result = Braintree_Subscription::update($subscription->id, array(
813
  'price' => $subscription->price + 1,
814
- ));
815
  $this->assertTrue($result->success);
816
  $this->assertEquals(sizeof($subscription->transactions) + 1, sizeof($result->subscription->transactions));
817
  }
818
 
819
- function testUpdate_createsProratedTransactionWhenFlagIsPassedTrue()
820
  {
821
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
822
- $result = Braintree_Subscription::update($subscription->id, array(
823
  'price' => $subscription->price + 1,
824
- 'options' => array('prorateCharges' => true)
825
- ));
826
  $this->assertTrue($result->success);
827
  $this->assertEquals(sizeof($subscription->transactions) + 1, sizeof($result->subscription->transactions));
828
  }
829
 
830
- function testUpdate_createsProratedTransactionWhenFlagIsPassedFalse()
831
  {
832
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
833
- $result = Braintree_Subscription::update($subscription->id, array(
834
  'price' => $subscription->price + 1,
835
- 'options' => array('prorateCharges' => false)
836
- ));
837
  $this->assertTrue($result->success);
838
  $this->assertEquals(sizeof($subscription->transactions), sizeof($result->subscription->transactions));
839
  }
840
 
841
- function testUpdate_DoesNotUpdateSubscriptionWhenProrationTransactionFailsAndRevertIsTrue()
842
  {
843
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
844
- $result = Braintree_Subscription::update($subscription->id, array(
845
  'price' => $subscription->price + 2100,
846
- 'options' => array('prorateCharges' => true, 'revertSubscriptionOnProrationFailure' => true)
847
- ));
848
  $this->assertFalse($result->success);
849
  $this->assertEquals(sizeof($subscription->transactions) + 1, sizeof($result->subscription->transactions));
850
- $this->assertEquals(Braintree_Transaction::PROCESSOR_DECLINED, $result->subscription->transactions[0]->status);
851
  $this->assertEquals("0.00", $result->subscription->balance);
852
  $this->assertEquals($subscription->price, $result->subscription->price);
853
  }
854
 
855
- function testUpdate_UpdatesSubscriptionWhenProrationTransactionFailsAndRevertIsFalse()
856
  {
857
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
858
- $result = Braintree_Subscription::update($subscription->id, array(
859
  'price' => $subscription->price + 2100,
860
- 'options' => array('prorateCharges' => true, 'revertSubscriptionOnProrationFailure' => false)
861
- ));
862
  $this->assertTrue($result->success);
863
  $this->assertEquals(sizeof($subscription->transactions) + 1, sizeof($result->subscription->transactions));
864
- $this->assertEquals(Braintree_Transaction::PROCESSOR_DECLINED, $result->subscription->transactions[0]->status);
865
  $this->assertEquals($result->subscription->transactions[0]->amount, $result->subscription->balance);
866
  $this->assertEquals($subscription->price + 2100, $result->subscription->price);
867
  }
868
 
869
- function testUpdate_invalidSubscriptionId()
870
  {
871
- $this->setExpectedException('Braintree_Exception_NotFound');
872
- Braintree_Subscription::update('does-not-exist', array());
873
  }
874
 
875
- function testUpdate_validationErrors()
876
  {
877
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
878
- $result = Braintree_Subscription::update($subscription->id, array('price' => ''));
879
  $this->assertFalse($result->success);
880
  $errors = $result->errors->forKey('subscription')->onAttribute('price');
881
- $this->assertEquals(Braintree_Error_Codes::SUBSCRIPTION_PRICE_CANNOT_BE_BLANK, $errors[0]->code);
882
  }
883
 
884
- function testUpdate_cannotUpdateCanceledSubscription()
885
  {
886
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
887
- Braintree_Subscription::cancel($subscription->id);
888
- $result = Braintree_Subscription::update($subscription->id, array('price' => '1.00'));
889
  $this->assertFalse($result->success);
890
  $errors = $result->errors->forKey('subscription')->onAttribute('base');
891
- $this->assertEquals(Braintree_Error_Codes::SUBSCRIPTION_CANNOT_EDIT_CANCELED_SUBSCRIPTION, $errors[0]->code);
892
  }
893
 
894
- function testUpdate_canUpdatePaymentMethodToken()
895
  {
896
- $oldCreditCard = Braintree_SubscriptionTestHelper::createCreditCard();
897
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
898
- $subscription = Braintree_Subscription::create(array(
899
  'paymentMethodToken' => $oldCreditCard->token,
900
  'price' => '54.99',
901
  'planId' => $plan['id']
902
- ))->subscription;
903
 
904
- $newCreditCard = Braintree_CreditCard::createNoValidate(array(
905
  'number' => '5105105105105100',
906
  'expirationDate' => '05/2010',
907
  'customerId' => $oldCreditCard->customerId
908
- ));
909
 
910
- $result = Braintree_Subscription::update($subscription->id, array(
911
  'paymentMethodToken' => $newCreditCard->token
912
- ));
913
  $this->assertTrue($result->success);
914
  $this->assertEquals($newCreditCard->token, $result->subscription->paymentMethodToken);
915
  }
916
 
917
- function testUpdate_canUpdatePaymentMethodWithPaymentMethodNonce()
918
  {
919
- $oldCreditCard = Braintree_SubscriptionTestHelper::createCreditCard();
920
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
921
- $subscription = Braintree_Subscription::create(array(
922
  'paymentMethodToken' => $oldCreditCard->token,
923
  'price' => '54.99',
924
  'planId' => $plan['id']
925
- ))->subscription;
926
 
927
- $customerId = Braintree_Customer::create()->customer->id;
928
- $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
929
- $nonce = $http->nonce_for_new_card(array(
930
- "creditCard" => array(
931
  "number" => "4111111111111111",
932
  "expirationMonth" => "11",
933
  "expirationYear" => "2099"
934
- ),
935
  "customerId" => $oldCreditCard->customerId,
936
  "share" => true
937
- ));
938
 
939
- $result = Braintree_Subscription::update($subscription->id, array(
940
  'paymentMethodNonce' => $nonce
941
- ));
942
 
943
  $this->assertTrue($result->success);
944
 
945
- $newCreditCard = Braintree_CreditCard::find($result->subscription->paymentMethodToken);
946
 
947
  $this->assertEquals("1111", $newCreditCard->last4);
948
  $this->assertNotEquals($oldCreditCard->last4, $newCreditCard->last4);
949
  }
950
 
951
- function testUpdate_canUpdateAddOnsAndDiscounts()
952
  {
953
- $oldCreditCard = Braintree_SubscriptionTestHelper::createCreditCard();
954
- $plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
955
- $subscription = Braintree_Subscription::create(array(
956
  'paymentMethodToken' => $oldCreditCard->token,
957
  'price' => '54.99',
958
  'planId' => $plan['id']
959
- ))->subscription;
960
 
961
- $result = Braintree_Subscription::update($subscription->id, array(
962
- 'addOns' => array(
963
- 'update' => array(
964
- array(
965
  'amount' => '99.99',
966
  'existingId' => 'increase_10',
967
  'quantity' => 99,
968
  'numberOfBillingCycles' => 99
969
- ),
970
- array(
971
  'amount' => '22.22',
972
  'existingId' => 'increase_20',
973
  'quantity' => 22,
974
  'neverExpires' => true
975
- )
976
- ),
977
- ),
978
- 'discounts' => array(
979
- 'update' => array(
980
- array(
981
  'amount' => '33.33',
982
  'existingId' => 'discount_11',
983
  'quantity' => 33,
984
  'numberOfBillingCycles' => 33
985
- )
986
- ),
987
- ),
988
- ));
989
  $this->assertTrue($result->success);
990
 
991
  $subscription = $result->subscription;
992
  $this->assertEquals(2, sizeof($subscription->addOns));
993
  $addOns = $subscription->addOns;
994
- Braintree_SubscriptionTestHelper::sortModificationsById($addOns);
995
 
996
  $this->assertEquals($addOns[0]->id, "increase_10");
997
  $this->assertEquals($addOns[0]->amount, "99.99");
@@ -1007,7 +1012,7 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
1007
 
1008
  $this->assertEquals(2, sizeof($subscription->discounts));
1009
  $discounts = $subscription->discounts;
1010
- Braintree_SubscriptionTestHelper::sortModificationsById($discounts);
1011
 
1012
  $this->assertEquals($discounts[0]->id, "discount_11");
1013
  $this->assertEquals($discounts[0]->amount, "33.33");
@@ -1016,43 +1021,43 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
1016
  $this->assertEquals($discounts[0]->quantity, 33);
1017
  }
1018
 
1019
- function testUpdate_canAddAndRemoveAddOnsAndDiscounts()
1020
  {
1021
- $oldCreditCard = Braintree_SubscriptionTestHelper::createCreditCard();
1022
- $plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
1023
- $subscription = Braintree_Subscription::create(array(
1024
  'paymentMethodToken' => $oldCreditCard->token,
1025
  'price' => '54.99',
1026
  'planId' => $plan['id']
1027
- ))->subscription;
1028
 
1029
- $result = Braintree_Subscription::update($subscription->id, array(
1030
- 'addOns' => array(
1031
- 'add' => array(
1032
- array(
1033
  'amount' => '33.33',
1034
  'inheritedFromId' => 'increase_30',
1035
  'quantity' => 33,
1036
  'numberOfBillingCycles' => 33
1037
- )
1038
- ),
1039
- 'remove' => array('increase_10', 'increase_20')
1040
- ),
1041
- 'discounts' => array(
1042
- 'add' => array(
1043
- array(
1044
  'inheritedFromId' => 'discount_15',
1045
- )
1046
- ),
1047
- 'remove' => array('discount_7')
1048
- ),
1049
- ));
1050
  $this->assertTrue($result->success);
1051
 
1052
  $subscription = $result->subscription;
1053
  $this->assertEquals(1, sizeof($subscription->addOns));
1054
  $addOns = $subscription->addOns;
1055
- Braintree_SubscriptionTestHelper::sortModificationsById($addOns);
1056
 
1057
  $this->assertEquals($addOns[0]->id, "increase_30");
1058
  $this->assertEquals($addOns[0]->amount, "33.33");
@@ -1062,7 +1067,7 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
1062
 
1063
  $this->assertEquals(2, sizeof($subscription->discounts));
1064
  $discounts = $subscription->discounts;
1065
- Braintree_SubscriptionTestHelper::sortModificationsById($discounts);
1066
 
1067
  $this->assertEquals($discounts[0]->id, "discount_11");
1068
  $this->assertEquals($discounts[1]->id, "discount_15");
@@ -1072,36 +1077,36 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
1072
  $this->assertEquals($discounts[1]->quantity, 1);
1073
  }
1074
 
1075
- function testUpdate_canReplaceEntireSetOfAddonsAndDiscounts()
1076
  {
1077
- $oldCreditCard = Braintree_SubscriptionTestHelper::createCreditCard();
1078
- $plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
1079
- $subscription = Braintree_Subscription::create(array(
1080
  'paymentMethodToken' => $oldCreditCard->token,
1081
  'price' => '54.99',
1082
  'planId' => $plan['id']
1083
- ))->subscription;
1084
-
1085
- $result = Braintree_Subscription::update($subscription->id, array(
1086
- 'addOns' => array(
1087
- 'add' => array(
1088
- array('inheritedFromId' => 'increase_30'),
1089
- array('inheritedFromId' => 'increase_20')
1090
- )
1091
- ),
1092
- 'discounts' => array(
1093
- 'add' => array(
1094
- array('inheritedFromId' => 'discount_15')
1095
- )
1096
- ),
1097
- 'options' => array('replaceAllAddOnsAndDiscounts' => true)
1098
- ));
1099
  $this->assertTrue($result->success);
1100
  $subscription = $result->subscription;
1101
 
1102
  $this->assertEquals(2, sizeof($subscription->addOns));
1103
  $addOns = $subscription->addOns;
1104
- Braintree_SubscriptionTestHelper::sortModificationsById($addOns);
1105
 
1106
  $this->assertEquals($addOns[0]->id, "increase_20");
1107
  $this->assertEquals($addOns[1]->id, "increase_30");
@@ -1112,86 +1117,86 @@ class Braintree_SubscriptionTest extends PHPUnit_Framework_TestCase
1112
  $this->assertEquals($discounts[0]->id, "discount_15");
1113
  }
1114
 
1115
- function testUpdate_withDescriptor()
1116
  {
1117
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
1118
- $plan = Braintree_SubscriptionTestHelper::triallessPlan();
1119
- $subscription = Braintree_Subscription::create(array(
1120
  'paymentMethodToken' => $creditCard->token,
1121
  'planId' => $plan['id'],
1122
- 'descriptor' => array(
1123
  'name' => '123*123456789012345678',
1124
  'phone' => '3334445555'
1125
- )
1126
- ))->subscription;
1127
- $result = Braintree_Subscription::update($subscription->id, array(
1128
- 'descriptor' => array(
1129
  'name' => '999*9999999',
1130
  'phone' => '8887776666'
1131
- )
1132
- ));
1133
  $updatedSubscription = $result->subscription;
1134
  $this->assertEquals('999*9999999', $updatedSubscription->descriptor->name);
1135
  $this->assertEquals('8887776666', $updatedSubscription->descriptor->phone);
1136
  }
1137
 
1138
- function testCancel_returnsSuccessIfCanceled()
1139
  {
1140
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
1141
- $result = Braintree_Subscription::cancel($subscription->id);
1142
  $this->assertTrue($result->success);
1143
- $this->assertEquals(Braintree_Subscription::CANCELED, $result->subscription->status);
1144
  }
1145
 
1146
- function testCancel_throwsErrorIfRecordNotFound()
1147
  {
1148
- $this->setExpectedException('Braintree_Exception_NotFound');
1149
- Braintree_Subscription::cancel('non-existing-id');
1150
  }
1151
 
1152
- function testCancel_returnsErrorIfCancelingCanceledSubscription()
1153
  {
1154
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
1155
- Braintree_Subscription::cancel($subscription->id);
1156
- $result = Braintree_Subscription::cancel($subscription->id);
1157
  $this->assertFalse($result->success);
1158
  $errors = $result->errors->forKey('subscription')->onAttribute('status');
1159
- $this->assertEquals(Braintree_Error_Codes::SUBSCRIPTION_STATUS_IS_CANCELED, $errors[0]->code);
1160
  }
1161
 
1162
- function testRetryCharge_WithoutAmount()
1163
  {
1164
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
1165
- $http = new Braintree_Http(Braintree_Configuration::$global);
1166
- $path = Braintree_Configuration::$global->merchantPath() . '/subscriptions/' . $subscription->id . '/make_past_due';
1167
  $http->put($path);
1168
 
1169
- $result = Braintree_Subscription::retryCharge($subscription->id);
1170
 
1171
  $this->assertTrue($result->success);
1172
  $transaction = $result->transaction;
1173
 
1174
  $this->assertEquals($subscription->price, $transaction->amount);
1175
  $this->assertNotNull($transaction->processorAuthorizationCode);
1176
- $this->assertEquals(Braintree_Transaction::SALE, $transaction->type);
1177
- $this->assertEquals(Braintree_Transaction::AUTHORIZED, $transaction->status);
1178
  }
1179
 
1180
- function testRetryCharge_WithAmount()
1181
  {
1182
- $subscription = Braintree_SubscriptionTestHelper::createSubscription();
1183
- $http = new Braintree_Http(Braintree_Configuration::$global);
1184
- $path = Braintree_Configuration::$global->merchantPath() . '/subscriptions/' . $subscription->id . '/make_past_due';
1185
  $http->put($path);
1186
 
1187
- $result = Braintree_Subscription::retryCharge($subscription->id, 1000);
1188
 
1189
  $this->assertTrue($result->success);
1190
  $transaction = $result->transaction;
1191
 
1192
  $this->assertEquals(1000, $transaction->amount);
1193
  $this->assertNotNull($transaction->processorAuthorizationCode);
1194
- $this->assertEquals(Braintree_Transaction::SALE, $transaction->type);
1195
- $this->assertEquals(Braintree_Transaction::AUTHORIZED, $transaction->status);
1196
  }
1197
  }
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 SubscriptionTest extends Setup
12
  {
13
+ public function testCreate_doesNotAcceptBadAttributes()
14
  {
15
  $this->setExpectedException('InvalidArgumentException', 'invalid keys: bad');
16
+ $result = Braintree\Subscription::create([
17
  'bad' => 'value'
18
+ ]);
19
  }
20
 
21
+ public function testCreate_whenSuccessful()
22
  {
23
+ $creditCard = SubscriptionHelper::createCreditCard();
24
+ $plan = SubscriptionHelper::triallessPlan();
25
+ $result = Braintree\Subscription::create([
26
  'paymentMethodToken' => $creditCard->token,
27
  'planId' => $plan['id']
28
 
29
+ ]);
30
+ Test\Helper::assertPrintable($result);
31
  $this->assertTrue($result->success);
32
  $subscription = $result->subscription;
33
  $this->assertEquals($creditCard->token, $subscription->paymentMethodToken);
34
  $this->assertEquals(0, $subscription->failureCount);
35
  $this->assertEquals($plan['id'], $subscription->planId);
36
+ $this->assertEquals(Test\Helper::defaultMerchantAccountId(), $subscription->merchantAccountId);
37
+ $this->assertEquals(Braintree\Subscription::ACTIVE, $subscription->status);
38
  $this->assertEquals('12.34', $subscription->nextBillAmount);
39
  $this->assertEquals('12.34', $subscription->nextBillingPeriodAmount);
40
  $this->assertEquals('0.00', $subscription->balance);
49
 
50
  $this->assertEquals('12.34', $subscription->statusHistory[0]->price);
51
  $this->assertEquals('0.00', $subscription->statusHistory[0]->balance);
52
+ $this->assertEquals(Braintree\Subscription::ACTIVE, $subscription->statusHistory[0]->status);
53
+ $this->assertEquals(Braintree\Subscription::API, $subscription->statusHistory[0]->subscriptionSource);
54
  }
55
 
56
+ public function testGatewayCreate_whenSuccessful()
57
  {
58
+ $creditCard = SubscriptionHelper::createCreditCard();
59
+ $plan = SubscriptionHelper::triallessPlan();
60
 
61
+ $gateway = new Braintree\Gateway([
62
  'environment' => 'development',
63
  'merchantId' => 'integration_merchant_id',
64
  'publicKey' => 'integration_public_key',
65
  'privateKey' => 'integration_private_key'
66
+ ]);
67
+ $result = $gateway->subscription()->create([
68
  'paymentMethodToken' => $creditCard->token,
69
  'planId' => $plan['id']
70
 
71
+ ]);
72
+ Test\Helper::assertPrintable($result);
73
  $this->assertTrue($result->success);
74
  $subscription = $result->subscription;
75
  $this->assertEquals($creditCard->token, $subscription->paymentMethodToken);
76
  $this->assertEquals(0, $subscription->failureCount);
77
  $this->assertEquals($plan['id'], $subscription->planId);
78
+ $this->assertEquals(Test\Helper::defaultMerchantAccountId(), $subscription->merchantAccountId);
79
+ $this->assertEquals(Braintree\Subscription::ACTIVE, $subscription->status);
80
  }
81
 
82
+ public function testCreate_withPaymentMethodNonce()
83
  {
84
+ $customerId = Braintree\Customer::create()->customer->id;
85
+ $http = new HttpClientApi(Braintree\Configuration::$global);
86
+ $nonce = $http->nonce_for_new_card([
87
+ "creditCard" => [
88
  "number" => "4111111111111111",
89
  "expirationMonth" => "11",
90
  "expirationYear" => "2099"
91
+ ],
92
  "customerId" => $customerId,
93
  "share" => true
94
+ ]);
95
+ $plan = SubscriptionHelper::triallessPlan();
96
+ $result = Braintree\Subscription::create([
97
  'paymentMethodNonce' => $nonce,
98
  'planId' => $plan['id']
99
+ ]);
100
 
101
  $this->assertTrue($result->success);
102
 
105
  $this->assertEquals("1111", $transaction->creditCardDetails->last4);
106
  }
107
 
108
+ public function testCreate_returnsTransactionWhenTransactionFails()
109
  {
110
+ $creditCard = SubscriptionHelper::createCreditCard();
111
+ $plan = SubscriptionHelper::triallessPlan();
112
+ $result = Braintree\Subscription::create([
113
  'paymentMethodToken' => $creditCard->token,
114
  'planId' => $plan['id'],
115
+ 'price' => Braintree\Test\TransactionAmounts::$decline
116
 
117
+ ]);
118
+ Test\Helper::assertPrintable($result);
119
  $this->assertFalse($result->success);
120
+ $this->assertEquals(Braintree\Transaction::PROCESSOR_DECLINED, $result->transaction->status);
121
  }
122
 
123
+ public function testCreate_canSetTheId()
124
  {
125
+ $creditCard = SubscriptionHelper::createCreditCard();
126
  $newId = strval(rand());
127
+ $plan = SubscriptionHelper::triallessPlan();
128
+ $result = Braintree\Subscription::create([
129
  'paymentMethodToken' => $creditCard->token,
130
  'planId' => $plan['id'],
131
  'id' => $newId
132
+ ]);
133
 
134
  $this->assertTrue($result->success);
135
  $subscription = $result->subscription;
136
  $this->assertEquals($newId, $subscription->id);
137
  }
138
 
139
+ public function testCreate_canSetTheMerchantAccountId()
140
  {
141
+ $creditCard = SubscriptionHelper::createCreditCard();
142
+ $plan = SubscriptionHelper::triallessPlan();
143
+ $result = Braintree\Subscription::create([
144
  'paymentMethodToken' => $creditCard->token,
145
  'planId' => $plan['id'],
146
+ 'merchantAccountId' => Test\Helper::nonDefaultMerchantAccountId()
147
+ ]);
148
 
149
  $this->assertTrue($result->success);
150
  $subscription = $result->subscription;
151
+ $this->assertEquals(Test\Helper::nonDefaultMerchantAccountId(), $subscription->merchantAccountId);
152
  }
153
 
154
+ public function testCreate_trialPeriodDefaultsToPlanWithoutTrial()
155
  {
156
+ $creditCard = SubscriptionHelper::createCreditCard();
157
+ $plan = SubscriptionHelper::triallessPlan();
158
+ $result = Braintree\Subscription::create([
159
  'paymentMethodToken' => $creditCard->token,
160
  'planId' => $plan['id'],
161
+ ]);
162
  $subscription = $result->subscription;
163
  $this->assertFalse($subscription->trialPeriod);
164
  $this->assertNull($subscription->trialDuration);
165
  $this->assertNull($subscription->trialDurationUnit);
166
  }
167
 
168
+ public function testCreate_trialPeriondDefaultsToPlanWithTrial()
169
  {
170
+ $creditCard = SubscriptionHelper::createCreditCard();
171
+ $plan = SubscriptionHelper::trialPlan();
172
+ $result = Braintree\Subscription::create([
173
  'paymentMethodToken' => $creditCard->token,
174
  'planId' => $plan['id'],
175
+ ]);
176
  $subscription = $result->subscription;
177
  $this->assertTrue($subscription->trialPeriod);
178
  $this->assertEquals(2, $subscription->trialDuration);
179
  $this->assertEquals('day', $subscription->trialDurationUnit);
180
  }
181
 
182
+ public function testCreate_alterPlanTrialPeriod()
183
  {
184
+ $creditCard = SubscriptionHelper::createCreditCard();
185
+ $plan = SubscriptionHelper::trialPlan();
186
+ $result = Braintree\Subscription::create([
187
  'paymentMethodToken' => $creditCard->token,
188
  'planId' => $plan['id'],
189
  'trialDuration' => 5,
190
  'trialDurationUnit' => 'month'
191
+ ]);
192
  $subscription = $result->subscription;
193
  $this->assertTrue($subscription->trialPeriod);
194
  $this->assertEquals(5, $subscription->trialDuration);
195
  $this->assertEquals('month', $subscription->trialDurationUnit);
196
  }
197
 
198
+ public function testCreate_removePlanTrialPeriod()
199
  {
200
+ $creditCard = SubscriptionHelper::createCreditCard();
201
+ $plan = SubscriptionHelper::trialPlan();
202
+ $result = Braintree\Subscription::create([
203
  'paymentMethodToken' => $creditCard->token,
204
  'planId' => $plan['id'],
205
  'trialPeriod' => false,
206
+ ]);
207
  $subscription = $result->subscription;
208
  $this->assertFalse($subscription->trialPeriod);
209
  }
210
 
211
+ public function testCreate_createsATransactionIfNoTrialPeriod()
212
  {
213
+ $creditCard = SubscriptionHelper::createCreditCard();
214
+ $plan = SubscriptionHelper::triallessPlan();
215
+ $result = Braintree\Subscription::create([
216
  'paymentMethodToken' => $creditCard->token,
217
  'planId' => $plan['id'],
218
+ ]);
219
  $subscription = $result->subscription;
220
  $this->assertEquals(1, sizeof($subscription->transactions));
221
  $transaction = $subscription->transactions[0];
222
+ $this->assertInstanceOf('Braintree\Transaction', $transaction);
223
  $this->assertEquals($plan['price'], $transaction->amount);
224
+ $this->assertEquals(Braintree\Transaction::SALE, $transaction->type);
225
  $this->assertEquals($subscription->id, $transaction->subscriptionId);
226
  }
227
 
228
+ public function testCreate_doesNotCreateTransactionIfTrialPeriod()
229
  {
230
+ $creditCard = SubscriptionHelper::createCreditCard();
231
+ $plan = SubscriptionHelper::trialPlan();
232
+ $result = Braintree\Subscription::create([
233
  'paymentMethodToken' => $creditCard->token,
234
  'planId' => $plan['id'],
235
+ ]);
236
  $subscription = $result->subscription;
237
  $this->assertEquals(0, sizeof($subscription->transactions));
238
  }
239
 
240
+ public function testCreate_returnsATransactionWithSubscriptionBillingPeriod()
241
  {
242
+ $creditCard = SubscriptionHelper::createCreditCard();
243
+ $plan = SubscriptionHelper::triallessPlan();
244
+ $result = Braintree\Subscription::create([
245
  'paymentMethodToken' => $creditCard->token,
246
  'planId' => $plan['id'],
247
+ ]);
248
  $subscription = $result->subscription;
249
  $transaction = $subscription->transactions[0];
250
  $this->assertEquals($subscription->billingPeriodStartDate, $transaction->subscriptionDetails->billingPeriodStartDate);
251
  $this->assertEquals($subscription->billingPeriodEndDate, $transaction->subscriptionDetails->billingPeriodEndDate);
252
  }
253
 
254
+ public function testCreate_priceCanBeOverriden()
255
  {
256
+ $creditCard = SubscriptionHelper::createCreditCard();
257
+ $plan = SubscriptionHelper::trialPlan();
258
+ $result = Braintree\Subscription::create([
259
  'paymentMethodToken' => $creditCard->token,
260
  'planId' => $plan['id'],
261
  'price' => '2.00'
262
+ ]);
263
  $subscription = $result->subscription;
264
  $this->assertEquals('2.00', $subscription->price);
265
  }
266
 
267
+ public function testCreate_billingDayOfMonthIsInheritedFromPlan()
268
  {
269
+ $creditCard = SubscriptionHelper::createCreditCard();
270
+ $plan = SubscriptionHelper::billingDayOfMonthPlan();
271
+ $result = Braintree\Subscription::create([
272
  'paymentMethodToken' => $creditCard->token,
273
  'planId' => $plan['id']
274
+ ]);
275
  $subscription = $result->subscription;
276
  $this->assertEquals(5, $subscription->billingDayOfMonth);
277
  }
278
 
279
+ public function testCreate_billingDayOfMonthCanBeOverriden()
280
  {
281
+ $creditCard = SubscriptionHelper::createCreditCard();
282
+ $plan = SubscriptionHelper::billingDayOfMonthPlan();
283
+ $result = Braintree\Subscription::create([
284
  'paymentMethodToken' => $creditCard->token,
285
  'planId' => $plan['id'],
286
  'billingDayOfMonth' => 14
287
+ ]);
288
  $subscription = $result->subscription;
289
  $this->assertEquals(14, $subscription->billingDayOfMonth);
290
  }
291
 
292
+ public function testCreate_billingDayOfMonthCanBeOverridenWithStartImmediately()
293
  {
294
+ $creditCard = SubscriptionHelper::createCreditCard();
295
+ $plan = SubscriptionHelper::billingDayOfMonthPlan();
296
+ $result = Braintree\Subscription::create([
297
  'paymentMethodToken' => $creditCard->token,
298
  'planId' => $plan['id'],
299
+ 'options' => ['startImmediately' => true]
300
+ ]);
301
  $subscription = $result->subscription;
302
  $this->assertEquals(1, sizeof($subscription->transactions));
303
  }
304
 
305
+ public function testCreate_firstBillingDateCanBeSet()
306
  {
307
+ $creditCard = SubscriptionHelper::createCreditCard();
308
+ $plan = SubscriptionHelper::billingDayOfMonthPlan();
309
 
310
  $tomorrow = new DateTime("now + 1 day");
311
  $tomorrow->setTime(0,0,0);
312
 
313
+ $result = Braintree\Subscription::create([
314
  'paymentMethodToken' => $creditCard->token,
315
  'planId' => $plan['id'],
316
  'firstBillingDate' => $tomorrow
317
+ ]);
318
 
319
  $subscription = $result->subscription;
320
  $this->assertEquals($tomorrow, $subscription->firstBillingDate);
321
+ $this->assertEquals(Braintree\Subscription::PENDING, $result->subscription->status);
322
  }
323
 
324
+ public function testCreate_firstBillingDateInThePast()
325
  {
326
+ $creditCard = SubscriptionHelper::createCreditCard();
327
+ $plan = SubscriptionHelper::billingDayOfMonthPlan();
328
 
329
  $past = new DateTime("now - 3 days");
330
  $past->setTime(0,0,0);
331
 
332
+ $result = Braintree\Subscription::create([
333
  'paymentMethodToken' => $creditCard->token,
334
  'planId' => $plan['id'],
335
  'firstBillingDate' => $past
336
+ ]);
337
 
338
  $this->assertFalse($result->success);
339
  $errors = $result->errors->forKey('subscription')->onAttribute('firstBillingDate');
340
+ $this->assertEquals(Braintree\Error\Codes::SUBSCRIPTION_FIRST_BILLING_DATE_CANNOT_BE_IN_THE_PAST, $errors[0]->code);
341
  }
342
 
343
+ public function testCreate_numberOfBillingCyclesCanBeOverridden()
344
  {
345
+ $creditCard = SubscriptionHelper::createCreditCard();
346
+ $plan = SubscriptionHelper::trialPlan();
347
+ $result = Braintree\Subscription::create([
348
  'paymentMethodToken' => $creditCard->token,
349
  'planId' => $plan['id']
350
+ ]);
351
  $subscription = $result->subscription;
352
  $this->assertEquals($plan['numberOfBillingCycles'], $subscription->numberOfBillingCycles);
353
 
354
+ $result = Braintree\Subscription::create([
355
  'numberOfBillingCycles' => '10',
356
  'paymentMethodToken' => $creditCard->token,
357
  'planId' => $plan['id']
358
+ ]);
359
  $subscription = $result->subscription;
360
  $this->assertEquals(10, $subscription->numberOfBillingCycles);
361
  $this->assertFalse($subscription->neverExpires);
362
  }
363
 
364
+ public function testCreate_numberOfBillingCyclesCanBeOverriddenToNeverExpire()
365
  {
366
+ $creditCard = SubscriptionHelper::createCreditCard();
367
+ $plan = SubscriptionHelper::trialPlan();
368
+ $result = Braintree\Subscription::create([
369
  'paymentMethodToken' => $creditCard->token,
370
  'planId' => $plan['id']
371
+ ]);
372
  $subscription = $result->subscription;
373
  $this->assertEquals($plan['numberOfBillingCycles'], $subscription->numberOfBillingCycles);
374
 
375
+ $result = Braintree\Subscription::create([
376
  'neverExpires' => true,
377
  'paymentMethodToken' => $creditCard->token,
378
  'planId' => $plan['id']
379
+ ]);
380
  $subscription = $result->subscription;
381
  $this->assertNull($subscription->numberOfBillingCycles);
382
  $this->assertTrue($subscription->neverExpires);
383
  }
384
 
385
+ public function testCreate_doesNotInheritAddOnsAndDiscountsWhenDoNotInheritAddOnsOrDiscountsIsSet()
386
  {
387
+ $creditCard = SubscriptionHelper::createCreditCard();
388
+ $plan = SubscriptionHelper::addOnDiscountPlan();
389
+ $result = Braintree\Subscription::create([
390
  'paymentMethodToken' => $creditCard->token,
391
  'planId' => $plan['id'],
392
+ 'options' => ['doNotInheritAddOnsOrDiscounts' => true]
393
+ ]);
394
  $subscription = $result->subscription;
395
  $this->assertEquals(0, sizeof($subscription->addOns));
396
  $this->assertEquals(0, sizeof($subscription->discounts));
397
  }
398
 
399
+ public function testCreate_inheritsAddOnsAndDiscountsFromPlanByDefault()
400
  {
401
+ $creditCard = SubscriptionHelper::createCreditCard();
402
+ $plan = SubscriptionHelper::addOnDiscountPlan();
403
+ $result = Braintree\Subscription::create([
404
  'paymentMethodToken' => $creditCard->token,
405
  'planId' => $plan['id'],
406
+ ]);
407
  $subscription = $result->subscription;
408
  $this->assertEquals(2, sizeof($subscription->addOns));
409
  $addOns = $subscription->addOns;
410
+ SubscriptionHelper::sortModificationsById($addOns);
411
 
412
  $this->assertEquals($addOns[0]->amount, "10.00");
413
  $this->assertEquals($addOns[0]->quantity, 1);
423
 
424
  $this->assertEquals(2, sizeof($subscription->discounts));
425
  $discounts = $subscription->discounts;
426
+ SubscriptionHelper::sortModificationsById($discounts);
427
 
428
  $this->assertEquals($discounts[0]->amount, "11.00");
429
  $this->assertEquals($discounts[0]->quantity, 1);
438
  $this->assertEquals($discounts[1]->currentBillingCycle, 0);
439
  }
440
 
441
+ public function testCreate_allowsOverridingInheritedAddOnsAndDiscounts()
442
  {
443
+ $creditCard = SubscriptionHelper::createCreditCard();
444
+ $plan = SubscriptionHelper::addOnDiscountPlan();
445
+ $result = Braintree\Subscription::create([
446
  'paymentMethodToken' => $creditCard->token,
447
  'planId' => $plan['id'],
448
+ 'addOns' => [
449
+ 'update' => [
450
+ [
451
  'amount' => '50.00',
452
  'existingId' => 'increase_10',
453
  'quantity' => 2,
454
  'numberOfBillingCycles' => 5
455
+ ],
456
+ [
457
  'amount' => '60.00',
458
  'existingId' => 'increase_20',
459
  'quantity' => 4,
460
  'numberOfBillingCycles' => 9
461
+ ]
462
+ ],
463
+ ],
464
+ 'discounts' => [
465
+ 'update' => [
466
+ [
467
  'amount' => '15.00',
468
  'existingId' => 'discount_7',
469
  'quantity' => 2,
470
  'neverExpires' => true
471
+ ]
472
+ ]
473
+ ]
474
+ ]);
475
  $subscription = $result->subscription;
476
  $this->assertEquals(2, sizeof($subscription->addOns));
477
  $addOns = $subscription->addOns;
478
+ SubscriptionHelper::sortModificationsById($addOns);
479
 
480
  $this->assertEquals($addOns[0]->amount, "50.00");
481
  $this->assertEquals($addOns[0]->quantity, 2);
491
 
492
  $this->assertEquals(2, sizeof($subscription->discounts));
493
  $discounts = $subscription->discounts;
494
+ SubscriptionHelper::sortModificationsById($discounts);
495
 
496
  $this->assertEquals($discounts[0]->amount, "11.00");
497
  $this->assertEquals($discounts[0]->quantity, 1);
506
  $this->assertEquals($discounts[1]->currentBillingCycle, 0);
507
  }
508
 
509
+ public function testCreate_allowsRemovalOfInheritedAddOnsAndDiscounts()
510
  {
511
+ $creditCard = SubscriptionHelper::createCreditCard();
512
+ $plan = SubscriptionHelper::addOnDiscountPlan();
513
+ $result = Braintree\Subscription::create([
514
  'paymentMethodToken' => $creditCard->token,
515
  'planId' => $plan['id'],
516
+ 'addOns' => [
517
+ 'remove' => ['increase_10', 'increase_20']
518
+ ],
519
+ 'discounts' => [
520
+ 'remove' => ['discount_7']
521
+ ]
522
+ ]);
523
  $subscription = $result->subscription;
524
  $this->assertEquals(0, sizeof($subscription->addOns));
525
 
532
  $this->assertEquals($subscription->discounts[0]->currentBillingCycle, 0);
533
  }
534
 
535
+ public function testCreate_allowsAddingNewAddOnsAndDiscounts()
536
  {
537
+ $creditCard = SubscriptionHelper::createCreditCard();
538
+ $plan = SubscriptionHelper::addOnDiscountPlan();
539
+ $result = Braintree\Subscription::create([
540
  'paymentMethodToken' => $creditCard->token,
541
  'planId' => $plan['id'],
542
+ 'addOns' => [
543
+ 'add' => [
544
+ [
545
  'inheritedFromId' => 'increase_30',
546
  'amount' => '35.00',
547
  'neverExpires' => true,
548
  'quantity' => 2
549
+ ],
550
+ ],
551
+ ],
552
+ 'discounts' => [
553
+ 'add' => [
554
+ [
555
  'inheritedFromId' => 'discount_15',
556
  'amount' => '15.50',
557
  'numberOfBillingCycles' => 10,
558
  'quantity' => 3
559
+ ]
560
+ ]
561
+ ]
562
+ ]);
563
 
564
  $subscription = $result->subscription;
565
  $this->assertEquals(3, sizeof($subscription->addOns));
566
  $addOns = $subscription->addOns;
567
+ SubscriptionHelper::sortModificationsById($addOns);
568
 
569
  $this->assertEquals($addOns[0]->amount, "10.00");
570
  $this->assertEquals($addOns[1]->amount, "20.00");
578
 
579
  $this->assertEquals(3, sizeof($subscription->discounts));
580
  $discounts = $subscription->discounts;
581
+ SubscriptionHelper::sortModificationsById($discounts);
582
 
583
  $this->assertEquals($discounts[0]->amount, "11.00");
584
 
592
  $this->assertEquals($discounts[2]->amount, "7.00");
593
  }
594
 
595
+ public function testCreate_properlyParsesValidationErrorsForArrays()
596
  {
597
+ $creditCard = SubscriptionHelper::createCreditCard();
598
+ $plan = SubscriptionHelper::addOnDiscountPlan();
599
+ $result = Braintree\Subscription::create([
600
  'paymentMethodToken' => $creditCard->token,
601
  'planId' => $plan['id'],
602
+ 'addOns' => [
603
+ 'update' => [
604
+ [
605
  'existingId' => 'increase_10',
606
  'amount' => 'invalid',
607
+ ],
608
+ [
609
  'existingId' => 'increase_20',
610
  'quantity' => -10,
611
+ ]
612
+ ]
613
+ ]
614
+ ]);
615
 
616
  $this->assertFalse($result->success);
617
  $errors = $result->errors->forKey('subscription')->forKey('addOns')->forKey('update')->forIndex(0)->onAttribute('amount');
618
+ $this->assertEquals(Braintree\Error\Codes::SUBSCRIPTION_MODIFICATION_AMOUNT_IS_INVALID, $errors[0]->code);
619
  $errors = $result->errors->forKey('subscription')->forKey('addOns')->forKey('update')->forIndex(1)->onAttribute('quantity');
620
+ $this->assertEquals(Braintree\Error\Codes::SUBSCRIPTION_MODIFICATION_QUANTITY_IS_INVALID, $errors[0]->code);
621
  }
622
 
623
+ public function testCreate_withDescriptor()
624
  {
625
+ $creditCard = SubscriptionHelper::createCreditCard();
626
+ $plan = SubscriptionHelper::triallessPlan();
627
+ $result = Braintree\Subscription::create([
628
  'paymentMethodToken' => $creditCard->token,
629
  'planId' => $plan['id'],
630
+ 'descriptor' => [
631
  'name' => '123*123456789012345678',
632
  'phone' => '3334445555',
633
  'url' => 'ebay.com'
634
+ ]
635
+ ]);
636
  $this->assertTrue($result->success);
637
  $subscription = $result->subscription;
638
  $this->assertEquals('123*123456789012345678', $subscription->descriptor->name);
644
  $this->assertEquals('ebay.com', $transaction->descriptor->url);
645
  }
646
 
647
+ public function testCreate_withDescriptorValidation()
648
  {
649
+ $creditCard = SubscriptionHelper::createCreditCard();
650
+ $plan = SubscriptionHelper::addOnDiscountPlan();
651
+ $result = Braintree\Subscription::create([
652
  'paymentMethodToken' => $creditCard->token,
653
  'planId' => $plan['id'],
654
+ 'descriptor' => [
655
  'name' => 'xxxxxx',
656
  'phone' => 'xxxx',
657
  'url' => '12345678901234'
658
+ ]
659
+ ]);
660
  $this->assertFalse($result->success);
661
  $subscription = $result->subscription;
662
 
663
  $errors = $result->errors->forKey('subscription')->forKey('descriptor')->onAttribute('name');
664
+ $this->assertEquals(Braintree\Error\Codes::DESCRIPTOR_NAME_FORMAT_IS_INVALID, $errors[0]->code);
665
 
666
  $errors = $result->errors->forKey('subscription')->forKey('descriptor')->onAttribute('phone');
667
+ $this->assertEquals(Braintree\Error\Codes::DESCRIPTOR_PHONE_FORMAT_IS_INVALID, $errors[0]->code);
668
 
669
  $errors = $result->errors->forKey('subscription')->forKey('descriptor')->onAttribute('url');
670
+ $this->assertEquals(Braintree\Error\Codes::DESCRIPTOR_URL_FORMAT_IS_INVALID, $errors[0]->code);
671
  }
672
 
673
+ public function testCreate_fromPayPalACcount()
674
  {
675
  $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
676
+ $customer = Braintree\Customer::createNoValidate();
677
+ $plan = SubscriptionHelper::triallessPlan();
678
+ $http = new HttpClientApi(Braintree\Configuration::$global);
679
+ $nonce = $http->nonceForPayPalAccount([
680
+ 'paypal_account' => [
681
  'consent_code' => 'PAYPAL_CONSENT_CODE',
682
  'token' => $paymentMethodToken
683
+ ]
684
+ ]);
685
 
686
+ $paypalResult = Braintree\PaymentMethod::create([
687
  'customerId' => $customer->id,
688
  'paymentMethodNonce' => $nonce
689
+ ]);
690
 
691
+ $subscriptionResult = Braintree\Subscription::create([
692
  'paymentMethodToken' => $paymentMethodToken,
693
  'planId' => $plan['id']
694
 
695
+ ]);
696
  $this->assertTrue($subscriptionResult->success);
697
  $transaction = $subscriptionResult->subscription->transactions[0];
698
  $this->assertEquals('payer@example.com', $transaction->paypalDetails->payerEmail);
699
  }
700
 
701
+ public function testCreate_fromPayPalACcountDoesNotWorkWithFutureNonce()
702
  {
703
+ $plan = SubscriptionHelper::triallessPlan();
704
+ $nonce = Braintree\Test\Nonces::$paypalFuturePayment;
705
 
706
+ $subscriptionResult = Braintree\Subscription::create([
707
  'paymentMethodNonce' => $nonce,
708
  'planId' => $plan['id']
709
 
710
+ ]);
711
  $this->assertFalse($subscriptionResult->success);
712
  $errors = $subscriptionResult->errors->forKey('subscription')->errors;
713
+ $this->assertEquals(Braintree\Error\Codes::SUBSCRIPTION_PAYMENT_METHOD_NONCE_IS_INVALID, $errors[0]->code);
714
  }
715
 
716
+ public function testCreate_fromPayPalACcountDoesNotWorkWithOnetimeNonce()
717
  {
718
+ $plan = SubscriptionHelper::triallessPlan();
719
+ $nonce = Braintree\Test\Nonces::$paypalOneTimePayment;
720
 
721
+ $subscriptionResult = Braintree\Subscription::create([
722
  'paymentMethodNonce' => $nonce,
723
  'planId' => $plan['id']
724
 
725
+ ]);
726
  $this->assertFalse($subscriptionResult->success);
727
  $errors = $subscriptionResult->errors->forKey('subscription')->errors;
728
+ $this->assertEquals(Braintree\Error\Codes::SUBSCRIPTION_PAYMENT_METHOD_NONCE_IS_INVALID, $errors[0]->code);
729
  }
730
 
731
+ public function testValidationErrors_hasValidationErrorsOnId()
732
  {
733
+ $creditCard = SubscriptionHelper::createCreditCard();
734
+ $plan = SubscriptionHelper::triallessPlan();
735
+ $result = Braintree\Subscription::create([
736
  'paymentMethodToken' => $creditCard->token,
737
  'planId' => $plan['id'],
738
  'id' => 'invalid token'
739
+ ]);
740
  $this->assertFalse($result->success);
741
  $errors = $result->errors->forKey('subscription')->onAttribute('id');
742
+ $this->assertEquals(Braintree\Error\Codes::SUBSCRIPTION_TOKEN_FORMAT_IS_INVALID, $errors[0]->code);
743
  }
744
 
745
+ public function testFind()
746
  {
747
+ $creditCard = SubscriptionHelper::createCreditCard();
748
+ $plan = SubscriptionHelper::triallessPlan();
749
+ $result = Braintree\Subscription::create([
750
  'paymentMethodToken' => $creditCard->token,
751
  'planId' => $plan['id']
752
+ ]);
753
  $this->assertTrue($result->success);
754
+ $subscription = Braintree\Subscription::find($result->subscription->id);
755
  $this->assertEquals($result->subscription->id, $subscription->id);
756
  $this->assertEquals($plan['id'], $subscription->planId);
757
  }
758
 
759
+ public function testFind_throwsIfNotFound()
760
  {
761
+ $this->setExpectedException('Braintree\Exception\NotFound', 'subscription with id does-not-exist not found');
762
+ Braintree\Subscription::find('does-not-exist');
763
 
764
  }
765
 
766
+ public function testUpdate_whenSuccessful()
767
  {
768
+ $subscription = SubscriptionHelper::createSubscription();
769
  $newId = strval(rand());
770
+ $newPlan = SubscriptionHelper::trialPlan();
771
+ $result = Braintree\Subscription::update($subscription->id, [
772
  'id' => $newId,
773
  'price' => '999.99',
774
  'planId' => $newPlan['id']
775
+ ]);
776
  $this->assertTrue($result->success);
777
  $this->assertEquals($newId, $result->subscription->id);
778
  $this->assertEquals($newPlan['id'], $result->subscription->planId);
779
  $this->assertEquals('999.99', $result->subscription->price);
780
  }
781
 
782
+ public function testUpdate_doesNotAcceptBadAttributes()
783
  {
784
  $this->setExpectedException('InvalidArgumentException', 'invalid keys: bad');
785
+ $result = Braintree\Subscription::update('id', [
786
  'bad' => 'value'
787
+ ]);
788
  }
789
 
790
+ public function testUpdate_canUpdateNumberOfBillingCycles()
791
  {
792
+ $plan = SubscriptionHelper::triallessPlan();
793
+ $subscription = SubscriptionHelper::createSubscription();
794
  $this->assertEquals($plan['numberOfBillingCycles'], $subscription->numberOfBillingCycles);
795
 
796
+ $updatedSubscription = Braintree\Subscription::update($subscription->id, [
797
  'numberOfBillingCycles' => 15
798
+ ])->subscription;
799
  $this->assertEquals(15, $updatedSubscription->numberOfBillingCycles);
800
  }
801
 
802
+ public function testUpdate_canUpdateNumberOfBillingCyclesToNeverExpire()
803
  {
804
+ $plan = SubscriptionHelper::triallessPlan();
805
+ $subscription = SubscriptionHelper::createSubscription();
806
  $this->assertEquals($plan['numberOfBillingCycles'], $subscription->numberOfBillingCycles);
807
 
808
+ $updatedSubscription = Braintree\Subscription::update($subscription->id, [
809
  'neverExpires' => true
810
+ ])->subscription;
811
  $this->assertNull($updatedSubscription->numberOfBillingCycles);
812
  }
813
 
814
+ public function testUpdate_createsTransactionOnProration()
815
  {
816
+ $subscription = SubscriptionHelper::createSubscription();
817
+ $result = Braintree\Subscription::update($subscription->id, [
818
  'price' => $subscription->price + 1,
819
+ ]);
820
  $this->assertTrue($result->success);
821
  $this->assertEquals(sizeof($subscription->transactions) + 1, sizeof($result->subscription->transactions));
822
  }
823
 
824
+ public function testUpdate_createsProratedTransactionWhenFlagIsPassedTrue()
825
  {
826
+ $subscription = SubscriptionHelper::createSubscription();
827
+ $result = Braintree\Subscription::update($subscription->id, [
828
  'price' => $subscription->price + 1,
829
+ 'options' => ['prorateCharges' => true]
830
+ ]);
831
  $this->assertTrue($result->success);
832
  $this->assertEquals(sizeof($subscription->transactions) + 1, sizeof($result->subscription->transactions));
833
  }
834
 
835
+ public function testUpdate_createsProratedTransactionWhenFlagIsPassedFalse()
836
  {
837
+ $subscription = SubscriptionHelper::createSubscription();
838
+ $result = Braintree\Subscription::update($subscription->id, [
839
  'price' => $subscription->price + 1,
840
+ 'options' => ['prorateCharges' => false]
841
+ ]);
842
  $this->assertTrue($result->success);
843
  $this->assertEquals(sizeof($subscription->transactions), sizeof($result->subscription->transactions));
844
  }
845
 
846
+ public function testUpdate_DoesNotUpdateSubscriptionWhenProrationTransactionFailsAndRevertIsTrue()
847
  {
848
+ $subscription = SubscriptionHelper::createSubscription();
849
+ $result = Braintree\Subscription::update($subscription->id, [
850
  'price' => $subscription->price + 2100,
851
+ 'options' => ['prorateCharges' => true, 'revertSubscriptionOnProrationFailure' => true]
852
+ ]);
853
  $this->assertFalse($result->success);
854
  $this->assertEquals(sizeof($subscription->transactions) + 1, sizeof($result->subscription->transactions));
855
+ $this->assertEquals(Braintree\Transaction::PROCESSOR_DECLINED, $result->subscription->transactions[0]->status);
856
  $this->assertEquals("0.00", $result->subscription->balance);
857
  $this->assertEquals($subscription->price, $result->subscription->price);
858
  }
859
 
860
+ public function testUpdate_UpdatesSubscriptionWhenProrationTransactionFailsAndRevertIsFalse()
861
  {
862
+ $subscription = SubscriptionHelper::createSubscription();
863
+ $result = Braintree\Subscription::update($subscription->id, [
864
  'price' => $subscription->price + 2100,
865
+ 'options' => ['prorateCharges' => true, 'revertSubscriptionOnProrationFailure' => false]
866
+ ]);
867
  $this->assertTrue($result->success);
868
  $this->assertEquals(sizeof($subscription->transactions) + 1, sizeof($result->subscription->transactions));
869
+ $this->assertEquals(Braintree\Transaction::PROCESSOR_DECLINED, $result->subscription->transactions[0]->status);
870
  $this->assertEquals($result->subscription->transactions[0]->amount, $result->subscription->balance);
871
  $this->assertEquals($subscription->price + 2100, $result->subscription->price);
872
  }
873
 
874
+ public function testUpdate_invalidSubscriptionId()
875
  {
876
+ $this->setExpectedException('Braintree\Exception\NotFound');
877
+ Braintree\Subscription::update('does-not-exist', []);
878
  }
879
 
880
+ public function testUpdate_validationErrors()
881
  {
882
+ $subscription = SubscriptionHelper::createSubscription();
883
+ $result = Braintree\Subscription::update($subscription->id, ['price' => '']);
884
  $this->assertFalse($result->success);
885
  $errors = $result->errors->forKey('subscription')->onAttribute('price');
886
+ $this->assertEquals(Braintree\Error\Codes::SUBSCRIPTION_PRICE_CANNOT_BE_BLANK, $errors[0]->code);
887
  }
888
 
889
+ public function testUpdate_cannotUpdateCanceledSubscription()
890
  {
891
+ $subscription = SubscriptionHelper::createSubscription();
892
+ Braintree\Subscription::cancel($subscription->id);
893
+ $result = Braintree\Subscription::update($subscription->id, ['price' => '1.00']);
894
  $this->assertFalse($result->success);
895
  $errors = $result->errors->forKey('subscription')->onAttribute('base');
896
+ $this->assertEquals(Braintree\Error\Codes::SUBSCRIPTION_CANNOT_EDIT_CANCELED_SUBSCRIPTION, $errors[0]->code);
897
  }
898
 
899
+ public function testUpdate_canUpdatePaymentMethodToken()
900
  {
901
+ $oldCreditCard = SubscriptionHelper::createCreditCard();
902
+ $plan = SubscriptionHelper::triallessPlan();
903
+ $subscription = Braintree\Subscription::create([
904
  'paymentMethodToken' => $oldCreditCard->token,
905
  'price' => '54.99',
906
  'planId' => $plan['id']
907
+ ])->subscription;
908
 
909
+ $newCreditCard = Braintree\CreditCard::createNoValidate([
910
  'number' => '5105105105105100',
911
  'expirationDate' => '05/2010',
912
  'customerId' => $oldCreditCard->customerId
913
+ ]);
914
 
915
+ $result = Braintree\Subscription::update($subscription->id, [
916
  'paymentMethodToken' => $newCreditCard->token
917
+ ]);
918
  $this->assertTrue($result->success);
919
  $this->assertEquals($newCreditCard->token, $result->subscription->paymentMethodToken);
920
  }
921
 
922
+ public function testUpdate_canUpdatePaymentMethodWithPaymentMethodNonce()
923
  {
924
+ $oldCreditCard = SubscriptionHelper::createCreditCard();
925
+ $plan = SubscriptionHelper::triallessPlan();
926
+ $subscription = Braintree\Subscription::create([
927
  'paymentMethodToken' => $oldCreditCard->token,
928
  'price' => '54.99',
929
  'planId' => $plan['id']
930
+ ])->subscription;
931
 
932
+ $customerId = Braintree\Customer::create()->customer->id;
933
+ $http = new HttpClientApi(Braintree\Configuration::$global);
934
+ $nonce = $http->nonce_for_new_card([
935
+ "creditCard" => [
936
  "number" => "4111111111111111",
937
  "expirationMonth" => "11",
938
  "expirationYear" => "2099"
939
+ ],
940
  "customerId" => $oldCreditCard->customerId,
941
  "share" => true
942
+ ]);
943
 
944
+ $result = Braintree\Subscription::update($subscription->id, [
945
  'paymentMethodNonce' => $nonce
946
+ ]);
947
 
948
  $this->assertTrue($result->success);
949
 
950
+ $newCreditCard = Braintree\CreditCard::find($result->subscription->paymentMethodToken);
951
 
952
  $this->assertEquals("1111", $newCreditCard->last4);
953
  $this->assertNotEquals($oldCreditCard->last4, $newCreditCard->last4);
954
  }
955
 
956
+ public function testUpdate_canUpdateAddOnsAndDiscounts()
957
  {
958
+ $oldCreditCard = SubscriptionHelper::createCreditCard();
959
+ $plan = SubscriptionHelper::addOnDiscountPlan();
960
+ $subscription = Braintree\Subscription::create([
961
  'paymentMethodToken' => $oldCreditCard->token,
962
  'price' => '54.99',
963
  'planId' => $plan['id']
964
+ ])->subscription;
965
 
966
+ $result = Braintree\Subscription::update($subscription->id, [
967
+ 'addOns' => [
968
+ 'update' => [
969
+ [
970
  'amount' => '99.99',
971
  'existingId' => 'increase_10',
972
  'quantity' => 99,
973
  'numberOfBillingCycles' => 99
974
+ ],
975
+ [
976
  'amount' => '22.22',
977
  'existingId' => 'increase_20',
978
  'quantity' => 22,
979
  'neverExpires' => true
980
+ ]
981
+ ],
982
+ ],
983
+ 'discounts' => [
984
+ 'update' => [
985
+ [
986
  'amount' => '33.33',
987
  'existingId' => 'discount_11',
988
  'quantity' => 33,
989
  'numberOfBillingCycles' => 33
990
+ ]
991
+ ],
992
+ ],
993
+ ]);
994
  $this->assertTrue($result->success);
995
 
996
  $subscription = $result->subscription;
997
  $this->assertEquals(2, sizeof($subscription->addOns));
998
  $addOns = $subscription->addOns;
999
+ SubscriptionHelper::sortModificationsById($addOns);
1000
 
1001
  $this->assertEquals($addOns[0]->id, "increase_10");
1002
  $this->assertEquals($addOns[0]->amount, "99.99");
1012
 
1013
  $this->assertEquals(2, sizeof($subscription->discounts));
1014
  $discounts = $subscription->discounts;
1015
+ SubscriptionHelper::sortModificationsById($discounts);
1016
 
1017
  $this->assertEquals($discounts[0]->id, "discount_11");
1018
  $this->assertEquals($discounts[0]->amount, "33.33");
1021
  $this->assertEquals($discounts[0]->quantity, 33);
1022
  }
1023
 
1024
+ public function testUpdate_canAddAndRemoveAddOnsAndDiscounts()
1025
  {
1026
+ $oldCreditCard = SubscriptionHelper::createCreditCard();
1027
+ $plan = SubscriptionHelper::addOnDiscountPlan();
1028
+ $subscription = Braintree\Subscription::create([
1029
  'paymentMethodToken' => $oldCreditCard->token,
1030
  'price' => '54.99',
1031
  'planId' => $plan['id']
1032
+ ])->subscription;
1033
 
1034
+ $result = Braintree\Subscription::update($subscription->id, [
1035
+ 'addOns' => [
1036
+ 'add' => [
1037
+ [
1038
  'amount' => '33.33',
1039
  'inheritedFromId' => 'increase_30',
1040
  'quantity' => 33,
1041
  'numberOfBillingCycles' => 33
1042
+ ]
1043
+ ],
1044
+ 'remove' => ['increase_10', 'increase_20']
1045
+ ],
1046
+ 'discounts' => [
1047
+ 'add' => [
1048
+ [
1049
  'inheritedFromId' => 'discount_15',
1050
+ ]
1051
+ ],
1052
+ 'remove' => ['discount_7']
1053
+ ],
1054
+ ]);
1055
  $this->assertTrue($result->success);
1056
 
1057
  $subscription = $result->subscription;
1058
  $this->assertEquals(1, sizeof($subscription->addOns));
1059
  $addOns = $subscription->addOns;
1060
+ SubscriptionHelper::sortModificationsById($addOns);
1061
 
1062
  $this->assertEquals($addOns[0]->id, "increase_30");
1063
  $this->assertEquals($addOns[0]->amount, "33.33");
1067
 
1068
  $this->assertEquals(2, sizeof($subscription->discounts));
1069
  $discounts = $subscription->discounts;
1070
+ SubscriptionHelper::sortModificationsById($discounts);
1071
 
1072
  $this->assertEquals($discounts[0]->id, "discount_11");
1073
  $this->assertEquals($discounts[1]->id, "discount_15");
1077
  $this->assertEquals($discounts[1]->quantity, 1);
1078
  }
1079
 
1080
+ public function testUpdate_canReplaceEntireSetOfAddonsAndDiscounts()
1081
  {
1082
+ $oldCreditCard = SubscriptionHelper::createCreditCard();
1083
+ $plan = SubscriptionHelper::addOnDiscountPlan();
1084
+ $subscription = Braintree\Subscription::create([
1085
  'paymentMethodToken' => $oldCreditCard->token,
1086
  'price' => '54.99',
1087
  'planId' => $plan['id']
1088
+ ])->subscription;
1089
+
1090
+ $result = Braintree\Subscription::update($subscription->id, [
1091
+ 'addOns' => [
1092
+ 'add' => [
1093
+ ['inheritedFromId' => 'increase_30'],
1094
+ ['inheritedFromId' => 'increase_20']
1095
+ ]
1096
+ ],
1097
+ 'discounts' => [
1098
+ 'add' => [
1099
+ ['inheritedFromId' => 'discount_15']
1100
+ ]
1101
+ ],
1102
+ 'options' => ['replaceAllAddOnsAndDiscounts' => true]
1103
+ ]);
1104
  $this->assertTrue($result->success);
1105
  $subscription = $result->subscription;
1106
 
1107
  $this->assertEquals(2, sizeof($subscription->addOns));
1108
  $addOns = $subscription->addOns;
1109
+ SubscriptionHelper::sortModificationsById($addOns);
1110
 
1111
  $this->assertEquals($addOns[0]->id, "increase_20");
1112
  $this->assertEquals($addOns[1]->id, "increase_30");
1117
  $this->assertEquals($discounts[0]->id, "discount_15");
1118
  }
1119
 
1120
+ public function testUpdate_withDescriptor()
1121
  {
1122
+ $creditCard = SubscriptionHelper::createCreditCard();
1123
+ $plan = SubscriptionHelper::triallessPlan();
1124
+ $subscription = Braintree\Subscription::create([
1125
  'paymentMethodToken' => $creditCard->token,
1126
  'planId' => $plan['id'],
1127
+ 'descriptor' => [
1128
  'name' => '123*123456789012345678',
1129
  'phone' => '3334445555'
1130
+ ]
1131
+ ])->subscription;
1132
+ $result = Braintree\Subscription::update($subscription->id, [
1133
+ 'descriptor' => [
1134
  'name' => '999*9999999',
1135
  'phone' => '8887776666'
1136
+ ]
1137
+ ]);
1138
  $updatedSubscription = $result->subscription;
1139
  $this->assertEquals('999*9999999', $updatedSubscription->descriptor->name);
1140
  $this->assertEquals('8887776666', $updatedSubscription->descriptor->phone);
1141
  }
1142
 
1143
+ public function testCancel_returnsSuccessIfCanceled()
1144
  {
1145
+ $subscription = SubscriptionHelper::createSubscription();
1146
+ $result = Braintree\Subscription::cancel($subscription->id);
1147
  $this->assertTrue($result->success);
1148
+ $this->assertEquals(Braintree\Subscription::CANCELED, $result->subscription->status);
1149
  }
1150
 
1151
+ public function testCancel_throwsErrorIfRecordNotFound()
1152
  {
1153
+ $this->setExpectedException('Braintree\Exception\NotFound');
1154
+ Braintree\Subscription::cancel('non-existing-id');
1155
  }
1156
 
1157
+ public function testCancel_returnsErrorIfCancelingCanceledSubscription()
1158
  {
1159
+ $subscription = SubscriptionHelper::createSubscription();
1160
+ Braintree\Subscription::cancel($subscription->id);
1161
+ $result = Braintree\Subscription::cancel($subscription->id);
1162
  $this->assertFalse($result->success);
1163
  $errors = $result->errors->forKey('subscription')->onAttribute('status');
1164
+ $this->assertEquals(Braintree\Error\Codes::SUBSCRIPTION_STATUS_IS_CANCELED, $errors[0]->code);
1165
  }
1166
 
1167
+ public function testRetryCharge_WithoutAmount()
1168
  {
1169
+ $subscription = SubscriptionHelper::createSubscription();
1170
+ $http = new Braintree\Http(Braintree\Configuration::$global);
1171
+ $path = Braintree\Configuration::$global->merchantPath() . '/subscriptions/' . $subscription->id . '/make_past_due';
1172
  $http->put($path);
1173
 
1174
+ $result = Braintree\Subscription::retryCharge($subscription->id);
1175
 
1176
  $this->assertTrue($result->success);
1177
  $transaction = $result->transaction;
1178
 
1179
  $this->assertEquals($subscription->price, $transaction->amount);
1180
  $this->assertNotNull($transaction->processorAuthorizationCode);
1181
+ $this->assertEquals(Braintree\Transaction::SALE, $transaction->type);
1182
+ $this->assertEquals(Braintree\Transaction::AUTHORIZED, $transaction->status);
1183
  }
1184
 
1185
+ public function testRetryCharge_WithAmount()
1186
  {
1187
+ $subscription = SubscriptionHelper::createSubscription();
1188
+ $http = new Braintree\Http(Braintree\Configuration::$global);
1189
+ $path = Braintree\Configuration::$global->merchantPath() . '/subscriptions/' . $subscription->id . '/make_past_due';
1190
  $http->put($path);
1191
 
1192
+ $result = Braintree\Subscription::retryCharge($subscription->id, 1000);
1193
 
1194
  $this->assertTrue($result->success);
1195
  $transaction = $result->transaction;
1196
 
1197
  $this->assertEquals(1000, $transaction->amount);
1198
  $this->assertNotNull($transaction->processorAuthorizationCode);
1199
+ $this->assertEquals(Braintree\Transaction::SALE, $transaction->type);
1200
+ $this->assertEquals(Braintree\Transaction::AUTHORIZED, $transaction->status);
1201
  }
1202
  }
braintree_sdk/tests/integration/TestTransactionTest.php CHANGED
@@ -1,11 +1,18 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
 
4
- class Braintree_TestTransactionTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
 
5
  {
6
  public function setUp()
7
  {
8
- Braintree_Configuration::environment('development');
9
  }
10
 
11
  /**
@@ -13,24 +20,24 @@ class Braintree_TestTransactionTest extends PHPUnit_Framework_TestCase
13
  */
14
  public function tearDownResetBraintreeEnvironment()
15
  {
16
- Braintree_Configuration::environment('development');
17
  }
18
 
19
  /**
20
- * @expectedException Braintree_Exception_TestOperationPerformedInProduction
21
  */
22
- function testThrowingExceptionWhenProduction()
23
  {
24
- Braintree_Configuration::environment('production');
25
 
26
- $this->setExpectedException('Braintree_Exception_TestOperationPerformedInProduction');
27
 
28
- Braintree_Test_Transaction::settle('transactionId');
29
  }
30
 
31
- function testSettle()
32
  {
33
- $transaction = Braintree_Transaction::saleNoValidate([
34
  'amount' => '100.00',
35
  'creditCard' => [
36
  'number' => '5105105105105100',
@@ -39,14 +46,14 @@ class Braintree_TestTransactionTest extends PHPUnit_Framework_TestCase
39
  'options' => ['submitForSettlement' => true]
40
  ]);
41
 
42
- $transaction = Braintree_Test_Transaction::settle($transaction->id);
43
 
44
  $this->assertEquals('settled', $transaction->status);
45
  }
46
 
47
- function testSettlementConfirmed()
48
  {
49
- $transaction = Braintree_Transaction::saleNoValidate([
50
  'amount' => '100.00',
51
  'creditCard' => [
52
  'number' => '5105105105105100',
@@ -55,14 +62,14 @@ class Braintree_TestTransactionTest extends PHPUnit_Framework_TestCase
55
  'options' => ['submitForSettlement' => true]
56
  ]);
57
 
58
- $transaction = Braintree_Test_Transaction::settlementConfirm($transaction->id);
59
 
60
  $this->assertEquals('settlement_confirmed', $transaction->status);
61
  }
62
 
63
- function testSettlementDeclined()
64
  {
65
- $transaction = Braintree_Transaction::saleNoValidate([
66
  'amount' => '100.00',
67
  'creditCard' => [
68
  'number' => '5105105105105100',
@@ -71,14 +78,14 @@ class Braintree_TestTransactionTest extends PHPUnit_Framework_TestCase
71
  'options' => ['submitForSettlement' => true]
72
  ]);
73
 
74
- $transaction = Braintree_Test_Transaction::settlementDecline($transaction->id);
75
 
76
  $this->assertEquals('settlement_declined', $transaction->status);
77
  }
78
 
79
- function testSettlementPending()
80
  {
81
- $transaction = Braintree_Transaction::saleNoValidate([
82
  'amount' => '100.00',
83
  'creditCard' => [
84
  'number' => '5105105105105100',
@@ -87,7 +94,7 @@ class Braintree_TestTransactionTest extends PHPUnit_Framework_TestCase
87
  'options' => ['submitForSettlement' => true]
88
  ]);
89
 
90
- $transaction = Braintree_Test_Transaction::settlementPending($transaction->id);
91
 
92
  $this->assertEquals('settlement_pending', $transaction->status);
93
  }
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 TestTransactionTest extends Setup
12
  {
13
  public function setUp()
14
  {
15
+ Braintree\Configuration::environment('development');
16
  }
17
 
18
  /**
20
  */
21
  public function tearDownResetBraintreeEnvironment()
22
  {
23
+ Braintree\Configuration::environment('development');
24
  }
25
 
26
  /**
27
+ * @expectedException Exception\TestOperationPerformedInProduction
28
  */
29
+ public function testThrowingExceptionWhenProduction()
30
  {
31
+ Braintree\Configuration::environment('production');
32
 
33
+ $this->setExpectedException('Braintree\Exception\TestOperationPerformedInProduction');
34
 
35
+ $transaction = Braintree\Test\Transaction::settle('foo');
36
  }
37
 
38
+ public function testSettle()
39
  {
40
+ $transaction = Braintree\Transaction::saleNoValidate([
41
  'amount' => '100.00',
42
  'creditCard' => [
43
  'number' => '5105105105105100',
46
  'options' => ['submitForSettlement' => true]
47
  ]);
48
 
49
+ $transaction = Braintree\Test\Transaction::settle($transaction->id);
50
 
51
  $this->assertEquals('settled', $transaction->status);
52
  }
53
 
54
+ public function testSettlementConfirmed()
55
  {
56
+ $transaction = Braintree\Transaction::saleNoValidate([
57
  'amount' => '100.00',
58
  'creditCard' => [
59
  'number' => '5105105105105100',
62
  'options' => ['submitForSettlement' => true]
63
  ]);
64
 
65
+ $transaction = Braintree\Test\Transaction::settlementConfirm($transaction->id);
66
 
67
  $this->assertEquals('settlement_confirmed', $transaction->status);
68
  }
69
 
70
+ public function testSettlementDeclined()
71
  {
72
+ $transaction = Braintree\Transaction::saleNoValidate([
73
  'amount' => '100.00',
74
  'creditCard' => [
75
  'number' => '5105105105105100',
78
  'options' => ['submitForSettlement' => true]
79
  ]);
80
 
81
+ $transaction = Braintree\Test\Transaction::settlementDecline($transaction->id);
82
 
83
  $this->assertEquals('settlement_declined', $transaction->status);
84
  }
85
 
86
+ public function testSettlementPending()
87
  {
88
+ $transaction = Braintree\Transaction::saleNoValidate([
89
  'amount' => '100.00',
90
  'creditCard' => [
91
  'number' => '5105105105105100',
94
  'options' => ['submitForSettlement' => true]
95
  ]);
96
 
97
+ $transaction = Braintree\Test\Transaction::settlementPending($transaction->id);
98
 
99
  $this->assertEquals('settlement_pending', $transaction->status);
100
  }
braintree_sdk/tests/integration/TextNodeTest.php CHANGED
@@ -1,142 +1,147 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/SubscriptionTestHelper.php';
4
 
5
- class Braintree_TextNodeTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
6
  {
7
- function testIs()
8
  {
9
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
10
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
11
- $trialPlan = Braintree_SubscriptionTestHelper::trialPlan();
12
 
13
- $trialSubscription = Braintree_Subscription::create(array(
14
  'paymentMethodToken' => $creditCard->token,
15
  'planId' => $trialPlan['id'],
16
- 'price' => '5'
17
- ))->subscription;
18
 
19
- $triallessSubscription = Braintree_Subscription::create(array(
20
  'paymentMethodToken' => $creditCard->token,
21
  'planId' => $triallessPlan['id'],
22
- 'price' => '5'
23
- ))->subscription;
24
 
25
- $collection = Braintree_Subscription::search(array(
26
- Braintree_SubscriptionSearch::planId()->is("integration_trial_plan"),
27
- Braintree_SubscriptionSearch::price()->is('5')
28
- ));
29
 
30
- $this->assertTrue(Braintree_TestHelper::includes($collection, $trialSubscription));
31
- $this->assertFalse(Braintree_TestHelper::includes($collection, $triallessSubscription));
32
  }
33
 
34
- function testIsNot()
35
  {
36
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
37
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
38
- $trialPlan = Braintree_SubscriptionTestHelper::trialPlan();
39
 
40
- $trialSubscription = Braintree_Subscription::create(array(
41
  'paymentMethodToken' => $creditCard->token,
42
  'planId' => $trialPlan['id'],
43
- 'price' => '6'
44
- ))->subscription;
45
 
46
- $triallessSubscription = Braintree_Subscription::create(array(
47
  'paymentMethodToken' => $creditCard->token,
48
  'planId' => $triallessPlan['id'],
49
  'price' => '6'
50
- ))->subscription;
51
 
52
- $collection = Braintree_Subscription::search(array(
53
- Braintree_SubscriptionSearch::planId()->isNot("integration_trialless_plan"),
54
- Braintree_SubscriptionSearch::price()->is("6")
55
- ));
56
 
57
- $this->assertTrue(Braintree_TestHelper::includes($collection, $trialSubscription));
58
- $this->assertFalse(Braintree_TestHelper::includes($collection, $triallessSubscription));
59
  }
60
 
61
- function testStartsWith()
62
  {
63
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
64
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
65
- $trialPlan = Braintree_SubscriptionTestHelper::trialPlan();
66
 
67
- $trialSubscription = Braintree_Subscription::create(array(
68
  'paymentMethodToken' => $creditCard->token,
69
  'planId' => $trialPlan['id'],
70
- 'price' => '7'
71
- ))->subscription;
72
 
73
- $triallessSubscription = Braintree_Subscription::create(array(
74
  'paymentMethodToken' => $creditCard->token,
75
  'planId' => $triallessPlan['id'],
76
- 'price' => '7'
77
- ))->subscription;
78
 
79
- $collection = Braintree_Subscription::search(array(
80
- Braintree_SubscriptionSearch::planId()->startsWith("integration_trial_pl"),
81
- Braintree_SubscriptionSearch::price()->is("7")
82
- ));
83
 
84
- $this->assertTrue(Braintree_TestHelper::includes($collection, $trialSubscription));
85
- $this->assertFalse(Braintree_TestHelper::includes($collection, $triallessSubscription));
86
  }
87
 
88
- function testEndsWith()
89
  {
90
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
91
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
92
- $trialPlan = Braintree_SubscriptionTestHelper::trialPlan();
93
 
94
- $trialSubscription = Braintree_Subscription::create(array(
95
  'paymentMethodToken' => $creditCard->token,
96
  'planId' => $trialPlan['id'],
97
  'price' => '8'
98
- ))->subscription;
99
 
100
- $triallessSubscription = Braintree_Subscription::create(array(
101
  'paymentMethodToken' => $creditCard->token,
102
  'planId' => $triallessPlan['id'],
103
  'price' => '8'
104
- ))->subscription;
105
 
106
- $collection = Braintree_Subscription::search(array(
107
- Braintree_SubscriptionSearch::planId()->endsWith("rial_plan"),
108
- Braintree_SubscriptionSearch::price()->is("8")
109
- ));
110
 
111
- $this->assertTrue(Braintree_TestHelper::includes($collection, $trialSubscription));
112
- $this->assertFalse(Braintree_TestHelper::includes($collection, $triallessSubscription));
113
  }
114
 
115
 
116
- function testContains()
117
  {
118
- $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
119
- $triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
120
- $trialPlan = Braintree_SubscriptionTestHelper::trialPlan();
121
 
122
- $trialSubscription = Braintree_Subscription::create(array(
123
  'paymentMethodToken' => $creditCard->token,
124
  'planId' => $trialPlan['id'],
125
  'price' => '9'
126
- ))->subscription;
127
 
128
- $triallessSubscription = Braintree_Subscription::create(array(
129
  'paymentMethodToken' => $creditCard->token,
130
  'planId' => $triallessPlan['id'],
131
  'price' => '9'
132
- ))->subscription;
133
 
134
- $collection = Braintree_Subscription::search(array(
135
- Braintree_SubscriptionSearch::planId()->contains("ration_trial_pl"),
136
- Braintree_SubscriptionSearch::price()->is("9")
137
- ));
138
 
139
- $this->assertTrue(Braintree_TestHelper::includes($collection, $trialSubscription));
140
- $this->assertFalse(Braintree_TestHelper::includes($collection, $triallessSubscription));
141
  }
142
  }
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 TextNodeTest extends Setup
11
  {
12
+ public function testIs()
13
  {
14
+ $creditCard = SubscriptionHelper::createCreditCard();
15
+ $triallessPlan = SubscriptionHelper::triallessPlan();
16
+ $trialPlan = SubscriptionHelper::trialPlan();
17
 
18
+ $trialSubscription = Braintree\Subscription::create([
19
  'paymentMethodToken' => $creditCard->token,
20
  'planId' => $trialPlan['id'],
21
+ 'price' => '5',
22
+ ])->subscription;
23
 
24
+ $triallessSubscription = Braintree\Subscription::create([
25
  'paymentMethodToken' => $creditCard->token,
26
  'planId' => $triallessPlan['id'],
27
+ 'price' => '5',
28
+ ])->subscription;
29
 
30
+ $collection = Braintree\Subscription::search([
31
+ Braintree\SubscriptionSearch::planId()->is("integration_trial_plan"),
32
+ Braintree\SubscriptionSearch::price()->is('5')
33
+ ]);
34
 
35
+ $this->assertTrue(Test\Helper::includes($collection, $trialSubscription));
36
+ $this->assertFalse(Test\Helper::includes($collection, $triallessSubscription));
37
  }
38
 
39
+ public function testIsNot()
40
  {
41
+ $creditCard = SubscriptionHelper::createCreditCard();
42
+ $triallessPlan = SubscriptionHelper::triallessPlan();
43
+ $trialPlan = SubscriptionHelper::trialPlan();
44
 
45
+ $trialSubscription = Braintree\Subscription::create([
46
  'paymentMethodToken' => $creditCard->token,
47
  'planId' => $trialPlan['id'],
48
+ 'price' => '6',
49
+ ])->subscription;
50
 
51
+ $triallessSubscription = Braintree\Subscription::create([
52
  'paymentMethodToken' => $creditCard->token,
53
  'planId' => $triallessPlan['id'],
54
  'price' => '6'
55
+ ])->subscription;
56
 
57
+ $collection = Braintree\Subscription::search([
58
+ Braintree\SubscriptionSearch::planId()->isNot("integration_trialless_plan"),
59
+ Braintree\SubscriptionSearch::price()->is("6")
60
+ ]);
61
 
62
+ $this->assertTrue(Test\Helper::includes($collection, $trialSubscription));
63
+ $this->assertFalse(Test\Helper::includes($collection, $triallessSubscription));
64
  }
65
 
66
+ public function testStartsWith()
67
  {
68
+ $creditCard = SubscriptionHelper::createCreditCard();
69
+ $triallessPlan = SubscriptionHelper::triallessPlan();
70
+ $trialPlan = SubscriptionHelper::trialPlan();
71
 
72
+ $trialSubscription = Braintree\Subscription::create([
73
  'paymentMethodToken' => $creditCard->token,
74
  'planId' => $trialPlan['id'],
75
+ 'price' => '7',
76
+ ])->subscription;
77
 
78
+ $triallessSubscription = Braintree\Subscription::create([
79
  'paymentMethodToken' => $creditCard->token,
80
  'planId' => $triallessPlan['id'],
81
+ 'price' => '7',
82
+ ])->subscription;
83
 
84
+ $collection = Braintree\Subscription::search([
85
+ Braintree\SubscriptionSearch::planId()->startsWith("integration_trial_pl"),
86
+ Braintree\SubscriptionSearch::price()->is('7')
87
+ ]);
88
 
89
+ $this->assertTrue(Test\Helper::includes($collection, $trialSubscription));
90
+ $this->assertFalse(Test\Helper::includes($collection, $triallessSubscription));
91
  }
92
 
93
+ public function testEndsWith()
94
  {
95
+ $creditCard = SubscriptionHelper::createCreditCard();
96
+ $triallessPlan = SubscriptionHelper::triallessPlan();
97
+ $trialPlan = SubscriptionHelper::trialPlan();
98
 
99
+ $trialSubscription = Braintree\Subscription::create([
100
  'paymentMethodToken' => $creditCard->token,
101
  'planId' => $trialPlan['id'],
102
  'price' => '8'
103
+ ])->subscription;
104
 
105
+ $triallessSubscription = Braintree\Subscription::create([
106
  'paymentMethodToken' => $creditCard->token,
107
  'planId' => $triallessPlan['id'],
108
  'price' => '8'
109
+ ])->subscription;
110
 
111
+ $collection = Braintree\Subscription::search([
112
+ Braintree\SubscriptionSearch::planId()->endsWith("rial_plan"),
113
+ Braintree\SubscriptionSearch::price()->is("8")
114
+ ]);
115
 
116
+ $this->assertTrue(Test\Helper::includes($collection, $trialSubscription));
117
+ $this->assertFalse(Test\Helper::includes($collection, $triallessSubscription));
118
  }
119
 
120
 
121
+ public function testContains()
122
  {
123
+ $creditCard = SubscriptionHelper::createCreditCard();
124
+ $triallessPlan = SubscriptionHelper::triallessPlan();
125
+ $trialPlan = SubscriptionHelper::trialPlan();
126
 
127
+ $trialSubscription = Braintree\Subscription::create([
128
  'paymentMethodToken' => $creditCard->token,
129
  'planId' => $trialPlan['id'],
130
  'price' => '9'
131
+ ])->subscription;
132
 
133
+ $triallessSubscription = Braintree\Subscription::create([
134
  'paymentMethodToken' => $creditCard->token,
135
  'planId' => $triallessPlan['id'],
136
  'price' => '9'
137
+ ])->subscription;
138
 
139
+ $collection = Braintree\Subscription::search([
140
+ Braintree\SubscriptionSearch::planId()->contains("ration_trial_pl"),
141
+ Braintree\SubscriptionSearch::price()->is("9")
142
+ ]);
143
 
144
+ $this->assertTrue(Test\Helper::includes($collection, $trialSubscription));
145
+ $this->assertFalse(Test\Helper::includes($collection, $triallessSubscription));
146
  }
147
  }
braintree_sdk/tests/integration/TransactionAdvancedSearchTest.php CHANGED
@@ -1,24 +1,30 @@
1
  <?php
2
- require_once realpath(dirname(__FILE__)) . '/../TestHelper.php';
3
- require_once realpath(dirname(__FILE__)) . '/HttpClientApi.php';
4
 
5
- class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
 
 
 
 
 
 
 
6
  {
7
- function testNoMatches()
8
  {
9
- $collection = Braintree_Transaction::search(array(
10
- Braintree_TransactionSearch::billingFirstName()->is('thisnameisnotreal')
11
- ));
12
 
13
  $this->assertEquals(0, $collection->maximumCount());
14
  }
15
 
16
- function test_noRequestsWhenIterating()
17
  {
18
  $resultsReturned = false;
19
- $collection = Braintree_Transaction::search(array(
20
- Braintree_TransactionSearch::billingFirstName()->is('thisnameisnotreal')
21
- ));
22
 
23
  foreach($collection as $transaction) {
24
  $resultsReturned = true;
@@ -29,21 +35,21 @@ class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
29
  $this->assertEquals(false, $resultsReturned);
30
  }
31
 
32
- function testSearchOnTextFields()
33
  {
34
  $firstName = 'Tim' . rand();
35
  $token = 'creditcard' . rand();
36
  $customerId = 'customer' . rand();
37
 
38
- $transaction = Braintree_Transaction::saleNoValidate(array(
39
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
40
- 'creditCard' => array(
41
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
42
  'expirationDate' => '05/2012',
43
  'cardholderName' => 'Tom Smith',
44
  'token' => $token,
45
- ),
46
- 'billing' => array(
47
  'company' => 'Braintree',
48
  'countryName' => 'United States of America',
49
  'extendedAddress' => 'Suite 123',
@@ -53,8 +59,8 @@ class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
53
  'postalCode' => '12345',
54
  'region' => 'IL',
55
  'streetAddress' => '123 Main St'
56
- ),
57
- 'customer' => array(
58
  'company' => 'Braintree',
59
  'email' => 'smith@example.com',
60
  'fax' => '5551231234',
@@ -63,12 +69,12 @@ class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
63
  'lastName' => 'Smith',
64
  'phone' => '5551231234',
65
  'website' => 'http://example.com',
66
- ),
67
- 'options' => array(
68
  'storeInVault' => true
69
- ),
70
  'orderId' => 'myorder',
71
- 'shipping' => array(
72
  'company' => 'Braintree P.S.',
73
  'countryName' => 'Mexico',
74
  'extendedAddress' => 'Apt 456',
@@ -78,10 +84,10 @@ class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
78
  'postalCode' => '54321',
79
  'region' => 'MA',
80
  'streetAddress' => '456 Road'
81
- ),
82
- ));
83
 
84
- $search_criteria = array(
85
  'billingCompany' => "Braintree",
86
  'billingCountryName' => "United States of America",
87
  'billingExtendedAddress' => "Suite 123",
@@ -93,7 +99,7 @@ class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
93
  'billingStreetAddress' => "123 Main St",
94
  'creditCardCardholderName' => "Tom Smith",
95
  'creditCardExpirationDate' => "05/2012",
96
- 'creditCardNumber' => Braintree_Test_CreditCardNumbers::$visa,
97
  'creditCardUniqueIdentifier' => $transaction->creditCardDetails->uniqueNumberIdentifier,
98
  'customerCompany' => "Braintree",
99
  'customerEmail' => "smith@example.com",
@@ -117,614 +123,606 @@ class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
117
  'shippingRegion' => "MA",
118
  'shippingStreetAddress' => "456 Road",
119
  'user' => "integration_user_public_id"
120
- );
121
 
122
- $query = array(Braintree_TransactionSearch::id()->is($transaction->id));
123
  foreach ($search_criteria AS $criterion => $value) {
124
- $query[] = Braintree_TransactionSearch::$criterion()->is($value);
125
  }
126
 
127
- $collection = Braintree_Transaction::search($query);
128
 
129
  $this->assertEquals(1, $collection->maximumCount());
130
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
131
 
132
  foreach ($search_criteria AS $criterion => $value) {
133
- $collection = Braintree_Transaction::search(array(
134
- Braintree_TransactionSearch::$criterion()->is($value),
135
- Braintree_TransactionSearch::id()->is($transaction->id)
136
- ));
137
  $this->assertEquals(1, $collection->maximumCount());
138
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
139
 
140
- $collection = Braintree_Transaction::search(array(
141
- Braintree_TransactionSearch::$criterion()->is('invalid_attribute'),
142
- Braintree_TransactionSearch::id()->is($transaction->id)
143
- ));
144
  $this->assertEquals(0, $collection->maximumCount());
145
  }
146
  }
147
 
148
- function testIs()
149
  {
150
- $transaction = Braintree_Transaction::saleNoValidate(array(
151
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
152
- 'creditCard' => array(
153
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
154
  'expirationDate' => '05/2012',
155
  'cardholderName' => 'tom smith'
156
- )
157
- ));
158
 
159
- $collection = Braintree_Transaction::search(array(
160
- Braintree_TransactionSearch::id()->is($transaction->id),
161
- Braintree_TransactionSearch::creditCardCardholderName()->is('tom smith')
162
- ));
163
 
164
  $this->assertEquals(1, $collection->maximumCount());
165
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
166
 
167
- $collection = Braintree_Transaction::search(array(
168
- Braintree_TransactionSearch::id()->is($transaction->id),
169
- Braintree_TransactionSearch::creditCardCardholderName()->is('somebody else')
170
- ));
171
 
172
  $this->assertEquals(0, $collection->maximumCount());
173
  }
174
 
175
- function testIsNot()
176
  {
177
- $transaction = Braintree_Transaction::saleNoValidate(array(
178
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
179
- 'creditCard' => array(
180
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
181
  'expirationDate' => '05/2012',
182
  'cardholderName' => 'tom smith'
183
- )
184
- ));
185
 
186
- $collection = Braintree_Transaction::search(array(
187
- Braintree_TransactionSearch::id()->is($transaction->id),
188
- Braintree_TransactionSearch::creditCardCardholderName()->isNot('somebody else')
189
- ));
190
 
191
  $this->assertEquals(1, $collection->maximumCount());
192
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
193
 
194
- $collection = Braintree_Transaction::search(array(
195
- Braintree_TransactionSearch::id()->is($transaction->id),
196
- Braintree_TransactionSearch::creditCardCardholderName()->isNot('tom smith')
197
- ));
198
 
199
  $this->assertEquals(0, $collection->maximumCount());
200
  }
201
 
202
- function testEndsWith()
203
  {
204
- $transaction = Braintree_Transaction::saleNoValidate(array(
205
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
206
- 'creditCard' => array(
207
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
208
  'expirationDate' => '05/2012',
209
  'cardholderName' => 'tom smith'
210
- )
211
- ));
212
 
213
- $collection = Braintree_Transaction::search(array(
214
- Braintree_TransactionSearch::id()->is($transaction->id),
215
- Braintree_TransactionSearch::creditCardCardholderName()->endsWith('m smith')
216
- ));
217
 
218
  $this->assertEquals(1, $collection->maximumCount());
219
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
220
 
221
- $collection = Braintree_Transaction::search(array(
222
- Braintree_TransactionSearch::id()->is($transaction->id),
223
- Braintree_TransactionSearch::creditCardCardholderName()->endsWith('tom s')
224
- ));
225
 
226
  $this->assertEquals(0, $collection->maximumCount());
227
  }
228
 
229
- function testStartsWith()
230
  {
231
- $transaction = Braintree_Transaction::saleNoValidate(array(
232
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
233
- 'creditCard' => array(
234
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
235
  'expirationDate' => '05/2012',
236
  'cardholderName' => 'tom smith'
237
- )
238
- ));
239
 
240
- $collection = Braintree_Transaction::search(array(
241
- Braintree_TransactionSearch::id()->is($transaction->id),
242
- Braintree_TransactionSearch::creditCardCardholderName()->startsWith('tom s')
243
- ));
244
 
245
  $this->assertEquals(1, $collection->maximumCount());
246
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
247
 
248
- $collection = Braintree_Transaction::search(array(
249
- Braintree_TransactionSearch::id()->is($transaction->id),
250
- Braintree_TransactionSearch::creditCardCardholderName()->startsWith('m smith')
251
- ));
252
 
253
  $this->assertEquals(0, $collection->maximumCount());
254
  }
255
 
256
- function testContains()
257
  {
258
- $transaction = Braintree_Transaction::saleNoValidate(array(
259
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
260
- 'creditCard' => array(
261
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
262
  'expirationDate' => '05/2012',
263
  'cardholderName' => 'tom smith'
264
- )
265
- ));
266
 
267
- $collection = Braintree_Transaction::search(array(
268
- Braintree_TransactionSearch::id()->is($transaction->id),
269
- Braintree_TransactionSearch::creditCardCardholderName()->contains('m sm')
270
- ));
271
 
272
  $this->assertEquals(1, $collection->maximumCount());
273
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
274
 
275
- $collection = Braintree_Transaction::search(array(
276
- Braintree_TransactionSearch::id()->is($transaction->id),
277
- Braintree_TransactionSearch::creditCardCardholderName()->contains('something else')
278
- ));
279
 
280
  $this->assertEquals(0, $collection->maximumCount());
281
  }
282
 
283
- function test_multipleValueNode_createdUsing()
284
  {
285
- $transaction = Braintree_Transaction::saleNoValidate(array(
286
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
287
- 'creditCard' => array(
288
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
289
  'expirationDate' => '05/2012'
290
- )
291
- ));
292
 
293
- $collection = Braintree_Transaction::search(array(
294
- Braintree_TransactionSearch::id()->is($transaction->id),
295
- Braintree_TransactionSearch::createdUsing()->is(Braintree_Transaction::FULL_INFORMATION)
296
- ));
297
  $this->assertEquals(1, $collection->maximumCount());
298
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
299
 
300
- $collection = Braintree_Transaction::search(array(
301
- Braintree_TransactionSearch::id()->is($transaction->id),
302
- Braintree_TransactionSearch::createdUsing()->in(
303
- array(Braintree_Transaction::FULL_INFORMATION, Braintree_Transaction::TOKEN)
304
  )
305
- ));
306
  $this->assertEquals(1, $collection->maximumCount());
307
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
308
 
309
- $collection = Braintree_Transaction::search(array(
310
- Braintree_TransactionSearch::id()->is($transaction->id),
311
- Braintree_TransactionSearch::createdUsing()->in(array(Braintree_Transaction::TOKEN))
312
- ));
313
  $this->assertEquals(0, $collection->maximumCount());
314
  }
315
 
316
- function test_multipleValueNode_paymentInstrumentType_is_creditCard()
317
  {
318
- $transaction = Braintree_Transaction::saleNoValidate(array(
319
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
320
- 'creditCard' => array(
321
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
322
  'expirationDate' => '05/2012'
323
- )
324
- ));
325
 
326
- $collection = Braintree_Transaction::search(array(
327
- Braintree_TransactionSearch::id()->is($transaction->id),
328
- Braintree_TransactionSearch::paymentInstrumentType()->is("CreditCardDetail")
329
- ));
330
 
331
 
332
- $this->assertEquals($transaction->paymentInstrumentType, Braintree_PaymentInstrumentType::CREDIT_CARD);
333
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
334
  }
335
 
336
- function test_multipleValueNode_paymentInstrumentType_is_paypal()
337
  {
338
- $transaction = Braintree_Transaction::saleNoValidate(array(
339
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
340
- 'paymentMethodNonce' => Braintree_Test_Nonces::$paypalOneTimePayment
341
- ));
342
 
343
- $collection = Braintree_Transaction::search(array(
344
- Braintree_TransactionSearch::id()->is($transaction->id),
345
- Braintree_TransactionSearch::paymentInstrumentType()->is("PayPalDetail")
346
- ));
347
 
348
 
349
- $this->assertEquals($transaction->paymentInstrumentType, Braintree_PaymentInstrumentType::PAYPAL_ACCOUNT);
350
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
351
  }
352
 
353
- function test_multipleValueNode_paymentInstrumentType_is_applepay()
354
  {
355
- $transaction = Braintree_Transaction::saleNoValidate(array(
356
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
357
- 'paymentMethodNonce' => Braintree_Test_Nonces::$applePayVisa
358
- ));
359
 
360
- $collection = Braintree_Transaction::search(array(
361
- Braintree_TransactionSearch::id()->is($transaction->id),
362
- Braintree_TransactionSearch::paymentInstrumentType()->is("ApplePayDetail")
363
- ));
364
 
365
 
366
- $this->assertEquals($transaction->paymentInstrumentType, Braintree_PaymentInstrumentType::APPLE_PAY_CARD);
367
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
368
  }
369
 
370
- function test_multipleValueNode_createdUsing_allowedValues()
371
  {
372
  $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for created_using: noSuchCreatedUsing');
373
- $collection = Braintree_Transaction::search(array(
374
- Braintree_TransactionSearch::createdUsing()->is('noSuchCreatedUsing')
375
- ));
376
  }
377
 
378
- function test_multipleValueNode_creditCardCustomerLocation()
379
  {
380
- $transaction = Braintree_Transaction::saleNoValidate(array(
381
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
382
- 'creditCard' => array(
383
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
384
  'expirationDate' => '05/2012'
385
- )
386
- ));
387
 
388
- $collection = Braintree_Transaction::search(array(
389
- Braintree_TransactionSearch::id()->is($transaction->id),
390
- Braintree_TransactionSearch::creditCardCustomerLocation()->is(Braintree_CreditCard::US)
391
- ));
392
  $this->assertEquals(1, $collection->maximumCount());
393
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
394
 
395
- $collection = Braintree_Transaction::search(array(
396
- Braintree_TransactionSearch::id()->is($transaction->id),
397
- Braintree_TransactionSearch::creditCardCustomerLocation()->in(
398
- array(Braintree_CreditCard::US, Braintree_CreditCard::INTERNATIONAL)
399
  )
400
- ));
401
  $this->assertEquals(1, $collection->maximumCount());
402
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
403
 
404
- $collection = Braintree_Transaction::search(array(
405
- Braintree_TransactionSearch::id()->is($transaction->id),
406
- Braintree_TransactionSearch::creditCardCustomerLocation()->in(array(Braintree_CreditCard::INTERNATIONAL))
407
- ));
408
  $this->assertEquals(0, $collection->maximumCount());
409
  }
410
 
411
- function test_multipleValueNode_creditCardCustomerLocation_allowedValues()
412
  {
413
  $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for credit_card_customer_location: noSuchLocation');
414
- $collection = Braintree_Transaction::search(array(
415
- Braintree_TransactionSearch::creditCardCustomerLocation()->is('noSuchLocation')
416
- ));
417
  }
418
 
419
- function test_multipleValueNode_merchantAccountId()
420
  {
421
- $transaction = Braintree_Transaction::saleNoValidate(array(
422
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
423
- 'creditCard' => array(
424
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
425
  'expirationDate' => '05/2012'
426
- )
427
- ));
428
 
429
- $collection = Braintree_Transaction::search(array(
430
- Braintree_TransactionSearch::id()->is($transaction->id),
431
- Braintree_TransactionSearch::merchantAccountId()->is($transaction->merchantAccountId)
432
- ));
433
  $this->assertEquals(1, $collection->maximumCount());
434
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
435
 
436
- $collection = Braintree_Transaction::search(array(
437
- Braintree_TransactionSearch::id()->is($transaction->id),
438
- Braintree_TransactionSearch::merchantAccountId()->in(
439
- array($transaction->merchantAccountId, "bogus_merchant_account_id")
440
  )
441
- ));
442
  $this->assertEquals(1, $collection->maximumCount());
443
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
444
 
445
- $collection = Braintree_Transaction::search(array(
446
- Braintree_TransactionSearch::id()->is($transaction->id),
447
- Braintree_TransactionSearch::merchantAccountId()->is("bogus_merchant_account_id")
448
- ));
449
  $this->assertEquals(0, $collection->maximumCount());
450
  }
451
 
452
- function test_multipleValueNode_creditCardType()
453
  {
454
- $transaction = Braintree_Transaction::saleNoValidate(array(
455
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
456
- 'creditCard' => array(
457
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
458
  'expirationDate' => '05/2012'
459
- )
460
- ));
461
 
462
- $collection = Braintree_Transaction::search(array(
463
- Braintree_TransactionSearch::id()->is($transaction->id),
464
- Braintree_TransactionSearch::creditCardCardType()->is($transaction->creditCardDetails->cardType)
465
- ));
466
  $this->assertEquals(1, $collection->maximumCount());
467
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
468
 
469
- $collection = Braintree_Transaction::search(array(
470
- Braintree_TransactionSearch::id()->is($transaction->id),
471
- Braintree_TransactionSearch::creditCardCardType()->in(
472
- array($transaction->creditCardDetails->cardType, Braintree_CreditCard::CHINA_UNION_PAY)
473
  )
474
- ));
475
  $this->assertEquals(1, $collection->maximumCount());
476
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
477
 
478
- $collection = Braintree_Transaction::search(array(
479
- Braintree_TransactionSearch::id()->is($transaction->id),
480
- Braintree_TransactionSearch::creditCardCardType()->is(Braintree_CreditCard::CHINA_UNION_PAY)
481
- ));
482
  $this->assertEquals(0, $collection->maximumCount());
483
  }
484
 
485
- function test_multipleValueNode_creditCardType_allowedValues()
486
  {
487
  $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for credit_card_card_type: noSuchCardType');
488
- $collection = Braintree_Transaction::search(array(
489
- Braintree_TransactionSearch::creditCardCardType()->is('noSuchCardType')
490
- ));
491
  }
492
 
493
- function test_multipleValueNode_status()
494
  {
495
- $transaction = Braintree_Transaction::saleNoValidate(array(
496
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
497
- 'creditCard' => array(
498
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
499
  'expirationDate' => '05/2012'
500
- )
501
- ));
502
 
503
- $collection = Braintree_Transaction::search(array(
504
- Braintree_TransactionSearch::id()->is($transaction->id),
505
- Braintree_TransactionSearch::status()->is($transaction->status)
506
- ));
507
  $this->assertEquals(1, $collection->maximumCount());
508
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
509
 
510
- $collection = Braintree_Transaction::search(array(
511
- Braintree_TransactionSearch::id()->is($transaction->id),
512
- Braintree_TransactionSearch::status()->in(
513
- array($transaction->status, Braintree_Transaction::SETTLED)
514
  )
515
- ));
516
  $this->assertEquals(1, $collection->maximumCount());
517
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
518
 
519
- $collection = Braintree_Transaction::search(array(
520
- Braintree_TransactionSearch::id()->is($transaction->id),
521
- Braintree_TransactionSearch::status()->is(Braintree_Transaction::SETTLED)
522
- ));
523
  $this->assertEquals(0, $collection->maximumCount());
524
  }
525
 
526
- function test_multipleValueNode_status_authorizationExpired()
527
  {
528
- $collection = Braintree_Transaction::search(array(
529
- Braintree_TransactionSearch::status()->is(Braintree_Transaction::AUTHORIZATION_EXPIRED)
530
- ));
531
  $this->assertGreaterThan(0, $collection->maximumCount());
532
- $this->assertEquals(Braintree_Transaction::AUTHORIZATION_EXPIRED, $collection->firstItem()->status);
533
  }
534
 
535
- function test_multipleValueNode_status_allowedValues()
536
  {
537
  $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for status: noSuchStatus');
538
- $collection = Braintree_Transaction::search(array(
539
- Braintree_TransactionSearch::status()->is('noSuchStatus')
540
- ));
541
  }
542
 
543
- function test_multipleValueNode_source()
544
  {
545
- $transaction = Braintree_Transaction::saleNoValidate(array(
546
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
547
- 'creditCard' => array(
548
- 'number' => Braintree_Test_CreditCardNumbers::$visa,
549
  'expirationDate' => '05/2012'
550
- )
551
- ));
552
 
553
- $collection = Braintree_Transaction::search(array(
554
- Braintree_TransactionSearch::id()->is($transaction->id),
555
- Braintree_TransactionSearch::source()->is(Braintree_Transaction::API)
556
- ));
557
  $this->assertEquals(1, $collection->maximumCount());
558
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
559
 
560
- $collection = Braintree_Transaction::search(array(
561
- Braintree_TransactionSearch::id()->is($transaction->id),
562
- Braintree_TransactionSearch::source()->in(
563
- array(Braintree_Transaction::API, Braintree_Transaction::RECURRING)
564
  )
565
- ));
566
  $this->assertEquals(1, $collection->maximumCount());
567
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
568
 
569
- $collection = Braintree_Transaction::search(array(
570
- Braintree_TransactionSearch::id()->is($transaction->id),
571
- Braintree_TransactionSearch::source()->is(Braintree_Transaction::RECURRING)
572
- ));
573
  $this->assertEquals(0, $collection->maximumCount());
574
  }
575
 
576
- function test_multipleValueNode_source_allowedValues()
577
- {
578
- $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for source: noSuchSource');
579
- $collection = Braintree_Transaction::search(array(
580
- Braintree_TransactionSearch::source()->is('noSuchSource')
581
- ));
582
- }
583
-
584
- function test_multipleValueNode_type()
585
  {
586
- $customer = Braintree_Customer::createNoValidate();
587
- $creditCard = Braintree_CreditCard::create(array(
588
  'customerId' => $customer->id,
589
  'cardholderName' => 'Joe Everyman' . rand(),
590
  'number' => '5105105105105100',
591
  'expirationDate' => '05/12'
592
- ))->creditCard;
593
 
594
- $sale = Braintree_Transaction::saleNoValidate(array(
595
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
596
  'paymentMethodToken' => $creditCard->token,
597
- 'options' => array('submitForSettlement' => true)
598
- ));
599
- $http = new Braintree_Http(Braintree_Configuration::$global);
600
- $path = Braintree_Configuration::$global->merchantPath() . '/transactions/' . $sale->id . '/settle';
601
  $http->put($path);
602
- $refund = Braintree_Transaction::refund($sale->id)->transaction;
603
 
604
- $credit = Braintree_Transaction::creditNoValidate(array(
605
  'amount' => '100.00',
606
  'paymentMethodToken' => $creditCard->token
607
- ));
608
 
609
 
610
- $collection = Braintree_Transaction::search(array(
611
- Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
612
- Braintree_TransactionSearch::type()->is($sale->type)
613
- ));
614
  $this->assertEquals(1, $collection->maximumCount());
615
 
616
 
617
- $collection = Braintree_Transaction::search(array(
618
- Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
619
- Braintree_TransactionSearch::type()->in(
620
- array($sale->type, $credit->type)
621
  )
622
- ));
623
  $this->assertEquals(3, $collection->maximumCount());
624
 
625
 
626
- $collection = Braintree_Transaction::search(array(
627
- Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
628
- Braintree_TransactionSearch::type()->is($credit->type)
629
- ));
630
  $this->assertEquals(2, $collection->maximumCount());
631
  }
632
 
633
- function test_multipleValueNode_type_allowedValues()
634
  {
635
  $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for type: noSuchType');
636
- $collection = Braintree_Transaction::search(array(
637
- Braintree_TransactionSearch::type()->is('noSuchType')
638
- ));
639
  }
640
 
641
- function test_multipleValueNode_type_withRefund()
642
  {
643
- $customer = Braintree_Customer::createNoValidate();
644
- $creditCard = Braintree_CreditCard::create(array(
645
  'customerId' => $customer->id,
646
  'cardholderName' => 'Joe Everyman' . rand(),
647
  'number' => '5105105105105100',
648
  'expirationDate' => '05/12'
649
- ))->creditCard;
650
 
651
- $sale = Braintree_Transaction::saleNoValidate(array(
652
- 'amount' => Braintree_Test_TransactionAmounts::$authorize,
653
  'paymentMethodToken' => $creditCard->token,
654
- 'options' => array('submitForSettlement' => true)
655
- ));
656
- $http = new Braintree_Http(Braintree_Configuration::$global);
657
- $path = Braintree_Configuration::$global->merchantPath() . '/transactions/' . $sale->id . '/settle';
658
  $http->put($path);
659
- $refund = Braintree_Transaction::refund($sale->id)->transaction;
660
 
661
- $credit = Braintree_Transaction::creditNoValidate(array(
662
  'amount' => '100.00',
663
  'paymentMethodToken' => $creditCard->token
664
- ));
665
 
666
- $collection = Braintree_Transaction::search(array(
667
- Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
668
- Braintree_TransactionSearch::type()->is($credit->type),
669
- Braintree_TransactionSearch::refund()->is(True)
670
- ));
671
  $this->assertEquals(1, $collection->maximumCount());
672
  $this->assertEquals($refund->id, $collection->firstItem()->id);
673
 
674
- $collection = Braintree_Transaction::search(array(
675
- Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
676
- Braintree_TransactionSearch::type()->is($credit->type),
677
- Braintree_TransactionSearch::refund()->is(False)
678
- ));
679
  $this->assertEquals(1, $collection->maximumCount());
680
  $this->assertEquals($credit->id, $collection->firstItem()->id);
681
  }
682
 
683
- function test_rangeNode_amount()
684
  {
685
- $customer = Braintree_Customer::createNoValidate();
686
- $creditCard = Braintree_CreditCard::create(array(
687
  'customerId' => $customer->id,
688
  'cardholderName' => 'Jane Everywoman' . rand(),
689
  'number' => '5105105105105100',
690
  'expirationDate' => '05/12'
691
- ))->creditCard;
692
 
693
- $t_1000 = Braintree_Transaction::saleNoValidate(array(
694
  'amount' => '1000.00',
695
  'paymentMethodToken' => $creditCard->token
696
- ));
697
 
698
- $t_1500 = Braintree_Transaction::saleNoValidate(array(
699
  'amount' => '1500.00',
700
  'paymentMethodToken' => $creditCard->token
701
- ));
702
 
703
- $t_1800 = Braintree_Transaction::saleNoValidate(array(
704
  'amount' => '1800.00',
705
  'paymentMethodToken' => $creditCard->token
706
- ));
707
 
708
- $collection = Braintree_Transaction::search(array(
709
- Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
710
- Braintree_TransactionSearch::amount()->greaterThanOrEqualTo('1700')
711
- ));
712
 
713
  $this->assertEquals(1, $collection->maximumCount());
714
  $this->assertEquals($t_1800->id, $collection->firstItem()->id);
715
 
716
- $collection = Braintree_Transaction::search(array(
717
- Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
718
- Braintree_TransactionSearch::amount()->lessThanOrEqualTo('1250')
719
- ));
720
 
721
  $this->assertEquals(1, $collection->maximumCount());
722
  $this->assertEquals($t_1000->id, $collection->firstItem()->id);
723
 
724
- $collection = Braintree_Transaction::search(array(
725
- Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
726
- Braintree_TransactionSearch::amount()->between('1100', '1600')
727
- ));
728
 
729
  $this->assertEquals(1, $collection->maximumCount());
730
  $this->assertEquals($t_1500->id, $collection->firstItem()->id);
@@ -739,27 +737,27 @@ class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
739
  $future = clone $now;
740
  $future->modify("+1 hour");
741
 
742
- $collections = array(
743
- 'future' => Braintree_Transaction::search(array(
744
- Braintree_TransactionSearch::id()->is($knownDepositId),
745
  $comparison($future)
746
- )),
747
- 'now' => Braintree_Transaction::search(array(
748
- Braintree_TransactionSearch::id()->is($knownDepositId),
749
  $comparison($now)
750
- )),
751
- 'past' => Braintree_Transaction::search(array(
752
- Braintree_TransactionSearch::id()->is($knownDepositId),
753
  $comparison($past)
754
- ))
755
- );
756
  return $collections;
757
  }
758
 
759
- function test_rangeNode_disbursementDate_lessThanOrEqualTo()
760
  {
761
  $compareLessThan = function($time) {
762
- return Braintree_TransactionSearch::disbursementDate()->lessThanOrEqualTo($time);
763
  };
764
  $collection = $this->runDisbursementDateSearchTests("2013-04-10", $compareLessThan);
765
 
@@ -768,10 +766,10 @@ class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
768
  $this->assertEquals(1, $collection['future']->maximumCount());
769
  }
770
 
771
- function test_rangeNode_disbursementDate_GreaterThanOrEqualTo()
772
  {
773
  $comparison = function($time) {
774
- return Braintree_TransactionSearch::disbursementDate()->GreaterThanOrEqualTo($time);
775
  };
776
  $collection = $this->runDisbursementDateSearchTests("2013-04-11", $comparison);
777
 
@@ -780,7 +778,7 @@ class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
780
  $this->assertEquals(0, $collection['future']->maximumCount());
781
  }
782
 
783
- function test_rangeNode_disbursementDate_between()
784
  {
785
  $knownId = "deposittransaction";
786
 
@@ -792,35 +790,35 @@ class Braintree_TransactionAdvancedSearchTest extends PHPUnit_Framework_TestCase
792
  $future2 = clone $now;
793
  $future2->modify("+2 days");
794
 
795
- $collection = Braintree_Transaction::search(array(
796
- Braintree_TransactionSearch::id()->is($knownId),
797
- Braintree_TransactionSearch::disbursementDate()->between($past, $future)
798
- ));
799
  $this->assertEquals(1, $collection->maximumCount());
800
  $this->assertEquals($knownId, $collection->firstItem()->id);
801
 
802
- $collection = Braintree_Transaction::search(array(
803
- Braintree_TransactionSearch::id()->is($knownId),
804
- Braintree_TransactionSearch::disbursementDate()->between($now, $future)
805
- ));
806
  $this->assertEquals(1, $collection->maximumCount());
807
  $this->assertEquals($knownId, $collection->firstItem()->id);
808
 
809
- $collection = Braintree_Transaction::search(array(
810
- Braintree_TransactionSearch::id()->is($knownId),
811
- Braintree_TransactionSearch::disbursementDate()->between($past, $now)
812
- ));
813
  $this->assertEquals(1, $collection->maximumCount());
814
  $this->assertEquals($knownId, $collection->firstItem()->id);
815
 
816
- $collection = Braintree_Transaction::search(array(
817
- Braintree_TransactionSearch::id()->is($knownId),
818
- Braintree_TransactionSearch::disbursementDate()->between($future, $future2)
819
- ));
820
  $this->assertEquals(0, $collection->maximumCount());
821
  }
822
 
823
- function test_rangeNode_disbursementDate_is()
824
  {
825
  $knownId = "deposittransaction";
826
 
@@ -832,23 +830,2
1
  <?php
2
+ namespace Test\Integration;
 
3
 
4
+ require_once dirname(__DIR__) . '/Setup.php';
5
+
6
+ use DateTime;
7
+ use DateTimeZone;
8
+ use Test\Setup;
9
+ use Braintree;
10
+
11
+ class TransactionAdvancedSearchTest extends Setup
12
  {
13
+ public function testNoMatches()
14
  {
15
+ $collection = Braintree\Transaction::search([
16
+ Braintree\TransactionSearch::billingFirstName()->is('thisnameisnotreal')
17
+ ]);
18
 
19
  $this->assertEquals(0, $collection->maximumCount());
20
  }
21
 
22
+ public function test_noRequestsWhenIterating()
23
  {
24
  $resultsReturned = false;
25
+ $collection = Braintree\Transaction::search([
26
+ Braintree\TransactionSearch::billingFirstName()->is('thisnameisnotreal')
27
+ ]);
28
 
29
  foreach($collection as $transaction) {
30
  $resultsReturned = true;
35
  $this->assertEquals(false, $resultsReturned);
36
  }
37
 
38
+ public function testSearchOnTextFields()
39
  {
40
  $firstName = 'Tim' . rand();
41
  $token = 'creditcard' . rand();
42
  $customerId = 'customer' . rand();
43
 
44
+ $transaction = Braintree\Transaction::saleNoValidate([
45
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
46
+ 'creditCard' => [
47
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
48
  'expirationDate' => '05/2012',
49
  'cardholderName' => 'Tom Smith',
50
  'token' => $token,
51
+ ],
52
+ 'billing' => [
53
  'company' => 'Braintree',
54
  'countryName' => 'United States of America',
55
  'extendedAddress' => 'Suite 123',
59
  'postalCode' => '12345',
60
  'region' => 'IL',
61
  'streetAddress' => '123 Main St'
62
+ ],
63
+ 'customer' => [
64
  'company' => 'Braintree',
65
  'email' => 'smith@example.com',
66
  'fax' => '5551231234',
69
  'lastName' => 'Smith',
70
  'phone' => '5551231234',
71
  'website' => 'http://example.com',
72
+ ],
73
+ 'options' => [
74
  'storeInVault' => true
75
+ ],
76
  'orderId' => 'myorder',
77
+ 'shipping' => [
78
  'company' => 'Braintree P.S.',
79
  'countryName' => 'Mexico',
80
  'extendedAddress' => 'Apt 456',
84
  'postalCode' => '54321',
85
  'region' => 'MA',
86
  'streetAddress' => '456 Road'
87
+ ],
88
+ ]);
89
 
90
+ $search_criteria = [
91
  'billingCompany' => "Braintree",
92
  'billingCountryName' => "United States of America",
93
  'billingExtendedAddress' => "Suite 123",
99
  'billingStreetAddress' => "123 Main St",
100
  'creditCardCardholderName' => "Tom Smith",
101
  'creditCardExpirationDate' => "05/2012",
102
+ 'creditCardNumber' => Braintree\Test\CreditCardNumbers::$visa,
103
  'creditCardUniqueIdentifier' => $transaction->creditCardDetails->uniqueNumberIdentifier,
104
  'customerCompany' => "Braintree",
105
  'customerEmail' => "smith@example.com",
123
  'shippingRegion' => "MA",
124
  'shippingStreetAddress' => "456 Road",
125
  'user' => "integration_user_public_id"
126
+ ];
127
 
128
+ $query = [Braintree\TransactionSearch::id()->is($transaction->id)];
129
  foreach ($search_criteria AS $criterion => $value) {
130
+ $query[] = Braintree\TransactionSearch::$criterion()->is($value);
131
  }
132
 
133
+ $collection = Braintree\Transaction::search($query);
134
 
135
  $this->assertEquals(1, $collection->maximumCount());
136
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
137
 
138
  foreach ($search_criteria AS $criterion => $value) {
139
+ $collection = Braintree\Transaction::search([
140
+ Braintree\TransactionSearch::$criterion()->is($value),
141
+ Braintree\TransactionSearch::id()->is($transaction->id)
142
+ ]);
143
  $this->assertEquals(1, $collection->maximumCount());
144
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
145
 
146
+ $collection = Braintree\Transaction::search([
147
+ Braintree\TransactionSearch::$criterion()->is('invalid_attribute'),
148
+ Braintree\TransactionSearch::id()->is($transaction->id)
149
+ ]);
150
  $this->assertEquals(0, $collection->maximumCount());
151
  }
152
  }
153
 
154
+ public function testIs()
155
  {
156
+ $transaction = Braintree\Transaction::saleNoValidate([
157
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
158
+ 'creditCard' => [
159
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
160
  'expirationDate' => '05/2012',
161
  'cardholderName' => 'tom smith'
162
+ ]
163
+ ]);
164
 
165
+ $collection = Braintree\Transaction::search([
166
+ Braintree\TransactionSearch::id()->is($transaction->id),
167
+ Braintree\TransactionSearch::creditCardCardholderName()->is('tom smith')
168
+ ]);
169
 
170
  $this->assertEquals(1, $collection->maximumCount());
171
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
172
 
173
+ $collection = Braintree\Transaction::search([
174
+ Braintree\TransactionSearch::id()->is($transaction->id),
175
+ Braintree\TransactionSearch::creditCardCardholderName()->is('somebody else')
176
+ ]);
177
 
178
  $this->assertEquals(0, $collection->maximumCount());
179
  }
180
 
181
+ public function testIsNot()
182
  {
183
+ $transaction = Braintree\Transaction::saleNoValidate([
184
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
185
+ 'creditCard' => [
186
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
187
  'expirationDate' => '05/2012',
188
  'cardholderName' => 'tom smith'
189
+ ]
190
+ ]);
191
 
192
+ $collection = Braintree\Transaction::search([
193
+ Braintree\TransactionSearch::id()->is($transaction->id),
194
+ Braintree\TransactionSearch::creditCardCardholderName()->isNot('somebody else')
195
+ ]);
196
 
197
  $this->assertEquals(1, $collection->maximumCount());
198
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
199
 
200
+ $collection = Braintree\Transaction::search([
201
+ Braintree\TransactionSearch::id()->is($transaction->id),
202
+ Braintree\TransactionSearch::creditCardCardholderName()->isNot('tom smith')
203
+ ]);
204
 
205
  $this->assertEquals(0, $collection->maximumCount());
206
  }
207
 
208
+ public function testEndsWith()
209
  {
210
+ $transaction = Braintree\Transaction::saleNoValidate([
211
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
212
+ 'creditCard' => [
213
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
214
  'expirationDate' => '05/2012',
215
  'cardholderName' => 'tom smith'
216
+ ]
217
+ ]);
218
 
219
+ $collection = Braintree\Transaction::search([
220
+ Braintree\TransactionSearch::id()->is($transaction->id),
221
+ Braintree\TransactionSearch::creditCardCardholderName()->endsWith('m smith')
222
+ ]);
223
 
224
  $this->assertEquals(1, $collection->maximumCount());
225
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
226
 
227
+ $collection = Braintree\Transaction::search([
228
+ Braintree\TransactionSearch::id()->is($transaction->id),
229
+ Braintree\TransactionSearch::creditCardCardholderName()->endsWith('tom s')
230
+ ]);
231
 
232
  $this->assertEquals(0, $collection->maximumCount());
233
  }
234
 
235
+ public function testStartsWith()
236
  {
237
+ $transaction = Braintree\Transaction::saleNoValidate([
238
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
239
+ 'creditCard' => [
240
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
241
  'expirationDate' => '05/2012',
242
  'cardholderName' => 'tom smith'
243
+ ]
244
+ ]);
245
 
246
+ $collection = Braintree\Transaction::search([
247
+ Braintree\TransactionSearch::id()->is($transaction->id),
248
+ Braintree\TransactionSearch::creditCardCardholderName()->startsWith('tom s')
249
+ ]);
250
 
251
  $this->assertEquals(1, $collection->maximumCount());
252
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
253
 
254
+ $collection = Braintree\Transaction::search([
255
+ Braintree\TransactionSearch::id()->is($transaction->id),
256
+ Braintree\TransactionSearch::creditCardCardholderName()->startsWith('m smith')
257
+ ]);
258
 
259
  $this->assertEquals(0, $collection->maximumCount());
260
  }
261
 
262
+ public function testContains()
263
  {
264
+ $transaction = Braintree\Transaction::saleNoValidate([
265
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
266
+ 'creditCard' => [
267
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
268
  'expirationDate' => '05/2012',
269
  'cardholderName' => 'tom smith'
270
+ ]
271
+ ]);
272
 
273
+ $collection = Braintree\Transaction::search([
274
+ Braintree\TransactionSearch::id()->is($transaction->id),
275
+ Braintree\TransactionSearch::creditCardCardholderName()->contains('m sm')
276
+ ]);
277
 
278
  $this->assertEquals(1, $collection->maximumCount());
279
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
280
 
281
+ $collection = Braintree\Transaction::search([
282
+ Braintree\TransactionSearch::id()->is($transaction->id),
283
+ Braintree\TransactionSearch::creditCardCardholderName()->contains('something else')
284
+ ]);
285
 
286
  $this->assertEquals(0, $collection->maximumCount());
287
  }
288
 
289
+ public function test_multipleValueNode_createdUsing()
290
  {
291
+ $transaction = Braintree\Transaction::saleNoValidate([
292
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
293
+ 'creditCard' => [
294
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
295
  'expirationDate' => '05/2012'
296
+ ]
297
+ ]);
298
 
299
+ $collection = Braintree\Transaction::search([
300
+ Braintree\TransactionSearch::id()->is($transaction->id),
301
+ Braintree\TransactionSearch::createdUsing()->is(Braintree\Transaction::FULL_INFORMATION)
302
+ ]);
303
  $this->assertEquals(1, $collection->maximumCount());
304
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
305
 
306
+ $collection = Braintree\Transaction::search([
307
+ Braintree\TransactionSearch::id()->is($transaction->id),
308
+ Braintree\TransactionSearch::createdUsing()->in(
309
+ [Braintree\Transaction::FULL_INFORMATION, Braintree\Transaction::TOKEN]
310
  )
311
+ ]);
312
  $this->assertEquals(1, $collection->maximumCount());
313
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
314
 
315
+ $collection = Braintree\Transaction::search([
316
+ Braintree\TransactionSearch::id()->is($transaction->id),
317
+ Braintree\TransactionSearch::createdUsing()->in([Braintree\Transaction::TOKEN])
318
+ ]);
319
  $this->assertEquals(0, $collection->maximumCount());
320
  }
321
 
322
+ public function test_multipleValueNode_paymentInstrumentType_is_creditCard()
323
  {
324
+ $transaction = Braintree\Transaction::saleNoValidate([
325
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
326
+ 'creditCard' => [
327
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
328
  'expirationDate' => '05/2012'
329
+ ]
330
+ ]);
331
 
332
+ $collection = Braintree\Transaction::search([
333
+ Braintree\TransactionSearch::id()->is($transaction->id),
334
+ Braintree\TransactionSearch::paymentInstrumentType()->is("CreditCardDetail")
335
+ ]);
336
 
337
 
338
+ $this->assertEquals($transaction->paymentInstrumentType, Braintree\PaymentInstrumentType::CREDIT_CARD);
339
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
340
  }
341
 
342
+ public function test_multipleValueNode_paymentInstrumentType_is_paypal()
343
  {
344
+ $transaction = Braintree\Transaction::saleNoValidate([
345
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
346
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$paypalOneTimePayment
347
+ ]);
348
 
349
+ $collection = Braintree\Transaction::search([
350
+ Braintree\TransactionSearch::id()->is($transaction->id),
351
+ Braintree\TransactionSearch::paymentInstrumentType()->is("PayPalDetail")
352
+ ]);
353
 
354
 
355
+ $this->assertEquals($transaction->paymentInstrumentType, Braintree\PaymentInstrumentType::PAYPAL_ACCOUNT);
356
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
357
  }
358
 
359
+ public function test_multipleValueNode_paymentInstrumentType_is_applepay()
360
  {
361
+ $transaction = Braintree\Transaction::saleNoValidate([
362
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
363
+ 'paymentMethodNonce' => Braintree\Test\Nonces::$applePayVisa
364
+ ]);
365
 
366
+ $collection = Braintree\Transaction::search([
367
+ Braintree\TransactionSearch::id()->is($transaction->id),
368
+ Braintree\TransactionSearch::paymentInstrumentType()->is("ApplePayDetail")
369
+ ]);
370
 
371
 
372
+ $this->assertEquals($transaction->paymentInstrumentType, Braintree\PaymentInstrumentType::APPLE_PAY_CARD);
373
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
374
  }
375
 
376
+ public function test_multipleValueNode_createdUsing_allowedValues()
377
  {
378
  $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for created_using: noSuchCreatedUsing');
379
+ $collection = Braintree\Transaction::search([
380
+ Braintree\TransactionSearch::createdUsing()->is('noSuchCreatedUsing')
381
+ ]);
382
  }
383
 
384
+ public function test_multipleValueNode_creditCardCustomerLocation()
385
  {
386
+ $transaction = Braintree\Transaction::saleNoValidate([
387
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
388
+ 'creditCard' => [
389
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
390
  'expirationDate' => '05/2012'
391
+ ]
392
+ ]);
393
 
394
+ $collection = Braintree\Transaction::search([
395
+ Braintree\TransactionSearch::id()->is($transaction->id),
396
+ Braintree\TransactionSearch::creditCardCustomerLocation()->is(Braintree\CreditCard::US)
397
+ ]);
398
  $this->assertEquals(1, $collection->maximumCount());
399
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
400
 
401
+ $collection = Braintree\Transaction::search([
402
+ Braintree\TransactionSearch::id()->is($transaction->id),
403
+ Braintree\TransactionSearch::creditCardCustomerLocation()->in(
404
+ [Braintree\CreditCard::US, Braintree\CreditCard::INTERNATIONAL]
405
  )
406
+ ]);
407
  $this->assertEquals(1, $collection->maximumCount());
408
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
409
 
410
+ $collection = Braintree\Transaction::search([
411
+ Braintree\TransactionSearch::id()->is($transaction->id),
412
+ Braintree\TransactionSearch::creditCardCustomerLocation()->in([Braintree\CreditCard::INTERNATIONAL])
413
+ ]);
414
  $this->assertEquals(0, $collection->maximumCount());
415
  }
416
 
417
+ public function test_multipleValueNode_creditCardCustomerLocation_allowedValues()
418
  {
419
  $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for credit_card_customer_location: noSuchLocation');
420
+ $collection = Braintree\Transaction::search([
421
+ Braintree\TransactionSearch::creditCardCustomerLocation()->is('noSuchLocation')
422
+ ]);
423
  }
424
 
425
+ public function test_multipleValueNode_merchantAccountId()
426
  {
427
+ $transaction = Braintree\Transaction::saleNoValidate([
428
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
429
+ 'creditCard' => [
430
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
431
  'expirationDate' => '05/2012'
432
+ ]
433
+ ]);
434
 
435
+ $collection = Braintree\Transaction::search([
436
+ Braintree\TransactionSearch::id()->is($transaction->id),
437
+ Braintree\TransactionSearch::merchantAccountId()->is($transaction->merchantAccountId)
438
+ ]);
439
  $this->assertEquals(1, $collection->maximumCount());
440
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
441
 
442
+ $collection = Braintree\Transaction::search([
443
+ Braintree\TransactionSearch::id()->is($transaction->id),
444
+ Braintree\TransactionSearch::merchantAccountId()->in(
445
+ [$transaction->merchantAccountId, "bogus_merchant_account_id"]
446
  )
447
+ ]);
448
  $this->assertEquals(1, $collection->maximumCount());
449
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
450
 
451
+ $collection = Braintree\Transaction::search([
452
+ Braintree\TransactionSearch::id()->is($transaction->id),
453
+ Braintree\TransactionSearch::merchantAccountId()->is('bogus_merchant_account_id')
454
+ ]);
455
  $this->assertEquals(0, $collection->maximumCount());
456
  }
457
 
458
+ public function test_multipleValueNode_creditCardType()
459
  {
460
+ $transaction = Braintree\Transaction::saleNoValidate([
461
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
462
+ 'creditCard' => [
463
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
464
  'expirationDate' => '05/2012'
465
+ ]
466
+ ]);
467
 
468
+ $collection = Braintree\Transaction::search([
469
+ Braintree\TransactionSearch::id()->is($transaction->id),
470
+ Braintree\TransactionSearch::creditCardCardType()->is($transaction->creditCardDetails->cardType)
471
+ ]);
472
  $this->assertEquals(1, $collection->maximumCount());
473
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
474
 
475
+ $collection = Braintree\Transaction::search([
476
+ Braintree\TransactionSearch::id()->is($transaction->id),
477
+ Braintree\TransactionSearch::creditCardCardType()->in(
478
+ [$transaction->creditCardDetails->cardType, Braintree\CreditCard::CHINA_UNION_PAY]
479
  )
480
+ ]);
481
  $this->assertEquals(1, $collection->maximumCount());
482
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
483
 
484
+ $collection = Braintree\Transaction::search([
485
+ Braintree\TransactionSearch::id()->is($transaction->id),
486
+ Braintree\TransactionSearch::creditCardCardType()->is(Braintree\CreditCard::CHINA_UNION_PAY)
487
+ ]);
488
  $this->assertEquals(0, $collection->maximumCount());
489
  }
490
 
491
+ public function test_multipleValueNode_creditCardType_allowedValues()
492
  {
493
  $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for credit_card_card_type: noSuchCardType');
494
+ $collection = Braintree\Transaction::search([
495
+ Braintree\TransactionSearch::creditCardCardType()->is('noSuchCardType')
496
+ ]);
497
  }
498
 
499
+ public function test_multipleValueNode_status()
500
  {
501
+ $transaction = Braintree\Transaction::saleNoValidate([
502
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
503
+ 'creditCard' => [
504
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
505
  'expirationDate' => '05/2012'
506
+ ]
507
+ ]);
508
 
509
+ $collection = Braintree\Transaction::search([
510
+ Braintree\TransactionSearch::id()->is($transaction->id),
511
+ Braintree\TransactionSearch::status()->is($transaction->status)
512
+ ]);
513
  $this->assertEquals(1, $collection->maximumCount());
514
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
515
 
516
+ $collection = Braintree\Transaction::search([
517
+ Braintree\TransactionSearch::id()->is($transaction->id),
518
+ Braintree\TransactionSearch::status()->in(
519
+ [$transaction->status, Braintree\Transaction::SETTLED]
520
  )
521
+ ]);
522
  $this->assertEquals(1, $collection->maximumCount());
523
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
524
 
525
+ $collection = Braintree\Transaction::search([
526
+ Braintree\TransactionSearch::id()->is($transaction->id),
527
+ Braintree\TransactionSearch::status()->is(Braintree\Transaction::SETTLED)
528
+ ]);
529
  $this->assertEquals(0, $collection->maximumCount());
530
  }
531
 
532
+ public function test_multipleValueNode_status_authorizationExpired()
533
  {
534
+ $collection = Braintree\Transaction::search([
535
+ Braintree\TransactionSearch::status()->is(Braintree\Transaction::AUTHORIZATION_EXPIRED)
536
+ ]);
537
  $this->assertGreaterThan(0, $collection->maximumCount());
538
+ $this->assertEquals(Braintree\Transaction::AUTHORIZATION_EXPIRED, $collection->firstItem()->status);
539
  }
540
 
541
+ public function test_multipleValueNode_status_allowedValues()
542
  {
543
  $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for status: noSuchStatus');
544
+ $collection = Braintree\Transaction::search([
545
+ Braintree\TransactionSearch::status()->is('noSuchStatus')
546
+ ]);
547
  }
548
 
549
+ public function test_multipleValueNode_source()
550
  {
551
+ $transaction = Braintree\Transaction::saleNoValidate([
552
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
553
+ 'creditCard' => [
554
+ 'number' => Braintree\Test\CreditCardNumbers::$visa,
555
  'expirationDate' => '05/2012'
556
+ ]
557
+ ]);
558
 
559
+ $collection = Braintree\Transaction::search([
560
+ Braintree\TransactionSearch::id()->is($transaction->id),
561
+ Braintree\TransactionSearch::source()->is(Braintree\Transaction::API)
562
+ ]);
563
  $this->assertEquals(1, $collection->maximumCount());
564
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
565
 
566
+ $collection = Braintree\Transaction::search([
567
+ Braintree\TransactionSearch::id()->is($transaction->id),
568
+ Braintree\TransactionSearch::source()->in(
569
+ [Braintree\Transaction::API, Braintree\Transaction::RECURRING]
570
  )
571
+ ]);
572
  $this->assertEquals(1, $collection->maximumCount());
573
  $this->assertEquals($transaction->id, $collection->firstItem()->id);
574
 
575
+ $collection = Braintree\Transaction::search([
576
+ Braintree\TransactionSearch::id()->is($transaction->id),
577
+ Braintree\TransactionSearch::source()->is(Braintree\Transaction::RECURRING)
578
+ ]);
579
  $this->assertEquals(0, $collection->maximumCount());
580
  }
581
 
582
+ public function test_multipleValueNode_type()
 
 
 
 
 
 
 
 
583
  {
584
+ $customer = Braintree\Customer::createNoValidate();
585
+ $creditCard = Braintree\CreditCard::create([
586
  'customerId' => $customer->id,
587
  'cardholderName' => 'Joe Everyman' . rand(),
588
  'number' => '5105105105105100',
589
  'expirationDate' => '05/12'
590
+ ])->creditCard;
591
 
592
+ $sale = Braintree\Transaction::saleNoValidate([
593
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
594
  'paymentMethodToken' => $creditCard->token,
595
+ 'options' => ['submitForSettlement' => true]
596
+ ]);
597
+ $http = new Braintree\Http(Braintree\Configuration::$global);
598
+ $path = Braintree\Configuration::$global->merchantPath() . '/transactions/' . $sale->id . '/settle';
599
  $http->put($path);
600
+ $refund = Braintree\Transaction::refund($sale->id)->transaction;
601
 
602
+ $credit = Braintree\Transaction::creditNoValidate([
603
  'amount' => '100.00',
604
  'paymentMethodToken' => $creditCard->token
605
+ ]);
606
 
607
 
608
+ $collection = Braintree\Transaction::search([
609
+ Braintree\TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
610
+ Braintree\TransactionSearch::type()->is($sale->type)
611
+ ]);
612
  $this->assertEquals(1, $collection->maximumCount());
613
 
614
 
615
+ $collection = Braintree\Transaction::search([
616
+ Braintree\TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
617
+ Braintree\TransactionSearch::type()->in(
618
+ [$sale->type, $credit->type]
619
  )
620
+ ]);
621
  $this->assertEquals(3, $collection->maximumCount());
622
 
623
 
624
+ $collection = Braintree\Transaction::search([
625
+ Braintree\TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
626
+ Braintree\TransactionSearch::type()->is($credit->type)
627
+ ]);
628
  $this->assertEquals(2, $collection->maximumCount());
629
  }
630
 
631
+ public function test_multipleValueNode_type_allowedValues()
632
  {
633
  $this->setExpectedException('InvalidArgumentException', 'Invalid argument(s) for type: noSuchType');
634
+ $collection = Braintree\Transaction::search([
635
+ Braintree\TransactionSearch::type()->is('noSuchType')
636
+ ]);
637
  }
638
 
639
+ public function test_multipleValueNode_type_withRefund()
640
  {
641
+ $customer = Braintree\Customer::createNoValidate();
642
+ $creditCard = Braintree\CreditCard::create([
643
  'customerId' => $customer->id,
644
  'cardholderName' => 'Joe Everyman' . rand(),
645
  'number' => '5105105105105100',
646
  'expirationDate' => '05/12'
647
+ ])->creditCard;
648
 
649
+ $sale = Braintree\Transaction::saleNoValidate([
650
+ 'amount' => Braintree\Test\TransactionAmounts::$authorize,
651
  'paymentMethodToken' => $creditCard->token,
652
+ 'options' => ['submitForSettlement' => true]
653
+ ]);
654
+ $http = new Braintree\Http(Braintree\Configuration::$global);
655
+ $path = Braintree\Configuration::$global->merchantPath() . '/transactions/' . $sale->id . '/settle';
656
  $http->put($path);
657
+ $refund = Braintree\Transaction::refund($sale->id)->transaction;
658
 
659
+ $credit = Braintree\Transaction::creditNoValidate([
660
  'amount' => '100.00',
661
  'paymentMethodToken' => $creditCard->token
662
+ ]);
663
 
664
+ $collection = Braintree\Transaction::search([
665
+ Braintree\TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
666
+ Braintree\TransactionSearch::type()->is($credit->type),
667
+ Braintree\TransactionSearch::refund()->is(True)
668
+ ]);
669
  $this->assertEquals(1, $collection->maximumCount());
670
  $this->assertEquals($refund->id, $collection->firstItem()->id);
671
 
672
+ $collection = Braintree\Transaction::search([
673
+ Braintree\TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
674
+ Braintree\TransactionSearch::type()->is($credit->type),
675
+ Braintree\TransactionSearch::refund()->is(False)
676
+ ]);
677
  $this->assertEquals(1, $collection->maximumCount());
678
  $this->assertEquals($credit->id, $collection->firstItem()->id);
679
  }
680
 
681
+ public function test_rangeNode_amount()
682
  {
683
+ $customer = Braintree\Customer::createNoValidate();
684
+ $creditCard = Braintree\CreditCard::create([
685
  'customerId' => $customer->id,
686
  'cardholderName' => 'Jane Everywoman' . rand(),
687
  'number' => '5105105105105100',
688
  'expirationDate' => '05/12'
689
+ ])->creditCard;
690
 
691
+ $t_1000 = Braintree\Transaction::saleNoValidate([
692
  'amount' => '1000.00',
693
  'paymentMethodToken' => $creditCard->token
694
+ ]);
695
 
696
+ $t_1500 = Braintree\Transaction::saleNoValidate([
697
  'amount' => '1500.00',
698
  'paymentMethodToken' => $creditCard->token
699
+ ]);
700
 
701
+ $t_1800 = Braintree\Transaction::saleNoValidate([
702
  'amount' => '1800.00',
703
  'paymentMethodToken' => $creditCard->token
704
+ ]);
705
 
706
+ $collection = Braintree\Transaction::search([
707
+ Braintree\TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
708
+ Braintree\TransactionSearch::amount()->greaterThanOrEqualTo('1700')
709
+ ]);
710
 
711
  $this->assertEquals(1, $collection->maximumCount());
712
  $this->assertEquals($t_1800->id, $collection->firstItem()->id);
713
 
714
+ $collection = Braintree\Transaction::search([
715
+ Braintree\TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
716
+ Braintree\TransactionSearch::amount()->lessThanOrEqualTo('1250')
717
+ ]);
718
 
719
  $this->assertEquals(1, $collection->maximumCount());
720
  $this->assertEquals($t_1000->id, $collection->firstItem()->id);
721
 
722
+ $collection = Braintree\Transaction::search([
723
+ Braintree\TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName),
724
+ Braintree\TransactionSearch::amount()->between('1100', '1600')
725
+ ]);
726
 
727
  $this->assertEquals(1, $collection->maximumCount());
728
  $this->assertEquals($t_1500->id, $collection->firstItem()->id);
737
  $future = clone $now;
738
  $future->modify("+1 hour");
739
 
740
+ $collections = [
741
+ 'future' => Braintree\Transaction::search([
742
+ Braintree\TransactionSearch::id()->is($knownDepositId),
743
  $comparison($future)
744
+ ]),
745
+ 'now' => Braintree\Transaction::search([
746
+ Braintree\TransactionSearch::id()->is($knownDepositId),
747
  $comparison($now)
748
+ ]),
749
+ 'past' => Braintree\Transaction::search([
750
+ Braintree\TransactionSearch::id()->is($knownDepositId),
751
  $comparison($past)
752
+ ])
753
+ ];
754
  return $collections;
755
  }
756
 
757
+ public function test_rangeNode_disbursementDate_lessThanOrEqualTo()
758
  {
759
  $compareLessThan = function($time) {
760
+ return Braintree\TransactionSearch::disbursementDate()->lessThanOrEqualTo($time);
761
  };
762
  $collection = $this->runDisbursementDateSearchTests("2013-04-10", $compareLessThan);
763
 
766
  $this->assertEquals(1, $collection['future']->maximumCount());
767
  }
768
 
769
+ public function test_rangeNode_disbursementDate_GreaterThanOrEqualTo()
770
  {
771
  $comparison = function($time) {
772
+ return Braintree\TransactionSearch::disbursementDate()->GreaterThanOrEqualTo($time);
773
  };
774
  $collection = $this->runDisbursementDateSearchTests("2013-04-11", $comparison);
775
 
778
  $this->assertEquals(0, $collection['future']->maximumCount());
779
  }
780
 
781
+ public function test_rangeNode_disbursementDate_between()
782
  {
783
  $knownId = "deposittransaction";
784
 
790
  $future2 = clone $now;
791
  $future2->modify("+2 days");
792
 
793
+ $collection = Braintree\Transaction::search([
794
+ Braintree\TransactionSearch::id()->is($knownId),
795
+ Braintree\TransactionSearch::disbursementDate()->between($past, $future)
796
+ ]);
797
  $this->assertEquals(1, $collection->maximumCount());
798
  $this->assertEquals($knownId, $collection->firstItem()->id);
799
 
800
+ $collection = Braintree\Transaction::search([
801
+ Braintree\TransactionSearch::id()->is($knownId),
802
+ Braintree\TransactionSearch::disbursementDate()->between($now, $future)
803
+ ]);
804
  $this->assertEquals(1, $collection->maximumCount());
805
  $this->assertEquals($knownId, $collection->firstItem()->id);
806
 
807
+ $collection = Braintree\Transaction::search([
808
+ Braintree\TransactionSearch::id()->is($knownId),
809
+ Braintree\TransactionSearch::disbursementDate()->between($past, $now)
810
+ ]);
811
  $this->assertEquals(1, $collection->maximumCount());
812
  $this->assertEquals($knownId, $collection->firstItem()->id);
813
 
814
+ $collection = Braintree\Transaction::search([
815
+ Braintree\TransactionSearch::id()->is($knownId),
816
+ Braintree\TransactionSearch::disbursementDate()->between($future, $future2)
817
+ ]);
818
  $this->assertEquals(0, $collection->maximumCount());
819
  }
820
 
821
+ public function test_rangeNode_disbursementDate_is()
822
  {
823
  $knownId = "deposittransaction";
824