Paid Memberships Pro - Version 1.9.1

Version Description

  • BUG FIX: Fixed the code checking if the Stripe library is already loaded to compatability issues with other plugins bundling the Stripe API library.
  • BUG FIX: Cancel code now properly uses preg_replace when sanitizing the list of level ids to cancel.
  • FIX/ENHANCEMENT: Removed test/doc code from Stripe and Braintree libraries.
  • ENHANCEMENT: Now pausing the license nag for the first week of use and removed the "invalid" error if no key is being used.
Download this release

Release Info

Developer strangerstudios
Plugin Icon 128x128 Paid Memberships Pro
Version 1.9.1
Comparing to
See all releases

Code changes from version 1.9 to 1.9.1

Files changed (196) hide show
  1. classes/gateways/class.pmprogateway_paypalstandard.php +13 -13
  2. classes/gateways/class.pmprogateway_stripe.php +1 -1
  3. includes/functions.php +2 -0
  4. includes/lib/Braintree/Rakefile +0 -81
  5. includes/lib/Braintree/ci.sh +0 -11
  6. includes/lib/Braintree/phpunit.xml.dist +0 -24
  7. includes/lib/Braintree/tests/Braintree/CreditCardDefaults.php +0 -8
  8. includes/lib/Braintree/tests/Braintree/CreditCardNumbers/CardTypeIndicators.php +0 -15
  9. includes/lib/Braintree/tests/Braintree/OAuthTestHelper.php +0 -35
  10. includes/lib/Braintree/tests/Helper.php +0 -202
  11. includes/lib/Braintree/tests/SanityTest.php +0 -20
  12. includes/lib/Braintree/tests/Setup.php +0 -32
  13. includes/lib/Braintree/tests/integration/AddOnsTest.php +0 -88
  14. includes/lib/Braintree/tests/integration/AddressTest.php +0 -311
  15. includes/lib/Braintree/tests/integration/ClientTokenTest.php +0 -188
  16. includes/lib/Braintree/tests/integration/CreditCardTest.php +0 -1323
  17. includes/lib/Braintree/tests/integration/CreditCardVerificationAdvancedSearchTest.php +0 -259
  18. includes/lib/Braintree/tests/integration/CreditCardVerificationTest.php +0 -56
  19. includes/lib/Braintree/tests/integration/CustomerAdvancedSearchTest.php +0 -199
  20. includes/lib/Braintree/tests/integration/CustomerTest.php +0 -1476
  21. includes/lib/Braintree/tests/integration/DisbursementTest.php +0 -39
  22. includes/lib/Braintree/tests/integration/DiscountTest.php +0 -88
  23. includes/lib/Braintree/tests/integration/Error/ErrorCollectionTest.php +0 -96
  24. includes/lib/Braintree/tests/integration/Error/ValidationErrorCollectionTest.php +0 -75
  25. includes/lib/Braintree/tests/integration/EuropeBankAccountTest.php +0 -54
  26. includes/lib/Braintree/tests/integration/HttpClientApi.php +0 -116
  27. includes/lib/Braintree/tests/integration/HttpTest.php +0 -100
  28. includes/lib/Braintree/tests/integration/MerchantAccountTest.php +0 -631
  29. includes/lib/Braintree/tests/integration/MerchantTest.php +0 -257
  30. includes/lib/Braintree/tests/integration/MultipleValueNodeTest.php +0 -94
  31. includes/lib/Braintree/tests/integration/OAuthTest.php +0 -324
  32. includes/lib/Braintree/tests/integration/PayPalAccountTest.php +0 -309
  33. includes/lib/Braintree/tests/integration/PaymentMethodNonceTest.php +0 -79
  34. includes/lib/Braintree/tests/integration/PaymentMethodTest.php +0 -1585
  35. includes/lib/Braintree/tests/integration/PlanTest.php +0 -132
  36. includes/lib/Braintree/tests/integration/Result/ErrorTest.php +0 -33
  37. includes/lib/Braintree/tests/integration/SettlementBatchSummaryTest.php +0 -95
  38. includes/lib/Braintree/tests/integration/SubscriptionHelper.php +0 -86
  39. includes/lib/Braintree/tests/integration/SubscriptionSearchTest.php +0 -479
  40. includes/lib/Braintree/tests/integration/SubscriptionTest.php +0 -1204
  41. includes/lib/Braintree/tests/integration/TestTransactionTest.php +0 -101
  42. includes/lib/Braintree/tests/integration/TextNodeTest.php +0 -147
  43. includes/lib/Braintree/tests/integration/TransactionAdvancedSearchTest.php +0 -1574
  44. includes/lib/Braintree/tests/integration/TransactionTest.php +0 -4223
  45. includes/lib/Braintree/tests/integration/TransparentRedirectTest.php +0 -354
  46. includes/lib/Braintree/tests/integration/UsBankAccountTest.php +0 -95
  47. includes/lib/Braintree/tests/unit/AddOnTest.php +0 -34
  48. includes/lib/Braintree/tests/unit/AddressTest.php +0 -79
  49. includes/lib/Braintree/tests/unit/BraintreeTest.php +0 -25
  50. includes/lib/Braintree/tests/unit/ClientApi/ClientTokenTest.php +0 -22
  51. includes/lib/Braintree/tests/unit/ConfigurationTest.php +0 -513
  52. includes/lib/Braintree/tests/unit/CreditCardTest.php +0 -150
  53. includes/lib/Braintree/tests/unit/CreditCardVerificationTest.php +0 -22
  54. includes/lib/Braintree/tests/unit/CustomerTest.php +0 -60
  55. includes/lib/Braintree/tests/unit/DigestTest.php +0 -97
  56. includes/lib/Braintree/tests/unit/DisbursementDetailsTest.php +0 -29
  57. includes/lib/Braintree/tests/unit/DisbursementTest.php +0 -35
  58. includes/lib/Braintree/tests/unit/DiscountTest.php +0 -34
  59. includes/lib/Braintree/tests/unit/GatewayTest.php +0 -51
  60. includes/lib/Braintree/tests/unit/InstanceTest.php +0 -37
  61. includes/lib/Braintree/tests/unit/MerchantAccountTest.php +0 -68
  62. includes/lib/Braintree/tests/unit/MultipleValueNodeTest.php +0 -24
  63. includes/lib/Braintree/tests/unit/MultipleValueOrTextNodeTest.php +0 -52
  64. includes/lib/Braintree/tests/unit/OAuthTest.php +0 -71
  65. includes/lib/Braintree/tests/unit/PayPalAccountTest.php +0 -44
  66. includes/lib/Braintree/tests/unit/PaymentMethodTest.php +0 -100
  67. includes/lib/Braintree/tests/unit/RangeNodeTest.php +0 -38
  68. includes/lib/Braintree/tests/unit/ResourceCollectionTest.php +0 -132
  69. includes/lib/Braintree/tests/unit/Result/ErrorTest.php +0 -16
  70. includes/lib/Braintree/tests/unit/Result/SuccessfulTest.php +0 -21
  71. includes/lib/Braintree/tests/unit/SanityTest.php +0 -19
  72. includes/lib/Braintree/tests/unit/SubscriptionSearchTest.php +0 -70
  73. includes/lib/Braintree/tests/unit/SubscriptionTest.php +0 -22
  74. includes/lib/Braintree/tests/unit/TextNodeTest.php +0 -45
  75. includes/lib/Braintree/tests/unit/TransactionTest.php +0 -120
  76. includes/lib/Braintree/tests/unit/TransparentRedirectTest.php +0 -31
  77. includes/lib/Braintree/tests/unit/UnknownPaymentMethodTest.php +0 -25
  78. includes/lib/Braintree/tests/unit/UsBankAccount.php +0 -21
  79. includes/lib/Braintree/tests/unit/UtilTest.php +0 -269
  80. includes/lib/Braintree/tests/unit/WebhookNotificationTest.php +0 -522
  81. includes/lib/Braintree/tests/unit/Xml_GeneratorTest.php +0 -134
  82. includes/lib/Braintree/tests/unit/Xml_ParserTest.php +0 -542
  83. includes/lib/Stripe/.coveralls.yml +0 -4
  84. includes/lib/Stripe/.github/ISSUE_TEMPLATE.md +0 -5
  85. includes/lib/Stripe/.travis.yml +0 -17
  86. includes/lib/Stripe/phpunit.no_autoload.xml +0 -15
  87. includes/lib/Stripe/phpunit.xml +0 -15
  88. includes/lib/Stripe/tests/AccountTest.php +0 -300
  89. includes/lib/Stripe/tests/ApiRequestorTest.php +0 -68
  90. includes/lib/Stripe/tests/ApplePayDomainTest.php +0 -72
  91. includes/lib/Stripe/tests/ApplicationFeeRefundTest.php +0 -18
  92. includes/lib/Stripe/tests/ApplicationFeeTest.php +0 -22
  93. includes/lib/Stripe/tests/AuthenticationErrorTest.php +0 -16
  94. includes/lib/Stripe/tests/BalanceTest.php +0 -15
  95. includes/lib/Stripe/tests/BalanceTransactionTest.php +0 -13
  96. includes/lib/Stripe/tests/BankAccountTest.php +0 -32
  97. includes/lib/Stripe/tests/BitcoinReceiverTest.php +0 -120
  98. includes/lib/Stripe/tests/CardErrorTest.php +0 -41
  99. includes/lib/Stripe/tests/ChargeTest.php +0 -204
  100. includes/lib/Stripe/tests/CollectionTest.php +0 -105
  101. includes/lib/Stripe/tests/CountrySpecTest.php +0 -31
  102. includes/lib/Stripe/tests/CouponTest.php +0 -29
  103. includes/lib/Stripe/tests/CurlClientTest.php +0 -100
  104. includes/lib/Stripe/tests/CustomerTest.php +0 -278
  105. includes/lib/Stripe/tests/DiscountTest.php +0 -31
  106. includes/lib/Stripe/tests/DisputeTest.php +0 -91
  107. includes/lib/Stripe/tests/ErrorTest.php +0 -61
  108. includes/lib/Stripe/tests/ExternalAccountTest.php +0 -30
  109. includes/lib/Stripe/tests/FileUploadTest.php +0 -44
  110. includes/lib/Stripe/tests/InvalidRequestErrorTest.php +0 -26
  111. includes/lib/Stripe/tests/InvoiceTest.php +0 -56
  112. includes/lib/Stripe/tests/PermissionsErrorTest.php +0 -22
  113. includes/lib/Stripe/tests/PlanTest.php +0 -51
  114. includes/lib/Stripe/tests/ProductTest.php +0 -158
  115. includes/lib/Stripe/tests/RateLimitErrorTest.php +0 -22
  116. includes/lib/Stripe/tests/RecipientTest.php +0 -112
  117. includes/lib/Stripe/tests/RefundTest.php +0 -131
  118. includes/lib/Stripe/tests/RequestOptionsTest.php +0 -69
  119. includes/lib/Stripe/tests/SourceTest.php +0 -108
  120. includes/lib/Stripe/tests/StripeObjectTest.php +0 -108
  121. includes/lib/Stripe/tests/SubscriptionItemTest.php +0 -38
  122. includes/lib/Stripe/tests/SubscriptionTest.php +0 -132
  123. includes/lib/Stripe/tests/TestCase.php +0 -224
  124. includes/lib/Stripe/tests/ThreeDSecureTest.php +0 -46
  125. includes/lib/Stripe/tests/TokenTest.php +0 -13
  126. includes/lib/Stripe/tests/TransferReversalTest.php +0 -15
  127. includes/lib/Stripe/tests/TransferTest.php +0 -110
  128. includes/lib/Stripe/tests/UtilTest.php +0 -45
  129. includes/lib/Stripe/tests/bootstrap.no_autoload.php +0 -4
  130. includes/lib/Stripe/tests/bootstrap.php +0 -3
  131. includes/license.php +13 -3
  132. includes/localization.php +7 -3
  133. includes/updates/upgrade_1.php +4 -0
  134. languages/gettext.sh +5 -5
  135. languages/{pmpro-ca.mo → paid-memberships-pro-ca.mo} +0 -0
  136. languages/{pmpro-ca.po → paid-memberships-pro-ca.po} +0 -0
  137. languages/{pmpro-ca_AD.mo → paid-memberships-pro-ca_AD.mo} +0 -0
  138. languages/{pmpro-ca_AD.po → paid-memberships-pro-ca_AD.po} +0 -0
  139. languages/{pmpro-ca_ES.mo → paid-memberships-pro-ca_ES.mo} +0 -0
  140. languages/{pmpro-ca_ES.po → paid-memberships-pro-ca_ES.po} +0 -0
  141. languages/{pmpro-cs_CZ.mo → paid-memberships-pro-cs_CZ.mo} +0 -0
  142. languages/{pmpro-cs_CZ.po → paid-memberships-pro-cs_CZ.po} +0 -0
  143. languages/{pmpro-da_DK.mo → paid-memberships-pro-da_DK.mo} +0 -0
  144. languages/{pmpro-da_DK.po → paid-memberships-pro-da_DK.po} +0 -0
  145. languages/{pmpro-de_DE.mo → paid-memberships-pro-de_DE.mo} +0 -0
  146. languages/{pmpro-de_DE.po → paid-memberships-pro-de_DE.po} +0 -0
  147. languages/{pmpro-el_GR.mo → paid-memberships-pro-el_GR.mo} +0 -0
  148. languages/{pmpro-el_GR.po → paid-memberships-pro-el_GR.po} +0 -0
  149. languages/{pmpro-en_GB.mo → paid-memberships-pro-en_GB.mo} +0 -0
  150. languages/{pmpro-en_GB.po → paid-memberships-pro-en_GB.po} +0 -0
  151. languages/{pmpro-es_CL.mo → paid-memberships-pro-es_CL.mo} +0 -0
  152. languages/{pmpro-es_CL.po → paid-memberships-pro-es_CL.po} +0 -0
  153. languages/{pmpro-es_CL.pot → paid-memberships-pro-es_CL.pot} +0 -0
  154. languages/{pmpro-es_ES.mo → paid-memberships-pro-es_ES.mo} +0 -0
  155. languages/{pmpro-es_ES.po → paid-memberships-pro-es_ES.po} +0 -0
  156. languages/{pmpro-es_ES.pot → paid-memberships-pro-es_ES.pot} +0 -0
  157. languages/{pmpro-es_PE.mo → paid-memberships-pro-es_PE.mo} +0 -0
  158. languages/{pmpro-es_PE.po → paid-memberships-pro-es_PE.po} +0 -0
  159. languages/{pmpro-es_PE.pot → paid-memberships-pro-es_PE.pot} +0 -0
  160. languages/{pmpro-et_EE.mo → paid-memberships-pro-et_EE.mo} +0 -0
  161. languages/{pmpro-et_EE.po → paid-memberships-pro-et_EE.po} +0 -0
  162. languages/{pmpro-fa_IR.mo → paid-memberships-pro-fa_IR.mo} +0 -0
  163. languages/{pmpro-fa_IR.po → paid-memberships-pro-fa_IR.po} +0 -0
  164. languages/{pmpro-fi.mo → paid-memberships-pro-fi.mo} +0 -0
  165. languages/{pmpro-fi.po → paid-memberships-pro-fi.po} +0 -0
  166. languages/{pmpro-fr_FR.mo → paid-memberships-pro-fr_FR.mo} +0 -0
  167. languages/{pmpro-fr_FR.po → paid-memberships-pro-fr_FR.po} +0 -0
  168. languages/{pmpro-he_IL.mo → paid-memberships-pro-he_IL.mo} +0 -0
  169. languages/{pmpro-he_IL.po → paid-memberships-pro-he_IL.po} +0 -0
  170. languages/{pmpro-it_IT.mo → paid-memberships-pro-it_IT.mo} +0 -0
  171. languages/{pmpro-it_IT.po → paid-memberships-pro-it_IT.po} +0 -0
  172. languages/{pmpro-nb_NO.mo → paid-memberships-pro-nb_NO.mo} +0 -0
  173. languages/{pmpro-nb_NO.po → paid-memberships-pro-nb_NO.po} +0 -0
  174. languages/{pmpro-nl_NL.mo → paid-memberships-pro-nl_NL.mo} +0 -0
  175. languages/{pmpro-nl_NL.po → paid-memberships-pro-nl_NL.po} +0 -0
  176. languages/{pmpro-pt_BR.mo → paid-memberships-pro-pt_BR.mo} +0 -0
  177. languages/{pmpro-pt_BR.po → paid-memberships-pro-pt_BR.po} +0 -0
  178. languages/{pmpro-sk_SK.mo → paid-memberships-pro-sk_SK.mo} +0 -0
  179. languages/{pmpro-sk_SK.po → paid-memberships-pro-sk_SK.po} +0 -0
  180. languages/{pmpro-sr_RS.mo → paid-memberships-pro-sr_RS.mo} +0 -0
  181. languages/{pmpro-sr_RS.po → paid-memberships-pro-sr_RS.po} +0 -0
  182. languages/{pmpro-sv_SE.mo → paid-memberships-pro-sv_SE.mo} +0 -0
  183. languages/{pmpro-sv_SE.po → paid-memberships-pro-sv_SE.po} +0 -0
  184. languages/{pmpro-tr_TR.mo → paid-memberships-pro-tr_TR.mo} +0 -0
  185. languages/{pmpro-tr_TR.po → paid-memberships-pro-tr_TR.po} +0 -0
  186. languages/{pmpro-vi_VN.mo → paid-memberships-pro-vi_VN.mo} +0 -0
  187. languages/{pmpro-vi_VN.po → paid-memberships-pro-vi_VN.po} +0 -0
  188. languages/{pmpro-zh_HK.mo → paid-memberships-pro-zh_HK.mo} +0 -0
  189. languages/{pmpro-zh_HK.po → paid-memberships-pro-zh_HK.po} +0 -0
  190. languages/paid-memberships-pro.mo +0 -0
  191. languages/{pmpro.pot → paid-memberships-pro.po} +550 -344
  192. languages/{pmpro.po → paid-memberships-pro.pot} +550 -344
  193. languages/pmpro.mo +0 -0
  194. paid-memberships-pro.php +2 -2
  195. preheaders/cancel.php +2 -1
  196. readme.txt +7 -1
classes/gateways/class.pmprogateway_paypalstandard.php CHANGED
@@ -314,8 +314,8 @@
314
'item_number' => $order->code,
315
'charset' => get_bloginfo( 'charset' ),
316
'rm' => '2',
317
- 'return' => pmpro_url("confirmation", "?level=" . $order->membership_level->id),
318
- 'notify_url' => admin_url("admin-ajax.php") . "?action=ipnhandler",
319
'src' => '1',
320
'sra' => '1',
321
'bn' => PAYPAL_BN_CODE
@@ -409,26 +409,26 @@
409
'item_number' => $order->code,
410
'charset' => get_bloginfo( 'charset' ),
411
'rm' => '2',
412
- 'return' => pmpro_url("confirmation", "?level=" . $order->membership_level->id),
413
- 'notify_url' => admin_url("admin-ajax.php") . "?action=ipnhandler",
414
- 'bn' => PAYPAL_BN_CODE
415
);
416
}
417
418
$nvpStr = "";
419
foreach($paypal_args as $key => $value)
420
{
421
$nvpStr .= "&" . $key . "=" . urlencode($value);
422
}
423
424
- //anything modders might add
425
- $additional_parameters = apply_filters("pmpro_paypal_express_return_url_parameters", array());
426
- if(!empty($additional_parameters))
427
- {
428
- foreach($additional_parameters as $key => $value)
429
- $nvpStr .= urlencode("&" . $key . "=" . $value);
430
- }
431
-
432
$account_optional = apply_filters('pmpro_paypal_account_optional', true);
433
if ($account_optional)
434
$nvpStr .= '&SOLUTIONTYPE=Sole&LANDINGPAGE=Billing';
314
'item_number' => $order->code,
315
'charset' => get_bloginfo( 'charset' ),
316
'rm' => '2',
317
+ 'return' => add_query_arg( 'level', $order->membership_level->id, pmpro_url("confirmation" ) ),
318
+ 'notify_url' => add_query_arg( 'action', 'ipnhandler', admin_url("admin-ajax.php") ),
319
'src' => '1',
320
'sra' => '1',
321
'bn' => PAYPAL_BN_CODE
409
'item_number' => $order->code,
410
'charset' => get_bloginfo( 'charset' ),
411
'rm' => '2',
412
+ 'return' => add_query_arg( 'level', $order->membership_level->id, pmpro_url("confirmation" ) ),
413
+ 'notify_url' => add_query_arg( 'action', 'ipnhandler', admin_url("admin-ajax.php") ),
414
+ 'bn' => PAYPAL_BN_CODE
415
);
416
}
417
418
+ //anything modders might add
419
+ $additional_parameters = apply_filters("pmpro_paypal_express_return_url_parameters", array());
420
+
421
+ foreach( $additional_parameters as $key => $value ) {
422
+
423
+ $paypal_args[$key] = $value;
424
+ }
425
+
426
$nvpStr = "";
427
foreach($paypal_args as $key => $value)
428
{
429
$nvpStr .= "&" . $key . "=" . urlencode($value);
430
}
431
432
$account_optional = apply_filters('pmpro_paypal_account_optional', true);
433
if ($account_optional)
434
$nvpStr .= '&SOLUTIONTYPE=Sole&LANDINGPAGE=Billing';
classes/gateways/class.pmprogateway_stripe.php CHANGED
@@ -101,7 +101,7 @@
101
function loadStripeLibrary()
102
{
103
//load Stripe library if it hasn't been loaded already (usually by another plugin using Stripe)
104
- if(!class_exists("\\Stripe")) {
105
require_once( PMPRO_DIR . "/includes/lib/Stripe/init.php" );
106
}
107
}
101
function loadStripeLibrary()
102
{
103
//load Stripe library if it hasn't been loaded already (usually by another plugin using Stripe)
104
+ if(!class_exists("Stripe\Stripe")) {
105
require_once( PMPRO_DIR . "/includes/lib/Stripe/init.php" );
106
}
107
}
includes/functions.php CHANGED
@@ -1055,6 +1055,8 @@ function pmpro_changeMembershipLevel($level, $user_id = NULL, $old_level_status
1055
$other_order_ids = $wpdb->get_col("SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = '" . $user_id . "' AND status = 'success' ORDER BY id DESC");
1056
}
1057
1058
//cancel any other subscriptions they have (updates pmpro_membership_orders table)
1059
if($pmpro_cancel_previous_subscriptions && !empty($other_order_ids))
1060
{
1055
$other_order_ids = $wpdb->get_col("SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = '" . $user_id . "' AND status = 'success' ORDER BY id DESC");
1056
}
1057
1058
+ $other_order_ids = apply_filters("pmpro_other_order_ids_to_cancel", $other_order_ids);
1059
+
1060
//cancel any other subscriptions they have (updates pmpro_membership_orders table)
1061
if($pmpro_cancel_previous_subscriptions && !empty($other_order_ids))
1062
{
includes/lib/Braintree/Rakefile DELETED
@@ -1,81 +0,0 @@
1
- task :default => :test
2
- task :test => %w[test:unit test:integration]
3
-
4
- namespace :test do
5
- task :unit => %w[test:php:unit test:hhvm:unit]
6
- task :integration => %w[test:php:integration test:hhvm:integration]
7
-
8
- namespace :php do
9
- desc "print PHP version"
10
- task :version do
11
- print_php_version("php")
12
- end
13
-
14
- desc "run unit tests under PHP"
15
- task :unit => :version do
16
- run_php_test_suite("php", "unit")
17
- end
18
-
19
- desc "run integration tests under PHP"
20
- task :integration do
21
- run_php_test_suite("php", "integration")
22
- end
23
- end
24
-
25
- namespace :hhvm do
26
- desc "print HHVM version"
27
- task :version do
28
- print_php_version("hhvm")
29
- end
30
-
31
- desc "run tests under HHVM"
32
- task :test => [:unit, :integration]
33
-
34
- desc "run unit tests under HHVM"
35
- task :unit => :version do
36
- run_php_test_suite("hhvm", "unit")
37
- end
38
-
39
- desc "run integration tests under HHVM"
40
- task :integration do
41
- run_php_test_suite("hhvm", "integration")
42
- end
43
- end
44
-
45
- desc "run tests under PHP"
46
- task :php => %w[php:unit php:integration]
47
-
48
- desc "run tests under HHVM"
49
- task :hhvm => %w[hhvm:unit hhvm:integration]
50
-
51
- desc "run a single test file"
52
- task :file, :file_path do |t, args|
53
- run_php_test_file(args[:file_path])
54
- end
55
-
56
- desc "run 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)
68
- sh "#{interpreter} --version"
69
- end
70
-
71
- def run_php_test_suite(interpreter, test_suite)
72
- sh "#{interpreter} ./vendor/bin/phpunit --testsuite #{test_suite}"
73
- end
74
-
75
- def run_php_test_file(test_file)
76
- sh "./vendor/bin/phpunit #{test_file}"
77
- end
78
-
79
- def run_php_test(test_name)
80
- sh "./vendor/bin/phpunit --filter #{test_name}"
81
- end
includes/lib/Braintree/ci.sh DELETED
@@ -1,11 +0,0 @@
1
- #!/bin/bash
2
-
3
- curl -sS https://getcomposer.org/installer | php -d suhosin.executor.include.whitelist=phar
4
-
5
- php -d suhosin.executor.include.whitelist=phar ./composer.phar install
6
-
7
- if [ "$1" == "hhvm" ]; then
8
- rake test:hhvm --trace
9
- else
10
- rake test:php --trace
11
- fi
includes/lib/Braintree/phpunit.xml.dist DELETED
@@ -1,24 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <phpunit backupGlobals="false"
3
- backupStaticAttributes="false"
4
- bootstrap="./vendor/autoload.php"
5
- convertErrorsToExceptions="true"
6
- convertNoticesToExceptions="true"
7
- convertWarningsToExceptions="true"
8
- processIsolation="false"
9
- stopOnFailure="false"
10
- syntaxCheck="false">
11
-
12
- <php>
13
- <ini name="error_reporting" value="32767"/>
14
- </php>
15
-
16
- <testsuites>
17
- <testsuite name="unit">
18
- <directory>./tests/unit</directory>
19
- </testsuite>
20
- <testsuite name="integration">
21
- <directory>./tests/integration</directory>
22
- </testsuite>
23
- </testsuites>
24
- </phpunit>
includes/lib/Braintree/tests/Braintree/CreditCardDefaults.php DELETED
@@ -1,8 +0,0 @@
1
- <?php
2
- namespace Test\Braintree;
3
-
4
- class CreditCardDefaults
5
- {
6
- const ISSUING_BANK = "NETWORK ONLY";
7
- const COUNTRY_OF_ISSUANCE = "USA";
8
- }
includes/lib/Braintree/tests/Braintree/CreditCardNumbers/CardTypeIndicators.php DELETED
@@ -1,15 +0,0 @@
1
- <?php
2
- namespace Test\Braintree\CreditCardNumbers;
3
-
4
- class CardTypeIndicators {
5
- const PREPAID = "4111111111111210";
6
- const COMMERCIAL = "4111111111131010";
7
- const PAYROLL = "4111111114101010";
8
- const HEALTHCARE = "4111111510101010";
9
- const DURBIN_REGULATED = "4111161010101010";
10
- const DEBIT = "4117101010101010";
11
- const UNKNOWN = "4111111111112101";
12
- const NO = "4111111111310101";
13
- const ISSUING_BANK = "4111111141010101";
14
- const COUNTRY_OF_ISSUANCE = "4111111111121102";
15
- }
includes/lib/Braintree/tests/Braintree/OAuthTestHelper.php DELETED
@@ -1,35 +0,0 @@
1
- <?php
2
- namespace Test\Braintree;
3
-
4
- use Braintree;
5
-
6
- class OAuthTestHelper
7
- {
8
- public static function createGrant($gateway, $params)
9
- {
10
- $http = new Braintree\Http($gateway->config);
11
- $http->useClientCredentials();
12
- $response = $http->post('/oauth_testing/grants', ['grant' => $params]);
13
- return $response['grant']['code'];
14
- }
15
-
16
- public static function createCredentials($params)
17
- {
18
- $gateway = new Braintree\Gateway([
19
- 'clientId' => $params['clientId'],
20
- 'clientSecret' => $params['clientSecret']
21
- ]);
22
-
23
- $code = OAuthTestHelper::createGrant($gateway, [
24
- 'merchant_public_id' => $params['merchantId'],
25
- 'scope' => 'read_write'
26
- ]);
27
-
28
- $credentials = $gateway->oauth()->createTokenFromCode([
29
- 'code' => $code,
30
- 'scope' => 'read_write',
31
- ]);
32
-
33
- return $credentials;
34
- }
35
- }
includes/lib/Braintree/tests/Helper.php DELETED
@@ -1,202 +0,0 @@
1
- <?php
2
- namespace Test;
3
-
4
- require_once __DIR__ . '/Setup.php';
5
-
6
- use DateTime;
7
- use DateTimeZone;
8
- use Braintree;
9
-
10
- class Helper
11
- {
12
- public static $valid_nonce_characters = 'bcdfghjkmnpqrstvwxyz23456789';
13
-
14
- public static function testMerchantConfig()
15
- {
16
- Braintree\Configuration::reset();
17
-
18
- Braintree\Configuration::environment('development');
19
- Braintree\Configuration::merchantId('test_merchant_id');
20
- Braintree\Configuration::publicKey('test_public_key');
21
- Braintree\Configuration::privateKey('test_private_key');
22
- }
23
-
24
- public static function defaultMerchantAccountId()
25
- {
26
- return 'sandbox_credit_card';
27
- }
28
-
29
- public static function nonDefaultMerchantAccountId()
30
- {
31
- return 'sandbox_credit_card_non_default';
32
- }
33
-
34
- public static function nonDefaultSubMerchantAccountId()
35
- {
36
- return 'sandbox_sub_merchant_account';
37
- }
38
-
39
- public static function threeDSecureMerchantAccountId()
40
- {
41
- return 'three_d_secure_merchant_account';
42
- }
43
-
44
- public static function fakeAmexDirectMerchantAccountId()
45
- {
46
- return 'fake_amex_direct_usd';
47
- }
48
-
49
- public static function fakeVenmoAccountMerchantAccountId()
50
- {
51
- return 'fake_first_data_venmo_account';
52
- }
53
-
54
- public static function createViaTr($regularParams, $trParams)
55
- {
56
- $trData = Braintree\TransparentRedirect::transactionData(
57
- array_merge($trParams, ["redirectUrl" => "http://www.example.com"])
58
- );
59
- return self::submitTrRequest(
60
- Braintree\TransparentRedirect::url(),
61
- $regularParams,
62
- $trData
63
- );
64
- }
65
-
66
- public static function submitTrRequest($url, $regularParams, $trData)
67
- {
68
- $curl = curl_init();
69
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
70
- curl_setopt($curl, CURLOPT_URL, $url);
71
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
72
- curl_setopt($curl, CURLOPT_HEADER, true);
73
- // curl_setopt($curl, CURLOPT_VERBOSE, true);
74
- curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array_merge($regularParams, ['tr_data' => $trData])));
75
- curl_setopt($curl, CURLOPT_HTTPHEADER, [
76
- 'Content-Type: application/x-www-form-urlencoded'
77
- ]);
78
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
79
- $response = curl_exec($curl);
80
- curl_close($curl);
81
- preg_match('/Location: .*\?(.*)/i', $response, $match);
82
- return trim($match[1]);
83
- }
84
-
85
- public static function suppressDeprecationWarnings()
86
- {
87
- set_error_handler("Test\Helper::_errorHandler", E_USER_NOTICE);
88
- }
89
-
90
- public static function _errorHandler($errno, $errstr, $errfile, $errline)
91
- {
92
- if (preg_match('/^DEPRECATED/', $errstr) == 0) {
93
- trigger_error('Unknown error received: ' . $errstr, E_USER_ERROR);
94
- }
95
- }
96
-
97
- public static function includes($collection, $targetItem)
98
- {
99
- foreach ($collection AS $item) {
100
- if ($item->id == $targetItem->id) {
101
- return true;
102
- }
103
- }
104
- return false;
105
- }
106
-
107
- public static function assertPrintable($object)
108
- {
109
- " " . $object;
110
- }
111
-
112
- public static function escrow($transactionId)
113
- {
114
- $http = new Braintree\Http(Braintree\Configuration::$global);
115
- $path = Braintree\Configuration::$global->merchantPath() . '/transactions/' . $transactionId . '/escrow';
116
- $http->put($path);
117
- }
118
-
119
- public static function create3DSVerification($merchantAccountId, $params)
120
- {
121
- $http = new Braintree\Http(Braintree\Configuration::$global);
122
- $path = Braintree\Configuration::$global->merchantPath() . '/three_d_secure/create_verification/' . $merchantAccountId;
123
- $response = $http->post($path, ['threeDSecureVerification' => $params]);
124
- return $response['threeDSecureVerification']['threeDSecureToken'];
125
- }
126
-
127
- public static function generate3DSNonce($params)
128
- {
129
- $http = new Braintree\Http(Braintree\Configuration::$global);
130
- $path = Braintree\Configuration::$global->merchantPath() . '/three_d_secure/create_nonce/' . self::threeDSecureMerchantAccountId();
131
- $response = $http->post($path, $params);
132
- return $response['paymentMethodNonce']['nonce'];
133
- }
134
-
135
- public static function nowInEastern()
136
- {
137
- $eastern = new DateTimeZone('America/New_York');
138
- $now = new DateTime('now', $eastern);
139
- return $now->format('Y-m-d');
140
- }
141
-
142
- public static function decodedClientToken($params=[]) {
143
- $encodedClientToken = Braintree\ClientToken::generate($params);
144
- return base64_decode($encodedClientToken);
145
- }
146
-
147
- public static function generateValidUsBankAccountNonce() {
148
- $client_token = json_decode(Helper::decodedClientToken(), true);
149
- $url = $client_token['braintree_api']['url'] . '/tokens';
150
- $token = $client_token['braintree_api']['access_token'];
151
-
152
- $curl = curl_init();
153
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
154
- curl_setopt($curl, CURLOPT_URL, $url);
155
-
156
- $headers[] = 'Content-Type: application/json';
157
- $headers[] = 'Braintree-Version: 2015-11-01';
158
- $headers[] = 'Authorization: Bearer ' . $token;
159
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
160
-
161
- $requestBody = [
162
- 'type' => 'us_bank_account',
163
- 'billing_address' => [
164
- 'street_address' => '123 Ave',
165
- 'region' => 'CA',
166
- 'locality' => 'San Francisco',
167
- 'postal_code' => '94112'
168
- ],
169
- 'account_type' => 'checking',
170
- 'routing_number' => '021000021',
171
- 'account_number' => '567891234',
172
- 'account_holder_name' => 'Dan Schulman',
173
- 'account_description' => 'PayPal Checking - 1234',
174
- 'ach_mandate' => [
175
- 'text' => 'cl mandate text'
176
- ]
177
- ];
178
-
179
- curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($requestBody));
180
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
181
-
182
- $response = curl_exec($curl);
183
- $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
184
- $error_code = curl_errno($curl);
185
- curl_close($curl);
186
- $jsonResponse = json_decode($response, true);
187
- return $jsonResponse['data']['id'];
188
- }
189
-
190
- public static function generateInvalidUsBankAccountNonce() {
191
- $valid_characters = str_split(self::$valid_nonce_characters);
192
- $nonce = 'tokenusbankacct';
193
- for($i=0; $i<4; $i++) {
194
- $nonce = $nonce . '_';
195
- for($j=0; $j<6; $j++) {
196
- $t = rand(0, sizeof($valid_characters)-1);
197
- $nonce = $nonce . $valid_characters[$t];
198
- }
199
- }
200
- return $nonce . "_xxx";
201
- }
202
- }
includes/lib/Braintree/tests/SanityTest.php DELETED
@@ -1,20 +0,0 @@
1
- <?php
2
-
3
- class SanityTest extends PHPUnit_Framework_TestCase
4
- {
5
- public function testLibraryWorksWithComposer()
6
- {
7
- if (version_compare(PHP_VERSION, "5.4.0", "<")) {
8
- $this->markTestSkipped("Requires PHP >=5.4");
9
- }
10
-
11
- $returnValue = null;
12
-
13
- $testFile = escapeshellarg(realpath(__DIR__ . '/Braintree/fixtures/composer_implementation.php'));
14
- $command = sprintf('%s %s', PHP_BINARY, $testFile);
15
-
16
- system($command, $returnValue);
17
-
18
- $this->assertEquals(0, $returnValue);
19
- }
20
- }
includes/lib/Braintree/tests/Setup.php DELETED
@@ -1,32 +0,0 @@
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
- }
includes/lib/Braintree/tests/integration/AddOnsTest.php DELETED
@@ -1,88 +0,0 @@
1
- <?php
2
- namespace Test\Integration;
3
-
4
- require_once dirname(__DIR__) . '/Setup.php';
5
-
6
- use Test\Setup;
7
- use Braintree;
8
-
9
- class AddOnsTest extends Setup
10
- {
11
- public function testAll_returnsAllAddOns()
12
- {
13
- $newId = strval(rand());
14
-
15
- $addOnParams = [
16
- "amount" => "100.00",
17
- "description" => "some description",
18
- "id" => $newId,
19
- "kind" => "add_on",
20
- "name" => "php_add_on",
21
- "neverExpires" => "false",
22
- "numberOfBillingCycles" => "1"
23
- ];
24
-
25
- $http = new Braintree\Http(Braintree\Configuration::$global);
26
- $path = Braintree\Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
27
- $http->post($path, ["modification" => $addOnParams]);
28
-
29
- $addOns = Braintree\AddOn::all();
30
-
31
- foreach ($addOns as $addOn)
32
- {
33
- if ($addOn->id == $newId)
34
- {
35
- $actualAddOn = $addOn;
36
- }
37
- }
38
-
39
- $this->assertNotNull($actualAddOn);
40
- $this->assertEquals($addOnParams["amount"], $actualAddOn->amount);
41
- $this->assertEquals($addOnParams["description"], $actualAddOn->description);
42
- $this->assertEquals($addOnParams["id"], $actualAddOn->id);
43
- $this->assertEquals($addOnParams["kind"], $actualAddOn->kind);
44
- $this->assertEquals($addOnParams["name"], $actualAddOn->name);
45
- $this->assertFalse($actualAddOn->neverExpires);
46
- $this->assertEquals($addOnParams["numberOfBillingCycles"], $actualAddOn->numberOfBillingCycles);
47
- }
48
-
49
- public function testGatewayAll_returnsAllAddOns()
50
- {
51
- $newId = strval(rand());
52
-
53
- $addOnParams = [
54
- "amount" => "100.00",
55
- "description" => "some description",
56
- "id" => $newId,
57
- "kind" => "add_on",
58
- "name" => "php_add_on",
59
- "neverExpires" => "false",
60
- "numberOfBillingCycles" => "1"
61
- ];
62
-
63
- $http = new Braintree\Http(Braintree\Configuration::$global);
64
- $path = Braintree\Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
65
- $http->post($path, ["modification" => $addOnParams]);
66
-
67
- $gateway = new Braintree\Gateway([
68
- 'environment' => 'development',
69
- 'merchantId' => 'integration_merchant_id',
70
- 'publicKey' => 'integration_public_key',
71
- 'privateKey' => 'integration_private_key'
72
- ]);
73
- $addOns = $gateway->addOn()->all();
74
-
75
- foreach ($addOns as $addOn)
76
- {
77
- if ($addOn->id == $newId)
78
- {
79
- $actualAddOn = $addOn;
80
- }
81
- }
82
-
83
- $this->assertNotNull($actualAddOn);
84
- $this->assertEquals($addOnParams["amount"], $actualAddOn->amount);
85
- $this->assertEquals($addOnParams["description"], $actualAddOn->description);
86
- $this->assertEquals($addOnParams["id"], $actualAddOn->id);
87
- }
88
- }
includes/lib/Braintree/tests/integration/AddressTest.php DELETED
@@ -1,311 +0,0 @@
1
- <?php
2
- namespace Test\Integration;
3
-
4
- require_once dirname(__DIR__) . '/Setup.php';
5
-
6
- use Test\Setup;
7
- use Braintree;
8
-
9
- class AddressTest extends Setup
10
- {
11
- public function testCreate()
12
- {
13
- $customer = Braintree\Customer::createNoValidate();
14
- $result = Braintree\Address::create([
15
- 'customerId' => $customer->id,
16
- 'firstName' => 'Dan',
17
- 'lastName' => 'Smith',
18
- 'company' => 'Braintree',
19
- 'streetAddress' => '1 E Main St',
20
- 'extendedAddress' => 'Apt 1F',
21
- 'locality' => 'Chicago',
22
- 'region' => 'IL',
23
- 'postalCode' => '60622',
24
- 'countryName' => 'Vatican City',
25
- 'countryCodeAlpha2' => 'VA',
26
- 'countryCodeAlpha3' => 'VAT',
27
- 'countryCodeNumeric' => '336'
28
- ]);
29
- $this->assertTrue($result->success);
30
- $address = $result->address;
31
- $this->assertEquals('Dan', $address->firstName);
32
- $this->assertEquals('Smith', $address->lastName);
33
- $this->assertEquals('Braintree', $address->company);
34
- $this->assertEquals('1 E Main St', $address->streetAddress);
35
- $this->assertEquals('Apt 1F', $address->extendedAddress);
36
- $this->assertEquals('Chicago', $address->locality);
37
- $this->assertEquals('IL', $address->region);
38
- $this->assertEquals('60622', $address->postalCode);
39
- $this->assertEquals('Vatican City', $address->countryName);
40
- $this->assertEquals('VA', $address->countryCodeAlpha2);
41
- $this->assertEquals('VAT', $address->countryCodeAlpha3);
42
- $this->assertEquals('336', $address->countryCodeNumeric);
43
- }
44
-
45
- public function testGatewayCreate()
46
- {
47
- $customer = Braintree\Customer::createNoValidate();
48
-
49
- $gateway = new Braintree\Gateway([
50
- 'environment' => 'development',
51
- 'merchantId' => 'integration_merchant_id',
52
- 'publicKey' => 'integration_public_key',
53
- 'privateKey' => 'integration_private_key'
54
- ]);
55
- $result = $gateway->address()->create([
56
- 'customerId' => $customer->id,
57
- 'streetAddress' => '1 E Main St',
58
- 'locality' => 'Chicago',
59
- 'region' => 'IL',
60
- 'postalCode' => '60622',
61
- ]);
62
-
63
- $this->assertTrue($result->success);
64
- $address = $result->address;
65
- $this->assertEquals('1 E Main St', $address->streetAddress);
66
- $this->assertEquals('Chicago', $address->locality);
67
- $this->assertEquals('IL', $address->region);
68
- $this->assertEquals('60622', $address->postalCode);
69
- }
70
-
71
- public function testCreate_withValidationErrors()
72
- {
73
- $customer = Braintree\Customer::createNoValidate();
74
- $result = Braintree\Address::create([
75
- 'customerId' => $customer->id,
76
- 'countryName' => 'Invalid States of America'
77
- ]);
78
- $this->assertFalse($result->success);
79
- $countryErrors = $result->errors->forKey('address')->onAttribute('countryName');
80
- $this->assertEquals(Braintree\Error\Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, $countryErrors[0]->code);
81
- }
82
-
83
- public function testCreate_withValidationErrors_onCountryCodes()
84
- {
85
- $customer = Braintree\Customer::createNoValidate();
86
- $result = Braintree\Address::create([
87
- 'customerId' => $customer->id,
88
- 'countryCodeAlpha2' => 'ZZ'
89
- ]);
90
- $this->assertFalse($result->success);
91
- $countryErrors = $result->errors->forKey('address')->onAttribute('countryCodeAlpha2');
92
- $this->assertEquals(Braintree\Error\Codes::ADDRESS_COUNTRY_CODE_ALPHA2_IS_NOT_ACCEPTED, $countryErrors[0]->code);
93
- }
94
-
95
- public function testCreate_withNotFoundErrors()
96
- {
97
- $this->setExpectedException('Braintree\Exception\NotFound','Customer nonExistentCustomerId not found.');
98
- $result = Braintree\Address::create([
99
- 'customerId' => 'nonExistentCustomerId',
100
- ]);
101
- }
102
-
103
- public function testCreateNoValidate()
104
- {
105
- $customer = Braintree\Customer::createNoValidate();
106
- $address = Braintree\Address::createNoValidate([
107
- 'customerId' => $customer->id,
108
- 'firstName' => 'Dan',
109
- 'lastName' => 'Smith',
110
- 'company' => 'Braintree',
111
- 'streetAddress' => '1 E Main St',
112
- 'extendedAddress' => 'Apt 1F',
113
- 'locality' => 'Chicago',
114
- 'region' => 'IL',
115
- 'postalCode' => '60622',
116
- 'countryName' => 'United States of America'
117
- ]);
118
- $this->assertEquals('Dan', $address->firstName);
119
- $this->assertEquals('Smith', $address->lastName);
120
- $this->assertEquals('Braintree', $address->company);
121
- $this->assertEquals('1 E Main St', $address->streetAddress);
122
- $this->assertEquals('Apt 1F', $address->extendedAddress);
123
- $this->assertEquals('Chicago', $address->locality);
124
- $this->assertEquals('IL', $address->region);
125
- $this->assertEquals('60622', $address->postalCode);
126
- $this->assertEquals('United States of America', $address->countryName);
127
- }
128
-
129
- public function testCreateNoValidate_withValidationErrors()
130
- {
131
- $customer = Braintree\Customer::createNoValidate();
132
- $this->setExpectedException('Braintree\Exception\ValidationsFailed');
133
- Braintree\Address::createNoValidate([
134
- 'customerId' => $customer->id,
135
- 'countryName' => 'Invalid States of America'
136
- ]);
137
- }
138
-
139
- public function testDelete()
140
- {
141
- $customer = Braintree\Customer::createNoValidate();
142
- $address = Braintree\Address::createNoValidate([
143
- 'customerId' => $customer->id,
144
- 'streetAddress' => '1 E Main St'
145
- ]);
146
- Braintree\Address::find($customer->id, $address->id);
147
- Braintree\Address::delete($customer->id, $address->id);
148
- $this->setExpectedException('Braintree\Exception\NotFound');
149
- Braintree\Address::find($customer->id, $address->id);
150
- }
151
-
152
- public function testFind()
153
- {
154
- $customer = Braintree\Customer::createNoValidate();
155
- $result = Braintree\Address::create([
156
- 'customerId' => $customer->id,
157
- 'firstName' => 'Dan',
158
- 'lastName' => 'Smith',
159
- 'company' => 'Braintree',
160
- 'streetAddress' => '1 E Main St',
161
- 'extendedAddress' => 'Apt 1F',
162
- 'locality' => 'Chicago',
163
- 'region' => 'IL',
164
- 'postalCode' => '60622',
165
- 'countryName' => 'United States of America'
166
- ]);
167
- $this->assertTrue($result->success);
168
- $address = Braintree\Address::find($customer->id, $result->address->id);
169
- $this->assertEquals('Dan', $address->firstName);
170
- $this->assertEquals('Smith', $address->lastName);
171
- $this->assertEquals('Braintree', $address->company);
172
- $this->assertEquals('1 E Main St', $address->streetAddress);
173
- $this->assertEquals('Apt 1F', $address->extendedAddress);
174
- $this->assertEquals('Chicago', $address->locality);
175
- $this->assertEquals('IL', $address->region);
176
- $this->assertEquals('60622', $address->postalCode);
177
- $this->assertEquals('United States of America', $address->countryName);
178
- }
179
-
180
- public function testFind_whenNotFound()
181
- {
182
- $customer = Braintree\Customer::createNoValidate();
183
- $this->setExpectedException('Braintree\Exception\NotFound');
184
- Braintree\Address::find($customer->id, 'does-not-exist');
185
- }
186
-
187
- public function testUpdate()
188
- {
189
- $customer = Braintree\Customer::createNoValidate();
190
- $address = Braintree\Address::createNoValidate([
191
- 'customerId' => $customer->id,
192
- 'firstName' => 'Old First',
193
- 'lastName' => 'Old Last',
194
- 'company' => 'Old Company',
195
- 'streetAddress' => '1 E Old St',
196
- 'extendedAddress' => 'Apt Old',
197
- 'locality' => 'Old Chicago',
198
- 'region' => 'Old Region',
199
- 'postalCode' => 'Old Postal',
200
- 'countryName' => 'United States of America',
201
- 'countryCodeAlpha2' => 'US',
202
- 'countryCodeAlpha3' => 'USA',
203
- 'countryCodeNumeric' => '840'
204
- ]);
205
- $result = Braintree\Address::update($customer->id, $address->id, [
206
- 'firstName' => 'New First',
207
- 'lastName' => 'New Last',
208
- 'company' => 'New Company',
209
- 'streetAddress' => '1 E New St',
210
- 'extendedAddress' => 'Apt New',
211
- 'locality' => 'New Chicago',
212
- 'region' => 'New Region',
213
- 'postalCode' => 'New Postal',
214
- 'countryName' => 'Mexico',
215
- 'countryCodeAlpha2' => 'MX',
216
- 'countryCodeAlpha3' => 'MEX',
217
- 'countryCodeNumeric' => '484'
218
- ]);
219
- $this->assertTrue($result->success);
220
- $address = $result->address;
221
- $this->assertEquals('New First', $address->firstName);
222
- $this->assertEquals('New Last', $address->lastName);
223
- $this->assertEquals('New Company', $address->company);
224
- $this->assertEquals('1 E New St', $address->streetAddress);
225
- $this->assertEquals('Apt New', $address->extendedAddress);
226
- $this->assertEquals('New Chicago', $address->locality);
227
- $this->assertEquals('New Region', $address->region);
228
- $this->assertEquals('New Postal', $address->postalCode);
229
- $this->assertEquals('Mexico', $address->countryName);
230
- $this->assertEquals('MX', $address->countryCodeAlpha2);
231
- $this->assertEquals('MEX', $address->countryCodeAlpha3);
232
- $this->assertEquals('484', $address->countryCodeNumeric);
233
- }
234
-
235
- public function testUpdate_withValidationErrors()
236
- {
237
- $customer = Braintree\Customer::createNoValidate();
238
- $address = Braintree\Address::createNoValidate([
239
- 'customerId' => $customer->id,
240
- 'streetAddress' => '1 E Main St'
241
- ]);
242
- $result = Braintree\Address::update(
243
- $customer->id,
244
- $address->id,
245
- [
246
- 'countryName' => 'Invalid States of America'
247
- ]
248
- );
249
- $this->assertFalse($result->success);
250
- $countryErrors = $result->errors->forKey('address')->onAttribute('countryName');
251
- $this->assertEquals(Braintree\Error\Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED, $countryErrors[0]->code);
252
- }
253
-
254
- public function testUpdate_withValidationErrors_onCountry()
255
- {
256
- $customer = Braintree\Customer::createNoValidate();
257
- $address = Braintree\Address::createNoValidate([
258
- 'customerId' => $customer->id,
259
- 'streetAddress' => '1 E Main St'
260
- ]);
261
- $result = Braintree\Address::update(
262
- $customer->id,
263
- $address->id,
264
- [
265
- 'countryCodeAlpha2' => 'MU',
266
- 'countryCodeAlpha3' => 'MYT'
267
- ]
268
- );
269
- $this->assertFalse($result->success);
270
- $countryErrors = $result->errors->forKey('address')->onAttribute('base');
271
- $this->assertEquals(Braintree\Error\Codes::ADDRESS_INCONSISTENT_COUNTRY, $countryErrors[0]->code);
272
- }
273
-
274
-
275
- public function testUpdateNoValidate()
276
- {
277
- $customer = Braintree\Customer::createNoValidate();
278
- $createdAddress = Braintree\Address::createNoValidate([
279
- 'customerId' => $customer->id,
280
- 'firstName' => 'Old First',
281
- 'lastName' => 'Old Last',
282
- 'company' => 'Old Company',
283
- 'streetAddress' => '1 E Old St',
284
- 'extendedAddress' => 'Apt Old',
285
- 'locality' => 'Old Chicago',
286
- 'region' => 'Old Region',
287
- 'postalCode' => 'Old Postal',
288
- 'countryName' => 'United States of America'
289
- ]);
290
- $address = Braintree\Address::updateNoValidate($customer->id, $createdAddress->id, [
291
- 'firstName' => 'New First',
292
- 'lastName' => 'New Last',
293
- 'company' => 'New Company',
294
- 'streetAddress' => '1 E New St',
295
- 'extendedAddress' => 'Apt New',
296
- 'locality' => 'New Chicago',
297
- 'region' => 'New Region',
298
- 'postalCode' => 'New Postal',
299
- 'countryName' => 'Mexico'
300
- ]);
301
- $this->assertEquals('New First', $address->firstName);
302
- $this->assertEquals('New Last', $address->lastName);
303
- $this->assertEquals('New Company', $address->company);
304
- $this->assertEquals('1 E New St', $address->streetAddress);
305
- $this->assertEquals('Apt New', $address->extendedAddress);
306
- $this->assertEquals('New Chicago', $address->locality);
307
- $this->assertEquals('New Region', $address->region);
308
- $this->assertEquals('New Postal', $address->postalCode);
309
- $this->assertEquals('Mexico', $address->countryName);
310
- }
311
- }
includes/lib/Braintree/tests/integration/ClientTokenTest.php DELETED
@@ -1,188 +0,0 @@
1
- <?php
2
- namespace Test\Integration;
3
-
4
- require_once dirname(__DIR__) . '/Setup.php';
5
-
6
- use Test;
7
- use Test\Setup;
8
- use Braintree;
9
-
10
- class ClientTokenTest extends Setup
11
- {
12
- public function test_ClientTokenAuthorizesRequest()
13
- {
14
- $clientToken = Test\Helper::decodedClientToken();
15
- $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
16
- $http = new HttpClientApi(Braintree\Configuration::$global);
17
- $response = $http->get_cards([
18
- "authorization_fingerprint" => $authorizationFingerprint,
19
- "shared_customer_identifier" => "fake_identifier",
20
- "shared_customer_identifier_type" => "testing",
21
- ]);
22
-
23
- $this->assertEquals(200, $response["status"]);
24
- }
25
-
26
- public function test_VersionOptionSupported()
27
- {
28
- $clientToken = Braintree\ClientToken::generate(["version" => 1]);
29
- $version = json_decode($clientToken)->version;
30
- $this->assertEquals(1, $version);
31
- }
32
-
33
- public function test_VersionDefaultsToTwo()
34
- {
35
- $encodedClientToken = Braintree\ClientToken::generate();
36
- $clientToken = base64_decode($encodedClientToken);
37
- $version = json_decode($clientToken)->version;
38
- $this->assertEquals(2, $version);
39
- }
40
-
41
- public function testGateway_VersionDefaultsToTwo()
42
- {
43
- $gateway = new Braintree\Gateway([
44
- 'environment' => 'development',
45
- 'merchantId' => 'integration_merchant_id',
46
- 'publicKey' => 'integration_public_key',
47
- 'privateKey' => 'integration_private_key',
48
- ]);
49
- $encodedClientToken = $gateway->clientToken()->generate();
50
- $clientToken = base64_decode($encodedClientToken);
51
- $version = json_decode($clientToken)->version;
52
- $this->assertEquals(2, $version);
53
- }
54
-
55
- public function test_GatewayRespectsVerifyCard()
56
- {
57
- $result = Braintree\Customer::create();
58
- $this->assertTrue($result->success);
59
- $customerId = $result->customer->id;
60
-
61
- $clientToken = Test\Helper::decodedClientToken([
62
- "customerId" => $customerId,
63
- "options" => [
64
- "verifyCard" => true
65
- ]
66
- ]);
67
- $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
68
-
69
- $http = new HttpClientApi(Braintree\Configuration::$global);
70
- $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode([
71
- "credit_card" => [
72
- "number" => "4000111111111115",
73
- "expirationDate" => "11/2099"
74
- ],
75
- "authorization_fingerprint" => $authorizationFingerprint,
76
- "shared_customer_identifier" => "fake_identifier",
77
- "shared_customer_identifier_type" => "testing"
78
- ]));
79
-
80
- $this->assertEquals(422, $response["status"]);
81
- }
82
-
83
- public function test_GatewayRespectsFailOnDuplicatePaymentMethod()
84
- {
85
- $result = Braintree\Customer::create();
86
- $this->assertTrue($result->success);
87
- $customerId = $result->customer->id;
88
-
89
- $clientToken = Test\Helper::decodedClientToken([
90
- "customerId" => $customerId,
91
- ]);
92
- $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
93
-
94
- $http = new HttpClientApi(Braintree\Configuration::$global);
95
- $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode([
96
- "credit_card" => [
97
- "number" => "4242424242424242",
98
- "expirationDate" => "11/2099"
99
- ],
100
- "authorization_fingerprint" => $authorizationFingerprint,
101
- "shared_customer_identifier" => "fake_identifier",
102
- "shared_customer_identifier_type" => "testing"
103
- ]));
104
- $this->assertEquals(201, $response["status"]);
105
-
106
- $clientToken = Test\Helper::decodedClientToken([
107
- "customerId" => $customerId,
108
- "options" => [
109
- "failOnDuplicatePaymentMethod" => true
110
- ]
111
- ]);
112
- $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
113
-
114
- $http = new HttpClientApi(Braintree\Configuration::$global);
115
- $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode([
116
- "credit_card" => [
117
- "number" => "4242424242424242",
118
- "expirationDate" => "11/2099"
119
- ],
120
- "authorization_fingerprint" => $authorizationFingerprint,
121
- "shared_customer_identifier" => "fake_identifier",
122
- "shared_customer_identifier_type" => "testing"
123
- ]));
124
- $this->assertEquals(422, $response["status"]);
125
- }
126
-
127
- public function test_GatewayRespectsMakeDefault()
128
- {
129
- $result = Braintree\Customer::create();
130
- $this->assertTrue($result->success);
131
- $customerId = $result->customer->id;
132
-
133
- $result = Braintree\CreditCard::create([
134
- 'customerId' => $customerId,
135
- 'number' => '4111111111111111',
136
- 'expirationDate' => '11/2099'
137
- ]);
138
- $this->assertTrue($result->success);
139
-
140
- $clientToken = Test\Helper::decodedClientToken([
141
- "customerId" => $customerId,
142
- "options" => [
143
- "makeDefault" => true
144
- ]
145
- ]);
146
- $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
147
-
148
- $http = new HttpClientApi(Braintree\Configuration::$global);
149
- $response = $http->post('/client_api/v1/payment_methods/credit_cards.json', json_encode([
150
- "credit_card" => [
151
- "number" => "4242424242424242",
152
- "expirationDate" => "11/2099"
153
- ],
154
- "authorization_fingerprint" => $authorizationFingerprint,
155
- "shared_customer_identifier" => "fake_identifier",
156
- "shared_customer_identifier_type" => "testing"
157
- ]));
158
-
159
- $this->assertEquals(201, $response["status"]);
160
-
161
- $customer = Braintree\Customer::find($customerId);
162
- $this->assertEquals(2, count($customer->creditCards));
163
- foreach ($customer->creditCards as $creditCard) {
164
- if ($creditCard->last4 == "4242") {
165
- $this->assertTrue($creditCard->default);
166
- }
167
- }
168
- }
169
-
170
- public function test_ClientTokenAcceptsMerchantAccountId()
171
- {
172
- $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
- }
includes/lib/Braintree/tests/integration/CreditCardTest.php DELETED
@@ -1,1323 +0,0 @@
1
- <?php
2
- namespace Test\Integration;
3
-
4
- require_once dirname(__DIR__) . '/Setup.php';
5
-
6
- use Test;
7
- use Test\Braintree\CreditCardNumbers\CardTypeIndicators;
8
- use Test\Setup;
9
- use Braintree;
10
-
11
- class CreditCardTest extends Setup
12
- {
13
- public function testCreate()
14
- {
15
- $customer = Braintree\Customer::createNoValidate();
16
- $result = Braintree\CreditCard::create([
17
- 'customerId' => $customer->id,
18
- 'cardholderName' => 'Cardholder',
19
- 'number' => '5105105105105100',
20
- 'expirationDate' => '05/12'
21
- ]);
22
- $this->assertTrue($result->success);
23
- $this->assertEquals($customer->id, $result->creditCard->customerId);
24
- $this->assertEquals('510510', $result->creditCard->bin);
25
- $this->assertEquals('5100', $result->creditCard->last4);
26
- $this->assertEquals('Cardholder', $result->creditCard->cardholderName);
27
- $this->assertEquals('05/2012', $result->creditCard->expirationDate);
28
- $this->assertEquals(1, preg_match('/\A\w{32}\z/', $result->creditCard->uniqueNumberIdentifier));
29
- $this->assertFalse($result->creditCard->isVenmoSdk());
30
- $this->assertEquals(1, preg_match('/png/', $result->creditCard->imageUrl));
31
- }
32
-
33
- public function testGatewayCreate()
34
- {
35
- $customer = Braintree\Customer::createNoValidate();
36
-
37
- $gateway = new Braintree\Gateway([
38
- 'environment' => 'development',
39
- 'merchantId' => 'integration_merchant_id',
40
- 'publicKey' => 'integration_public_key',
41
- 'privateKey' => 'integration_private_key'
42
- ]);
43
- $result = $gateway->creditCard()->create([
44
- 'customerId' => $customer->id,
45
- 'cardholderName' => 'Cardholder',
46
- 'number' => '5105105105105100',
47
- 'expirationDate' => '05/12'
48
- ]);
49
-
50
- $this->assertTrue($result->success);
51
- $this->assertEquals($customer->id, $result->creditCard->customerId);
52
- $this->assertEquals('510510', $result->creditCard->bin);
53
- $this->assertEquals('5100', $result->creditCard->last4);
54
- $this->assertEquals('Cardholder', $result->creditCard->cardholderName);
55
- $this->assertEquals('05/2012', $result->creditCard->expirationDate);
56
- }
57
-
58
- public function testCreate_withDefault()
59
- {
60
- $customer = Braintree\Customer::createNoValidate();
61
- $card1 = Braintree\CreditCard::create([
62
- 'customerId' => $customer->id,
63
- 'cardholderName' => 'Cardholder',
64
- 'number' => '5105105105105100',
65
- 'expirationDate' => '05/12'
66
- ])->creditCard;
67
- $this->assertTrue($card1->isDefault());
68
-
69
- $card2 = Braintree\CreditCard::create([
70
- 'customerId' => $customer->id,
71
- 'cardholderName' => 'Cardholder',
72
- 'number' => '5105105105105100',
73
- 'expirationDate' => '05/12',
74
- 'options' => [
75
- 'makeDefault' => true
76
- ]
77
- ])->creditCard;
78
-
79
- $card1 = Braintree\CreditCard::find($card1->token);
80
- $this->assertFalse($card1->isDefault());
81
- $this->assertTrue($card2->isDefault());
82
- }
83
-
84
- public function testCreateWithVerificationAmount()
85
- {
86
- $customer = Braintree\Customer::createNoValidate();
87
- $result = Braintree\CreditCard::create([
88
- 'customerId' => $customer->id,
89
- 'cardholderName' => 'Cardholder',
90
- 'number' => '4111111111111111',
91
- 'expirationDate' => '05/12',
92
- 'options' => [
93
- 'verificationAmount' => '5.00',
94
- 'verifyCard' => true
95
- ]
96
- ]);
97
- $this->assertTrue($result->success);
98
- $this->assertEquals($customer->id, $result->creditCard->customerId);
99
- $this->assertEquals('411111', $result->creditCard->bin);
100
- $this->assertEquals('1111', $result->creditCard->last4);
101
- $this->assertEquals('Cardholder', $result->creditCard->cardholderName);
102
- $this->assertEquals('05/2012', $result->creditCard->expirationDate);
103
- $this->assertEquals(1, preg_match('/\A\w{32}\z/', $result->creditCard->uniqueNumberIdentifier));
104
- $this->assertFalse($result->creditCard->isVenmoSdk());
105
- $this->assertEquals(1, preg_match('/png/', $result->creditCard->imageUrl));
106
- }
107
-
108
- public function testAddCardToExistingCustomerUsingNonce()
109
- {
110
- $customer = Braintree\Customer::createNoValidate();
111
- $http = new HttpClientApi(Braintree\Configuration::$global);
112
- $nonce = $http->nonce_for_new_card([
113
- "credit_card" => [
114
- "number" => "4111111111111111",
115
- "expirationMonth" => "11",
116
- "expirationYear" => "2099"
117
- ],
118
- "share" => true
119
- ]);
120
-
121
- $result = Braintree\CreditCard::create([
122
- 'customerId' => $customer->id,
123
- 'paymentMethodNonce' => $nonce
124
- ]);
125
-
126
- $this->assertSame("411111", $result->creditCard->bin);
127
- $this->assertSame("1111", $result->creditCard->last4);
128
- }
129
-
130
- public function testCreate_withSecurityParams()
131
- {
132
- $customer = Braintree\Customer::createNoValidate();
133
- $result = Braintree\CreditCard::create([
134
- 'customerId' => $customer->id,
135
- 'deviceSessionId' => 'abc_123',
136
- 'fraudMerchantId' => '456',
137
- 'cardholderName' => 'Cardholder',
138
- 'number' => '5105105105105100',
139
- 'expirationDate' => '05/12'
140
- ]);
141
-
142
- $this->assertTrue($result->success);
143
- }
144
-
145
- public function testCreate_withExpirationMonthAndYear()
146
- {
147
- $customer = Braintree\Customer::createNoValidate();
148
- $result = Braintree\CreditCard::create([
149
- 'customerId' => $customer->id,
150
- 'cardholderName' => 'Cardholder',
151
- 'number' => '5105105105105100',
152
- 'expirationMonth' => '05',
153
- 'expirationYear' => '2011'
154
- ]);
155
- $this->assertTrue($result->success);
156
- $this->assertEquals($customer->id, $result->creditCard->customerId);
157
- $this->assertEquals('510510', $result->creditCard->bin);
158
- $this->assertEquals('5100', $result->creditCard->last4);
159
- $this->assertEquals('Cardholder', $result->creditCard->cardholderName);
160
- $this->assertEquals('05/2011', $result->creditCard->expirationDate);
161
- }
162
-
163
- public function testCreate_withSpecifyingToken()
164
- {
165
- $token = strval(rand());
166
- $customer = Braintree\Customer::createNoValidate();
167
- $result = Braintree\CreditCard::create([
168
- 'customerId' => $customer->id,
169
- 'number' => '5105105105105100',
170
- 'expirationDate' => '05/2011',
171
- 'token' => $token
172
- ]);
173
- $this->assertTrue($result->success);
174
- $this->assertEquals($token, $result->creditCard->token);
175
- $this->assertEquals($token, Braintree\CreditCard::find($token)->token);
176
- }
177
-
178
- public function testCreate_withDuplicateCardCheck()
179
- {
180
- $customer = Braintree\Customer::createNoValidate();
181
-
182
- $attributes = [
183
- 'customerId' => $customer->id,
184
- 'number' => '5105105105105100',
185
- 'expirationDate' => '05/2011',
186
- 'options' => ['failOnDuplicatePaymentMethod' => true]
187
- ];
188
- Braintree\CreditCard::create($attributes);
189
-
190
- $result = Braintree\CreditCard::create($attributes);
191
- $this->assertFalse($result->success);
192
- $errors = $result->errors->forKey('creditCard')->onAttribute('number');
193
- $this->assertEquals(Braintree\Error\Codes::CREDIT_CARD_DUPLICATE_CARD_EXISTS, $errors[0]->code);
194
- $this->assertEquals(1, preg_match('/Duplicate card exists in the vault\./', $result->message));
195
- }
196
-
197
- public function testCreate_withCardVerification()
198
- {
199
- $customer = Braintree\Customer::createNoValidate();
200
- $result = Braintree\CreditCard::create([
201
- 'customerId' => $customer->id,
202
- 'number' => '5105105105105100',
203
- 'expirationDate' => '05/2011',
204
- 'options' => ['verifyCard' => true]
205
- ]);
206
- $this->assertFalse($result->success);
207
- $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
208
- $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
209
- $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
210
- $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
211
- $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
212
- $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
213
- $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
214
- $this->assertEquals(Braintree\CreditCard::PREPAID_UNKNOWN, $result->creditCardVerification->creditCard['prepaid']);
215
- }
216
-
217
- public function testCreate_withCardVerificationReturnsVerificationWithRiskData()
218
- {
219
- $customer = Braintree\Customer::createNoValidate();
220
- $result = Braintree\CreditCard::create([
221
- 'customerId' => $customer->id,
222
- 'number' => '4111111111111111',
223
- 'expirationDate' => '05/2011',
224
- 'options' => ['verifyCard' => true]
225
- ]);
226
- $this->assertTrue($result->success);
227
- $this->assertNotNull($result->creditCard->verification->riskData);
228
- $this->assertNotNull($result->creditCard->verification->riskData->decision);
229
- }
230
-
231
- public function testCreate_withCardVerificationAndOverriddenAmount()
232
- {
233
- $customer = Braintree\Customer::createNoValidate();
234
- $result = Braintree\CreditCard::create([
235
- 'customerId' => $customer->id,
236
- 'number' => '5105105105105100',
237
- 'expirationDate' => '05/2011',
238
- 'options' => ['verifyCard' => true, 'verificationAmount' => '1.02']
239
- ]);
240
- $this->assertFalse($result->success);
241
- $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
242
- $this->assertEquals('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);
265
- $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
266
- $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
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.',
282
- 'streetAddress' => '1 E Main St',
283
- 'extendedAddress' => 'Suite 101',
284
- 'locality' => 'Chicago',
285
- 'region' => 'IL',
286
- 'postalCode' => '60622',
287
- 'countryName' => 'Micronesia',
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);
296
- $this->assertEquals('5100', $result->creditCard->last4);
297
- $this->assertEquals('Peter Tomlin', $result->creditCard->cardholderName);
298
- $this->assertEquals('05/2012', $result->creditCard->expirationDate);
299
- $address = $result->creditCard->billingAddress;
300
- $this->assertEquals('Drew', $address->firstName);
301
- $this->assertEquals('Smith', $address->lastName);
302
- $this->assertEquals('Smith Co.', $address->company);
303
- $this->assertEquals('1 E Main St', $address->streetAddress);
304
- $this->assertEquals('Suite 101', $address->extendedAddress);
305
- $this->assertEquals('Chicago', $address->locality);
306
- $this->assertEquals('IL', $address->region);
307
- $this->assertEquals('60622', $address->postalCode);
308
- $this->assertEquals('Micronesia', $address->countryName);
309
- $this->assertEquals('FM', $address->countryCodeAlpha2);
310
- $this->assertEquals('FSM', $address->countryCodeAlpha3);
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);
430
- $this->assertEquals('Cardholder', $creditCard->cardholderName);
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.',
545
- 'streetAddress' => '123 Old St',
546
- 'extendedAddress' => 'Suite 101',
547
- 'locality' => 'Chicago',
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);
713
- }
714
- $uniqueCreditCardTokens = array_unique(array_values($arr));
715
- $this->assertEquals($collection->maximumCount(), count($uniqueCreditCardTokens));
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);
731
- }
732
- $uniqueCreditCardTokens = array_unique(array_values($arr));
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
- );
742
- $this->assertTrue($collection->maximumCount() > 1);
743
-
744
- foreach($collection as $creditCard) {
745
- foreach($creditCard->subscriptions as $subscription) {
746
- foreach($subscription->transactions as $transaction) {
747
- $this->assertNotNull($transaction->creditCardDetails->expirationMonth);
748
- }
749
- }
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.',
784
- 'streetAddress' => '1 E Main St',
785
- 'extendedAddress' => 'Suite 101',
786
- 'locality' => 'Chicago',
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);
894
- $this->assertEquals('New Cardholder', $updateResult->creditCard->cardholderName);
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