Mollie Payments for WooCommerce - Version 5.3.0

Version Description

  • 21-08-2019 =

  • Add - Introduce MyBank payment method

  • Fix - Active Payment Object may be NULL causing WSOD after order is placed in Mollie

  • Fix - ApplePay logo does not have the right resolution

Download this release

Release Info

Developer wido
Plugin Icon wp plugin Mollie Payments for WooCommerce
Version 5.3.0
Comparing to
See all releases

Code changes from version 5.2.1 to 5.3.0

Files changed (110) hide show
  1. assets/images/applepay.svg +1 -1
  2. assets/images/mybank.svg +1 -0
  3. includes/mollie-api-php/.gitattributes +8 -0
  4. includes/mollie-api-php/.github/ISSUE_TEMPLATE.md +8 -0
  5. includes/mollie-api-php/.gitignore +8 -0
  6. includes/mollie-api-php/.travis.yml +46 -0
  7. includes/mollie-api-php/Makefile +31 -0
  8. includes/mollie-api-php/composer.json +80 -0
  9. includes/mollie-api-php/examples/captures/get-capture.php +27 -0
  10. includes/mollie-api-php/examples/captures/list-captures.php +27 -0
  11. includes/mollie-api-php/examples/customers/create-customer-first-payment.php +67 -0
  12. includes/mollie-api-php/examples/customers/create-customer-payment.php +61 -0
  13. includes/mollie-api-php/examples/customers/create-customer-recurring-payment.php +63 -0
  14. includes/mollie-api-php/examples/customers/create-customer.php +27 -0
  15. includes/mollie-api-php/examples/customers/delete-customer.php +17 -0
  16. includes/mollie-api-php/examples/customers/list-customer-payments.php +58 -0
  17. includes/mollie-api-php/examples/customers/update-customer.php +31 -0
  18. includes/mollie-api-php/examples/database/.gitignore +1 -0
  19. includes/mollie-api-php/examples/functions.php +23 -0
  20. includes/mollie-api-php/examples/initialize.php +18 -0
  21. includes/mollie-api-php/examples/initialize_with_oauth.php +19 -0
  22. includes/mollie-api-php/examples/invoices/list-invoices.php +37 -0
  23. includes/mollie-api-php/examples/mandates/create-mandate.php +30 -0
  24. includes/mollie-api-php/examples/mandates/list-mandates.php +28 -0
  25. includes/mollie-api-php/examples/mandates/revoke-mandate.php +31 -0
  26. includes/mollie-api-php/examples/orders/cancel-order-lines.php +44 -0
  27. includes/mollie-api-php/examples/orders/cancel-order.php +26 -0
  28. includes/mollie-api-php/examples/orders/create-order.php +118 -0
  29. includes/mollie-api-php/examples/orders/list-methods.php +28 -0
  30. includes/mollie-api-php/examples/orders/list-orders.php +49 -0
  31. includes/mollie-api-php/examples/orders/refund-order-completely.php +25 -0
  32. includes/mollie-api-php/examples/orders/refund-order-partially.php +33 -0
  33. includes/mollie-api-php/examples/orders/webhook.php +50 -0
  34. includes/mollie-api-php/examples/payments/create-ideal-payment.php +81 -0
  35. includes/mollie-api-php/examples/payments/create-payment-oauth.php +67 -0
  36. includes/mollie-api-php/examples/payments/create-payment.php +60 -0
  37. includes/mollie-api-php/examples/payments/list-methods.php +27 -0
  38. includes/mollie-api-php/examples/payments/list-payments.php +85 -0
  39. includes/mollie-api-php/examples/payments/refund-payment.php +71 -0
  40. includes/mollie-api-php/examples/payments/return.php +29 -0
  41. includes/mollie-api-php/examples/payments/webhook.php +65 -0
  42. includes/mollie-api-php/examples/profiles/create-profile.php +30 -0
  43. includes/mollie-api-php/examples/profiles/delete-profile.php +23 -0
  44. includes/mollie-api-php/examples/profiles/list-profiles.php +28 -0
  45. includes/mollie-api-php/examples/profiles/update-profile.php +33 -0
  46. includes/mollie-api-php/examples/settlements/list-settlements.php +53 -0
  47. includes/mollie-api-php/examples/shipments/create-shipment-all.php +27 -0
  48. includes/mollie-api-php/examples/shipments/create-shipment-partial.php +42 -0
  49. includes/mollie-api-php/examples/shipments/get-shipment.php +27 -0
  50. includes/mollie-api-php/examples/shipments/list-shipments.php +30 -0
  51. includes/mollie-api-php/examples/shipments/update-shipment.php +40 -0
  52. includes/mollie-api-php/examples/subscriptions/cancel-subscription.php +36 -0
  53. includes/mollie-api-php/examples/subscriptions/create-subscription.php +61 -0
  54. includes/mollie-api-php/examples/subscriptions/update-subscription.php +31 -0
  55. includes/mollie-api-php/phpunit.xml +15 -0
  56. includes/mollie-api-php/tests/Mollie/API/CompatibilityCheckerTest.php +57 -0
  57. includes/mollie-api-php/tests/Mollie/API/Endpoints/BaseEndpointTest.php +76 -0
  58. includes/mollie-api-php/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php +156 -0
  59. includes/mollie-api-php/tests/Mollie/API/Endpoints/CustomerEndpointTest.php +234 -0
  60. includes/mollie-api-php/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php +314 -0
  61. includes/mollie-api-php/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php +222 -0
  62. includes/mollie-api-php/tests/Mollie/API/Endpoints/MandateEndpointTest.php +428 -0
  63. includes/mollie-api-php/tests/Mollie/API/Endpoints/MethodEndpointTest.php +641 -0
  64. includes/mollie-api-php/tests/Mollie/API/Endpoints/OnboardingEndpointTest.php +82 -0
  65. includes/mollie-api-php/tests/Mollie/API/Endpoints/OrderEndpointTest.php +1085 -0
  66. includes/mollie-api-php/tests/Mollie/API/Endpoints/OrderLineEndpointTest.php +21 -0
  67. includes/mollie-api-php/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php +289 -0
  68. includes/mollie-api-php/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php +427 -0
  69. includes/mollie-api-php/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php +126 -0
  70. includes/mollie-api-php/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php +283 -0
  71. includes/mollie-api-php/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php +265 -0
  72. includes/mollie-api-php/tests/Mollie/API/Endpoints/PaymentEndpointTest.php +381 -0
  73. includes/mollie-api-php/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php +388 -0
  74. includes/mollie-api-php/tests/Mollie/API/Endpoints/PermissionEndpointTest.php +169 -0
  75. includes/mollie-api-php/tests/Mollie/API/Endpoints/ProfileEndpointTest.php +501 -0
  76. includes/mollie-api-php/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php +232 -0
  77. includes/mollie-api-php/tests/Mollie/API/Endpoints/RefundEndpointTest.php +161 -0
  78. includes/mollie-api-php/tests/Mollie/API/Endpoints/SettlementEndpointTest.php +450 -0
  79. includes/mollie-api-php/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php +565 -0
  80. includes/mollie-api-php/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php +491 -0
  81. includes/mollie-api-php/tests/Mollie/API/Exceptions/ApiExceptionTest.php +89 -0
  82. includes/mollie-api-php/tests/Mollie/API/MollieApiClientTest.php +159 -0
  83. includes/mollie-api-php/tests/Mollie/API/Resources/InvoiceTest.php +42 -0
  84. includes/mollie-api-php/tests/Mollie/API/Resources/OnboardingTest.php +42 -0
  85. includes/mollie-api-php/tests/Mollie/API/Resources/OrderLineCollectionTest.php +36 -0
  86. includes/mollie-api-php/tests/Mollie/API/Resources/OrderLineTest.php +149 -0
  87. includes/mollie-api-php/tests/Mollie/API/Resources/OrderTest.php +295 -0
  88. includes/mollie-api-php/tests/Mollie/API/Resources/PaymentTest.php +212 -0
  89. includes/mollie-api-php/tests/Mollie/API/Resources/ProfileTest.php +42 -0
  90. includes/mollie-api-php/tests/Mollie/API/Resources/RefundTest.php +50 -0
  91. includes/mollie-api-php/tests/Mollie/API/Resources/ResourceFactoryTest.php +34 -0
  92. includes/mollie-api-php/tests/Mollie/API/Resources/SettlementTest.php +50 -0
  93. includes/mollie-api-php/tests/Mollie/API/Resources/ShipmentTest.php +84 -0
  94. includes/mollie-api-php/tests/Mollie/API/Resources/SubscriptionTest.php +60 -0
  95. includes/mollie-api-php/tests/Mollie/API/Types/MandateMethodTest.php +37 -0
  96. includes/mollie-api-php/tests/Mollie/TestHelpers/AmountObjectTestHelpers.php +22 -0
  97. includes/mollie-api-php/tests/Mollie/TestHelpers/LinkObjectTestHelpers.php +29 -0
  98. includes/mollie-api-php/vendor/autoload.php +1 -1
  99. includes/mollie-api-php/vendor/composer/autoload_real.php +7 -7
  100. includes/mollie-api-php/vendor/composer/autoload_static.php +4 -4
  101. includes/mollie-api-php/vendor/composer/ca-bundle/README.md +7 -7
  102. includes/mollie-api-php/vendor/composer/ca-bundle/composer.json +2 -2
  103. includes/mollie-api-php/vendor/composer/ca-bundle/res/cacert.pem +108 -2
  104. includes/mollie-api-php/vendor/composer/ca-bundle/src/CaBundle.php +25 -23
  105. includes/mollie-api-php/vendor/composer/installed.json +8 -8
  106. includes/mollie/wc/gateway/applepay.php +0 -1
  107. includes/mollie/wc/gateway/mybank.php +85 -0
  108. includes/mollie/wc/plugin.php +2 -1
  109. mollie-payments-for-woocommerce.php +2 -2
  110. readme.txt +7 -1
assets/images/applepay.svg CHANGED
@@ -1,5 +1,5 @@
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <svg width="165.52px" height="105.97px" enable-background="new 0 0 165.52107 105.9651" version="1.1" viewBox="0 0 165.52107 105.9651" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
3
  <path d="m150.7 0h-135.87c-0.5659 0-1.1328 0-1.6977 0.0033-0.47751 0.0034-0.95391 0.0087-1.4303 0.0217-1.039 0.0281-2.0869 0.0894-3.1129 0.2738-1.0424 0.1876-2.0124 0.4936-2.9587 0.9754-0.9303 0.4731-1.782 1.0919-2.5201 1.8303-0.73841 0.7384-1.3572 1.5887-1.8302 2.52-0.4819 0.9463-0.7881 1.9166-0.9744 2.9598-0.18539 1.0263-0.2471 2.074-0.2751 3.1119-0.0128 0.4764-0.01829 0.9528-0.0214 1.4291-0.0033 0.5661-0.0022 1.1318-0.0022 1.6989v76.318c0 0.5671-0.0011 1.1318 0.0022 1.699 0.00311 0.4763 0.0086 0.9527 0.0214 1.4291 0.028 1.037 0.08971 2.0847 0.2751 3.1107 0.1863 1.0436 0.4925 2.0135 0.9744 2.9599 0.473 0.9313 1.0918 1.7827 1.8302 2.52 0.73809 0.7396 1.5898 1.3583 2.5201 1.8302 0.9463 0.4831 1.9163 0.7892 2.9587 0.9767 1.026 0.1832 2.0739 0.2456 3.1129 0.2737 0.4764 0.0108 0.9528 0.0172 1.4303 0.0194 0.56489 0.0044 1.1318 0.0044 1.6977 0.0044h135.87c0.5649 0 1.1318 0 1.6966-0.0044 0.47641-0.0022 0.95282-0.0086 1.4314-0.0194 1.0368-0.0281 2.0845-0.0905 3.113-0.2737 1.041-0.1875 2.0112-0.4936 2.9576-0.9767 0.9313-0.4719 1.7805-1.0906 2.5201-1.8302 0.7372-0.7373 1.356-1.5887 1.8302-2.52 0.48299-0.9464 0.78889-1.9163 0.97429-2.9599 0.1855-1.026 0.2457-2.0737 0.2738-3.1107 0.013-0.4764 0.01941-0.9528 0.02161-1.4291 0.00439-0.5672 0.00439-1.1319 0.00439-1.699v-76.318c0-0.5671 0-1.1328-0.00439-1.6989-0.0022-0.4763-0.00861-0.9527-0.02161-1.4291-0.02811-1.0379-0.0883-2.0856-0.2738-3.1119-0.18539-1.0432-0.4913-2.0135-0.97429-2.9598-0.47421-0.9313-1.093-1.7816-1.8302-2.52-0.73961-0.7384-1.5888-1.3572-2.5201-1.8303-0.9464-0.4818-1.9166-0.7878-2.9576-0.9754-1.0285-0.1844-2.0762-0.2457-3.113-0.2738-0.47858-0.013-0.95499-0.0183-1.4314-0.0217-0.56478-0.0033-1.1317-0.0033-1.6966-0.0033z"/>
4
  <path d="m150.7 3.532l1.6715 0.0032c0.4528 0.0032 0.90561 0.0081 1.3609 0.0205 0.79201 0.0214 1.7185 0.0643 2.5821 0.2191 0.7507 0.1352 1.3803 0.3408 1.9845 0.6484 0.5965 0.3031 1.143 0.7003 1.6202 1.1768 0.479 0.4797 0.87671 1.0271 1.1838 1.6302 0.30589 0.5995 0.51019 1.2261 0.64459 1.9823 0.1544 0.8542 0.1971 1.7832 0.21881 2.5801 0.01219 0.4498 0.01819 0.8996 0.0204 1.3601 0.00429 0.5569 0.0042 1.1135 0.0042 1.6715v76.318c0 0.558 9e-5 1.1136-0.0043 1.6824-0.00211 0.4497-0.0081 0.8995-0.0204 1.3501-0.02161 0.7957-0.0643 1.7242-0.2206 2.5885-0.13251 0.7458-0.3367 1.3725-0.64429 1.975-0.30621 0.6016-0.70331 1.1484-1.1802 1.6251-0.47989 0.48-1.0246 0.876-1.6282 1.1819-0.5997 0.3061-1.2282 0.51151-1.9715 0.6453-0.88109 0.157-1.8464 0.2002-2.5734 0.2199-0.4574 0.0103-0.9126 0.01649-1.3789 0.0187-0.55571 0.0043-1.1134 0.0042-1.6692 0.0042h-135.87-0.0221c-0.5494 0-1.0999 0-1.6593-0.0043-0.4561-0.00211-0.9112-0.0082-1.3512-0.0182-0.7436-0.0201-1.7095-0.0632-2.5834-0.2193-0.74969-0.1348-1.3782-0.3402-1.9858-0.6503-0.59789-0.3032-1.1422-0.6988-1.6223-1.1797-0.4764-0.4756-0.8723-1.0207-1.1784-1.6232-0.3064-0.6019-0.5114-1.2305-0.64619-1.9852-0.15581-0.8626-0.19861-1.7874-0.22-2.5777-0.01221-0.4525-0.01731-0.9049-0.02021-1.3547l-0.0022-1.3279 1e-4 -0.3506v-76.318l-1e-4 -0.3506 0.0021-1.3251c3e-3 -0.4525 0.0081-0.9049 0.02031-1.357 0.02139-0.7911 0.06419-1.7163 0.22129-2.5861 0.1336-0.7479 0.3385-1.3765 0.6465-1.9814 0.3037-0.5979 0.7003-1.1437 1.1792-1.6225 0.477-0.4772 1.0231-0.8739 1.6248-1.1799 0.6011-0.3061 1.2308-0.5116 1.9805-0.6465 0.8638-0.1552 1.7909-0.198 2.5849-0.2195 0.4526-0.0123 0.9052-0.0172 1.3544-0.0203l1.6771-0.0033h135.87" fill="#fff"/>
5
  <path d="m45.186 35.641c1.4172-1.7727 2.379-4.1528 2.1253-6.5851-2.0746 0.10316-4.6063 1.3687-6.0721 3.1428-1.3161 1.5192-2.4809 3.999-2.1772 6.3293 2.3289 0.20201 4.6556-1.1641 6.124-2.887"/>
1
  <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="32" height="25" enable-background="new 0 0 165.52107 105.9651" version="1.1" viewBox="0 0 165.52107 105.9651" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
3
  <path d="m150.7 0h-135.87c-0.5659 0-1.1328 0-1.6977 0.0033-0.47751 0.0034-0.95391 0.0087-1.4303 0.0217-1.039 0.0281-2.0869 0.0894-3.1129 0.2738-1.0424 0.1876-2.0124 0.4936-2.9587 0.9754-0.9303 0.4731-1.782 1.0919-2.5201 1.8303-0.73841 0.7384-1.3572 1.5887-1.8302 2.52-0.4819 0.9463-0.7881 1.9166-0.9744 2.9598-0.18539 1.0263-0.2471 2.074-0.2751 3.1119-0.0128 0.4764-0.01829 0.9528-0.0214 1.4291-0.0033 0.5661-0.0022 1.1318-0.0022 1.6989v76.318c0 0.5671-0.0011 1.1318 0.0022 1.699 0.00311 0.4763 0.0086 0.9527 0.0214 1.4291 0.028 1.037 0.08971 2.0847 0.2751 3.1107 0.1863 1.0436 0.4925 2.0135 0.9744 2.9599 0.473 0.9313 1.0918 1.7827 1.8302 2.52 0.73809 0.7396 1.5898 1.3583 2.5201 1.8302 0.9463 0.4831 1.9163 0.7892 2.9587 0.9767 1.026 0.1832 2.0739 0.2456 3.1129 0.2737 0.4764 0.0108 0.9528 0.0172 1.4303 0.0194 0.56489 0.0044 1.1318 0.0044 1.6977 0.0044h135.87c0.5649 0 1.1318 0 1.6966-0.0044 0.47641-0.0022 0.95282-0.0086 1.4314-0.0194 1.0368-0.0281 2.0845-0.0905 3.113-0.2737 1.041-0.1875 2.0112-0.4936 2.9576-0.9767 0.9313-0.4719 1.7805-1.0906 2.5201-1.8302 0.7372-0.7373 1.356-1.5887 1.8302-2.52 0.48299-0.9464 0.78889-1.9163 0.97429-2.9599 0.1855-1.026 0.2457-2.0737 0.2738-3.1107 0.013-0.4764 0.01941-0.9528 0.02161-1.4291 0.00439-0.5672 0.00439-1.1319 0.00439-1.699v-76.318c0-0.5671 0-1.1328-0.00439-1.6989-0.0022-0.4763-0.00861-0.9527-0.02161-1.4291-0.02811-1.0379-0.0883-2.0856-0.2738-3.1119-0.18539-1.0432-0.4913-2.0135-0.97429-2.9598-0.47421-0.9313-1.093-1.7816-1.8302-2.52-0.73961-0.7384-1.5888-1.3572-2.5201-1.8303-0.9464-0.4818-1.9166-0.7878-2.9576-0.9754-1.0285-0.1844-2.0762-0.2457-3.113-0.2738-0.47858-0.013-0.95499-0.0183-1.4314-0.0217-0.56478-0.0033-1.1317-0.0033-1.6966-0.0033z"/>
4
  <path d="m150.7 3.532l1.6715 0.0032c0.4528 0.0032 0.90561 0.0081 1.3609 0.0205 0.79201 0.0214 1.7185 0.0643 2.5821 0.2191 0.7507 0.1352 1.3803 0.3408 1.9845 0.6484 0.5965 0.3031 1.143 0.7003 1.6202 1.1768 0.479 0.4797 0.87671 1.0271 1.1838 1.6302 0.30589 0.5995 0.51019 1.2261 0.64459 1.9823 0.1544 0.8542 0.1971 1.7832 0.21881 2.5801 0.01219 0.4498 0.01819 0.8996 0.0204 1.3601 0.00429 0.5569 0.0042 1.1135 0.0042 1.6715v76.318c0 0.558 9e-5 1.1136-0.0043 1.6824-0.00211 0.4497-0.0081 0.8995-0.0204 1.3501-0.02161 0.7957-0.0643 1.7242-0.2206 2.5885-0.13251 0.7458-0.3367 1.3725-0.64429 1.975-0.30621 0.6016-0.70331 1.1484-1.1802 1.6251-0.47989 0.48-1.0246 0.876-1.6282 1.1819-0.5997 0.3061-1.2282 0.51151-1.9715 0.6453-0.88109 0.157-1.8464 0.2002-2.5734 0.2199-0.4574 0.0103-0.9126 0.01649-1.3789 0.0187-0.55571 0.0043-1.1134 0.0042-1.6692 0.0042h-135.87-0.0221c-0.5494 0-1.0999 0-1.6593-0.0043-0.4561-0.00211-0.9112-0.0082-1.3512-0.0182-0.7436-0.0201-1.7095-0.0632-2.5834-0.2193-0.74969-0.1348-1.3782-0.3402-1.9858-0.6503-0.59789-0.3032-1.1422-0.6988-1.6223-1.1797-0.4764-0.4756-0.8723-1.0207-1.1784-1.6232-0.3064-0.6019-0.5114-1.2305-0.64619-1.9852-0.15581-0.8626-0.19861-1.7874-0.22-2.5777-0.01221-0.4525-0.01731-0.9049-0.02021-1.3547l-0.0022-1.3279 1e-4 -0.3506v-76.318l-1e-4 -0.3506 0.0021-1.3251c3e-3 -0.4525 0.0081-0.9049 0.02031-1.357 0.02139-0.7911 0.06419-1.7163 0.22129-2.5861 0.1336-0.7479 0.3385-1.3765 0.6465-1.9814 0.3037-0.5979 0.7003-1.1437 1.1792-1.6225 0.477-0.4772 1.0231-0.8739 1.6248-1.1799 0.6011-0.3061 1.2308-0.5116 1.9805-0.6465 0.8638-0.1552 1.7909-0.198 2.5849-0.2195 0.4526-0.0123 0.9052-0.0172 1.3544-0.0203l1.6771-0.0033h135.87" fill="#fff"/>
5
  <path d="m45.186 35.641c1.4172-1.7727 2.379-4.1528 2.1253-6.5851-2.0746 0.10316-4.6063 1.3687-6.0721 3.1428-1.3161 1.5192-2.4809 3.999-2.1772 6.3293 2.3289 0.20201 4.6556-1.1641 6.124-2.887"/>
assets/images/mybank.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg fill="none" height="24" viewBox="0 0 32 24" width="32" xmlns="http://www.w3.org/2000/svg"><path d="m4.12903.5h23.74197c1.9991 0 3.629 1.63976 3.629 3.67391v15.65219c0 2.0341-1.6299 3.6739-3.629 3.6739h-23.74197c-1.99917 0-3.62903-1.6398-3.62903-3.6739v-15.65219c0-2.03415 1.62986-3.67391 3.62903-3.67391z" fill="#fff" stroke="#e6e6e6"/><g clip-rule="evenodd" fill-rule="evenodd"><path d="m22.2986 13.6423s-.7024.1442-.6951-.3586c.0075-.5028 1.2797-.4727 1.41-.432 0 0 .0401.5705-.7149.7906zm.2114-3.1717c-1.0921-.0102-1.6028.6179-1.6028.6179-.3316.3517-.119.828.2063.8624.4674.0494.4626-.3423 1.18-.516.6294-.1523.6566.4307.6566.4307-2.6842-.0667-2.556 2.1857-1.6423 2.6641.8763.4587 1.6953-.12 1.6953-.12s.0308.3117.4643.3117c.4961 0 .4954-.4951.4954-.4951l-.002-2.1924c-.0327-1.604-1.4508-1.5633-1.4508-1.5633z" fill="#204256"/><path d="m31.1779 13.8362-1.0943-1.6471.8043-.7605s.3712-.3436.0664-.6842c-.3377-.3772-.7404-.0048-.7404-.0048l-1.0106.9388v-1.88444c0-.27002-.2188-.48872-.4887-.48872-.2702 0-.489.2187-.489.48872v4.43424c0 .2699.2188.4887.489.4887.2699 0 .4887-.2188.4887-.4887v-1.1805l.1849-.1847.99 1.5516s.3227.5387.798.1959c.3573-.2578.0017-.7743.0017-.7743z" fill="#204256"/><path d="m27.6864 12.0341c0-1.6017-1.3352-1.8274-2.2431-1.3193-.0007.0006-.0016.0024-.002.0029-.0683-.1949-.2519-.3357-.4702-.3357-.2759 0-.4997.2238-.4997.4999v3.3396c0 .2761.2238.4999.4997.4999.2761 0 .4999-.2238.4999-.4999l-.0069-2.2531s.1212-.1443.3158-.2824c.4675-.3314.9132-.2185.9132.3479l.0114 2.1957c0 .2719.2201.4918.4918.4918.2715 0 .4916-.2199.4916-.4918z" fill="#204256"/><path d="m13.317 14.7856c.1145-.1913.1344-.326.1344-.326l-1.1287-2.9503s-.2048-.5708.2465-.7399c.4782-.1794.6508.2773.6867.3731.0359.0957.7131 1.899.7131 1.899l.652-1.8949s.1868-.5891.7091-.379c.4315.1737.2098.7516.2098.7516s-.6672 1.9744-1.2266 3.4067c-.3341.8558-.6194.9402-.9454 1.0204-.4363.1074-1.2612.0542-1.2612-.4883 0-.4279.4381-.4546.6357-.4482.0106.0002.4191.0356.5746-.2242z" fill="#1cb9de"/><path d="m10.6955 9.82625-1.03174 2.84675-1.12477-2.82943s-.16669-.53638-.63567-.53638c-.5434 0-.52567.43043-.5379.53638-.01223.10603 0 4.42453 0 4.42453s-.0055.4534.49307.4534c.50941 0 .48495-.4574.48901-.4574.00407 0 0-2.2798 0-2.2798l.82725 2.2798s.1222.4482.5053.44c.38305-.008.49305-.44.49305-.44l.6928-2.2757v2.2757s0 .4574.5012.4574c.4849 0 .4849-.4574.4849-.4574l.0007-4.41643s0-.54048-.5263-.53789c-.4365.00205-.6024.4205-.6309.51647-.0033.0112-.0048.01732-.0048.01732z" fill="#1cb9de"/><path d="m31.3388 16.4653h-8.708l-6.3938-.0011.0044.0071c-1.2638 1.4809-3.1409 2.4227-5.2405 2.4227-3.80662 0-6.89247-3.0861-6.89247-6.8927 0-3.80669 3.08585-6.89254 6.89247-6.89254 2.1087 0 3.9947.94719 5.2587 2.43893h1.384c-1.4362-2.13813-3.8733-3.54769-6.6427-3.54769-4.41861 0-8.0009 3.58233-8.0009 8.0013 0 4.4189 3.58229 8.0012 8.0009 8.0012 2.3181 0 4.4013-.9896 5.8617-2.5653l13.8203-.0138z" fill="#1cb9de"/><path d="m18.6571 13.7552h-1.3908v-1.3257h1.3908c.3364.0173.663.1885.663.6629 0 .4872-.297.6628-.663.6628zm-1.3908-3.4015h1.2964c.2597.0067.5322.1452.5322.5323 0 .4034-.2383.5323-.5322.5323h-1.2964zm2.4866 1.4663c.0264-.0364.3591-.3059.3328-1.0226-.053-1.45095-1.3131-1.43441-1.592-1.44287-.4493-.0135-.7198-.00808-1.5445 0-.6964.0069-.6913.63978-.6913.63978v4.72709h2.3473c1.2561 0 1.7234-.6915 1.7234-1.6583 0-.9727-.5757-1.2431-.5757-1.2431z" fill="#204256"/></g></svg>
includes/mollie-api-php/.gitattributes ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ /.github export-ignore
2
+ /tests export-ignore
3
+ /.gitattributes export-ignore
4
+ /.gitignore export-ignore
5
+ /.travis.yml export-ignore
6
+ /Makefile export-ignore
7
+ /phpunit.xml export-ignore
8
+ /scoper.inc.php export-ignore
includes/mollie-api-php/.github/ISSUE_TEMPLATE.md ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ ## Specifications
2
+
3
+ - API Version:
4
+
5
+ ## Describe the issue
6
+
7
+ ...
8
+
includes/mollie-api-php/.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ /.idea
2
+ /build
3
+ /vendor
4
+ /composer.lock
5
+ .DS_Store
6
+ composer.phar
7
+ php-scoper.phar
8
+ php-scoper.phar.pubkey
includes/mollie-api-php/.travis.yml ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ language: php
2
+
3
+ dist: xenial
4
+
5
+ matrix:
6
+ fast_finish: true
7
+ allow_failures:
8
+ - php: nightly
9
+ include:
10
+ - php: 5.6
11
+ - php: 7.0
12
+ - php: 7.1
13
+ - php: 7.2
14
+ - php: 7.3
15
+ - php: nightly
16
+
17
+ sudo: false
18
+
19
+ cache:
20
+ directories:
21
+ - "$HOME/.composer/cache"
22
+
23
+ env:
24
+ - COMPOSER_NO_INTERACTION=1
25
+
26
+ install:
27
+ - travis_retry composer install --no-scripts --no-suggest
28
+
29
+ script:
30
+ - composer validate --strict
31
+ - find src examples tests -name '*.php' | xargs -n 1 -P4 php -l
32
+ - vendor/bin/phpunit
33
+
34
+ before_deploy:
35
+ - sed -i "/const CLIENT_VERSION/c\\ const CLIENT_VERSION = '${TRAVIS_TAG:1}';" src/MollieApiClient.php
36
+ - make mollie-api-php.zip
37
+
38
+ deploy:
39
+ provider: releases
40
+ api_key:
41
+ secure: oXVzXjLkVfr7+5leMbIHQnLDg1o9/ldG6qdJ/GtwumZJYiit9h7VBYpxRvQGgXUESzhDlBf2jCLKxqxW+P2/PwG738/rSJVjLvbtbyFRz+pvk4o8rm3U7IKRv87BFhIvhaO9HcgvmyHbPMzGKRdAsWYWGQf/dg9N77xeDZ9++80=
42
+ file: mollie-api-php.zip
43
+ skip_cleanup: true
44
+ on:
45
+ tags: true
46
+ php: 7.2
includes/mollie-api-php/Makefile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # This automatically creates a fresh build for distribution with other modules or for getting started with Mollie
3
+ # without composer.
4
+ #
5
+ mollie-api-php.zip: php-scoper.phar
6
+ rm -rf build/*
7
+
8
+ #
9
+ # First, install all dependencies. Then prefix everything with humbug/php-scoper. Finally, we should dump the
10
+ # autoloader again to update the autoloader with the new classnames.
11
+ #
12
+ composer install --no-dev --no-scripts --no-suggest
13
+ php php-scoper.phar add-prefix --force
14
+ composer dump-autoload --working-dir build --classmap-authoritative
15
+
16
+ #
17
+ # Now move the autoload files. We have to use the scoper one to load the aliasses but we want to load the normal
18
+ # filename. Flip them around.
19
+ #
20
+ mv build/vendor/autoload.php build/vendor/composer-autoload.php
21
+ sed -i 's/autoload.php/composer-autoload.php/g' build/vendor/scoper-autoload.php
22
+ mv build/vendor/scoper-autoload.php build/vendor/autoload.php
23
+
24
+ #
25
+ # Finally, create a zip file with all built files.
26
+ #
27
+ cd build; zip -r ../mollie-api-php.zip examples src vendor composer.json LICENSE README.md
28
+
29
+ php-scoper.phar:
30
+ wget -q https://github.com/humbug/php-scoper/releases/download/0.9.2/php-scoper.phar
31
+ wget -q https://github.com/humbug/php-scoper/releases/download/0.9.2/php-scoper.phar.pubkey
includes/mollie-api-php/composer.json ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "mollie/mollie-api-php",
3
+ "description": "Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.",
4
+ "keywords": [
5
+ "mollie",
6
+ "payment",
7
+ "service",
8
+ "ideal",
9
+ "creditcard",
10
+ "apple pay",
11
+ "mistercash",
12
+ "bancontact",
13
+ "sofort",
14
+ "sofortbanking",
15
+ "sepa",
16
+ "paypal",
17
+ "paysafecard",
18
+ "podiumcadeaukaart",
19
+ "przelewy24",
20
+ "banktransfer",
21
+ "direct debit",
22
+ "belfius",
23
+ "belfius direct net",
24
+ "refunds",
25
+ "api",
26
+ "payments",
27
+ "gateway",
28
+ "subscriptions",
29
+ "recurring",
30
+ "charges",
31
+ "kbc",
32
+ "cbc",
33
+ "gift cards",
34
+ "intersolve",
35
+ "fashioncheque",
36
+ "inghomepay",
37
+ "klarna",
38
+ "paylater",
39
+ "sliceit"
40
+ ],
41
+ "homepage": "https://www.mollie.com/en/developers",
42
+ "license": "BSD-2-Clause",
43
+ "authors": [
44
+ {
45
+ "name": "Mollie B.V.",
46
+ "email": "info@mollie.com"
47
+ }
48
+ ],
49
+ "require": {
50
+ "php": ">=5.6",
51
+ "ext-curl": "*",
52
+ "ext-json": "*",
53
+ "ext-openssl": "*",
54
+ "composer/ca-bundle": "^1.1",
55
+ "guzzlehttp/guzzle": "^6.3"
56
+ },
57
+ "require-dev": {
58
+ "eloquent/liberator": "^2.0",
59
+ "phpunit/phpunit": "^5.7 || ^6.5 || ^7.1"
60
+ },
61
+ "suggest": {
62
+ "mollie/oauth2-mollie-php": "Use OAuth to authenticate with the Mollie API. This is needed for some endpoints. Visit https://docs.mollie.com/ for more information."
63
+ },
64
+ "config": {
65
+ "sort-packages": true
66
+ },
67
+ "autoload": {
68
+ "psr-4": {
69
+ "Mollie\\Api\\": "src/"
70
+ }
71
+ },
72
+ "autoload-dev": {
73
+ "psr-4": {
74
+ "Tests\\": "tests"
75
+ }
76
+ },
77
+ "scripts": {
78
+ "test": "./vendor/bin/phpunit tests"
79
+ }
80
+ }
includes/mollie-api-php/examples/captures/get-capture.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Retrieve a payment capture using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Retrieve a capture with ID 'cpt_4qqhO89gsT' for payment with
14
+ * ID 'tr_WDqYK6vllg'.
15
+ *
16
+ * See: https://docs.mollie.com/reference/v2/captures-api/get-capture
17
+ */
18
+
19
+ $payment = $mollie->payments->get('tr_WDqYK6vllg');
20
+ $capture = $payment->getCapture('cpt_4qqhO89gsT');
21
+
22
+ $amount = $capture->amount->currency . ' ' . $capture->amount->value;
23
+
24
+ echo 'Captured ' . $amount;
25
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
26
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
27
+ }
includes/mollie-api-php/examples/captures/list-captures.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * List captures for a payment using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * List captures for payment with ID 'tr_WDqYK6vllg'.
14
+ *
15
+ * See: https://docs.mollie.com/reference/v2/captures-api/list-captures
16
+ */
17
+
18
+ $payment = $mollie->payments->get('tr_WDqYK6vllg');
19
+ $captures = $payment->captures();
20
+
21
+ foreach ($captures as $capture) {
22
+ $amount = $capture->amount->currency . ' ' . $capture->amount->value;
23
+ echo 'Captured ' . $amount . ' for payment ' . $payment->id;
24
+ }
25
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
26
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
27
+ }
includes/mollie-api-php/examples/customers/create-customer-first-payment.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to create a first payment to allow recurring payments later.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Retrieve the last created customer for this example.
14
+ * If no customers are created yet, run the create-customer example.
15
+ */
16
+ $customer = $mollie->customers->page(null, 1)[0];
17
+
18
+ /*
19
+ * Generate a unique order id for this example. It is important to include this unique attribute
20
+ * in the redirectUrl (below) so a proper return page can be shown to the customer.
21
+ */
22
+ $orderId = time();
23
+
24
+ /*
25
+ * Determine the url parts to these example files.
26
+ */
27
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
28
+ $hostname = $_SERVER['HTTP_HOST'];
29
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
30
+
31
+ /**
32
+ * Customer Payment creation parameters.
33
+ *
34
+ * @See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment
35
+ */
36
+ $payment = $customer->createPayment([
37
+ "amount" => [
38
+ "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings
39
+ "currency" => "EUR"
40
+ ],
41
+ "description" => "First payment - Order #{$orderId}",
42
+ "redirectUrl" => "{$protocol}://{$hostname}{$path}/payments/return.php?order_id={$orderId}",
43
+ "webhookUrl" => "{$protocol}://{$hostname}{$path}/payments/webhook.php",
44
+ "metadata" => [
45
+ "order_id" => $orderId,
46
+ ],
47
+
48
+ // Flag this payment as a first payment to allow recurring payments later.
49
+ "sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST,
50
+ ]);
51
+
52
+ /*
53
+ * In this example we store the order with its payment status in a database.
54
+ */
55
+ database_write($orderId, $payment->status);
56
+
57
+ /*
58
+ * Send the customer off to complete the payment.
59
+ * This request should always be a GET, thus we enforce 303 http response code
60
+ *
61
+ * After completion, the customer will have a pending or valid mandate that can be
62
+ * used for recurring payments and subscriptions.
63
+ */
64
+ header("Location: " . $payment->getCheckoutUrl(), true, 303);
65
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
66
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
67
+ }
includes/mollie-api-php/examples/customers/create-customer-payment.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to create a new customer in the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Retrieve the last created customer for this example.
14
+ * If no customers are created yet, run create-customer example.
15
+ */
16
+ $customer = $mollie->customers->page(null, 1)[0];
17
+
18
+ /*
19
+ * Generate a unique order id for this example. It is important to include this unique attribute
20
+ * in the redirectUrl (below) so a proper return page can be shown to the customer.
21
+ */
22
+ $orderId = time();
23
+
24
+ /*
25
+ * Determine the url parts to these example files.
26
+ */
27
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
28
+ $hostname = $_SERVER['HTTP_HOST'];
29
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
30
+
31
+ /**
32
+ * Linking customers to payments has a few benefits
33
+ *
34
+ * @see https://docs.mollie.com/reference/v2/customers-api/create-customer-payment
35
+ */
36
+ $payment = $customer->createPayment([
37
+ "amount" => [
38
+ "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings
39
+ "currency" => "EUR"
40
+ ],
41
+ "description" => "Order #{$orderId}",
42
+ "redirectUrl" => "{$protocol}://{$hostname}{$path}/payments/return.php?order_id={$orderId}",
43
+ "webhookUrl" => "{$protocol}://{$hostname}{$path}/payments/webhook.php",
44
+ "metadata" => [
45
+ "order_id" => $orderId,
46
+ ]
47
+ ]);
48
+
49
+ /*
50
+ * In this example we store the order with its payment status in a database.
51
+ */
52
+ database_write($orderId, $payment->status);
53
+
54
+ /*
55
+ * Send the customer off to complete the payment.
56
+ * This request should always be a GET, thus we enforce 303 http response code
57
+ */
58
+ header("Location: " . $payment->getCheckoutUrl(), true, 303);
59
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
60
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
61
+ }
includes/mollie-api-php/examples/customers/create-customer-recurring-payment.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to create an on-demand recurring payment.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Retrieve the last created customer for this example.
14
+ * If no customers are created yet, run the create-customer example.
15
+ */
16
+ $customer = $mollie->customers->page(null, 1)[0];
17
+
18
+ /*
19
+ * Generate a unique order id for this example.
20
+ */
21
+ $orderId = time();
22
+
23
+ /*
24
+ * Determine the url parts to these example files.
25
+ */
26
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
27
+ $hostname = $_SERVER['HTTP_HOST'];
28
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
29
+
30
+ /**
31
+ * Customer Payment creation parameters.
32
+ *
33
+ * @See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment
34
+ */
35
+ $payment = $customer->createPayment([
36
+ "amount" => [
37
+ "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings
38
+ "currency" => "EUR"
39
+ ],
40
+ "description" => "On-demand payment - Order #{$orderId}",
41
+ "webhookUrl" => "{$protocol}://{$hostname}{$path}/payments/webhook.php",
42
+ "metadata" => [
43
+ "order_id" => $orderId,
44
+ ],
45
+
46
+ // Flag this payment as a recurring payment.
47
+ "sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_RECURRING,
48
+ ]);
49
+
50
+ /*
51
+ * In this example we store the order with its payment status in a database.
52
+ */
53
+ database_write($orderId, $payment->status);
54
+
55
+ /*
56
+ * The payment will be either pending or paid immediately. The customer
57
+ * does not have to perform any payment steps.
58
+ */
59
+ echo "<p>Selected mandate is '" . htmlspecialchars($payment->mandateId) . "' (" . htmlspecialchars($payment->method) . ").</p>\n";
60
+ echo "<p>The payment status is '" . htmlspecialchars($payment->status) . "'.</p>\n";
61
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
62
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
63
+ }
includes/mollie-api-php/examples/customers/create-customer.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to create a new customer in the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /**
13
+ * Customer creation parameters.
14
+ *
15
+ * @See https://docs.mollie.com/reference/v2/customers-api/create-customer
16
+ */
17
+ $customer = $mollie->customers->create([
18
+ "name" => "Luke Skywalker",
19
+ "email" => "luke@example.org",
20
+ "metadata" => [
21
+ "isJedi" => TRUE,
22
+ ],
23
+ ]);
24
+ echo "<p>New customer created " . htmlspecialchars($customer->id) . " (" . htmlspecialchars($customer->name) . ").</p>";
25
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
26
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
27
+ }
includes/mollie-api-php/examples/customers/delete-customer.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Delete a customer from the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ $mollie->customers->delete("cst_fE3F6nvX");
13
+ echo "<p>Customer deleted!</p>";
14
+
15
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
16
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
17
+ }
includes/mollie-api-php/examples/customers/list-customer-payments.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to retrieve your customers' payments history.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key.
9
+ *
10
+ * See: https://www.mollie.com/dashboard/developers/api-keys
11
+ */
12
+ require "../initialize.php";
13
+
14
+ /*
15
+ * Determine the url parts to these example files.
16
+ */
17
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
18
+ $hostname = $_SERVER['HTTP_HOST'];
19
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
20
+
21
+ /*
22
+ * Retrieve the last created customer for this example.
23
+ * If no customers are created yet, run create-customer example.
24
+ */
25
+ $customer = $mollie->customers->page(null, 1)[0];
26
+
27
+ /*
28
+ * Get the all payments for this API key ordered by newest.
29
+ */
30
+ $payments = $customer->payments();
31
+
32
+ echo "<ul>";
33
+ foreach ($payments as $payment) {
34
+ echo "<li>";
35
+ echo "<strong style='font-family: monospace'>" . htmlspecialchars($payment->id) . "</strong><br />";
36
+ echo htmlspecialchars($payment->description) . "<br />";
37
+ echo htmlspecialchars($payment->amount->currency) . " " . htmlspecialchars($payment->amount->value) . "<br />";
38
+
39
+ echo "Status: " . htmlspecialchars($payment->status) . "<br />";
40
+
41
+ if ($payment->hasRefunds()) {
42
+ echo "Payment has been (partially) refunded.<br />";
43
+ }
44
+
45
+ if ($payment->hasChargebacks()) {
46
+ echo "Payment has been charged back.<br />";
47
+ }
48
+
49
+ if ($payment->canBeRefunded() && $payment->amountRemaining->currency === 'EUR' && $payment->amountRemaining->value >= '2.00') {
50
+ echo " (<a href=\"{$protocol}://{$hostname}{$path}/payments/refund-payment.php?payment_id=" . htmlspecialchars($payment->id) . "\">refund</a>)";
51
+ }
52
+
53
+ echo "</li>";
54
+ }
55
+ echo "</ul>";
56
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
57
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
58
+ }
includes/mollie-api-php/examples/customers/update-customer.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Updating an existing customer via the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Retrieve an existing customer by his customerId
14
+ */
15
+ $customer = $mollie->customers->get("cst_cUe8HjeBuz");
16
+
17
+ /**
18
+ * Customer fields that can be updated.
19
+ *
20
+ * @See https://docs.mollie.com/reference/v2/customers-api/update-customer
21
+ */
22
+ $customer->name = "Luke Sky";
23
+ $customer->email = "luke@example.org";
24
+ $customer->locale = "en_US";
25
+ $customer->metadata->isJedi = TRUE;
26
+ $customer->update();
27
+
28
+ echo "<p>Customer updated: " . htmlspecialchars($customer->name) . "</p>";
29
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
30
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
31
+ }
includes/mollie-api-php/examples/database/.gitignore ADDED
@@ -0,0 +1 @@
 
1
+ *.txt
includes/mollie-api-php/examples/functions.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * NOTE: The examples are using a text file as a database.
4
+ * Please use a real database like MySQL in production code.
5
+ */
6
+
7
+ function database_read($orderId)
8
+ {
9
+ $orderId = intval($orderId);
10
+ $database = dirname(__FILE__) . "/database/order-{$orderId}.txt";
11
+
12
+ $status = @file_get_contents($database);
13
+
14
+ return $status ? $status : "unknown order";
15
+ }
16
+
17
+ function database_write($orderId, $status)
18
+ {
19
+ $orderId = intval($orderId);
20
+ $database = dirname(__FILE__) . "/database/order-{$orderId}.txt";
21
+
22
+ file_put_contents($database, $status);
23
+ }
includes/mollie-api-php/examples/initialize.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Make sure to disable the display of errors in production code!
4
+ */
5
+ ini_set('display_errors', 1);
6
+ ini_set('display_startup_errors', 1);
7
+ error_reporting(E_ALL);
8
+
9
+ require_once __DIR__ . "/../vendor/autoload.php";
10
+ require_once __DIR__ . "/functions.php";
11
+
12
+ /*
13
+ * Initialize the Mollie API library with your API key.
14
+ *
15
+ * See: https://www.mollie.com/dashboard/developers/api-keys
16
+ */
17
+ $mollie = new \Mollie\Api\MollieApiClient();
18
+ $mollie->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM");
includes/mollie-api-php/examples/initialize_with_oauth.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * Make sure to disable the display of errors in production code!
5
+ */
6
+ ini_set('display_errors', 1);
7
+ ini_set('display_startup_errors', 1);
8
+ error_reporting(E_ALL);
9
+
10
+ require_once __DIR__ . "/../vendor/autoload.php";
11
+ require_once __DIR__ . "/functions.php";
12
+
13
+ /*
14
+ * Initialize the Mollie API library with OAuth.
15
+ *
16
+ * See: https://docs.mollie.com/oauth/overview
17
+ */
18
+ $mollie = new \Mollie\Api\MollieApiClient();
19
+ $mollie->setAccessToken("access_Wwvu7egPcJLLJ9Kb7J632x8wJ2zMeJ");
includes/mollie-api-php/examples/invoices/list-invoices.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * List the Mollie invoices.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize_with_oauth.php";
11
+
12
+ /*
13
+ * Get all the activated methods for this API key.
14
+ */
15
+ $invoices = $mollie->invoices->all();
16
+ foreach ($invoices as $invoice) {
17
+ echo '<li><b>Invoice ' . htmlspecialchars($invoice->reference) . ':</b> (' . htmlspecialchars($invoice->issuedAt) . ')';
18
+ echo '<br>Status: <b>' . $invoice->status;
19
+ echo '<table border="1"><tr><th>Period</th><th>Description</th><th>Count</th><th>VAT Percentage</th><th>Amount</th></tr>';
20
+ foreach ($invoice->lines as $line) {
21
+ echo '<tr>';
22
+ echo '<td>' . htmlspecialchars($line->period) . '</td>';
23
+ echo '<td>' . htmlspecialchars($line->description) . '</td>';
24
+ echo '<td align="right">' . htmlspecialchars($line->count) . '</td>';
25
+ echo '<td align="right">' . htmlspecialchars($line->vatPercentage) . '</td>';
26
+ echo '<td align="right">' . htmlspecialchars($line->amount->currency . " " . $line->amount->value) . '</td>';
27
+ echo '</tr>';
28
+ }
29
+ echo '<tr><th colspan="5" align="right">Gross Total</th><th align="right">' . htmlspecialchars($invoice->grossAmount->value . " " . $invoice->grossAmount->currency) . '</th></tr>';
30
+ echo '</table>';
31
+ echo '<a href="'. $invoice->_links->pdf->href .'" target="_blank">Click here to open PDF</a>';
32
+ echo '</li>';
33
+ }
34
+
35
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
36
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
37
+ }
includes/mollie-api-php/examples/mandates/create-mandate.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Create a customer mandate via the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Retrieve the last created customer for this example.
14
+ * If no customers are created yet, run create-customer example.
15
+ */
16
+ $customer = $mollie->customers->page(null, 1)[0];
17
+
18
+ /*
19
+ * Create a SEPA Direct Debit mandate for the customer
20
+ */
21
+ $mandate = $customer->createMandate([
22
+ "method" => \Mollie\Api\Types\MandateMethod::DIRECTDEBIT,
23
+ "consumerAccount" => 'NL34ABNA0243341423',
24
+ "consumerName" => 'B. A. Example',
25
+ ]);
26
+
27
+ echo "<p>Mandate created with id " . $mandate->id . " for customer " . $customer->name . "</p>";
28
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
29
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
30
+ }
includes/mollie-api-php/examples/mandates/list-mandates.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * List all customer mandates
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Retrieve an existing customer by his customerId
14
+ */
15
+ $customer = $mollie->customers->get("cst_cUa8HjKBus");
16
+
17
+ /*
18
+ * List the mandates of this customer
19
+ */
20
+ echo "<ul>";
21
+ foreach ($customer->mandates() as $mandate) {
22
+ echo "<li>" . htmlspecialchars($mandate->id) . " - " . htmlspecialchars($mandate->method) . ": " . htmlspecialchars($mandate->status) . "</li>";
23
+ }
24
+ echo "</ul>";
25
+
26
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
27
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
28
+ }
includes/mollie-api-php/examples/mandates/revoke-mandate.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Revoke a customer mandate
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Retrieve an existing customer by his customerId
14
+ */
15
+ $customer = $mollie->customers->get("cst_cUa8HjKBus");
16
+
17
+ /*
18
+ * Retrieve an existing mandate by his mandateId
19
+ */
20
+ $mandate = $customer->getMandate("mdt_pa3s7rGnrC");
21
+
22
+ /*
23
+ * Revoke the mandate
24
+ */
25
+ $mandate->revoke();
26
+
27
+ echo "<p>Mandate has been successfully revoked.</p>";
28
+
29
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
30
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
31
+ }
includes/mollie-api-php/examples/orders/cancel-order-lines.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Cancel order lines using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Cancel an order line with ID "odl_dgtxyl" for order ID "ord_8wmqcHMN4U"
14
+ *
15
+ * See: https://docs.mollie.com/reference/v2/orders-api/cancel-order-line
16
+ */
17
+
18
+ $orderId = 'ord_8wmqcHMN4U';
19
+ $lineId = 'odl_dgtxyl';
20
+
21
+ $order = $mollie->orders->get($orderId);
22
+ $line = $order->lines()->get($lineId);
23
+ if ($line && $line->isCancelable) {
24
+ $order->cancelLines([
25
+ 'lines' => [
26
+ [
27
+ 'id' => $lineId,
28
+ 'quantity' => 1, // optional parameter
29
+ ]
30
+ ],
31
+ ]);
32
+
33
+ $updatedOrder = $mollie->orders->get($orderId);
34
+
35
+ echo 'Your order ' . $order->id . ' was updated:';
36
+ foreach ($order->lines as $line) {
37
+ echo $line->description . '. Status: <b>' . $line->status . '</b>.';
38
+ }
39
+ } else {
40
+ echo "Unable to cancel line " . $lineId . " for your order " . $orderId . ".";
41
+ }
42
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
43
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
44
+ }
includes/mollie-api-php/examples/orders/cancel-order.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Cancel an order using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Cancel the order with ID "ord_pbjz8x"
14
+ *
15
+ * See: https://docs.mollie.com/reference/v2/orders-api/cancel-order
16
+ */
17
+ $order = $mollie->orders->get("ord_pbjz8x");
18
+ if ($order->isCancelable) {
19
+ $canceledOrder = $order->cancel();
20
+ echo "Your order " . $order->id . " has been canceled.";
21
+ } else {
22
+ echo "Unable to cancel your order " . $order->id . ".";
23
+ }
24
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
25
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
26
+ }
includes/mollie-api-php/examples/orders/create-order.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to create a new order in the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Generate a unique order id for this example. It is important to include this unique attribute
14
+ * in the redirectUrl (below) so a proper return page can be shown to the customer.
15
+ */
16
+ $orderId = time();
17
+
18
+ /*
19
+ * Determine the url parts to these example files.
20
+ */
21
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
22
+ $hostname = $_SERVER['HTTP_HOST'];
23
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
24
+
25
+ /*
26
+ * Order creation parameters.
27
+ *
28
+ * See: https://docs.mollie.com/reference/v2/orders-api/create-order
29
+ */
30
+ $order = $mollie->orders->create([
31
+ "amount" => [
32
+ "value" => "1027.99",
33
+ "currency" => "EUR"
34
+ ],
35
+ "billingAddress" => [
36
+ "streetAndNumber" => "Keizersgracht 313",
37
+ "postalCode" => "1016 EE",
38
+ "city" => "Amsterdam",
39
+ "country" => "nl",
40
+ "givenName" => "Luke",
41
+ "familyName" => "Skywalker",
42
+ "email" => "luke@skywalker.com",
43
+ ],
44
+ "shippingAddress" => [
45
+ "streetAndNumber" => "Keizersgracht 313",
46
+ "postalCode" => "1016 EE",
47
+ "city" => "Amsterdam",
48
+ "country" => "nl",
49
+ "givenName" => "Luke",
50
+ "familyName" => "Skywalker",
51
+ "email" => "luke@skywalker.com",
52
+ ],
53
+ "metadata" => [
54
+ "order_id" => $orderId
55
+ ],
56
+ "consumerDateOfBirth" => "1958-01-31",
57
+ "locale" => "en_US",
58
+ "orderNumber" => strval($orderId),
59
+ "redirectUrl" => "{$protocol}://{$hostname}{$path}/orders/return.php?order_id={$orderId}",
60
+ "webhookUrl" => "{$protocol}://{$hostname}{$path}/orders/webhook.php",
61
+ "method" => "ideal",
62
+ "lines" => [
63
+ [
64
+ "sku" => "5702016116977",
65
+ "name" => "LEGO 42083 Bugatti Chiron",
66
+ "productUrl" => "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
67
+ "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$',
68
+ "quantity" => 2,
69
+ "vatRate" => "21.00",
70
+ "unitPrice" => [
71
+ "currency" => "EUR",
72
+ "value" => "399.00"
73
+ ],
74
+ "totalAmount" => [
75
+ "currency" => "EUR",
76
+ "value" => "698.00"
77
+ ],
78
+ "discountAmount" => [
79
+ "currency" => "EUR",
80
+ "value" => "100.00"
81
+ ],
82
+ "vatAmount" => [
83
+ "currency" => "EUR",
84
+ "value" => "121.14"
85
+ ]
86
+ ],
87
+ [
88
+ "type" => "digital",
89
+ "sku" => "5702015594028",
90
+ "name" => "LEGO 42056 Porsche 911 GT3 RS",
91
+ "productUrl" => "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
92
+ "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$',
93
+ "quantity" => 1,
94
+ "vatRate" => "21.00",
95
+ "unitPrice" => [
96
+ "currency" => "EUR",
97
+ "value" => "329.99"
98
+ ],
99
+ "totalAmount" => [
100
+ "currency" => "EUR",
101
+ "value" => "329.99"
102
+ ],
103
+ "vatAmount" => [
104
+ "currency" => "EUR",
105
+ "value" => "57.27"
106
+ ]
107
+ ]
108
+ ]
109
+ ]);
110
+
111
+ /*
112
+ * Send the customer off to complete the order payment.
113
+ * This request should always be a GET, thus we enforce 303 http response code
114
+ */
115
+ header("Location: " . $order->getCheckoutUrl(), true, 303);
116
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
117
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
118
+ }
includes/mollie-api-php/examples/orders/list-methods.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to get the currently activated payment methods for the Orders API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key.
9
+ *
10
+ * See: https://www.mollie.com/dashboard/developers/api-keys
11
+ */
12
+ require "../initialize.php";
13
+
14
+ /*
15
+ * Get all the activated methods for this API key.
16
+ * To get methods that are compatible with the Orders API
17
+ * we are passing the 'resource' parameter.
18
+ */
19
+ $methods = $mollie->methods->all(['resource' => 'orders']);
20
+ foreach ($methods as $method) {
21
+ echo '<div style="line-height:40px; vertical-align:top">';
22
+ echo '<img src="' . htmlspecialchars($method->image->size1x) . '" srcset="' . htmlspecialchars($method->image->size2x) . ' 2x"> ';
23
+ echo htmlspecialchars($method->description) . ' (' . htmlspecialchars($method->id) . ')';
24
+ echo '</div>';
25
+ }
26
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
27
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
28
+ }
includes/mollie-api-php/examples/orders/list-orders.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * List orders using the Mollie API.
4
+ */
5
+
6
+ use Mollie\Api\Resources\OrderCollection;
7
+
8
+ try {
9
+ /*
10
+ * Initialize the Mollie API library with your API key or OAuth access token.
11
+ */
12
+ require "../initialize.php";
13
+
14
+ /*
15
+ * List the most recent orders
16
+ *
17
+ * See: https://docs.mollie.com/reference/v2/orders-api/list-orders
18
+ */
19
+ echo '<ul>';
20
+ $latestOrders = $mollie->orders->page();
21
+ printOrders($latestOrders);
22
+
23
+ $previousOrders = $latestOrders->next();
24
+ printOrders($previousOrders);
25
+ echo '</ul>';
26
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
27
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
28
+ }
29
+
30
+ function printOrders($orders)
31
+ {
32
+ if (empty($orders)) {
33
+ return ;
34
+ }
35
+
36
+ foreach ($orders as $order) {
37
+ echo '<li><b>Order ' . htmlspecialchars($order->id) . ':</b> (' . htmlspecialchars($order->createdAt) . ')';
38
+ echo '<br>Status: <b>' . htmlspecialchars($order->status);
39
+ echo '<table border="1"><tr><th>Billed to</th><th>Shipped to</th><th>Total amount</th></tr>';
40
+ echo '<tr>';
41
+ echo '<td>' . htmlspecialchars($order->shippingAddress->givenName) . ' ' . htmlspecialchars($order->shippingAddress->familyName) . '</td>';
42
+ echo '<td>' . htmlspecialchars($order->billingAddress->givenName) . ' ' . htmlspecialchars($order->billingAddress->familyName) . '</td>';
43
+ echo '<td>' . htmlspecialchars($order->amount->currency) . str_replace('.', ',', htmlspecialchars($order->amount->value)) . '</td>';
44
+ echo '</tr>';
45
+ echo '</table>';
46
+ echo '<a href="'. $order->getCheckoutUrl() .'" target="_blank">Click here to pay</a>';
47
+ echo '</li>';
48
+ }
49
+ }
includes/mollie-api-php/examples/orders/refund-order-completely.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Refund all eligible items for an order using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Refund all eligible items for an order with ID "ord_8wmqcHMN4U".
14
+ *
15
+ * See: https://docs.mollie.com/reference/v2/orders-api/create-order-refund
16
+ */
17
+
18
+ $order = $mollie->orders->get('ord_8wmqcHMN4U');
19
+ $refund = $order->refundAll();
20
+
21
+ echo 'Refund ' . $refund->id . ' was created for order ' . $order->id;
22
+ echo 'You will receive ' . $refund->amount->currency . $refund->amount->value;
23
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
24
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
25
+ }
includes/mollie-api-php/examples/orders/refund-order-partially.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Refund some items for an order using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Refund 1 item of order line "odl_dgtxyl" for an order with ID "ord_8wmqcHMN4U".
14
+ *
15
+ * See: https://docs.mollie.com/reference/v2/orders-api/create-order-refund
16
+ */
17
+
18
+ $order = $mollie->orders->get('ord_8wmqcHMN4U');
19
+ $refund = $order->refund([
20
+ 'lines' => [
21
+ [
22
+ 'id' => 'odl_dgtxyl',
23
+ 'quantity' => 1,
24
+ ]
25
+ ],
26
+ "description" => "Required quantity not in stock, refunding one photo book.",
27
+ ]);
28
+
29
+ echo 'Refund ' . $refund->id . ' was created for part of your order ' . $order->id;
30
+ echo 'You will receive ' . $refund->amount->currency . $refund->amount->value;
31
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
32
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
33
+ }
includes/mollie-api-php/examples/orders/webhook.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Handle an order status change using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * After your webhook has been called with the order ID in its body, you'd like
14
+ * to handle the order's status change. This is how you can do that.
15
+ *
16
+ * See: https://docs.mollie.com/reference/v2/orders-api/get-order
17
+ */
18
+ $order = $mollie->orders->get($_POST["id"]);
19
+ $orderId = $order->metadata->order_id;
20
+
21
+ /*
22
+ * Update the order in the database.
23
+ */
24
+ database_write($orderId, $order->status);
25
+
26
+ if ($order->isPaid() || $order->isAuthorized()) {
27
+ /*
28
+ * The order is paid or authorized
29
+ * At this point you'd probably want to start the process of delivering the product to the customer.
30
+ */
31
+ } elseif ($order->isCanceled()) {
32
+ /*
33
+ * The order is canceled.
34
+ */
35
+ } elseif ($order->isExpired()) {
36
+ /*
37
+ * The order is expired.
38
+ */
39
+ } elseif ($order->isCompleted()) {
40
+ /*
41
+ * The order is completed.
42
+ */
43
+ } elseif ($order->isPending()) {
44
+ /*
45
+ * The order is pending.
46
+ */
47
+ }
48
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
49
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
50
+ }
includes/mollie-api-php/examples/payments/create-ideal-payment.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to prepare an iDEAL payment with the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key.
9
+ *
10
+ * See: https://www.mollie.com/dashboard/developers/api-keys
11
+ */
12
+ require "../initialize.php";
13
+
14
+ /*
15
+ * First, let the customer pick the bank in a simple HTML form. This step is actually optional.
16
+ */
17
+ if ($_SERVER["REQUEST_METHOD"] != "POST") {
18
+ $method = $mollie->methods->get(\Mollie\Api\Types\PaymentMethod::IDEAL, ["include" => "issuers"]);
19
+
20
+ echo '<form method="post">Select your bank: <select name="issuer">';
21
+
22
+ foreach ($method->issuers() as $issuer) {
23
+ echo '<option value=' . htmlspecialchars($issuer->id) . '>' . htmlspecialchars($issuer->name) . '</option>';
24
+ }
25
+
26
+ echo '<option value="">or select later</option>';
27
+ echo '</select><button>OK</button></form>';
28
+ exit;
29
+ }
30
+
31
+ /*
32
+ * Generate a unique order id for this example. It is important to include this unique attribute
33
+ * in the redirectUrl (below) so a proper return page can be shown to the customer.
34
+ */
35
+ $orderId = time();
36
+
37
+ /*
38
+ * Determine the url parts to these example files.
39
+ */
40
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
41
+ $hostname = $_SERVER['HTTP_HOST'];
42
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
43
+
44
+ /*
45
+ * Payment parameters:
46
+ * amount Amount in EUROs. This example creates a € 27.50 payment.
47
+ * method Payment method "ideal".
48
+ * description Description of the payment.
49
+ * redirectUrl Redirect location. The customer will be redirected there after the payment.
50
+ * webhookUrl Webhook location, used to report when the payment changes state.
51
+ * metadata Custom metadata that is stored with the payment.
52
+ * issuer The customer's bank. If empty the customer can select it later.
53
+ */
54
+ $payment = $mollie->payments->create([
55
+ "amount" => [
56
+ "currency" => "EUR",
57
+ "value" => "27.50" // You must send the correct number of decimals, thus we enforce the use of strings
58
+ ],
59
+ "method" => \Mollie\Api\Types\PaymentMethod::IDEAL,
60
+ "description" => "Order #{$orderId}",
61
+ "redirectUrl" => "{$protocol}://{$hostname}{$path}/payments/return.php?order_id={$orderId}",
62
+ "webhookUrl" => "{$protocol}://{$hostname}{$path}/payments/webhook.php",
63
+ "metadata" => [
64
+ "order_id" => $orderId,
65
+ ],
66
+ "issuer" => !empty($_POST["issuer"]) ? $_POST["issuer"] : null
67
+ ]);
68
+
69
+ /*
70
+ * In this example we store the order with its payment status in a database.
71
+ */
72
+ database_write($orderId, $payment->status);
73
+
74
+ /*
75
+ * Send the customer off to complete the payment.
76
+ * This request should always be a GET, thus we enforce 303 http response code
77
+ */
78
+ header("Location: " . $payment->getCheckoutUrl(), true, 303);
79
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
80
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
81
+ }
includes/mollie-api-php/examples/payments/create-payment-oauth.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Example 10 - Using OAuth access token to prepare a new payment.
4
+ */
5
+ try
6
+ {
7
+ /*
8
+ * Initialize the Mollie API library with your OAuth access token.
9
+ */
10
+ require "../initialize_with_oauth.php";
11
+ /*
12
+ * Generate a unique order id for this example. It is important to include this unique attribute
13
+ * in the redirectUrl (below) so a proper return page can be shown to the customer.
14
+ */
15
+ $orderId = time();
16
+ /*
17
+ * Determine the url parts to these example files.
18
+ */
19
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
20
+ $hostname = $_SERVER['HTTP_HOST'] ? : "my.app";
21
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
22
+ /*
23
+ * Since unlike an API key the OAuth access token does NOT belong to a profile, we need to retrieve a profile
24
+ * so we can specify the profileId-parameter when creating a payment below.
25
+ */
26
+ $profiles = $mollie->profiles->page();
27
+ $profile = reset($profiles);
28
+
29
+ /**
30
+ * Paramaters for creating a payment via oAuth
31
+ *
32
+ * @See https://docs.mollie.com/reference/v2/payments-api/create-payment
33
+ */
34
+ $payment = $mollie->payments->create([
35
+ "amount" => [
36
+ "value" => "10.00",
37
+ "currency" => "EUR"
38
+ ],
39
+ "description" => "My first API payment",
40
+ "redirectUrl" => "{$protocol}://{$hostname}{$path}/payments/return.php?order_id={$orderId}",
41
+ "webhookUrl" => "{$protocol}://{$hostname}{$path}/payments/webhook.php",
42
+ "metadata" => [
43
+ "order_id" => $orderId,
44
+ ],
45
+ "profileId" => $profile->id // This is specifically necessary for payment resources via OAuth access.
46
+ ]);
47
+
48
+ /*
49
+ * In this example we store the order with its payment status in a database.
50
+ */
51
+ database_write($orderId, $payment->status);
52
+
53
+ /*
54
+ * Send the customer off to complete the payment.
55
+ * This request should always be a GET, thus we enforce 303 http response code
56
+ */
57
+ if (PHP_SAPI === "cli")
58
+ {
59
+ echo "Redirect to: " . $payment->getCheckoutUrl() . PHP_EOL;
60
+ return;
61
+ }
62
+ header("Location: " . $payment->getCheckoutUrl(), true, 303);
63
+ }
64
+ catch (\Mollie\Api\Exceptions\ApiException $e)
65
+ {
66
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
67
+ }
includes/mollie-api-php/examples/payments/create-payment.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to prepare a new payment with the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key.
9
+ *
10
+ * See: https://www.mollie.com/dashboard/developers/api-keys
11
+ */
12
+ require "../initialize.php";
13
+
14
+ /*
15
+ * Generate a unique order id for this example. It is important to include this unique attribute
16
+ * in the redirectUrl (below) so a proper return page can be shown to the customer.
17
+ */
18
+ $orderId = time();
19
+
20
+ /*
21
+ * Determine the url parts to these example files.
22
+ */
23
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
24
+ $hostname = $_SERVER['HTTP_HOST'];
25
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
26
+
27
+ /*
28
+ * Payment parameters:
29
+ * amount Amount in EUROs. This example creates a € 10,- payment.
30
+ * description Description of the payment.
31
+ * redirectUrl Redirect location. The customer will be redirected there after the payment.
32
+ * webhookUrl Webhook location, used to report when the payment changes state.
33
+ * metadata Custom metadata that is stored with the payment.
34
+ */
35
+ $payment = $mollie->payments->create([
36
+ "amount" => [
37
+ "currency" => "EUR",
38
+ "value" => "10.00" // You must send the correct number of decimals, thus we enforce the use of strings
39
+ ],
40
+ "description" => "Order #{$orderId}",
41
+ "redirectUrl" => "{$protocol}://{$hostname}{$path}/payments/return.php?order_id={$orderId}",
42
+ "webhookUrl" => "{$protocol}://{$hostname}{$path}/payments/webhook.php",
43
+ "metadata" => [
44
+ "order_id" => $orderId,
45
+ ],
46
+ ]);
47
+
48
+ /*
49
+ * In this example we store the order with its payment status in a database.
50
+ */
51
+ database_write($orderId, $payment->status);
52
+
53
+ /*
54
+ * Send the customer off to complete the payment.
55
+ * This request should always be a GET, thus we enforce 303 http response code
56
+ */
57
+ header("Location: " . $payment->getCheckoutUrl(), true, 303);
58
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
59
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
60
+ }
includes/mollie-api-php/examples/payments/list-methods.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to get the currently activated payment methods for the Payments API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key.
9
+ *
10
+ * See: https://www.mollie.com/dashboard/developers/api-keys
11
+ */
12
+ require "../initialize.php";
13
+ /*
14
+ * Get all the activated methods for this API key.
15
+ * By default we are using the resource "payments".
16
+ * See the orders folder for an example with the Orders API.
17
+ */
18
+ $methods = $mollie->methods->all();
19
+ foreach ($methods as $method) {
20
+ echo '<div style="line-height:40px; vertical-align:top">';
21
+ echo '<img src="' . htmlspecialchars($method->image->size1x) . '" srcset="' . htmlspecialchars($method->image->size2x) . ' 2x"> ';
22
+ echo htmlspecialchars($method->description) . ' (' . htmlspecialchars($method->id) . ')';
23
+ echo '</div>';
24
+ }
25
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
26
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
27
+ }
includes/mollie-api-php/examples/payments/list-payments.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to list your payments.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key.
9
+ *
10
+ * See: https://www.mollie.com/dashboard/developers/api-keys
11
+ */
12
+ require "../initialize.php";
13
+
14
+ /*
15
+ * Determine the url parts to these example files.
16
+ */
17
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
18
+ $hostname = $_SERVER['HTTP_HOST'];
19
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
20
+
21
+ /*
22
+ * Get the all payments for this API key ordered by newest.
23
+ */
24
+ $payments = $mollie->payments->page();
25
+
26
+ echo "<ul>";
27
+ foreach ($payments as $payment) {
28
+ echo "<li>";
29
+ echo "<strong style='font-family: monospace'>" . htmlspecialchars($payment->id) . "</strong><br />";
30
+ echo htmlspecialchars($payment->description) . "<br />";
31
+ echo htmlspecialchars($payment->amount->currency) . " " . htmlspecialchars($payment->amount->value) . "<br />";
32
+
33
+ echo "Status: " . htmlspecialchars($payment->status) . "<br />";
34
+
35
+ if ($payment->hasRefunds()) {
36
+ echo "Payment has been (partially) refunded.<br />";
37
+ }
38
+
39
+ if ($payment->hasChargebacks()) {
40
+ echo "Payment has been charged back.<br />";
41
+ }
42
+
43
+ if ($payment->canBeRefunded() && $payment->amountRemaining->currency === 'EUR' && $payment->amountRemaining->value >= '2.00') {
44
+ echo " (<a href=\"{$protocol}://{$hostname}{$path}/payments/refund-payment.php?payment_id=" . htmlspecialchars($payment->id) . "\">refund</a>)";
45
+ }
46
+
47
+ echo "</li>";
48
+ }
49
+ echo "</ul>";
50
+
51
+ /**
52
+ * Get the next set of Payments if applicable
53
+ */
54
+ $nextPayments = $payments->next();
55
+
56
+ if (!empty($nextPayments)) {
57
+ echo "<ul>";
58
+ foreach ($nextPayments as $payment) {
59
+ echo "<li>";
60
+ echo "<strong style='font-family: monospace'>" . htmlspecialchars($payment->id) . "</strong><br />";
61
+ echo htmlspecialchars($payment->description) . "<br />";
62
+ echo htmlspecialchars($payment->amount->currency) . " " . htmlspecialchars($payment->amount->value) . "<br />";
63
+
64
+ echo "Status: " . htmlspecialchars($payment->status) . "<br />";
65
+
66
+ if ($payment->hasRefunds()) {
67
+ echo "Payment has been (partially) refunded.<br />";
68
+ }
69
+
70
+ if ($payment->hasChargebacks()) {
71
+ echo "Payment has been charged back.<br />";
72
+ }
73
+
74
+ if ($payment->canBeRefunded() && $payment->amountRemaining->currency === 'EUR' && $payment->amountRemaining->value >= '2.00') {
75
+ echo " (<a href=\"{$protocol}://{$hostname}{$path}/payments/refund-payment.php?payment_id=" . htmlspecialchars($payment->id) . "\">refund</a>)";
76
+ }
77
+
78
+ echo "</li>";
79
+ }
80
+ echo "</ul>";
81
+ }
82
+
83
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
84
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
85
+ }
includes/mollie-api-php/examples/payments/refund-payment.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to refund a payment programmatically
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key.
9
+ *
10
+ * See: https://www.mollie.com/dashboard/developers/api-keys
11
+ */
12
+ require "../initialize.php";
13
+
14
+ /*
15
+ * Determine the url parts to these example files.
16
+ */
17
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
18
+ $hostname = $_SERVER['HTTP_HOST'];
19
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
20
+
21
+ if (isset($_GET['payment_id'])) {
22
+ /*
23
+ * Retrieve the payment you want to refund from the API.
24
+ */
25
+ $paymentId = $_GET['payment_id'];
26
+ $payment = $mollie->payments->get($paymentId);
27
+
28
+ if ($payment->canBeRefunded() && $payment->amountRemaining->currency === 'EUR' && $payment->amountRemaining->value >= '2.00') {
29
+ /*
30
+ * Refund € 2,00 of the payment.
31
+ *
32
+ * https://docs.mollie.com/reference/v2/refunds-api/create-refund
33
+ */
34
+ $refund = $payment->refund([
35
+ "amount" => [
36
+ "currency" => "EUR",
37
+ "value" => "2.00" // You must send the correct number of decimals, thus we enforce the use of strings
38
+ ]
39
+ ]);
40
+
41
+ echo "{$refund->amount->currency} {$refund->amount->value} of payment {$paymentId} refunded.", PHP_EOL;
42
+ } else {
43
+ echo "Payment {$paymentId} can not be refunded.", PHP_EOL;
44
+ }
45
+
46
+ /*
47
+ * Retrieve all refunds on a payment.
48
+ */
49
+ echo "<ul>";
50
+ foreach ($payment->refunds() as $refund) {
51
+ echo "<li>";
52
+ echo "<strong style='font-family: monospace'>" . htmlspecialchars($refund->id) . "</strong><br />";
53
+ echo htmlspecialchars($refund->description) . "<br />";
54
+ echo htmlspecialchars($refund->amount->currency) . " " . htmlspecialchars($refund->amount->value) . "<br />";
55
+ echo "Status: " . htmlspecialchars($refund->status);
56
+ echo "</li>";
57
+ }
58
+ echo "</ul>";
59
+ }
60
+
61
+ echo "Refund payment: ";
62
+ echo "<form method='get'><input name='payment_id' value='tr_xxx'/><input type='submit' /></form>";
63
+
64
+ echo "<p>";
65
+ echo '<a href="' . $protocol . '://' . $hostname . $path . '/payments/create-payment.php">Create a payment</a><br>';
66
+ echo '<a href="' . $protocol . '://' . $hostname . $path . '/payments/create-ideal-payment.php">Create an iDEAL payment</a><br>';
67
+ echo '<a href="' . $protocol . '://' . $hostname . $path . '/payments/list-payments.php">List payments</a><br>';
68
+ echo "</p>";
69
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
70
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
71
+ }
includes/mollie-api-php/examples/payments/return.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to show a return page to the customer.
4
+ *
5
+ * In this example we retrieve the order stored in the database.
6
+ * Here, it's unnecessary to use the Mollie API Client.
7
+ */
8
+
9
+ /*
10
+ * NOTE: The examples are using a text file as a database.
11
+ * Please use a real database like MySQL in production code.
12
+ */
13
+ require_once "../functions.php";
14
+
15
+ $status = database_read($_GET["order_id"]);
16
+
17
+ /*
18
+ * Determine the url parts to these example files.
19
+ */
20
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
21
+ $hostname = $_SERVER['HTTP_HOST'];
22
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
23
+
24
+ echo "<p>Your payment status is '" . htmlspecialchars($status) . "'.</p>";
25
+ echo "<p>";
26
+ echo '<a href="' . $protocol . '://' . $hostname . $path . '/payments/create-payment.php">Create a payment</a><br>';
27
+ echo '<a href="' . $protocol . '://' . $hostname . $path . '/payments/create-ideal-payment.php">Create an iDEAL payment</a><br>';
28
+ echo '<a href="' . $protocol . '://' . $hostname . $path . '/payments/list-payments.php">List payments</a><br>';
29
+ echo "</p>";
includes/mollie-api-php/examples/payments/webhook.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to verify Mollie API Payments in a webhook.
4
+ *
5
+ * See: https://docs.mollie.com/guides/webhooks
6
+ */
7
+
8
+ try {
9
+ /*
10
+ * Initialize the Mollie API library with your API key.
11
+ *
12
+ * See: https://www.mollie.com/dashboard/developers/api-keys
13
+ */
14
+ require "../initialize.php";
15
+
16
+ /*
17
+ * Retrieve the payment's current state.
18
+ */
19
+ $payment = $mollie->payments->get($_POST["id"]);
20
+ $orderId = $payment->metadata->order_id;
21
+
22
+ /*
23
+ * Update the order in the database.
24
+ */
25
+ database_write($orderId, $payment->status);
26
+
27
+ if ($payment->isPaid() && !$payment->hasRefunds() && !$payment->hasChargebacks()) {
28
+ /*
29
+ * The payment is paid and isn't refunded or charged back.
30
+ * At this point you'd probably want to start the process of delivering the product to the customer.
31
+ */
32
+ } elseif ($payment->isOpen()) {
33
+ /*
34
+ * The payment is open.
35
+ */
36
+ } elseif ($payment->isPending()) {
37
+ /*
38
+ * The payment is pending.
39
+ */
40
+ } elseif ($payment->isFailed()) {
41
+ /*
42
+ * The payment has failed.
43
+ */
44
+ } elseif ($payment->isExpired()) {
45
+ /*
46
+ * The payment is expired.
47
+ */
48
+ } elseif ($payment->isCanceled()) {
49
+ /*
50
+ * The payment has been canceled.
51
+ */
52
+ } elseif ($payment->hasRefunds()) {
53
+ /*
54
+ * The payment has been (partially) refunded.
55
+ * The status of the payment is still "paid"
56
+ */
57
+ } elseif ($payment->hasChargebacks()) {
58
+ /*
59
+ * The payment has been (partially) charged back.
60
+ * The status of the payment is still "paid"
61
+ */
62
+ }
63
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
64
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
65
+ }
includes/mollie-api-php/examples/profiles/create-profile.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Create a profile via the Mollie API.
4
+ */
5
+ try
6
+ {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize_with_oauth.php";
11
+
12
+ /**
13
+ * Create the profile
14
+ *
15
+ * @See https://docs.mollie.com/reference/v2/profiles-api/create-profile
16
+ */
17
+ $profile = $mollie->profiles->create([
18
+ "name" => "My website name",
19
+ "website" => "https://www.mywebsite.com",
20
+ "email" => "info@mywebsite.com",
21
+ "phone" => "+31208202070",
22
+ "categoryCode" => 5399,
23
+ "mode" => "live",
24
+ ]);
25
+ echo "<p>Profile created: " . htmlspecialchars($profile->name) . "</p>";
26
+ }
27
+ catch (\Mollie\Api\Exceptions\ApiException $e)
28
+ {
29
+ echo "<p>API call failed: " . htmlspecialchars($e->getMessage()) . "</p>";
30
+ }
includes/mollie-api-php/examples/profiles/delete-profile.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Delete a profile via the Mollie API.
4
+ */
5
+ try
6
+ {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize_with_oauth.php";
11
+
12
+ /**
13
+ * Delete a profile via the profileId
14
+ *
15
+ * @See https://docs.mollie.com/reference/v2/profiles-api/delete-profile
16
+ */
17
+ $profile = $mollie->profiles->delete("pfl_v9hTwCvYqw");
18
+ echo "<p>Profile deleted</p>";
19
+ }
20
+ catch (\Mollie\Api\Exceptions\ApiException $e)
21
+ {
22
+ echo "<p>API call failed: " . htmlspecialchars($e->getMessage()) . "</p>";
23
+ }
includes/mollie-api-php/examples/profiles/list-profiles.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Using OAuth access token to list profiles of an account.
4
+ */
5
+ try
6
+ {
7
+ /*
8
+ * Initialize the Mollie API library with your OAuth access token.
9
+ */
10
+ require "../initialize_with_oauth.php";
11
+
12
+ /*
13
+ * Get the all the profiles for this account.
14
+ */
15
+ $profiles = $mollie->profiles->page();
16
+ foreach ($profiles as $profile)
17
+ {
18
+ echo '<div style="line-height:40px; vertical-align:top">';
19
+ echo htmlspecialchars($profile->name) .
20
+ ' - ' . htmlspecialchars($profile->website) .
21
+ ' (' . htmlspecialchars($profile->id) . ')';
22
+ echo '</div>';
23
+ }
24
+ }
25
+ catch (\Mollie\Api\Exceptions\ApiException $e)
26
+ {
27
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
28
+ }
includes/mollie-api-php/examples/profiles/update-profile.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Updating an existing profile via the Mollie API.
4
+ */
5
+ try
6
+ {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize_with_oauth.php";
11
+
12
+ /*
13
+ * Retrieve an existing profile by his profileId
14
+ */
15
+ $profile = $mollie->profiles->get("pfl_eA4MSz7Bvy");
16
+
17
+ /**
18
+ * Profile fields that can be updated.
19
+ *
20
+ * @See https://docs.mollie.com/reference/v2/profiles-api/update-profile
21
+ */
22
+ $profile->name = "Mollie B.V.";
23
+ $profile->website = 'www.mollie.com';
24
+ $profile->email = 'info@mollie.com';
25
+ $profile->phone = '0612345670';
26
+ $profile->categoryCode = 5399;
27
+ $profile->update();
28
+ echo "<p>Profile updated: " . htmlspecialchars($profile->name) . "</p>";
29
+ }
30
+ catch (\Mollie\Api\Exceptions\ApiException $e)
31
+ {
32
+ echo "<p>API call failed: " . htmlspecialchars($e->getMessage()) . "</p>";
33
+ }
includes/mollie-api-php/examples/settlements/list-settlements.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Using OAuth access token to list settlements of an account.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your OAuth access token.
9
+ */
10
+ require "../initialize_with_oauth.php";
11
+
12
+ /*
13
+ * Get the all the settlements for this account.
14
+ */
15
+ $settlements = $mollie->settlements->page();
16
+ echo '<ul>';
17
+ foreach ($settlements as $settlement) {
18
+ echo '<li><b>Settlement ' . htmlspecialchars($settlement->reference) . ':</b> (' . htmlspecialchars($settlement->createdAt) . ')';
19
+ echo '<table border="1"><tr><th>Month</th><th>Description</th><th>Count</th><th>Net</th><th>VAT</th><th>Gross</th></tr>';
20
+ // Convert from stdClass to array
21
+ $settlement_periods = json_decode(json_encode($settlement->periods), TRUE);
22
+ foreach ($settlement_periods as $year => $months) {
23
+ foreach ($months as $month => $monthly_settlement) {
24
+ foreach ($monthly_settlement['revenue'] as $revenue) {
25
+ echo '<tr>';
26
+ echo '<td>' . htmlspecialchars($year . '-' . $month) . '</td>';
27
+ echo '<td>' . htmlspecialchars($revenue['description']) . '</td>';
28
+ echo '<td align="right">' . htmlspecialchars($revenue['count']) . ' x</td>';
29
+ echo '<td align="right">' . htmlspecialchars($revenue['amountNet']['value'] ? $revenue['amountNet']['value'] . " " . $revenue['amountNet']['currency'] : '-') . '</td>';
30
+ echo '<td align="right">' . htmlspecialchars($revenue['amountVat']['value'] ? $revenue['amountVat']['value'] . " " . $revenue['amountVat']['currency'] : '-') . '</td>';
31
+ echo '<td align="right">' . htmlspecialchars($revenue['amountGross']['value'] ? $revenue['amountGross']['value'] . " " . $revenue['amountGross']['currency'] : '-') . '</td>';
32
+ echo '</tr>';
33
+ }
34
+ foreach ($monthly_settlement['costs'] as $revenue) {
35
+ echo '<tr>';
36
+ echo '<td>' . htmlspecialchars($year . '-' . $month) . '</td>';
37
+ echo '<td>' . htmlspecialchars($revenue['description']) . '</td>';
38
+ echo '<td align="right">' . htmlspecialchars($revenue['count']) . ' x</td>';
39
+ echo '<td align="right">' . htmlspecialchars($revenue['amountNet']['value'] ? $revenue['amountNet']['value'] . " " . $revenue['amountNet']['currency'] : '-') . '</td>';
40
+ echo '<td align="right">' . htmlspecialchars($revenue['amountVat']['value'] ? $revenue['amountVat']['value'] . " " . $revenue['amountVat']['currency'] : '-') . '</td>';
41
+ echo '<td align="right">' . htmlspecialchars($revenue['amountGross']['value'] ? $revenue['amountGross']['value'] . " " . $revenue['amountGross']['currency'] : '-') . '</td>';
42
+ echo '</tr>';
43
+ }
44
+ }
45
+ }
46
+ echo '<tr><th colspan="5" align="right">TOTAL</th><th align="right">' . htmlspecialchars($settlement->amount->value . " " . $settlement->amount->currency) . '</th></tr>';
47
+ echo '</table>';
48
+ echo '</li>';
49
+ }
50
+ echo '</ul>';
51
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
52
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
53
+ }
includes/mollie-api-php/examples/shipments/create-shipment-all.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Create a shipment for an entire order using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Create a shipment for the entire order with ID "ord_8wmqcHMN4U"
14
+ *
15
+ * See: https://docs.mollie.com/reference/v2/shipments-api/create-shipment
16
+ */
17
+
18
+ $order = $mollie->orders->get('ord_8wmqcHMN4U');
19
+ $shipment = $order->shipAll();
20
+
21
+ echo 'A shipment with ID ' . $shipment->id. ' has been created for your order with ID ' . $order->id . '.';
22
+ foreach ($shipment->lines as $line) {
23
+ echo $line->name . ' - status: <b>' . $line->status . '</b>.';
24
+ }
25
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
26
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
27
+ }
includes/mollie-api-php/examples/shipments/create-shipment-partial.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Example 32 - Create a shipment for part of an order using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "./initialize.php";
11
+
12
+ /*
13
+ * Create a shipment for only two lines of the order with ID "ord_8wmqcHMN4U".
14
+ *
15
+ * See: https://docs.mollie.com/reference/v2/shipments-api/create-shipment
16
+ */
17
+
18
+ $order = $this->getOrder('ord_8wmqcHMN4U');
19
+ $lineId1 = $order->lines()[0]->id;
20
+ $lineId2 = $order->lines()[1]->id;
21
+ $shipment = $order->createShipment(
22
+ [
23
+ 'lines' => [
24
+ [
25
+ 'id' => $lineId1,
26
+ // assume all is shipped if no quantity is specified
27
+ ],
28
+ [
29
+ 'id' => $lineId2,
30
+ 'quantity' => 1, // you can set the quantity if not all is shipped at once
31
+ ],
32
+ ],
33
+ ]
34
+ );
35
+
36
+ echo 'A shipment with ID ' . $shipment->id. ' has been created for your order with ID ' . $order->id . '.';
37
+ foreach ($shipment->lines as $line) {
38
+ echo $line->name . '- status: <b>' . $line->status . '</b>.';
39
+ }
40
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
41
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
42
+ }
includes/mollie-api-php/examples/shipments/get-shipment.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Retrieve a shipment using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Retrieve a shipment with ID "shp_3wmsgCJN4U" for the order with ID "ord_8wmqcHMN4U".
14
+ *
15
+ * See: https://docs.mollie.com/reference/v2/shipments-api/get-shipment
16
+ */
17
+
18
+ $order = $mollie->orders->get('ord_8wmqcHMN4U');
19
+ $shipment = $order->getShipment("shp_3wmsgCJN4U");
20
+
21
+ echo 'Shipment with ID ' . $shipment->id. ' for order with ID ' . $order->id . '.';
22
+ foreach ($shipment->lines as $line) {
23
+ echo $line->name . ' - status: <b>' . $line->status . '</b>.';
24
+ }
25
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
26
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
27
+ }
includes/mollie-api-php/examples/shipments/list-shipments.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * List shipment for an order using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Listing shipments for the order with ID "ord_8wmqcHMN4U".
14
+ *
15
+ * See: https://docs.mollie.com/reference/v2/shipments-api/get-shipment
16
+ */
17
+
18
+ $order = $mollie->orders->get('ord_8wmqcHMN4U');
19
+ $shipments = $order->shipments();
20
+
21
+ echo 'Shipments for order with ID ' . $order->id . ':';
22
+ foreach ($shipments as $shipment) {
23
+ echo 'Shipment ' . $shipment->id . '. Items:';
24
+ foreach ($shipment->lines as $line) {
25
+ echo $line->name . ' - status: <b>' . $line->status . '</b>.';
26
+ }
27
+ }
28
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
29
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
30
+ }
includes/mollie-api-php/examples/shipments/update-shipment.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Update shipment tracking information using the Mollie API.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Update the tracking information for a shipment with ID "shp_3wmsgCJN4U" and
14
+ * order ID "ord_8wmqcHMN4U"
15
+ *
16
+ * See: https://docs.mollie.com/reference/v2/shipments-api/update-shipment
17
+ */
18
+
19
+ $order = $mollie->orders->get('ord_8wmqcHMN4U');
20
+ $shipment = $order->getShipment("shp_3wmsgCJN4U");
21
+
22
+ $shipment->tracking = [
23
+ 'carrier' => 'PostNL',
24
+ 'code' => '3SKABA000000000',
25
+ 'url' => 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C',
26
+ ];
27
+ $shipment = $shipment->update();
28
+
29
+ echo 'Shipment with ID ' . $shipment->id. ' for order with ID ' . $order->id . '.';
30
+ echo 'Tracking information updated:';
31
+ echo 'Carrier: ' . $shipment->tracking->carrier;
32
+ echo 'Code: ' . $shipment->tracking->code;
33
+ echo 'Url: ' . $shipment->tracking->url;
34
+
35
+ foreach ($shipment->lines as $line) {
36
+ echo $line->name . ' - status: <b>' . $line->status . '</b>.';
37
+ }
38
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
39
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
40
+ }
includes/mollie-api-php/examples/subscriptions/cancel-subscription.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to cancel a subscription.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Retrieve the last created customer for this example.
14
+ * If no customers are created yet, run the create-customer example.
15
+ */
16
+ $customer = $mollie->customers->page(null, 1)[0];
17
+
18
+ /*
19
+ * The subscription ID, starting with sub_
20
+ */
21
+ $subscriptionId = isset($_GET['subscription_id']) ? $_GET['subscription_id'] : '';
22
+
23
+ /*
24
+ * Customer Subscription deletion parameters.
25
+ *
26
+ * See: https://www.mollie.com/nl/docs/reference/subscriptions/delete
27
+ */
28
+ $canceledSubscription = $customer->cancelSubscription($subscriptionId);
29
+
30
+ /*
31
+ * The subscription status should now be canceled
32
+ */
33
+ echo "<p>The subscription status is now: '" . htmlspecialchars($canceledSubscription->status) . "'.</p>\n";
34
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
35
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
36
+ }
includes/mollie-api-php/examples/subscriptions/create-subscription.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * How to create a regular subscription.
4
+ */
5
+
6
+ try {
7
+ /*
8
+ * Initialize the Mollie API library with your API key or OAuth access token.
9
+ */
10
+ require "../initialize.php";
11
+
12
+ /*
13
+ * Determine the url parts to these example files.
14
+ */
15
+ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http";
16
+ $hostname = $_SERVER['HTTP_HOST'];
17
+ $path = dirname(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF']);
18
+
19
+ /*
20
+ * Retrieve the last created customer for this example.
21
+ * If no customers are created yet, run create-customer example.
22
+ */
23
+ $customer = $mollie->customers->page(null, 1)[0];
24
+
25
+ /*
26
+ * Generate a unique subscription id for this example. It is important to include this unique attribute
27
+ * in the webhookUrl (below) so new payments can be associated with this subscription.
28
+ */
29
+ $subscriptionId = time();
30
+
31
+ /**
32
+ * Customer Subscription creation parameters.
33
+ *
34
+ * @See: https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription
35
+ */
36
+ $subscription = $customer->createSubscription([
37
+ "amount" => [
38
+ "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings
39
+ "currency" => "EUR"
40
+ ],
41
+ "times" => 12,
42
+ "interval" => "1 month",
43
+ "description" => "Subscription #{$subscriptionId}",
44
+ "webhookUrl" => "{$protocol}://{$hostname}{$path}/subscriptions/webhook.php",
45
+ "metadata" => [
46
+ "subscription_id" => $subscriptionId
47
+ ],
48
+ ]);
49
+
50
+ /*
51
+ * The subscription will be either pending or active depending on whether the customer has
52
+ * a pending or valid mandate. If the customer has no mandates an error is returned. You
53
+ * should then set up a "first payment" for the customer.
54
+ */
55
+ echo "<p>The subscription status is '" . htmlspecialchars($subscription->status) . "'.</p>\n";
56
+ echo "<p>";
57
+ echo '<a href="' . $protocol . '://' . $hostname . $path . '/17-cancel-subscription.php?subscription_id=' . $subscription->id . '">18-cancel-subscription</a><br>';
58
+ echo "</p>";
59
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
60
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
61
+ }
includes/mollie-api-php/examples/subscriptions/update-subscription.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Updating an existing subscription via the Mollie API.
4
+ */
5
+ try {
6
+ /*
7
+ * Initialize the Mollie API library with your API key or OAuth access token.
8
+ */
9
+ require "../initialize.php";
10
+
11
+ /*
12
+ * Retrieve an existing subscription
13
+ */
14
+ $customer = $mollie->customers->get("cst_cUe8HjeBuz");
15
+ $subscription = $customer->getSubscription("sub_DRjwaT5qHx");
16
+
17
+ /**
18
+ * Subscription fields that can be updated are described by the link:
19
+ * See https://docs.mollie.com/reference/v2/subscriptions-api/update-subscription
20
+ */
21
+ $subscription->times = 10;
22
+ $subscription->startDate = '2018-12-02'; // Year-month-day
23
+ $subscription->amount = (object)['value' => '12.12', 'currency' => 'EUR'];
24
+ $subscription->webhookUrl = 'https://some-webhook-url.com/with/path';
25
+ $subscription->description = 'Monthly subscription';
26
+ $subscription->update();
27
+
28
+ echo "<p>Subscription updated: " . $subscription->id . "</p>";
29
+ } catch (\Mollie\Api\Exceptions\ApiException $e) {
30
+ echo "API call failed: " . htmlspecialchars($e->getMessage());
31
+ }
includes/mollie-api-php/phpunit.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <phpunit colors="true" bootstrap="./vendor/autoload.php">
3
+ <php>
4
+ <ini name="display_errors" value="stderr"/>
5
+ <ini name="error_log" value="/dev/null"/>
6
+ </php>
7
+ <testsuite name="Unit tests">
8
+ <directory>tests/</directory>
9
+ </testsuite>
10
+ <filter>
11
+ <whitelist processUncoveredFilesFromWhitelist="true">
12
+ <directory suffix=".php">src/</directory>
13
+ </whitelist>
14
+ </filter>
15
+ </phpunit>
includes/mollie-api-php/tests/Mollie/API/CompatibilityCheckerTest.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Tests\Mollie\Api;
3
+
4
+ use Mollie\Api\CompatibilityChecker;
5
+
6
+ class CompatibilityCheckerTest extends \PHPUnit\Framework\TestCase
7
+ {
8
+ /**
9
+ * @var CompatibilityChecker|\PHPUnit_Framework_MockObject_MockObject
10
+ */
11
+ protected $checker;
12
+
13
+ protected function setUp()
14
+ {
15
+ parent::setUp();
16
+
17
+ $this->checker = $this->getMockBuilder(CompatibilityChecker::class)
18
+ ->setMethods([
19
+ "satisfiesPhpVersion",
20
+ "satisfiesJsonExtension",
21
+ ])
22
+ ->getMock();
23
+ }
24
+
25
+ /**
26
+ * @expectedException \Mollie\Api\Exceptions\IncompatiblePlatform
27
+ * @expectedExceptionCode Mollie\Api\Exceptions\IncompatiblePlatform::INCOMPATIBLE_PHP_VERSION
28
+ */
29
+ public function testCheckCompatibilityThrowsExceptionOnPhpVersion()
30
+ {
31
+ $this->checker->expects($this->once())
32
+ ->method("satisfiesPhpVersion")
33
+ ->will($this->returnValue(false)); // Fail
34
+
35
+ $this->checker->expects($this->never())
36
+ ->method("satisfiesJsonExtension");
37
+
38
+ $this->checker->checkCompatibility();
39
+ }
40
+
41
+ /**
42
+ * @expectedException \Mollie\Api\Exceptions\IncompatiblePlatform
43
+ * @expectedExceptionCode Mollie\Api\Exceptions\IncompatiblePlatform::INCOMPATIBLE_JSON_EXTENSION
44
+ */
45
+ public function testCheckCompatibilityThrowsExceptionOnJsonExtension()
46
+ {
47
+ $this->checker->expects($this->once())
48
+ ->method("satisfiesPhpVersion")
49
+ ->will($this->returnValue(true));
50
+
51
+ $this->checker->expects($this->once())
52
+ ->method("satisfiesJsonExtension")
53
+ ->will($this->returnValue(false)); // Fail
54
+
55
+ $this->checker->checkCompatibility();
56
+ }
57
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/BaseEndpointTest.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Client;
6
+ use GuzzleHttp\Psr7\Request;
7
+ use GuzzleHttp\Psr7\Response;
8
+ use Mollie\Api\MollieApiClient;
9
+
10
+ abstract class BaseEndpointTest extends \PHPUnit\Framework\TestCase
11
+ {
12
+ /**
13
+ * @var Client|\PHPUnit_Framework_MockObject_MockObject
14
+ */
15
+ protected $guzzleClient;
16
+
17
+ /**
18
+ * @var MollieApiClient
19
+ */
20
+ protected $apiClient;
21
+
22
+ protected function mockApiCall(Request $expectedRequest, Response $response, $oAuthClient = false)
23
+ {
24
+ $this->guzzleClient = $this->createMock(Client::class);
25
+
26
+ $this->apiClient = new MollieApiClient($this->guzzleClient);
27
+
28
+ if (!$oAuthClient) {
29
+ $this->apiClient->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM");
30
+ } else {
31
+ $this->apiClient->setAccessToken("access_Wwvu7egPcJLLJ9Kb7J632x8wJ2zMeJ");
32
+ }
33
+
34
+ $this->guzzleClient
35
+ ->expects($this->once())
36
+ ->method('send')
37
+ ->with($this->isInstanceOf(Request::class))
38
+ ->willReturnCallback(function (Request $request) use ($expectedRequest, $response) {
39
+ $this->assertEquals($expectedRequest->getMethod(), $request->getMethod(), "HTTP method must be identical");
40
+
41
+ $this->assertEquals(
42
+ $expectedRequest->getUri()->getPath(),
43
+ $request->getUri()->getPath(),
44
+ "URI path must be identical"
45
+ );
46
+
47
+ $this->assertEquals(
48
+ $expectedRequest->getUri()->getQuery(),
49
+ $request->getUri()->getQuery(),
50
+ 'Query string parameters must be identical'
51
+ );
52
+
53
+ $requestBody = $request->getBody()->getContents();
54
+ $expectedBody = $expectedRequest->getBody()->getContents();
55
+
56
+ if (strlen($expectedBody) > 0 && strlen($requestBody) > 0) {
57
+ $this->assertJsonStringEqualsJsonString(
58
+ $expectedBody,
59
+ $requestBody,
60
+ "HTTP body must be identical"
61
+ );
62
+ }
63
+
64
+ return $response;
65
+ });
66
+ }
67
+
68
+ protected function copy($array, $object)
69
+ {
70
+ foreach ($array as $property => $value) {
71
+ $object->$property = $value;
72
+ }
73
+
74
+ return $object;
75
+ }
76
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Chargeback;
8
+ use Mollie\Api\Resources\ChargebackCollection;
9
+ use Mollie\Api\Resources\Payment;
10
+ use Tests\Mollie\TestHelpers\AmountObjectTestHelpers;
11
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
12
+
13
+ class ChargebackEndpointTest extends BaseEndpointTest
14
+ {
15
+ use LinkObjectTestHelpers;
16
+ use AmountObjectTestHelpers;
17
+
18
+ public function testListChargebacks()
19
+ {
20
+ $this->mockApiCall(
21
+ new Request(
22
+ "GET",
23
+ "/v2/chargebacks"
24
+ ),
25
+ new Response(
26
+ 200,
27
+ [],
28
+ '{
29
+ "_embedded":{
30
+ "chargebacks":[
31
+ {
32
+ "resource":"chargeback",
33
+ "id":"chb_n9z0tp",
34
+ "amount":{
35
+ "value":"-13.00",
36
+ "currency":"EUR"
37
+ },
38
+ "createdAt":"2018-03-28T11:44:32+00:00",
39
+ "paymentId":"tr_44aKxzEbr8",
40
+ "settlementAmount":{
41
+ "value":"-13.00",
42
+ "currency":"EUR"
43
+ },
44
+ "_links":{
45
+ "self":{
46
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp",
47
+ "type":"application/hal+json"
48
+ },
49
+ "payment":{
50
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
51
+ "type":"application/hal+json"
52
+ },
53
+ "documentation": {
54
+ "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback",
55
+ "type": "text/html"
56
+ }
57
+ }
58
+ },
59
+ {
60
+ "resource":"chargeback",
61
+ "id":"chb_6cqlwf",
62
+ "amount":{
63
+ "value":"-0.37",
64
+ "currency":"EUR"
65
+ },
66
+ "createdAt":"2018-03-28T11:44:32+00:00",
67
+ "paymentId":"tr_nQKWJbDj7j",
68
+ "settlementAmount":{
69
+ "value":"-0.37",
70
+ "currency":"EUR"
71
+ },
72
+ "_links":{
73
+ "self":{
74
+ "href":"https://api.mollie.com/v2/payments/tr_nQKWJbDj7j/chargebacks/chb_6cqlwf",
75
+ "type":"application/hal+json"
76
+ },
77
+ "payment":{
78
+ "href":"https://api.mollie.com/v2/payments/tr_nQKWJbDj7j",
79
+ "type":"application/hal+json"
80
+ },
81
+ "documentation": {
82
+ "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback",
83
+ "type": "text/html"
84
+ }
85
+ }
86
+ }
87
+ ]
88
+ },
89
+ "_links":{
90
+ "documentation":{
91
+ "href":"https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks",
92
+ "type":"text/html"
93
+ },
94
+ "self":{
95
+ "href":"https://api.mollie.com/v2/chargebacks",
96
+ "type":"application/hal+json"
97
+ }
98
+ },
99
+ "count": 2
100
+ }'
101
+ )
102
+ );
103
+
104
+ $chargebacks = $this->apiClient->chargebacks->page();
105
+
106
+ $this->assertInstanceOf(ChargebackCollection::class, $chargebacks);
107
+ $this->assertEquals(2, $chargebacks->count);
108
+ $this->assertCount(2, $chargebacks);
109
+
110
+ $this->assertLinkObject(
111
+ "https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks",
112
+ "text/html",
113
+ $chargebacks->_links->documentation
114
+ );
115
+
116
+ $this->assertLinkObject(
117
+ "https://api.mollie.com/v2/chargebacks",
118
+ "application/hal+json",
119
+ $chargebacks->_links->self
120
+ );
121
+
122
+ $this->assertChargeback($chargebacks[0], 'tr_44aKxzEbr8', 'chb_n9z0tp', "-13.00");
123
+ $this->assertChargeback($chargebacks[1], 'tr_nQKWJbDj7j', 'chb_6cqlwf', "-0.37");
124
+ }
125
+
126
+ protected function assertChargeback($chargeback, $paymentId, $chargebackId, $amount)
127
+ {
128
+ $this->assertInstanceOf(Chargeback::class, $chargeback);
129
+ $this->assertEquals("chargeback", $chargeback->resource);
130
+ $this->assertEquals($chargebackId, $chargeback->id);
131
+
132
+ $this->assertAmountObject($amount, "EUR", $chargeback->amount);
133
+ $this->assertAmountObject($amount, "EUR", $chargeback->settlementAmount);
134
+
135
+ $this->assertEquals("2018-03-28T11:44:32+00:00", $chargeback->createdAt);
136
+ $this->assertEquals($paymentId, $chargeback->paymentId);
137
+
138
+ $this->assertLinkObject(
139
+ "https://api.mollie.com/v2/payments/{$paymentId}/chargebacks/{$chargebackId}",
140
+ "application/hal+json",
141
+ $chargeback->_links->self
142
+ );
143
+
144
+ $this->assertLinkObject(
145
+ "https://api.mollie.com/v2/payments/{$paymentId}",
146
+ "application/hal+json",
147
+ $chargeback->_links->payment
148
+ );
149
+
150
+ $this->assertLinkObject(
151
+ "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback",
152
+ "text/html",
153
+ $chargeback->_links->documentation
154
+ );
155
+ }
156
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/CustomerEndpointTest.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Customer;
8
+ use Mollie\Api\Resources\CustomerCollection;
9
+
10
+ class CustomerEndpointTest extends BaseEndpointTest
11
+ {
12
+ public function testCreateWorks()
13
+ {
14
+ $this->mockApiCall(
15
+ new Request('POST', '/v2/customers'),
16
+ new Response(
17
+ 200,
18
+ [],
19
+ '{
20
+ "resource": "customer",
21
+ "id": "cst_FhQJRw4s2n",
22
+ "mode": "test",
23
+ "name": "John Doe",
24
+ "email": "johndoe@example.org",
25
+ "locale": null,
26
+ "metadata": null,
27
+ "recentlyUsedMethods": [],
28
+ "createdAt": "2018-04-19T08:49:01+00:00",
29
+ "_links": {
30
+ "documentation": {
31
+ "href": "https://docs.mollie.com/reference/v2/customers-api/create-customer",
32
+ "type": "text/html"
33
+ }
34
+ }
35
+ }'
36
+ )
37
+ );
38
+
39
+ /** @var Customer $customer */
40
+ $customer = $this->apiClient->customers->create([
41
+ "name" => "John Doe",
42
+ "email" => "johndoe@example.org"
43
+ ]);
44
+
45
+ $this->assertInstanceOf(Customer::class, $customer);
46
+ $this->assertEquals("customer", $customer->resource);
47
+ $this->assertEquals("cst_FhQJRw4s2n", $customer->id);
48
+ $this->assertEquals("John Doe", $customer->name);
49
+ $this->assertEquals("johndoe@example.org", $customer->email);
50
+ $this->assertNull($customer->locale);
51
+ $this->assertNull($customer->metadata);
52
+ $this->assertEquals([], $customer->recentlyUsedMethods);
53
+ $this->assertEquals("2018-04-19T08:49:01+00:00", $customer->createdAt);
54
+
55
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/create-customer", "type" => "text/html"];
56
+ $this->assertEquals($documentationLink, $customer->_links->documentation);
57
+
58
+ }
59
+
60
+ public function testGetWorks()
61
+ {
62
+ $this->mockApiCall(
63
+ new Request('GET', '/v2/customers/cst_FhQJRw4s2n'),
64
+ new Response(
65
+ 200,
66
+ [],
67
+ '{
68
+ "resource": "customer",
69
+ "id": "cst_FhQJRw4s2n",
70
+ "mode": "test",
71
+ "name": "John Doe",
72
+ "email": "johndoe@example.org",
73
+ "locale": null,
74
+ "metadata": null,
75
+ "recentlyUsedMethods": [],
76
+ "createdAt": "2018-04-19T08:49:01+00:00",
77
+ "_links": {
78
+ "documentation": {
79
+ "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer",
80
+ "type": "text/html"
81
+ }
82
+ }
83
+ }'
84
+ )
85
+ );
86
+
87
+ /** @var Customer $customer */
88
+ $customer = $this->apiClient->customers->get("cst_FhQJRw4s2n");
89
+
90
+ $this->assertInstanceOf(Customer::class, $customer);
91
+ $this->assertEquals("customer", $customer->resource);
92
+ $this->assertEquals("cst_FhQJRw4s2n", $customer->id);
93
+ $this->assertEquals("John Doe", $customer->name);
94
+ $this->assertEquals("johndoe@example.org", $customer->email);
95
+ $this->assertNull($customer->locale);
96
+ $this->assertNull($customer->metadata);
97
+ $this->assertEquals([], $customer->recentlyUsedMethods);
98
+ $this->assertEquals("2018-04-19T08:49:01+00:00", $customer->createdAt);
99
+
100
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/get-customer", "type" => "text/html"];
101
+ $this->assertEquals($documentationLink, $customer->_links->documentation);
102
+
103
+ }
104
+
105
+ public function testListWorks()
106
+ {
107
+ $this->mockApiCall(
108
+ new Request('GET', '/v2/customers'),
109
+ new Response(
110
+ 200,
111
+ [],
112
+ '{
113
+ "_embedded": {
114
+ "customers": [
115
+ {
116
+ "resource": "customer",
117
+ "id": "cst_FhQJRw4s2n",
118
+ "mode": "test",
119
+ "name": "John Doe",
120
+ "email": "johndoe@example.org",
121
+ "locale": null,
122
+ "metadata": null,
123
+ "recentlyUsedMethods": [],
124
+ "createdAt": "2018-04-19T08:49:01+00:00"
125
+ }
126
+ ]
127
+ },
128
+ "count": 1,
129
+ "_links": {
130
+ "documentation": {
131
+ "href": "https://docs.mollie.com/reference/v2/customers-api/list-customers",
132
+ "type": "text/html"
133
+ },
134
+ "self": {
135
+ "href": "https://api.mollie.com/v2/customers?limit=50",
136
+ "type": "application/hal+json"
137
+ },
138
+ "previous": null,
139
+ "next": null
140
+ }
141
+ }'
142
+ )
143
+ );
144
+
145
+ /** @var Customer $customer */
146
+ $customers = $this->apiClient->customers->page();
147
+
148
+ $this->assertInstanceOf(CustomerCollection::class, $customers);
149
+
150
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/list-customers", "type" => "text/html"];
151
+ $this->assertEquals($documentationLink, $customers->_links->documentation);
152
+
153
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/customers?limit=50", "type" => "application/hal+json"];
154
+ $this->assertEquals($selfLink, $customers->_links->self);
155
+
156
+ foreach ($customers as $customer) {
157
+ $this->assertInstanceOf(Customer::class, $customer);
158
+ $this->assertEquals("customer", $customer->resource);
159
+ $this->assertNotEmpty($customer->createdAt);
160
+ }
161
+
162
+ }
163
+
164
+ public function testUpdateWorks()
165
+ {
166
+ $expectedName = 'Kaas Broodje';
167
+ $expectedEmail = 'kaas.broodje@gmail.com';
168
+
169
+ $this->mockApiCall(
170
+ new Request('PATCH', '/v2/customers/cst_FhQJRw4s2n'),
171
+ new Response(
172
+ 200,
173
+ [],
174
+ '{
175
+ "resource": "customer",
176
+ "id": "cst_FhQJRw4s2n",
177
+ "mode": "test",
178
+ "name": "' . $expectedName . '",
179
+ "email": "' . $expectedEmail . '",
180
+ "locale": null,
181
+ "metadata": null,
182
+ "recentlyUsedMethods": [],
183
+ "createdAt": "2018-04-19T08:49:01+00:00",
184
+ "_links": {
185
+ "documentation": {
186
+ "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer",
187
+ "type": "text/html"
188
+ }
189
+ }
190
+ }'
191
+ )
192
+ );
193
+
194
+ $customer = $this->getCustomer();
195
+ $customer->name = $expectedName;
196
+ $customer->email = $expectedEmail;
197
+
198
+ $updatedCustomer = $customer->update();
199
+
200
+ $this->assertEquals($expectedName, $updatedCustomer->name);
201
+ $this->assertEquals($expectedEmail, $updatedCustomer->email);
202
+ }
203
+
204
+ /**
205
+ * @return Customer
206
+ */
207
+ private function getCustomer()
208
+ {
209
+ $customerJson = '{
210
+ "resource": "customer",
211
+ "id": "cst_FhQJRw4s2n",
212
+ "mode": "test",
213
+ "name": "John Doe",
214
+ "email": "johndoe@example.org",
215
+ "locale": null,
216
+ "metadata": null,
217
+ "recentlyUsedMethods": [],
218
+ "createdAt": "2018-04-19T08:49:01+00:00",
219
+ "_links": {
220
+ "self": {
221
+ "href": "http://api.mollie.test/v2/customers/cst_FhQJRw4s2n",
222
+ "type": "application/hal+json"
223
+ },
224
+ "documentation": {
225
+ "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer",
226
+ "type": "text/html"
227
+ }
228
+ }
229
+ }';
230
+
231
+ return $this->copy(json_decode($customerJson), new Customer($this->apiClient));
232
+ }
233
+
234
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Customer;
8
+ use Mollie\Api\Resources\Payment;
9
+ use Mollie\Api\Resources\PaymentCollection;
10
+ use Mollie\Api\Types\PaymentStatus;
11
+ use Mollie\Api\Types\SequenceType;
12
+ use stdClass;
13
+
14
+ class CustomerPaymentEndpointTest extends BaseEndpointTest
15
+ {
16
+ public function testCreateCustomerPayment()
17
+ {
18
+ $this->mockApiCall(
19
+ new Request(
20
+ "POST",
21
+ "/v2/customers/cst_FhQJRw4s2n/payments",
22
+ [],
23
+ '{
24
+ "amount":{
25
+ "value":"20.00",
26
+ "currency":"EUR"
27
+ },
28
+ "description": "My first API payment",
29
+ "redirectUrl": "https://example.org/redirect",
30
+ "webhookUrl": "https://example.org/webhook",
31
+ "metadata": {
32
+ "order_id": "1234"
33
+ }
34
+ }'
35
+ ),
36
+ new Response(
37
+ 201,
38
+ [],
39
+ '{
40
+ "resource":"payment",
41
+ "id":"tr_44aKxzEbr8",
42
+ "mode":"test",
43
+ "createdAt":"2018-03-13T14:02:29+00:00",
44
+ "amount":{
45
+ "value":"20.00",
46
+ "currency":"EUR"
47
+ },
48
+ "description":"My first API payment",
49
+ "method":null,
50
+ "metadata":{
51
+ "order_id":1234
52
+ },
53
+ "status":"open",
54
+ "isCancelable":false,
55
+ "expiresAt":"2018-03-13T14:17:29+00:00",
56
+ "details":null,
57
+ "profileId":"pfl_2A1gacu42V",
58
+ "sequenceType":"oneoff",
59
+ "redirectUrl":"http://example.org/examples/payment/03-return-page.php?order_id=1234",
60
+ "webhookUrl":"http://example.org/examples/payment/02-webhook-verification.php",
61
+ "_links":{
62
+ "self":{
63
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
64
+ "type":"application/hal+json"
65
+ },
66
+ "checkout":{
67
+ "href":"https://www.mollie.com/payscreen/select-method/44aKxzEbr8",
68
+ "type":"text/html"
69
+ },
70
+ "customer": {
71
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
72
+ "type": "application/hal+json"
73
+ },
74
+ "documentation":{
75
+ "href":"https://docs.mollie.com/reference/v2/customers-api/create-payment",
76
+ "type":"text/html"
77
+ }
78
+ }
79
+ }'
80
+ )
81
+ );
82
+
83
+ $customer = $this->getCustomer();
84
+
85
+ $payment = $customer->createPayment([
86
+ "amount" => [
87
+ "currency" => "EUR",
88
+ "value" => "20.00"
89
+ ],
90
+ "description" => "My first API payment",
91
+ "redirectUrl" => "https://example.org/redirect",
92
+ "webhookUrl" => "https://example.org/webhook",
93
+ "metadata" => [
94
+ "order_id" => "1234",
95
+ ],
96
+ ]);
97
+
98
+ $this->assertInstanceOf(Payment::class, $payment);
99
+ $this->assertEquals('tr_44aKxzEbr8', $payment->id);
100
+ $this->assertEquals('test', $payment->mode);
101
+ $this->assertEquals("2018-03-13T14:02:29+00:00", $payment->createdAt);
102
+
103
+ $amount = new Stdclass();
104
+ $amount->value = '20.00';
105
+ $amount->currency = "EUR";
106
+ $this->assertEquals($amount, $payment->amount);
107
+
108
+ $this->assertEquals('My first API payment', $payment->description);
109
+ $this->assertNull($payment->method);
110
+ $this->assertEquals((object)["order_id" => "1234"], $payment->metadata);
111
+ $this->assertEquals(PaymentStatus::STATUS_OPEN, $payment->status);
112
+ $this->assertFalse($payment->isCancelable);
113
+ $this->assertEquals("2018-03-13T14:17:29+00:00", $payment->expiresAt);
114
+ $this->assertNull($payment->details);
115
+ $this->assertEquals("pfl_2A1gacu42V", $payment->profileId);
116
+ $this->assertEquals(SequenceType::SEQUENCETYPE_ONEOFF, $payment->sequenceType);
117
+ $this->assertEquals("http://example.org/examples/payment/03-return-page.php?order_id=1234", $payment->redirectUrl);
118
+ $this->assertEquals("http://example.org/examples/payment/02-webhook-verification.php", $payment->webhookUrl);
119
+
120
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"];
121
+ $this->assertEquals($selfLink, $payment->_links->self);
122
+
123
+ $checkoutLink = (object)["href" => "https://www.mollie.com/payscreen/select-method/44aKxzEbr8", "type" => "text/html"];
124
+ $this->assertEquals($checkoutLink, $payment->_links->checkout);
125
+
126
+ $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"];
127
+ $this->assertEquals($customerLink, $payment->_links->customer);
128
+
129
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/create-payment", "type" => "text/html"];
130
+ $this->assertEquals($documentationLink, $payment->_links->documentation);
131
+ }
132
+
133
+ public function testListCustomerPayments()
134
+ {
135
+ $this->mockApiCall(
136
+ new Request(
137
+ "GET",
138
+ "/v2/customers/cst_FhQJRw4s2n/payments?testmode=true",
139
+ [],
140
+ ''
141
+ ),
142
+ new Response(
143
+ 200,
144
+ [],
145
+ '{
146
+ "_embedded": {
147
+ "payments": [
148
+ {
149
+ "resource": "payment",
150
+ "id": "tr_admNa2tFfa",
151
+ "mode": "test",
152
+ "createdAt": "2018-03-19T15:00:50+00:00",
153
+ "amount": {
154
+ "value": "100.00",
155
+ "currency": "EUR"
156
+ },
157
+ "description": "Payment no 1",
158
+ "method": null,
159
+ "metadata": null,
160
+ "status": "open",
161
+ "isCancelable": false,
162
+ "expiresAt": "2018-03-19T15:15:50+00:00",
163
+ "details": null,
164
+ "locale": "nl_NL",
165
+ "profileId": "pfl_7N5qjbu42V",
166
+ "sequenceType": "oneoff",
167
+ "redirectUrl": "https://www.example.org/",
168
+ "_links": {
169
+ "self": {
170
+ "href": "https://api.mollie.com/v2/payments/tr_admNa2tFfa",
171
+ "type": "application/hal+json"
172
+ },
173
+ "checkout": {
174
+ "href": "https://www.mollie.com/payscreen/select-method/admNa2tFfa",
175
+ "type": "text/html"
176
+ },
177
+ "customer": {
178
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
179
+ "type": "application/hal+json"
180
+ }
181
+ }
182
+ },
183
+ {
184
+ "resource": "payment",
185
+ "id": "tr_bcaLc7hFfa",
186
+ "mode": "test",
187
+ "createdAt": "2018-03-19T15:00:50+00:00",
188
+ "amount": {
189
+ "value": "100.00",
190
+ "currency": "EUR"
191
+ },
192
+ "description": "Payment no 2",
193
+ "method": null,
194
+ "metadata": null,
195
+ "status": "open",
196
+ "isCancelable": false,
197
+ "expiresAt": "2018-03-19T15:15:50+00:00",
198
+ "details": null,
199
+ "locale": "nl_NL",
200
+ "profileId": "pfl_7N5qjbu42V",
201
+ "sequenceType": "oneoff",
202
+ "redirectUrl": "https://www.example.org/",
203
+ "_links": {
204
+ "self": {
205
+ "href": "https://api.mollie.com/v2/payments/tr_bcaLc7hFfa",
206
+ "type": "application/hal+json"
207
+ },
208
+ "checkout": {
209
+ "href": "https://www.mollie.com/payscreen/select-method/bcaLc7hFfa",
210
+ "type": "text/html"
211
+ },
212
+ "customer": {
213
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
214
+ "type": "application/hal+json"
215
+ }
216
+ }
217
+ },
218
+ {
219
+ "resource": "payment",
220
+ "id": "tr_pslHy1tFfa",
221
+ "mode": "test",
222
+ "createdAt": "2018-03-19T15:00:50+00:00",
223
+ "amount": {
224
+ "value": "100.00",
225
+ "currency": "EUR"
226
+ },
227
+ "description": "Payment no 3",
228
+ "method": null,
229
+ "metadata": null,
230
+ "status": "open",
231
+ "isCancelable": false,
232
+ "expiresAt": "2018-03-19T15:15:50+00:00",
233
+ "details": null,
234
+ "locale": "nl_NL",
235
+ "profileId": "pfl_7N5qjbu42V",
236
+ "sequenceType": "oneoff",
237
+ "redirectUrl": "https://www.example.org/",
238
+ "_links": {
239
+ "self": {
240
+ "href": "https://api.mollie.com/v2/payments/tr_pslHy1tFfa",
241
+ "type": "application/hal+json"
242
+ },
243
+ "checkout": {
244
+ "href": "https://www.mollie.com/payscreen/select-method/pslHy1tFfa",
245
+ "type": "text/html"
246
+ },
247
+ "customer": {
248
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
249
+ "type": "application/hal+json"
250
+ }
251
+ }
252
+ }
253
+ ]
254
+ },
255
+ "_links": {
256
+ "documentation": {
257
+ "href": "https://docs.mollie.com/reference/v2/customers-api/list-customer-payments",
258
+ "type": "text/html"
259
+ },
260
+ "self": {
261
+ "href": "https://api.mollie.com/v2/customers/cst_TkNdP8yPrH/payments?limit=50",
262
+ "type": "application/hal+json"
263
+ },
264
+ "previous": null,
265
+ "next": null
266
+ },
267
+ "count": 3
268
+ }'
269
+ ),
270
+ true
271
+ );
272
+
273
+ /** @var Customer $customer */
274
+ $customer = $this->getCustomer();
275
+
276
+ $payments = $customer->payments();
277
+
278
+ $this->assertInstanceOf(PaymentCollection::class, $payments);
279
+ $this->assertEquals(3, $payments->count);
280
+ $this->assertEquals(3, count($payments));
281
+
282
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/list-customer-payments", "type" => "text/html"];
283
+ $this->assertEquals($documentationLink, $payments->_links->documentation);
284
+
285
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_TkNdP8yPrH/payments?limit=50", "type" => "application/hal+json"];
286
+ $this->assertEquals($selfLink, $payments->_links->self);
287
+ }
288
+
289
+ /**
290
+ * @return CustomerPaymentEndpointTest
291
+ */
292
+ private function getCustomer()
293
+ {
294
+ $customerJson = '{
295
+ "resource": "customer",
296
+ "id": "cst_FhQJRw4s2n",
297
+ "mode": "test",
298
+ "name": "John Doe",
299
+ "email": "johndoe@example.org",
300
+ "locale": null,
301
+ "metadata": null,
302
+ "recentlyUsedMethods": [],
303
+ "createdAt": "2018-04-19T08:49:01+00:00",
304
+ "_links": {
305
+ "documentation": {
306
+ "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer",
307
+ "type": "text/html"
308
+ }
309
+ }
310
+ }';
311
+
312
+ return $this->copy(json_decode($customerJson), new Customer($this->apiClient));
313
+ }
314
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Invoice;
8
+ use Mollie\Api\Resources\InvoiceCollection;
9
+ use Mollie\Api\Types\InvoiceStatus;
10
+
11
+ class InvoiceEndpointTest extends BaseEndpointTest
12
+ {
13
+ public function testGetInvoice()
14
+ {
15
+ $this->mockApiCall(
16
+ new Request(
17
+ "GET",
18
+ "/v2/invoices/inv_bsa6PvAwaK",
19
+ [],
20
+ ''
21
+ ),
22
+ new Response(
23
+ 200,
24
+ [],
25
+ '{
26
+ "resource": "invoice",
27
+ "id": "inv_bsa6PvAwaK",
28
+ "reference": "2018.190241",
29
+ "vatNumber": "123456789B01",
30
+ "status": "paid",
31
+ "issuedAt": "2018-05-02",
32
+ "paidAt": "2018-05-02",
33
+ "netAmount": {
34
+ "value": "100.00",
35
+ "currency": "EUR"
36
+ },
37
+ "vatAmount": {
38
+ "value": "0.00",
39
+ "currency": "EUR"
40
+ },
41
+ "grossAmount": {
42
+ "value": "100.00",
43
+ "currency": "EUR"
44
+ },
45
+ "lines": [
46
+ {
47
+ "period": "2018-04",
48
+ "description": "iDEAL transaction costs: april 2018",
49
+ "count": 1337,
50
+ "vatPercentage": 0,
51
+ "amount": {
52
+ "value": "50.00",
53
+ "currency": "EUR"
54
+ }
55
+ },
56
+ {
57
+ "period": "2018-04",
58
+ "description": "Refunds iDEAL: april 2018",
59
+ "count": 1337,
60
+ "vatPercentage": 0,
61
+ "amount": {
62
+ "value": "50.00",
63
+ "currency": "EUR"
64
+ }
65
+ }
66
+ ],
67
+ "_links": {
68
+ "self": {
69
+ "href": "https://api.mollie.com/v2/invoices/inv_bsa6PvAwaK",
70
+ "type": "application/hal+json"
71
+ },
72
+ "pdf": {
73
+ "href": "https://www.mollie.com/merchant/download/invoice/bsa6PvAwaK/79aa10f49132b7844c0243648ade6985",
74
+ "type": "application/pdf"
75
+ },
76
+ "documentation": {
77
+ "href": "https://docs.mollie.com/reference/v2/invoices-api/get-invoice",
78
+ "type": "text/html"
79
+ }
80
+ }
81
+ }'
82
+ )
83
+ );
84
+
85
+ $invoice = $this->apiClient->invoices->get("inv_bsa6PvAwaK");
86
+
87
+ $this->assertInstanceOf(Invoice::class, $invoice);
88
+ $this->assertEquals("invoice", $invoice->resource);
89
+ $this->assertEquals("inv_bsa6PvAwaK", $invoice->id);
90
+ $this->assertEquals("2018.190241", $invoice->reference);
91
+ $this->assertEquals("123456789B01", $invoice->vatNumber);
92
+ $this->assertEquals(InvoiceStatus::STATUS_PAID, $invoice->status);
93
+ $this->assertEquals("2018-05-02", $invoice->issuedAt);
94
+ $this->assertEquals("2018-05-02", $invoice->paidAt);
95
+
96
+ $this->assertEquals((object) ["value" => "100.00", "currency" => "EUR"], $invoice->netAmount);
97
+ $this->assertEquals((object) ["value" => "0.00", "currency" => "EUR"], $invoice->vatAmount);
98
+ $this->assertEquals((object) ["value" => "100.00", "currency" => "EUR"], $invoice->grossAmount);
99
+
100
+ $this->assertCount(2, $invoice->lines);
101
+
102
+ $selfLink = (object)['href' => 'https://api.mollie.com/v2/invoices/inv_bsa6PvAwaK', 'type' => 'application/hal+json'];
103
+ $this->assertEquals($selfLink, $invoice->_links->self);
104
+
105
+ $pdfLink = (object)['href' => 'https://www.mollie.com/merchant/download/invoice/bsa6PvAwaK/79aa10f49132b7844c0243648ade6985', 'type' => 'application/pdf'];
106
+ $this->assertEquals($pdfLink, $invoice->_links->pdf);
107
+
108
+ $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/invoices-api/get-invoice', 'type' => 'text/html'];
109
+ $this->assertEquals($documentationLink, $invoice->_links->documentation);
110
+ }
111
+
112
+ public function testListInvoices()
113
+ {
114
+ $this->mockApiCall(
115
+ new Request(
116
+ "GET",
117
+ "/v2/invoices",
118
+ [],
119
+ ''
120
+ ),
121
+ new Response(
122
+ 200,
123
+ [],
124
+ '{
125
+ "_embedded": {
126
+ "invoices": [
127
+ {
128
+ "resource": "invoice",
129
+ "id": "inv_bsa6PvAwaK",
130
+ "reference": "2018.190241",
131
+ "vatNumber": "123456789B01",
132
+ "status": "paid",
133
+ "issuedAt": "2018-05-02",
134
+ "paidAt": "2018-05-02",
135
+ "netAmount": {
136
+ "value": "100.00",
137
+ "currency": "EUR"
138
+ },
139
+ "vatAmount": {
140
+ "value": "0.00",
141
+ "currency": "EUR"
142
+ },
143
+ "grossAmount": {
144
+ "value": "100.00",
145
+ "currency": "EUR"
146
+ },
147
+ "lines": [
148
+ {
149
+ "period": "2018-04",
150
+ "description": "iDEAL transaction costs: april 2018",
151
+ "count": 1337,
152
+ "vatPercentage": 0,
153
+ "amount": {
154
+ "value": "50.00",
155
+ "currency": "EUR"
156
+ }
157
+ },
158
+ {
159
+ "period": "2018-04",
160
+ "description": "Refunds iDEAL: april 2018",
161
+ "count": 1337,
162
+ "vatPercentage": 0,
163
+ "amount": {
164
+ "value": "50.00",
165
+ "currency": "EUR"
166
+ }
167
+ }
168
+ ],
169
+ "_links": {
170
+ "self": {
171
+ "href": "https://api.mollie.com/v2/invoices/inv_bsa6PvAwaK",
172
+ "type": "application/hal+json"
173
+ },
174
+ "pdf": {
175
+ "href": "https://www.mollie.com/merchant/download/invoice/bsa6PvAwaK/79aa10f49132b7844c0243648ade6985",
176
+ "type": "application/pdf"
177
+ },
178
+ "documentation": {
179
+ "href": "https://docs.mollie.com/reference/v2/invoices-api/get-invoice",
180
+ "type": "text/html"
181
+ }
182
+ }
183
+ }
184
+ ]
185
+ },
186
+ "count": 1,
187
+ "_links": {
188
+ "documentation": {
189
+ "href": "https://docs.mollie.com/reference/v2/invoices-api/list-invoices",
190
+ "type": "text/html"
191
+ },
192
+ "self": {
193
+ "href": "https://api.mollie.nl/v2/invoices?limit=50",
194
+ "type": "application/hal+json"
195
+ },
196
+ "previous": null,
197
+ "next": null
198
+ }
199
+ }'
200
+ )
201
+ );
202
+
203
+ $invoices = $this->apiClient->invoices->page();
204
+ $this->assertInstanceOf(InvoiceCollection::class, $invoices);
205
+
206
+ $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/invoices-api/list-invoices', 'type' => 'text/html'];
207
+ $this->assertEquals($documentationLink, $invoices->_links->documentation);
208
+
209
+ $selfLink = (object)['href' => 'https://api.mollie.nl/v2/invoices?limit=50', 'type' => 'application/hal+json'];
210
+ $this->assertEquals($selfLink, $invoices->_links->self);
211
+
212
+ $this->assertEmpty($invoices->_links->previous);
213
+ $this->assertEmpty($invoices->_links->next);
214
+
215
+ foreach($invoices as $invoice) {
216
+ $this->assertInstanceOf(Invoice::class, $invoice);
217
+ $this->assertEquals("invoice", $invoice->resource);
218
+ $this->assertNotEmpty($invoice->lines);
219
+ }
220
+ }
221
+
222
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/MandateEndpointTest.php ADDED
@@ -0,0 +1,428 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Customer;
8
+ use Mollie\Api\Resources\Mandate;
9
+ use Mollie\Api\Resources\MandateCollection;
10
+ use Mollie\Api\Types\MandateMethod;
11
+ use Mollie\Api\Types\MandateStatus;
12
+
13
+ class MandateEndpointTest extends BaseEndpointTest
14
+ {
15
+
16
+ public function testCreateWorks()
17
+ {
18
+ $this->mockApiCall(
19
+ new Request('POST', '/v2/customers/cst_FhQJRw4s2n/mandates'),
20
+ new Response(
21
+ 200,
22
+ [],
23
+ '{
24
+ "resource": "mandate",
25
+ "id": "mdt_AcQl5fdL4h",
26
+ "status": "valid",
27
+ "method": "directdebit",
28
+ "details": {
29
+ "consumerName": "John Doe",
30
+ "consumerAccount": "NL55INGB0000000000",
31
+ "consumerBic": "INGBNL2A"
32
+ },
33
+ "mandateReference": null,
34
+ "signatureDate": "2018-05-07",
35
+ "createdAt": "2018-05-07T10:49:08+00:00",
36
+ "_links": {
37
+ "self": {
38
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h",
39
+ "type": "application/hal+json"
40
+ },
41
+ "customer": {
42
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
43
+ "type": "application/hal+json"
44
+ },
45
+ "documentation": {
46
+ "href": "https://mollie.com/en/docs/reference/customers/create-mandate",
47
+ "type": "text/html"
48
+ }
49
+ }
50
+ }'
51
+ )
52
+ );
53
+
54
+ $customer = $this->getCustomer();
55
+
56
+ /** @var Mandate $mandate */
57
+ $mandate = $customer->createMandate([
58
+ "consumerName" => "John Doe",
59
+ "method" => "directdebit",
60
+ "consumerBic" => "INGBNL2A",
61
+ "consumerAccount" => "NL55INGB0000000000"
62
+ ]);
63
+
64
+ $this->assertInstanceOf(Mandate::class, $mandate);
65
+ $this->assertEquals("mandate", $mandate->resource);
66
+ $this->assertEquals(MandateStatus::STATUS_VALID, $mandate->status);
67
+ $this->assertEquals("directdebit", $mandate->method);
68
+ $this->assertEquals((object) ["consumerName" => "John Doe", "consumerAccount" => "NL55INGB0000000000", "consumerBic" => "INGBNL2A"], $mandate->details);
69
+ $this->assertNull($mandate->mandateReference);
70
+ $this->assertEquals("2018-05-07", $mandate->signatureDate);
71
+ $this->assertEquals("2018-05-07T10:49:08+00:00", $mandate->createdAt);
72
+
73
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h", "type" => "application/hal+json"];
74
+ $this->assertEquals($selfLink, $mandate->_links->self);
75
+
76
+ $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"];
77
+ $this->assertEquals($customerLink, $mandate->_links->customer);
78
+
79
+ $documentationLink = (object)["href" => "https://mollie.com/en/docs/reference/customers/create-mandate", "type" => "text/html"];
80
+ $this->assertEquals($documentationLink, $mandate->_links->documentation);
81
+ }
82
+
83
+ public function testGetWorks()
84
+ {
85
+ $this->mockApiCall(
86
+ new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h'),
87
+ new Response(
88
+ 200,
89
+ [],
90
+ '{
91
+ "resource": "mandate",
92
+ "id": "mdt_AcQl5fdL4h",
93
+ "status": "valid",
94
+ "method": "directdebit",
95
+ "details": {
96
+ "consumerName": "John Doe",
97
+ "consumerAccount": "NL55INGB0000000000",
98
+ "consumerBic": "INGBNL2A"
99
+ },
100
+ "mandateReference": null,
101
+ "signatureDate": "2018-05-07",
102
+ "createdAt": "2018-05-07T10:49:08+00:00",
103
+ "_links": {
104
+ "self": {
105
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h",
106
+ "type": "application/hal+json"
107
+ },
108
+ "customer": {
109
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
110
+ "type": "application/hal+json"
111
+ },
112
+ "documentation": {
113
+ "href": "https://mollie.com/en/docs/reference/customers/create-mandate",
114
+ "type": "text/html"
115
+ }
116
+ }
117
+ }'
118
+ )
119
+ );
120
+
121
+ $customer = $this->getCustomer();
122
+
123
+ /** @var Mandate $mandate */
124
+ $mandate = $customer->getMandate("mdt_AcQl5fdL4h");
125
+
126
+ $this->assertInstanceOf(Mandate::class, $mandate);
127
+ $this->assertEquals("mandate", $mandate->resource);
128
+ $this->assertEquals(MandateStatus::STATUS_VALID, $mandate->status);
129
+ $this->assertEquals(MandateMethod::DIRECTDEBIT, $mandate->method);
130
+ $this->assertEquals((object) ["consumerName" => "John Doe", "consumerAccount" => "NL55INGB0000000000", "consumerBic" => "INGBNL2A"], $mandate->details);
131
+ $this->assertNull($mandate->mandateReference);
132
+ $this->assertEquals("2018-05-07", $mandate->signatureDate);
133
+ $this->assertEquals("2018-05-07T10:49:08+00:00", $mandate->createdAt);
134
+
135
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h", "type" => "application/hal+json"];
136
+ $this->assertEquals($selfLink, $mandate->_links->self);
137
+
138
+ $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"];
139
+ $this->assertEquals($customerLink, $mandate->_links->customer);
140
+
141
+ $documentationLink = (object)["href" => "https://mollie.com/en/docs/reference/customers/create-mandate", "type" => "text/html"];
142
+ $this->assertEquals($documentationLink, $mandate->_links->documentation);
143
+ }
144
+
145
+ public function testListWorks()
146
+ {
147
+ $this->mockApiCall(
148
+ new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'),
149
+ new Response(
150
+ 200,
151
+ [],
152
+ '{
153
+ "_embedded": {
154
+ "mandates": [
155
+ {
156
+ "resource": "mandate",
157
+ "id": "mdt_AcQl5fdL4h",
158
+ "status": "valid",
159
+ "method": "directdebit",
160
+ "details": {
161
+ "consumerName": "John Doe",
162
+ "consumerAccount": "NL55INGB0000000000",
163
+ "consumerBic": "INGBNL2A"
164
+ },
165
+ "mandateReference": null,
166
+ "signatureDate": "2018-05-07",
167
+ "createdAt": "2018-05-07T10:49:08+00:00",
168
+ "_links": {
169
+ "self": {
170
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h",
171
+ "type": "application/hal+json"
172
+ },
173
+ "customer": {
174
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
175
+ "type": "application/hal+json"
176
+ }
177
+ }
178
+ }
179
+ ]
180
+ },
181
+ "count": 1,
182
+ "_links": {
183
+ "documentation": {
184
+ "href": "https://mollie.com/en/docs/reference/customers/list-mandates",
185
+ "type": "text/html"
186
+ },
187
+ "self": {
188
+ "href": "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50",
189
+ "type": "application/hal+json"
190
+ },
191
+ "previous": null,
192
+ "next": null
193
+ }
194
+ }'
195
+ )
196
+ );
197
+
198
+ $customer = $this->getCustomer();
199
+
200
+ /** @var Mandate $mandate */
201
+ $mandates = $customer->mandates();
202
+ $this->assertInstanceOf(MandateCollection::class, $mandates);
203
+
204
+ foreach ($mandates as $mandate) {
205
+ $this->assertInstanceOf(Mandate::class, $mandate);
206
+ $this->assertEquals("mandate", $mandate->resource);
207
+ $this->assertEquals(MandateStatus::STATUS_VALID, $mandate->status);
208
+
209
+ $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"];
210
+ $this->assertEquals($customerLink, $mandate->_links->customer);
211
+ }
212
+
213
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50", "type" => "application/hal+json"];
214
+ $this->assertEquals($selfLink, $mandates->_links->self);
215
+
216
+ $documentationLink = (object)["href" => "https://mollie.com/en/docs/reference/customers/list-mandates", "type" => "text/html"];
217
+ $this->assertEquals($documentationLink, $mandates->_links->documentation);
218
+ }
219
+
220
+ public function testCustomerHasValidMandateWhenTrue()
221
+ {
222
+ $this->mockApiCall(
223
+ new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'),
224
+ new Response(
225
+ 200,
226
+ [],
227
+ '{
228
+ "_embedded": {
229
+ "mandates": [
230
+ {
231
+ "resource": "mandate",
232
+ "id": "mdt_AcQl5fdL4h",
233
+ "status": "valid",
234
+ "method": "directdebit",
235
+ "details": {
236
+ "consumerName": "John Doe",
237
+ "consumerAccount": "NL55INGB0000000000",
238
+ "consumerBic": "INGBNL2A"
239
+ },
240
+ "mandateReference": null,
241
+ "signatureDate": "2018-05-07",
242
+ "createdAt": "2018-05-07T10:49:08+00:00",
243
+ "_links": {
244
+ "self": {
245
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h",
246
+ "type": "application/hal+json"
247
+ },
248
+ "customer": {
249
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
250
+ "type": "application/hal+json"
251
+ }
252
+ }
253
+ }
254
+ ]
255
+ },
256
+ "count": 1,
257
+ "_links": {
258
+ "documentation": {
259
+ "href": "https://mollie.com/en/docs/reference/customers/list-mandates",
260
+ "type": "text/html"
261
+ },
262
+ "self": {
263
+ "href": "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50",
264
+ "type": "application/hal+json"
265
+ },
266
+ "previous": null,
267
+ "next": null
268
+ }
269
+ }'
270
+ )
271
+ );
272
+
273
+ $customer = $this->getCustomer();
274
+
275
+ $this->assertTrue($customer->hasValidMandate());
276
+ }
277
+
278
+ public function testCustomerHasValidMandateWhenFalse()
279
+ {
280
+ $this->mockApiCall(
281
+ new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'),
282
+ new Response(
283
+ 200,
284
+ [],
285
+ '{
286
+ "_embedded": {
287
+ "mandates": []
288
+ },
289
+ "count": 0,
290
+ "_links": {
291
+ "documentation": {
292
+ "href": "https://mollie.com/en/docs/reference/customers/list-mandates",
293
+ "type": "text/html"
294
+ },
295
+ "self": {
296
+ "href": "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50",
297
+ "type": "application/hal+json"
298
+ },
299
+ "previous": null,
300
+ "next": null
301
+ }
302
+ }'
303
+ )
304
+ );
305
+
306
+ $customer = $this->getCustomer();
307
+
308
+ $this->assertFalse($customer->hasValidMandate());
309
+ }
310
+
311
+ public function testCustomerHasValidMandateForMethodWhenFalse()
312
+ {
313
+ $this->mockApiCall(
314
+ new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'),
315
+ new Response(
316
+ 200,
317
+ [],
318
+ '{
319
+ "_embedded": {
320
+ "mandates": []
321
+ },
322
+ "count": 0,
323
+ "_links": {
324
+ "documentation": {
325
+ "href": "https://mollie.com/en/docs/reference/customers/list-mandates",
326
+ "type": "text/html"
327
+ },
328
+ "self": {
329
+ "href": "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50",
330
+ "type": "application/hal+json"
331
+ },
332
+ "previous": null,
333
+ "next": null
334
+ }
335
+ }'
336
+ )
337
+ );
338
+
339
+ $customer = $this->getCustomer();
340
+
341
+ $this->assertFalse($customer->hasValidMandateForMethod('directdebit'));
342
+ }
343
+
344
+ public function testCustomerHasValidMandateForMethodWhenTrue()
345
+ {
346
+ $this->mockApiCall(
347
+ new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'),
348
+ new Response(
349
+ 200,
350
+ [],
351
+ '{
352
+ "_embedded": {
353
+ "mandates": [
354
+ {
355
+ "resource": "mandate",
356
+ "id": "mdt_AcQl5fdL4h",
357
+ "status": "valid",
358
+ "method": "directdebit",
359
+ "details": {
360
+ "consumerName": "John Doe",
361
+ "consumerAccount": "NL55INGB0000000000",
362
+ "consumerBic": "INGBNL2A"
363
+ },
364
+ "mandateReference": null,
365
+ "signatureDate": "2018-05-07",
366
+ "createdAt": "2018-05-07T10:49:08+00:00",
367
+ "_links": {
368
+ "self": {
369
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h",
370
+ "type": "application/hal+json"
371
+ },
372
+ "customer": {
373
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
374
+ "type": "application/hal+json"
375
+ }
376
+ }
377
+ }
378
+ ]
379
+ },
380
+ "count": 1,
381
+ "_links": {
382
+ "documentation": {
383
+ "href": "https://mollie.com/en/docs/reference/customers/list-mandates",
384
+ "type": "text/html"
385
+ },
386
+ "self": {
387
+ "href": "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50",
388
+ "type": "application/hal+json"
389
+ },
390
+ "previous": null,
391
+ "next": null
392
+ }
393
+ }'
394
+ )
395
+ );
396
+
397
+ $customer = $this->getCustomer();
398
+
399
+ $this->assertTrue($customer->hasValidMandateForMethod('directdebit'));
400
+ }
401
+
402
+ /**
403
+ * @return Customer
404
+ */
405
+ private function getCustomer()
406
+ {
407
+ $customerJson = '{
408
+ "resource": "customer",
409
+ "id": "cst_FhQJRw4s2n",
410
+ "mode": "test",
411
+ "name": "John Doe",
412
+ "email": "johndoe@example.org",
413
+ "locale": null,
414
+ "metadata": null,
415
+ "recentlyUsedMethods": [],
416
+ "createdAt": "2018-04-19T08:49:01+00:00",
417
+ "_links": {
418
+ "documentation": {
419
+ "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer",
420
+ "type": "text/html"
421
+ }
422
+ }
423
+ }';
424
+
425
+ return $this->copy(json_decode($customerJson), new Customer($this->apiClient));
426
+ }
427
+
428
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/MethodEndpointTest.php ADDED
@@ -0,0 +1,641 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Issuer;
8
+ use Mollie\Api\Resources\IssuerCollection;
9
+ use Mollie\Api\Resources\Method;
10
+ use Mollie\Api\Resources\MethodCollection;
11
+ use Mollie\Api\Resources\MethodPrice;
12
+ use Mollie\Api\Resources\MethodPriceCollection;
13
+ use stdClass;
14
+ use Tests\Mollie\TestHelpers\AmountObjectTestHelpers;
15
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
16
+
17
+ class MethodEndpointTest extends BaseEndpointTest
18
+ {
19
+ use LinkObjectTestHelpers;
20
+ use AmountObjectTestHelpers;
21
+
22
+ public function testGetMethod()
23
+ {
24
+ $this->mockApiCall(
25
+ new Request('GET', '/v2/methods/ideal'),
26
+ new Response(
27
+ 200,
28
+ [],
29
+ '{
30
+ "resource": "method",
31
+ "id": "ideal",
32
+ "description": "iDEAL",
33
+ "minimumAmount": {
34
+ "value": "0.01",
35
+ "currency": "EUR"
36
+ },
37
+ "maximumAmount": {
38
+ "value": "50000.00",
39
+ "currency": "EUR"
40
+ },
41
+ "image": {
42
+ "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png",
43
+ "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png"
44
+ },
45
+ "_links": {
46
+ "self": {
47
+ "href": "https://api.mollie.com/v2/methods/ideal",
48
+ "type": "application/hal+json"
49
+ },
50
+ "documentation": {
51
+ "href": "https://docs.mollie.com/reference/v2/methods-api/get-method",
52
+ "type": "text/html"
53
+ }
54
+ }
55
+ }'
56
+ )
57
+ );
58
+
59
+ $idealMethod = $this->apiClient->methods->get('ideal');
60
+
61
+ $this->assertInstanceOf(Method::class, $idealMethod);
62
+ $this->assertEquals('ideal', $idealMethod->id);
63
+ $this->assertEquals('iDEAL', $idealMethod->description);
64
+ $this->assertAmountObject(0.01, 'EUR', $idealMethod->minimumAmount);
65
+ $this->assertAmountObject(50000, 'EUR', $idealMethod->maximumAmount);
66
+ $this->assertEquals('https://www.mollie.com/images/payscreen/methods/ideal.png', $idealMethod->image->size1x);
67
+ $this->assertEquals('https://www.mollie.com/images/payscreen/methods/ideal%402x.png', $idealMethod->image->size2x);
68
+
69
+ $this->assertLinkObject(
70
+ 'https://api.mollie.com/v2/methods/ideal',
71
+ 'application/hal+json',
72
+ $idealMethod->_links->self
73
+ );
74
+
75
+ $this->assertLinkObject(
76
+ 'https://docs.mollie.com/reference/v2/methods-api/get-method',
77
+ 'text/html',
78
+ $idealMethod->_links->documentation
79
+ );
80
+ }
81
+
82
+ public function testGetMethodWithIncludeIssuers()
83
+ {
84
+ $this->mockApiCall(
85
+ new Request('GET', '/v2/methods/ideal?include=issuers'),
86
+ new Response(
87
+ 200,
88
+ [],
89
+ '{
90
+ "resource": "method",
91
+ "id": "ideal",
92
+ "description": "iDEAL",
93
+ "minimumAmount": {
94
+ "value": "0.01",
95
+ "currency": "EUR"
96
+ },
97
+ "maximumAmount": {
98
+ "value": "50000.00",
99
+ "currency": "EUR"
100
+ },
101
+ "image": {
102
+ "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png",
103
+ "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png"
104
+ },
105
+ "issuers": [
106
+ {
107
+ "resource": "issuer",
108
+ "id": "ideal_TESTNL99",
109
+ "name": "TBM Bank",
110
+ "method": "ideal",
111
+ "image": {
112
+ "size1x": "https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/TESTNL99.png",
113
+ "size2x": "https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/TESTNL99.png"
114
+ }
115
+ }
116
+ ],
117
+
118
+ "_links": {
119
+ "self": {
120
+ "href": "https://api.mollie.com/v2/methods/ideal",
121
+ "type": "application/hal+json"
122
+ },
123
+ "documentation": {
124
+ "href": "https://docs.mollie.com/reference/v2/methods-api/get-method",
125
+ "type": "text/html"
126
+ }
127
+ }
128
+ }'
129
+ )
130
+ );
131
+
132
+ $idealMethod = $this->apiClient->methods->get('ideal', ['include' => 'issuers']);
133
+
134
+ $this->assertInstanceOf(Method::class, $idealMethod);
135
+ $this->assertEquals('ideal', $idealMethod->id);
136
+ $this->assertEquals('iDEAL', $idealMethod->description);
137
+ $this->assertAmountObject(0.01, 'EUR', $idealMethod->minimumAmount);
138
+ $this->assertAmountObject(50000, 'EUR', $idealMethod->maximumAmount);
139
+ $this->assertEquals('https://www.mollie.com/images/payscreen/methods/ideal.png', $idealMethod->image->size1x);
140
+ $this->assertEquals('https://www.mollie.com/images/payscreen/methods/ideal%402x.png', $idealMethod->image->size2x);
141
+
142
+ $issuers = $idealMethod->issuers();
143
+ $this->assertInstanceOf(IssuerCollection::class, $issuers);
144
+ $this->assertCount(1, $issuers);
145
+
146
+ $testIssuer = $issuers[0];
147
+
148
+ $this->assertInstanceOf(Issuer::class, $testIssuer);
149
+ $this->assertEquals('ideal_TESTNL99', $testIssuer->id);
150
+ $this->assertEquals('TBM Bank', $testIssuer->name);
151
+ $this->assertEquals('ideal', $testIssuer->method);
152
+
153
+ $expectedSize1xImageLink = 'https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/TESTNL99.png';
154
+ $this->assertEquals($expectedSize1xImageLink, $testIssuer->image->size1x);
155
+
156
+ $expectedSize2xImageLink = 'https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/TESTNL99.png';
157
+ $this->assertEquals($expectedSize2xImageLink, $testIssuer->image->size2x);
158
+
159
+ $this->assertLinkObject(
160
+ 'https://api.mollie.com/v2/methods/ideal',
161
+ 'application/hal+json',
162
+ $idealMethod->_links->self
163
+ );
164
+
165
+ $this->assertLinkObject(
166
+ 'https://docs.mollie.com/reference/v2/methods-api/get-method',
167
+ 'text/html',
168
+ $idealMethod->_links->documentation
169
+ );
170
+ }
171
+
172
+ public function testGetMethodWithIncludePricing()
173
+ {
174
+ $this->mockApiCall(
175
+ new Request('GET', '/v2/methods/ideal?include=pricing'),
176
+ new Response(
177
+ 200,
178
+ [],
179
+ '{
180
+ "resource": "method",
181
+ "id": "ideal",
182
+ "description": "iDEAL",
183
+ "minimumAmount": {
184
+ "value": "0.01",
185
+ "currency": "EUR"
186
+ },
187
+ "maximumAmount": {
188
+ "value": "50000.00",
189
+ "currency": "EUR"
190
+ },
191
+ "image": {
192
+ "size1x": "https://www.mollie.com/external/icons/payment-methods/ideal.png",
193
+ "size2x": "https://www.mollie.com/external/icons/payment-methods/ideal%402x.png",
194
+ "svg": "https://www.mollie.com/external/icons/payment-methods/ideal.svg"
195
+ },
196
+ "pricing": [
197
+ {
198
+ "description": "The Netherlands",
199
+ "fixed": {
200
+ "value": "0.29",
201
+ "currency": "EUR"
202
+ },
203
+ "variable": "0"
204
+ }
205
+ ],
206
+ "_links": {
207
+ "self": {
208
+ "href": "https://api.mollie.com/v2/methods/ideal",
209
+ "type": "application/hal+json"
210
+ },
211
+ "documentation": {
212
+ "href": "https://docs.mollie.com/reference/v2/methods-api/get-method",
213
+ "type": "text/html"
214
+ }
215
+ }
216
+ }'
217
+ )
218
+ );
219
+
220
+ $method = $this->apiClient->methods->get('ideal', ['include' => 'pricing']);
221
+
222
+ $this->assertInstanceOf(Method::class, $method);
223
+ $this->assertEquals('method', $method->resource);
224
+ $this->assertEquals('ideal', $method->id);
225
+ $this->assertEquals('iDEAL', $method->description);
226
+ $this->assertAmountObject(0.01, 'EUR', $method->minimumAmount);
227
+ $this->assertAmountObject(50000, 'EUR', $method->maximumAmount);
228
+ $this->assertEquals(
229
+ 'https://www.mollie.com/external/icons/payment-methods/ideal.png',
230
+ $method->image->size1x);
231
+ $this->assertEquals(
232
+ 'https://www.mollie.com/external/icons/payment-methods/ideal%402x.png',
233
+ $method->image->size2x);
234
+
235
+ $this->assertEquals(
236
+ 'https://www.mollie.com/external/icons/payment-methods/ideal.svg',
237
+ $method->image->svg);
238
+
239
+ $this->assertLinkObject(
240
+ 'https://api.mollie.com/v2/methods/ideal',
241
+ 'application/hal+json',
242
+ $method->_links->self
243
+ );
244
+
245
+ $this->assertLinkObject(
246
+ 'https://docs.mollie.com/reference/v2/methods-api/get-method',
247
+ 'text/html',
248
+ $method->_links->documentation
249
+ );
250
+
251
+ $price = $method->pricing[0];
252
+
253
+ $this->assertEquals('The Netherlands', $price->description);
254
+ $this->assertAmountObject(0.29, 'EUR', $price->fixed);
255
+ $this->assertEquals('0', $price->variable);
256
+
257
+ $method_prices = $method->pricing();
258
+
259
+ $this->assertInstanceOf(MethodPriceCollection::class, $method_prices);
260
+
261
+ $method_price = $method_prices[0];
262
+ $this->assertInstanceOf(MethodPrice::class, $method_price);
263
+ $this->assertAmountObject(0.29, 'EUR', $method_price->fixed);
264
+ $this->assertEquals('0', $method_price->variable);
265
+ }
266
+
267
+ public function testGetTranslatedMethod()
268
+ {
269
+ $this->mockApiCall(
270
+ new Request('GET', '/v2/methods/sofort?locale=de_DE'),
271
+ new Response(
272
+ 200,
273
+ [],
274
+ '{
275
+ "resource": "method",
276
+ "id": "sofort",
277
+ "description": "SOFORT \u00dcberweisung",
278
+ "minimumAmount": {
279
+ "value": "0.01",
280
+ "currency": "EUR"
281
+ },
282
+ "maximumAmount": {
283
+ "value": "50000.00",
284
+ "currency": "EUR"
285
+ },
286
+ "image": {
287
+ "size1x": "https://www.mollie.com/images/payscreen/methods/sofort.png",
288
+ "size2x": "https://www.mollie.com/images/payscreen/methods/sofort%402x.png"
289
+ },
290
+ "_links": {
291
+ "self": {
292
+ "href": "https://api.mollie.com/v2/methods/sofort",
293
+ "type": "application/hal+json"
294
+ },
295
+ "documentation": {
296
+ "href": "https://docs.mollie.com/reference/v2/methods-api/get-method",
297
+ "type": "text/html"
298
+ }
299
+ }
300
+ }'
301
+ )
302
+ );
303
+
304
+ $method = $this->apiClient->methods->get('sofort', ['locale' => 'de_DE']);
305
+
306
+ $this->assertInstanceOf(Method::class, $method);
307
+ $this->assertEquals('sofort', $method->id);
308
+ $this->assertEquals('SOFORT Überweisung', $method->description);
309
+ $this->assertAmountObject(0.01, 'EUR', $method->minimumAmount);
310
+ $this->assertAmountObject(50000, 'EUR', $method->maximumAmount);
311
+
312
+ $amount = new Stdclass();
313
+ $amount->size1x = 'https://www.mollie.com/images/payscreen/methods/sofort.png';
314
+ $amount->size2x = 'https://www.mollie.com/images/payscreen/methods/sofort%402x.png';
315
+
316
+ $selfLink = (object)[
317
+ 'href' => 'https://api.mollie.com/v2/methods/sofort',
318
+ 'type' => 'application/hal+json'
319
+ ];
320
+ $this->assertEquals($selfLink, $method->_links->self);
321
+
322
+ $documentationLink = (object)[
323
+ 'href' => 'https://docs.mollie.com/reference/v2/methods-api/get-method',
324
+ 'type' => 'text/html'
325
+ ];
326
+
327
+ $this->assertEquals($documentationLink, $method->_links->documentation);
328
+ }
329
+
330
+ public function testListAllActiveMethods()
331
+ {
332
+ $this->mockApiCall(
333
+ new Request('GET', '/v2/methods'),
334
+ new Response(
335
+ 200,
336
+ [],
337
+ '{
338
+ "_embedded": {
339
+ "methods": [
340
+ {
341
+ "resource": "method",
342
+ "id": "ideal",
343
+ "description": "iDEAL",
344
+ "minimumAmount": {
345
+ "value": "0.01",
346
+ "currency": "EUR"
347
+ },
348
+ "maximumAmount": {
349
+ "value": "50000.00",
350
+ "currency": "EUR"
351
+ },
352
+ "image": {
353
+ "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png",
354
+ "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png"
355
+ },
356
+ "_links": {
357
+ "self": {
358
+ "href": "https://api.mollie.com/v2/methods/ideal",
359
+ "type": "application/hal+json"
360
+ }
361
+ }
362
+ },
363
+ {
364
+ "resource": "method",
365
+ "id": "creditcard",
366
+ "description": "Credit card",
367
+ "minimumAmount": {
368
+ "value": "0.01",
369
+ "currency": "EUR"
370
+ },
371
+ "maximumAmount": {
372
+ "value": "2000.00",
373
+ "currency": "EUR"
374
+ },
375
+ "image": {
376
+ "size1x": "https://www.mollie.com/images/payscreen/methods/creditcard.png",
377
+ "size2x": "https://www.mollie.com/images/payscreen/methods/creditcard%402x.png"
378
+ },
379
+ "_links": {
380
+ "self": {
381
+ "href": "https://api.mollie.com/v2/methods/creditcard",
382
+ "type": "application/hal+json"
383
+ }
384
+ }
385
+ },
386
+ {
387
+ "resource": "method",
388
+ "id": "mistercash",
389
+ "description": "Bancontact",
390
+ "minimumAmount": {
391
+ "value": "0.02",
392
+ "currency": "EUR"
393
+ },
394
+ "maximumAmount": {
395
+ "value": "50000.00",
396
+ "currency": "EUR"
397
+ },
398
+ "image": {
399
+ "size1x": "https://www.mollie.com/images/payscreen/methods/mistercash.png",
400
+ "size2x": "https://www.mollie.com/images/payscreen/methods/mistercash%402x.png"
401
+ },
402
+ "_links": {
403
+ "self": {
404
+ "href": "https://api.mollie.com/v2/methods/mistercash",
405
+ "type": "application/hal+json"
406
+ }
407
+ }
408
+ },
409
+ {
410
+ "resource": "method",
411
+ "id": "giftcard",
412
+ "description": "Gift cards",
413
+ "minimumAmount": {
414
+ "value": "0.01",
415
+ "currency": "EUR"
416
+ },
417
+ "maximumAmount": null,
418
+ "image": {
419
+ "size1x": "https://www.mollie.com/images/payscreen/methods/giftcard.png",
420
+ "size2x": "https://www.mollie.com/images/payscreen/methods/giftcard%402x.png"
421
+ },
422
+ "_links": {
423
+ "self": {
424
+ "href": "https://api.mollie.com/v2/methods/giftcard",
425
+ "type": "application/hal+json"
426
+ }
427
+ }
428
+ }
429
+ ]
430
+ },
431
+ "count": 4,
432
+ "_links": {
433
+ "documentation": {
434
+ "href": "https://docs.mollie.com/reference/v2/methods-api/list-methods",
435
+ "type": "text/html"
436
+ },
437
+ "self": {
438
+ "href": "http://api.mollie.com/v2/methods",
439
+ "type": "application/hal+json"
440
+ }
441
+ }
442
+ }'
443
+ )
444
+ );
445
+
446
+ $methods = $this->apiClient->methods->allActive();
447
+
448
+ $this->assertInstanceOf(MethodCollection::class, $methods);
449
+ $this->assertEquals(4, $methods->count);
450
+ $this->assertCount(4, $methods);
451
+
452
+ $documentationLink = (object)[
453
+ 'href' => 'https://docs.mollie.com/reference/v2/methods-api/list-methods',
454
+ 'type' => 'text/html'
455
+ ];
456
+ $this->assertEquals($documentationLink, $methods->_links->documentation);
457
+
458
+ $selfLink = (object)[
459
+ 'href' => 'http://api.mollie.com/v2/methods',
460
+ 'type' => 'application/hal+json'
461
+ ];
462
+ $this->assertEquals($selfLink, $methods->_links->self);
463
+
464
+ $creditcardMethod = $methods[1];
465
+
466
+ $this->assertInstanceOf(Method::class, $creditcardMethod);
467
+ $this->assertEquals('creditcard', $creditcardMethod->id);
468
+ $this->assertEquals('Credit card', $creditcardMethod->description);
469
+ $this->assertAmountObject(0.01, 'EUR', $creditcardMethod->minimumAmount);
470
+ $this->assertAmountObject(2000, 'EUR', $creditcardMethod->maximumAmount);
471
+ $this->assertEquals('https://www.mollie.com/images/payscreen/methods/creditcard.png', $creditcardMethod->image->size1x);
472
+ $this->assertEquals('https://www.mollie.com/images/payscreen/methods/creditcard%402x.png', $creditcardMethod->image->size2x);
473
+
474
+ $selfLink = (object)[
475
+ 'href' => 'https://api.mollie.com/v2/methods/creditcard',
476
+ 'type' => 'application/hal+json'
477
+ ];
478
+ $this->assertEquals($selfLink, $creditcardMethod->_links->self);
479
+ }
480
+
481
+ public function testListAllAvailableMethods()
482
+ {
483
+ $this->mockApiCall(
484
+ new Request('GET', '/v2/methods/all?include=pricing'),
485
+ new Response(
486
+ 200,
487
+ [],
488
+ '{
489
+ "_embedded": {
490
+ "methods": [
491
+ {
492
+ "resource": "method",
493
+ "id": "ideal",
494
+ "description": "iDEAL",
495
+ "minimumAmount": {
496
+ "value": "0.01",
497
+ "currency": "EUR"
498
+ },
499
+ "maximumAmount": {
500
+ "value": "50000.00",
501
+ "currency": "EUR"
502
+ },
503
+ "image": {
504
+ "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png",
505
+ "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png"
506
+ },
507
+ "pricing": [
508
+ {
509
+ "description": "Netherlands",
510
+ "fixed": {
511
+ "value": "0.29",
512
+ "currency": "EUR"
513
+ },
514
+ "variable": "0"
515
+ }
516
+ ],
517
+ "_links": {
518
+ "self": {
519
+ "href": "https://api.mollie.com/v2/methods/ideal",
520
+ "type": "application/hal+json"
521
+ }
522
+ }
523
+ },
524
+ {
525
+ "resource": "method",
526
+ "id": "creditcard",
527
+ "description": "Credit card",
528
+ "minimumAmount": {
529
+ "value": "0.01",
530
+ "currency": "EUR"
531
+ },
532
+ "maximumAmount": {
533
+ "value": "2000.00",
534
+ "currency": "EUR"
535
+ },
536
+ "image": {
537
+ "size1x": "https://www.mollie.com/images/payscreen/methods/creditcard.png",
538
+ "size2x": "https://www.mollie.com/images/payscreen/methods/creditcard%402x.png"
539
+ },
540
+ "_links": {
541
+ "self": {
542
+ "href": "https://api.mollie.com/v2/methods/creditcard",
543
+ "type": "application/hal+json"
544
+ }
545
+ }
546
+ },
547
+ {
548
+ "resource": "method",
549
+ "id": "mistercash",
550
+ "description": "Bancontact",
551
+ "minimumAmount": {
552
+ "value": "0.02",
553
+ "currency": "EUR"
554
+ },
555
+ "maximumAmount": {
556
+ "value": "50000.00",
557
+ "currency": "EUR"
558
+ },
559
+ "image": {
560
+ "size1x": "https://www.mollie.com/images/payscreen/methods/mistercash.png",
561
+ "size2x": "https://www.mollie.com/images/payscreen/methods/mistercash%402x.png"
562
+ },
563
+ "_links": {
564
+ "self": {
565
+ "href": "https://api.mollie.com/v2/methods/mistercash",
566
+ "type": "application/hal+json"
567
+ }
568
+ }
569
+ },
570
+ {
571
+ "resource": "method",
572
+ "id": "giftcard",
573
+ "description": "Gift cards",
574
+ "minimumAmount": {
575
+ "value": "0.01",
576
+ "currency": "EUR"
577
+ },
578
+ "maximumAmount": null,
579
+ "image": {
580
+ "size1x": "https://www.mollie.com/images/payscreen/methods/giftcard.png",
581
+ "size2x": "https://www.mollie.com/images/payscreen/methods/giftcard%402x.png"
582
+ },
583
+ "_links": {
584
+ "self": {
585
+ "href": "https://api.mollie.com/v2/methods/giftcard",
586
+ "type": "application/hal+json"
587
+ }
588
+ }
589
+ }
590
+ ]
591
+ },
592
+ "count": 4,
593
+ "_links": {
594
+ "documentation": {
595
+ "href": "https://docs.mollie.com/reference/v2/methods-api/list-methods",
596
+ "type": "text/html"
597
+ },
598
+ "self": {
599
+ "href": "http://api.mollie.com/v2/methods",
600
+ "type": "application/hal+json"
601
+ }
602
+ }
603
+ }'
604
+ )
605
+ );
606
+
607
+ $methods = $this->apiClient->methods->allAvailable(['include' => 'pricing']);
608
+
609
+ $this->assertInstanceOf(MethodCollection::class, $methods);
610
+ $this->assertEquals(4, $methods->count);
611
+ $this->assertCount(4, $methods);
612
+
613
+ $this->assertLinkObject(
614
+ 'https://docs.mollie.com/reference/v2/methods-api/list-methods',
615
+ 'text/html',
616
+ $methods->_links->documentation
617
+ );
618
+
619
+ $this->assertLinkObject(
620
+ 'http://api.mollie.com/v2/methods',
621
+ 'application/hal+json',
622
+ $methods->_links->self
623
+ );
624
+
625
+ $creditcardMethod = $methods[1];
626
+
627
+ $this->assertInstanceOf(Method::class, $creditcardMethod);
628
+ $this->assertEquals('creditcard', $creditcardMethod->id);
629
+ $this->assertEquals('Credit card', $creditcardMethod->description);
630
+ $this->assertAmountObject(0.01, 'EUR', $creditcardMethod->minimumAmount);
631
+ $this->assertAmountObject(2000, 'EUR', $creditcardMethod->maximumAmount);
632
+ $this->assertEquals('https://www.mollie.com/images/payscreen/methods/creditcard.png', $creditcardMethod->image->size1x);
633
+ $this->assertEquals('https://www.mollie.com/images/payscreen/methods/creditcard%402x.png', $creditcardMethod->image->size2x);
634
+
635
+ $this->assertLinkObject(
636
+ 'https://api.mollie.com/v2/methods/creditcard',
637
+ 'application/hal+json',
638
+ $creditcardMethod->_links->self
639
+ );
640
+ }
641
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/OnboardingEndpointTest.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ declare(strict_types=1);
4
+
5
+ namespace Tests\Mollie\API\Endpoints;
6
+
7
+ use GuzzleHttp\Psr7\Request;
8
+ use GuzzleHttp\Psr7\Response;
9
+ use Mollie\Api\Resources\Onboarding;
10
+ use Mollie\Api\Types\OnboardingStatus;
11
+
12
+ final class OnboardingEndpointTest extends BaseEndpointTest
13
+ {
14
+ public function testGetWorks()
15
+ {
16
+ $this->mockApiCall(
17
+ new Request('GET', '/v2/onboarding/me'),
18
+ new Response(
19
+ 200,
20
+ [],
21
+ '{
22
+ "resource": "onboarding",
23
+ "name": "Mollie B.V.",
24
+ "signedUpAt": "2018-12-20T10:49:08+00:00",
25
+ "status": "completed",
26
+ "canReceivePayments": true,
27
+ "canReceiveSettlements": true,
28
+ "_links": {
29
+ "self": {
30
+ "href": "https://api.mollie.com/v2/onboarding/me",
31
+ "type": "application/hal+json"
32
+ },
33
+ "onboarding": {
34
+ "href": "https://www.mollie.com/dashboard/onboarding",
35
+ "type": "text/html"
36
+ },
37
+ "organization": {
38
+ "href": "https://api.mollie.com/v2/organization/org_12345",
39
+ "type": "application/hal+json"
40
+ },
41
+ "documentation": {
42
+ "href": "https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status",
43
+ "type": "text/html"
44
+ }
45
+ }
46
+ }'
47
+ )
48
+ );
49
+
50
+ $onboarding = $this->apiClient->onboarding->get();
51
+
52
+ $this->assertInstanceOf(Onboarding::class, $onboarding);
53
+ $this->assertEquals("onboarding", $onboarding->resource);
54
+ $this->assertEquals("Mollie B.V.", $onboarding->name);
55
+ $this->assertEquals(OnboardingStatus::COMPLETED, $onboarding->status);
56
+ $this->assertEquals("2018-12-20T10:49:08+00:00", $onboarding->signedUpAt);
57
+ $this->assertEquals(true, $onboarding->canReceivePayments);
58
+ $this->assertEquals(true, $onboarding->canReceiveSettlements);
59
+
60
+ $selfLink = (object)['href' => 'https://api.mollie.com/v2/onboarding/me', 'type' => 'application/hal+json'];
61
+ $this->assertEquals($selfLink, $onboarding->_links->self);
62
+
63
+ $onboardingLink = (object)['href' => 'https://www.mollie.com/dashboard/onboarding', 'type' => 'text/html'];
64
+ $this->assertEquals($onboardingLink, $onboarding->_links->onboarding);
65
+
66
+ $organizationLink = (object)['href' => 'https://api.mollie.com/v2/organization/org_12345', 'type' => 'application/hal+json'];
67
+ $this->assertEquals($organizationLink, $onboarding->_links->organization);
68
+
69
+ $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status', 'type' => 'text/html'];
70
+ $this->assertEquals($documentationLink, $onboarding->_links->documentation);
71
+ }
72
+
73
+ public function testSubmitWorks()
74
+ {
75
+ $this->mockApiCall(
76
+ new Request('POST', '/v2/onboarding/me'),
77
+ new Response(204)
78
+ );
79
+
80
+ $this->apiClient->onboarding->submit();
81
+ }
82
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/OrderEndpointTest.php ADDED
@@ -0,0 +1,1085 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Order;
8
+ use Mollie\Api\Resources\OrderCollection;
9
+ use Mollie\Api\Resources\Payment;
10
+ use Mollie\Api\Resources\PaymentCollection;
11
+ use Mollie\Api\Resources\Shipment;
12
+ use Mollie\Api\Types\OrderLineStatus;
13
+ use Mollie\Api\Types\OrderLineType;
14
+ use Mollie\Api\Types\OrderStatus;
15
+ use Tests\Mollie\TestHelpers\AmountObjectTestHelpers;
16
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
17
+ use stdClass;
18
+
19
+ class OrderEndpointTest extends BaseEndpointTest
20
+ {
21
+ use LinkObjectTestHelpers;
22
+ use AmountObjectTestHelpers;
23
+
24
+ public function testCreateOrder()
25
+ {
26
+ $this->mockApiCall(
27
+ new Request(
28
+ "POST",
29
+ "/v2/orders",
30
+ [],
31
+ '{
32
+ "amount": {
33
+ "value": "1027.99",
34
+ "currency": "EUR"
35
+ },
36
+ "billingAddress": {
37
+ "organizationName": "Organization Name LTD.",
38
+ "streetAndNumber": "Keizersgracht 313",
39
+ "postalCode": "1016 EE",
40
+ "city": "Amsterdam",
41
+ "country": "nl",
42
+ "givenName": "Luke",
43
+ "familyName": "Skywalker",
44
+ "email": "luke@skywalker.com"
45
+ },
46
+ "shippingAddress": {
47
+ "organizationName": "Organization Name LTD.",
48
+ "streetAndNumber": "Keizersgracht 313",
49
+ "postalCode": "1016 EE",
50
+ "city": "Amsterdam",
51
+ "country": "nl",
52
+ "givenName": "Luke",
53
+ "familyName": "Skywalker",
54
+ "email": "luke@skywalker.com"
55
+ },
56
+ "metadata": {
57
+ "order_id": "1337",
58
+ "description": "Lego cars"
59
+ },
60
+ "consumerDateOfBirth": "1958-01-31",
61
+ "orderNumber": "1337",
62
+ "locale": "nl_NL",
63
+ "method" : "klarnapaylater",
64
+ "redirectUrl": "https://example.org/redirect",
65
+ "webhookUrl": "https://example.org/webhook",
66
+ "lines": [
67
+ {
68
+ "sku": "5702016116977",
69
+ "name": "LEGO 42083 Bugatti Chiron",
70
+ "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
71
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
72
+ "quantity": 2,
73
+ "unitPrice": {
74
+ "currency": "EUR",
75
+ "value": "399.00"
76
+ },
77
+ "vatRate": "21.00",
78
+ "vatAmount": {
79
+ "currency": "EUR",
80
+ "value": "121.14"
81
+ },
82
+ "discountAmount": {
83
+ "currency": "EUR",
84
+ "value": "100.00"
85
+ },
86
+ "totalAmount": {
87
+ "currency": "EUR",
88
+ "value": "698.00"
89
+ }
90
+ },
91
+ {
92
+ "type": "digital",
93
+ "sku": "5702015594028",
94
+ "name": "LEGO 42056 Porsche 911 GT3 RS",
95
+ "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
96
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$",
97
+ "quantity": 1,
98
+ "unitPrice": {
99
+ "currency": "EUR",
100
+ "value": "329.99"
101
+ },
102
+ "vatRate": "21.00",
103
+ "vatAmount": {
104
+ "currency": "EUR",
105
+ "value": "57.27"
106
+ },
107
+ "totalAmount": {
108
+ "currency": "EUR",
109
+ "value": "329.99"
110
+ }
111
+ }
112
+ ]
113
+ }'
114
+ ),
115
+ new Response(
116
+ 201,
117
+ [],
118
+ $this->getOrderResponseFixture("ord_pbjz8x")
119
+ )
120
+ );
121
+
122
+ $order = $this->apiClient->orders->create([
123
+ "amount" => [
124
+ "value" => "1027.99",
125
+ "currency" => "EUR"
126
+ ],
127
+ "billingAddress" => [
128
+ "organizationName" => "Organization Name LTD.",
129
+ "streetAndNumber" => "Keizersgracht 313",
130
+ "postalCode" => "1016 EE",
131
+ "city" => "Amsterdam",
132
+ "country" => "nl",
133
+ "givenName" => "Luke",
134
+ "familyName" => "Skywalker",
135
+ "email" => "luke@skywalker.com",
136
+ ],
137
+ "shippingAddress" => [
138
+ "organizationName" => "Organization Name LTD.",
139
+ "streetAndNumber" => "Keizersgracht 313",
140
+ "postalCode" => "1016 EE",
141
+ "city" => "Amsterdam",
142
+ "country" => "nl",
143
+ "givenName" => "Luke",
144
+ "familyName" => "Skywalker",
145
+ "email" => "luke@skywalker.com",
146
+ ],
147
+ "metadata" => [
148
+ "order_id" => "1337",
149
+ "description" => "Lego cars"
150
+ ],
151
+ "consumerDateOfBirth" => "1958-01-31",
152
+ "locale" => "nl_NL",
153
+ "orderNumber" => "1337",
154
+ "redirectUrl" => "https://example.org/redirect",
155
+ "webhookUrl" => "https://example.org/webhook",
156
+ "method" => "klarnapaylater",
157
+ "lines" => [
158
+ [
159
+ "sku" => "5702016116977",
160
+ "name" => "LEGO 42083 Bugatti Chiron",
161
+ "productUrl" => "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
162
+ "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$',
163
+ "quantity" => 2,
164
+ "vatRate" => "21.00",
165
+ "unitPrice" => [
166
+ "currency" => "EUR",
167
+ "value" => "399.00"
168
+ ],
169
+ "totalAmount" => [
170
+ "currency" => "EUR",
171
+ "value" => "698.00"
172
+ ],
173
+ "discountAmount" => [
174
+ "currency" => "EUR",
175
+ "value" => "100.00"
176
+ ],
177
+ "vatAmount" => [
178
+ "currency" => "EUR",
179
+ "value" => "121.14"
180
+ ]
181
+ ],
182
+ [
183
+ "type" => "digital",
184
+ "sku" => "5702015594028",
185
+ "name" => "LEGO 42056 Porsche 911 GT3 RS",
186
+ "productUrl" => "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
187
+ "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$',
188
+ "quantity" => 1,
189
+ "vatRate" => "21.00",
190
+ "unitPrice" => [
191
+ "currency" => "EUR",
192
+ "value" => "329.99"
193
+ ],
194
+ "totalAmount" => [
195
+ "currency" => "EUR",
196
+ "value" => "329.99"
197
+ ],
198
+ "vatAmount" => [
199
+ "currency" => "EUR",
200
+ "value" => "57.27"
201
+ ]
202
+ ]
203
+ ]
204
+ ]);
205
+
206
+ $this->assertOrder($order, 'ord_pbjz8x');
207
+ }
208
+
209
+ public function testGetOrderDirectly()
210
+ {
211
+ $this->mockApiCall(
212
+ new Request(
213
+ "GET",
214
+ "/v2/orders/ord_pbjz8x"
215
+ ),
216
+ new Response(
217
+ 200,
218
+ [],
219
+ $this->getOrderResponseFixture("ord_pbjz8x")
220
+ )
221
+ );
222
+
223
+ $order = $this->apiClient->orders->get('ord_pbjz8x');
224
+
225
+ $this->assertOrder($order, 'ord_pbjz8x');
226
+ }
227
+
228
+ public function testGetOrderDirectlyIncludingPayments()
229
+ {
230
+ $this->mockApiCall(
231
+ new Request(
232
+ "GET",
233
+ "/v2/orders/ord_kEn1PlbGa?embed=payments"
234
+ ),
235
+ new Response(
236
+ 200,
237
+ [],
238
+ '{
239
+ "resource": "order",
240
+ "id": "ord_kEn1PlbGa",
241
+ "profileId": "pfl_URR55HPMGx",
242
+ "method": "klarnapaylater",
243
+ "amount": {
244
+ "value": "1027.99",
245
+ "currency": "EUR"
246
+ },
247
+ "status": "created",
248
+ "isCancelable": true,
249
+ "metadata": null,
250
+ "createdAt": "2018-08-02T09:29:56+00:00",
251
+ "expiresAt": "2018-08-30T09:29:56+00:00",
252
+ "mode": "live",
253
+ "locale": "nl_NL",
254
+ "billingAddress": {
255
+ "organizationName": "Mollie B.V.",
256
+ "streetAndNumber": "Keizersgracht 313",
257
+ "postalCode": "1016 EE",
258
+ "city": "Amsterdam",
259
+ "country": "nl",
260
+ "givenName": "Luke",
261
+ "familyName": "Skywalker",
262
+ "email": "luke@skywalker.com"
263
+ },
264
+ "orderNumber": "18475",
265
+ "shippingAddress": {
266
+ "organizationName": "Mollie B.V.",
267
+ "streetAndNumber": "Keizersgracht 313",
268
+ "postalCode": "1016 EE",
269
+ "city": "Amsterdam",
270
+ "country": "nl",
271
+ "givenName": "Luke",
272
+ "familyName": "Skywalker",
273
+ "email": "luke@skywalker.com"
274
+ },
275
+ "redirectUrl": "https://example.org/redirect",
276
+ "lines": [
277
+ {
278
+ "resource": "orderline",
279
+ "id": "odl_dgtxyl",
280
+ "orderId": "ord_pbjz8x",
281
+ "name": "LEGO 42083 Bugatti Chiron",
282
+ "sku": "5702016116977",
283
+ "type": "physical",
284
+ "status": "created",
285
+ "metadata": null,
286
+ "isCancelable": false,
287
+ "quantity": 2,
288
+ "quantityShipped": 0,
289
+ "amountShipped": {
290
+ "value": "0.00",
291
+ "currency": "EUR"
292
+ },
293
+ "quantityRefunded": 0,
294
+ "amountRefunded": {
295
+ "value": "0.00",
296
+ "currency": "EUR"
297
+ },
298
+ "quantityCanceled": 0,
299
+ "amountCanceled": {
300
+ "value": "0.00",
301
+ "currency": "EUR"
302
+ },
303
+ "shippableQuantity": 0,
304
+ "refundableQuantity": 0,
305
+ "cancelableQuantity": 0,
306
+ "unitPrice": {
307
+ "value": "399.00",
308
+ "currency": "EUR"
309
+ },
310
+ "vatRate": "21.00",
311
+ "vatAmount": {
312
+ "value": "121.14",
313
+ "currency": "EUR"
314
+ },
315
+ "discountAmount": {
316
+ "value": "100.00",
317
+ "currency": "EUR"
318
+ },
319
+ "totalAmount": {
320
+ "value": "698.00",
321
+ "currency": "EUR"
322
+ },
323
+ "createdAt": "2018-08-02T09:29:56+00:00",
324
+ "_links": {
325
+ "productUrl": {
326
+ "href": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
327
+ "type": "text/html"
328
+ },
329
+ "imageUrl": {
330
+ "href": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
331
+ "type": "text/html"
332
+ }
333
+ }
334
+ },
335
+ {
336
+ "resource": "orderline",
337
+ "id": "odl_jp31jz",
338
+ "orderId": "ord_pbjz8x",
339
+ "name": "LEGO 42056 Porsche 911 GT3 RS",
340
+ "sku": "5702015594028",
341
+ "type": "physical",
342
+ "status": "created",
343
+ "metadata": null,
344
+ "isCancelable": false,
345
+ "quantity": 1,
346
+ "quantityShipped": 0,
347
+ "amountShipped": {
348
+ "value": "0.00",
349
+ "currency": "EUR"
350
+ },
351
+ "quantityRefunded": 0,
352
+ "amountRefunded": {
353
+ "value": "0.00",
354
+ "currency": "EUR"
355
+ },
356
+ "quantityCanceled": 0,
357
+ "amountCanceled": {
358
+ "value": "0.00",
359
+ "currency": "EUR"
360
+ },
361
+ "shippableQuantity": 0,
362
+ "refundableQuantity": 0,
363
+ "cancelableQuantity": 0,
364
+ "unitPrice": {
365
+ "value": "329.99",
366
+ "currency": "EUR"
367
+ },
368
+ "vatRate": "21.00",
369
+ "vatAmount": {
370
+ "value": "57.27",
371
+ "currency": "EUR"
372
+ },
373
+ "totalAmount": {
374
+ "value": "329.99",
375
+ "currency": "EUR"
376
+ },
377
+ "createdAt": "2018-08-02T09:29:56+00:00",
378
+ "_links": {
379
+ "productUrl": {
380
+ "href": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
381
+ "type": "text/html"
382
+ },
383
+ "imageUrl": {
384
+ "href": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$",
385
+ "type": "text/html"
386
+ }
387
+ }
388
+ }
389
+ ],
390
+ "_embedded": {
391
+ "payments": [
392
+ {
393
+ "resource": "payment",
394
+ "id": "tr_ncaPcAhuUV",
395
+ "mode": "live",
396
+ "createdAt": "2018-09-07T12:00:05+00:00",
397
+ "amount": {
398
+ "value": "1027.99",
399
+ "currency": "EUR"
400
+ },
401
+ "description": "Order #1337 (Lego cars)",
402
+ "method": null,
403
+ "metadata": null,
404
+ "status": "open",
405
+ "isCancelable": false,
406
+ "locale": "nl_NL",
407
+ "profileId": "pfl_URR55HPMGx",
408
+ "orderId": "ord_kEn1PlbGa",
409
+ "sequenceType": "oneoff",
410
+ "redirectUrl": "https://example.org/redirect",
411
+ "_links": {
412
+ "self": {
413
+ "href": "https://api.mollie.com/v2/payments/tr_ncaPcAhuUV",
414
+ "type": "application/hal+json"
415
+ },
416
+ "checkout": {
417
+ "href": "https://www.mollie.com/payscreen/select-method/ncaPcAhuUV",
418
+ "type": "text/html"
419
+ },
420
+ "order": {
421
+ "href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa",
422
+ "type": "application/hal+json"
423
+ }
424
+ }
425
+ }
426
+ ]
427
+ },
428
+ "_links": {
429
+ "self": {
430
+ "href": "https://api.mollie.com/v2/orders/ord_pbjz8x",
431
+ "type": "application/hal+json"
432
+ },
433
+ "checkout": {
434
+ "href": "https://www.mollie.com/payscreen/order/checkout/pbjz8x",
435
+ "type": "text/html"
436
+ },
437
+ "documentation": {
438
+ "href": "https://docs.mollie.com/reference/v2/orders-api/get-order",
439
+ "type": "text/html"
440
+ }
441
+ }
442
+ }'
443
+ )
444
+ );
445
+
446
+ $order = $this->apiClient->orders->get('ord_kEn1PlbGa', ['embed' => 'payments']);
447
+
448
+ $this->assertInstanceOf(Order::class, $order);
449
+ $this->assertEquals('ord_kEn1PlbGa', $order->id);
450
+
451
+ $payments = $order->payments();
452
+ $this->assertInstanceOf(PaymentCollection::class, $payments);
453
+
454
+ $payment = $payments[0];
455
+ $this->assertInstanceOf(Payment::class, $payment);
456
+ $this->assertEquals('tr_ncaPcAhuUV', $payment->id);
457
+ $this->assertEquals('2018-09-07T12:00:05+00:00', $payment->createdAt);
458
+ $this->assertAmountObject('1027.99', 'EUR', $payment->amount);
459
+ $this->assertEquals('Order #1337 (Lego cars)', $payment->description);
460
+ $this->assertNull($payment->method);
461
+ $this->assertNull($payment->metadata);
462
+ $this->assertEquals('open', $payment->status);
463
+ $this->assertFalse($payment->isCancelable);
464
+ $this->assertEquals('nl_NL', $payment->locale);
465
+ $this->assertEquals('pfl_URR55HPMGx', $payment->profileId);
466
+ $this->assertEquals('ord_kEn1PlbGa', $payment->orderId);
467
+ $this->assertEquals('oneoff', $payment->sequenceType);
468
+ $this->assertEquals('https://example.org/redirect', $payment->redirectUrl);
469
+ $this->assertLinkObject(
470
+ 'https://api.mollie.com/v2/payments/tr_ncaPcAhuUV',
471
+ 'application/hal+json',
472
+ $payment->_links->self
473
+ );
474
+ $this->assertLinkObject(
475
+ 'https://www.mollie.com/payscreen/select-method/ncaPcAhuUV',
476
+ 'text/html',
477
+ $payment->_links->checkout
478
+ );
479
+ $this->assertLinkObject(
480
+ 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa',
481
+ 'application/hal+json',
482
+ $payment->_links->order
483
+ );
484
+ }
485
+
486
+ public function testGetOrderOnShipmentResource()
487
+ {
488
+ $this->mockApiCall(
489
+ new Request(
490
+ "GET",
491
+ "/v2/orders/ord_pbjz8x"
492
+ ),
493
+ new Response(
494
+ 200,
495
+ [],
496
+ $this->getOrderResponseFixture("ord_pbjz8x")
497
+ )
498
+ );
499
+
500
+ $shipment = $this->getShipment("shp_3wmsgCJN4U", "ord_pbjz8x");
501
+ $order = $shipment->order();
502
+
503
+ $this->assertOrder($order, 'ord_pbjz8x');
504
+ }
505
+
506
+ public function testListOrders()
507
+ {
508
+ $this->mockApiCall(
509
+ new Request("GET", "/v2/orders"),
510
+ new Response(
511
+ 200,
512
+ [],
513
+ '{
514
+ "count": 3,
515
+ "_embedded": {
516
+ "orders": [
517
+ ' . $this->getOrderResponseFixture("ord_pbjz1x") . ',
518
+ ' . $this->getOrderResponseFixture("ord_pbjz2y") . ',
519
+ ' . $this->getOrderResponseFixture("ord_pbjz3z") . '
520
+ ]
521
+ },
522
+ "_links": {
523
+ "self": {
524
+ "href": "https://api.mollie.com/v2/orders",
525
+ "type": "application/hal+json"
526
+ },
527
+ "previous": null,
528
+ "next": {
529
+ "href": "https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS",
530
+ "type": "application/hal+json"
531
+ },
532
+ "documentation": {
533
+ "href": "https://docs.mollie.com/reference/v2/orders-api/list-orders",
534
+ "type": "text/html"
535
+ }
536
+ }
537
+ }'
538
+ )
539
+ );
540
+
541
+ $orders = $this->apiClient->orders->page();
542
+
543
+ $this->assertInstanceOf(OrderCollection::class, $orders);
544
+ $this->assertEquals(3, $orders->count);
545
+ $this->assertEquals(3, count($orders));
546
+
547
+ $this->assertNull($orders->_links->previous);
548
+ $selfLink = $this->createLinkObject(
549
+ "https://api.mollie.com/v2/orders",
550
+ "application/hal+json"
551
+ );
552
+ $this->assertEquals($selfLink, $orders->_links->self);
553
+
554
+ $nextLink = $this->createLinkObject(
555
+ "https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS",
556
+ "application/hal+json"
557
+ );
558
+ $this->assertEquals($nextLink, $orders->_links->next);
559
+
560
+ $documentationLink = $this->createLinkObject(
561
+ "https://docs.mollie.com/reference/v2/orders-api/list-orders",
562
+ "text/html"
563
+ );
564
+ $this->assertEquals($documentationLink, $orders->_links->documentation);
565
+
566
+ $this->assertOrder($orders[0], 'ord_pbjz1x');
567
+ $this->assertOrder($orders[1], 'ord_pbjz2y');
568
+ $this->assertOrder($orders[2], 'ord_pbjz3z');
569
+ }
570
+
571
+ public function testCancelOrderDirectly()
572
+ {
573
+ $this->mockApiCall(
574
+ new Request("DELETE", "/v2/orders/ord_pbjz1x"),
575
+ new Response(
576
+ 200,
577
+ [],
578
+ $this->getOrderResponseFixture(
579
+ 'ord_pbjz1x',
580
+ OrderStatus::STATUS_CANCELED
581
+ )
582
+ )
583
+ );
584
+ $order = $this->apiClient->orders->cancel('ord_pbjz1x');
585
+ $this->assertOrder($order, 'ord_pbjz1x', OrderStatus::STATUS_CANCELED);
586
+ }
587
+
588
+ public function testCancelOrderOnResource()
589
+ {
590
+ $this->mockApiCall(
591
+ new Request("DELETE", "/v2/orders/ord_pbjz1x"),
592
+ new Response(
593
+ 200,
594
+ [],
595
+ $this->getOrderResponseFixture(
596
+ 'ord_pbjz1x',
597
+ OrderStatus::STATUS_CANCELED
598
+ )
599
+ )
600
+ );
601
+ $order = $this->getOrder('ord_pbjz1x');
602
+ $canceledOrder = $order->cancel();
603
+ $this->assertOrder($canceledOrder, 'ord_pbjz1x', OrderStatus::STATUS_CANCELED);
604
+ }
605
+
606
+ public function testCancelOrderLines()
607
+ {
608
+ $this->mockApiCall(
609
+ new Request(
610
+ "DELETE",
611
+ "/v2/orders/ord_8wmqcHMN4U/lines",
612
+ [],
613
+ '{
614
+ "lines": [
615
+ {
616
+ "id": "odl_dgtxyl",
617
+ "quantity": 1
618
+ }
619
+ ]
620
+ }'
621
+ ),
622
+ new Response(204)
623
+ );
624
+
625
+ $order = $this->getOrder('ord_8wmqcHMN4U');
626
+
627
+ $result = $order->cancelLines([
628
+ 'lines' => [
629
+ [
630
+ 'id' => 'odl_dgtxyl',
631
+ 'quantity' => 1,
632
+ ],
633
+ ],
634
+ ]);
635
+
636
+ $this->assertNull($result);
637
+ }
638
+
639
+ public function testCancelAllOrderLines()
640
+ {
641
+ $this->mockApiCall(
642
+ new Request(
643
+ "DELETE",
644
+ "/v2/orders/ord_8wmqcHMN4U/lines",
645
+ [],
646
+ '{
647
+ "lines": [],
648
+ "foo": "bar"
649
+ }'
650
+ ),
651
+ new Response(204)
652
+ );
653
+
654
+ $order = $this->getOrder('ord_8wmqcHMN4U');
655
+
656
+ $result = $order->cancelAllLines([
657
+ 'foo' => 'bar',
658
+ ]);
659
+
660
+ $this->assertNull($result);
661
+ }
662
+
663
+ /** @test */
664
+ public function testUpdateOrder()
665
+ {
666
+ $this->mockApiCall(
667
+ new Request(
668
+ "PATCH",
669
+ "/v2/orders/ord_pbjz8x",
670
+ [],
671
+ '{
672
+ "billingAddress": {
673
+ "organizationName": "Organization Name LTD.",
674
+ "streetAndNumber": "Keizersgracht 313",
675
+ "postalCode": "1234AB",
676
+ "city": "Amsterdam",
677
+ "country": "NL",
678
+ "givenName": "Piet",
679
+ "familyName": "Mondriaan",
680
+ "email": "piet@mondriaan.com",
681
+ "region": "Noord-Holland",
682
+ "title": "Dhr",
683
+ "phone": "+31208202070"
684
+ },
685
+ "shippingAddress": {
686
+ "organizationName": "Organization Name LTD.",
687
+ "streetAndNumber": "Keizersgracht 313",
688
+ "postalCode": "1016 EE",
689
+ "city": "Amsterdam",
690
+ "country": "nl",
691
+ "givenName": "Luke",
692
+ "familyName": "Skywalker",
693
+ "email": "luke@skywalker.com"
694
+ },
695
+ "orderNumber": "16738"
696
+ }'
697
+ ),
698
+ new Response(
699
+ 200,
700
+ [],
701
+ $this->getOrderResponseFixture(
702
+ "ord_pbjz8x",
703
+ OrderStatus::STATUS_CREATED,
704
+ "16738"
705
+ )
706
+ )
707
+ );
708
+
709
+ /** @var Order $order */
710
+ $order = $this->getOrder("ord_pbjz8x");
711
+
712
+ $order->billingAddress->organizationName = "Organization Name LTD.";
713
+ $order->billingAddress->streetAndNumber = "Keizersgracht 313";
714
+ $order->billingAddress->city = "Amsterdam";
715
+ $order->billingAddress->region = "Noord-Holland";
716
+ $order->billingAddress->postalCode = "1234AB";
717
+ $order->billingAddress->country = "NL";
718
+ $order->billingAddress->title = "Dhr";
719
+ $order->billingAddress->givenName = "Piet";
720
+ $order->billingAddress->familyName = "Mondriaan";
721
+ $order->billingAddress->email = "piet@mondriaan.com";
722
+ $order->billingAddress->phone = "+31208202070";
723
+ $order->orderNumber = "16738";
724
+ $order = $order->update();
725
+
726
+ $this->assertOrder($order, "ord_pbjz8x", OrderStatus::STATUS_CREATED, "16738");
727
+ }
728
+
729
+ protected function assertOrder($order, $order_id, $order_status = OrderStatus::STATUS_CREATED, $orderNumber = "1337")
730
+ {
731
+ $this->assertInstanceOf(Order::class, $order);
732
+ $this->assertEquals('order', $order->resource);
733
+ $this->assertEquals($order_id, $order->id);
734
+ $this->assertEquals('pfl_URR55HPMGx', $order->profileId);
735
+ $this->assertEquals('live', $order->mode);
736
+ $this->assertEquals('klarnapaylater', $order->method);
737
+ $this->assertEquals('2018-08-02T09:29:56+00:00', $order->createdAt);
738
+
739
+ $this->assertAmountObject('1027.99', 'EUR', $order->amount);
740
+ $this->assertAmountObject('0.00', 'EUR', $order->amountCaptured);
741
+ $this->assertAmountObject('0.00', 'EUR', $order->amountRefunded);
742
+
743
+ $this->assertEquals((object) [
744
+ 'order_id' => '1337',
745
+ 'description' => 'Lego cars',
746
+ ], $order->metadata);
747
+
748
+ $this->assertEquals($order_status, $order->status);
749
+
750
+ $billingAddress = new stdClass();
751
+ $billingAddress->organizationName = "Organization Name LTD.";
752
+ $billingAddress->streetAndNumber = "Keizersgracht 313";
753
+ $billingAddress->postalCode = "1016 EE";
754
+ $billingAddress->city = "Amsterdam";
755
+ $billingAddress->country = "nl";
756
+ $billingAddress->givenName = "Luke";
757
+ $billingAddress->familyName = "Skywalker";
758
+ $billingAddress->email = "luke@skywalker.com";
759
+ $this->assertEquals($billingAddress, $order->billingAddress);
760
+
761
+ $shippingAddress = new stdClass();
762
+ $shippingAddress->organizationName = "Organization Name LTD.";
763
+ $shippingAddress->streetAndNumber = "Keizersgracht 313";
764
+ $shippingAddress->postalCode = "1016 EE";
765
+ $shippingAddress->city = "Amsterdam";
766
+ $shippingAddress->country = "nl";
767
+ $shippingAddress->givenName = "Luke";
768
+ $shippingAddress->familyName = "Skywalker";
769
+ $shippingAddress->email = "luke@skywalker.com";
770
+ $this->assertEquals($shippingAddress, $order->shippingAddress);
771
+
772
+ $this->assertEquals($orderNumber, $order->orderNumber);
773
+ $this->assertEquals('nl_NL', $order->locale);
774
+
775
+ $this->assertEquals("https://example.org/redirect", $order->redirectUrl);
776
+ $this->assertEquals("https://example.org/webhook", $order->webhookUrl);
777
+
778
+ $links = (object )[
779
+ 'self' => $this->createLinkObject(
780
+ 'https://api.mollie.com/v2/orders/' . $order_id,
781
+ 'application/hal+json'
782
+ ),
783
+ 'checkout' => $this->createLinkObject(
784
+ 'https://www.mollie.com/payscreen/select-method/7UhSN1zuXS',
785
+ 'text/html'
786
+ ),
787
+ 'documentation' => $this->createLinkObject(
788
+ 'https://docs.mollie.com/reference/v2/orders-api/get-order',
789
+ 'text/html'
790
+ ),
791
+ ];
792
+ $this->assertEquals($links, $order->_links);
793
+
794
+ $line1 = new stdClass();
795
+ $line1->resource = "orderline";
796
+ $line1->id = "odl_dgtxyl";
797
+ $line1->orderId = $order_id;
798
+ $line1->name = "LEGO 42083 Bugatti Chiron";
799
+ $line1->productUrl = "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083";
800
+ $line1->imageUrl = 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$';
801
+ $line1->sku = "5702016116977";
802
+ $line1->type = OrderLineType::TYPE_PHYSICAL;
803
+ $line1->status = OrderLineStatus::STATUS_CREATED;
804
+ $line1->isCancelable = true;
805
+ $line1->quantity = 2;
806
+ $line1->unitPrice = $this->createAmountObject("399.00", "EUR");
807
+ $line1->vatRate = "21.00";
808
+ $line1->vatAmount = $this->createAmountObject("121.14", "EUR");
809
+ $line1->discountAmount = $this->createAmountObject("100.00", "EUR");
810
+ $line1->totalAmount = $this->createAmountObject("698.00", "EUR");
811
+ $line1->createdAt = "2018-08-02T09:29:56+00:00";
812
+ $this->assertEquals($line1, $order->lines[0]);
813
+
814
+ $line2 = new stdClass();
815
+ $line2->resource = "orderline";
816
+ $line2->id = "odl_jp31jz";
817
+ $line2->orderId = $order_id;
818
+ $line2->name = "LEGO 42056 Porsche 911 GT3 RS";
819
+ $line2->productUrl = "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056";
820
+ $line2->imageUrl = 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$';
821
+ $line2->sku = "5702015594028";
822
+ $line2->type = OrderLineType::TYPE_DIGITAL;
823
+ $line2->status = OrderLineStatus::STATUS_CREATED;
824
+ $line2->isCancelable = true;
825
+ $line2->quantity = 1;
826
+ $line2->unitPrice = $this->createAmountObject("329.99", "EUR");
827
+ $line2->vatRate = "21.00";
828
+ $line2->vatAmount = $this->createAmountObject("57.27", "EUR");
829
+ $line2->totalAmount = $this->createAmountObject("329.99", "EUR");
830
+ $line2->createdAt = "2018-08-02T09:29:56+00:00";
831
+ $this->assertEquals($line2, $order->lines[1]);
832
+
833
+ $this->assertNull($order->payments());
834
+ }
835
+
836
+ protected function getOrder($id)
837
+ {
838
+ $orderJson = $this->getOrderResponseFixture($id);
839
+ return $this->copy(json_decode($orderJson), new Order($this->apiClient));
840
+ }
841
+
842
+ protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::STATUS_CREATED, $orderNumber = '1337')
843
+ {
844
+ return str_replace(
845
+ [
846
+ "<<order_id>>",
847
+ "<<order_number>>"
848
+ ],
849
+ [
850
+ $order_id,
851
+ $orderNumber,
852
+ ],
853
+ '{
854
+ "resource": "order",
855
+ "id": "<<order_id>>",
856
+ "profileId": "pfl_URR55HPMGx",
857
+ "amount": {
858
+ "value": "1027.99",
859
+ "currency": "EUR"
860
+ },
861
+ "amountCaptured": {
862
+ "value": "0.00",
863
+ "currency": "EUR"
864
+ },
865
+ "amountRefunded": {
866
+ "value": "0.00",
867
+ "currency": "EUR"
868
+ },
869
+ "status": "' . $order_status . '",
870
+ "metadata": {
871
+ "order_id": "1337",
872
+ "description": "Lego cars"
873
+ },
874
+ "consumerDateOfBirth": "1958-01-31",
875
+ "createdAt": "2018-08-02T09:29:56+00:00",
876
+ "mode": "live",
877
+ "billingAddress": {
878
+ "organizationName": "Organization Name LTD.",
879
+ "streetAndNumber": "Keizersgracht 313",
880
+ "postalCode": "1016 EE",
881
+ "city": "Amsterdam",
882
+ "country": "nl",
883
+ "givenName": "Luke",
884
+ "familyName": "Skywalker",
885
+ "email": "luke@skywalker.com"
886
+ },
887
+ "shippingAddress": {
888
+ "organizationName": "Organization Name LTD.",
889
+ "streetAndNumber": "Keizersgracht 313",
890
+ "postalCode": "1016 EE",
891
+ "city": "Amsterdam",
892
+ "country": "nl",
893
+ "givenName": "Luke",
894
+ "familyName": "Skywalker",
895
+ "email": "luke@skywalker.com"
896
+ },
897
+ "orderNumber": <<order_number>>,
898
+ "locale": "nl_NL",
899
+ "method" : "klarnapaylater",
900
+ "isCancelable": true,
901
+ "redirectUrl": "https://example.org/redirect",
902
+ "webhookUrl": "https://example.org/webhook",
903
+ "lines": [
904
+ {
905
+ "resource": "orderline",
906
+ "id": "odl_dgtxyl",
907
+ "orderId": "<<order_id>>",
908
+ "name": "LEGO 42083 Bugatti Chiron",
909
+ "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
910
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
911
+ "sku": "5702016116977",
912
+ "type": "physical",
913
+ "status": "created",
914
+ "isCancelable": true,
915
+ "quantity": 2,
916
+ "unitPrice": {
917
+ "value": "399.00",
918
+ "currency": "EUR"
919
+ },
920
+ "vatRate": "21.00",
921
+ "vatAmount": {
922
+ "value": "121.14",
923
+ "currency": "EUR"
924
+ },
925
+ "discountAmount": {
926
+ "value": "100.00",
927
+ "currency": "EUR"
928
+ },
929
+ "totalAmount": {
930
+ "value": "698.00",
931
+ "currency": "EUR"
932
+ },
933
+ "createdAt": "2018-08-02T09:29:56+00:00"
934
+ },
935
+ {
936
+ "resource": "orderline",
937
+ "id": "odl_jp31jz",
938
+ "orderId": "<<order_id>>",
939
+ "name": "LEGO 42056 Porsche 911 GT3 RS",
940
+ "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
941
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$",
942
+ "sku": "5702015594028",
943
+ "type": "digital",
944
+ "status": "created",
945
+ "isCancelable": true,
946
+ "quantity": 1,
947
+ "unitPrice": {
948
+ "value": "329.99",
949
+ "currency": "EUR"
950
+ },
951
+ "vatRate": "21.00",
952
+ "vatAmount": {
953
+ "value": "57.27",
954
+ "currency": "EUR"
955
+ },
956
+ "totalAmount": {
957
+ "value": "329.99",
958
+ "currency": "EUR"
959
+ },
960
+ "createdAt": "2018-08-02T09:29:56+00:00"
961
+ }
962
+ ],
963
+ "_links": {
964
+ "self": {
965
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>",
966
+ "type": "application/hal+json"
967
+ },
968
+ "checkout": {
969
+ "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS",
970
+ "type": "text/html"
971
+ },
972
+ "documentation": {
973
+ "href": "https://docs.mollie.com/reference/v2/orders-api/get-order",
974
+ "type": "text/html"
975
+ }
976
+ }
977
+ }'
978
+ );
979
+ }
980
+
981
+ protected function getShipment($shipmentId, $orderId, $orderlineStatus = OrderLineStatus::STATUS_SHIPPING)
982
+ {
983
+ $shipmentJson = $this->getShipmentResponseFixture(
984
+ $shipmentId,
985
+ $orderId,
986
+ $orderlineStatus
987
+ );
988
+ return $this->copy(json_decode($shipmentJson), new Shipment($this->apiClient));
989
+ }
990
+
991
+ protected function getShipmentResponseFixture($shipmentId, $orderId, $orderlineStatus = OrderLineStatus::STATUS_SHIPPING)
992
+ {
993
+ return str_replace(
994
+ [
995
+ "<<order_id>>",
996
+ "<<shipment_id>>",
997
+ "<<orderline_status>>",
998
+ ],
999
+ [
1000
+ $orderId,
1001
+ $shipmentId,
1002
+ $orderlineStatus
1003
+ ],
1004
+ '{
1005
+ "resource": "shipment",
1006
+ "id": "<<shipment_id>>",
1007
+ "orderId": "<<order_id>>",
1008
+ "createdAt": "2018-08-02T09:29:56+00:00",
1009
+ "profileId": "pfl_URR55HPMGx",
1010
+ "lines": [
1011
+ {
1012
+ "resource": "orderline",
1013
+ "id": "odl_dgtxyl",
1014
+ "orderId": "<<order_id>>",
1015
+ "name": "LEGO 42083 Bugatti Chiron",
1016
+ "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
1017
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
1018
+ "sku": "5702016116977",
1019
+ "type": "physical",
1020
+ "status": "<<orderline_status>>",
1021
+ "quantity": 1,
1022
+ "unitPrice": {
1023
+ "value": "399.00",
1024
+ "currency": "EUR"
1025
+ },
1026
+ "vatRate": "21.00",
1027
+ "vatAmount": {
1028
+ "value": "121.14",
1029
+ "currency": "EUR"
1030
+ },
1031
+ "discountAmount": {
1032
+ "value": "100.00",
1033
+ "currency": "EUR"
1034
+ },
1035
+ "totalAmount": {
1036
+ "value": "698.00",
1037
+ "currency": "EUR"
1038
+ },
1039
+ "createdAt": "2018-08-02T09:29:56+00:00"
1040
+ },
1041
+ {
1042
+ "resource": "orderline",
1043
+ "id": "odl_jp31jz",
1044
+ "orderId": "<<order_id>>",
1045
+ "name": "LEGO 42056 Porsche 911 GT3 RS",
1046
+ "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
1047
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$",
1048
+ "sku": "5702015594028",
1049
+ "type": "digital",
1050
+ "status": "<<orderline_status>>",
1051
+ "quantity": 1,
1052
+ "unitPrice": {
1053
+ "value": "329.99",
1054
+ "currency": "EUR"
1055
+ },
1056
+ "vatRate": "21.00",
1057
+ "vatAmount": {
1058
+ "value": "57.27",
1059
+ "currency": "EUR"
1060
+ },
1061
+ "totalAmount": {
1062
+ "value": "329.99",
1063
+ "currency": "EUR"
1064
+ },
1065
+ "createdAt": "2018-08-02T09:29:56+00:00"
1066
+ }
1067
+ ],
1068
+ "_links": {
1069
+ "self": {
1070
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>/shipments/<<shipment_id>>",
1071
+ "type": "application/hal+json"
1072
+ },
1073
+ "order": {
1074
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>",
1075
+ "type": "application/hal+json"
1076
+ },
1077
+ "documentation": {
1078
+ "href": "https://docs.mollie.com/reference/v2/shipments-api/get-shipment",
1079
+ "type": "text/html"
1080
+ }
1081
+ }
1082
+ }'
1083
+ );
1084
+ }
1085
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/OrderLineEndpointTest.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Client;
6
+ use Mollie\Api\Exceptions\ApiException;
7
+ use Mollie\Api\MollieApiClient;
8
+ use Mollie\Api\Resources\Order;
9
+
10
+
11
+ class OrderLineEndpointTest extends BaseEndpointTest
12
+ {
13
+ public function testCancelLinesRequiresLinesArray() {
14
+ $this->expectException(ApiException::class);
15
+
16
+ $this->guzzleClient = $this->createMock(Client::class);
17
+ $this->apiClient = new MollieApiClient($this->guzzleClient);
18
+
19
+ $this->apiClient->orderLines->cancelFor(new Order($this->apiClient), []);
20
+ }
21
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Order;
8
+ use Mollie\Api\Resources\OrderCollection;
9
+ use Mollie\Api\Resources\Payment;
10
+ use Mollie\Api\Resources\Shipment;
11
+ use Mollie\Api\Types\OrderLineStatus;
12
+ use Mollie\Api\Types\OrderLineType;
13
+ use Mollie\Api\Types\OrderStatus;
14
+ use Mollie\Api\Types\PaymentMethod;
15
+ use Mollie\Api\Types\PaymentStatus;
16
+ use Mollie\Api\Types\SequenceType;
17
+ use Tests\Mollie\TestHelpers\AmountObjectTestHelpers;
18
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
19
+ use stdClass;
20
+
21
+ class OrderPaymentEndpointTest extends BaseEndpointTest
22
+ {
23
+ use LinkObjectTestHelpers;
24
+ use AmountObjectTestHelpers;
25
+
26
+ public function testCreateOrderPayment()
27
+ {
28
+ $this->mockApiCall(
29
+ new Request(
30
+ "POST",
31
+ "/v2/orders/ord_stTC2WHAuS/payments",
32
+ [],
33
+ '{
34
+ "method": "banktransfer",
35
+ "dueDate": "2018-12-21"
36
+ }'
37
+ ),
38
+ new Response(
39
+ 201,
40
+ [],
41
+ '{
42
+ "resource": "payment",
43
+ "id": "tr_WDqYK6vllg",
44
+ "mode": "test",
45
+ "amount": {
46
+ "currency": "EUR",
47
+ "value": "698.00"
48
+ },
49
+ "status": "open",
50
+ "description": "Order #1337 (Lego cars)",
51
+ "createdAt": "2018-12-01T17:09:02+00:00",
52
+ "method": "banktransfer",
53
+ "metadata": null,
54
+ "orderId": "ord_stTC2WHAuS",
55
+ "isCancelable": true,
56
+ "locale": "nl_NL",
57
+ "profileId": "pfl_URR55HPMGx",
58
+ "sequenceType": "oneoff",
59
+ "settlementAmount": {
60
+ "value": "698.00",
61
+ "currency": "EUR"
62
+ },
63
+ "_links": {
64
+ "self": {
65
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg",
66
+ "type": "application/hal+json"
67
+ },
68
+ "order": {
69
+ "href": "https://api.mollie.com/v2/orders/ord_stTC2WHAuS",
70
+ "type": "application/hal+json"
71
+ },
72
+ "checkout": {
73
+ "href": "https://www.mollie.com/paymentscreen/testmode/?method=banktransfer&token=fgnwdh",
74
+ "type": "text/html"
75
+ },
76
+ "status": {
77
+ "href": "https://www.mollie.com/paymentscreen/banktransfer/status/fgnwdh",
78
+ "type": "text/html"
79
+ },
80
+ "payOnline": {
81
+ "href": "https://www.mollie.com/paymentscreen/banktransfer/pay-online/fgnwdh",
82
+ "type": "text/html"
83
+ },
84
+ "documentation": {
85
+ "href": "https://docs.mollie.com/reference/v2/orders-api/create-order-payment",
86
+ "type": "text/html"
87
+ }
88
+ }
89
+ }'
90
+ )
91
+ );
92
+
93
+ $order = $this->getOrder('ord_stTC2WHAuS');
94
+
95
+ $payment = $order->createPayment([
96
+ 'method' => 'banktransfer',
97
+ 'dueDate' => '2018-12-21',
98
+ ]);
99
+
100
+ $this->assertNotNull($payment);
101
+ $this->assertInstanceOf(Payment::class, $payment);
102
+ $this->assertEquals('payment', $payment->resource);
103
+ $this->assertEquals('tr_WDqYK6vllg', $payment->id);
104
+ $this->assertEquals('test', $payment->mode);
105
+ $this->assertAmountObject(698, 'EUR', $payment->amount);
106
+ $this->assertEquals('open', $payment->status);
107
+ $this->assertEquals(PaymentStatus::STATUS_OPEN, $payment->status);
108
+ $this->assertEquals('Order #1337 (Lego cars)', $payment->description);
109
+ $this->assertEquals('2018-12-01T17:09:02+00:00', $payment->createdAt);
110
+ $this->assertEquals(PaymentMethod::BANKTRANSFER, $payment->method);
111
+ $this->assertNull($payment->metadata);
112
+ $this->assertEquals('ord_stTC2WHAuS', $payment->orderId);
113
+ $this->assertTrue($payment->isCancelable);
114
+ $this->assertEquals('nl_NL', $payment->locale);
115
+ $this->assertEquals('pfl_URR55HPMGx', $payment->profileId);
116
+ $this->assertEquals(SequenceType::SEQUENCETYPE_ONEOFF, $payment->sequenceType);
117
+ $this->assertAmountObject(698, 'EUR', $payment->settlementAmount);
118
+
119
+ $this->assertLinkObject(
120
+ 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg',
121
+ 'application/hal+json',
122
+ $payment->_links->self
123
+ );
124
+ $this->assertLinkObject(
125
+ 'https://api.mollie.com/v2/orders/ord_stTC2WHAuS',
126
+ 'application/hal+json',
127
+ $payment->_links->order
128
+ );
129
+ $this->assertLinkObject(
130
+ 'https://www.mollie.com/paymentscreen/testmode/?method=banktransfer&token=fgnwdh',
131
+ 'text/html',
132
+ $payment->_links->checkout
133
+ );
134
+ $this->assertLinkObject(
135
+ 'https://www.mollie.com/paymentscreen/banktransfer/status/fgnwdh',
136
+ 'text/html',
137
+ $payment->_links->status
138
+ );
139
+ $this->assertLinkObject(
140
+ 'https://www.mollie.com/paymentscreen/banktransfer/pay-online/fgnwdh',
141
+ 'text/html',
142
+ $payment->_links->payOnline
143
+ );
144
+ $this->assertLinkObject(
145
+ 'https://docs.mollie.com/reference/v2/orders-api/create-order-payment',
146
+ 'text/html',
147
+ $payment->_links->documentation
148
+ );
149
+ }
150
+
151
+ protected function getOrder($id)
152
+ {
153
+ $orderJson = $this->getOrderResponseFixture($id);
154
+ return $this->copy(json_decode($orderJson), new Order($this->apiClient));
155
+ }
156
+
157
+ protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::STATUS_CREATED)
158
+ {
159
+ return str_replace(
160
+ "<<order_id>>",
161
+ $order_id,
162
+ '{
163
+ "resource": "order",
164
+ "id": "<<order_id>>",
165
+ "profileId": "pfl_URR55HPMGx",
166
+ "amount": {
167
+ "value": "1027.99",
168
+ "currency": "EUR"
169
+ },
170
+ "amountCaptured": {
171
+ "value": "0.00",
172
+ "currency": "EUR"
173
+ },
174
+ "amountRefunded": {
175
+ "value": "0.00",
176
+ "currency": "EUR"
177
+ },
178
+ "status": "' . $order_status . '",
179
+ "metadata": {
180
+ "order_id": "1337",
181
+ "description": "Lego cars"
182
+ },
183
+ "consumerDateOfBirth": "1958-01-31",
184
+ "createdAt": "2018-08-02T09:29:56+00:00",
185
+ "mode": "live",
186
+ "billingAddress": {
187
+ "organizationName": "Organization Name LTD.",
188
+ "streetAndNumber": "Keizersgracht 313",
189
+ "postalCode": "1016 EE",
190
+ "city": "Amsterdam",
191
+ "country": "nl",
192
+ "givenName": "Luke",
193
+ "familyName": "Skywalker",
194
+ "email": "luke@skywalker.com"
195
+ },
196
+ "shippingAddress": {
197
+ "organizationName": "Organization Name LTD.",
198
+ "streetAndNumber": "Keizersgracht 313",
199
+ "postalCode": "1016 EE",
200
+ "city": "Amsterdam",
201
+ "country": "nl",
202
+ "givenName": "Luke",
203
+ "familyName": "Skywalker",
204
+ "email": "luke@skywalker.com"
205
+ },
206
+ "orderNumber": "1337",
207
+ "locale": "nl_NL",
208
+ "method" : "klarnapaylater",
209
+ "isCancelable": true,
210
+ "redirectUrl": "https://example.org/redirect",
211
+ "webhookUrl": "https://example.org/webhook",
212
+ "lines": [
213
+ {
214
+ "resource": "orderline",
215
+ "id": "odl_dgtxyl",
216
+ "orderId": "<<order_id>>",
217
+ "name": "LEGO 42083 Bugatti Chiron",
218
+ "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
219
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
220
+ "sku": "5702016116977",
221
+ "type": "physical",
222
+ "status": "created",
223
+ "isCancelable": true,
224
+ "quantity": 2,
225
+ "unitPrice": {
226
+ "value": "399.00",
227
+ "currency": "EUR"
228
+ },
229
+ "vatRate": "21.00",
230
+ "vatAmount": {
231
+ "value": "121.14",
232
+ "currency": "EUR"
233
+ },
234
+ "discountAmount": {
235
+ "value": "100.00",
236
+ "currency": "EUR"
237
+ },
238
+ "totalAmount": {
239
+ "value": "698.00",
240
+ "currency": "EUR"
241
+ },
242
+ "createdAt": "2018-08-02T09:29:56+00:00"
243
+ },
244
+ {
245
+ "resource": "orderline",
246
+ "id": "odl_jp31jz",
247
+ "orderId": "<<order_id>>",
248
+ "name": "LEGO 42056 Porsche 911 GT3 RS",
249
+ "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
250
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$",
251
+ "sku": "5702015594028",
252
+ "type": "digital",
253
+ "status": "created",
254
+ "isCancelable": true,
255
+ "quantity": 1,
256
+ "unitPrice": {
257
+ "value": "329.99",
258
+ "currency": "EUR"
259
+ },
260
+ "vatRate": "21.00",
261
+ "vatAmount": {
262
+ "value": "57.27",
263
+ "currency": "EUR"
264
+ },
265
+ "totalAmount": {
266
+ "value": "329.99",
267
+ "currency": "EUR"
268
+ },
269
+ "createdAt": "2018-08-02T09:29:56+00:00"
270
+ }
271
+ ],
272
+ "_links": {
273
+ "self": {
274
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>",
275
+ "type": "application/hal+json"
276
+ },
277
+ "checkout": {
278
+ "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS",
279
+ "type": "text/html"
280
+ },
281
+ "documentation": {
282
+ "href": "https://docs.mollie.com/reference/v2/orders-api/get-order",
283
+ "type": "text/html"
284
+ }
285
+ }
286
+ }'
287
+ );
288
+ }
289
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php ADDED
@@ -0,0 +1,427 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Order;
8
+ use Mollie\Api\Resources\OrderLine;
9
+ use Mollie\Api\Resources\Refund;
10
+ use Mollie\Api\Resources\RefundCollection;
11
+ use Mollie\Api\Types\OrderStatus;
12
+ use Mollie\Api\Types\RefundStatus;
13
+ use Tests\Mollie\TestHelpers\AmountObjectTestHelpers;
14
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
15
+
16
+ class OrderRefundEndpointTest extends BaseEndpointTest
17
+ {
18
+ use LinkObjectTestHelpers;
19
+ use AmountObjectTestHelpers;
20
+
21
+ public function testCreatePartialOrderRefund()
22
+ {
23
+ $this->mockApiCall(
24
+ new Request(
25
+ "POST",
26
+ "/v2/orders/ord_stTC2WHAuS/refunds",
27
+ [],
28
+ '{
29
+ "lines": [
30
+ {
31
+ "id": "odl_dgtxyl",
32
+ "quantity": 1
33
+ }
34
+ ]
35
+ }'
36
+ ),
37
+ new Response(
38
+ 201,
39
+ [],
40
+ $this->getOrderRefundResponseFixture('re_4qqhO89gsT', 'ord_stTC2WHAuS')
41
+ )
42
+ );
43
+
44
+ $order = $this->getOrder('ord_stTC2WHAuS');
45
+
46
+ $refund = $order->refund([
47
+ 'lines' => [
48
+ [
49
+ 'id' => 'odl_dgtxyl',
50
+ 'quantity' => 1,
51
+ ]
52
+ ],
53
+ ]);
54
+
55
+ $this->assertOrderRefund($refund, 're_4qqhO89gsT');
56
+ }
57
+
58
+ public function testCreateCompleteOrderRefund()
59
+ {
60
+ $this->mockApiCall(
61
+ new Request(
62
+ "POST",
63
+ "/v2/orders/ord_stTC2WHAuS/refunds",
64
+ [],
65
+ '{
66
+ "lines": []
67
+ }'
68
+ ),
69
+ new Response(
70
+ 201,
71
+ [],
72
+ $this->getOrderRefundResponseFixture('re_4qqhO89gsT', 'ord_stTC2WHAuS')
73
+ )
74
+ );
75
+
76
+ $order = $this->getOrder('ord_stTC2WHAuS');
77
+
78
+ $refund = $order->refundAll();
79
+
80
+ $this->assertOrderRefund($refund, 're_4qqhO89gsT');
81
+ }
82
+
83
+ public function testListOrderRefunds()
84
+ {
85
+ $this->mockApiCall(
86
+ new Request(
87
+ "GET",
88
+ "/v2/orders/ord_stTC2WHAuS/refunds"
89
+ ),
90
+ new Response(
91
+ 200,
92
+ [],
93
+ '{
94
+ "count": 1,
95
+ "_embedded": {
96
+ "refunds": [
97
+ {
98
+ "resource": "refund",
99
+ "id": "re_4qqhO89gsT",
100
+ "amount": {
101
+ "currency": "EUR",
102
+ "value": "698.00"
103
+ },
104
+ "status": "pending",
105
+ "createdAt": "2018-03-19T12:33:37+00:00",
106
+ "description": "Item not in stock, refunding",
107
+ "paymentId": "tr_WDqYK6vllg",
108
+ "orderId": "ord_pbjz8x",
109
+ "lines": [
110
+ {
111
+ "resource": "orderline",
112
+ "id": "odl_dgtxyl",
113
+ "orderId": "ord_pbjz8x",
114
+ "name": "LEGO 42083 Bugatti Chiron",
115
+ "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
116
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
117
+ "sku": "5702016116977",
118
+ "type": "physical",
119
+ "status": "refunded",
120
+ "quantity": 2,
121
+ "unitPrice": {
122
+ "value": "399.00",
123
+ "currency": "EUR"
124
+ },
125
+ "vatRate": "21.00",
126
+ "vatAmount": {
127
+ "value": "121.14",
128
+ "currency": "EUR"
129
+ },
130
+ "discountAmount": {
131
+ "value": "100.00",
132
+ "currency": "EUR"
133
+ },
134
+ "totalAmount": {
135
+ "value": "698.00",
136
+ "currency": "EUR"
137
+ },
138
+ "createdAt": "2018-08-02T09:29:56+00:00"
139
+ }
140
+ ],
141
+ "_links": {
142
+ "self": {
143
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT",
144
+ "type": "application/hal+json"
145
+ },
146
+ "payment": {
147
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg",
148
+ "type": "application/hal+json"
149
+ },
150
+ "order": {
151
+ "href": "https://api.mollie.com/v2/orders/ord_pbjz8x",
152
+ "type": "application/hal+json"
153
+ },
154
+ "documentation": {
155
+ "href": "https://docs.mollie.com/reference/v2/refunds-api/get-refund",
156
+ "type": "text/html"
157
+ }
158
+ }
159
+ }
160
+ ]
161
+ },
162
+ "_links": {
163
+ "self": {
164
+ "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/refunds?limit=5",
165
+ "type": "application/hal+json"
166
+ },
167
+ "previous": null,
168
+ "next": {
169
+ "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/refunds?from=re_APBiGPH2vV&limit=5",
170
+ "type": "application/hal+json"
171
+ },
172
+ "documentation": {
173
+ "href": "https://docs.mollie.com/reference/v2/orders-api/list-order-refunds",
174
+ "type": "text/html"
175
+ }
176
+ }
177
+ }'
178
+ )
179
+ );
180
+
181
+ $order = $this->getOrder('ord_stTC2WHAuS');
182
+
183
+ $refunds = $order->refunds();
184
+
185
+ $this->assertInstanceOf(RefundCollection::class, $refunds);
186
+ $this->assertEquals(1, $refunds->count);
187
+ $this->assertCount(1, $refunds);
188
+
189
+ $this->assertOrderRefund($refunds[0], 're_4qqhO89gsT');
190
+ }
191
+
192
+ protected function assertOrderRefund($refund, $refund_id, $refund_status = RefundStatus::STATUS_PENDING)
193
+ {
194
+ $this->assertInstanceOf(Refund::class, $refund);
195
+ $this->assertEquals($refund_id, $refund->id);
196
+ $this->assertAmountObject('698.00', 'EUR', $refund->amount);
197
+
198
+ $this->assertEquals($refund_status, $refund->status);
199
+ $this->assertEquals("2018-03-19T12:33:37+00:00", $refund->createdAt);
200
+ $this->assertEquals("Item not in stock, refunding", $refund->description);
201
+ $this->assertEquals("tr_WDqYK6vllg", $refund->paymentId);
202
+
203
+ $this->assertLinkObject(
204
+ "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/{$refund_id}",
205
+ 'application/hal+json',
206
+ $refund->_links->self
207
+ );
208
+
209
+ $this->assertLinkObject(
210
+ 'https://docs.mollie.com/reference/v2/refunds-api/get-refund',
211
+ 'text/html',
212
+ $refund->_links->documentation
213
+ );
214
+ }
215
+
216
+ protected function getOrderRefundResponseFixture($refund_id, $order_id)
217
+ {
218
+ return str_replace(
219
+ ["<<refund_id>>", "<<order_id>>"],
220
+ [$refund_id, $order_id],
221
+ '{
222
+ "resource": "refund",
223
+ "id": "<<refund_id>>",
224
+ "amount": {
225
+ "currency": "EUR",
226
+ "value": "698.00"
227
+ },
228
+ "status": "pending",
229
+ "createdAt": "2018-03-19T12:33:37+00:00",
230
+ "description": "Item not in stock, refunding",
231
+ "paymentId": "tr_WDqYK6vllg",
232
+ "orderId": "<<order_id>>",
233
+ "lines": [
234
+ {
235
+ "resource": "orderline",
236
+ "id": "odl_dgtxyl",
237
+ "orderId": "<<order_id>>",
238
+ "name": "LEGO 42083 Bugatti Chiron",
239
+ "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
240
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
241
+ "sku": "5702016116977",
242
+ "type": "physical",
243
+ "status": "refunded",
244
+ "quantity": 2,
245
+ "unitPrice": {
246
+ "value": "399.00",
247
+ "currency": "EUR"
248
+ },
249
+ "vatRate": "21.00",
250
+ "vatAmount": {
251
+ "value": "121.14",
252
+ "currency": "EUR"
253
+ },
254
+ "discountAmount": {
255
+ "value": "100.00",
256
+ "currency": "EUR"
257
+ },
258
+ "totalAmount": {
259
+ "value": "698.00",
260
+ "currency": "EUR"
261
+ },
262
+ "createdAt": "2018-08-02T09:29:56+00:00"
263
+ }
264
+ ],
265
+ "_links": {
266
+ "self": {
267
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/<<refund_id>>",
268
+ "type": "application/hal+json"
269
+ },
270
+ "payment": {
271
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg",
272
+ "type": "application/hal+json"
273
+ },
274
+ "order": {
275
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>",
276
+ "type": "application/hal+json"
277
+ },
278
+ "documentation": {
279
+ "href": "https://docs.mollie.com/reference/v2/refunds-api/get-refund",
280
+ "type": "text/html"
281
+ }
282
+ }
283
+ }'
284
+ );
285
+ }
286
+
287
+ protected function getOrder($id)
288
+ {
289
+ $orderJson = $this->getOrderResponseFixture($id);
290
+ return $this->copy(json_decode($orderJson), new Order($this->apiClient));
291
+ }
292
+
293
+ protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::STATUS_CREATED)
294
+ {
295
+ return str_replace(
296
+ "<<order_id>>",
297
+ $order_id,
298
+ '{
299
+ "resource": "order",
300
+ "id": "<<order_id>>",
301
+ "profileId": "pfl_URR55HPMGx",
302
+ "amount": {
303
+ "value": "1027.99",
304
+ "currency": "EUR"
305
+ },
306
+ "amountCaptured": {
307
+ "value": "0.00",
308
+ "currency": "EUR"
309
+ },
310
+ "amountRefunded": {
311
+ "value": "0.00",
312
+ "currency": "EUR"
313
+ },
314
+ "status": "' . $order_status . '",
315
+ "metadata": {
316
+ "order_id": "1337",
317
+ "description": "Lego cars"
318
+ },
319
+ "consumerDateOfBirth": "1958-01-31",
320
+ "createdAt": "2018-08-02T09:29:56+00:00",
321
+ "mode": "live",
322
+ "billingAddress": {
323
+ "streetAndNumber": "Keizersgracht 313",
324
+ "postalCode": "1016 EE",
325
+ "city": "Amsterdam",
326
+ "country": "nl",
327
+ "givenName": "Luke",
328
+ "familyName": "Skywalker",
329
+ "email": "luke@skywalker.com"
330
+ },
331
+ "shippingAddress": {
332
+ "streetAndNumber": "Keizersgracht 313",
333
+ "postalCode": "1016 EE",
334
+ "city": "Amsterdam",
335
+ "country": "nl",
336
+ "givenName": "Luke",
337
+ "familyName": "Skywalker",
338
+ "email": "luke@skywalker.com"
339
+ },
340
+ "orderNumber": "1337",
341
+ "locale": "nl_NL",
342
+ "method" : "klarnapaylater",
343
+ "isCancelable": true,
344
+ "redirectUrl": "https://example.org/redirect",
345
+ "webhookUrl": "https://example.org/webhook",
346
+ "lines": [
347
+ {
348
+ "resource": "orderline",
349
+ "id": "odl_dgtxyl",
350
+ "orderId": "<<order_id>>",
351
+ "name": "LEGO 42083 Bugatti Chiron",
352
+ "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
353
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
354
+ "sku": "5702016116977",
355
+ "type": "physical",
356
+ "status": "created",
357
+ "isCancelable": true,
358
+ "quantity": 2,
359
+ "unitPrice": {
360
+ "value": "399.00",
361
+ "currency": "EUR"
362
+ },
363
+ "vatRate": "21.00",
364
+ "vatAmount": {
365
+ "value": "121.14",
366
+ "currency": "EUR"
367
+ },
368
+ "discountAmount": {
369
+ "value": "100.00",
370
+ "currency": "EUR"
371
+ },
372
+ "totalAmount": {
373
+ "value": "698.00",
374
+ "currency": "EUR"
375
+ },
376
+ "createdAt": "2018-08-02T09:29:56+00:00"
377
+ },
378
+ {
379
+ "resource": "orderline",
380
+ "id": "odl_jp31jz",
381
+ "orderId": "<<order_id>>",
382
+ "name": "LEGO 42056 Porsche 911 GT3 RS",
383
+ "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
384
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$",
385
+ "sku": "5702015594028",
386
+ "type": "digital",
387
+ "status": "created",
388
+ "isCancelable": true,
389
+ "quantity": 1,
390
+ "unitPrice": {
391
+ "value": "329.99",
392
+ "currency": "EUR"
393
+ },
394
+ "vatRate": "21.00",
395
+ "vatAmount": {
396
+ "value": "57.27",
397
+ "currency": "EUR"
398
+ },
399
+ "totalAmount": {
400
+ "value": "329.99",
401
+ "currency": "EUR"
402
+ },
403
+ "createdAt": "2018-08-02T09:29:56+00:00"
404
+ }
405
+ ],
406
+ "_links": {
407
+ "refunds": {
408
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>/refunds",
409
+ "type": "application/hal+json"
410
+ },
411
+ "self": {
412
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>",
413
+ "type": "application/hal+json"
414
+ },
415
+ "checkout": {
416
+ "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS",
417
+ "type": "text/html"
418
+ },
419
+ "documentation": {
420
+ "href": "https://docs.mollie.com/reference/v2/orders-api/get-order",
421
+ "type": "text/html"
422
+ }
423
+ }
424
+ }'
425
+ );
426
+ }
427
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Organization;
8
+ use Mollie\Api\Resources\OrganizationCollection;
9
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
10
+
11
+ class OrganizationEndpointTest extends BaseEndpointTest
12
+ {
13
+ use LinkObjectTestHelpers;
14
+
15
+ public function testGetOrganization()
16
+ {
17
+ $this->mockApiCall(
18
+ new Request("GET", "/v2/organizations/org_12345678"),
19
+ new Response(
20
+ 200,
21
+ [],
22
+ '{
23
+ "resource": "organization",
24
+ "id": "org_12345678",
25
+ "name": "Mollie B.V.",
26
+ "email": "info@mollie.com",
27
+ "locale": "nl_NL",
28
+ "address": {
29
+ "streetAndNumber": "Keizersgracht 313",
30
+ "postalCode": "1016 EE",
31
+ "city": "Amsterdam",
32
+ "country": "NL"
33
+ },
34
+ "registrationNumber": "30204462",
35
+ "vatNumber": "NL815839091B01",
36
+ "_links": {
37
+ "self": {
38
+ "href": "https://api.mollie.com/v2/organizations/org_12345678",
39
+ "type": "application/hal+json"
40
+ },
41
+ "documentation": {
42
+ "href": "https://docs.mollie.com/reference/v2/organizations-api/get-organization",
43
+ "type": "text/html"
44
+ }
45
+ }
46
+ }'
47
+ )
48
+ );
49
+
50
+ $organization = $this->apiClient->organizations->get('org_12345678');
51
+
52
+ $this->assertOrganization($organization);
53
+ }
54
+
55
+ public function testGetCurrentOrganization()
56
+ {
57
+ $this->mockApiCall(
58
+ new Request("GET", "/v2/organizations/me"),
59
+ new Response(
60
+ 200,
61
+ [],
62
+ '{
63
+ "resource": "organization",
64
+ "id": "org_12345678",
65
+ "name": "Mollie B.V.",
66
+ "email": "info@mollie.com",
67
+ "locale": "nl_NL",
68
+ "address": {
69
+ "streetAndNumber": "Keizersgracht 313",
70
+ "postalCode": "1016 EE",
71
+ "city": "Amsterdam",
72
+ "country": "NL"
73
+ },
74
+ "registrationNumber": "30204462",
75
+ "vatNumber": "NL815839091B01",
76
+ "_links": {
77
+ "self": {
78
+ "href": "https://api.mollie.com/v2/organizations/org_12345678",
79
+ "type": "application/hal+json"
80
+ },
81
+ "documentation": {
82
+ "href": "https://docs.mollie.com/reference/v2/organizations-api/get-organization",
83
+ "type": "text/html"
84
+ }
85
+ }
86
+ }'
87
+ )
88
+ );
89
+
90
+ $organization = $this->apiClient->organizations->current();
91
+
92
+ $this->assertOrganization($organization);
93
+ }
94
+
95
+ protected function assertOrganization($organization)
96
+ {
97
+ $this->assertInstanceOf(Organization::class, $organization);
98
+
99
+ $this->assertEquals('org_12345678', $organization->id);
100
+ $this->assertEquals('Mollie B.V.', $organization->name);
101
+ $this->assertEquals('info@mollie.com', $organization->email);
102
+ $this->assertEquals('nl_NL', $organization->locale);
103
+
104
+ $this->assertEquals((object) [
105
+ 'streetAndNumber' => 'Keizersgracht 313',
106
+ 'postalCode' => '1016 EE',
107
+ 'city' => 'Amsterdam',
108
+ 'country' => 'NL',
109
+ ], $organization->address);
110
+
111
+ $this->assertEquals('30204462', $organization->registrationNumber);
112
+ $this->assertEquals('NL815839091B01', $organization->vatNumber);
113
+
114
+ $this->assertLinkObject(
115
+ 'https://api.mollie.com/v2/organizations/org_12345678',
116
+ 'application/hal+json',
117
+ $organization->_links->self
118
+ );
119
+
120
+ $this->assertLinkObject(
121
+ 'https://docs.mollie.com/reference/v2/organizations-api/get-organization',
122
+ 'text/html',
123
+ $organization->_links->documentation
124
+ );
125
+ }
126
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Capture;
8
+ use Mollie\Api\Resources\Payment;
9
+ use Tests\Mollie\TestHelpers\AmountObjectTestHelpers;
10
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
11
+
12
+ class PaymentCaptureEndpointTest extends BaseEndpointTest
13
+ {
14
+ use AmountObjectTestHelpers;
15
+ use LinkObjectTestHelpers;
16
+
17
+ public function testGetCaptureForPaymentResource()
18
+ {
19
+ $this->mockApiCall(
20
+ new Request(
21
+ 'GET',
22
+ '/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT'
23
+ ),
24
+ new Response(
25
+ 200,
26
+ [],
27
+ $this->getCaptureFixture('tr_WDqYK6vllg', 'cpt_4qqhO89gsT')
28
+ )
29
+ );
30
+
31
+ $capture = $this->apiClient->paymentCaptures->getFor(
32
+ $this->getPayment('tr_WDqYK6vllg'),
33
+ 'cpt_4qqhO89gsT'
34
+ );
35
+
36
+ $this->assertCapture($capture);
37
+ }
38
+
39
+ public function testGetCaptureOnPaymentResource()
40
+ {
41
+ $this->mockApiCall(
42
+ new Request(
43
+ 'GET',
44
+ '/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT'
45
+ ),
46
+ new Response(
47
+ 200,
48
+ [],
49
+ $this->getCaptureFixture('tr_WDqYK6vllg', 'cpt_4qqhO89gsT')
50
+ )
51
+ );
52
+
53
+ $capture = $this->getPayment('tr_WDqYK6vllg')->getCapture('cpt_4qqhO89gsT');
54
+
55
+ $this->assertCapture($capture);
56
+ }
57
+
58
+ public function testListCapturesOnPaymentResource()
59
+ {
60
+ $this->mockApiCall(
61
+ new Request(
62
+ 'GET',
63
+ '/v2/payments/tr_WDqYK6vllg/captures'
64
+ ),
65
+ new Response(
66
+ 200,
67
+ [],
68
+ '{
69
+ "_embedded": {
70
+ "captures": [
71
+ ' . $this->getCaptureFixture('tr_WDqYK6vllg', 'cpt_4qqhO89gsT') . '
72
+ ]
73
+ },
74
+ "count": 1,
75
+ "_links": {
76
+ "documentation": {
77
+ "href": "https://docs.mollie.com/reference/v2/captures-api/list-captures",
78
+ "type": "text/html"
79
+ },
80
+ "self": {
81
+ "href": "https://api.mollie.dev/v2/payments/tr_WDqYK6vllg/captures?limit=50",
82
+ "type": "application/hal+json"
83
+ },
84
+ "previous": null,
85
+ "next": null
86
+ }
87
+ }'
88
+ )
89
+ );
90
+
91
+ $captures = $this->getPayment('tr_WDqYK6vllg')->captures();
92
+
93
+ $this->assertEquals(1, $captures->count);
94
+
95
+ $this->assertLinkObject(
96
+ 'https://docs.mollie.com/reference/v2/captures-api/list-captures',
97
+ 'text/html',
98
+ $captures->_links->documentation
99
+ );
100
+
101
+ $this->assertLinkObject(
102
+ 'https://api.mollie.dev/v2/payments/tr_WDqYK6vllg/captures?limit=50',
103
+ 'application/hal+json',
104
+ $captures->_links->self
105
+ );
106
+
107
+ $this->assertNull($captures->_links->previous);
108
+ $this->assertNull($captures->_links->next);
109
+
110
+ $this->assertCapture($captures[0]);
111
+ }
112
+
113
+ protected function assertCapture($capture)
114
+ {
115
+ $this->assertInstanceOf(Capture::class, $capture);
116
+
117
+ $this->assertEquals('capture', $capture->resource);
118
+ $this->assertEquals('cpt_4qqhO89gsT', $capture->id);
119
+ $this->assertEquals('live', $capture->mode);
120
+ $this->assertEquals('tr_WDqYK6vllg', $capture->paymentId);
121
+ $this->assertEquals('shp_3wmsgCJN4U', $capture->shipmentId);
122
+ $this->assertEquals('stl_jDk30akdN', $capture->settlementId);
123
+
124
+ $this->assertAmountObject('1027.99', 'EUR', $capture->amount);
125
+ $this->assertAmountObject('399.00', 'EUR', $capture->settlementAmount);
126
+
127
+ $this->assertEquals('2018-08-02T09:29:56+00:00', $capture->createdAt);
128
+
129
+ $this->assertLinkObject(
130
+ 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT',
131
+ 'application/hal+json',
132
+ $capture->_links->self
133
+ );
134
+
135
+ $this->assertLinkObject(
136
+ 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg',
137
+ 'application/hal+json',
138
+ $capture->_links->payment
139
+ );
140
+
141
+ $this->assertLinkObject(
142
+ 'https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U',
143
+ 'application/hal+json',
144
+ $capture->_links->shipment
145
+ );
146
+
147
+ $this->assertLinkObject(
148
+ 'https://api.mollie.com/v2/settlements/stl_jDk30akdN',
149
+ 'application/hal+json',
150
+ $capture->_links->settlement
151
+ );
152
+
153
+ $this->assertLinkObject(
154
+ 'https://docs.mollie.com/reference/v2/captures-api/get-capture',
155
+ 'text/html',
156
+ $capture->_links->documentation
157
+ );
158
+ }
159
+
160
+ protected function getCaptureFixture(
161
+ $payment_id = 'tr_WDqYK6vllg',
162
+ $capture_id = 'cpt_4qqhO89gsT'
163
+ ) {
164
+ return str_replace(
165
+ [
166
+ '<<payment_id>>',
167
+ '<<capture_id>>',
168
+ ],
169
+ [
170
+ $payment_id,
171
+ $capture_id,
172
+ ],
173
+ '{
174
+ "resource": "capture",
175
+ "id": "<<capture_id>>",
176
+ "mode": "live",
177
+ "amount": {
178
+ "value": "1027.99",
179
+ "currency": "EUR"
180
+ },
181
+ "settlementAmount": {
182
+ "value": "399.00",
183
+ "currency": "EUR"
184
+ },
185
+ "paymentId": "<<payment_id>>",
186
+ "shipmentId": "shp_3wmsgCJN4U",
187
+ "settlementId": "stl_jDk30akdN",
188
+ "createdAt": "2018-08-02T09:29:56+00:00",
189
+ "_links": {
190
+ "self": {
191
+ "href": "https://api.mollie.com/v2/payments/<<payment_id>>/captures/<<capture_id>>",
192
+ "type": "application/hal+json"
193
+ },
194
+ "payment": {
195
+ "href": "https://api.mollie.com/v2/payments/<<payment_id>>",
196
+ "type": "application/hal+json"
197
+ },
198
+ "shipment": {
199
+ "href": "https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U",
200
+ "type": "application/hal+json"
201
+ },
202
+ "settlement": {
203
+ "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN",
204
+ "type": "application/hal+json"
205
+ },
206
+ "documentation": {
207
+ "href": "https://docs.mollie.com/reference/v2/captures-api/get-capture",
208
+ "type": "text/html"
209
+ }
210
+ }
211
+ }'
212
+ );
213
+ }
214
+
215
+ /**
216
+ * @return Payment
217
+ */
218
+ protected function getPayment($payment_id = 'tr_44aKxzEbr8')
219
+ {
220
+ $paymentJson = '{
221
+ "resource":"payment",
222
+ "id":"<<payment_id>>",
223
+ "mode":"test",
224
+ "createdAt":"2018-03-19T12:17:57+00:00",
225
+ "amount":{
226
+ "value":"20.00",
227
+ "currency":"EUR"
228
+ },
229
+ "description":"My first API payment",
230
+ "method":"ideal",
231
+ "metadata":{
232
+ "order_id":1234
233
+ },
234
+ "status":"paid",
235
+ "paidAt":"2018-03-19T12:18:35+00:00",
236
+ "amountRefunded":{
237
+ "value":"0.00",
238
+ "currency":"EUR"
239
+ },
240
+ "amountRemaining":{
241
+ "value":"20.00",
242
+ "currency":"EUR"
243
+ },
244
+ "details":{
245
+ "consumerName":"T. TEST",
246
+ "consumerAccount":"NL17RABO0213698412",
247
+ "consumerBic":"TESTNL99"
248
+ },
249
+ "locale":"nl_NL",
250
+ "countryCode":"NL",
251
+ "profileId":"pfl_2A1gacu42V",
252
+ "sequenceType":"oneoff",
253
+ "redirectUrl":"http://example.org/examples/03-return-page.php?order_id=1234",
254
+ "webhookUrl":"http://example.org/examples/02-webhook-verification.php",
255
+ "settlementAmount":{
256
+ "value":"20.00",
257
+ "currency":"EUR"
258
+ },
259
+ "_links":{
260
+ "self":{
261
+ "href":"https://api.mollie.com/v2/payments/<<payment_id>>",
262
+ "type":"application/hal+json"
263
+ },
264
+ "documentation":{
265
+ "href":"https://docs.mollie.com/reference/v2/payments-api/get-payment",
266
+ "type":"text/html"
267
+ },
268
+ "refunds":{
269
+ "href":"https://api.mollie.com/v2/payments/<<payment_id>>/refunds",
270
+ "type":"application/hal+json"
271
+ },
272
+ "captures":{
273
+ "href":"https://api.mollie.com/v2/payments/<<payment_id>>/captures",
274
+ "type":"application/hal+json"
275
+ }
276
+ }
277
+ }';
278
+
279
+ $paymentJson = str_replace('<<payment_id>>', $payment_id, $paymentJson);
280
+
281
+ return $this->copy(json_decode($paymentJson), new Payment($this->apiClient));
282
+ }
283
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Chargeback;
8
+ use Mollie\Api\Resources\ChargebackCollection;
9
+ use Mollie\Api\Resources\Payment;
10
+ use Tests\Mollie\TestHelpers\AmountObjectTestHelpers;
11
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
12
+
13
+ class PaymentChargebackEndpointTest extends BaseEndpointTest
14
+ {
15
+ use LinkObjectTestHelpers;
16
+ use AmountObjectTestHelpers;
17
+
18
+ public function testListChargebacksOnPaymentResource()
19
+ {
20
+ $this->mockApiCall(
21
+ new Request(
22
+ "GET",
23
+ "/v2/payments/tr_44aKxzEbr8/chargebacks"
24
+ ),
25
+ new Response(
26
+ 200,
27
+ [],
28
+ '{
29
+ "_embedded":{
30
+ "chargebacks":[
31
+ {
32
+ "resource":"chargeback",
33
+ "id":"chb_n9z0tp",
34
+ "amount":{
35
+ "value":"-13.00",
36
+ "currency":"EUR"
37
+ },
38
+ "createdAt":"2018-03-28T11:44:32+00:00",
39
+ "paymentId":"tr_44aKxzEbr8",
40
+ "settlementAmount":{
41
+ "value":"-13.00",
42
+ "currency":"EUR"
43
+ },
44
+ "_links":{
45
+ "self":{
46
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp",
47
+ "type":"application/hal+json"
48
+ },
49
+ "payment":{
50
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
51
+ "type":"application/hal+json"
52
+ },
53
+ "documentation": {
54
+ "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback",
55
+ "type": "text/html"
56
+ }
57
+ }
58
+ },
59
+ {
60
+ "resource":"chargeback",
61
+ "id":"chb_6cqlwf",
62
+ "amount":{
63
+ "value":"-0.37",
64
+ "currency":"EUR"
65
+ },
66
+ "createdAt":"2018-03-28T11:44:32+00:00",
67
+ "paymentId":"tr_44aKxzEbr8",
68
+ "settlementAmount":{
69
+ "value":"-0.37",
70
+ "currency":"EUR"
71
+ },
72
+ "_links":{
73
+ "self":{
74
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks/chb_6cqlwf",
75
+ "type":"application/hal+json"
76
+ },
77
+ "payment":{
78
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
79
+ "type":"application/hal+json"
80
+ },
81
+ "documentation": {
82
+ "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback",
83
+ "type": "text/html"
84
+ }
85
+ }
86
+ }
87
+ ]
88
+ },
89
+ "_links":{
90
+ "documentation":{
91
+ "href":"https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks",
92
+ "type":"text/html"
93
+ },
94
+ "self":{
95
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks",
96
+ "type":"application/hal+json"
97
+ }
98
+ },
99
+ "count": 2
100
+ }'
101
+ )
102
+ );
103
+
104
+ $chargebacks = $this->getPayment()->chargebacks();
105
+
106
+ $this->assertInstanceOf(ChargebackCollection::class, $chargebacks);
107
+ $this->assertEquals(2, $chargebacks->count);
108
+ $this->assertCount(2, $chargebacks);
109
+
110
+ $this->assertLinkObject(
111
+ "https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks",
112
+ "text/html",
113
+ $chargebacks->_links->documentation
114
+ );
115
+
116
+ $this->assertLinkObject(
117
+ "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks",
118
+ "application/hal+json",
119
+ $chargebacks->_links->self
120
+ );
121
+
122
+ $this->assertChargeback($chargebacks[0], 'tr_44aKxzEbr8', 'chb_n9z0tp', "-13.00");
123
+ $this->assertChargeback($chargebacks[1], 'tr_44aKxzEbr8', 'chb_6cqlwf', "-0.37");
124
+ }
125
+
126
+ public function testGetChargebackOnPaymentResource()
127
+ {
128
+ $this->mockApiCall(
129
+ new Request(
130
+ "GET",
131
+ "/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp"
132
+ ),
133
+ new Response(
134
+ 200,
135
+ [],
136
+ '{
137
+ "resource":"chargeback",
138
+ "id":"chb_n9z0tp",
139
+ "amount":{
140
+ "value":"-13.00",
141
+ "currency":"EUR"
142
+ },
143
+ "createdAt":"2018-03-28T11:44:32+00:00",
144
+ "paymentId":"tr_44aKxzEbr8",
145
+ "settlementAmount":{
146
+ "value":"-13.00",
147
+ "currency":"EUR"
148
+ },
149
+ "_links":{
150
+ "self":{
151
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp",
152
+ "type":"application/hal+json"
153
+ },
154
+ "payment":{
155
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
156
+ "type":"application/hal+json"
157
+ },
158
+ "documentation": {
159
+ "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback",
160
+ "type": "text/html"
161
+ }
162
+ }
163
+ }'
164
+ )
165
+ );
166
+
167
+ $chargeback = $this->getPayment()->getChargeback("chb_n9z0tp");
168
+
169
+ $this->assertChargeback($chargeback, 'tr_44aKxzEbr8', 'chb_n9z0tp', "-13.00");
170
+ }
171
+
172
+ protected function assertChargeback($chargeback, $paymentId, $chargebackId, $amount)
173
+ {
174
+ $this->assertInstanceOf(Chargeback::class, $chargeback);
175
+ $this->assertEquals("chargeback", $chargeback->resource);
176
+ $this->assertEquals($chargebackId, $chargeback->id);
177
+
178
+ $this->assertAmountObject($amount, "EUR", $chargeback->amount);
179
+ $this->assertAmountObject($amount, "EUR", $chargeback->settlementAmount);
180
+
181
+ $this->assertEquals("2018-03-28T11:44:32+00:00", $chargeback->createdAt);
182
+ $this->assertEquals($paymentId, $chargeback->paymentId);
183
+
184
+ $this->assertLinkObject(
185
+ "https://api.mollie.com/v2/payments/{$paymentId}/chargebacks/{$chargebackId}",
186
+ "application/hal+json",
187
+ $chargeback->_links->self
188
+ );
189
+
190
+ $this->assertLinkObject(
191
+ "https://api.mollie.com/v2/payments/{$paymentId}",
192
+ "application/hal+json",
193
+ $chargeback->_links->payment
194
+ );
195
+
196
+ $this->assertLinkObject(
197
+ "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback",
198
+ "text/html",
199
+ $chargeback->_links->documentation
200
+ );
201
+ }
202
+
203
+ /**
204
+ * @return Payment
205
+ */
206
+ protected function getPayment()
207
+ {
208
+ $paymentJson = '{
209
+ "resource":"payment",
210
+ "id":"tr_44aKxzEbr8",
211
+ "mode":"test",
212
+ "createdAt":"2018-03-19T12:17:57+00:00",
213
+ "amount":{
214
+ "value":"20.00",
215
+ "currency":"EUR"
216
+ },
217
+ "description":"My first API payment",
218
+ "method":"ideal",
219
+ "metadata":{
220
+ "order_id":1234
221
+ },
222
+ "status":"paid",
223
+ "paidAt":"2018-03-19T12:18:35+00:00",
224
+ "amountRefunded":{
225
+ "value":"0.00",
226
+ "currency":"EUR"
227
+ },
228
+ "amountRemaining":{
229
+ "value":"20.00",
230
+ "currency":"EUR"
231
+ },
232
+ "details":{
233
+ "consumerName":"T. TEST",
234
+ "consumerAccount":"NL17RABO0213698412",
235
+ "consumerBic":"TESTNL99"
236
+ },
237
+ "locale":"nl_NL",
238
+ "countryCode":"NL",
239
+ "profileId":"pfl_2A1gacu42V",
240
+ "sequenceType":"oneoff",
241
+ "redirectUrl":"http://example.org/examples/03-return-page.php?order_id=1234",
242
+ "webhookUrl":"http://example.org/examples/02-webhook-verification.php",
243
+ "settlementAmount":{
244
+ "value":"20.00",
245
+ "currency":"EUR"
246
+ },
247
+ "_links":{
248
+ "self":{
249
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
250
+ "type":"application/hal+json"
251
+ },
252
+ "documentation":{
253
+ "href":"https://docs.mollie.com/reference/v2/payments-api/get-payment",
254
+ "type":"text/html"
255
+ },
256
+ "chargebacks":{
257
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks",
258
+ "type":"application/hal+json"
259
+ }
260
+ }
261
+ }';
262
+
263
+ return $this->copy(json_decode($paymentJson), new Payment($this->apiClient));
264
+ }
265
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/PaymentEndpointTest.php ADDED
@@ -0,0 +1,381 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Payment;
8
+ use Mollie\Api\Resources\PaymentCollection;
9
+ use Mollie\Api\Types\PaymentStatus;
10
+ use Mollie\Api\Types\SequenceType;
11
+ use stdClass;
12
+
13
+ class PaymentEndpointTest extends BaseEndpointTest
14
+ {
15
+ public function testCreatePayment()
16
+ {
17
+ $this->mockApiCall(
18
+ new Request(
19
+ "POST",
20
+ "/v2/payments",
21
+ [],
22
+ '{
23
+ "amount":{
24
+ "value":"20.00",
25
+ "currency":"EUR"
26
+ },
27
+ "description": "My first API payment",
28
+ "redirectUrl": "https://example.org/redirect",
29
+ "webhookUrl": "https://example.org/webhook",
30
+ "metadata": {
31
+ "order_id": "1234"
32
+ }
33
+ }'
34
+ ),
35
+ new Response(
36
+ 201,
37
+ [],
38
+ '{
39
+ "resource":"payment",
40
+ "id":"tr_44aKxzEbr8",
41
+ "mode":"test",
42
+ "createdAt":"2018-03-13T14:02:29+00:00",
43
+ "amount":{
44
+ "value":"20.00",
45
+ "currency":"EUR"
46
+ },
47
+ "description":"My first API payment",
48
+ "method":null,
49
+ "metadata":{
50
+ "order_id":1234
51
+ },
52
+ "status":"open",
53
+ "isCancelable":false,
54
+ "expiresAt":"2018-03-13T14:17:29+00:00",
55
+ "details":null,
56
+ "profileId":"pfl_2A1gacu42V",
57
+ "sequenceType":"oneoff",
58
+ "redirectUrl":"http://example.org/examples/payment/03-return-page.php?order_id=1234",
59
+ "webhookUrl":"http://example.org/examples/payment/02-webhook-verification.php",
60
+ "_links":{
61
+ "self":{
62
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
63
+ "type":"application/hal+json"
64
+ },
65
+ "checkout":{
66
+ "href":"https://www.mollie.com/payscreen/select-method/44aKxzEbr8",
67
+ "type":"text/html"
68
+ },
69
+ "documentation":{
70
+ "href":"https://docs.mollie.com/reference/v2/payments-api/create-payment",
71
+ "type":"text/html"
72
+ }
73
+ }
74
+ }'
75
+ )
76
+ );
77
+
78
+ $payment = $this->apiClient->payments->create([
79
+ "amount" => [
80
+ "currency" => "EUR",
81
+ "value" => "20.00"
82
+ ],
83
+ "description" => "My first API payment",
84
+ "redirectUrl" => "https://example.org/redirect",
85
+ "webhookUrl" => "https://example.org/webhook",
86
+ "metadata" => [
87
+ "order_id" => "1234",
88
+ ],
89
+ ]);
90
+
91
+ $this->assertInstanceOf(Payment::class, $payment);
92
+ $this->assertEquals('tr_44aKxzEbr8', $payment->id);
93
+ $this->assertEquals('test', $payment->mode);
94
+ $this->assertEquals("2018-03-13T14:02:29+00:00", $payment->createdAt);
95
+
96
+ $amount = new Stdclass();
97
+ $amount->value = '20.00';
98
+ $amount->currency = "EUR";
99
+ $this->assertEquals($amount, $payment->amount);
100
+
101
+ $this->assertEquals('My first API payment', $payment->description);
102
+ $this->assertNull($payment->method);
103
+ $this->assertEquals((object)["order_id" => "1234"], $payment->metadata);
104
+ $this->assertEquals(PaymentStatus::STATUS_OPEN, $payment->status);
105
+ $this->assertFalse($payment->isCancelable);
106
+ $this->assertEquals("2018-03-13T14:17:29+00:00", $payment->expiresAt);
107
+ $this->assertNull($payment->details);
108
+ $this->assertEquals("pfl_2A1gacu42V", $payment->profileId);
109
+ $this->assertEquals(SequenceType::SEQUENCETYPE_ONEOFF, $payment->sequenceType);
110
+ $this->assertEquals("http://example.org/examples/payment/03-return-page.php?order_id=1234", $payment->redirectUrl);
111
+ $this->assertEquals("http://example.org/examples/payment/02-webhook-verification.php", $payment->webhookUrl);
112
+
113
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"];
114
+ $this->assertEquals($selfLink, $payment->_links->self);
115
+
116
+ $checkoutLink = (object)["href" => "https://www.mollie.com/payscreen/select-method/44aKxzEbr8", "type" => "text/html"];
117
+ $this->assertEquals($checkoutLink, $payment->_links->checkout);
118
+
119
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/payments-api/create-payment", "type" => "text/html"];
120
+ $this->assertEquals($documentationLink, $payment->_links->documentation);
121
+ }
122
+
123
+ public function testGetPayment()
124
+ {
125
+ $this->mockApiCall(
126
+ new Request(
127
+ "GET",
128
+ "/v2/payments/tr_44aKxzEbr8?testmode=true",
129
+ [],
130
+ ''
131
+ ),
132
+ new Response(
133
+ 200,
134
+ [],
135
+ '{
136
+ "resource":"payment",
137
+ "id":"tr_44aKxzEbr8",
138
+ "mode":"test",
139
+ "createdAt":"2018-03-13T14:02:29+00:00",
140
+ "amount":{
141
+ "value":"20.00",
142
+ "currency":"EUR"
143
+ },
144
+ "description":"My first API payment",
145
+ "method":"ideal",
146
+ "metadata":{
147
+ "order_id":1234
148
+ },
149
+ "status":"paid",
150
+ "paidAt":"2018-03-19T12:18:35+00:00",
151
+ "amountRefunded":{
152
+ "value":"0.00",
153
+ "currency":"EUR"
154
+ },
155
+ "amountRemaining":{
156
+ "value":"20.00",
157
+ "currency":"EUR"
158
+ },
159
+ "details":{
160
+ "consumerName":"T. TEST",
161
+ "consumerAccount":"NL17RABO0213698412",
162
+ "consumerBic":"TESTNL99"
163
+ },
164
+ "locale":"nl_NL",
165
+ "countryCode":"NL",
166
+ "profileId":"pfl_2A1gacu42V",
167
+ "sequenceType":"oneoff",
168
+ "redirectUrl":"http://example.org/examples/03-return-page.php?order_id=1234",
169
+ "webhookUrl":"http://example.org/examples/02-webhook-verification.php",
170
+ "settlementAmount":{
171
+ "value":"20.00",
172
+ "currency":"EUR"
173
+ },
174
+ "_links":{
175
+ "self":{
176
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
177
+ "type":"application/hal+json"
178
+ },
179
+ "documentation":{
180
+ "href":"https://docs.mollie.com/reference/v2/payments-api/get-payment",
181
+ "type":"text/html"
182
+ }
183
+ }
184
+ }'
185
+ )
186
+ );
187
+
188
+ $payment = $this->apiClient->payments->get("tr_44aKxzEbr8", ["testmode" => true]);
189
+
190
+ $this->assertInstanceOf(Payment::class, $payment);
191
+ $this->assertEquals('tr_44aKxzEbr8', $payment->id);
192
+ $this->assertEquals('test', $payment->mode);
193
+ $this->assertEquals("2018-03-13T14:02:29+00:00", $payment->createdAt);
194
+
195
+ $amount = new Stdclass();
196
+ $amount->value = '20.00';
197
+ $amount->currency = "EUR";
198
+ $this->assertEquals($amount, $payment->amount);
199
+
200
+ $this->assertEquals('My first API payment', $payment->description);
201
+ $this->assertEquals("ideal", $payment->method);
202
+ $this->assertEquals((object)["order_id" => "1234"], $payment->metadata);
203
+ $this->assertEquals(PaymentStatus::STATUS_PAID, $payment->status);
204
+
205
+ $amountRefunded = new Stdclass();
206
+ $amountRefunded->value = '0.00';
207
+ $amountRefunded->currency = "EUR";
208
+ $this->assertEquals($amountRefunded, $payment->amountRefunded);
209
+
210
+ $amountRemaining = new Stdclass();
211
+ $amountRemaining->value = '20.00';
212
+ $amountRemaining->currency = "EUR";
213
+ $this->assertEquals($amountRemaining, $payment->amountRemaining);
214
+
215
+ $details = (object)[
216
+ 'consumerName' => 'T. TEST',
217
+ 'consumerAccount' => 'NL17RABO0213698412',
218
+ 'consumerBic' => 'TESTNL99'
219
+ ];
220
+
221
+ $this->assertEquals($details, $payment->details);
222
+ $this->assertEquals("pfl_2A1gacu42V", $payment->profileId);
223
+ $this->assertEquals(SequenceType::SEQUENCETYPE_ONEOFF, $payment->sequenceType);
224
+ $this->assertEquals("http://example.org/examples/03-return-page.php?order_id=1234", $payment->redirectUrl);
225
+ $this->assertEquals("http://example.org/examples/02-webhook-verification.php", $payment->webhookUrl);
226
+
227
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"];
228
+ $this->assertEquals($selfLink, $payment->_links->self);
229
+
230
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/payments-api/get-payment", "type" => "text/html"];
231
+ $this->assertEquals($documentationLink, $payment->_links->documentation);
232
+ }
233
+
234
+ public function testListPayment()
235
+ {
236
+ $this->mockApiCall(
237
+ new Request(
238
+ "GET",
239
+ "/v2/payments?limit=3",
240
+ [],
241
+ ''
242
+ ),
243
+ new Response(
244
+ 200,
245
+ [],
246
+ '{
247
+ "_embedded": {
248
+ "payments": [
249
+ {
250
+ "resource": "payment",
251
+ "id": "tr_admNa2tFfa",
252
+ "mode": "test",
253
+ "createdAt": "2018-03-19T15:00:50+00:00",
254
+ "amount": {
255
+ "value": "100.00",
256
+ "currency": "EUR"
257
+ },
258
+ "description": "Payment no 1",
259
+ "method": null,
260
+ "metadata": null,
261
+ "status": "open",
262
+ "isCancelable": false,
263
+ "expiresAt": "2018-03-19T15:15:50+00:00",
264
+ "details": null,
265
+ "locale": "nl_NL",
266
+ "profileId": "pfl_7N5qjbu42V",
267
+ "sequenceType": "oneoff",
268
+ "redirectUrl": "https://www.example.org/",
269
+ "_links": {
270
+ "self": {
271
+ "href": "https://api.mollie.com/v2/payments/tr_admNa2tFfa",
272
+ "type": "application/hal+json"
273
+ },
274
+ "checkout": {
275
+ "href": "https://www.mollie.com/payscreen/select-method/admNa2tFfa",
276
+ "type": "text/html"
277
+ }
278
+ }
279
+ },
280
+ {
281
+ "resource": "payment",
282
+ "id": "tr_bcaLc7hFfa",
283
+ "mode": "test",
284
+ "createdAt": "2018-03-19T15:00:50+00:00",
285
+ "amount": {
286
+ "value": "100.00",
287
+ "currency": "EUR"
288
+ },
289
+ "description": "Payment no 2",
290
+ "method": null,
291
+ "metadata": null,
292
+ "status": "open",
293
+ "isCancelable": false,
294
+ "expiresAt": "2018-03-19T15:15:50+00:00",
295
+ "details": null,
296
+ "locale": "nl_NL",
297
+ "profileId": "pfl_7N5qjbu42V",
298
+ "sequenceType": "oneoff",
299
+ "redirectUrl": "https://www.example.org/",
300
+ "_links": {
301
+ "self": {
302
+ "href": "https://api.mollie.com/v2/payments/tr_bcaLc7hFfa",
303
+ "type": "application/hal+json"
304
+ },
305
+ "checkout": {
306
+ "href": "https://www.mollie.com/payscreen/select-method/bcaLc7hFfa",
307
+ "type": "text/html"
308
+ }
309
+ }
310
+ },
311
+ {
312
+ "resource": "payment",
313
+ "id": "tr_pslHy1tFfa",
314
+ "mode": "test",
315
+ "createdAt": "2018-03-19T15:00:50+00:00",
316
+ "amount": {
317
+ "value": "100.00",
318
+ "currency": "EUR"
319
+ },
320
+ "description": "Payment no 3",
321
+ "method": null,
322
+ "metadata": null,
323
+ "status": "open",
324
+ "isCancelable": false,
325
+ "expiresAt": "2018-03-19T15:15:50+00:00",
326
+ "details": null,
327
+ "locale": "nl_NL",
328
+ "profileId": "pfl_7N5qjbu42V",
329
+ "sequenceType": "oneoff",
330
+ "redirectUrl": "https://www.example.org/",
331
+ "_links": {
332
+ "self": {
333
+ "href": "https://api.mollie.com/v2/payments/tr_pslHy1tFfa",
334
+ "type": "application/hal+json"
335
+ },
336
+ "checkout": {
337
+ "href": "https://www.mollie.com/payscreen/select-method/pslHy1tFfa",
338
+ "type": "text/html"
339
+ }
340
+ }
341
+ }
342
+ ]
343
+ },
344
+ "_links": {
345
+ "documentation": {
346
+ "href": "https://docs.mollie.com/reference/v2/payments-api/list-payments",
347
+ "type": "text/html"
348
+ },
349
+ "self": {
350
+ "href": "http://api.mollie.com/v2/payments?limit=3",
351
+ "type": "application/hal+json"
352
+ },
353
+ "previous": null,
354
+ "next": {
355
+ "href": "http://api.mollie.com/v2/payments?from=tr_eW8f5kzUkF&limit=3",
356
+ "type": "application/hal+json"
357
+ }
358
+ },
359
+ "count": 3
360
+ }'
361
+ )
362
+ );
363
+
364
+ $payments = $this->apiClient->payments->page(null, 3);
365
+
366
+ $this->assertInstanceOf(PaymentCollection::class, $payments);
367
+ $this->assertEquals(3, $payments->count);
368
+ $this->assertEquals(3, count($payments));
369
+
370
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/payments-api/list-payments", "type" => "text/html"];
371
+ $this->assertEquals($documentationLink, $payments->_links->documentation);
372
+
373
+ $selfLink = (object)["href" => "http://api.mollie.com/v2/payments?limit=3", "type" => "application/hal+json"];
374
+ $this->assertEquals($selfLink, $payments->_links->self);
375
+
376
+ $this->assertNull($payments->_links->previous);
377
+
378
+ $nextLink = (object)["href" => "http://api.mollie.com/v2/payments?from=tr_eW8f5kzUkF&limit=3", "type" => "application/hal+json"];
379
+ $this->assertEquals($nextLink, $payments->_links->next);
380
+ }
381
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Payment;
8
+ use Mollie\Api\Resources\Refund;
9
+ use Mollie\Api\Resources\RefundCollection;
10
+ use stdClass;
11
+
12
+ class PaymentRefundEndpointTest extends BaseEndpointTest
13
+ {
14
+ public function testGetRefundForPaymentResource()
15
+ {
16
+ $this->mockApiCall(
17
+ new Request(
18
+ "GET",
19
+ "/v2/payments/tr_44aKxzEbr8/refunds/re_PsAvxvLsnm"
20
+ ),
21
+ new Response(
22
+ 201,
23
+ [],
24
+ '{
25
+ "resource":"refund",
26
+ "id":"re_PsAvxvLsnm",
27
+ "amount":{
28
+ "value":"20.00",
29
+ "currency":"EUR"
30
+ },
31
+ "status":"pending",
32
+ "createdAt":"2018-03-19T12:33:37+00:00",
33
+ "description":"My first API payment",
34
+ "paymentId":"tr_44aKxzEbr8",
35
+ "settlementAmount":{
36
+ "value":"-20.00",
37
+ "currency":"EUR"
38
+ },
39
+ "_links":{
40
+ "self":{
41
+ "href":"https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm",
42
+ "type":"application/hal+json"
43
+ },
44
+ "payment":{
45
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
46
+ "type":"application/hal+json"
47
+ },
48
+ "documentation":{
49
+ "href":"https://docs.mollie.com/reference/v2/refunds-api/create-refund",
50
+ "type":"text/html"
51
+ }
52
+ }
53
+ }'
54
+ )
55
+ );
56
+
57
+ $refund = $this->apiClient->paymentRefunds->getFor($this->getPayment(), "re_PsAvxvLsnm");
58
+
59
+ $this->assertInstanceOf(Refund::class, $refund);
60
+ $this->assertEquals("re_PsAvxvLsnm", $refund->id);
61
+
62
+ $amount = new Stdclass();
63
+ $amount->value = '20.00';
64
+ $amount->currency = "EUR";
65
+ $this->assertEquals($amount, $refund->amount);
66
+
67
+ $this->assertEquals("pending", $refund->status);
68
+ $this->assertEquals("2018-03-19T12:33:37+00:00", $refund->createdAt);
69
+ $this->assertEquals("My first API payment", $refund->description);
70
+ $this->assertEquals("tr_44aKxzEbr8", $refund->paymentId);
71
+
72
+ $amount = new Stdclass();
73
+ $amount->value = '-20.00';
74
+ $amount->currency = "EUR";
75
+ $this->assertEquals($amount, $refund->settlementAmount);
76
+
77
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm", "type" => "application/hal+json"];
78
+ $this->assertEquals($selfLink, $refund->_links->self);
79
+
80
+ $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"];
81
+ $this->assertEquals($paymentLink, $refund->_links->payment);
82
+
83
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/refunds-api/create-refund", "type" => "text/html"];
84
+ $this->assertEquals($documentationLink, $refund->_links->documentation);
85
+ }
86
+
87
+ public function testGetRefundOnPaymentResource()
88
+ {
89
+ $this->mockApiCall(
90
+ new Request(
91
+ "GET",
92
+ "/v2/payments/tr_44aKxzEbr8/refunds/re_PsAvxvLsnm"
93
+ ),
94
+ new Response(
95
+ 201,
96
+ [],
97
+ '{
98
+ "resource":"refund",
99
+ "id":"re_PsAvxvLsnm",
100
+ "amount":{
101
+ "value":"20.00",
102
+ "currency":"EUR"
103
+ },
104
+ "status":"pending",
105
+ "createdAt":"2018-03-19T12:33:37+00:00",
106
+ "description":"My first API payment",
107
+ "paymentId":"tr_44aKxzEbr8",
108
+ "settlementAmount":{
109
+ "value":"-20.00",
110
+ "currency":"EUR"
111
+ },
112
+ "_links":{
113
+ "self":{
114
+ "href":"https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm",
115
+ "type":"application/hal+json"
116
+ },
117
+ "payment":{
118
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
119
+ "type":"application/hal+json"
120
+ },
121
+ "documentation":{
122
+ "href":"https://docs.mollie.com/reference/v2/refunds-api/create-refund",
123
+ "type":"text/html"
124
+ }
125
+ }
126
+ }'
127
+ )
128
+ );
129
+
130
+ $refund = $this->getPayment("tr_44aKxzEbr8")->getRefund("re_PsAvxvLsnm");
131
+
132
+ $this->assertInstanceOf(Refund::class, $refund);
133
+ $this->assertEquals("re_PsAvxvLsnm", $refund->id);
134
+
135
+ $amount = new Stdclass();
136
+ $amount->value = '20.00';
137
+ $amount->currency = "EUR";
138
+ $this->assertEquals($amount, $refund->amount);
139
+
140
+ $this->assertEquals("pending", $refund->status);
141
+ $this->assertEquals("2018-03-19T12:33:37+00:00", $refund->createdAt);
142
+ $this->assertEquals("My first API payment", $refund->description);
143
+ $this->assertEquals("tr_44aKxzEbr8", $refund->paymentId);
144
+
145
+ $amount = new Stdclass();
146
+ $amount->value = '-20.00';
147
+ $amount->currency = "EUR";
148
+ $this->assertEquals($amount, $refund->settlementAmount);
149
+
150
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm", "type" => "application/hal+json"];
151
+ $this->assertEquals($selfLink, $refund->_links->self);
152
+
153
+ $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"];
154
+ $this->assertEquals($paymentLink, $refund->_links->payment);
155
+
156
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/refunds-api/create-refund", "type" => "text/html"];
157
+ $this->assertEquals($documentationLink, $refund->_links->documentation);
158
+ }
159
+
160
+ public function testCreateRefund()
161
+ {
162
+ $this->mockApiCall(
163
+ new Request(
164
+ "POST",
165
+ "/v2/payments/tr_44aKxzEbr8/refunds",
166
+ [],
167
+ '{"amount":{"currency":"EUR","value":"20.00"}}'
168
+ ),
169
+ new Response(
170
+ 201,
171
+ [],
172
+ '{
173
+ "resource":"refund",
174
+ "id":"re_PsAvxvLsnm",
175
+ "amount":{
176
+ "value":"20.00",
177
+ "currency":"EUR"
178
+ },
179
+ "status":"pending",
180
+ "createdAt":"2018-03-19T12:33:37+00:00",
181
+ "description":"My first API payment",
182
+ "paymentId":"tr_44aKxzEbr8",
183
+ "settlementAmount":{
184
+ "value":"-20.00",
185
+ "currency":"EUR"
186
+ },
187
+ "_links":{
188
+ "self":{
189
+ "href":"https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm",
190
+ "type":"application/hal+json"
191
+ },
192
+ "payment":{
193
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
194
+ "type":"application/hal+json"
195
+ },
196
+ "documentation":{
197
+ "href":"https://docs.mollie.com/reference/v2/refunds-api/create-refund",
198
+ "type":"text/html"
199
+ }
200
+ }
201
+ }'
202
+ )
203
+ );
204
+
205
+ $refund = $this->getPayment()->refund([
206
+ "amount" => [
207
+ "currency" => "EUR",
208
+ "value" => "20.00"
209
+ ]
210
+ ]);
211
+
212
+ $this->assertInstanceOf(Refund::class, $refund);
213
+ $this->assertEquals("re_PsAvxvLsnm", $refund->id);
214
+
215
+ $amount = new Stdclass();
216
+ $amount->value = '20.00';
217
+ $amount->currency = "EUR";
218
+ $this->assertEquals($amount, $refund->amount);
219
+
220
+ $this->assertEquals("pending", $refund->status);
221
+ $this->assertEquals("2018-03-19T12:33:37+00:00", $refund->createdAt);
222
+ $this->assertEquals("My first API payment", $refund->description);
223
+ $this->assertEquals("tr_44aKxzEbr8", $refund->paymentId);
224
+
225
+ $amount = new Stdclass();
226
+ $amount->value = '-20.00';
227
+ $amount->currency = "EUR";
228
+ $this->assertEquals($amount, $refund->settlementAmount);
229
+
230
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm", "type" => "application/hal+json"];
231
+ $this->assertEquals($selfLink, $refund->_links->self);
232
+
233
+ $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"];
234
+ $this->assertEquals($paymentLink, $refund->_links->payment);
235
+
236
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/refunds-api/create-refund", "type" => "text/html"];
237
+ $this->assertEquals($documentationLink, $refund->_links->documentation);
238
+ }
239
+
240
+ public function testGetRefundsOnPaymentResource()
241
+ {
242
+ $this->mockApiCall(
243
+ new Request(
244
+ "GET",
245
+ "/v2/payments/tr_44aKxzEbr8/refunds",
246
+ [],
247
+ ''
248
+ ),
249
+ new Response(
250
+ 201,
251
+ [],
252
+ '{
253
+ "_embedded": {
254
+ "refunds": [
255
+ {
256
+ "resource": "refund",
257
+ "id": "re_haCsig5aru",
258
+ "amount": {
259
+ "value": "2.00",
260
+ "currency": "EUR"
261
+ },
262
+ "status": "pending",
263
+ "createdAt": "2018-03-28T10:56:10+00:00",
264
+ "description": "My first API payment",
265
+ "paymentId": "tr_44aKxzEbr8",
266
+ "settlementAmount": {
267
+ "value": "-2.00",
268
+ "currency": "EUR"
269
+ },
270
+ "_links": {
271
+ "self": {
272
+ "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru",
273
+ "type": "application/hal+json"
274
+ },
275
+ "payment": {
276
+ "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
277
+ "type": "application/hal+json"
278
+ }
279
+ }
280
+ }
281
+ ]
282
+ },
283
+ "_links": {
284
+ "documentation": {
285
+ "href": "https://docs.mollie.com/reference/v2/refunds-api/list-refunds",
286
+ "type": "text/html"
287
+ },
288
+ "self": {
289
+ "href": "http://api.mollie.nl/v2/payments/tr_44aKxzEbr8/refunds?limit=10",
290
+ "type": "application/hal+json"
291
+ },
292
+ "previous": null,
293
+ "next": null
294
+ },
295
+ "count": 1
296
+ }'
297
+ )
298
+ );
299
+
300
+ $refunds = $this->getPayment()->refunds();
301
+
302
+ $this->assertInstanceOf(RefundCollection::class, $refunds);
303
+ $this->assertEquals(1, $refunds->count);
304
+ $this->assertCount(1, $refunds);
305
+
306
+ $refund = $refunds[0];
307
+
308
+ $this->assertInstanceOf(Refund::class, $refund);
309
+ $this->assertEquals("re_haCsig5aru", $refund->id);
310
+ $this->assertEquals("2.00", $refund->amount->value);
311
+ $this->assertEquals("EUR", $refund->amount->currency);
312
+ $this->assertEquals("pending", $refund->status);
313
+ $this->assertEquals("2018-03-28T10:56:10+00:00", $refund->createdAt);
314
+ $this->assertEquals("My first API payment", $refund->description);
315
+ $this->assertEquals("tr_44aKxzEbr8", $refund->paymentId);
316
+ $this->assertEquals("-2.00", $refund->settlementAmount->value);
317
+ $this->assertEquals("EUR", $refund->settlementAmount->currency);
318
+
319
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru", "type" => "application/hal+json"];
320
+ $this->assertEquals($selfLink, $refund->_links->self);
321
+
322
+ $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"];
323
+ $this->assertEquals($paymentLink, $refund->_links->payment);
324
+ }
325
+
326
+ /**
327
+ * @return Payment
328
+ */
329
+ private function getPayment()
330
+ {
331
+ $paymentJson = '{
332
+ "resource":"payment",
333
+ "id":"tr_44aKxzEbr8",
334
+ "mode":"test",
335
+ "createdAt":"2018-03-19T12:17:57+00:00",
336
+ "amount":{
337
+ "value":"20.00",
338
+ "currency":"EUR"
339
+ },
340
+ "description":"My first API payment",
341
+ "method":"ideal",
342
+ "metadata":{
343
+ "order_id":1234
344
+ },
345
+ "status":"paid",
346
+ "paidAt":"2018-03-19T12:18:35+00:00",
347
+ "amountRefunded":{
348
+ "value":"0.00",
349
+ "currency":"EUR"
350
+ },
351
+ "amountRemaining":{
352
+ "value":"20.00",
353
+ "currency":"EUR"
354
+ },
355
+ "details":{
356
+ "consumerName":"T. TEST",
357
+ "consumerAccount":"NL17RABO0213698412",
358
+ "consumerBic":"TESTNL99"
359
+ },
360
+ "locale":"nl_NL",
361
+ "countryCode":"NL",
362
+ "profileId":"pfl_2A1gacu42V",
363
+ "sequenceType":"oneoff",
364
+ "redirectUrl":"http://example.org/examples/03-return-page.php?order_id=1234",
365
+ "webhookUrl":"http://example.org/examples/02-webhook-verification.php",
366
+ "settlementAmount":{
367
+ "value":"20.00",
368
+ "currency":"EUR"
369
+ },
370
+ "_links":{
371
+ "self":{
372
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
373
+ "type":"application/hal+json"
374
+ },
375
+ "documentation":{
376
+ "href":"https://docs.mollie.com/reference/v2/payments-api/get-payment",
377
+ "type":"text/html"
378
+ },
379
+ "refunds":{
380
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds",
381
+ "type":"application/hal+json"
382
+ }
383
+ }
384
+ }';
385
+
386
+ return $this->copy(json_decode($paymentJson), new Payment($this->apiClient));
387
+ }
388
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/PermissionEndpointTest.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Permission;
8
+ use Mollie\Api\Resources\PermissionCollection;
9
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
10
+
11
+ class PermissionEndpointTest extends BaseEndpointTest
12
+ {
13
+ use LinkObjectTestHelpers;
14
+
15
+ /**
16
+ * @param string id
17
+ *
18
+ * @dataProvider dpTestGetPermissionIds
19
+ */
20
+ public function testGetPermissionIds($permissionId)
21
+ {
22
+ $this->mockApiCall(
23
+ new Request('GET', '/v2/permissions/' . $permissionId),
24
+ new Response(
25
+ 200,
26
+ [],
27
+ '{
28
+ "resource": "permission",
29
+ "id": "' . $permissionId . '",
30
+ "description": "Some dummy permission description",
31
+ "granted": true,
32
+ "_links": {
33
+ "self": {
34
+ "href": "https://api.mollie.com/v2/permissions/' . $permissionId . '",
35
+ "type": "application/hal+json"
36
+ },
37
+ "documentation": {
38
+ "href": "https://docs.mollie.com/reference/v2/permissions-api/get-permission",
39
+ "type": "text/html"
40
+ }
41
+ }
42
+ }'
43
+ )
44
+ );
45
+
46
+ $permission = $this->apiClient->permissions->get($permissionId);
47
+
48
+ $this->assertPermission($permission, $permissionId);
49
+ }
50
+
51
+ public function dpTestGetPermissionIds()
52
+ {
53
+ return [
54
+ ['payments.read'],
55
+ ['payments.write'],
56
+ ['refunds.read'],
57
+ ['refunds.write'],
58
+ ['customers.read'],
59
+ ['customers.write'],
60
+ ['mandates.read'],
61
+ ['mandates.write'],
62
+ ['subscriptions.read'],
63
+ ['subscriptions.write'],
64
+ ['profiles.read'],
65
+ ['profiles.write'],
66
+ ['invoices.read'],
67
+ ['invoices.write'],
68
+ ['settlements.read'],
69
+ ['settlements.write'],
70
+ ['orders.read'],
71
+ ['orders.write'],
72
+ ['organizations.read'],
73
+ ['organizations.write'],
74
+ ];
75
+ }
76
+
77
+ protected function assertPermission($permission, $permissionId)
78
+ {
79
+ $this->assertInstanceOf(Permission::class, $permission);
80
+ $this->assertEquals('permission', $permission->resource);
81
+ $this->assertEquals($permissionId, $permission->id);
82
+ $this->assertEquals(
83
+ 'Some dummy permission description',
84
+ $permission->description
85
+ );
86
+ $this->assertTrue($permission->granted);
87
+
88
+ $this->assertLinkObject(
89
+ 'https://api.mollie.com/v2/permissions/' . $permissionId,
90
+ 'application/hal+json',
91
+ $permission->_links->self
92
+ );
93
+
94
+ $this->assertLinkObject(
95
+ 'https://docs.mollie.com/reference/v2/permissions-api/get-permission',
96
+ 'text/html',
97
+ $permission->_links->documentation
98
+ );
99
+ }
100
+
101
+ public function testListPermissions()
102
+ {
103
+ $this->mockApiCall(
104
+ new Request('GET', '/v2/permissions'),
105
+ new Response(
106
+ 200,
107
+ [],
108
+ '{
109
+ "_embedded": {
110
+ "permissions": [
111
+ {
112
+ "resource": "permission",
113
+ "id": "payments.write",
114
+ "description": "Some dummy permission description",
115
+ "granted": true,
116
+ "_links": {
117
+ "self": {
118
+ "href": "https://api.mollie.com/v2/permissions/payments.write",
119
+ "type": "application/hal+json"
120
+ },
121
+ "documentation": {
122
+ "href": "https://docs.mollie.com/reference/v2/permissions-api/get-permission",
123
+ "type": "text/html"
124
+ }
125
+ }
126
+ },
127
+ {
128
+ "resource": "permission",
129
+ "id": "payments.read",
130
+ "description": "Some dummy permission description",
131
+ "granted": true,
132
+ "_links": {
133
+ "self": {
134
+ "href": "https://api.mollie.com/v2/permissions/payments.read",
135
+ "type": "application/hal+json"
136
+ },
137
+ "documentation": {
138
+ "href": "https://docs.mollie.com/reference/v2/permissions-api/get-permission",
139
+ "type": "text/html"
140
+ }
141
+ }
142
+ }
143
+ ]
144
+ },
145
+ "count": 2,
146
+ "_links": {
147
+ "documentation": {
148
+ "href": "https://docs.mollie.com/reference/v2/permissions-api/list-permissions",
149
+ "type": "text/html"
150
+ },
151
+ "self": {
152
+ "href": "https://api.mollie.com/v2/permissions",
153
+ "type": "application/hal+json"
154
+ }
155
+ }
156
+ }'
157
+ )
158
+ );
159
+
160
+ $permissions = $this->apiClient->permissions->all();
161
+
162
+ $this->assertInstanceOf(PermissionCollection::class, $permissions);
163
+
164
+ $this->assertCount(2, $permissions);
165
+
166
+ $this->assertPermission($permissions[0], 'payments.write');
167
+ $this->assertPermission($permissions[1], 'payments.read');
168
+ }
169
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/ProfileEndpointTest.php ADDED
@@ -0,0 +1,501 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\CurrentProfile;
8
+ use Mollie\Api\Resources\Profile;
9
+ use Mollie\Api\Resources\ProfileCollection;
10
+ use Mollie\Api\Types\ProfileStatus;
11
+
12
+ class ProfileEndpointTest extends BaseEndpointTest
13
+ {
14
+ public function testGetProfile()
15
+ {
16
+ $this->mockApiCall(
17
+ new Request(
18
+ "GET",
19
+ "/v2/profiles/pfl_ahe8z8OPut",
20
+ [],
21
+ ''
22
+ ),
23
+ new Response(
24
+ 200,
25
+ [],
26
+ '{
27
+ "resource": "profile",
28
+ "id": "pfl_ahe8z8OPut",
29
+ "mode": "live",
30
+ "name": "My website name",
31
+ "website": "http://www.mywebsite.com",
32
+ "email": "info@mywebsite.com",
33
+ "phone": "31123456789",
34
+ "categoryCode": 5399,
35
+ "status": "verified",
36
+ "review": {
37
+ "status": "pending"
38
+ },
39
+ "createdAt": "2016-01-11T13:03:55+00:00",
40
+ "_links": {
41
+ "self": {
42
+ "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut",
43
+ "type": "application/hal+json"
44
+ },
45
+ "chargebacks": {
46
+ "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut",
47
+ "type": "application/hal+json"
48
+ },
49
+ "methods": {
50
+ "href": "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut",
51
+ "type": "application/hal+json"
52
+ },
53
+ "payments": {
54
+ "href": "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut",
55
+ "type": "application/hal+json"
56
+ },
57
+ "refunds": {
58
+ "href": "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut",
59
+ "type": "application/hal+json"
60
+ },
61
+ "checkoutPreviewUrl": {
62
+ "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut",
63
+ "type": "text/html"
64
+ }
65
+ }
66
+ }'
67
+ )
68
+ );
69
+
70
+ $profile = $this->apiClient->profiles->get('pfl_ahe8z8OPut');
71
+
72
+ $this->assertInstanceOf(Profile::class, $profile);
73
+ $this->assertEquals("pfl_ahe8z8OPut", $profile->id);
74
+ $this->assertEquals("live", $profile->mode);
75
+ $this->assertEquals("My website name", $profile->name);
76
+ $this->assertEquals("http://www.mywebsite.com", $profile->website);
77
+ $this->assertEquals("info@mywebsite.com", $profile->email);
78
+ $this->assertEquals("31123456789", $profile->phone);
79
+ $this->assertEquals(5399, $profile->categoryCode);
80
+ $this->assertEquals(ProfileStatus::STATUS_VERIFIED, $profile->status);
81
+ $this->assertEquals((object) ["status" => "pending"], $profile->review);
82
+
83
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", "type" => "application/hal+json"];
84
+ $this->assertEquals($selfLink, $profile->_links->self);
85
+
86
+ $chargebacksLink = (object)["href" => "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut", "type" => "application/hal+json"];
87
+ $this->assertEquals($chargebacksLink, $profile->_links->chargebacks);
88
+
89
+ $methodsLink = (object)["href" => "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut", "type" => "application/hal+json"];
90
+ $this->assertEquals($methodsLink, $profile->_links->methods);
91
+
92
+ $paymentsLink = (object)["href" => "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut", "type" => "application/hal+json"];
93
+ $this->assertEquals($paymentsLink, $profile->_links->payments);
94
+
95
+ $refundsLink = (object)["href" => "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut", "type" => "application/hal+json"];
96
+ $this->assertEquals($refundsLink, $profile->_links->refunds);
97
+
98
+ $checkoutPreviewLink = (object)["href" => "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut", "type" => "text/html"];
99
+ $this->assertEquals($checkoutPreviewLink, $profile->_links->checkoutPreviewUrl);
100
+ }
101
+
102
+ public function testGetProfileUsingMe()
103
+ {
104
+ $this->mockApiCall(
105
+ new Request(
106
+ "GET",
107
+ "/v2/profiles/me",
108
+ [],
109
+ ''
110
+ ),
111
+ new Response(
112
+ 200,
113
+ [],
114
+ '{
115
+ "resource": "profile",
116
+ "id": "pfl_ahe8z8OPut",
117
+ "mode": "live",
118
+ "name": "My website name",
119
+ "website": "http://www.mywebsite.com",
120
+ "email": "info@mywebsite.com",
121
+ "phone": "31123456789",
122
+ "categoryCode": 5399,
123
+ "status": "verified",
124
+ "review": {
125
+ "status": "pending"
126
+ },
127
+ "createdAt": "2016-01-11T13:03:55+00:00",
128
+ "_links": {
129
+ "self": {
130
+ "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut",
131
+ "type": "application/hal+json"
132
+ },
133
+ "chargebacks": {
134
+ "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut",
135
+ "type": "application/hal+json"
136
+ },
137
+ "methods": {
138
+ "href": "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut",
139
+ "type": "application/hal+json"
140
+ },
141
+ "payments": {
142
+ "href": "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut",
143
+ "type": "application/hal+json"
144
+ },
145
+ "refunds": {
146
+ "href": "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut",
147
+ "type": "application/hal+json"
148
+ },
149
+ "checkoutPreviewUrl": {
150
+ "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut",
151
+ "type": "text/html"
152
+ }
153
+ }
154
+ }'
155
+ )
156
+ );
157
+
158
+ $profile = $this->apiClient->profiles->get('me');
159
+
160
+ $this->assertInstanceOf(CurrentProfile::class, $profile);
161
+ $this->assertEquals("pfl_ahe8z8OPut", $profile->id);
162
+
163
+ // No need to test it all again...
164
+ }
165
+
166
+ public function testGetCurrentProfile()
167
+ {
168
+ $this->mockApiCall(
169
+ new Request(
170
+ "GET",
171
+ "/v2/profiles/me",
172
+ [],
173
+ ''
174
+ ),
175
+ new Response(
176
+ 200,
177
+ [],
178
+ '{
179
+ "resource": "profile",
180
+ "id": "pfl_ahe8z8OPut",
181
+ "mode": "live",
182
+ "name": "My website name",
183
+ "website": "http://www.mywebsite.com",
184
+ "email": "info@mywebsite.com",
185
+ "phone": "31123456789",
186
+ "categoryCode": 5399,
187
+ "status": "verified",
188
+ "review": {
189
+ "status": "pending"
190
+ },
191
+ "createdAt": "2016-01-11T13:03:55+00:00",
192
+ "_links": {
193
+ "self": {
194
+ "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut",
195
+ "type": "application/hal+json"
196
+ },
197
+ "chargebacks": {
198
+ "href": "https://api.mollie.com/v2/chargebacks",
199
+ "type": "application/hal+json"
200
+ },
201
+ "methods": {
202
+ "href": "https://api.mollie.com/v2/methods",
203
+ "type": "application/hal+json"
204
+ },
205
+ "payments": {
206
+ "href": "https://api.mollie.com/v2/payments",
207
+ "type": "application/hal+json"
208
+ },
209
+ "refunds": {
210
+ "href": "https://api.mollie.com/v2/refunds",
211
+ "type": "application/hal+json"
212
+ },
213
+ "checkoutPreviewUrl": {
214
+ "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut",
215
+ "type": "text/html"
216
+ }
217
+ }
218
+ }'
219
+ )
220
+ );
221
+
222
+ $profile = $this->apiClient->profiles->getCurrent();
223
+
224
+ $this->assertInstanceOf(CurrentProfile::class, $profile);
225
+ $this->assertEquals("pfl_ahe8z8OPut", $profile->id);
226
+ $this->assertEquals("live", $profile->mode);
227
+ $this->assertEquals("My website name", $profile->name);
228
+ $this->assertEquals("http://www.mywebsite.com", $profile->website);
229
+ $this->assertEquals("info@mywebsite.com", $profile->email);
230
+ $this->assertEquals("31123456789", $profile->phone);
231
+ $this->assertEquals(5399, $profile->categoryCode);
232
+ $this->assertEquals(ProfileStatus::STATUS_VERIFIED, $profile->status);
233
+ $this->assertEquals((object) ["status" => "pending"], $profile->review);
234
+
235
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", "type" => "application/hal+json"];
236
+ $this->assertEquals($selfLink, $profile->_links->self);
237
+
238
+ $chargebacksLink = (object)["href" => "https://api.mollie.com/v2/chargebacks", "type" => "application/hal+json"];
239
+ $this->assertEquals($chargebacksLink, $profile->_links->chargebacks);
240
+
241
+ $methodsLink = (object)["href" => "https://api.mollie.com/v2/methods", "type" => "application/hal+json"];
242
+ $this->assertEquals($methodsLink, $profile->_links->methods);
243
+
244
+ $paymentsLink = (object)["href" => "https://api.mollie.com/v2/payments", "type" => "application/hal+json"];
245
+ $this->assertEquals($paymentsLink, $profile->_links->payments);
246
+
247
+ $refundsLink = (object)["href" => "https://api.mollie.com/v2/refunds", "type" => "application/hal+json"];
248
+ $this->assertEquals($refundsLink, $profile->_links->refunds);
249
+
250
+ $checkoutPreviewLink = (object)["href" => "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut", "type" => "text/html"];
251
+ $this->assertEquals($checkoutPreviewLink, $profile->_links->checkoutPreviewUrl);
252
+ }
253
+
254
+ public function testListProfiles()
255
+ {
256
+ $this->mockApiCall(
257
+ new Request(
258
+ "GET",
259
+ "/v2/profiles",
260
+ [],
261
+ ''
262
+ ),
263
+ new Response(
264
+ 201,
265
+ [],
266
+ '{
267
+ "_embedded": {
268
+ "profiles": [{
269
+ "resource": "profile",
270
+ "id": "pfl_ahe8z8OPut",
271
+ "mode": "live",
272
+ "name": "My website name",
273
+ "website": "http://www.mywebsite.com",
274
+ "email": "info@mywebsite.com",
275
+ "phone": "31123456789",
276
+ "categoryCode": 5399,
277
+ "status": "verified",
278
+ "review": {
279
+ "status": "pending"
280
+ },
281
+ "createdAt": "2016-01-11T13:03:55+00:00",
282
+ "_links": {
283
+ "self": {
284
+ "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut",
285
+ "type": "application/hal+json"
286
+ },
287
+ "chargebacks": {
288
+ "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut",
289
+ "type": "application/hal+json"
290
+ },
291
+ "methods": {
292
+ "href": "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut",
293
+ "type": "application/hal+json"
294
+ },
295
+ "payments": {
296
+ "href": "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut",
297
+ "type": "application/hal+json"
298
+ },
299
+ "refunds": {
300
+ "href": "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut",
301
+ "type": "application/hal+json"
302
+ },
303
+ "checkoutPreviewUrl": {
304
+ "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut",
305
+ "type": "text/html"
306
+ }
307
+ }
308
+ },
309
+ {
310
+ "resource": "profile",
311
+ "id": "pfl_znNaTRkJs5",
312
+ "mode": "live",
313
+ "name": "My website name 2",
314
+ "website": "http://www.mywebsite2.com",
315
+ "email": "info@mywebsite2.com",
316
+ "phone": "31123456789",
317
+ "categoryCode": 5399,
318
+ "status": "verified",
319
+ "review": {
320
+ "status": "pending"
321
+ },
322
+ "createdAt": "2016-01-11T13:03:55+00:00",
323
+ "_links": {
324
+ "self": {
325
+ "href": "https://api.mollie.com/v2/profiles/pfl_znNaTRkJs5",
326
+ "type": "application/hal+json"
327
+ },
328
+ "chargebacks": {
329
+ "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_znNaTRkJs5",
330
+ "type": "application/hal+json"
331
+ },
332
+ "methods": {
333
+ "href": "https://api.mollie.com/v2/methods?profileId=pfl_znNaTRkJs5",
334
+ "type": "application/hal+json"
335
+ },
336
+ "payments": {
337
+ "href": "https://api.mollie.com/v2/payments?profileId=pfl_znNaTRkJs5",
338
+ "type": "application/hal+json"
339
+ },
340
+ "refunds": {
341
+ "href": "https://api.mollie.com/v2/refunds?profileId=pfl_znNaTRkJs5",
342
+ "type": "application/hal+json"
343
+ },
344
+ "checkoutPreviewUrl": {
345
+ "href": "https://www.mollie.com/payscreen/preview/pfl_znNaTRkJs5",
346
+ "type": "text/html"
347
+ }
348
+ }
349
+ }
350
+ ]
351
+ },
352
+ "count": 2,
353
+ "_links": {
354
+ "documentation": {
355
+ "href": "https://docs.mollie.com/reference/v2/profiles-api/list-profiles",
356
+ "type": "text/html"
357
+ },
358
+ "self": {
359
+ "href": "https://api.mollie.nl/v2/profiles?limit=50",
360
+ "type": "application/hal+json"
361
+ },
362
+ "previous": null,
363
+ "next": null
364
+ }
365
+ }'
366
+ )
367
+ );
368
+
369
+ $profiles = $this->apiClient->profiles->page();
370
+ $this->assertInstanceOf(ProfileCollection::class, $profiles);
371
+ $this->assertEquals(2, $profiles->count);
372
+
373
+ foreach($profiles as $profile) {
374
+ $this->assertInstanceOf(Profile::class, $profile);
375
+ }
376
+
377
+ $selfLink = (object)["href" => "https://api.mollie.nl/v2/profiles?limit=50", "type" => "application/hal+json"];
378
+ $this->assertEquals($selfLink, $profiles->_links->self);
379
+
380
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/profiles-api/list-profiles", "type" => "text/html"];
381
+ $this->assertEquals($documentationLink, $profiles->_links->documentation);
382
+
383
+ }
384
+
385
+ public function testUpdateProfile()
386
+ {
387
+ $expectedWebsiteName = 'Mollie';
388
+ $expectedEmail = 'mollie@mollie.com';
389
+ $expectedPhone = '31123456766';
390
+
391
+ $this->mockApiCall(
392
+ new Request('PATCH', '/v2/profiles/pfl_ahe8z8OPut'),
393
+ new Response(
394
+ 200,
395
+ [],
396
+ '{
397
+ "resource": "profile",
398
+ "id": "pfl_ahe8z8OPut",
399
+ "mode": "live",
400
+ "name": "' . $expectedWebsiteName . '",
401
+ "website": "http://www.mywebsite.com",
402
+ "email": "' . $expectedEmail . '",
403
+ "phone": "' . $expectedPhone . '",
404
+ "categoryCode": 5399,
405
+ "status": "verified",
406
+ "review": {
407
+ "status": "pending"
408
+ },
409
+ "createdAt": "2016-01-11T13:03:55+00:00",
410
+ "_links": {
411
+ "self": {
412
+ "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut",
413
+ "type": "application/hal+json"
414
+ },
415
+ "chargebacks": {
416
+ "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut",
417
+ "type": "application/hal+json"
418
+ },
419
+ "methods": {
420
+ "href": "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut",
421
+ "type": "application/hal+json"
422
+ },
423
+ "payments": {
424
+ "href": "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut",
425
+ "type": "application/hal+json"
426
+ },
427
+ "refunds": {
428
+ "href": "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut",
429
+ "type": "application/hal+json"
430
+ },
431
+ "checkoutPreviewUrl": {
432
+ "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut",
433
+ "type": "text/html"
434
+ }
435
+ }
436
+ }'
437
+ )
438
+ );
439
+
440
+ $profile = $this->getProfile();
441
+ $profile->name = $expectedWebsiteName;
442
+ $profile->email = $expectedEmail;
443
+ $profile->phone = $expectedPhone;
444
+
445
+ $updatedProfile = $profile->update();
446
+
447
+ $this->assertEquals($expectedWebsiteName, $updatedProfile->name);
448
+ $this->assertEquals($expectedEmail, $updatedProfile->email);
449
+ $this->assertEquals($expectedPhone, $updatedProfile->phone);
450
+ }
451
+
452
+ /**
453
+ * @return Profile
454
+ */
455
+ private function getProfile()
456
+ {
457
+ $json = '{
458
+ "resource": "profile",
459
+ "id": "pfl_ahe8z8OPut",
460
+ "mode": "live",
461
+ "name": "My website name",
462
+ "website": "http://www.mywebsite.com",
463
+ "email": "info@mywebsite.com",
464
+ "phone": "31123456789",
465
+ "categoryCode": 5399,
466
+ "status": "verified",
467
+ "review": {
468
+ "status": "pending"
469
+ },
470
+ "createdAt": "2016-01-11T13:03:55+00:00",
471
+ "_links": {
472
+ "self": {
473
+ "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut",
474
+ "type": "application/hal+json"
475
+ },
476
+ "chargebacks": {
477
+ "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut",
478
+ "type": "application/hal+json"
479
+ },
480
+ "methods": {
481
+ "href": "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut",
482
+ "type": "application/hal+json"
483
+ },
484
+ "payments": {
485
+ "href": "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut",
486
+ "type": "application/hal+json"
487
+ },
488
+ "refunds": {
489
+ "href": "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut",
490
+ "type": "application/hal+json"
491
+ },
492
+ "checkoutPreviewUrl": {
493
+ "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut",
494
+ "type": "text/html"
495
+ }
496
+ }
497
+ }';
498
+
499
+ return $this->copy(json_decode($json), new Profile($this->apiClient));
500
+ }
501
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\CurrentProfile;
8
+ use Mollie\Api\Resources\Method;
9
+ use Mollie\Api\Resources\Profile;
10
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
11
+
12
+ class ProfileMethodEndpointTest extends BaseEndpointTest
13
+ {
14
+ use LinkObjectTestHelpers;
15
+
16
+ public function testEnableProfileMethod()
17
+ {
18
+ $this->mockApiCall(
19
+ new Request(
20
+ "POST",
21
+ "/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact"
22
+ ),
23
+ new Response(
24
+ 201,
25
+ [],
26
+ '{
27
+ "resource": "method",
28
+ "id": "bancontact",
29
+ "description": "Bancontact",
30
+ "image": {
31
+ "size1x": "https://www.mollie.com/external/icons/payment-methods/bancontact.png",
32
+ "size2x": "https://www.mollie.com/external/icons/payment-methods/bancontact%402x.png",
33
+ "svg": "https://www.mollie.com/external/icons/payment-methods/bancontact.svg"
34
+ },
35
+ "_links": {
36
+ "self": {
37
+ "href": "https://api.mollie.com/v2/methods/bancontact",
38
+ "type": "application/hal+json"
39
+ },
40
+ "documentation": {
41
+ "href": "https://docs.mollie.com/reference/v2/profiles-api/activate-method",
42
+ "type": "text/html"
43
+ }
44
+ }
45
+ }'
46
+ )
47
+ );
48
+
49
+ $profile = $this->getProfile();
50
+ $method = $profile->enableMethod('bancontact');
51
+
52
+ $this->assertInstanceOf(Method::class, $method);
53
+ $this->assertEquals('bancontact', $method->id);
54
+ $this->assertEquals('Bancontact', $method->description);
55
+ $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact.png', $method->image->size1x);
56
+ $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact%402x.png', $method->image->size2x);
57
+ $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact.svg', $method->image->svg);
58
+
59
+ $this->assertLinkObject(
60
+ "https://api.mollie.com/v2/methods/bancontact",
61
+ "application/hal+json",
62
+ $method->_links->self
63
+ );
64
+
65
+ $this->assertLinkObject(
66
+ "https://docs.mollie.com/reference/v2/profiles-api/activate-method",
67
+ "text/html",
68
+ $method->_links->documentation
69
+ );
70
+
71
+ }
72
+
73
+ public function testDisableProfileMethod()
74
+ {
75
+ $this->mockApiCall(
76
+ new Request(
77
+ "DELETE",
78
+ "/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact"
79
+ ),
80
+ new Response(204)
81
+ );
82
+
83
+ $profile = $this->getProfile();
84
+ $result = $profile->disableMethod('bancontact');
85
+
86
+ $this->assertNull($result);
87
+ }
88
+
89
+ public function testEnableCurrentProfileMethod()
90
+ {
91
+ $this->mockApiCall(
92
+ new Request(
93
+ "POST",
94
+ "/v2/profiles/me/methods/bancontact"
95
+ ),
96
+ new Response(
97
+ 201,
98
+ [],
99
+ '{
100
+ "resource": "method",
101
+ "id": "bancontact",
102
+ "description": "Bancontact",
103
+ "image": {
104
+ "size1x": "https://www.mollie.com/external/icons/payment-methods/bancontact.png",
105
+ "size2x": "https://www.mollie.com/external/icons/payment-methods/bancontact%402x.png",
106
+ "svg": "https://www.mollie.com/external/icons/payment-methods/bancontact.svg"
107
+ },
108
+ "_links": {
109
+ "self": {
110
+ "href": "https://api.mollie.com/v2/methods/bancontact",
111
+ "type": "application/hal+json"
112
+ },
113
+ "documentation": {
114
+ "href": "https://docs.mollie.com/reference/v2/profiles-api/activate-method",
115
+ "type": "text/html"
116
+ }
117
+ }
118
+ }'
119
+ )
120
+ );
121
+
122
+ $profile = $this->getCurrentProfile();
123
+ $method = $profile->enableMethod('bancontact');
124
+
125
+ $this->assertInstanceOf(Method::class, $method);
126
+ $this->assertEquals('bancontact', $method->id);
127
+ $this->assertEquals('Bancontact', $method->description);
128
+ $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact.png', $method->image->size1x);
129
+ $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact%402x.png', $method->image->size2x);
130
+ $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact.svg', $method->image->svg);
131
+
132
+ $this->assertLinkObject(
133
+ "https://api.mollie.com/v2/methods/bancontact",
134
+ "application/hal+json",
135
+ $method->_links->self
136
+ );
137
+
138
+ $this->assertLinkObject(
139
+ "https://docs.mollie.com/reference/v2/profiles-api/activate-method",
140
+ "text/html",
141
+ $method->_links->documentation
142
+ );
143
+
144
+ }
145
+
146
+ public function testDisableCurrentProfileMethod()
147
+ {
148
+ $this->mockApiCall(
149
+ new Request(
150
+ "DELETE",
151
+ "/v2/profiles/me/methods/bancontact"
152
+ ),
153
+ new Response(204)
154
+ );
155
+
156
+ $profile = $this->getCurrentProfile();
157
+
158
+ $result = $profile->disableMethod('bancontact');
159
+
160
+ $this->assertNull($result);
161
+ }
162
+
163
+ /**
164
+ * @return CurrentProfile
165
+ */
166
+ private function getCurrentProfile()
167
+ {
168
+ return $this->copy(
169
+ json_decode($this->getProfileFixture()),
170
+ new CurrentProfile($this->apiClient)
171
+ );
172
+ }
173
+
174
+ /**
175
+ * @return Profile
176
+ */
177
+ private function getProfile()
178
+ {
179
+ return $this->copy(
180
+ json_decode($this->getProfileFixture()),
181
+ new Profile($this->apiClient)
182
+ );
183
+ }
184
+
185
+ /**
186
+ * @return string
187
+ */
188
+ private function getProfileFixture()
189
+ {
190
+ return '{
191
+ "resource": "profile",
192
+ "id": "pfl_v9hTwCvYqw",
193
+ "mode": "live",
194
+ "name": "My website name",
195
+ "website": "http://www.mywebsite.com",
196
+ "email": "info@mywebsite.com",
197
+ "phone": "31123456789",
198
+ "categoryCode": 5399,
199
+ "status": "verified",
200
+ "review": {
201
+ "status": "pending"
202
+ },
203
+ "createdAt": "2016-01-11T13:03:55+00:00",
204
+ "_links": {
205
+ "self": {
206
+ "href": "https://api.mollie.com/v2/profiles/pfl_v9hTwCvYqw",
207
+ "type": "application/hal+json"
208
+ },
209
+ "chargebacks": {
210
+ "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_v9hTwCvYqw",
211
+ "type": "application/hal+json"
212
+ },
213
+ "methods": {
214
+ "href": "https://api.mollie.com/v2/methods?profileId=pfl_v9hTwCvYqw",
215
+ "type": "application/hal+json"
216
+ },
217
+ "payments": {
218
+ "href": "https://api.mollie.com/v2/payments?profileId=pfl_v9hTwCvYqw",
219
+ "type": "application/hal+json"
220
+ },
221
+ "refunds": {
222
+ "href": "https://api.mollie.com/v2/refunds?profileId=pfl_v9hTwCvYqw",
223
+ "type": "application/hal+json"
224
+ },
225
+ "checkoutPreviewUrl": {
226
+ "href": "https://www.mollie.com/payscreen/preview/pfl_v9hTwCvYqw",
227
+ "type": "text/html"
228
+ }
229
+ }
230
+ }';
231
+ }
232
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/RefundEndpointTest.php ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Payment;
8
+ use Mollie\Api\Resources\Refund;
9
+ use Mollie\Api\Resources\RefundCollection;
10
+
11
+ class RefundEndpointTest extends BaseEndpointTest
12
+ {
13
+ public function testListRefunds()
14
+ {
15
+ $this->mockApiCall(
16
+ new Request(
17
+ "GET",
18
+ "/v2/refunds",
19
+ [],
20
+ ''
21
+ ),
22
+ new Response(
23
+ 201,
24
+ [],
25
+ '{
26
+ "_embedded": {
27
+ "refunds": [
28
+ {
29
+ "resource": "refund",
30
+ "id": "re_haCsig5aru",
31
+ "amount": {
32
+ "value": "2.00",
33
+ "currency": "EUR"
34
+ },
35
+ "status": "pending",
36
+ "createdAt": "2018-03-28T10:56:10+00:00",
37
+ "description": "My first API payment",
38
+ "paymentId": "tr_44aKxzEbr8",
39
+ "settlementAmount": {
40
+ "value": "-2.00",
41
+ "currency": "EUR"
42
+ },
43
+ "_links": {
44
+ "self": {
45
+ "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru",
46
+ "type": "application/hal+json"
47
+ },
48
+ "payment": {
49
+ "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
50
+ "type": "application/hal+json"
51
+ }
52
+ }
53
+ }
54
+ ]
55
+ },
56
+ "_links": {
57
+ "documentation": {
58
+ "href": "https://docs.mollie.com/reference/v2/refunds-api/list-refunds",
59
+ "type": "text/html"
60
+ },
61
+ "self": {
62
+ "href": "http://api.mollie.nl/v2/payments/tr_44aKxzEbr8/refunds?limit=10",
63
+ "type": "application/hal+json"
64
+ },
65
+ "previous": null,
66
+ "next": null
67
+ },
68
+ "count": 1
69
+ }'
70
+ )
71
+ );
72
+
73
+ $refunds = $this->apiClient->refunds->page();
74
+
75
+ $this->assertInstanceOf(RefundCollection::class, $refunds);
76
+ $this->assertEquals(1, $refunds->count);
77
+ $this->assertCount(1, $refunds);
78
+
79
+ $refund = $refunds[0];
80
+
81
+ $this->assertInstanceOf(Refund::class, $refund);
82
+ $this->assertEquals("re_haCsig5aru", $refund->id);
83
+ $this->assertEquals("2.00", $refund->amount->value);
84
+ $this->assertEquals("EUR", $refund->amount->currency);
85
+ $this->assertEquals("pending", $refund->status);
86
+ $this->assertEquals("2018-03-28T10:56:10+00:00", $refund->createdAt);
87
+ $this->assertEquals("My first API payment", $refund->description);
88
+ $this->assertEquals("tr_44aKxzEbr8", $refund->paymentId);
89
+ $this->assertEquals("-2.00", $refund->settlementAmount->value);
90
+ $this->assertEquals("EUR", $refund->settlementAmount->currency);
91
+
92
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru", "type" => "application/hal+json"];
93
+ $this->assertEquals($selfLink, $refund->_links->self);
94
+
95
+ $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"];
96
+ $this->assertEquals($paymentLink, $refund->_links->payment);
97
+ }
98
+
99
+ /**
100
+ * @return Payment
101
+ */
102
+ private function getPayment()
103
+ {
104
+ $paymentJson = '{
105
+ "resource":"payment",
106
+ "id":"tr_44aKxzEbr8",
107
+ "mode":"test",
108
+ "createdAt":"2018-03-19T12:17:57+00:00",
109
+ "amount":{
110
+ "value":"20.00",
111
+ "currency":"EUR"
112
+ },
113
+ "description":"My first API payment",
114
+ "method":"ideal",
115
+ "metadata":{
116
+ "order_id":1234
117
+ },
118
+ "status":"paid",
119
+ "paidAt":"2018-03-19T12:18:35+00:00",
120
+ "amountRefunded":{
121
+ "value":"0.00",
122
+ "currency":"EUR"
123
+ },
124
+ "amountRemaining":{
125
+ "value":"20.00",
126
+ "currency":"EUR"
127
+ },
128
+ "details":{
129
+ "consumerName":"T. TEST",
130
+ "consumerAccount":"NL17RABO0213698412",
131
+ "consumerBic":"TESTNL99"
132
+ },
133
+ "locale":"nl_NL",
134
+ "countryCode":"NL",
135
+ "profileId":"pfl_2A1gacu42V",
136
+ "sequenceType":"oneoff",
137
+ "redirectUrl":"http://example.org/examples/03-return-page.php?order_id=1234",
138
+ "webhookUrl":"http://example.org/examples/02-webhook-verification.php",
139
+ "settlementAmount":{
140
+ "value":"20.00",
141
+ "currency":"EUR"
142
+ },
143
+ "_links":{
144
+ "self":{
145
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8",
146
+ "type":"application/hal+json"
147
+ },
148
+ "documentation":{
149
+ "href":"https://docs.mollie.com/reference/v2/payments-api/get-payment",
150
+ "type":"text/html"
151
+ },
152
+ "refunds":{
153
+ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds",
154
+ "type":"application/hal+json"
155
+ }
156
+ }
157
+ }';
158
+
159
+ return $this->copy(json_decode($paymentJson), new Payment($this->apiClient));
160
+ }
161
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/SettlementEndpointTest.php ADDED
@@ -0,0 +1,450 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Settlement;
8
+ use Mollie\Api\Resources\SettlementCollection;
9
+ use Mollie\Api\Types\SettlementStatus;
10
+
11
+ class SettlementEndpointTest extends BaseEndpointTest
12
+ {
13
+ public function testGetSettlement()
14
+ {
15
+ $this->mockApiCall(
16
+ new Request(
17
+ "GET",
18
+ "/v2/settlements/stl_xcaSGAHuRt",
19
+ [],
20
+ ''
21
+ ),
22
+ new Response(
23
+ 200,
24
+ [],
25
+ '{
26
+ "resource": "settlement",
27
+ "id": "stl_xcaSGAHuRt",
28
+ "reference": "1234567.1234.12",
29
+ "createdAt": "2018-04-30T04:00:02+00:00",
30
+ "settledAt": "2018-05-01T04:00:02+00:00",
31
+ "status": "pending",
32
+ "amount": {
33
+ "value": "1980.98",
34
+ "currency": "EUR"
35
+ },
36
+ "periods": {
37
+ "2018": {
38
+ "04": {
39
+ "revenue": [
40
+ {
41
+ "description": "Creditcard",
42
+ "method": "creditcard",
43
+ "count": 2,
44
+ "amountNet": {
45
+ "value": "790.00",
46
+ "currency": "EUR"
47
+ },
48
+ "amountVat": null,
49
+ "amountGross": {
50
+ "value": "1000.00",
51
+ "currency": "EUR"
52
+ }
53
+ },
54
+ {
55
+ "description": "iDEAL",
56
+ "method": "ideal",
57
+ "count": 2,
58
+ "amountNet": {
59
+ "value": "790.00",
60
+ "currency": "EUR"
61
+ },
62
+ "amountVat": null,
63
+ "amountGross": {
64
+ "value": "1000.00",
65
+ "currency": "EUR"
66
+ }
67
+ }
68
+ ],
69
+ "costs": [
70
+ {
71
+ "description": "Creditcard",
72
+ "method": "creditcard",
73
+ "count": 2,
74
+ "rate": {
75
+ "fixed": {
76
+ "value": "0.00",
77
+ "currency": "EUR"
78
+ },
79
+ "percentage": "1.80"
80
+ },
81
+ "amountNet": {
82
+ "value": "14.22",
83
+ "currency": "EUR"
84
+ },
85
+ "amountVat": {
86
+ "value": "2.9862",
87
+ "currency": "EUR"
88
+ },
89
+ "amountGross": {
90
+ "value": "17.2062",
91
+ "currency": "EUR"
92
+ }
93
+ },
94
+ {
95
+ "description": "Fixed creditcard costs",
96
+ "method": "creditcard",
97
+ "count": 2,
98
+ "rate": {
99
+ "fixed": {
100
+ "value": "0.25",
101
+ "currency": "EUR"
102
+ },
103
+ "percentage": "0"
104
+ },
105
+ "amountNet": {
106
+ "value": "0.50",
107
+ "currency": "EUR"
108
+ },
109
+ "amountVat": {
110
+ "value": "0.105",
111
+ "currency": "EUR"
112
+ },
113
+ "amountGross": {
114
+ "value": "0.605",
115
+ "currency": "EUR"
116
+ }
117
+ },
118
+ {
119
+ "description": "Fixed iDEAL costs",
120
+ "method": "ideal",
121
+ "count": 2,
122
+ "rate": {
123
+ "fixed": {
124
+ "value": "0.25",
125
+ "currency": "EUR"
126
+ },
127
+ "percentage": "0"
128
+ },
129
+ "amountNet": {
130
+ "value": "0.50",
131
+ "currency": "EUR"
132
+ },
133
+ "amountVat": {
134
+ "value": "0.105",
135
+ "currency": "EUR"
136
+ },
137
+ "amountGross": {
138
+ "value": "0.605",
139
+ "currency": "EUR"
140
+ }
141
+ },
142
+ {
143
+ "description": "Refunds iDEAL",
144
+ "method": "refund",
145
+ "count": 2,
146
+ "rate": {
147
+ "fixed": {
148
+ "value": "0.25",
149
+ "currency": "EUR"
150
+ },
151
+ "percentage": "0"
152
+ },
153
+ "amountNet": {
154
+ "value": "0.50",
155
+ "currency": "EUR"
156
+ },
157
+ "amountVat": {
158
+ "value": "0.105",
159
+ "currency": "EUR"
160
+ },
161
+ "amountGross": {
162
+ "value": "0.605",
163
+ "currency": "EUR"
164
+ }
165
+ }
166
+ ]
167
+ }
168
+ }
169
+ },
170
+ "invoiceId": "inv_VseyTUhJSy",
171
+ "_links": {
172
+ "self": {
173
+ "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt",
174
+ "type": "application/hal+json"
175
+ },
176
+ "payments": {
177
+ "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/payments",
178
+ "type": "application/hal+json"
179
+ },
180
+ "refunds": {
181
+ "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/refunds",
182
+ "type": "application/hal+json"
183
+ },
184
+ "chargebacks": {
185
+ "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/chargebacks",
186
+ "type": "application/hal+json"
187
+ },
188
+ "documentation": {
189
+ "href": "https://docs.mollie.com/reference/v2/settlements-api/get-settlement",
190
+ "type": "text/html"
191
+ }
192
+ }
193
+ }'
194
+ )
195
+ );
196
+
197
+ /** @var Settlement $settlement */
198
+ $settlement = $this->apiClient->settlements->get("stl_xcaSGAHuRt");
199
+
200
+ $this->assertInstanceOf(Settlement::class, $settlement);
201
+ $this->assertEquals("settlement", $settlement->resource);
202
+ $this->assertEquals("stl_xcaSGAHuRt", $settlement->id);
203
+ $this->assertEquals("1234567.1234.12", $settlement->reference);
204
+ $this->assertEquals("2018-04-30T04:00:02+00:00", $settlement->createdAt);
205
+ $this->assertEquals("2018-05-01T04:00:02+00:00", $settlement->settledAt);
206
+ $this->assertEquals(SettlementStatus::STATUS_PENDING, $settlement->status);
207
+ $this->assertEquals((object) ["value" => "1980.98", "currency" => "EUR"], $settlement->amount);
208
+ $this->assertNotEmpty($settlement->periods);
209
+ $this->assertEquals("inv_VseyTUhJSy", $settlement->invoiceId);
210
+
211
+ $selfLink = (object)['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt', 'type' => 'application/hal+json'];
212
+ $this->assertEquals($selfLink, $settlement->_links->self);
213
+
214
+ $paymentLink = (object)['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/payments', 'type' => 'application/hal+json'];
215
+ $this->assertEquals($paymentLink, $settlement->_links->payments);
216
+
217
+ $refundLink = (object)['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/refunds', 'type' => 'application/hal+json'];
218
+ $this->assertEquals($refundLink, $settlement->_links->refunds);
219
+
220
+ $chargebackLink = (object)['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/chargebacks', 'type' => 'application/hal+json'];
221
+ $this->assertEquals($chargebackLink, $settlement->_links->chargebacks);
222
+
223
+ $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/settlements-api/get-settlement', 'type' => 'text/html'];
224
+ $this->assertEquals($documentationLink, $settlement->_links->documentation);
225
+ }
226
+
227
+ public function testListSettlement()
228
+ {
229
+ $this->mockApiCall(
230
+ new Request(
231
+ "GET",
232
+ "/v2/settlements",
233
+ [],
234
+ ''
235
+ ),
236
+ new Response(
237
+ 200,
238
+ [],
239
+ '{
240
+ "_embedded": {
241
+ "settlements": [
242
+ {
243
+ "resource": "settlement",
244
+ "id": "stl_xcaSGAHuRt",
245
+ "reference": "1234567.1234.12",
246
+ "createdAt": "2018-04-30T04:00:02+00:00",
247
+ "settledAt": "2018-05-01T04:00:02+00:00",
248
+ "status": "pending",
249
+ "amount": {
250
+ "value": "1980.98",
251
+ "currency": "EUR"
252
+ },
253
+ "periods": {
254
+ "2018": {
255
+ "04": {
256
+ "revenue": [
257
+ {
258
+ "description": "Creditcard",
259
+ "method": "creditcard",
260
+ "count": 2,
261
+ "amountNet": {
262
+ "value": "790.00",
263
+ "currency": "EUR"
264
+ },
265
+ "amountVat": null,
266
+ "amountGross": {
267
+ "value": "1000.00",
268
+ "currency": "EUR"
269
+ }
270
+ },
271
+ {
272
+ "description": "iDEAL",
273
+ "method": "ideal",
274
+ "count": 2,
275
+ "amountNet": {
276
+ "value": "790.00",
277
+ "currency": "EUR"
278
+ },
279
+ "amountVat": null,
280
+ "amountGross": {
281
+ "value": "1000.00",
282
+ "currency": "EUR"
283
+ }
284
+ }
285
+ ],
286
+ "costs": [
287
+ {
288
+ "description": "Creditcard",
289
+ "method": "creditcard",
290
+ "count": 2,
291
+ "rate": {
292
+ "fixed": {
293
+ "value": "0.00",
294
+ "currency": "EUR"
295
+ },
296
+ "percentage": "1.80"
297
+ },
298
+ "amountNet": {
299
+ "value": "14.22",
300
+ "currency": "EUR"
301
+ },
302
+ "amountVat": {
303
+ "value": "2.9862",
304
+ "currency": "EUR"
305
+ },
306
+ "amountGross": {
307
+ "value": "17.2062",
308
+ "currency": "EUR"
309
+ }
310
+ },
311
+ {
312
+ "description": "Fixed creditcard costs",
313
+ "method": "creditcard",
314
+ "count": 2,
315
+ "rate": {
316
+ "fixed": {
317
+ "value": "0.25",
318
+ "currency": "EUR"
319
+ },
320
+ "percentage": "0"
321
+ },
322
+ "amountNet": {
323
+ "value": "0.50",
324
+ "currency": "EUR"
325
+ },
326
+ "amountVat": {
327
+ "value": "0.105",
328
+ "currency": "EUR"
329
+ },
330
+ "amountGross": {
331
+ "value": "0.605",
332
+ "currency": "EUR"
333
+ }
334
+ },
335
+ {
336
+ "description": "Fixed iDEAL costs",
337
+ "method": "ideal",
338
+ "count": 2,
339
+ "rate": {
340
+ "fixed": {
341
+ "value": "0.25",
342
+ "currency": "EUR"
343
+ },
344
+ "percentage": "0"
345
+ },
346
+ "amountNet": {
347
+ "value": "0.50",
348
+ "currency": "EUR"
349
+ },
350
+ "amountVat": {
351
+ "value": "0.105",
352
+ "currency": "EUR"
353
+ },
354
+ "amountGross": {
355
+ "value": "0.605",
356
+ "currency": "EUR"
357
+ }
358
+ },
359
+ {
360
+ "description": "Refunds iDEAL",
361
+ "method": "refund",
362
+ "count": 2,
363
+ "rate": {
364
+ "fixed": {
365
+ "value": "0.25",
366
+ "currency": "EUR"
367
+ },
368
+ "percentage": "0"
369
+ },
370
+ "amountNet": {
371
+ "value": "0.50",
372
+ "currency": "EUR"
373
+ },
374
+ "amountVat": {
375
+ "value": "0.105",
376
+ "currency": "EUR"
377
+ },
378
+ "amountGross": {
379
+ "value": "0.605",
380
+ "currency": "EUR"
381
+ }
382
+ }
383
+ ]
384
+ }
385
+ }
386
+ },
387
+ "_links": {
388
+ "self": {
389
+ "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt",
390
+ "type": "application/hal+json"
391
+ },
392
+ "payments": {
393
+ "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/payments",
394
+ "type": "application/hal+json"
395
+ },
396
+ "refunds": {
397
+ "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/refunds",
398
+ "type": "application/hal+json"
399
+ },
400
+ "chargebacks": {
401
+ "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/chargebacks",
402
+ "type": "application/hal+json"
403
+ }
404
+ }
405
+ }
406
+ ]
407
+ },
408
+ "count": 1,
409
+ "_links": {
410
+ "documentation": {
411
+ "href": "https://docs.mollie.com/reference/v2/settlements-api/list-settlements",
412
+ "type": "text/html"
413
+ },
414
+ "self": {
415
+ "href": "https://api.mollie.nl/v2/settlements",
416
+ "type": "application/hal+json"
417
+ },
418
+ "previous": null,
419
+ "next": {
420
+ "href": "https://api.mollie.nl/v2/settlements?from=stl_xcaSGAHuRt&limit=1&previous=stl_xcaPACKpLs",
421
+ "type": "application/hal+json"
422
+ }
423
+ }
424
+ }'
425
+ )
426
+ );
427
+
428
+ /** @var Settlement $settlement */
429
+ $settlements = $this->apiClient->settlements->page();
430
+ $this->assertInstanceOf(SettlementCollection::class, $settlements);
431
+
432
+ $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/settlements-api/list-settlements', 'type' => 'text/html'];
433
+ $this->assertEquals($documentationLink, $settlements->_links->documentation);
434
+
435
+ $selfLink = (object)['href' => 'https://api.mollie.nl/v2/settlements', 'type' => 'application/hal+json'];
436
+ $this->assertEquals($selfLink, $settlements->_links->self);
437
+
438
+ $this->assertEmpty($settlements->_links->previous);
439
+
440
+ $nextLink = (object)['href' => 'https://api.mollie.nl/v2/settlements?from=stl_xcaSGAHuRt&limit=1&previous=stl_xcaPACKpLs', 'type' => 'application/hal+json'];
441
+ $this->assertEquals($nextLink, $settlements->_links->next);
442
+
443
+ foreach($settlements as $settlement) {
444
+ $this->assertInstanceOf(Settlement::class, $settlement);
445
+ $this->assertEquals("settlement", $settlement->resource);
446
+ $this->assertNotEmpty($settlement->periods);
447
+ }
448
+ }
449
+
450
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php ADDED
@@ -0,0 +1,565 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Order;
8
+ use Mollie\Api\Resources\OrderLine;
9
+ use Mollie\Api\Resources\Shipment;
10
+ use Mollie\Api\Resources\ShipmentCollection;
11
+ use Mollie\Api\Types\OrderLineStatus;
12
+ use Mollie\Api\Types\OrderStatus;
13
+ use Tests\Mollie\TestHelpers\AmountObjectTestHelpers;
14
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
15
+
16
+ class ShipmentEndpointTest extends BaseEndpointTest
17
+ {
18
+ use LinkObjectTestHelpers;
19
+ use AmountObjectTestHelpers;
20
+
21
+ public function testCreateShipment()
22
+ {
23
+ $this->mockApiCall(
24
+ new Request(
25
+ "POST",
26
+ "/v2/orders/ord_pbjz8x/shipments",
27
+ [],
28
+ '{
29
+ "lines": [
30
+ {
31
+ "id": "odl_dgtxyl",
32
+ "quantity": 1
33
+ },
34
+ {
35
+ "id": "odl_jp31jz"
36
+ }
37
+ ]
38
+ }'
39
+ ),
40
+ new Response(
41
+ 201,
42
+ [],
43
+ $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x")
44
+ )
45
+ );
46
+
47
+ $order = $this->getOrder('ord_pbjz8x');
48
+ $shipment = $order->createShipment([
49
+ 'lines' => [
50
+ [
51
+ 'id' => 'odl_dgtxyl',
52
+ 'quantity' => 1,
53
+ ],
54
+ [
55
+ 'id' => 'odl_jp31jz'
56
+ ],
57
+ ],
58
+ ]);
59
+
60
+ $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x');
61
+ }
62
+
63
+ public function testCreateShipmentUsingShorthand()
64
+ {
65
+ $this->mockApiCall(
66
+ new Request(
67
+ "POST",
68
+ "/v2/orders/ord_pbjz8x/shipments",
69
+ [],
70
+ '{
71
+ "lines": []
72
+ }'
73
+ ),
74
+ new Response(
75
+ 201,
76
+ [],
77
+ $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x")
78
+ )
79
+ );
80
+
81
+ $order = $this->getOrder('ord_pbjz8x');
82
+ $shipment = $order->shipAll();
83
+
84
+ $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x');
85
+ }
86
+
87
+ public function testGetShipment()
88
+ {
89
+ $this->mockApiCall(
90
+ new Request(
91
+ "GET",
92
+ "/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U"
93
+ ),
94
+ new Response(
95
+ 200,
96
+ [],
97
+ $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x")
98
+ )
99
+ );
100
+
101
+ $order = $this->getOrder('ord_pbjz8x');
102
+ $shipment = $this->apiClient->shipments->getFor($order, "shp_3wmsgCJN4U");
103
+
104
+ $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x');
105
+ }
106
+
107
+ public function testGetShipmentOnOrderResource()
108
+ {
109
+ $this->mockApiCall(
110
+ new Request(
111
+ "GET",
112
+ "/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U"
113
+ ),
114
+ new Response(
115
+ 200,
116
+ [],
117
+ $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x")
118
+ )
119
+ );
120
+
121
+ $order = $this->getOrder('ord_pbjz8x');
122
+ $shipment = $order->getShipment('shp_3wmsgCJN4U');
123
+
124
+ $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x');
125
+ }
126
+
127
+ public function testListShipmentsViaShipmentEndpoint()
128
+ {
129
+ $this->mockApiCall(
130
+ new Request(
131
+ "GET",
132
+ "/v2/orders/ord_pbjz8x/shipments"
133
+ ),
134
+ new Response(
135
+ 200,
136
+ [],
137
+ '{
138
+ "count": 2,
139
+ "_embedded": {
140
+ "shipments": [
141
+ ' . $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x") . ',
142
+ ' . $this->getShipmentResponseFixture("shp_kjh234CASX", "ord_pbjz8x") . '
143
+ ]
144
+ },
145
+ "_links": {
146
+ "self": {
147
+ "href": "https://api.mollie.com/v2/order/ord_pbjz8x/shipments",
148
+ "type": "application/hal+json"
149
+ },
150
+ "documentation": {
151
+ "href": "https://docs.mollie.com/reference/v2/shipments-api/list-shipments",
152
+ "type": "text/html"
153
+ }
154
+ }
155
+ }'
156
+ )
157
+ );
158
+
159
+ $order = $this->getOrder('ord_pbjz8x');
160
+ $shipments = $this->apiClient->shipments->listFor($order);
161
+
162
+ $this->assertInstanceOf(ShipmentCollection::class, $shipments);
163
+ $this->assertShipment($shipments[0], 'shp_3wmsgCJN4U', 'ord_pbjz8x');
164
+ $this->assertShipment($shipments[1], 'shp_kjh234CASX', 'ord_pbjz8x');
165
+ }
166
+
167
+ public function testListShipmentsOnOrderResource()
168
+ {
169
+ $this->mockApiCall(
170
+ new Request(
171
+ "GET",
172
+ "/v2/orders/ord_pbjz8x/shipments"
173
+ ),
174
+ new Response(
175
+ 200,
176
+ [],
177
+ '{
178
+ "count": 2,
179
+ "_embedded": {
180
+ "shipments": [
181
+ ' . $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x") . ',
182
+ ' . $this->getShipmentResponseFixture("shp_kjh234CASX", "ord_pbjz8x") . '
183
+ ]
184
+ },
185
+ "_links": {
186
+ "self": {
187
+ "href": "https://api.mollie.com/v2/order/ord_pbjz8x/shipments",
188
+ "type": "application/hal+json"
189
+ },
190
+ "documentation": {
191
+ "href": "https://docs.mollie.com/reference/v2/shipments-api/list-shipments",
192
+ "type": "text/html"
193
+ }
194
+ }
195
+ }'
196
+ )
197
+ );
198
+
199
+ $order = $this->getOrder('ord_pbjz8x');
200
+
201
+ $shipments = $order->shipments();
202
+
203
+ $this->assertInstanceOf(ShipmentCollection::class, $shipments);
204
+ $this->assertShipment($shipments[0], 'shp_3wmsgCJN4U', 'ord_pbjz8x');
205
+ $this->assertShipment($shipments[1], 'shp_kjh234CASX', 'ord_pbjz8x');
206
+ }
207
+
208
+ public function testUpdateShipmentTrackingInfo()
209
+ {
210
+ $this->mockApiCall(
211
+ new Request(
212
+ "PATCH",
213
+ "/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U",
214
+ [],
215
+ '{
216
+ "tracking": {
217
+ "carrier": "PostNL",
218
+ "code": "3SKABA000000000",
219
+ "url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C"
220
+ }
221
+ }'
222
+ ),
223
+ new Response(
224
+ 200,
225
+ [],
226
+ $this->getShipmentResponseFixture(
227
+ "shp_3wmsgCJN4U",
228
+ "ord_pbjz8x",
229
+ OrderLineStatus::STATUS_SHIPPING,
230
+ '"tracking": {
231
+ "carrier": "PostNL",
232
+ "code": "3SKABA000000000",
233
+ "url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C"
234
+ },'
235
+ )
236
+ )
237
+ );
238
+
239
+ $shipment = $this->getShipment('shp_3wmsgCJN4U', 'ord_pbjz8x', OrderLineStatus::STATUS_SHIPPING);
240
+
241
+ $shipment->tracking = [
242
+ 'carrier' => 'PostNL',
243
+ 'code' => '3SKABA000000000',
244
+ 'url' => 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C',
245
+ ];
246
+ $shipment = $shipment->update();
247
+
248
+ $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x');
249
+
250
+ $this->assertEquals((object) [
251
+ 'carrier' => 'PostNL',
252
+ 'code' => '3SKABA000000000',
253
+ 'url' => 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C',
254
+ ], $shipment->tracking);
255
+ }
256
+
257
+ protected function assertShipment($shipment, $shipment_id, $order_id)
258
+ {
259
+ $this->assertInstanceOf(Shipment::class, $shipment);
260
+ $this->assertEquals("shipment", $shipment->resource);
261
+ $this->assertEquals($shipment_id, $shipment->id);
262
+ $this->assertEquals($order_id, $shipment->orderId);
263
+ $this->assertEquals('2018-08-02T09:29:56+00:00', $shipment->createdAt);
264
+ $this->assertLinkObject(
265
+ "https://api.mollie.com/v2/orders/ord_pbjz8x/shipments/{$shipment_id}",
266
+ 'application/hal+json',
267
+ $shipment->_links->self
268
+ );
269
+ $this->assertLinkObject(
270
+ 'https://api.mollie.com/v2/orders/ord_pbjz8x',
271
+ 'application/hal+json',
272
+ $shipment->_links->order
273
+ );
274
+ $this->assertLinkObject(
275
+ 'https://docs.mollie.com/reference/v2/shipments-api/get-shipment',
276
+ 'text/html',
277
+ $shipment->_links->documentation
278
+ );
279
+
280
+ $line1 = $shipment->lines()[0];
281
+ $this->assertEquals('orderline', $line1->resource);
282
+ $this->assertEquals('odl_dgtxyl', $line1->id);
283
+ $this->assertEquals('ord_pbjz8x', $line1->orderId);
284
+ $this->assertEquals('LEGO 42083 Bugatti Chiron', $line1->name);
285
+ $this->assertEquals('https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', $line1->productUrl);
286
+ $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line1->imageUrl);
287
+ $this->assertEquals('5702016116977', $line1->sku);
288
+ $this->assertEquals('physical', $line1->type);
289
+ $this->assertEquals(OrderLineStatus::STATUS_SHIPPING, $line1->status);
290
+ $this->assertEquals(2, $line1->quantity);
291
+ $this->assertEquals('2018-08-02T09:29:56+00:00', $line1->createdAt);
292
+ $this->assertEquals('21.00', $line1->vatRate);
293
+ $this->assertAmountObject('121.14', 'EUR', $line1->vatAmount);
294
+ $this->assertAmountObject('399.00', 'EUR', $line1->unitPrice);
295
+ $this->assertAmountObject('100.00', 'EUR', $line1->discountAmount);
296
+ $this->assertAmountObject('698.00', 'EUR', $line1->totalAmount);
297
+
298
+ $line2 = $shipment->lines()[1];
299
+ $this->assertEquals('orderline', $line2->resource);
300
+ $this->assertEquals('odl_jp31jz', $line2->id);
301
+ $this->assertEquals('ord_pbjz8x', $line2->orderId);
302
+ $this->assertEquals('LEGO 42056 Porsche 911 GT3 RS', $line2->name);
303
+ $this->assertEquals('https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056', $line2->productUrl);
304
+ $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', $line2->imageUrl);
305
+ $this->assertEquals('5702015594028', $line2->sku);
306
+ $this->assertEquals('digital', $line2->type);
307
+ $this->assertEquals(OrderLineStatus::STATUS_SHIPPING, $line2->status);
308
+ $this->assertEquals(1, $line2->quantity);
309
+ $this->assertEquals('2018-08-02T09:29:56+00:00', $line2->createdAt);
310
+ $this->assertEquals('21.00', $line2->vatRate);
311
+ $this->assertAmountObject('57.27', 'EUR', $line2->vatAmount);
312
+ $this->assertAmountObject('329.99', 'EUR', $line2->unitPrice);
313
+ $this->assertAmountObject('329.99', 'EUR', $line2->totalAmount);
314
+ }
315
+
316
+ protected function getOrder($id)
317
+ {
318
+ $orderJson = $this->getOrderResponseFixture($id);
319
+ return $this->copy(json_decode($orderJson), new Order($this->apiClient));
320
+ }
321
+
322
+ protected function getShipment($shipment_id, $order_id, $orderLineStatus = OrderLineStatus::STATUS_SHIPPING)
323
+ {
324
+ $shipmentJson = $this->getShipmentResponseFixture($shipment_id, $order_id, $orderLineStatus);
325
+ return $this->copy(json_decode($shipmentJson), new Shipment($this->apiClient));
326
+ }
327
+
328
+ protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::STATUS_CREATED)
329
+ {
330
+ return str_replace(
331
+ "<<order_id>>",
332
+ $order_id,
333
+ '{
334
+ "resource": "order",
335
+ "id": "<<order_id>>",
336
+ "profileId": "pfl_URR55HPMGx",
337
+ "amount": {
338
+ "value": "1027.99",
339
+ "currency": "EUR"
340
+ },
341
+ "amountCaptured": {
342
+ "value": "0.00",
343
+ "currency": "EUR"
344
+ },
345
+ "amountRefunded": {
346
+ "value": "0.00",
347
+ "currency": "EUR"
348
+ },
349
+ "status": "' . $order_status . '",
350
+ "metadata": {
351
+ "order_id": "1337",
352
+ "description": "Lego cars"
353
+ },
354
+ "consumerDateOfBirth": "1958-01-31",
355
+ "createdAt": "2018-08-02T09:29:56+00:00",
356
+ "mode": "live",
357
+ "billingAddress": {
358
+ "streetAndNumber": "Keizersgracht 313",
359
+ "postalCode": "1016 EE",
360
+ "city": "Amsterdam",
361
+ "country": "nl",
362
+ "givenName": "Luke",
363
+ "familyName": "Skywalker",
364
+ "email": "luke@skywalker.com"
365
+ },
366
+ "shippingAddress": {
367
+ "streetAndNumber": "Keizersgracht 313",
368
+ "postalCode": "1016 EE",
369
+ "city": "Amsterdam",
370
+ "country": "nl",
371
+ "givenName": "Luke",
372
+ "familyName": "Skywalker",
373
+ "email": "luke@skywalker.com"
374
+ },
375
+ "orderNumber": "1337",
376
+ "locale": "nl_NL",
377
+ "method" : "klarnapaylater",
378
+ "redirectUrl": "https://example.org/redirect",
379
+ "webhookUrl": "https://example.org/webhook",
380
+ "lines": [
381
+ {
382
+ "resource": "orderline",
383
+ "id": "odl_dgtxyl",
384
+ "orderId": "<<order_id>>",
385
+ "name": "LEGO 42083 Bugatti Chiron",
386
+ "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
387
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
388
+ "sku": "5702016116977",
389
+ "type": "physical",
390
+ "status": "created",
391
+ "quantity": 2,
392
+ "unitPrice": {
393
+ "value": "399.00",
394
+ "currency": "EUR"
395
+ },
396
+ "vatRate": "21.00",
397
+ "vatAmount": {
398
+ "value": "121.14",
399
+ "currency": "EUR"
400
+ },
401
+ "discountAmount": {
402
+ "value": "100.00",
403
+ "currency": "EUR"
404
+ },
405
+ "totalAmount": {
406
+ "value": "698.00",
407
+ "currency": "EUR"
408
+ },
409
+ "createdAt": "2018-08-02T09:29:56+00:00",
410
+ "_links": {
411
+ "self": {
412
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>/orderlines/odl_dgtxyl",
413
+ "type": "application/hal+json"
414
+ }
415
+ }
416
+ },
417
+ {
418
+ "resource": "orderline",
419
+ "id": "odl_jp31jz",
420
+ "orderId": "<<order_id>>",
421
+ "name": "LEGO 42056 Porsche 911 GT3 RS",
422
+ "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
423
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$",
424
+ "sku": "5702015594028",
425
+ "type": "digital",
426
+ "status": "created",
427
+ "quantity": 1,
428
+ "unitPrice": {
429
+ "value": "329.99",
430
+ "currency": "EUR"
431
+ },
432
+ "vatRate": "21.00",
433
+ "vatAmount": {
434
+ "value": "57.27",
435
+ "currency": "EUR"
436
+ },
437
+ "totalAmount": {
438
+ "value": "329.99",
439
+ "currency": "EUR"
440
+ },
441
+ "createdAt": "2018-08-02T09:29:56+00:00",
442
+ "_links": {
443
+ "self": {
444
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>/orderlines/odl_jp31jz",
445
+ "type": "application/hal+json"
446
+ }
447
+ }
448
+ }
449
+ ],
450
+ "_links": {
451
+ "self": {
452
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>",
453
+ "type": "application/hal+json"
454
+ },
455
+ "checkout": {
456
+ "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS",
457
+ "type": "text/html"
458
+ },
459
+ "documentation": {
460
+ "href": "https://docs.mollie.com/reference/v2/orders-api/get-order",
461
+ "type": "text/html"
462
+ }
463
+ }
464
+ }'
465
+ );
466
+ }
467
+
468
+ protected function getShipmentResponseFixture($shipment_id, $order_id, $orderline_status = OrderLineStatus::STATUS_SHIPPING, $tracking_info = '')
469
+ {
470
+ return str_replace(
471
+ [
472
+ "<<order_id>>",
473
+ "<<shipment_id>>",
474
+ "<<orderline_status>>",
475
+ "<<tracking_info>>",
476
+ ],
477
+ [
478
+ $order_id,
479
+ $shipment_id,
480
+ $orderline_status,
481
+ $tracking_info,
482
+ ],
483
+ '{
484
+ "resource": "shipment",
485
+ "id": "<<shipment_id>>",
486
+ "orderId": "<<order_id>>",
487
+ "createdAt": "2018-08-02T09:29:56+00:00",
488
+ "profileId": "pfl_URR55HPMGx",
489
+ <<tracking_info>>
490
+ "lines": [
491
+ {
492
+ "resource": "orderline",
493
+ "id": "odl_dgtxyl",
494
+ "orderId": "<<order_id>>",
495
+ "name": "LEGO 42083 Bugatti Chiron",
496
+ "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
497
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
498
+ "sku": "5702016116977",
499
+ "type": "physical",
500
+ "status": "<<orderline_status>>",
501
+ "quantity": 2,
502
+ "unitPrice": {
503
+ "value": "399.00",
504
+ "currency": "EUR"
505
+ },
506
+ "vatRate": "21.00",
507
+ "vatAmount": {
508
+ "value": "121.14",
509
+ "currency": "EUR"
510
+ },
511
+ "discountAmount": {
512
+ "value": "100.00",
513
+ "currency": "EUR"
514
+ },
515
+ "totalAmount": {
516
+ "value": "698.00",
517
+ "currency": "EUR"
518
+ },
519
+ "createdAt": "2018-08-02T09:29:56+00:00"
520
+ },
521
+ {
522
+ "resource": "orderline",
523
+ "id": "odl_jp31jz",
524
+ "orderId": "<<order_id>>",
525
+ "name": "LEGO 42056 Porsche 911 GT3 RS",
526
+ "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
527
+ "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$",
528
+ "sku": "5702015594028",
529
+ "type": "digital",
530
+ "status": "<<orderline_status>>",
531
+ "quantity": 1,
532
+ "unitPrice": {
533
+ "value": "329.99",
534
+ "currency": "EUR"
535
+ },
536
+ "vatRate": "21.00",
537
+ "vatAmount": {
538
+ "value": "57.27",
539
+ "currency": "EUR"
540
+ },
541
+ "totalAmount": {
542
+ "value": "329.99",
543
+ "currency": "EUR"
544
+ },
545
+ "createdAt": "2018-08-02T09:29:56+00:00"
546
+ }
547
+ ],
548
+ "_links": {
549
+ "self": {
550
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>/shipments/<<shipment_id>>",
551
+ "type": "application/hal+json"
552
+ },
553
+ "order": {
554
+ "href": "https://api.mollie.com/v2/orders/<<order_id>>",
555
+ "type": "application/hal+json"
556
+ },
557
+ "documentation": {
558
+ "href": "https://docs.mollie.com/reference/v2/shipments-api/get-shipment",
559
+ "type": "text/html"
560
+ }
561
+ }
562
+ }'
563
+ );
564
+ }
565
+ }
includes/mollie-api-php/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php ADDED
@@ -0,0 +1,491 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Endpoints;
4
+
5
+ use GuzzleHttp\Psr7\Request;
6
+ use GuzzleHttp\Psr7\Response;
7
+ use Mollie\Api\Resources\Customer;
8
+ use Mollie\Api\Resources\Subscription;
9
+ use Mollie\Api\Resources\SubscriptionCollection;
10
+ use Mollie\Api\Types\SubscriptionStatus;
11
+
12
+ class SubscriptionEndpointTest extends BaseEndpointTest
13
+ {
14
+ public function testCreateWorks()
15
+ {
16
+ $this->mockApiCall(
17
+ new Request('POST', '/v2/customers/cst_FhQJRw4s2n/subscriptions'),
18
+ new Response(
19
+ 200,
20
+ [],
21
+ '{
22
+ "resource": "subscription",
23
+ "id": "sub_wByQa6efm6",
24
+ "mode": "test",
25
+ "createdAt": "2018-04-24T11:41:55+00:00",
26
+ "status": "active",
27
+ "amount": {
28
+ "value": "10.00",
29
+ "currency": "EUR"
30
+ },
31
+ "description": "Order 1234",
32
+ "method": null,
33
+ "times": null,
34
+ "interval": "1 month",
35
+ "startDate": "2018-04-24",
36
+ "webhookUrl": null,
37
+ "_links": {
38
+ "self": {
39
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6",
40
+ "type": "application/hal+json"
41
+ },
42
+ "customer": {
43
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
44
+ "type": "application/hal+json"
45
+ },
46
+ "documentation": {
47
+ "href": "https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription",
48
+ "type": "text/html"
49
+ }
50
+ }
51
+ }'
52
+ )
53
+ );
54
+
55
+ $customer = $this->getCustomer();
56
+
57
+ /** @var Subscription $subscription */
58
+ $subscription = $customer->createSubscription([
59
+ "amount" => [
60
+ "value" => "10.00",
61
+ "currency" => "EUR"
62
+ ],
63
+ "interval" => "1 month",
64
+ "description" => "Order 1234"
65
+ ]);
66
+
67
+ $this->assertInstanceOf(Subscription::class, $subscription);
68
+ $this->assertEquals("subscription", $subscription->resource);
69
+ $this->assertEquals("sub_wByQa6efm6", $subscription->id);
70
+ $this->assertEquals("test", $subscription->mode);
71
+ $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt);
72
+ $this->assertEquals(SubscriptionStatus::STATUS_ACTIVE, $subscription->status);
73
+ $this->assertEquals((object)["value" => "10.00", "currency" => "EUR"], $subscription->amount);
74
+ $this->assertEquals("Order 1234", $subscription->description);
75
+ $this->assertNull($subscription->method);
76
+ $this->assertNull($subscription->times);
77
+ $this->assertEquals("1 month", $subscription->interval);
78
+ $this->assertEquals("2018-04-24", $subscription->startDate);
79
+
80
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", "type" => "application/hal+json"];
81
+ $this->assertEquals($selfLink, $subscription->_links->self);
82
+
83
+ $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"];
84
+ $this->assertEquals($customerLink, $subscription->_links->customer);
85
+
86
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription", "type" => "text/html"];
87
+ $this->assertEquals($documentationLink, $subscription->_links->documentation);
88
+ }
89
+
90
+ public function testGetWorks()
91
+ {
92
+ $this->mockApiCall(
93
+ new Request('GET', '/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6'),
94
+ new Response(
95
+ 200,
96
+ [],
97
+ '{
98
+ "resource": "subscription",
99
+ "id": "sub_wByQa6efm6",
100
+ "mode": "test",
101
+ "createdAt": "2018-04-24T11:41:55+00:00",
102
+ "status": "active",
103
+ "amount": {
104
+ "value": "10.00",
105
+ "currency": "EUR"
106
+ },
107
+ "description": "Order 1234",
108
+ "method": null,
109
+ "times": null,
110
+ "interval": "1 month",
111
+ "startDate": "2018-04-24",
112
+ "webhookUrl": null,
113
+ "_links": {
114
+ "self": {
115
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6",
116
+ "type": "application/hal+json"
117
+ },
118
+ "customer": {
119
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
120
+ "type": "application/hal+json"
121
+ },
122
+ "documentation": {
123
+ "href": "https://docs.mollie.com/reference/v2/subscriptions-api/get-subscription",
124
+ "type": "text/html"
125
+ }
126
+ }
127
+ }'
128
+ )
129
+ );
130
+
131
+ $customer = $this->getCustomer();
132
+
133
+ /** @var Subscription $subscription */
134
+ $subscription = $customer->getSubscription("sub_wByQa6efm6");
135
+
136
+ $this->assertInstanceOf(Subscription::class, $subscription);
137
+ $this->assertEquals("subscription", $subscription->resource);
138
+ $this->assertEquals("sub_wByQa6efm6", $subscription->id);
139
+ $this->assertEquals("test", $subscription->mode);
140
+ $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt);
141
+ $this->assertEquals(SubscriptionStatus::STATUS_ACTIVE, $subscription->status);
142
+ $this->assertEquals((object)["value" => "10.00", "currency" => "EUR"], $subscription->amount);
143
+ $this->assertEquals("Order 1234", $subscription->description);
144
+ $this->assertNull($subscription->method);
145
+ $this->assertNull($subscription->times);
146
+ $this->assertEquals("1 month", $subscription->interval);
147
+ $this->assertEquals("2018-04-24", $subscription->startDate);
148
+
149
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", "type" => "application/hal+json"];
150
+ $this->assertEquals($selfLink, $subscription->_links->self);
151
+
152
+ $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"];
153
+ $this->assertEquals($customerLink, $subscription->_links->customer);
154
+
155
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/get-subscription", "type" => "text/html"];
156
+ $this->assertEquals($documentationLink, $subscription->_links->documentation);
157
+ }
158
+
159
+ public function testListWorks()
160
+ {
161
+ $this->mockApiCall(
162
+ new Request('GET', '/v2/customers/cst_FhQJRw4s2n/subscriptions'),
163
+ new Response(
164
+ 200,
165
+ [],
166
+ '{
167
+ "_embedded": {
168
+ "subscriptions": [{
169
+ "resource": "subscription",
170
+ "id": "sub_wByQa6efm6",
171
+ "mode": "test",
172
+ "createdAt": "2018-04-24T11:41:55+00:00",
173
+ "status": "active",
174
+ "amount": {
175
+ "value": "10.00",
176
+ "currency": "EUR"
177
+ },
178
+ "description": "Order 1234",
179
+ "method": null,
180
+ "times": null,
181
+ "interval": "1 month",
182
+ "startDate": "2018-04-24",
183
+ "webhookUrl": null,
184
+ "_links": {
185
+ "self": {
186
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6",
187
+ "type": "application/hal+json"
188
+ },
189
+ "customer": {
190
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
191
+ "type": "application/hal+json"
192
+ }
193
+ }
194
+ }]
195
+ },
196
+ "count": 1,
197
+ "_links": {
198
+ "documentation": {
199
+ "href": "https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions",
200
+ "type": "text/html"
201
+ },
202
+ "self": {
203
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions?limit=50",
204
+ "type": "application/hal+json"
205
+ },
206
+ "previous": null,
207
+ "next": null
208
+ }
209
+ }'
210
+ )
211
+ );
212
+
213
+ $customer = $this->getCustomer();
214
+
215
+ $subscriptions = $customer->subscriptions();
216
+
217
+ $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions);
218
+
219
+ $this->assertEquals(count($subscriptions), $subscriptions->count);
220
+
221
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions", "type" => "text/html"];
222
+ $this->assertEquals($documentationLink, $subscriptions->_links->documentation);
223
+
224
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions?limit=50", "type" => "application/hal+json"];
225
+ $this->assertEquals($selfLink, $subscriptions->_links->self);
226
+
227
+ foreach ($subscriptions as $subscription) {
228
+ $this->assertInstanceOf(Subscription::class, $subscription);
229
+ $this->assertEquals("subscription", $subscription->resource);
230
+ $this->assertNotEmpty($subscription->createdAt);
231
+ }
232
+ }
233
+
234
+ public function testCancelViaCustomerResourceWorks()
235
+ {
236
+ $this->mockApiCall(
237
+ new Request('DELETE', '/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6'),
238
+ new Response(
239
+ 200,
240
+ [],
241
+ '{
242
+ "resource": "subscription",
243
+ "id": "sub_wByQa6efm6",
244
+ "mode": "test",
245
+ "createdAt": "2018-04-24T11:41:55+00:00",
246
+ "status": "canceled",
247
+ "amount": {
248
+ "value": "10.00",
249
+ "currency": "EUR"
250
+ },
251
+ "description": "Order 1234",
252
+ "method": null,
253
+ "times": null,
254
+ "interval": "1 month",
255
+ "startDate": "2018-04-24",
256
+ "webhookUrl": null,
257
+ "canceledAt": "2018-04-24T12:31:32+00:00",
258
+ "_links": {
259
+ "self": {
260
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6",
261
+ "type": "application/hal+json"
262
+ },
263
+ "customer": {
264
+ "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n",
265
+ "type": "application/hal+json"
266
+ },
267
+ "documentation": {
268
+ "href": "https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription",
269
+ "type": "text/html"
270
+ }
271
+ }
272
+ }'
273
+ )
274
+ );
275
+
276
+ $customer = $this->getCustomer();
277
+
278
+ /** @var Subscription $subscription */
279
+ $subscription = $customer->cancelSubscription("sub_wByQa6efm6");
280
+
281
+ $this->assertInstanceOf(Subscription::class, $subscription);
282
+ $this->assertEquals("subscription", $subscription->resource);
283
+ $this->assertEquals("sub_wByQa6efm6", $subscription->id);
284
+ $this->assertEquals("test", $subscription->mode);
285
+ $this->assertEquals(SubscriptionStatus::STATUS_CANCELED, $subscription->status);
286
+ $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt);
287
+ $this->assertEquals("2018-04-24T12:31:32+00:00", $subscription->canceledAt);
288
+
289
+
290
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", "type" => "application/hal+json"];
291
+ $this->assertEquals($selfLink, $subscription->_links->self);
292
+
293
+ $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"];
294
+ $this->assertEquals($customerLink, $subscription->_links->customer);
295
+
296
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription", "type" => "text/html"];
297
+ $this->assertEquals($documentationLink, $subscription->_links->documentation);
298
+ }
299
+
300
+ public function testCancelOnSubscriptionResourceWorks($value='')
301
+ {
302
+ $this->mockApiCall(
303
+ new Request('DELETE', '/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx'),
304
+ new Response(
305
+ 200,
306
+ [],
307
+ '{
308
+ "resource": "subscription",
309
+ "id": "sub_DRjwaT5qHx",
310
+ "mode": "test",
311
+ "createdAt": "2018-04-24T11:41:55+00:00",
312
+ "status": "canceled",
313
+ "amount": {
314
+ "value": "10.00",
315
+ "currency": "EUR"
316
+ },
317
+ "description": "Order 1234",
318
+ "method": null,
319
+ "times": null,
320
+ "interval": "1 month",
321
+ "startDate": "2018-04-24",
322
+ "webhookUrl": null,
323
+ "canceledAt": "2018-04-24T12:31:32+00:00",
324
+ "_links": {
325
+ "self": {
326
+ "href": "https://api.mollie.com/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx",
327
+ "type": "application/hal+json"
328
+ },
329
+ "customer": {
330
+ "href": "https://api.mollie.com/v2/customers/cst_VhjQebNW5j",
331
+ "type": "application/hal+json"
332
+ },
333
+ "documentation": {
334
+ "href": "https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription",
335
+ "type": "text/html"
336
+ }
337
+ }
338
+ }'
339
+ )
340
+ );
341
+
342
+ $subscription = $this->getSubscription();
343
+
344
+ $subscription = $subscription->cancel();
345
+
346
+ $this->assertInstanceOf(Subscription::class, $subscription);
347
+ $this->assertEquals("subscription", $subscription->resource);
348
+ $this->assertEquals("sub_DRjwaT5qHx", $subscription->id);
349
+ $this->assertEquals("test", $subscription->mode);
350
+ $this->assertEquals(SubscriptionStatus::STATUS_CANCELED, $subscription->status);
351
+ $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt);
352
+ $this->assertEquals("2018-04-24T12:31:32+00:00", $subscription->canceledAt);
353
+
354
+
355
+ $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx", "type" => "application/hal+json"];
356
+ $this->assertEquals($selfLink, $subscription->_links->self);
357
+
358
+ $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_VhjQebNW5j", "type" => "application/hal+json"];
359
+ $this->assertEquals($customerLink, $subscription->_links->customer);
360
+
361
+ $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription", "type" => "text/html"];
362
+ $this->assertEquals($documentationLink, $subscription->_links->documentation);
363
+ }
364
+
365
+ public function testThatUpdateSubscriptionWorks()
366
+ {
367
+ $expectedAmountValue = '12.00';
368
+ $expectedAmountCurrency = 'EUR';
369
+ $expectedStartDate = '2018-12-12';
370
+
371
+ $this->mockApiCall(
372
+ new Request('PATCH', '/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx'),
373
+ new Response(
374
+ 200,
375
+ [],
376
+ '{
377
+ "resource": "subscription",
378
+ "id": "sub_DRjwaT5qHx",
379
+ "customerId": "cst_VhjQebNW5j",
380
+ "mode": "live",
381
+ "createdAt": "2018-07-17T07:45:52+00:00",
382
+ "status": "active",
383
+ "amount": {
384
+ "value": "' . $expectedAmountValue . '",
385
+ "currency": "' . $expectedAmountCurrency . '"
386
+ },
387
+ "description": "Mollie Recurring subscription #1",
388
+ "method": null,
389
+ "times": 42,
390
+ "interval": "15 days",
391
+ "startDate": "' . $expectedStartDate . '",
392
+ "webhookUrl": "https://example.org/webhook",
393
+ "_links": {
394
+ "self": {
395
+ "href": "http://api.mollie.test/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx",
396
+ "type": "application/hal+json"
397
+ },
398
+ "customer": {
399
+ "href": "http://api.mollie.test/v2/customers/cst_VhjQebNW5j",
400
+ "type": "application/hal+json"
401
+ },
402
+ "documentation": {
403
+ "href": "https://docs.mollie.com/reference/v2/subscriptions-api/update-subscription",
404
+ "type": "text/html"
405
+ }
406
+ }
407
+ }'
408
+ )
409
+ );
410
+
411
+ $subscription = $this->getSubscription();
412
+ $expectedAmountObject = (object)[
413
+ 'value' => $expectedAmountValue,
414
+ 'currency' => $expectedAmountCurrency,
415
+ ];
416
+ $subscription->amount = $expectedAmountObject;
417
+ $subscription->startDate = $expectedStartDate;
418
+
419
+ $updatedSubscription = $subscription->update();
420
+
421
+ $this->assertEquals($expectedStartDate, $updatedSubscription->startDate);
422
+ $this->assertEquals($expectedAmountObject, $updatedSubscription->amount);
423
+ }
424
+
425
+ /**
426
+ * @return Subscription
427
+ */
428
+ private function getSubscription()
429
+ {
430
+ $subscriptionJson = '{
431
+ "resource": "subscription",
432
+ "id": "sub_DRjwaT5qHx",
433
+ "customerId": "cst_VhjQebNW5j",
434
+ "mode": "live",
435
+ "createdAt": "2018-07-17T07:45:52+00:00",
436
+ "status": "active",
437
+ "amount": {
438
+ "value": "10.00",
439
+ "currency": "EUR"
440
+ },
441
+ "description": "Mollie Recurring subscription #1",
442
+ "method": null,
443
+ "times": 42,
444
+ "interval": "15 days",
445
+ "startDate": "2018-12-12",
446
+ "webhookUrl": "https://example.org/webhook",
447
+ "_links": {
448
+ "self": {
449
+ "href": "http://api.mollie.test/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx",
450
+ "type": "application/hal+json"
451
+ },
452
+ "customer": {
453
+ "href": "http://api.mollie.test/v2/customers/cst_VhjQebNW5j",
454
+ "type": "application/hal+json"
455
+ },
456
+ "documentation": {
457
+ "href": "https://docs.mollie.com/reference/v2/subscriptions-api/update-subscription",
458
+ "type": "text/html"
459
+ }
460
+ }
461
+ }';
462
+
463
+ return $this->copy(json_decode($subscriptionJson), new Subscription($this->apiClient));
464
+ }
465
+
466
+ /**
467
+ * @return Customer
468
+ */
469
+ private function getCustomer()
470
+ {
471
+ $customerJson = '{
472
+ "resource": "customer",
473
+ "id": "cst_FhQJRw4s2n",
474
+ "mode": "test",
475
+ "name": "John Doe",
476
+ "email": "johndoe@example.org",
477
+ "locale": null,
478
+ "metadata": null,
479
+ "recentlyUsedMethods": [],
480
+ "createdAt": "2018-04-19T08:49:01+00:00",
481
+ "_links": {
482
+ "documentation": {
483
+ "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer",
484
+ "type": "text/html"
485
+ }
486
+ }
487
+ }';
488
+
489
+ return $this->copy(json_decode($customerJson), new Customer($this->apiClient));
490
+ }
491
+ }
includes/mollie-api-php/tests/Mollie/API/Exceptions/ApiExceptionTest.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\API\Exceptions;
4
+
5
+ use GuzzleHttp\Exception\RequestException;
6
+ use GuzzleHttp\Psr7\Request;
7
+ use GuzzleHttp\Psr7\Response;
8
+ use Mollie\Api\Exceptions\ApiException;
9
+ use PHPUnit\Framework\TestCase;
10
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
11
+
12
+ class ApiExceptionTest extends TestCase
13
+ {
14
+ use LinkObjectTestHelpers;
15
+
16
+ public function testCreateFromGuzzleException()
17
+ {
18
+ $response = new Response(
19
+ 422,
20
+ [],
21
+ '{
22
+ "status": 422,
23
+ "title": "Unprocessable Entity",
24
+ "detail": "Can not enable Credit card via the API. Please go to the dashboard to enable this payment method.",
25
+ "_links": {
26
+ "dashboard": {
27
+ "href": "https://www.mollie.com/dashboard/settings/profiles/pfl_v9hTwCvYqw/payment-methods",
28
+ "type": "text/html"
29
+ },
30
+ "documentation": {
31
+ "href": "https://docs.mollie.com/guides/handling-errors",
32
+ "type": "text/html"
33
+ }
34
+ }
35
+ }'
36
+ );
37
+
38
+ $guzzleException = new RequestException(
39
+ 'Something went wrong...',
40
+ new Request(
41
+ 'POST',
42
+ 'https://api.mollie.com/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact'
43
+ ),
44
+ $response
45
+ );
46
+
47
+ $exception = ApiException::createFromGuzzleException($guzzleException);
48
+
49
+ $this->assertInstanceOf(ApiException::class, $exception);
50
+ $this->assertInstanceOf(Response::class, $exception->getResponse());
51
+
52
+ $this->assertEquals($response, $exception->getResponse());
53
+ $this->assertTrue($exception->hasResponse());
54
+
55
+ $this->assertTrue($exception->hasLink('dashboard'));
56
+ $this->assertTrue($exception->hasLink('documentation'));
57
+ $this->assertFalse($exception->hasLink('foo'));
58
+
59
+ $this->assertLinkObject(
60
+ 'https://www.mollie.com/dashboard/settings/profiles/pfl_v9hTwCvYqw/payment-methods',
61
+ 'text/html',
62
+ $exception->getLink('dashboard')
63
+ );
64
+
65
+ $this->assertEquals(
66
+ 'https://www.mollie.com/dashboard/settings/profiles/pfl_v9hTwCvYqw/payment-methods',
67
+ $exception->getUrl('dashboard')
68
+ );
69
+
70
+ $this->assertEquals(
71
+ 'https://www.mollie.com/dashboard/settings/profiles/pfl_v9hTwCvYqw/payment-methods',
72
+ $exception->getDashboardUrl()
73
+ );
74
+
75
+ $this->assertLinkObject(
76
+ 'https://docs.mollie.com/guides/handling-errors',
77
+ 'text/html',
78
+ $exception->getLink('documentation')
79
+ );
80
+
81
+ $this->assertEquals(
82
+ 'https://docs.mollie.com/guides/handling-errors',
83
+ $exception->getDocumentationUrl()
84
+ );
85
+
86
+ $this->assertNull($exception->getLink('foo'));
87
+ $this->assertNull($exception->getUrl('foo'));
88
+ }
89
+ }
includes/mollie-api-php/tests/Mollie/API/MollieApiClientTest.php ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Tests\Mollie\Api;
3
+
4
+ use Eloquent\Liberator\Liberator;
5
+ use GuzzleHttp\Client;
6
+ use GuzzleHttp\ClientInterface;
7
+ use GuzzleHttp\Psr7\Response;
8
+ use Mollie\Api\Exceptions\ApiException;
9
+ use Mollie\Api\MollieApiClient;
10
+
11
+ class MollieApiClientTest extends \PHPUnit\Framework\TestCase
12
+ {
13
+ /**
14
+ * @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject
15
+ */
16
+ private $guzzleClient;
17
+
18
+ /**
19
+ * @var MollieApiClient
20
+ */
21
+ private $mollieApiClient;
22
+
23
+ protected function setUp()
24
+ {
25
+ parent::setUp();
26
+
27
+ $this->guzzleClient = $this->createMock(Client::class);
28
+ $this->mollieApiClient = new MollieApiClient($this->guzzleClient);
29
+
30
+ $this->mollieApiClient->setApiKey('test_foobarfoobarfoobarfoobarfoobar');
31
+ }
32
+
33
+ public function testPerformHttpCallReturnsBodyAsObject()
34
+ {
35
+ $response = new Response(200, [], '{"resource": "payment"}');
36
+
37
+ $this->guzzleClient
38
+ ->expects($this->once())
39
+ ->method('send')
40
+ ->willReturn($response);
41
+
42
+
43
+ $parsedResponse = $this->mollieApiClient->performHttpCall('GET', '');
44
+
45
+ $this->assertEquals(
46
+ (object)['resource' => 'payment'],
47
+ $parsedResponse
48
+ );
49
+ }
50
+
51
+ public function testPerformHttpCallCreatesApiExceptionCorrectly()
52
+ {
53
+ $this->expectException(ApiException::class);
54
+ $this->expectExceptionMessage('Error executing API call (422: Unprocessable Entity): Non-existent parameter "recurringType" for this API call. Did you mean: "sequenceType"?');
55
+ $this->expectExceptionCode(422);
56
+
57
+ $response = new Response(422, [], '{
58
+ "status": 422,
59
+ "title": "Unprocessable Entity",
60
+ "detail": "Non-existent parameter \"recurringType\" for this API call. Did you mean: \"sequenceType\"?",
61
+ "field": "recurringType",
62
+ "_links": {
63
+ "documentation": {
64
+ "href": "https://docs.mollie.com/guides/handling-errors",
65
+ "type": "text/html"
66
+ }
67
+ }
68
+ }');
69
+
70
+ $this->guzzleClient
71
+ ->expects($this->once())
72
+ ->method('send')
73
+ ->willReturn($response);
74
+
75
+ try {
76
+ $parsedResponse = $this->mollieApiClient->performHttpCall('GET', '');
77
+ } catch (ApiException $e) {
78
+ $this->assertEquals('recurringType', $e->getField());
79
+ $this->assertEquals('https://docs.mollie.com/guides/handling-errors', $e->getDocumentationUrl());
80
+ $this->assertEquals($response, $e->getResponse());
81
+
82
+ throw $e;
83
+ }
84
+ }
85
+
86
+ public function testPerformHttpCallCreatesApiExceptionWithoutFieldAndDocumentationUrl()
87
+ {
88
+ $this->expectException(ApiException::class);
89
+ $this->expectExceptionMessage('Error executing API call (422: Unprocessable Entity): Non-existent parameter "recurringType" for this API call. Did you mean: "sequenceType"?');
90
+ $this->expectExceptionCode(422);
91
+
92
+ $response = new Response(422, [], '{
93
+ "status": 422,
94
+ "title": "Unprocessable Entity",
95
+ "detail": "Non-existent parameter \"recurringType\" for this API call. Did you mean: \"sequenceType\"?"
96
+ }');
97
+
98
+ $this->guzzleClient
99
+ ->expects($this->once())
100
+ ->method('send')
101
+ ->willReturn($response);
102
+
103
+ try {
104
+ $parsedResponse = $this->mollieApiClient->performHttpCall('GET', '');
105
+ } catch (ApiException $e) {
106
+ $this->assertNull($e->getField());
107
+ $this->assertNull($e->getDocumentationUrl());
108
+ $this->assertEquals($response, $e->getResponse());
109
+
110
+ throw $e;
111
+ }
112
+ }
113
+
114
+ public function testCanBeSerializedAndUnserialized()
115
+ {
116
+ $this->mollieApiClient->setApiEndpoint("https://mymollieproxy.local");
117
+ $serialized = \serialize($this->mollieApiClient);
118
+
119
+ $this->assertNotContains('test_foobarfoobarfoobarfoobarfoobar', $serialized, "API key should not be in serialized data or it will end up in caches.");
120
+
121
+ /** @var MollieApiClient $client_copy */
122
+ $client_copy = Liberator::liberate(unserialize($serialized));
123
+
124
+ $this->assertEmpty($client_copy->apiKey, "API key should not have been remembered");
125
+ $this->assertInstanceOf(ClientInterface::class, $client_copy->httpClient, "A Guzzle client should have been set.");
126
+ $this->assertNull($client_copy->usesOAuth());
127
+ $this->assertEquals("https://mymollieproxy.local", $client_copy->getApiEndpoint(), "The API endpoint should be remembered");
128
+
129
+ $this->assertNotEmpty($client_copy->customerPayments);
130
+ $this->assertNotEmpty($client_copy->payments);
131
+ $this->assertNotEmpty($client_copy->methods);
132
+ // no need to assert them all.
133
+ }
134
+
135
+ public function testResponseBodyCanBeReadMultipleTimesIfMiddlewareReadsItFirst()
136
+ {
137
+ $response = new Response(200, [], '{"resource": "payment"}');
138
+
139
+ // Before the MollieApiClient gets the response, some middleware reads the body first.
140
+ $bodyAsReadFromMiddleware = (string) $response->getBody();
141
+
142
+ $this->guzzleClient
143
+ ->expects($this->once())
144
+ ->method('send')
145
+ ->willReturn($response);
146
+
147
+ $parsedResponse = $this->mollieApiClient->performHttpCall('GET', '');
148
+
149
+ $this->assertEquals(
150
+ '{"resource": "payment"}',
151
+ $bodyAsReadFromMiddleware
152
+ );
153
+
154
+ $this->assertEquals(
155
+ (object)['resource' => 'payment'],
156
+ $parsedResponse
157
+ );
158
+ }
159
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/InvoiceTest.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\Invoice;
7
+ use Mollie\Api\Types\InvoiceStatus;
8
+ use PHPUnit\Framework\TestCase;
9
+
10
+ class InvoiceTest extends TestCase
11
+ {
12
+ /**
13
+ * @param string $status
14
+ * @param string $function
15
+ * @param boolean $expected_boolean
16
+ *
17
+ * @dataProvider dpTestInvoiceStatuses
18
+ */
19
+ public function testInvoiceStatuses($status, $function, $expected_boolean)
20
+ {
21
+ $invoice = new Invoice($this->createMock(MollieApiClient::class));
22
+ $invoice->status = $status;
23
+
24
+ $this->assertEquals($expected_boolean, $invoice->{$function}());
25
+ }
26
+ public function dpTestInvoiceStatuses()
27
+ {
28
+ return [
29
+ [InvoiceStatus::STATUS_PAID, "isPaid", true],
30
+ [InvoiceStatus::STATUS_PAID, "isOpen", false],
31
+ [InvoiceStatus::STATUS_PAID, "isOverdue", false],
32
+
33
+ [InvoiceStatus::STATUS_OPEN, "isPaid", false],
34
+ [InvoiceStatus::STATUS_OPEN, "isOpen", true],
35
+ [InvoiceStatus::STATUS_OPEN, "isOverdue", false],
36
+
37
+ [InvoiceStatus::STATUS_OVERDUE, "isPaid", false],
38
+ [InvoiceStatus::STATUS_OVERDUE, "isOpen", false],
39
+ [InvoiceStatus::STATUS_OVERDUE, "isOverdue", true],
40
+ ];
41
+ }
42
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/OnboardingTest.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\API\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\Onboarding;
7
+ use Mollie\Api\Types\OnboardingStatus;
8
+
9
+ class OnboardingTest extends \PHPUnit\Framework\TestCase
10
+ {
11
+ /**
12
+ * @param string $status
13
+ * @param string $function
14
+ * @param boolean $expected_boolean
15
+ *
16
+ * @dataProvider dpTestOnboardingStatuses
17
+ */
18
+ public function testOnboardingStatuses($status, $function, $expected_boolean)
19
+ {
20
+ $orderLine = new Onboarding($this->createMock(MollieApiClient::class));
21
+ $orderLine->status = $status;
22
+
23
+ $this->assertEquals($expected_boolean, $orderLine->{$function}());
24
+ }
25
+
26
+ public function dpTestOnboardingStatuses()
27
+ {
28
+ return [
29
+ [OnboardingStatus::NEEDS_DATA, "needsData", true],
30
+ [OnboardingStatus::NEEDS_DATA, "isInReview", false],
31
+ [OnboardingStatus::NEEDS_DATA, "isCompleted", false],
32
+
33
+ [OnboardingStatus::IN_REVIEW, "needsData", false],
34
+ [OnboardingStatus::IN_REVIEW, "isInReview", true],
35
+ [OnboardingStatus::IN_REVIEW, "isCompleted", false],
36
+
37
+ [OnboardingStatus::COMPLETED, "needsData", false],
38
+ [OnboardingStatus::COMPLETED, "isInReview", false],
39
+ [OnboardingStatus::COMPLETED, "isCompleted", true],
40
+ ];
41
+ }
42
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/OrderLineCollectionTest.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\OrderLine;
7
+ use Mollie\Api\Resources\OrderLineCollection;
8
+
9
+ class OrderLineCollectionTest extends \PHPUnit\Framework\TestCase
10
+ {
11
+ public function testCanGetOrderLine()
12
+ {
13
+ $mockApi = $this->createMock(MollieApiClient::class);
14
+ $lines = new OrderLineCollection($mockApi, 3, []);
15
+
16
+ $line1 = new OrderLine($mockApi);
17
+ $line1->id = 'odl_aaaaaaaaaaa1';
18
+
19
+ $line2 = new OrderLine($mockApi);
20
+ $line2->id = 'odl_aaaaaaaaaaa2';
21
+
22
+ $line3 = new OrderLine($mockApi);
23
+ $line3->id = 'odl_aaaaaaaaaaa3';
24
+
25
+ $lines[] = $line1;
26
+ $lines[] = $line2;
27
+ $lines[] = $line3;
28
+
29
+ $this->assertNull($lines->get('odl_not_existent'));
30
+
31
+ $line = $lines->get('odl_aaaaaaaaaaa2');
32
+
33
+ $this->assertInstanceOf(OrderLine::class, $line);
34
+ $this->assertEquals($line2, $line);
35
+ }
36
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/OrderLineTest.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\OrderLine;
7
+ use Mollie\Api\Types\OrderLineStatus;
8
+ use Mollie\Api\Types\OrderLineType;
9
+
10
+ class OrderLineTest extends \PHPUnit\Framework\TestCase
11
+ {
12
+ /**
13
+ * @param string $status
14
+ * @param string $function
15
+ * @param boolean $expected_boolean
16
+ *
17
+ * @dataProvider dpTestOrderLineStatuses
18
+ */
19
+ public function testOrderLineStatuses($status, $function, $expected_boolean)
20
+ {
21
+ $orderLine = new OrderLine($this->createMock(MollieApiClient::class));
22
+ $orderLine->status = $status;
23
+
24
+ $this->assertEquals($expected_boolean, $orderLine->{$function}());
25
+ }
26
+
27
+ /**
28
+ * @param string $type
29
+ * @param string $function
30
+ * @param boolean $expected_boolean
31
+ *
32
+ * @dataProvider dpTestOrderLineTypes
33
+ */
34
+ public function testOrderLineTypes($type, $function, $expected_boolean)
35
+ {
36
+ $orderLine = new OrderLine($this->createMock(MollieApiClient::class));
37
+ $orderLine->type = $type;
38
+
39
+ $this->assertEquals($expected_boolean, $orderLine->{$function}());
40
+ }
41
+
42
+ public function dpTestOrderLineTypes()
43
+ {
44
+ return [
45
+ [OrderLineType::TYPE_PHYSICAL, "isPhysical", true],
46
+ [OrderLineType::TYPE_PHYSICAL, "isDiscount", false],
47
+ [OrderLineType::TYPE_PHYSICAL, "isDigital", false],
48
+ [OrderLineType::TYPE_PHYSICAL, "isShippingFee", false],
49
+ [OrderLineType::TYPE_PHYSICAL, "isStoreCredit", false],
50
+ [OrderLineType::TYPE_PHYSICAL, "isGiftCard", false],
51
+ [OrderLineType::TYPE_PHYSICAL, "isSurcharge", false],
52
+
53
+ [OrderLineType::TYPE_DISCOUNT, "isPhysical", false],
54
+ [OrderLineType::TYPE_DISCOUNT, "isDiscount", true],
55
+ [OrderLineType::TYPE_DISCOUNT, "isDigital", false],
56
+ [OrderLineType::TYPE_DISCOUNT, "isShippingFee", false],
57
+ [OrderLineType::TYPE_DISCOUNT, "isStoreCredit", false],
58
+ [OrderLineType::TYPE_DISCOUNT, "isGiftCard", false],
59
+ [OrderLineType::TYPE_DISCOUNT, "isSurcharge", false],
60
+
61
+ [OrderLineType::TYPE_DIGITAL, "isPhysical", false],
62
+ [OrderLineType::TYPE_DIGITAL, "isDiscount", false],
63
+ [OrderLineType::TYPE_DIGITAL, "isDigital", true],
64
+ [OrderLineType::TYPE_DIGITAL, "isShippingFee", false],
65
+ [OrderLineType::TYPE_DIGITAL, "isStoreCredit", false],
66
+ [OrderLineType::TYPE_DIGITAL, "isGiftCard", false],
67
+ [OrderLineType::TYPE_DIGITAL, "isSurcharge", false],
68
+
69
+ [OrderLineType::TYPE_SHIPPING_FEE, "isPhysical", false],
70
+ [OrderLineType::TYPE_SHIPPING_FEE, "isDiscount", false],
71
+ [OrderLineType::TYPE_SHIPPING_FEE, "isDigital", false],
72
+ [OrderLineType::TYPE_SHIPPING_FEE, "isShippingFee", true],
73
+ [OrderLineType::TYPE_SHIPPING_FEE, "isStoreCredit", false],
74
+ [OrderLineType::TYPE_SHIPPING_FEE, "isGiftCard", false],
75
+ [OrderLineType::TYPE_SHIPPING_FEE, "isSurcharge", false],
76
+
77
+ [OrderLineType::TYPE_STORE_CREDIT, "isPhysical", false],
78
+ [OrderLineType::TYPE_STORE_CREDIT, "isDiscount", false],
79
+ [OrderLineType::TYPE_STORE_CREDIT, "isDigital", false],
80
+ [OrderLineType::TYPE_STORE_CREDIT, "isShippingFee", false],
81
+ [OrderLineType::TYPE_STORE_CREDIT, "isStoreCredit", true],
82
+ [OrderLineType::TYPE_STORE_CREDIT, "isGiftCard", false],
83
+ [OrderLineType::TYPE_STORE_CREDIT, "isSurcharge", false],
84
+
85
+ [OrderLineType::TYPE_GIFT_CARD, "isPhysical", false],
86
+ [OrderLineType::TYPE_GIFT_CARD, "isDiscount", false],
87
+ [OrderLineType::TYPE_GIFT_CARD, "isDigital", false],
88
+ [OrderLineType::TYPE_GIFT_CARD, "isShippingFee", false],
89
+ [OrderLineType::TYPE_GIFT_CARD, "isStoreCredit", false],
90
+ [OrderLineType::TYPE_GIFT_CARD, "isGiftCard", true],
91
+ [OrderLineType::TYPE_GIFT_CARD, "isSurcharge", false],
92
+
93
+ [OrderLineType::TYPE_SURCHARGE, "isPhysical", false],
94
+ [OrderLineType::TYPE_SURCHARGE, "isDiscount", false],
95
+ [OrderLineType::TYPE_SURCHARGE, "isDigital", false],
96
+ [OrderLineType::TYPE_SURCHARGE, "isShippingFee", false],
97
+ [OrderLineType::TYPE_SURCHARGE, "isStoreCredit", false],
98
+ [OrderLineType::TYPE_SURCHARGE, "isGiftCard", false],
99
+ [OrderLineType::TYPE_SURCHARGE, "isSurcharge", true],
100
+ ];
101
+ }
102
+
103
+ public function dpTestOrderLineStatuses()
104
+ {
105
+ return [
106
+ [OrderLineStatus::STATUS_CREATED, "isCreated", true],
107
+ [OrderLineStatus::STATUS_CREATED, "isPaid", false],
108
+ [OrderLineStatus::STATUS_CREATED, "isAuthorized", false],
109
+ [OrderLineStatus::STATUS_CREATED, "isCanceled", false],
110
+ [OrderLineStatus::STATUS_CREATED, "isShipping", false],
111
+ [OrderLineStatus::STATUS_CREATED, "isCompleted", false],
112
+
113
+ [OrderLineStatus::STATUS_PAID, "isCreated", false],
114
+ [OrderLineStatus::STATUS_PAID, "isPaid", true],
115
+ [OrderLineStatus::STATUS_PAID, "isAuthorized", false],
116
+ [OrderLineStatus::STATUS_PAID, "isCanceled", false],
117
+ [OrderLineStatus::STATUS_PAID, "isShipping", false],
118
+ [OrderLineStatus::STATUS_PAID, "isCompleted", false],
119
+
120
+ [OrderLineStatus::STATUS_AUTHORIZED, "isCreated", false],
121
+ [OrderLineStatus::STATUS_AUTHORIZED, "isPaid", false],
122
+ [OrderLineStatus::STATUS_AUTHORIZED, "isAuthorized", true],
123
+ [OrderLineStatus::STATUS_AUTHORIZED, "isCanceled", false],
124
+ [OrderLineStatus::STATUS_AUTHORIZED, "isShipping", false],
125
+ [OrderLineStatus::STATUS_AUTHORIZED, "isCompleted", false],
126
+
127
+ [OrderLineStatus::STATUS_CANCELED, "isCreated", false],
128
+ [OrderLineStatus::STATUS_CANCELED, "isPaid", false],
129
+ [OrderLineStatus::STATUS_CANCELED, "isAuthorized", false],
130
+ [OrderLineStatus::STATUS_CANCELED, "isCanceled", true],
131
+ [OrderLineStatus::STATUS_CANCELED, "isShipping", false],
132
+ [OrderLineStatus::STATUS_CANCELED, "isCompleted", false],
133
+
134
+ [OrderLineStatus::STATUS_SHIPPING, "isCreated", false],
135
+ [OrderLineStatus::STATUS_SHIPPING, "isPaid", false],
136
+ [OrderLineStatus::STATUS_SHIPPING, "isAuthorized", false],
137
+ [OrderLineStatus::STATUS_SHIPPING, "isCanceled", false],
138
+ [OrderLineStatus::STATUS_SHIPPING, "isShipping", true],
139
+ [OrderLineStatus::STATUS_SHIPPING, "isCompleted", false],
140
+
141
+ [OrderLineStatus::STATUS_COMPLETED, "isCreated", false],
142
+ [OrderLineStatus::STATUS_COMPLETED, "isPaid", false],
143
+ [OrderLineStatus::STATUS_COMPLETED, "isAuthorized", false],
144
+ [OrderLineStatus::STATUS_COMPLETED, "isCanceled", false],
145
+ [OrderLineStatus::STATUS_COMPLETED, "isShipping", false],
146
+ [OrderLineStatus::STATUS_COMPLETED, "isCompleted", true],
147
+ ];
148
+ }
149
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/OrderTest.php ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\Order;
7
+ use Mollie\Api\Resources\OrderLine;
8
+ use Mollie\Api\Resources\OrderLineCollection;
9
+ use Mollie\Api\Types\OrderLineStatus;
10
+ use Mollie\Api\Types\OrderLineType;
11
+ use Mollie\Api\Types\OrderStatus;
12
+ use Tests\Mollie\TestHelpers\AmountObjectTestHelpers;
13
+ use Tests\Mollie\TestHelpers\LinkObjectTestHelpers;
14
+ use stdClass;
15
+
16
+ class OrderTest extends \PHPUnit\Framework\TestCase
17
+ {
18
+ use AmountObjectTestHelpers;
19
+ use LinkObjectTestHelpers;
20
+
21
+ /**
22
+ * @param string $status
23
+ * @param string $function
24
+ * @param boolean $expected_boolean
25
+ *
26
+ * @dataProvider dpTestOrderStatuses
27
+ */
28
+ public function testOrderStatuses($status, $function, $expected_boolean)
29
+ {
30
+ $order = new Order($this->createMock(MollieApiClient::class));
31
+ $order->status = $status;
32
+
33
+ $this->assertEquals($expected_boolean, $order->{$function}());
34
+ }
35
+
36
+ public function dpTestOrderStatuses()
37
+ {
38
+ return [
39
+ [OrderStatus::STATUS_CREATED, "isCreated", true],
40
+ [OrderStatus::STATUS_CREATED, "isPaid", false],
41
+ [OrderStatus::STATUS_CREATED, "isAuthorized", false],
42
+ [OrderStatus::STATUS_CREATED, "isCanceled", false],
43
+ [OrderStatus::STATUS_CREATED, "isShipping", false],
44
+ [OrderStatus::STATUS_CREATED, "isCompleted", false],
45
+ [OrderStatus::STATUS_CREATED, "isExpired", false],
46
+ [OrderStatus::STATUS_CREATED, "isPending", false],
47
+
48
+ [OrderStatus::STATUS_PAID, "isCreated", false],
49
+ [OrderStatus::STATUS_PAID, "isPaid", true],
50
+ [OrderStatus::STATUS_PAID, "isAuthorized", false],
51
+ [OrderStatus::STATUS_PAID, "isCanceled", false],
52
+ [OrderStatus::STATUS_PAID, "isShipping", false],
53
+ [OrderStatus::STATUS_PAID, "isCompleted", false],
54
+ [OrderStatus::STATUS_PAID, "isExpired", false],
55
+ [OrderStatus::STATUS_PAID, "isPending", false],
56
+
57
+ [OrderStatus::STATUS_AUTHORIZED, "isCreated", false],
58
+ [OrderStatus::STATUS_AUTHORIZED, "isPaid", false],
59
+ [OrderStatus::STATUS_AUTHORIZED, "isAuthorized", true],
60
+ [OrderStatus::STATUS_AUTHORIZED, "isCanceled", false],
61
+ [OrderStatus::STATUS_AUTHORIZED, "isShipping", false],
62
+ [OrderStatus::STATUS_AUTHORIZED, "isCompleted", false],
63
+ [OrderStatus::STATUS_AUTHORIZED, "isExpired", false],
64
+ [OrderStatus::STATUS_AUTHORIZED, "isPending", false],
65
+
66
+ [OrderStatus::STATUS_CANCELED, "isCreated", false],
67
+ [OrderStatus::STATUS_CANCELED, "isPaid", false],
68
+ [OrderStatus::STATUS_CANCELED, "isAuthorized", false],
69
+ [OrderStatus::STATUS_CANCELED, "isCanceled", true],
70
+ [OrderStatus::STATUS_CANCELED, "isShipping", false],
71
+ [OrderStatus::STATUS_CANCELED, "isCompleted", false],
72
+ [OrderStatus::STATUS_CANCELED, "isExpired", false],
73
+ [OrderStatus::STATUS_CANCELED, "isPending", false],
74
+
75
+ [OrderStatus::STATUS_SHIPPING, "isCreated", false],
76
+ [OrderStatus::STATUS_SHIPPING, "isPaid", false],
77
+ [OrderStatus::STATUS_SHIPPING, "isAuthorized", false],
78
+ [OrderStatus::STATUS_SHIPPING, "isCanceled", false],
79
+ [OrderStatus::STATUS_SHIPPING, "isShipping", true],
80
+ [OrderStatus::STATUS_SHIPPING, "isCompleted", false],
81
+ [OrderStatus::STATUS_SHIPPING, "isExpired", false],
82
+ [OrderStatus::STATUS_SHIPPING, "isPending", false],
83
+
84
+ [OrderStatus::STATUS_COMPLETED, "isCreated", false],
85
+ [OrderStatus::STATUS_COMPLETED, "isPaid", false],
86
+ [OrderStatus::STATUS_COMPLETED, "isAuthorized", false],
87
+ [OrderStatus::STATUS_COMPLETED, "isCanceled", false],
88
+ [OrderStatus::STATUS_COMPLETED, "isShipping", false],
89
+ [OrderStatus::STATUS_COMPLETED, "isCompleted", true],
90
+ [OrderStatus::STATUS_COMPLETED, "isExpired", false],
91
+ [OrderStatus::STATUS_COMPLETED, "isPending", false],
92
+
93
+ [OrderStatus::STATUS_EXPIRED, "isCreated", false],
94
+ [OrderStatus::STATUS_EXPIRED, "isPaid", false],
95
+ [OrderStatus::STATUS_EXPIRED, "isAuthorized", false],
96
+ [OrderStatus::STATUS_EXPIRED, "isCanceled", false],
97
+ [OrderStatus::STATUS_EXPIRED, "isShipping", false],
98
+ [OrderStatus::STATUS_EXPIRED, "isCompleted", false],
99
+ [OrderStatus::STATUS_EXPIRED, "isExpired", true],
100
+ [OrderStatus::STATUS_EXPIRED, "isPending", false],
101
+
102
+ [OrderStatus::STATUS_PENDING, "isCreated", false],
103
+ [OrderStatus::STATUS_PENDING, "isPaid", false],
104
+ [OrderStatus::STATUS_PENDING, "isAuthorized", false],
105
+ [OrderStatus::STATUS_PENDING, "isCanceled", false],
106
+ [OrderStatus::STATUS_PENDING, "isShipping", false],
107
+ [OrderStatus::STATUS_PENDING, "isCompleted", false],
108
+ [OrderStatus::STATUS_PENDING, "isExpired", false],
109
+ [OrderStatus::STATUS_PENDING, "isPending", true],
110
+ ];
111
+ }
112
+
113
+ public function testCanGetLinesAsResourcesOnOrderResource()
114
+ {
115
+ $order = new Order($this->createMock(MollieApiClient::class));
116
+ $orderLine = new stdClass;
117
+ $lineArray = [
118
+ 'resource' => 'orderline',
119
+ 'id' => 'odl_dgtxyl',
120
+ 'orderId' => 'ord_pbjz8x',
121
+ 'type' => 'physical',
122
+ 'name' => 'LEGO 42083 Bugatti Chiron',
123
+ 'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083',
124
+ 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$',
125
+ 'sku' => '5702016116977',
126
+ 'type' => 'physical',
127
+ 'status' => 'created',
128
+ 'quantity' => 2,
129
+ 'unitPrice' => (object) [
130
+ 'value' => '399.00',
131
+ 'currency' => 'EUR',
132
+ ],
133
+ 'vatRate' => '21.00',
134
+ 'vatAmount' => (object) [
135
+ 'value' => '121.14',
136
+ 'currency' => 'EUR',
137
+ ],
138
+ 'discountAmount' => (object) [
139
+ 'value' => '100.00',
140
+ 'currency' => 'EUR',
141
+ ],
142
+ 'totalAmount' => (object) [
143
+ 'value' => '698.00',
144
+ 'currency' => 'EUR',
145
+ ],
146
+ 'createdAt' => '2018-08-02T09:29:56+00:00',
147
+ ];
148
+
149
+ foreach ($lineArray as $key => $value) {
150
+ $orderLine->{$key} = $value;
151
+ }
152
+
153
+ $order->lines = [$orderLine];
154
+
155
+ $lines = $order->lines();
156
+
157
+ $this->assertInstanceOf(OrderLineCollection::class, $lines);
158
+ $this->assertCount(1, $lines);
159
+
160
+ $line = $lines[0];
161
+
162
+ $this->assertInstanceOf(OrderLine::class, $line);
163
+
164
+ $this->assertEquals("orderline", $line->resource);
165
+ $this->assertEquals("odl_dgtxyl", $line->id);
166
+ $this->assertEquals('ord_pbjz8x', $line->orderId);
167
+ $this->assertEquals("LEGO 42083 Bugatti Chiron", $line->name);
168
+ $this->assertEquals("https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", $line->productUrl);
169
+ $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line->imageUrl);
170
+ $this->assertEquals("5702016116977", $line->sku);
171
+ $this->assertEquals(OrderLineType::TYPE_PHYSICAL, $line->type);
172
+ $this->assertEquals(OrderLineStatus::STATUS_CREATED, $line->status);
173
+ $this->assertEquals(2, $line->quantity);
174
+ $this->assertAmountObject("399.00", "EUR", $line->unitPrice);
175
+ $this->assertEquals("21.00", $line->vatRate);
176
+ $this->assertAmountObject("121.14", "EUR", $line->vatAmount);
177
+ $this->assertAmountObject("100.00", "EUR", $line->discountAmount);
178
+ $this->assertAmountObject("698.00", "EUR", $line->totalAmount);
179
+ $this->assertEquals("2018-08-02T09:29:56+00:00", $line->createdAt);
180
+ }
181
+
182
+ public function testCanGetPaymentsAsResourcesOnOrderResource()
183
+ {
184
+ $order = new Order($this->createMock(MollieApiClient::class));
185
+ $orderLine = new stdClass;
186
+ $lineArray = [
187
+ 'resource' => 'orderline',
188
+ 'id' => 'odl_dgtxyl',
189
+ 'orderId' => 'ord_pbjz8x',
190
+ 'type' => 'physical',
191
+ 'name' => 'LEGO 42083 Bugatti Chiron',
192
+ 'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083',
193
+ 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$',
194
+ 'sku' => '5702016116977',
195
+ 'type' => 'physical',
196
+ 'status' => 'created',
197
+ 'quantity' => 2,
198
+ 'unitPrice' => (object) [
199
+ 'value' => '399.00',
200
+ 'currency' => 'EUR',
201
+ ],
202
+ 'vatRate' => '21.00',
203
+ 'vatAmount' => (object) [
204
+ 'value' => '121.14',
205
+ 'currency' => 'EUR',
206
+ ],
207
+ 'discountAmount' => (object) [
208
+ 'value' => '100.00',
209
+ 'currency' => 'EUR',
210
+ ],
211
+ 'totalAmount' => (object) [
212
+ 'value' => '698.00',
213
+ 'currency' => 'EUR',
214
+ ],
215
+ 'createdAt' => '2018-08-02T09:29:56+00:00',
216
+ ];
217
+
218
+ foreach ($lineArray as $key => $value) {
219
+ $orderLine->{$key} = $value;
220
+ }
221
+
222
+ $order->lines = [$orderLine];
223
+
224
+ $lines = $order->lines();
225
+
226
+ $this->assertInstanceOf(OrderLineCollection::class, $lines);
227
+ $this->assertCount(1, $lines);
228
+
229
+ $line = $lines[0];
230
+
231
+ $this->assertInstanceOf(OrderLine::class, $line);
232
+
233
+ $this->assertEquals("orderline", $line->resource);
234
+ $this->assertEquals("odl_dgtxyl", $line->id);
235
+ $this->assertEquals('ord_pbjz8x', $line->orderId);
236
+ $this->assertEquals("LEGO 42083 Bugatti Chiron", $line->name);
237
+ $this->assertEquals("https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", $line->productUrl);
238
+ $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line->imageUrl);
239
+ $this->assertEquals("5702016116977", $line->sku);
240
+ $this->assertEquals(OrderLineType::TYPE_PHYSICAL, $line->type);
241
+ $this->assertEquals(OrderLineStatus::STATUS_CREATED, $line->status);
242
+ $this->assertEquals(2, $line->quantity);
243
+ $this->assertAmountObject("399.00", "EUR", $line->unitPrice);
244
+ $this->assertEquals("21.00", $line->vatRate);
245
+ $this->assertAmountObject("121.14", "EUR", $line->vatAmount);
246
+ $this->assertAmountObject("100.00", "EUR", $line->discountAmount);
247
+ $this->assertAmountObject("698.00", "EUR", $line->totalAmount);
248
+ $this->assertEquals("2018-08-02T09:29:56+00:00", $line->createdAt);
249
+ }
250
+
251
+ public function testGetCheckoutUrlWorks()
252
+ {
253
+ $order = new Order($this->createMock(MollieApiClient::class));
254
+ $order->_links = $this->getOrderLinksDummy([
255
+ 'checkout' => (object) [
256
+ 'href' => 'https://www.some-mollie-checkout-url.com/123',
257
+ 'type' => 'text/html',
258
+ ]
259
+ ]);
260
+
261
+ $this->assertEquals(
262
+ 'https://www.some-mollie-checkout-url.com/123',
263
+ $order->getCheckoutUrl()
264
+ );
265
+ }
266
+
267
+ public function testGetCheckoutUrlReturnsNullIfNoCheckoutUrlAvailable()
268
+ {
269
+ $order = new Order($this->createMock(MollieApiClient::class));
270
+ $order->_links = $this->getOrderLinksDummy(['checkout' => null]);
271
+
272
+ $this->assertNull($order->getCheckoutUrl());
273
+ }
274
+
275
+ public function testPaymentsHelperReturnsIfNoEmbedAvailable()
276
+ {
277
+ $order = new Order($this->createMock(MollieApiClient::class));
278
+ $this->assertNull($order->payments());
279
+ }
280
+
281
+ public function testPaymentsHelperReturnsIfNoPaymentsEmbedded()
282
+ {
283
+ $order = new Order($this->createMock(MollieApiClient::class));
284
+ $order->_embedded = [];
285
+ $this->assertNull($order->payments());
286
+ }
287
+
288
+ protected function getOrderLinksDummy($overrides = [])
289
+ {
290
+ return (object) array_merge(
291
+ [],
292
+ $overrides
293
+ );
294
+ }
295
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/PaymentTest.php ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\Payment;
7
+ use Mollie\Api\Types\PaymentStatus;
8
+ use Mollie\Api\Types\SequenceType;
9
+ use stdClass;
10
+
11
+ class PaymentTest extends \PHPUnit\Framework\TestCase
12
+ {
13
+ /**
14
+ * @param string $status
15
+ * @param string $function
16
+ * @param boolean $expected_boolean
17
+ *
18
+ * @dataProvider dpTestPaymentStatuses
19
+ */
20
+ public function testPaymentStatuses($status, $function, $expected_boolean)
21
+ {
22
+ $payment = new Payment($this->createMock(MollieApiClient::class));
23
+ $payment->status = $status;
24
+
25
+ $this->assertEquals($expected_boolean, $payment->{$function}());
26
+ }
27
+
28
+ public function dpTestPaymentStatuses()
29
+ {
30
+ return [
31
+ [PaymentStatus::STATUS_PENDING, "isPending", true],
32
+ [PaymentStatus::STATUS_PENDING, "isAuthorized", false],
33
+ [PaymentStatus::STATUS_PENDING, "isFailed", false],
34
+ [PaymentStatus::STATUS_PENDING, "isOpen", false],
35
+ [PaymentStatus::STATUS_PENDING, "isCanceled", false],
36
+ [PaymentStatus::STATUS_PENDING, "isPaid", false],
37
+ [PaymentStatus::STATUS_PENDING, "isExpired", false],
38
+
39
+ [PaymentStatus::STATUS_AUTHORIZED, "isPending", false],
40
+ [PaymentStatus::STATUS_AUTHORIZED, "isAuthorized", true],
41
+ [PaymentStatus::STATUS_AUTHORIZED, "isFailed", false],
42
+ [PaymentStatus::STATUS_AUTHORIZED, "isOpen", false],
43
+ [PaymentStatus::STATUS_AUTHORIZED, "isCanceled", false],
44
+ [PaymentStatus::STATUS_AUTHORIZED, "isPaid", false],
45
+ [PaymentStatus::STATUS_AUTHORIZED, "isExpired", false],
46
+
47
+ [PaymentStatus::STATUS_FAILED, "isPending", false],
48
+ [PaymentStatus::STATUS_FAILED, "isAuthorized", false],
49
+ [PaymentStatus::STATUS_FAILED, "isFailed", true],
50
+ [PaymentStatus::STATUS_FAILED, "isOpen", false],
51
+ [PaymentStatus::STATUS_FAILED, "isCanceled", false],
52
+ [PaymentStatus::STATUS_FAILED, "isPaid", false],
53
+ [PaymentStatus::STATUS_FAILED, "isExpired", false],
54
+
55
+ [PaymentStatus::STATUS_OPEN, "isPending", false],
56
+ [PaymentStatus::STATUS_OPEN, "isAuthorized", false],
57
+ [PaymentStatus::STATUS_OPEN, "isFailed", false],
58
+ [PaymentStatus::STATUS_OPEN, "isOpen", true],
59
+ [PaymentStatus::STATUS_OPEN, "isCanceled", false],
60
+ [PaymentStatus::STATUS_OPEN, "isPaid", false],
61
+ [PaymentStatus::STATUS_OPEN, "isExpired", false],
62
+
63
+ [PaymentStatus::STATUS_CANCELED, "isPending", false],
64
+ [PaymentStatus::STATUS_CANCELED, "isAuthorized", false],
65
+ [PaymentStatus::STATUS_CANCELED, "isFailed", false],
66
+ [PaymentStatus::STATUS_CANCELED, "isOpen", false],
67
+ [PaymentStatus::STATUS_CANCELED, "isCanceled", true],
68
+ [PaymentStatus::STATUS_CANCELED, "isPaid", false],
69
+ [PaymentStatus::STATUS_CANCELED, "isExpired", false],
70
+
71
+ [PaymentStatus::STATUS_EXPIRED, "isPending", false],
72
+ [PaymentStatus::STATUS_EXPIRED, "isAuthorized", false],
73
+ [PaymentStatus::STATUS_EXPIRED, "isFailed", false],
74
+ [PaymentStatus::STATUS_EXPIRED, "isOpen", false],
75
+ [PaymentStatus::STATUS_EXPIRED, "isCanceled", false],
76
+ [PaymentStatus::STATUS_EXPIRED, "isPaid", false],
77
+ [PaymentStatus::STATUS_EXPIRED, "isExpired", true],
78
+ ];
79
+ }
80
+
81
+ public function testIsPaidReturnsTrueWhenPaidDatetimeIsSet()
82
+ {
83
+ $payment = new Payment($this->createMock(MollieApiClient::class));
84
+
85
+ $payment->paidAt = "2016-10-24";
86
+ $this->assertTrue($payment->isPaid());
87
+ }
88
+
89
+ public function testHasRefundsReturnsTrueWhenPaymentHasRefunds()
90
+ {
91
+ $payment = new Payment($this->createMock(MollieApiClient::class));
92
+
93
+ $payment->_links = new stdClass();
94
+ $payment->_links->refunds = (object) ["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds", "type" => "application/hal+json"];
95
+
96
+ $this->assertTrue($payment->hasRefunds());
97
+ }
98
+
99
+ public function testHasRefundsReturnsFalseWhenPaymentHasNoRefunds()
100
+ {
101
+ $payment = new Payment($this->createMock(MollieApiClient::class));
102
+
103
+ $payment->_links = new stdClass();
104
+ $this->assertFalse($payment->hasRefunds());
105
+ }
106
+
107
+ public function testHasChargedbacksReturnsTrueWhenPaymentHasChargebacks()
108
+ {
109
+ $payment = new Payment($this->createMock(MollieApiClient::class));
110
+
111
+ $payment->_links = new stdClass();
112
+ $payment->_links->chargebacks = (object) ["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks", "type" => "application/hal+json"];
113
+
114
+ $this->assertTrue($payment->hasChargebacks());
115
+ }
116
+
117
+ public function testHasChargedbacksReturnsFalseWhenPaymentHasNoChargebacks()
118
+ {
119
+ $payment = new Payment($this->createMock(MollieApiClient::class));
120
+
121
+ $payment->_links = new stdClass();
122
+ $this->assertFalse($payment->hasChargebacks());
123
+ }
124
+
125
+ public function testHasRecurringTypeReturnsTrueWhenRecurringTypeIsFirst()
126
+ {
127
+ $payment = new Payment($this->createMock(MollieApiClient::class));
128
+
129
+ $payment->sequenceType = SequenceType::SEQUENCETYPE_FIRST;
130
+ $this->assertFalse($payment->hasSequenceTypeRecurring());
131
+ $this->assertTrue($payment->hasSequenceTypeFirst());
132
+ }
133
+
134
+ public function testHasRecurringTypeReturnsTrueWhenRecurringTypeIsRecurring()
135
+ {
136
+ $payment = new Payment($this->createMock(MollieApiClient::class));
137
+
138
+ $payment->sequenceType = SequenceType::SEQUENCETYPE_RECURRING;
139
+ $this->assertTrue($payment->hasSequenceTypeRecurring());
140
+ $this->assertFalse($payment->hasSequenceTypeFirst());
141
+ }
142
+
143
+ public function testHasRecurringTypeReturnsFalseWhenRecurringTypeIsNone()
144
+ {
145
+ $payment = new Payment($this->createMock(MollieApiClient::class));
146
+
147
+ $payment->sequenceType = SequenceType::SEQUENCETYPE_ONEOFF;
148
+ $this->assertFalse($payment->hasSequenceTypeFirst());
149
+ $this->assertFalse($payment->hasSequenceTypeRecurring());
150
+ }
151
+
152
+ public function testGetCheckoutUrlReturnsPaymentUrlFromLinksObject()
153
+ {
154
+ $payment = new Payment($this->createMock(MollieApiClient::class));
155
+
156
+ $payment->_links = new stdClass();
157
+ $payment->_links->checkout = new stdClass();
158
+ $payment->_links->checkout->href = "https://example.com";
159
+
160
+ $this->assertSame($payment->getCheckoutUrl(), "https://example.com");
161
+ }
162
+
163
+ public function testCanBeRefundedReturnsTrueWhenAmountRemainingIsSet()
164
+ {
165
+ $payment = new Payment($this->createMock(MollieApiClient::class));
166
+
167
+ $payment->amountRemaining = 15;
168
+ $this->assertTrue($payment->canBeRefunded());
169
+ $this->assertTrue($payment->canBePartiallyRefunded());
170
+ }
171
+
172
+ public function testCanBeRefundedReturnsFalseWhenAmountRemainingIsNull()
173
+ {
174
+ $payment = new Payment($this->createMock(MollieApiClient::class));
175
+
176
+ $payment->amountRemaining = null;
177
+ $this->assertFalse($payment->canBeRefunded());
178
+ $this->assertFalse($payment->canBePartiallyRefunded());
179
+ }
180
+
181
+ public function testGetAmountRefundedReturnsAmountRefundedAsFloat()
182
+ {
183
+ $payment = new Payment($this->createMock(MollieApiClient::class));
184
+
185
+ $payment->amountRefunded = (object)["value" => 22.0, "currency" => "EUR"];
186
+ self::assertSame(22.0, $payment->getAmountRefunded());
187
+ }
188
+
189
+ public function testGetAmountRefundedReturns0WhenAmountRefundedIsSetToNull()
190
+ {
191
+ $payment = new Payment($this->createMock(MollieApiClient::class));
192
+
193
+ $payment->amountRefunded = null;
194
+ self::assertSame(0.0, $payment->getAmountRefunded());
195
+ }
196
+
197
+ public function testGetAmountRemainingReturnsAmountRemainingAsFloat()
198
+ {
199
+ $payment = new Payment($this->createMock(MollieApiClient::class));
200
+
201
+ $payment->amountRemaining = (object)["value" => 22.0, "currency" => "EUR"];
202
+ self::assertSame(22.0, $payment->getAmountRemaining());
203
+ }
204
+
205
+ public function testGetAmountRemainingReturns0WhenAmountRemainingIsSetToNull()
206
+ {
207
+ $payment = new Payment($this->createMock(MollieApiClient::class));
208
+
209
+ $payment->amountRefunded = null;
210
+ self::assertSame(0.0, $payment->getAmountRemaining());
211
+ }
212
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/ProfileTest.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\Profile;
7
+ use Mollie\Api\Types\ProfileStatus;
8
+
9
+ class ProfileTest extends \PHPUnit\Framework\TestCase
10
+ {
11
+ /**
12
+ * @param string $status
13
+ * @param string $function
14
+ * @param boolean $expected_boolean
15
+ *
16
+ * @dataProvider dpTestProfileStatusses
17
+ */
18
+ public function testProfileStatusses($status, $function, $expected_boolean)
19
+ {
20
+ $profile = new Profile($this->createMock(MollieApiClient::class));
21
+ $profile->status = $status;
22
+
23
+ $this->assertEquals($expected_boolean, $profile->{$function}());
24
+ }
25
+
26
+ public function dpTestProfileStatusses()
27
+ {
28
+ return [
29
+ [ProfileStatus::STATUS_BLOCKED, "isBlocked", true],
30
+ [ProfileStatus::STATUS_BLOCKED, "isVerified", false],
31
+ [ProfileStatus::STATUS_BLOCKED, "isUnverified", false],
32
+
33
+ [ProfileStatus::STATUS_VERIFIED, "isBlocked", false],
34
+ [ProfileStatus::STATUS_VERIFIED, "isVerified", true],
35
+ [ProfileStatus::STATUS_VERIFIED, "isUnverified", false],
36
+
37
+ [ProfileStatus::STATUS_UNVERIFIED, "isBlocked", false],
38
+ [ProfileStatus::STATUS_UNVERIFIED, "isVerified", false],
39
+ [ProfileStatus::STATUS_UNVERIFIED, "isUnverified", true],
40
+ ];
41
+ }
42
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/RefundTest.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\Refund;
7
+ use Mollie\Api\Types\RefundStatus;
8
+
9
+ class RefundTest extends \PHPUnit\Framework\TestCase
10
+ {
11
+ /**
12
+ * @param string $status
13
+ * @param string $function
14
+ * @param boolean $expected_boolean
15
+ *
16
+ * @dataProvider dpTestRefundStatuses
17
+ */
18
+ public function testRefundStatuses($status, $function, $expected_boolean)
19
+ {
20
+ $refund = new Refund($this->createMock(MollieApiClient::class));
21
+ $refund->status = $status;
22
+
23
+ $this->assertEquals($expected_boolean, $refund->{$function}());
24
+ }
25
+
26
+ public function dpTestRefundStatuses()
27
+ {
28
+ return [
29
+ [RefundStatus::STATUS_PENDING, "isPending", true],
30
+ [RefundStatus::STATUS_PENDING, "isProcessing", false],
31
+ [RefundStatus::STATUS_PENDING, "isQueued", false],
32
+ [RefundStatus::STATUS_PENDING, "isTransferred", false],
33
+
34
+ [RefundStatus::STATUS_PROCESSING, "isPending", false],
35
+ [RefundStatus::STATUS_PROCESSING, "isProcessing", true],
36
+ [RefundStatus::STATUS_PROCESSING, "isQueued", false],
37
+ [RefundStatus::STATUS_PROCESSING, "isTransferred", false],
38
+
39
+ [RefundStatus::STATUS_QUEUED, "isPending", false],
40
+ [RefundStatus::STATUS_QUEUED, "isProcessing", false],
41
+ [RefundStatus::STATUS_QUEUED, "isQueued", true],
42
+ [RefundStatus::STATUS_QUEUED, "isTransferred", false],
43
+
44
+ [RefundStatus::STATUS_REFUNDED, "isPending", false],
45
+ [RefundStatus::STATUS_REFUNDED, "isProcessing", false],
46
+ [RefundStatus::STATUS_REFUNDED, "isQueued", false],
47
+ [RefundStatus::STATUS_REFUNDED, "isTransferred", true],
48
+ ];
49
+ }
50
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/ResourceFactoryTest.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+
6
+ use Mollie\Api\MollieApiClient;
7
+ use Mollie\Api\Resources\Payment;
8
+ use Mollie\Api\Resources\ResourceFactory;
9
+
10
+ class ResourceFactoryTest extends \PHPUnit\Framework\TestCase
11
+ {
12
+ public function testCreateFromApiResponseWorks()
13
+ {
14
+ $apiResult = json_decode('{
15
+ "resource":"payment",
16
+ "id":"tr_44aKxzEbr8",
17
+ "mode":"test",
18
+ "createdAt":"2018-03-13T14:02:29+00:00",
19
+ "amount":{
20
+ "value":"20.00",
21
+ "currency":"EUR"
22
+ }
23
+ }');
24
+
25
+ $payment = ResourceFactory::createFromApiResult($apiResult, new Payment($this->createMock(MollieApiClient::class)));
26
+
27
+ $this->assertInstanceOf(Payment::class, $payment);
28
+ $this->assertEquals("payment", $payment->resource);
29
+ $this->assertEquals("tr_44aKxzEbr8", $payment->id);
30
+ $this->assertEquals("test", $payment->mode);
31
+ $this->assertEquals("2018-03-13T14:02:29+00:00", $payment->createdAt);
32
+ $this->assertEquals((object) ["value" => "20.00", "currency" => "EUR"], $payment->amount);
33
+ }
34
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/SettlementTest.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\Settlement;
7
+ use Mollie\Api\Types\SettlementStatus;
8
+
9
+ class SettlementTest extends \PHPUnit\Framework\TestCase
10
+ {
11
+ /**
12
+ * @param string $status
13
+ * @param string $function
14
+ * @param boolean $expected_boolean
15
+ *
16
+ * @dataProvider dpTestSettlementStatuses
17
+ */
18
+ public function testSettlementStatuses($status, $function, $expected_boolean)
19
+ {
20
+ $settlement = new Settlement($this->createMock(MollieApiClient::class));
21
+ $settlement->status = $status;
22
+
23
+ $this->assertEquals($expected_boolean, $settlement->{$function}());
24
+ }
25
+
26
+ public function dpTestSettlementStatuses()
27
+ {
28
+ return [
29
+ [SettlementStatus::STATUS_PENDING, "isPending", true],
30
+ [SettlementStatus::STATUS_PENDING, "isOpen", false],
31
+ [SettlementStatus::STATUS_PENDING, "isPaidout", false],
32
+ [SettlementStatus::STATUS_PENDING, "isFailed", false],
33
+
34
+ [SettlementStatus::STATUS_OPEN, "isPending", false],
35
+ [SettlementStatus::STATUS_OPEN, "isOpen", true],
36
+ [SettlementStatus::STATUS_OPEN, "isPaidout", false],
37
+ [SettlementStatus::STATUS_OPEN, "isFailed", false],
38
+
39
+ [SettlementStatus::STATUS_PAIDOUT, "isPending", false],
40
+ [SettlementStatus::STATUS_PAIDOUT, "isOpen", false],
41
+ [SettlementStatus::STATUS_PAIDOUT, "isPaidout", true],
42
+ [SettlementStatus::STATUS_PAIDOUT, "isFailed", false],
43
+
44
+ [SettlementStatus::STATUS_FAILED, "isPending", false],
45
+ [SettlementStatus::STATUS_FAILED, "isOpen", false],
46
+ [SettlementStatus::STATUS_FAILED, "isPaidout", false],
47
+ [SettlementStatus::STATUS_FAILED, "isFailed", true],
48
+ ];
49
+ }
50
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/ShipmentTest.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\Shipment;
7
+ use PHPUnit\Framework\TestCase;
8
+
9
+ class ShipmentTest extends TestCase
10
+ {
11
+ public function testHasTrackingReturnsTrueIfObjectNotNull()
12
+ {
13
+ $shipment = new Shipment($this->createMock(MollieApiClient::class));
14
+ $shipment->tracking = $this->getTrackingDummy();
15
+ $this->assertTrue($shipment->hasTracking());
16
+ }
17
+
18
+ public function testHasTrackingReturnsFalseIfObjectIsNull()
19
+ {
20
+ $shipment = new Shipment($this->createMock(MollieApiClient::class));
21
+ $shipment->tracking = null;
22
+ $this->assertFalse($shipment->hasTracking());
23
+ }
24
+
25
+ public function testHasTrackingUrlReturnsFalseIfTrackingIsNotSet()
26
+ {
27
+ $shipment = new Shipment($this->createMock(MollieApiClient::class));
28
+ $shipment->tracking = null;
29
+ $this->assertFalse($shipment->hasTrackingUrl());
30
+ }
31
+
32
+ public function testHasTrackingUrlReturnsTrueIfUrlIsSet()
33
+ {
34
+ $shipment = new Shipment($this->createMock(MollieApiClient::class));
35
+ $shipment->tracking = $this->getTrackingDummy([
36
+ 'url' => 'https://www.some-tracking-url.com/123',
37
+ ]);
38
+ $this->assertTrue($shipment->hasTrackingUrl());
39
+ }
40
+
41
+ public function testHasTrackingUrlReturnsFalseIfUrlIsNotSet()
42
+ {
43
+ $shipment = new Shipment($this->createMock(MollieApiClient::class));
44
+ $shipment->tracking = $this->getTrackingDummy([
45
+ 'url' => null,
46
+ ]);
47
+ $this->assertFalse($shipment->hasTrackingUrl());
48
+ }
49
+
50
+ public function testGetTrackingUrlReturnsNullIfNotAvailable()
51
+ {
52
+ $shipment = new Shipment($this->createMock(MollieApiClient::class));
53
+
54
+ $shipment->tracking = null;
55
+ $this->assertNull($shipment->getTrackingUrl());
56
+
57
+ $shipment->tracking = $this->getTrackingDummy([
58
+ 'url' => null,
59
+ ]);
60
+ $this->assertNull($shipment->getTrackingUrl());
61
+ }
62
+
63
+ public function testGetTrackingUrlReturnsUrlIfAvailable()
64
+ {
65
+ $shipment = new Shipment($this->createMock(MollieApiClient::class));
66
+ $shipment->tracking = $this->getTrackingDummy([
67
+ 'url' => 'https://www.some-tracking-url.com/123',
68
+ ]);
69
+
70
+ $this->assertEquals(
71
+ 'https://www.some-tracking-url.com/123',
72
+ $shipment->getTrackingUrl()
73
+ );
74
+ }
75
+
76
+ protected function getTrackingDummy($overrides = [])
77
+ {
78
+ return (object) array_merge([
79
+ 'carrier' => 'DummyCarrier',
80
+ 'code' => '123456ABCD',
81
+ 'url' => 'https://www.example.org/tracktrace/1234',
82
+ ], $overrides);
83
+ }
84
+ }
includes/mollie-api-php/tests/Mollie/API/Resources/SubscriptionTest.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\Api\Resources;
4
+
5
+ use Mollie\Api\MollieApiClient;
6
+ use Mollie\Api\Resources\Subscription;
7
+ use Mollie\Api\Types\SubscriptionStatus;
8
+
9
+ class SubscriptionTest extends \PHPUnit\Framework\TestCase
10
+ {
11
+ /**
12
+ * @param string $status
13
+ * @param string $function
14
+ * @param boolean $expected_boolean
15
+ *
16
+ * @dataProvider dpTestSubscriptionStatuses
17
+ */
18
+ public function testSubscriptionStatuses($status, $function, $expected_boolean)
19
+ {
20
+ $subscription = new Subscription($this->createMock(MollieApiClient::class));
21
+ $subscription->status = $status;
22
+
23
+ $this->assertEquals($expected_boolean, $subscription->{$function}());
24
+ }
25
+
26
+ public function dpTestSubscriptionStatuses()
27
+ {
28
+ return [
29
+ [SubscriptionStatus::STATUS_PENDING, "isPending", true],
30
+ [SubscriptionStatus::STATUS_PENDING, "isCanceled", false],
31
+ [SubscriptionStatus::STATUS_PENDING, "isCompleted", false],
32
+ [SubscriptionStatus::STATUS_PENDING, "isSuspended", false],
33
+ [SubscriptionStatus::STATUS_PENDING, "isActive", false],
34
+
35
+ [SubscriptionStatus::STATUS_CANCELED, "isPending", false],
36
+ [SubscriptionStatus::STATUS_CANCELED, "isCanceled", true],
37
+ [SubscriptionStatus::STATUS_CANCELED, "isCompleted", false],
38
+ [SubscriptionStatus::STATUS_CANCELED, "isSuspended", false],
39
+ [SubscriptionStatus::STATUS_CANCELED, "isActive", false],
40
+
41
+ [SubscriptionStatus::STATUS_COMPLETED, "isPending", false],
42
+ [SubscriptionStatus::STATUS_COMPLETED, "isCanceled", false],
43
+ [SubscriptionStatus::STATUS_COMPLETED, "isCompleted", true],
44
+ [SubscriptionStatus::STATUS_COMPLETED, "isSuspended", false],
45
+ [SubscriptionStatus::STATUS_COMPLETED, "isActive", false],
46
+
47
+ [SubscriptionStatus::STATUS_SUSPENDED, "isPending", false],
48
+ [SubscriptionStatus::STATUS_SUSPENDED, "isCanceled", false],
49
+ [SubscriptionStatus::STATUS_SUSPENDED, "isCompleted", false],
50
+ [SubscriptionStatus::STATUS_SUSPENDED, "isSuspended", true],
51
+ [SubscriptionStatus::STATUS_SUSPENDED, "isActive", false],
52
+
53
+ [SubscriptionStatus::STATUS_ACTIVE, "isPending", false],
54
+ [SubscriptionStatus::STATUS_ACTIVE, "isCanceled", false],
55
+ [SubscriptionStatus::STATUS_ACTIVE, "isCompleted", false],
56
+ [SubscriptionStatus::STATUS_ACTIVE, "isSuspended", false],
57
+ [SubscriptionStatus::STATUS_ACTIVE, "isActive", true],
58
+ ];
59
+ }
60
+ }
includes/mollie-api-php/tests/Mollie/API/Types/MandateMethodTest.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\API\Types;
4
+
5
+ use Mollie\Api\Types\MandateMethod;
6
+ use Mollie\Api\Types\PaymentMethod;
7
+ use PHPUnit\Framework\TestCase;
8
+
9
+ class MandateMethodTest extends TestCase
10
+ {
11
+ /**
12
+ * @param string $firstPaymentMethod
13
+ * @param string $expectedMethod
14
+ * @dataProvider dpTestGetForFirstPaymentMethod
15
+ */
16
+ public function testGetForFirstPaymentMethod($firstPaymentMethod, $expectedMethod)
17
+ {
18
+ $actualMethod = MandateMethod::getForFirstPaymentMethod($firstPaymentMethod);
19
+ $this->assertEquals($expectedMethod, $actualMethod);
20
+ }
21
+
22
+ public function dpTestGetForFirstPaymentMethod()
23
+ {
24
+ return [
25
+ [PaymentMethod::APPLEPAY, MandateMethod::CREDITCARD],
26
+ [PaymentMethod::CREDITCARD, MandateMethod::CREDITCARD],
27
+ [PaymentMethod::BANCONTACT, MandateMethod::DIRECTDEBIT],
28
+ [PaymentMethod::BELFIUS, MandateMethod::DIRECTDEBIT],
29
+ [PaymentMethod::EPS, MandateMethod::DIRECTDEBIT],
30
+ [PaymentMethod::GIROPAY, MandateMethod::DIRECTDEBIT],
31
+ [PaymentMethod::IDEAL, MandateMethod::DIRECTDEBIT],
32
+ [PaymentMethod::INGHOMEPAY, MandateMethod::DIRECTDEBIT],
33
+ [PaymentMethod::KBC, MandateMethod::DIRECTDEBIT],
34
+ [PaymentMethod::SOFORT, MandateMethod::DIRECTDEBIT],
35
+ ];
36
+ }
37
+ }
includes/mollie-api-php/tests/Mollie/TestHelpers/AmountObjectTestHelpers.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\TestHelpers;
4
+
5
+ trait AmountObjectTestHelpers
6
+ {
7
+ protected function assertAmountObject($value, $currency, $amountObject)
8
+ {
9
+ return $this->assertEquals(
10
+ $this->createAmountObject($value, $currency),
11
+ $amountObject
12
+ );
13
+ }
14
+
15
+ protected function createAmountObject($value, $currency)
16
+ {
17
+ return (object) [
18
+ 'value' => $value,
19
+ 'currency' => $currency,
20
+ ];
21
+ }
22
+ }
includes/mollie-api-php/tests/Mollie/TestHelpers/LinkObjectTestHelpers.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Tests\Mollie\TestHelpers;
4
+
5
+ trait LinkObjectTestHelpers
6
+ {
7
+ protected function assertLinkObject($href, $type, $linkObject)
8
+ {
9
+ return $this->assertEquals(
10
+ $this->createLinkObject($href, $type),
11
+ $linkObject
12
+ );
13
+ }
14
+
15
+ protected function createNamedLinkObject($name, $href, $type)
16
+ {
17
+ return (object) [
18
+ $name => $this->createLinkObject($href, $type),
19
+ ];
20
+ }
21
+
22
+ protected function createLinkObject($href, $type)
23
+ {
24
+ return (object) [
25
+ 'href' => $href,
26
+ 'type' => $type,
27
+ ];
28
+ }
29
+ }
includes/mollie-api-php/vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInitf833268ed2646da8e853833e738212e8::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInitbadbc7c27712fe1126301394a10557db::getLoader();
includes/mollie-api-php/vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInitf833268ed2646da8e853833e738212e8
6
  {
7
  private static $loader;
8
 
@@ -19,15 +19,15 @@ class ComposerAutoloaderInitf833268ed2646da8e853833e738212e8
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInitf833268ed2646da8e853833e738212e8', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInitf833268ed2646da8e853833e738212e8', 'loadClassLoader'));
25
 
26
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27
  if ($useStaticLoader) {
28
  require_once __DIR__ . '/autoload_static.php';
29
 
30
- call_user_func(\Composer\Autoload\ComposerStaticInitf833268ed2646da8e853833e738212e8::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
@@ -48,19 +48,19 @@ class ComposerAutoloaderInitf833268ed2646da8e853833e738212e8
48
  $loader->register(true);
49
 
50
  if ($useStaticLoader) {
51
- $includeFiles = Composer\Autoload\ComposerStaticInitf833268ed2646da8e853833e738212e8::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
- composerRequiref833268ed2646da8e853833e738212e8($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
- function composerRequiref833268ed2646da8e853833e738212e8($fileIdentifier, $file)
64
  {
65
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
66
  require $file;
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInitbadbc7c27712fe1126301394a10557db
6
  {
7
  private static $loader;
8
 
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInitbadbc7c27712fe1126301394a10557db', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInitbadbc7c27712fe1126301394a10557db', 'loadClassLoader'));
25
 
26
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27
  if ($useStaticLoader) {
28
  require_once __DIR__ . '/autoload_static.php';
29
 
30
+ call_user_func(\Composer\Autoload\ComposerStaticInitbadbc7c27712fe1126301394a10557db::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
48
  $loader->register(true);
49
 
50
  if ($useStaticLoader) {
51
+ $includeFiles = Composer\Autoload\ComposerStaticInitbadbc7c27712fe1126301394a10557db::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
+ composerRequirebadbc7c27712fe1126301394a10557db($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
+ function composerRequirebadbc7c27712fe1126301394a10557db($fileIdentifier, $file)
64
  {
65
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
66
  require $file;
includes/mollie-api-php/vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInitf833268ed2646da8e853833e738212e8
8
  {
9
  public static $files = array (
10
  '7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
@@ -229,9 +229,9 @@ class ComposerStaticInitf833268ed2646da8e853833e738212e8
229
  public static function getInitializer(ClassLoader $loader)
230
  {
231
  return \Closure::bind(function () use ($loader) {
232
- $loader->prefixLengthsPsr4 = ComposerStaticInitf833268ed2646da8e853833e738212e8::$prefixLengthsPsr4;
233
- $loader->prefixDirsPsr4 = ComposerStaticInitf833268ed2646da8e853833e738212e8::$prefixDirsPsr4;
234
- $loader->classMap = ComposerStaticInitf833268ed2646da8e853833e738212e8::$classMap;
235
 
236
  }, null, ClassLoader::class);
237
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInitbadbc7c27712fe1126301394a10557db
8
  {
9
  public static $files = array (
10
  '7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
229
  public static function getInitializer(ClassLoader $loader)
230
  {
231
  return \Closure::bind(function () use ($loader) {
232
+ $loader->prefixLengthsPsr4 = ComposerStaticInitbadbc7c27712fe1126301394a10557db::$prefixLengthsPsr4;
233
+ $loader->prefixDirsPsr4 = ComposerStaticInitbadbc7c27712fe1126301394a10557db::$prefixDirsPsr4;
234
+ $loader->classMap = ComposerStaticInitbadbc7c27712fe1126301394a10557db::$classMap;
235
 
236
  }, null, ClassLoader::class);
237
  }
includes/mollie-api-php/vendor/composer/ca-bundle/README.md CHANGED
@@ -27,22 +27,22 @@ Requirements
27
  Basic usage
28
  -----------
29
 
30
- # `Composer\CaBundle\CaBundle`
31
 
32
  - `CaBundle::getSystemCaRootBundlePath()`: Returns the system CA bundle path, or a path to the bundled one as fallback
33
  - `CaBundle::getBundledCaBundlePath()`: Returns the path to the bundled CA file
34
- - `CaBundle::validateCaFile($filename)`: Validates a CA file using opensl_x509_parse only if it is safe to use
35
  - `CaBundle::isOpensslParseSafe()`: Test if it is safe to use the PHP function openssl_x509_parse()
36
  - `CaBundle::reset()`: Resets the static caches
37
 
38
 
39
- ## To use with curl
40
 
41
  ```php
42
  $curl = curl_init("https://example.org/");
43
 
44
  $caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath();
45
- if (is_dir($caPathOrFile) || (is_link($caPathOrFile) && is_dir(readlink($caPathOrFile)))) {
46
  curl_setopt($curl, CURLOPT_CAPATH, $caPathOrFile);
47
  } else {
48
  curl_setopt($curl, CURLOPT_CAINFO, $caPathOrFile);
@@ -51,7 +51,7 @@ if (is_dir($caPathOrFile) || (is_link($caPathOrFile) && is_dir(readlink($caPathO
51
  $result = curl_exec($curl);
52
  ```
53
 
54
- ## To use with php streams
55
 
56
  ```php
57
  $opts = array(
@@ -61,7 +61,7 @@ $opts = array(
61
  );
62
 
63
  $caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath();
64
- if (is_dir($caPathOrFile) || (is_link($caPathOrFile) && is_dir(readlink($caPathOrFile)))) {
65
  $opts['ssl']['capath'] = $caPathOrFile;
66
  } else {
67
  $opts['ssl']['cafile'] = $caPathOrFile;
@@ -71,7 +71,7 @@ $context = stream_context_create($opts);
71
  $result = file_get_contents('https://example.com', false, $context);
72
  ```
73
 
74
- ## To use with Guzzle
75
 
76
  ```php
77
  $client = new \GuzzleHttp\Client([
27
  Basic usage
28
  -----------
29
 
30
+ ### `Composer\CaBundle\CaBundle`
31
 
32
  - `CaBundle::getSystemCaRootBundlePath()`: Returns the system CA bundle path, or a path to the bundled one as fallback
33
  - `CaBundle::getBundledCaBundlePath()`: Returns the path to the bundled CA file
34
+ - `CaBundle::validateCaFile($filename)`: Validates a CA file using openssl_x509_parse only if it is safe to use
35
  - `CaBundle::isOpensslParseSafe()`: Test if it is safe to use the PHP function openssl_x509_parse()
36
  - `CaBundle::reset()`: Resets the static caches
37
 
38
 
39
+ #### To use with curl
40
 
41
  ```php
42
  $curl = curl_init("https://example.org/");
43
 
44
  $caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath();
45
+ if (is_dir($caPathOrFile)) {
46
  curl_setopt($curl, CURLOPT_CAPATH, $caPathOrFile);
47
  } else {
48
  curl_setopt($curl, CURLOPT_CAINFO, $caPathOrFile);
51
  $result = curl_exec($curl);
52
  ```
53
 
54
+ #### To use with php streams
55
 
56
  ```php
57
  $opts = array(
61
  );
62
 
63
  $caPathOrFile = \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath();
64
+ if (is_dir($caPathOrFile)) {
65
  $opts['ssl']['capath'] = $caPathOrFile;
66
  } else {
67
  $opts['ssl']['cafile'] = $caPathOrFile;
71
  $result = file_get_contents('https://example.com', false, $context);
72
  ```
73
 
74
+ #### To use with Guzzle
75
 
76
  ```php
77
  $client = new \GuzzleHttp\Client([
includes/mollie-api-php/vendor/composer/ca-bundle/composer.json CHANGED
@@ -24,10 +24,10 @@
24
  "require": {
25
  "ext-openssl": "*",
26
  "ext-pcre": "*",
27
- "php": "^5.3.2 || ^7.0"
28
  },
29
  "require-dev": {
30
- "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5",
31
  "psr/log": "^1.0",
32
  "symfony/process": "^2.5 || ^3.0 || ^4.0"
33
  },
24
  "require": {
25
  "ext-openssl": "*",
26
  "ext-pcre": "*",
27
+ "php": "^5.3.2 || ^7.0 || ^8.0"
28
  },
29
  "require-dev": {
30
+ "phpunit/phpunit": "^4.8.35 || ^5.7 || 6.5 - 8",
31
  "psr/log": "^1.0",
32
  "symfony/process": "^2.5 || ^3.0 || ^4.0"
33
  },
includes/mollie-api-php/vendor/composer/ca-bundle/res/cacert.pem CHANGED
@@ -1,7 +1,7 @@
1
  ##
2
  ## Bundle of CA Root Certificates
3
  ##
4
- ## Certificate data from Mozilla as of: Wed Jan 23 04:12:09 2019 GMT
5
  ##
6
  ## This is a bundle of X.509 certificates of public Certificate Authorities
7
  ## (CA). These were automatically extracted from Mozilla's root certificates
@@ -14,7 +14,7 @@
14
  ## Just configure this file as the SSLCACertificateFile.
15
  ##
16
  ## Conversion done with mk-ca-bundle.pl version 1.27.
17
- ## SHA256: 18372117493b5b7ec006c31d966143fc95a9464a2b5f8d5188e23c5557b2292d
18
  ##
19
 
20
 
@@ -3399,3 +3399,109 @@ tlu3zM63Nwf9JtmYhST/WSMDmu2dnajkXjjO11INb9I/bbEFa0nOipFGc/T2L/Coc3cOZayhjWZS
3399
  aX5LaAzHHjcng6WMxwLkFM1JAbBzs/3GkDpv0mztO+7skb6iQ12LAEpmJURw3kAP+HwV96LOPNde
3400
  E4yBFxgX0b3xdxA61GU5wSesVywlVP+i2k+KYTlerj1KjL0=
3401
  -----END CERTIFICATE-----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ##
2
  ## Bundle of CA Root Certificates
3
  ##
4
+ ## Certificate data from Mozilla as of: Wed May 15 03:12:09 2019 GMT
5
  ##
6
  ## This is a bundle of X.509 certificates of public Certificate Authorities
7
  ## (CA). These were automatically extracted from Mozilla's root certificates
14
  ## Just configure this file as the SSLCACertificateFile.
15
  ##
16
  ## Conversion done with mk-ca-bundle.pl version 1.27.
17
+ ## SHA256: 61eaa79ac46d923f2f74dfe401189424e96fa8736102b47ba2cdb4ea19af2cc8
18
  ##
19
 
20
 
3399
  aX5LaAzHHjcng6WMxwLkFM1JAbBzs/3GkDpv0mztO+7skb6iQ12LAEpmJURw3kAP+HwV96LOPNde
3400
  E4yBFxgX0b3xdxA61GU5wSesVywlVP+i2k+KYTlerj1KjL0=
3401
  -----END CERTIFICATE-----
3402
+
3403
+ emSign Root CA - G1
3404
+ ===================
3405
+ -----BEGIN CERTIFICATE-----
3406
+ MIIDlDCCAnygAwIBAgIKMfXkYgxsWO3W2DANBgkqhkiG9w0BAQsFADBnMQswCQYDVQQGEwJJTjET
3407
+ MBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRl
3408
+ ZDEcMBoGA1UEAxMTZW1TaWduIFJvb3QgQ0EgLSBHMTAeFw0xODAyMTgxODMwMDBaFw00MzAyMTgx
3409
+ ODMwMDBaMGcxCzAJBgNVBAYTAklOMRMwEQYDVQQLEwplbVNpZ24gUEtJMSUwIwYDVQQKExxlTXVk
3410
+ aHJhIFRlY2hub2xvZ2llcyBMaW1pdGVkMRwwGgYDVQQDExNlbVNpZ24gUm9vdCBDQSAtIEcxMIIB
3411
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAk0u76WaK7p1b1TST0Bsew+eeuGQzf2N4aLTN
3412
+ LnF115sgxk0pvLZoYIr3IZpWNVrzdr3YzZr/k1ZLpVkGoZM0Kd0WNHVO8oG0x5ZOrRkVUkr+PHB1
3413
+ cM2vK6sVmjM8qrOLqs1D/fXqcP/tzxE7lM5OMhbTI0Aqd7OvPAEsbO2ZLIvZTmmYsvePQbAyeGHW
3414
+ DV/D+qJAkh1cF+ZwPjXnorfCYuKrpDhMtTk1b+oDafo6VGiFbdbyL0NVHpENDtjVaqSW0RM8LHhQ
3415
+ 6DqS0hdW5TUaQBw+jSztOd9C4INBdN+jzcKGYEho42kLVACL5HZpIQ15TjQIXhTCzLG3rdd8cIrH
3416
+ hQIDAQABo0IwQDAdBgNVHQ4EFgQU++8Nhp6w492pufEhF38+/PB3KxowDgYDVR0PAQH/BAQDAgEG
3417
+ MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAFn/8oz1h31xPaOfG1vR2vjTnGs2
3418
+ vZupYeveFix0PZ7mddrXuqe8QhfnPZHr5X3dPpzxz5KsbEjMwiI/aTvFthUvozXGaCocV685743Q
3419
+ NcMYDHsAVhzNixl03r4PEuDQqqE/AjSxcM6dGNYIAwlG7mDgfrbESQRRfXBgvKqy/3lyeqYdPV8q
3420
+ +Mri/Tm3R7nrft8EI6/6nAYH6ftjk4BAtcZsCjEozgyfz7MjNYBBjWzEN3uBL4ChQEKF6dk4jeih
3421
+ U80Bv2noWgbyRQuQ+q7hv53yrlc8pa6yVvSLZUDp/TGBLPQ5Cdjua6e0ph0VpZj3AYHYhX3zUVxx
3422
+ iN66zB+Afko=
3423
+ -----END CERTIFICATE-----
3424
+
3425
+ emSign ECC Root CA - G3
3426
+ =======================
3427
+ -----BEGIN CERTIFICATE-----
3428
+ MIICTjCCAdOgAwIBAgIKPPYHqWhwDtqLhDAKBggqhkjOPQQDAzBrMQswCQYDVQQGEwJJTjETMBEG
3429
+ A1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEg
3430
+ MB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0gRzMwHhcNMTgwMjE4MTgzMDAwWhcNNDMwMjE4
3431
+ MTgzMDAwWjBrMQswCQYDVQQGEwJJTjETMBEGA1UECxMKZW1TaWduIFBLSTElMCMGA1UEChMcZU11
3432
+ ZGhyYSBUZWNobm9sb2dpZXMgTGltaXRlZDEgMB4GA1UEAxMXZW1TaWduIEVDQyBSb290IENBIC0g
3433
+ RzMwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAQjpQy4LRL1KPOxst3iAhKAnjlfSU2fySU0WXTsuwYc
3434
+ 58Byr+iuL+FBVIcUqEqy6HyC5ltqtdyzdc6LBtCGI79G1Y4PPwT01xySfvalY8L1X44uT6EYGQIr
3435
+ MgqCZH0Wk9GjQjBAMB0GA1UdDgQWBBR8XQKEE9TMipuBzhccLikenEhjQjAOBgNVHQ8BAf8EBAMC
3436
+ AQYwDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjOPQQDAwNpADBmAjEAvvNhzwIQHWSVB7gYboiFBS+D
3437
+ CBeQyh+KTOgNG3qxrdWBCUfvO6wIBHxcmbHtRwfSAjEAnbpV/KlK6O3t5nYBQnvI+GDZjVGLVTv7
3438
+ jHvrZQnD+JbNR6iC8hZVdyR+EhCVBCyj
3439
+ -----END CERTIFICATE-----
3440
+
3441
+ emSign Root CA - C1
3442
+ ===================
3443
+ -----BEGIN CERTIFICATE-----
3444
+ MIIDczCCAlugAwIBAgILAK7PALrEzzL4Q7IwDQYJKoZIhvcNAQELBQAwVjELMAkGA1UEBhMCVVMx
3445
+ EzARBgNVBAsTCmVtU2lnbiBQS0kxFDASBgNVBAoTC2VNdWRocmEgSW5jMRwwGgYDVQQDExNlbVNp
3446
+ Z24gUm9vdCBDQSAtIEMxMB4XDTE4MDIxODE4MzAwMFoXDTQzMDIxODE4MzAwMFowVjELMAkGA1UE
3447
+ BhMCVVMxEzARBgNVBAsTCmVtU2lnbiBQS0kxFDASBgNVBAoTC2VNdWRocmEgSW5jMRwwGgYDVQQD
3448
+ ExNlbVNpZ24gUm9vdCBDQSAtIEMxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz+up
3449
+ ufGZBczYKCFK83M0UYRWEPWgTywS4/oTmifQz/l5GnRfHXk5/Fv4cI7gklL35CX5VIPZHdPIWoU/
3450
+ Xse2B+4+wM6ar6xWQio5JXDWv7V7Nq2s9nPczdcdioOl+yuQFTdrHCZH3DspVpNqs8FqOp099cGX
3451
+ OFgFixwR4+S0uF2FHYP+eF8LRWgYSKVGczQ7/g/IdrvHGPMF0Ybzhe3nudkyrVWIzqa2kbBPrH4V
3452
+ I5b2P/AgNBbeCsbEBEV5f6f9vtKppa+cxSMq9zwhbL2vj07FOrLzNBL834AaSaTUqZX3noleooms
3453
+ lMuoaJuvimUnzYnu3Yy1aylwQ6BpC+S5DwIDAQABo0IwQDAdBgNVHQ4EFgQU/qHgcB4qAzlSWkK+
3454
+ XJGFehiqTbUwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQAD
3455
+ ggEBAMJKVvoVIXsoounlHfv4LcQ5lkFMOycsxGwYFYDGrK9HWS8mC+M2sO87/kOXSTKZEhVb3xEp
3456
+ /6tT+LvBeA+snFOvV71ojD1pM/CjoCNjO2RnIkSt1XHLVip4kqNPEjE2NuLe/gDEo2APJ62gsIq1
3457
+ NnpSob0n9CAnYuhNlCQT5AoE6TyrLshDCUrGYQTlSTR+08TI9Q/Aqum6VF7zYytPT1DU/rl7mYw9
3458
+ wC68AivTxEDkigcxHpvOJpkT+xHqmiIMERnHXhuBUDDIlhJu58tBf5E7oke3VIAb3ADMmpDqw8NQ
3459
+ BmIMMMAVSKeoWXzhriKi4gp6D/piq1JM4fHfyr6DDUI=
3460
+ -----END CERTIFICATE-----
3461
+
3462
+ emSign ECC Root CA - C3
3463
+ =======================
3464
+ -----BEGIN CERTIFICATE-----
3465
+ MIICKzCCAbGgAwIBAgIKe3G2gla4EnycqDAKBggqhkjOPQQDAzBaMQswCQYDVQQGEwJVUzETMBEG
3466
+ A1UECxMKZW1TaWduIFBLSTEUMBIGA1UEChMLZU11ZGhyYSBJbmMxIDAeBgNVBAMTF2VtU2lnbiBF
3467
+ Q0MgUm9vdCBDQSAtIEMzMB4XDTE4MDIxODE4MzAwMFoXDTQzMDIxODE4MzAwMFowWjELMAkGA1UE
3468
+ BhMCVVMxEzARBgNVBAsTCmVtU2lnbiBQS0kxFDASBgNVBAoTC2VNdWRocmEgSW5jMSAwHgYDVQQD
3469
+ ExdlbVNpZ24gRUNDIFJvb3QgQ0EgLSBDMzB2MBAGByqGSM49AgEGBSuBBAAiA2IABP2lYa57JhAd
3470
+ 6bciMK4G9IGzsUJxlTm801Ljr6/58pc1kjZGDoeVjbk5Wum739D+yAdBPLtVb4OjavtisIGJAnB9
3471
+ SMVK4+kiVCJNk7tCDK93nCOmfddhEc5lx/h//vXyqaNCMEAwHQYDVR0OBBYEFPtaSNCAIEDyqOkA
3472
+ B2kZd6fmw/TPMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MAoGCCqGSM49BAMDA2gA
3473
+ MGUCMQC02C8Cif22TGK6Q04ThHK1rt0c3ta13FaPWEBaLd4gTCKDypOofu4SQMfWh0/434UCMBwU
3474
+ ZOR8loMRnLDRWmFLpg9J0wD8ofzkpf9/rdcw0Md3f76BB1UwUCAU9Vc4CqgxUQ==
3475
+ -----END CERTIFICATE-----
3476
+
3477
+ Hongkong Post Root CA 3
3478
+ =======================
3479
+ -----BEGIN CERTIFICATE-----
3480
+ MIIFzzCCA7egAwIBAgIUCBZfikyl7ADJk0DfxMauI7gcWqQwDQYJKoZIhvcNAQELBQAwbzELMAkG
3481
+ A1UEBhMCSEsxEjAQBgNVBAgTCUhvbmcgS29uZzESMBAGA1UEBxMJSG9uZyBLb25nMRYwFAYDVQQK
3482
+ Ew1Ib25na29uZyBQb3N0MSAwHgYDVQQDExdIb25na29uZyBQb3N0IFJvb3QgQ0EgMzAeFw0xNzA2
3483
+ MDMwMjI5NDZaFw00MjA2MDMwMjI5NDZaMG8xCzAJBgNVBAYTAkhLMRIwEAYDVQQIEwlIb25nIEtv
3484
+ bmcxEjAQBgNVBAcTCUhvbmcgS29uZzEWMBQGA1UEChMNSG9uZ2tvbmcgUG9zdDEgMB4GA1UEAxMX
3485
+ SG9uZ2tvbmcgUG9zdCBSb290IENBIDMwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCz
3486
+ iNfqzg8gTr7m1gNt7ln8wlffKWihgw4+aMdoWJwcYEuJQwy51BWy7sFOdem1p+/l6TWZ5Mwc50tf
3487
+ jTMwIDNT2aa71T4Tjukfh0mtUC1Qyhi+AViiE3CWu4mIVoBc+L0sPOFMV4i707mV78vH9toxdCim
3488
+ 5lSJ9UExyuUmGs2C4HDaOym71QP1mbpV9WTRYA6ziUm4ii8F0oRFKHyPaFASePwLtVPLwpgchKOe
3489
+ sL4jpNrcyCse2m5FHomY2vkALgbpDDtw1VAliJnLzXNg99X/NWfFobxeq81KuEXryGgeDQ0URhLj
3490
+ 0mRiikKYvLTGCAj4/ahMZJx2Ab0vqWwzD9g/KLg8aQFChn5pwckGyuV6RmXpwtZQQS4/t+TtbNe/
3491
+ JgERohYpSms0BpDsE9K2+2p20jzt8NYt3eEV7KObLyzJPivkaTv/ciWxNoZbx39ri1UbSsUgYT2u
3492
+ y1DhCDq+sI9jQVMwCFk8mB13umOResoQUGC/8Ne8lYePl8X+l2oBlKN8W4UdKjk60FSh0Tlxnf0h
3493
+ +bV78OLgAo9uliQlLKAeLKjEiafv7ZkGL7YKTE/bosw3Gq9HhS2KX8Q0NEwA/RiTZxPRN+ZItIsG
3494
+ xVd7GYYKecsAyVKvQv83j+GjHno9UKtjBucVtT+2RTeUN7F+8kjDf8V1/peNRY8apxpyKBpADwID
3495
+ AQABo2MwYTAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAfBgNVHSMEGDAWgBQXnc0e
3496
+ i9Y5K3DTXNSguB+wAPzFYTAdBgNVHQ4EFgQUF53NHovWOStw01zUoLgfsAD8xWEwDQYJKoZIhvcN
3497
+ AQELBQADggIBAFbVe27mIgHSQpsY1Q7XZiNc4/6gx5LS6ZStS6LG7BJ8dNVI0lkUmcDrudHr9Egw
3498
+ W62nV3OZqdPlt9EuWSRY3GguLmLYauRwCy0gUCCkMpXRAJi70/33MvJJrsZ64Ee+bs7Lo3I6LWld
3499
+ y8joRTnU+kLBEUx3XZL7av9YROXrgZ6voJmtvqkBZss4HTzfQx/0TW60uhdG/H39h4F5ag0zD/ov
3500
+ +BS5gLNdTaqX4fnkGMX41TiMJjz98iji7lpJiCzfeT2OnpA8vUFKOt1b9pq0zj8lMH8yfaIDlNDc
3501
+ eqFS3m6TjRgm/VWsvY+b0s+v54Ysyx8Jb6NvqYTUc79NoXQbTiNg8swOqn+knEwlqLJmOzj/2ZQw
3502
+ 9nKEvmhVEA/GcywWaZMH/rFF7buiVWqw2rVKAiUnhde3t4ZEFolsgCs+l6mc1X5VTMbeRRAc6uk7
3503
+ nwNT7u56AQIWeNTowr5GdogTPyK7SBIdUgC0An4hGh6cJfTzPV4e0hz5sy229zdcxsshTrD3mUcY
3504
+ hcErulWuBurQB7Lcq9CClnXO0lD+mefPL5/ndtFhKvshuzHQqp9HpLIiyhY6UFfEW0NnxWViA0kB
3505
+ 60PZ2Pierc+xYw5F9KBaLJstxabArahH9CdMOA0uG0k7UvToiIMrVCjU8jVStDKDYmlkDJGcn5fq
3506
+ dBb9HxEGmpv0
3507
+ -----END CERTIFICATE-----
includes/mollie-api-php/vendor/composer/ca-bundle/src/CaBundle.php CHANGED
@@ -66,32 +66,21 @@ class CaBundle
66
  if (self::$caPath !== null) {
67
  return self::$caPath;
68
  }
 
 
69
 
70
  // If SSL_CERT_FILE env variable points to a valid certificate/bundle, use that.
71
  // This mimics how OpenSSL uses the SSL_CERT_FILE env variable.
72
- $envCertFile = getenv('SSL_CERT_FILE');
73
- if ($envCertFile && is_readable($envCertFile) && static::validateCaFile($envCertFile, $logger)) {
74
- return self::$caPath = $envCertFile;
75
- }
76
 
77
  // If SSL_CERT_DIR env variable points to a valid certificate/bundle, use that.
78
  // This mimics how OpenSSL uses the SSL_CERT_FILE env variable.
79
- $envCertDir = getenv('SSL_CERT_DIR');
80
- if ($envCertDir && is_dir($envCertDir) && is_readable($envCertDir)) {
81
- return self::$caPath = $envCertDir;
82
- }
83
 
84
- $configured = ini_get('openssl.cafile');
85
- if ($configured && strlen($configured) > 0 && is_readable($configured) && static::validateCaFile($configured, $logger)) {
86
- return self::$caPath = $configured;
87
- }
88
 
89
- $configured = ini_get('openssl.capath');
90
- if ($configured && is_dir($configured) && is_readable($configured)) {
91
- return self::$caPath = $configured;
92
- }
93
-
94
- $caBundlePaths = array(
95
  '/etc/pki/tls/certs/ca-bundle.crt', // Fedora, RHEL, CentOS (ca-certificates package)
96
  '/etc/ssl/certs/ca-certificates.crt', // Debian, Ubuntu, Gentoo, Arch Linux (ca-certificates package)
97
  '/etc/ssl/ca-bundle.pem', // SUSE, openSUSE (ca-certificates package)
@@ -105,15 +94,18 @@ class CaBundle
105
  '/usr/local/etc/openssl/cert.pem', // OS X homebrew, openssl package
106
  );
107
 
 
 
 
 
 
 
108
  foreach ($caBundlePaths as $caBundle) {
109
- if (@is_readable($caBundle) && static::validateCaFile($caBundle, $logger)) {
110
  return self::$caPath = $caBundle;
111
  }
112
- }
113
 
114
- foreach ($caBundlePaths as $caBundle) {
115
- $caBundle = dirname($caBundle);
116
- if (@is_dir($caBundle) && glob($caBundle.'/*')) {
117
  return self::$caPath = $caBundle;
118
  }
119
  }
@@ -305,4 +297,14 @@ EOT;
305
  self::$caPath = null;
306
  self::$useOpensslParse = null;
307
  }
 
 
 
 
 
 
 
 
 
 
308
  }
66
  if (self::$caPath !== null) {
67
  return self::$caPath;
68
  }
69
+ $caBundlePaths = array();
70
+
71
 
72
  // If SSL_CERT_FILE env variable points to a valid certificate/bundle, use that.
73
  // This mimics how OpenSSL uses the SSL_CERT_FILE env variable.
74
+ $caBundlePaths[] = getenv('SSL_CERT_FILE');
 
 
 
75
 
76
  // If SSL_CERT_DIR env variable points to a valid certificate/bundle, use that.
77
  // This mimics how OpenSSL uses the SSL_CERT_FILE env variable.
78
+ $caBundlePaths[] = getenv('SSL_CERT_DIR');
 
 
 
79
 
80
+ $caBundlePaths[] = ini_get('openssl.cafile');
81
+ $caBundlePaths[] = ini_get('openssl.capath');
 
 
82
 
83
+ $otherLocations = array(
 
 
 
 
 
84
  '/etc/pki/tls/certs/ca-bundle.crt', // Fedora, RHEL, CentOS (ca-certificates package)
85
  '/etc/ssl/certs/ca-certificates.crt', // Debian, Ubuntu, Gentoo, Arch Linux (ca-certificates package)
86
  '/etc/ssl/ca-bundle.pem', // SUSE, openSUSE (ca-certificates package)
94
  '/usr/local/etc/openssl/cert.pem', // OS X homebrew, openssl package
95
  );
96
 
97
+ foreach($otherLocations as $location) {
98
+ $otherLocations[] = dirname($location);
99
+ }
100
+
101
+ $caBundlePaths = array_merge($caBundlePaths, $otherLocations);
102
+
103
  foreach ($caBundlePaths as $caBundle) {
104
+ if (self::caFileUsable($caBundle, $logger)) {
105
  return self::$caPath = $caBundle;
106
  }
 
107
 
108
+ if (self::caDirUsable($caBundle)) {
 
 
109
  return self::$caPath = $caBundle;
110
  }
111
  }
297
  self::$caPath = null;
298
  self::$useOpensslParse = null;
299
  }
300
+
301
+ private static function caFileUsable($certFile, LoggerInterface $logger = null)
302
+ {
303
+ return $certFile && @is_file($certFile) && @is_readable($certFile) && static::validateCaFile($certFile, $logger);
304
+ }
305
+
306
+ private static function caDirUsable($certDir)
307
+ {
308
+ return $certDir && @is_dir($certDir) && @is_readable($certDir) && glob($certDir . '/*');
309
+ }
310
  }
includes/mollie-api-php/vendor/composer/installed.json CHANGED
@@ -1,30 +1,30 @@
1
  [
2
  {
3
  "name": "composer/ca-bundle",
4
- "version": "1.1.4",
5
- "version_normalized": "1.1.4.0",
6
  "source": {
7
  "type": "git",
8
  "url": "https://github.com/composer/ca-bundle.git",
9
- "reference": "558f321c52faeb4828c03e7dc0cfe39a09e09a2d"
10
  },
11
  "dist": {
12
  "type": "zip",
13
- "url": "https://api.github.com/repos/composer/ca-bundle/zipball/558f321c52faeb4828c03e7dc0cfe39a09e09a2d",
14
- "reference": "558f321c52faeb4828c03e7dc0cfe39a09e09a2d",
15
  "shasum": ""
16
  },
17
  "require": {
18
  "ext-openssl": "*",
19
  "ext-pcre": "*",
20
- "php": "^5.3.2 || ^7.0"
21
  },
22
  "require-dev": {
23
- "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5",
24
  "psr/log": "^1.0",
25
  "symfony/process": "^2.5 || ^3.0 || ^4.0"
26
  },
27
- "time": "2019-01-28T09:30:10+00:00",
28
  "type": "library",
29
  "extra": {
30
  "branch-alias": {
1
  [
2
  {
3
  "name": "composer/ca-bundle",
4
+ "version": "1.2.3",
5
+ "version_normalized": "1.2.3.0",
6
  "source": {
7
  "type": "git",
8
  "url": "https://github.com/composer/ca-bundle.git",
9
+ "reference": "f26a67e397be0e5c00d7c52ec7b5010098e15ce5"
10
  },
11
  "dist": {
12
  "type": "zip",
13
+ "url": "https://api.github.com/repos/composer/ca-bundle/zipball/f26a67e397be0e5c00d7c52ec7b5010098e15ce5",
14
+ "reference": "f26a67e397be0e5c00d7c52ec7b5010098e15ce5",
15
  "shasum": ""
16
  },
17
  "require": {
18
  "ext-openssl": "*",
19
  "ext-pcre": "*",
20
+ "php": "^5.3.2 || ^7.0 || ^8.0"
21
  },
22
  "require-dev": {
23
+ "phpunit/phpunit": "^4.8.35 || ^5.7 || 6.5 - 8",
24
  "psr/log": "^1.0",
25
  "symfony/process": "^2.5 || ^3.0 || ^4.0"
26
  },
27
+ "time": "2019-08-02T09:05:43+00:00",
28
  "type": "library",
29
  "extra": {
30
  "branch-alias": {
includes/mollie/wc/gateway/applepay.php CHANGED
@@ -13,7 +13,6 @@ class Mollie_WC_Gateway_Applepay extends Mollie_WC_Gateway_Abstract
13
  */
14
  public function __construct()
15
  {
16
- // TODO Check if its support refund?
17
  $this->supports = [
18
  'products',
19
  'refunds',
13
  */
14
  public function __construct()
15
  {
 
16
  $this->supports = [
17
  'products',
18
  'refunds',
includes/mollie/wc/gateway/mybank.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Mollie\Api\Resources\Payment;
4
+
5
+ /**
6
+ * Class Mollie_WC_Gateway_MyBank
7
+ */
8
+ class Mollie_WC_Gateway_MyBank extends Mollie_WC_Gateway_Abstract
9
+ {
10
+ /**
11
+ * Mollie_WC_Gateway_Applepay constructor.
12
+ */
13
+ public function __construct()
14
+ {
15
+ $this->supports = [
16
+ 'products',
17
+ 'refunds',
18
+ ];
19
+
20
+ parent::__construct();
21
+ }
22
+
23
+ /**
24
+ * @return string
25
+ */
26
+ public function getMollieMethodId()
27
+ {
28
+ return 'mybank';
29
+ }
30
+
31
+ /**
32
+ * @return string
33
+ */
34
+ public function getDefaultTitle()
35
+ {
36
+ return __('MyBank', 'mollie-payments-for-woocommerce');
37
+ }
38
+
39
+ /**
40
+ * @return string
41
+ */
42
+ protected function getSettingsDescription()
43
+ {
44
+ return __('To accept payments via MyBank', 'mollie-payments-for-woocommerce');
45
+ }
46
+
47
+ /**
48
+ * @return string
49
+ */
50
+ protected function getDefaultDescription()
51
+ {
52
+ return '';
53
+ }
54
+
55
+ /**
56
+ * Get Order Instructions
57
+ *
58
+ * @param WC_Order $order
59
+ * @param Payment $payment
60
+ * @param bool $admin_instructions
61
+ * @param bool $plain_text
62
+ * @return string|null
63
+ */
64
+ protected function getInstructions(
65
+ WC_Order $order,
66
+ Mollie\Api\Resources\Payment $payment,
67
+ $admin_instructions,
68
+ $plain_text
69
+ ) {
70
+
71
+ if ($payment->isPaid() && $payment->details) {
72
+ return sprintf(
73
+ __(
74
+ /* translators: Placeholder 1: MyBank consumer name, placeholder 2: Consumer Account number */
75
+ 'Payment completed by <strong>%1$s</strong> - %2$s',
76
+ 'mollie-payments-for-woocommerce'
77
+ ),
78
+ $payment->details->consumerName,
79
+ $payment->details->consumerAccount
80
+ );
81
+ }
82
+
83
+ return parent::getInstructions($order, $payment, $admin_instructions, $plain_text);
84
+ }
85
+ }
includes/mollie/wc/plugin.php CHANGED
@@ -7,7 +7,7 @@ class Mollie_WC_Plugin
7
  {
8
  const PLUGIN_ID = 'mollie-payments-for-woocommerce';
9
  const PLUGIN_TITLE = 'Mollie Payments for WooCommerce';
10
- const PLUGIN_VERSION = '5.2.1';
11
 
12
  const DB_VERSION = '1.0';
13
  const DB_VERSION_PARAM_NAME = 'mollie-db-version';
@@ -46,6 +46,7 @@ class Mollie_WC_Plugin
46
  'Mollie_WC_Gateway_Sofort',
47
  'Mollie_WC_Gateway_Giftcard',
48
  'Mollie_WC_Gateway_Applepay',
 
49
  );
50
 
51
  private function __construct () {}
7
  {
8
  const PLUGIN_ID = 'mollie-payments-for-woocommerce';
9
  const PLUGIN_TITLE = 'Mollie Payments for WooCommerce';
10
+ const PLUGIN_VERSION = '5.3.0';
11
 
12
  const DB_VERSION = '1.0';
13
  const DB_VERSION_PARAM_NAME = 'mollie-db-version';
46
  'Mollie_WC_Gateway_Sofort',
47
  'Mollie_WC_Gateway_Giftcard',
48
  'Mollie_WC_Gateway_Applepay',
49
+ 'Mollie_WC_Gateway_MyBank',
50
  );
51
 
52
  private function __construct () {}
mollie-payments-for-woocommerce.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Mollie Payments for WooCommerce
4
  * Plugin URI: https://www.mollie.com
5
  * Description: Accept payments in WooCommerce with the official Mollie plugin
6
- * Version: 5.2.1
7
  * Author: Mollie
8
  * Author URI: https://www.mollie.com
9
  * Requires at least: 3.8
@@ -12,7 +12,7 @@
12
  * Domain Path: /i18n/languages/
13
  * License: GPLv2 or later
14
  * WC requires at least: 2.2.0
15
- * WC tested up to: 3.6
16
  */
17
 
18
  // Exit if accessed directly.
3
  * Plugin Name: Mollie Payments for WooCommerce
4
  * Plugin URI: https://www.mollie.com
5
  * Description: Accept payments in WooCommerce with the official Mollie plugin
6
+ * Version: 5.3.0
7
  * Author: Mollie
8
  * Author URI: https://www.mollie.com
9
  * Requires at least: 3.8
12
  * Domain Path: /i18n/languages/
13
  * License: GPLv2 or later
14
  * WC requires at least: 2.2.0
15
+ * WC tested up to: 3.7
16
  */
17
 
18
  // Exit if accessed directly.
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: daanvm, danielhuesken, davdebcom, dinamiko, inpsyde, l.vangunst, n
3
  Tags: mollie, payments, payment gateway, woocommerce, credit card, ideal, bancontact, klarna, sofort, giropay, woocommerce subscriptions
4
  Requires at least: 3.8
5
  Tested up to: 5.2
6
- Stable tag: 5.2.1
7
  Requires PHP: 5.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -181,6 +181,12 @@ Automatic updates should work like a charm; as always though, ensure you backup
181
 
182
  == Changelog ==
183
 
 
 
 
 
 
 
184
  = 5.2.1 - 24-07-2019 =
185
 
186
  * Fix - Payment wall won't load because third party code may register gateways in form of a class instance instead of a string
3
  Tags: mollie, payments, payment gateway, woocommerce, credit card, ideal, bancontact, klarna, sofort, giropay, woocommerce subscriptions
4
  Requires at least: 3.8
5
  Tested up to: 5.2
6
+ Stable tag: 5.3.0
7
  Requires PHP: 5.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
181
 
182
  == Changelog ==
183
 
184
+ = 5.3.0 - 21-08-2019 =
185
+
186
+ * Add - Introduce MyBank payment method
187
+ * Fix - Active Payment Object may be NULL causing WSOD after order is placed in Mollie
188
+ * Fix - ApplePay logo does not have the right resolution
189
+
190
  = 5.2.1 - 24-07-2019 =
191
 
192
  * Fix - Payment wall won't load because third party code may register gateways in form of a class instance instead of a string