Version Description
Download this release
Release Info
Developer | woothemes |
Plugin | ![]() |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- LICENSE +235 -0
- changelog.txt +4 -0
- modules/ppcp-admin-notices/extensions.php +10 -0
- modules/ppcp-admin-notices/module.php +16 -0
- modules/ppcp-admin-notices/services.php +28 -0
- modules/ppcp-admin-notices/src/Entity/class-message.php +77 -0
- modules/ppcp-admin-notices/src/Renderer/class-renderer.php +53 -0
- modules/ppcp-admin-notices/src/Renderer/class-rendererinterface.php +23 -0
- modules/ppcp-admin-notices/src/Repository/class-repository.php +37 -0
- modules/ppcp-admin-notices/src/Repository/class-repositoryinterface.php +26 -0
- modules/ppcp-admin-notices/src/class-adminnotices.php +56 -0
- modules/ppcp-api-client/extensions.php +12 -0
- modules/ppcp-api-client/module.php +16 -0
- modules/ppcp-api-client/services.php +294 -0
- modules/ppcp-api-client/src/Authentication/class-bearer.php +25 -0
- modules/ppcp-api-client/src/Authentication/class-connectbearer.php +32 -0
- modules/ppcp-api-client/src/Authentication/class-paypalbearer.php +140 -0
- modules/ppcp-api-client/src/Endpoint/class-identitytoken.php +133 -0
- modules/ppcp-api-client/src/Endpoint/class-loginseller.php +196 -0
- modules/ppcp-api-client/src/Endpoint/class-orderendpoint.php +538 -0
- modules/ppcp-api-client/src/Endpoint/class-partnerreferrals.php +146 -0
- modules/ppcp-api-client/src/Endpoint/class-partnersendpoint.php +149 -0
- modules/ppcp-api-client/src/Endpoint/class-paymentsendpoint.php +251 -0
- modules/ppcp-api-client/src/Endpoint/class-paymenttokenendpoint.php +203 -0
- modules/ppcp-api-client/src/Endpoint/class-requesttrait.php +39 -0
- modules/ppcp-api-client/src/Endpoint/class-webhookendpoint.php +305 -0
- modules/ppcp-api-client/src/Entity/class-address.php +155 -0
- modules/ppcp-api-client/src/Entity/class-amount.php +84 -0
- modules/ppcp-api-client/src/Entity/class-amountbreakdown.php +190 -0
- modules/ppcp-api-client/src/Entity/class-applicationcontext.php +249 -0
- modules/ppcp-api-client/src/Entity/class-authorization.php +75 -0
- modules/ppcp-api-client/src/Entity/class-authorizationstatus.php +94 -0
- modules/ppcp-api-client/src/Entity/class-capture.php +197 -0
- modules/ppcp-api-client/src/Entity/class-cardauthenticationresult.php +119 -0
- modules/ppcp-api-client/src/Entity/class-item.php +185 -0
- modules/ppcp-api-client/src/Entity/class-money.php +71 -0
- modules/ppcp-api-client/src/Entity/class-order.php +245 -0
- modules/ppcp-api-client/src/Entity/class-orderstatus.php +89 -0
- modules/ppcp-api-client/src/Entity/class-patch.php +100 -0
- modules/ppcp-api-client/src/Entity/class-patchcollection.php +55 -0
- modules/ppcp-api-client/src/Entity/class-payee.php +79 -0
- modules/ppcp-api-client/src/Entity/class-payer.php +186 -0
- modules/ppcp-api-client/src/Entity/class-payername.php +75 -0
- modules/ppcp-api-client/src/Entity/class-payertaxinfo.php +93 -0
- modules/ppcp-api-client/src/Entity/class-paymentmethod.php +81 -0
- modules/ppcp-api-client/src/Entity/class-payments.php +93 -0
- modules/ppcp-api-client/src/Entity/class-paymentsource.php +82 -0
- modules/ppcp-api-client/src/Entity/class-paymentsourcecard.php +123 -0
- modules/ppcp-api-client/src/Entity/class-paymentsourcewallet.php +25 -0
- modules/ppcp-api-client/src/Entity/class-paymenttoken.php +85 -0
- modules/ppcp-api-client/src/Entity/class-phone.php +52 -0
- modules/ppcp-api-client/src/Entity/class-phonewithtype.php +79 -0
- modules/ppcp-api-client/src/Entity/class-purchaseunit.php +358 -0
- modules/ppcp-api-client/src/Entity/class-refund.php +118 -0
- modules/ppcp-api-client/src/Entity/class-sellerstatus.php +65 -0
- modules/ppcp-api-client/src/Entity/class-sellerstatusproduct.php +108 -0
- modules/ppcp-api-client/src/Entity/class-shipping.php +73 -0
- modules/ppcp-api-client/src/Entity/class-token.php +123 -0
- modules/ppcp-api-client/src/Entity/class-webhook.php +97 -0
- modules/ppcp-api-client/src/Exception/class-notfoundexception.php +21 -0
- modules/ppcp-api-client/src/Exception/class-paypalapiexception.php +109 -0
- modules/ppcp-api-client/src/Exception/class-runtimeexception.php +18 -0
- modules/ppcp-api-client/src/Factory/class-addressfactory.php +86 -0
- modules/ppcp-api-client/src/Factory/class-amountfactory.php +222 -0
- modules/ppcp-api-client/src/Factory/class-applicationcontextfactory.php +44 -0
- modules/ppcp-api-client/src/Factory/class-authorizationfactory.php +47 -0
- modules/ppcp-api-client/src/Factory/class-capturefactory.php +57 -0
- modules/ppcp-api-client/src/Factory/class-itemfactory.php +155 -0
- modules/ppcp-api-client/src/Factory/class-orderfactory.php +171 -0
- modules/ppcp-api-client/src/Factory/class-patchcollectionfactory.php +85 -0
- modules/ppcp-api-client/src/Factory/class-payeefactory.php +38 -0
- modules/ppcp-api-client/src/Factory/class-payerfactory.php +147 -0
- modules/ppcp-api-client/src/Factory/class-paymentsfactory.php +73 -0
- modules/ppcp-api-client/src/Factory/class-paymentsourcefactory.php +53 -0
- modules/ppcp-api-client/src/Factory/class-paymenttokenfactory.php +50 -0
- modules/ppcp-api-client/src/Factory/class-purchaseunitfactory.php +264 -0
- modules/ppcp-api-client/src/Factory/class-sellerstatusfactory.php +42 -0
- modules/ppcp-api-client/src/Factory/class-shippingfactory.php +99 -0
- modules/ppcp-api-client/src/Factory/class-webhookfactory.php +83 -0
- modules/ppcp-api-client/src/Helper/class-cache.php +76 -0
- modules/ppcp-api-client/src/Helper/class-dccapplies.php +239 -0
- modules/ppcp-api-client/src/Helper/class-errorresponse.php +121 -0
- modules/ppcp-api-client/src/Repository/class-applicationcontextrepository.php +62 -0
- modules/ppcp-api-client/src/Repository/class-cartrepository.php +46 -0
- modules/ppcp-api-client/src/Repository/class-partnerreferralsdata.php +117 -0
- modules/ppcp-api-client/src/Repository/class-payeerepository.php +55 -0
- modules/ppcp-api-client/src/Repository/class-paypalrequestidrepository.php +90 -0
- modules/ppcp-api-client/src/Repository/class-purchaseunitrepositoryinterface.php +26 -0
- modules/ppcp-api-client/src/class-apimodule.php +50 -0
- modules/ppcp-button/assets/css/hosted-fields.css +1 -0
- modules/ppcp-button/assets/js/button.js +2 -0
- modules/ppcp-button/assets/js/button.js.map +1 -0
- modules/ppcp-button/assets/js/hosted-fields.js +2 -0
- modules/ppcp-button/assets/js/hosted-fields.js.map +1 -0
- modules/ppcp-button/assets/js/hostedfields.js +2 -0
- modules/ppcp-button/assets/js/hostedfields.js.map +1 -0
- modules/ppcp-button/extensions.php +10 -0
- modules/ppcp-button/module.php +16 -0
- modules/ppcp-button/resources/css/hosted-fields.scss +5 -0
- modules/ppcp-button/resources/js/button.js +98 -0
- modules/ppcp-button/resources/js/modules/ActionHandler/CartActionHandler.js +46 -0
- modules/ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler.js +60 -0
- modules/ppcp-button/resources/js/modules/ActionHandler/SingleProductActionHandler.js +133 -0
- modules/ppcp-button/resources/js/modules/ContextBootstrap/CartBootstap.js +42 -0
- modules/ppcp-button/resources/js/modules/ContextBootstrap/CheckoutBootstap.js +82 -0
- modules/ppcp-button/resources/js/modules/ContextBootstrap/MiniCartBootstap.js +43 -0
- modules/ppcp-button/resources/js/modules/ContextBootstrap/PayNowBootstrap.js +80 -0
- modules/ppcp-button/resources/js/modules/ContextBootstrap/SingleProductBootstap.js +65 -0
- modules/ppcp-button/resources/js/modules/DataClientIdAttributeHandler.js +52 -0
- modules/ppcp-button/resources/js/modules/Entity/Product.js +18 -0
- modules/ppcp-button/resources/js/modules/ErrorHandler.js +46 -0
- modules/ppcp-button/resources/js/modules/Helper/ButtonsToggleListener.js +36 -0
- modules/ppcp-button/resources/js/modules/Helper/DccInputFactory.js +14 -0
- modules/ppcp-button/resources/js/modules/Helper/PayerData.js +34 -0
- modules/ppcp-button/resources/js/modules/Helper/Spinner.js +23 -0
- modules/ppcp-button/resources/js/modules/Helper/UpdateCart.js +45 -0
- modules/ppcp-button/resources/js/modules/OnApproveHandler/onApproveForContinue.js +24 -0
- modules/ppcp-button/resources/js/modules/OnApproveHandler/onApproveForPayNow.js +31 -0
- modules/ppcp-button/resources/js/modules/Renderer/CreditCardRenderer.js +150 -0
- modules/ppcp-button/resources/js/modules/Renderer/MessageRenderer.js +49 -0
- modules/ppcp-button/resources/js/modules/Renderer/Renderer.js +48 -0
- modules/ppcp-button/services.php +163 -0
- modules/ppcp-button/src/Assets/class-disabledsmartbutton.php +44 -0
- modules/ppcp-button/src/Assets/class-smartbutton.php +912 -0
- modules/ppcp-button/src/Assets/class-smartbuttoninterface.php +37 -0
- modules/ppcp-button/src/Endpoint/class-approveorderendpoint.php +198 -0
- modules/ppcp-button/src/Endpoint/class-changecartendpoint.php +289 -0
- modules/ppcp-button/src/Endpoint/class-createorderendpoint.php +328 -0
- modules/ppcp-button/src/Endpoint/class-dataclientidendpoint.php +92 -0
- modules/ppcp-button/src/Endpoint/class-endpointinterface.php +30 -0
- modules/ppcp-button/src/Endpoint/class-requestdata.php +91 -0
- modules/ppcp-button/src/Exception/class-runtimeexception.php +18 -0
- modules/ppcp-button/src/Helper/class-earlyorderhandler.php +174 -0
- modules/ppcp-button/src/Helper/class-messagesapply.php +37 -0
- modules/ppcp-button/src/Helper/class-threedsecure.php +104 -0
- modules/ppcp-button/src/class-buttonmodule.php +162 -0
- modules/ppcp-onboarding/assets/css/onboarding.css +90 -0
- modules/ppcp-onboarding/assets/js/onboarding.js +212 -0
- modules/ppcp-onboarding/assets/js/settings.js +262 -0
- modules/ppcp-onboarding/extensions.php +12 -0
- modules/ppcp-onboarding/module.php +16 -0
- modules/ppcp-onboarding/services.php +210 -0
- modules/ppcp-onboarding/src/Assets/class-onboardingassets.php +130 -0
- modules/ppcp-onboarding/src/Endpoint/class-loginsellerendpoint.php +149 -0
- modules/ppcp-onboarding/src/Render/class-onboardingrenderer.php +112 -0
- modules/ppcp-onboarding/src/class-environment.php +60 -0
- modules/ppcp-onboarding/src/class-onboardingmodule.php +112 -0
- modules/ppcp-onboarding/src/class-state.php +145 -0
- modules/ppcp-session/extensions.php +12 -0
- modules/ppcp-session/module.php +16 -0
- modules/ppcp-session/services.php +39 -0
- modules/ppcp-session/src/Cancellation/class-cancelcontroller.php +74 -0
- modules/ppcp-session/src/Cancellation/class-cancelview.php +42 -0
- modules/ppcp-session/src/class-sessionhandler.php +126 -0
- modules/ppcp-session/src/class-sessionmodule.php +62 -0
- modules/ppcp-subscription/extensions.php +10 -0
- modules/ppcp-subscription/module.php +16 -0
- modules/ppcp-subscription/services.php +39 -0
- modules/ppcp-subscription/src/Helper/class-subscriptionhelper.php +86 -0
- modules/ppcp-subscription/src/Repository/class-paymenttokenrepository.php +102 -0
- modules/ppcp-subscription/src/class-renewalhandler.php +222 -0
- modules/ppcp-subscription/src/class-subscriptionmodule.php +62 -0
- modules/ppcp-wc-gateway/assets/images/amex.svg +10 -0
- modules/ppcp-wc-gateway/assets/images/blik.svg +25 -0
- modules/ppcp-wc-gateway/assets/images/credit.svg +33 -0
- modules/ppcp-wc-gateway/assets/images/discover.svg +46 -0
- modules/ppcp-wc-gateway/assets/images/elo.svg +1 -0
- modules/ppcp-wc-gateway/assets/images/giropay.svg +15 -0
- modules/ppcp-wc-gateway/assets/images/hiper.svg +18 -0
- modules/ppcp-wc-gateway/assets/images/ideal.svg +21 -0
- modules/ppcp-wc-gateway/assets/images/jcb.svg +9 -0
- modules/ppcp-wc-gateway/assets/images/mastercard.svg +16 -0
- modules/ppcp-wc-gateway/assets/images/mybank.svg +19 -0
- modules/ppcp-wc-gateway/assets/images/przelewy.svg +33 -0
- modules/ppcp-wc-gateway/assets/images/sofort.svg +13 -0
- modules/ppcp-wc-gateway/assets/images/visa.svg +19 -0
- modules/ppcp-wc-gateway/extensions.php +100 -0
- modules/ppcp-wc-gateway/module.php +16 -0
- modules/ppcp-wc-gateway/services.php +1837 -0
- modules/ppcp-wc-gateway/src/Admin/class-ordertablepaymentstatuscolumn.php +140 -0
- modules/ppcp-wc-gateway/src/Admin/class-paymentstatusorderdetail.php +50 -0
- modules/ppcp-wc-gateway/src/Admin/class-renderauthorizeaction.php +51 -0
- modules/ppcp-wc-gateway/src/Checkout/class-checkoutpaypaladdresspreset.php +152 -0
- modules/ppcp-wc-gateway/src/Checkout/class-disablegateways.php +129 -0
- modules/ppcp-wc-gateway/src/Endpoint/class-returnurlendpoint.php +94 -0
- modules/ppcp-wc-gateway/src/Exception/class-notfoundexception.php +21 -0
- modules/ppcp-wc-gateway/src/Gateway/class-creditcardgateway.php +253 -0
- modules/ppcp-wc-gateway/src/Gateway/class-paypalgateway.php +343 -0
- modules/ppcp-wc-gateway/src/Gateway/class-processpaymenttrait.php +82 -0
- modules/ppcp-wc-gateway/src/Gateway/class-wcgatewayinterface.php +18 -0
- modules/ppcp-wc-gateway/src/Helper/class-dccproductstatus.php +102 -0
- modules/ppcp-wc-gateway/src/Notice/class-authorizeorderactionnotice.php +110 -0
- modules/ppcp-wc-gateway/src/Notice/class-connectadminnotice.php +76 -0
- modules/ppcp-wc-gateway/src/Processor/class-authorizedpaymentsprocessor.php +182 -0
- modules/ppcp-wc-gateway/src/Processor/class-orderprocessor.php +275 -0
- modules/ppcp-wc-gateway/src/Processor/class-refundprocessor.php +99 -0
- modules/ppcp-wc-gateway/src/Settings/class-sectionsrenderer.php +59 -0
- modules/ppcp-wc-gateway/src/Settings/class-settings.php +112 -0
- modules/ppcp-wc-gateway/src/Settings/class-settingslistener.php +361 -0
- modules/ppcp-wc-gateway/src/Settings/class-settingsrenderer.php +477 -0
- modules/ppcp-wc-gateway/src/class-wcgatewaymodule.php +386 -0
- modules/ppcp-webhooks/extensions.php +12 -0
- modules/ppcp-webhooks/module.php +16 -0
- modules/ppcp-webhooks/services.php +58 -0
- modules/ppcp-webhooks/src/Handler/class-checkoutorderapproved.php +226 -0
- modules/ppcp-webhooks/src/Handler/class-checkoutordercompleted.php +166 -0
- modules/ppcp-webhooks/src/Handler/class-paymentcapturecompleted.php +141 -0
- modules/ppcp-webhooks/src/Handler/class-paymentcapturerefunded.php +156 -0
- modules/ppcp-webhooks/src/Handler/class-paymentcapturereversed.php +144 -0
- modules/ppcp-webhooks/src/Handler/class-prefixtrait.php +37 -0
- modules/ppcp-webhooks/src/Handler/class-requesthandler.php +41 -0
- modules/ppcp-webhooks/src/class-incomingwebhookendpoint.php +214 -0
- modules/ppcp-webhooks/src/class-webhookmodule.php +87 -0
- modules/ppcp-webhooks/src/class-webhookregistrar.php +116 -0
- modules/woocommerce-logging/extensions.php +13 -0
- modules/woocommerce-logging/module.php +16 -0
- modules/woocommerce-logging/services.php +33 -0
- modules/woocommerce-logging/src/Logger/class-nulllogger.php +33 -0
- modules/woocommerce-logging/src/Logger/class-woocommercelogger.php +64 -0
- modules/woocommerce-logging/src/class-woocommerceloggingmodule.php +50 -0
- readme.txt +62 -0
- src/README.md +3 -0
- src/class-pluginmodule.php +44 -0
- vendor/autoload.php +7 -0
- vendor/composer/ClassLoader.php +445 -0
- vendor/composer/LICENSE +21 -0
- vendor/composer/autoload_classmap.php +154 -0
- vendor/composer/autoload_namespaces.php +9 -0
- vendor/composer/autoload_psr4.php +21 -0
- vendor/composer/autoload_real.php +55 -0
- vendor/composer/autoload_static.php +247 -0
- vendor/composer/installed.json +781 -0
- vendor/composer/installers/LICENSE +19 -0
- vendor/composer/installers/composer.json +112 -0
- vendor/composer/installers/src/Composer/Installers/AglInstaller.php +21 -0
- vendor/composer/installers/src/Composer/Installers/AimeosInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/AnnotateCmsInstaller.php +11 -0
- vendor/composer/installers/src/Composer/Installers/AsgardInstaller.php +49 -0
- vendor/composer/installers/src/Composer/Installers/AttogramInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/BaseInstaller.php +137 -0
- vendor/composer/installers/src/Composer/Installers/BitrixInstaller.php +126 -0
- vendor/composer/installers/src/Composer/Installers/BonefishInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/CakePHPInstaller.php +72 -0
- vendor/composer/installers/src/Composer/Installers/ChefInstaller.php +11 -0
- vendor/composer/installers/src/Composer/Installers/CiviCrmInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/ClanCatsFrameworkInstaller.php +10 -0
- vendor/composer/installers/src/Composer/Installers/CockpitInstaller.php +34 -0
- vendor/composer/installers/src/Composer/Installers/CodeIgniterInstaller.php +11 -0
- vendor/composer/installers/src/Composer/Installers/Concrete5Installer.php +13 -0
- vendor/composer/installers/src/Composer/Installers/CraftInstaller.php +35 -0
- vendor/composer/installers/src/Composer/Installers/CroogoInstaller.php +21 -0
- vendor/composer/installers/src/Composer/Installers/DecibelInstaller.php +10 -0
- vendor/composer/installers/src/Composer/Installers/DframeInstaller.php +10 -0
- vendor/composer/installers/src/Composer/Installers/DokuWikiInstaller.php +50 -0
- vendor/composer/installers/src/Composer/Installers/DolibarrInstaller.php +16 -0
- vendor/composer/installers/src/Composer/Installers/DrupalInstaller.php +22 -0
- vendor/composer/installers/src/Composer/Installers/ElggInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/EliasisInstaller.php +12 -0
- vendor/composer/installers/src/Composer/Installers/ExpressionEngineInstaller.php +29 -0
- vendor/composer/installers/src/Composer/Installers/EzPlatformInstaller.php +10 -0
- vendor/composer/installers/src/Composer/Installers/FuelInstaller.php +11 -0
- vendor/composer/installers/src/Composer/Installers/FuelphpInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/GravInstaller.php +30 -0
- vendor/composer/installers/src/Composer/Installers/HuradInstaller.php +25 -0
- vendor/composer/installers/src/Composer/Installers/ImageCMSInstaller.php +11 -0
- vendor/composer/installers/src/Composer/Installers/Installer.php +280 -0
- vendor/composer/installers/src/Composer/Installers/ItopInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/JoomlaInstaller.php +15 -0
- vendor/composer/installers/src/Composer/Installers/KanboardInstaller.php +18 -0
- vendor/composer/installers/src/Composer/Installers/KirbyInstaller.php +11 -0
- vendor/composer/installers/src/Composer/Installers/KnownInstaller.php +11 -0
- vendor/composer/installers/src/Composer/Installers/KodiCMSInstaller.php +10 -0
- vendor/composer/installers/src/Composer/Installers/KohanaInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/LanManagementSystemInstaller.php +27 -0
- vendor/composer/installers/src/Composer/Installers/LaravelInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/LavaLiteInstaller.php +10 -0
- vendor/composer/installers/src/Composer/Installers/LithiumInstaller.php +10 -0
- vendor/composer/installers/src/Composer/Installers/MODULEWorkInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/MODXEvoInstaller.php +16 -0
- vendor/composer/installers/src/Composer/Installers/MagentoInstaller.php +11 -0
- vendor/composer/installers/src/Composer/Installers/MajimaInstaller.php +37 -0
- vendor/composer/installers/src/Composer/Installers/MakoInstaller.php +9 -0
- vendor/composer/installers/src/Composer/Installers/MantisBTInstaller.php +23 -0
- vendor/composer/installers/src/Composer/Installers/MauticInstaller.php +25 -0
- vendor/composer/installers/src/Composer/Installers/MayaInstaller.php +33 -0
- vendor/composer/installers/src/Composer/Installers/MediaWikiInstaller.php +51 -0
- vendor/composer/installers/src/Composer/Installers/MicroweberInstaller.php +119 -0
- vendor/composer/installers/src/Composer/Installers/ModxInstaller.php +12 -0
- vendor/composer/installers/src/Composer/Installers/MoodleInstaller.php +58 -0
- vendor/composer/installers/src/Composer/Installers/OctoberInstaller.php +2 -0
LICENSE
ADDED
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 2, June 1991
|
3 |
+
|
4 |
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
5 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
6 |
+
|
7 |
+
Everyone is permitted to copy and distribute verbatim copies
|
8 |
+
of this license document, but changing it is not allowed.
|
9 |
+
|
10 |
+
Preamble
|
11 |
+
|
12 |
+
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General
|
13 |
+
Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free
|
14 |
+
for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other
|
15 |
+
program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library
|
16 |
+
General Public License instead.) You can apply it to your programs, too.
|
17 |
+
|
18 |
+
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make
|
19 |
+
sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you
|
20 |
+
receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs;
|
21 |
+
and that you know you can do these things.
|
22 |
+
|
23 |
+
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender
|
24 |
+
the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if
|
25 |
+
you modify it.
|
26 |
+
|
27 |
+
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the
|
28 |
+
rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these
|
29 |
+
terms so they know their rights.
|
30 |
+
|
31 |
+
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal
|
32 |
+
permission to copy, distribute and/or modify the software.
|
33 |
+
|
34 |
+
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for
|
35 |
+
this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they
|
36 |
+
have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
|
37 |
+
|
38 |
+
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a
|
39 |
+
free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have
|
40 |
+
made it clear that any patent must be licensed for everyone's free use or not licensed at all.
|
41 |
+
|
42 |
+
The precise terms and conditions for copying, distribution and modification follow.
|
43 |
+
|
44 |
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
45 |
+
|
46 |
+
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be
|
47 |
+
distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a
|
48 |
+
"work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work
|
49 |
+
containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language.
|
50 |
+
(Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
|
51 |
+
|
52 |
+
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope.
|
53 |
+
The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute
|
54 |
+
a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what
|
55 |
+
the Program does.
|
56 |
+
|
57 |
+
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that
|
58 |
+
you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep
|
59 |
+
intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the
|
60 |
+
Program a copy of this License along with the Program.
|
61 |
+
|
62 |
+
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in
|
63 |
+
exchange for a fee.
|
64 |
+
|
65 |
+
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and
|
66 |
+
copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these
|
67 |
+
conditions:
|
68 |
+
|
69 |
+
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any
|
70 |
+
change.
|
71 |
+
|
72 |
+
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the
|
73 |
+
Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
|
74 |
+
|
75 |
+
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for
|
76 |
+
such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright
|
77 |
+
notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may
|
78 |
+
redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if
|
79 |
+
the Program itself is interactive but does not normally print such an announcement, your work based on the Program is
|
80 |
+
not required to print an announcement.)
|
81 |
+
|
82 |
+
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the
|
83 |
+
Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms,
|
84 |
+
do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as
|
85 |
+
part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License,
|
86 |
+
whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
|
87 |
+
|
88 |
+
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather,
|
89 |
+
the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
|
90 |
+
|
91 |
+
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the
|
92 |
+
Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
|
93 |
+
|
94 |
+
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under
|
95 |
+
the terms of Sections 1 and 2 above provided that you also do one of the following:
|
96 |
+
|
97 |
+
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms
|
98 |
+
of Sections 1 and 2 above on a medium customarily used for software interchange; or,
|
99 |
+
|
100 |
+
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than
|
101 |
+
your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source
|
102 |
+
code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange;
|
103 |
+
or,
|
104 |
+
|
105 |
+
c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This
|
106 |
+
alternative is allowed only for noncommercial distribution and only if you received the program in object code or
|
107 |
+
executable form with such an offer, in accord with Subsection b above.)
|
108 |
+
|
109 |
+
The source code for a work means the preferred form of the work for making modifications to it. For an executable work,
|
110 |
+
complete source code means all the source code for all modules it contains, plus any associated interface definition files,
|
111 |
+
plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source
|
112 |
+
code distributed need not include anything that is normally distributed (in either source or binary form) with the major
|
113 |
+
components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself
|
114 |
+
accompanies the executable.
|
115 |
+
|
116 |
+
If distribution of executable or object code is made by offering access to copy from a designated place, then offering
|
117 |
+
equivalent access to copy the source code from the same place counts as distribution of the source code, even though third
|
118 |
+
parties are not compelled to copy the source along with the object code.
|
119 |
+
|
120 |
+
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any
|
121 |
+
attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your
|
122 |
+
rights under this License. However, parties who have received copies, or rights, from you under this License will not have
|
123 |
+
their licenses terminated so long as such parties remain in full compliance.
|
124 |
+
|
125 |
+
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to
|
126 |
+
modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this
|
127 |
+
License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance
|
128 |
+
of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based
|
129 |
+
on it.
|
130 |
+
|
131 |
+
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license
|
132 |
+
from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not
|
133 |
+
impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for
|
134 |
+
enforcing compliance by third parties to this License.
|
135 |
+
|
136 |
+
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to
|
137 |
+
patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions
|
138 |
+
of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy
|
139 |
+
simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not
|
140 |
+
distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program
|
141 |
+
by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this
|
142 |
+
License would be to refrain entirely from distribution of the Program.
|
143 |
+
|
144 |
+
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the
|
145 |
+
section is intended to apply and the section as a whole is intended to apply in other circumstances.
|
146 |
+
|
147 |
+
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest
|
148 |
+
validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution
|
149 |
+
system, which is implemented by public license practices. Many people have made generous contributions to the wide range of
|
150 |
+
software distributed through that system in reliance on consistent application of that system; it is up to the author/donor
|
151 |
+
to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
|
152 |
+
|
153 |
+
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
|
154 |
+
|
155 |
+
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted
|
156 |
+
interfaces, the original copyright holder who places the Program under this License may add an explicit geographical
|
157 |
+
distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus
|
158 |
+
excluded. In such case, this License incorporates the limitation as if written in the body of this License.
|
159 |
+
|
160 |
+
9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time.
|
161 |
+
Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or
|
162 |
+
concerns.
|
163 |
+
|
164 |
+
Each version is given a distinguishing version number. If the Program specifies a version number of this License which
|
165 |
+
applies to it and "any later version", you have the option of following the terms and conditions either of that version or
|
166 |
+
of any later version published by the Free Software Foundation. If the Program does not specify a version number of this
|
167 |
+
License, you may choose any version ever published by the Free Software Foundation.
|
168 |
+
|
169 |
+
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different,
|
170 |
+
write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the
|
171 |
+
Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving
|
172 |
+
the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
|
173 |
+
|
174 |
+
NO WARRANTY
|
175 |
+
|
176 |
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
177 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS
|
178 |
+
IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
179 |
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS
|
180 |
+
ITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
181 |
+
|
182 |
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO
|
183 |
+
MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
|
184 |
+
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO
|
185 |
+
LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO
|
186 |
+
OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
187 |
+
|
188 |
+
END OF TERMS AND CONDITIONS
|
189 |
+
|
190 |
+
How to Apply These Terms to Your New Programs
|
191 |
+
|
192 |
+
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this
|
193 |
+
is to make it free software which everyone can redistribute and change under these terms.
|
194 |
+
|
195 |
+
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most
|
196 |
+
effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where
|
197 |
+
the full notice is found.
|
198 |
+
|
199 |
+
One line to give the program's name and a brief idea of what it does.
|
200 |
+
Copyright (C) <year> <name of author>
|
201 |
+
|
202 |
+
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
|
203 |
+
License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
|
204 |
+
version.
|
205 |
+
|
206 |
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
207 |
+
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
208 |
+
|
209 |
+
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
|
210 |
+
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
211 |
+
|
212 |
+
Also add information on how to contact you by electronic and paper mail.
|
213 |
+
|
214 |
+
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
|
215 |
+
|
216 |
+
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
|
217 |
+
type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for
|
218 |
+
details.
|
219 |
+
|
220 |
+
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course,
|
221 |
+
the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu
|
222 |
+
tems--whatever suits your program.
|
223 |
+
|
224 |
+
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for
|
225 |
+
the program, if necessary. Here is a sample; alter the names:
|
226 |
+
|
227 |
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers)
|
228 |
+
written by James Hacker.
|
229 |
+
|
230 |
+
signature of Ty Coon, 1 April 1989
|
231 |
+
Ty Coon, President of Vice
|
232 |
+
|
233 |
+
This General Public License does not permit incorporating your program into proprietary programs. If your program is a
|
234 |
+
subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is
|
235 |
+
what you want to do, use the GNU Library General Public License instead of this License.
|
changelog.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
*** Changelog ***
|
2 |
+
|
3 |
+
= 1.0.0 - 2020-10-15 =
|
4 |
+
* Initial release.
|
modules/ppcp-admin-notices/extensions.php
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The extensions of the admin notice module.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\Button
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
return array();
|
modules/ppcp-admin-notices/module.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The admin notice module.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\Button
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\AdminNotices;
|
11 |
+
|
12 |
+
use Dhii\Modular\Module\ModuleInterface;
|
13 |
+
|
14 |
+
return static function (): ModuleInterface {
|
15 |
+
return new AdminNotices();
|
16 |
+
};
|
modules/ppcp-admin-notices/services.php
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The services of the admin notice module.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\Button
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\AdminNotices;
|
11 |
+
|
12 |
+
use Dhii\Data\Container\ContainerInterface;
|
13 |
+
use WooCommerce\PayPalCommerce\AdminNotices\Renderer\Renderer;
|
14 |
+
use WooCommerce\PayPalCommerce\AdminNotices\Renderer\RendererInterface;
|
15 |
+
use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
|
16 |
+
use WooCommerce\PayPalCommerce\AdminNotices\Repository\RepositoryInterface;
|
17 |
+
|
18 |
+
return array(
|
19 |
+
'admin-notices.renderer' => static function ( $container ): RendererInterface {
|
20 |
+
|
21 |
+
$repository = $container->get( 'admin-notices.repository' );
|
22 |
+
return new Renderer( $repository );
|
23 |
+
},
|
24 |
+
'admin-notices.repository' => static function ( $container ): RepositoryInterface {
|
25 |
+
|
26 |
+
return new Repository();
|
27 |
+
},
|
28 |
+
);
|
modules/ppcp-admin-notices/src/Entity/class-message.php
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The message entity.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\AdminNotices\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\AdminNotices\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Message
|
14 |
+
*/
|
15 |
+
class Message {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The messagte text.
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
private $message;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The message type.
|
26 |
+
*
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
private $type;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Whether the message is dismissable.
|
33 |
+
*
|
34 |
+
* @var bool
|
35 |
+
*/
|
36 |
+
private $dismissable;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Message constructor.
|
40 |
+
*
|
41 |
+
* @param string $message The message text.
|
42 |
+
* @param string $type The message type.
|
43 |
+
* @param bool $dismissable Whether the message is dismissable.
|
44 |
+
*/
|
45 |
+
public function __construct( string $message, string $type, bool $dismissable = true ) {
|
46 |
+
$this->type = $type;
|
47 |
+
$this->message = $message;
|
48 |
+
$this->dismissable = $dismissable;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Returns the message text.
|
53 |
+
*
|
54 |
+
* @return string
|
55 |
+
*/
|
56 |
+
public function message(): string {
|
57 |
+
return $this->message;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Returns the message type.
|
62 |
+
*
|
63 |
+
* @return string
|
64 |
+
*/
|
65 |
+
public function type(): string {
|
66 |
+
return $this->type;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Returns whether the message is dismissable.
|
71 |
+
*
|
72 |
+
* @return bool
|
73 |
+
*/
|
74 |
+
public function is_dismissable(): bool {
|
75 |
+
return $this->dismissable;
|
76 |
+
}
|
77 |
+
}
|
modules/ppcp-admin-notices/src/Renderer/class-renderer.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The renderer.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\AdminNotices\Renderer
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\AdminNotices\Renderer;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\AdminNotices\Repository\RepositoryInterface;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class Renderer
|
16 |
+
*/
|
17 |
+
class Renderer implements RendererInterface {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* The message repository.
|
21 |
+
*
|
22 |
+
* @var RepositoryInterface
|
23 |
+
*/
|
24 |
+
private $repository;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Renderer constructor.
|
28 |
+
*
|
29 |
+
* @param RepositoryInterface $repository The message repository.
|
30 |
+
*/
|
31 |
+
public function __construct( RepositoryInterface $repository ) {
|
32 |
+
$this->repository = $repository;
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Renders the current messages.
|
37 |
+
*
|
38 |
+
* @return bool
|
39 |
+
*/
|
40 |
+
public function render(): bool {
|
41 |
+
$messages = $this->repository->current_message();
|
42 |
+
foreach ( $messages as $message ) {
|
43 |
+
printf(
|
44 |
+
'<div class="notice notice-%s %s"><p>%s</p></div>',
|
45 |
+
$message->type(),
|
46 |
+
( $message->is_dismissable() ) ? 'is-dismissible' : '',
|
47 |
+
wp_kses_post( $message->message() )
|
48 |
+
);
|
49 |
+
}
|
50 |
+
|
51 |
+
return (bool) count( $messages );
|
52 |
+
}
|
53 |
+
}
|
modules/ppcp-admin-notices/src/Renderer/class-rendererinterface.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The renderer interface.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\AdminNotices\Renderer
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\AdminNotices\Renderer;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Interface RendererInterface
|
14 |
+
*/
|
15 |
+
interface RendererInterface {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Renders the messages.
|
19 |
+
*
|
20 |
+
* @return bool
|
21 |
+
*/
|
22 |
+
public function render(): bool;
|
23 |
+
}
|
modules/ppcp-admin-notices/src/Repository/class-repository.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The message repository.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\AdminNotices\Repository
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\AdminNotices\Repository;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class Repository
|
16 |
+
*/
|
17 |
+
class Repository implements RepositoryInterface {
|
18 |
+
|
19 |
+
const NOTICES_FILTER = 'ppcp.admin-notices.current-notices';
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Returns the current messages.
|
23 |
+
*
|
24 |
+
* @return Message[]
|
25 |
+
*/
|
26 |
+
public function current_message(): array {
|
27 |
+
return array_filter(
|
28 |
+
(array) apply_filters(
|
29 |
+
self::NOTICES_FILTER,
|
30 |
+
array()
|
31 |
+
),
|
32 |
+
function( $element ) : bool {
|
33 |
+
return is_a( $element, Message::class );
|
34 |
+
}
|
35 |
+
);
|
36 |
+
}
|
37 |
+
}
|
modules/ppcp-admin-notices/src/Repository/class-repositoryinterface.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The repository interface.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\AdminNotices\Repository
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\AdminNotices\Repository;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Interface RepositoryInterface
|
16 |
+
*/
|
17 |
+
interface RepositoryInterface {
|
18 |
+
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Returns the current messages.
|
22 |
+
*
|
23 |
+
* @return Message[]
|
24 |
+
*/
|
25 |
+
public function current_message(): array;
|
26 |
+
}
|
modules/ppcp-admin-notices/src/class-adminnotices.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The admin notice module.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\Button
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\AdminNotices;
|
11 |
+
|
12 |
+
use Dhii\Container\ServiceProvider;
|
13 |
+
use Dhii\Modular\Module\ModuleInterface;
|
14 |
+
use Interop\Container\ServiceProviderInterface;
|
15 |
+
use Psr\Container\ContainerInterface;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Class AdminNotices
|
19 |
+
*/
|
20 |
+
class AdminNotices implements ModuleInterface {
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Sets up the module.
|
24 |
+
*
|
25 |
+
* @return ServiceProviderInterface
|
26 |
+
*/
|
27 |
+
public function setup(): ServiceProviderInterface {
|
28 |
+
return new ServiceProvider(
|
29 |
+
require __DIR__ . '/../services.php',
|
30 |
+
require __DIR__ . '/../extensions.php'
|
31 |
+
);
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Runs the module.
|
36 |
+
*
|
37 |
+
* @param ContainerInterface $container The container.
|
38 |
+
*/
|
39 |
+
public function run( ContainerInterface $container = null ) {
|
40 |
+
add_action(
|
41 |
+
'admin_notices',
|
42 |
+
function() use ( $container ) {
|
43 |
+
$renderer = $container->get( 'admin-notices.renderer' );
|
44 |
+
$renderer->render();
|
45 |
+
}
|
46 |
+
);
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Returns the key for the module.
|
51 |
+
*
|
52 |
+
* @return string|void
|
53 |
+
*/
|
54 |
+
public function getKey() {
|
55 |
+
}
|
56 |
+
}
|
modules/ppcp-api-client/extensions.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The extensions of the api client module.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient;
|
11 |
+
|
12 |
+
return array();
|
modules/ppcp-api-client/module.php
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The api client module.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient;
|
11 |
+
|
12 |
+
use Dhii\Modular\Module\ModuleInterface;
|
13 |
+
|
14 |
+
return function (): ModuleInterface {
|
15 |
+
return new ApiModule();
|
16 |
+
};
|
modules/ppcp-api-client/services.php
ADDED
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The services of the API client.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
13 |
+
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
14 |
+
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\IdentityToken;
|
15 |
+
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\LoginSeller;
|
16 |
+
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
17 |
+
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnerReferrals;
|
18 |
+
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
19 |
+
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
|
20 |
+
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokenEndpoint;
|
21 |
+
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\WebhookEndpoint;
|
22 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\AddressFactory;
|
23 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\AmountFactory;
|
24 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\ApplicationContextFactory;
|
25 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\AuthorizationFactory;
|
26 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\CaptureFactory;
|
27 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\ItemFactory;
|
28 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
|
29 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\PatchCollectionFactory;
|
30 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayeeFactory;
|
31 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
32 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentsFactory;
|
33 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentSourceFactory;
|
34 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentTokenFactory;
|
35 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
36 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\SellerStatusFactory;
|
37 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingFactory;
|
38 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory;
|
39 |
+
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
40 |
+
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
41 |
+
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
|
42 |
+
use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
|
43 |
+
use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
|
44 |
+
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayeeRepository;
|
45 |
+
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
|
46 |
+
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
47 |
+
|
48 |
+
return array(
|
49 |
+
'api.host' => function( $container ) : string {
|
50 |
+
return PAYPAL_API_URL;
|
51 |
+
},
|
52 |
+
'api.paypal-host' => function( $container ) : string {
|
53 |
+
return PAYPAL_API_URL;
|
54 |
+
},
|
55 |
+
'api.partner_merchant_id' => static function () : string {
|
56 |
+
return '';
|
57 |
+
},
|
58 |
+
'api.merchant_email' => function () : string {
|
59 |
+
return '';
|
60 |
+
},
|
61 |
+
'api.merchant_id' => function () : string {
|
62 |
+
return '';
|
63 |
+
},
|
64 |
+
'api.key' => static function (): string {
|
65 |
+
return '';
|
66 |
+
},
|
67 |
+
'api.secret' => static function (): string {
|
68 |
+
return '';
|
69 |
+
},
|
70 |
+
'api.prefix' => static function (): string {
|
71 |
+
return 'WC-';
|
72 |
+
},
|
73 |
+
'api.bearer' => static function ( $container ): Bearer {
|
74 |
+
|
75 |
+
$cache = new Cache( 'ppcp-paypal-bearer' );
|
76 |
+
$key = $container->get( 'api.key' );
|
77 |
+
$secret = $container->get( 'api.secret' );
|
78 |
+
|
79 |
+
$host = $container->get( 'api.host' );
|
80 |
+
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
81 |
+
return new PayPalBearer(
|
82 |
+
$cache,
|
83 |
+
$host,
|
84 |
+
$key,
|
85 |
+
$secret,
|
86 |
+
$logger
|
87 |
+
);
|
88 |
+
},
|
89 |
+
'api.endpoint.partners' => static function ( $container ) : PartnersEndpoint {
|
90 |
+
return new PartnersEndpoint(
|
91 |
+
$container->get( 'api.host' ),
|
92 |
+
$container->get( 'api.bearer' ),
|
93 |
+
$container->get( 'woocommerce.logger.woocommerce' ),
|
94 |
+
$container->get( 'api.factory.sellerstatus' ),
|
95 |
+
$container->get( 'api.partner_merchant_id' ),
|
96 |
+
$container->get( 'api.merchant_id' )
|
97 |
+
);
|
98 |
+
},
|
99 |
+
'api.factory.sellerstatus' => static function ( $container ) : SellerStatusFactory {
|
100 |
+
return new SellerStatusFactory();
|
101 |
+
},
|
102 |
+
'api.endpoint.payment-token' => static function ( $container ) : PaymentTokenEndpoint {
|
103 |
+
return new PaymentTokenEndpoint(
|
104 |
+
$container->get( 'api.host' ),
|
105 |
+
$container->get( 'api.bearer' ),
|
106 |
+
$container->get( 'api.factory.payment-token' ),
|
107 |
+
$container->get( 'woocommerce.logger.woocommerce' ),
|
108 |
+
$container->get( 'api.prefix' )
|
109 |
+
);
|
110 |
+
},
|
111 |
+
'api.endpoint.webhook' => static function ( $container ) : WebhookEndpoint {
|
112 |
+
|
113 |
+
return new WebhookEndpoint(
|
114 |
+
$container->get( 'api.host' ),
|
115 |
+
$container->get( 'api.bearer' ),
|
116 |
+
$container->get( 'api.factory.webhook' ),
|
117 |
+
$container->get( 'woocommerce.logger.woocommerce' )
|
118 |
+
);
|
119 |
+
},
|
120 |
+
'api.endpoint.partner-referrals' => static function ( $container ) : PartnerReferrals {
|
121 |
+
|
122 |
+
return new PartnerReferrals(
|
123 |
+
$container->get( 'api.host' ),
|
124 |
+
$container->get( 'api.bearer' ),
|
125 |
+
$container->get( 'api.repository.partner-referrals-data' ),
|
126 |
+
$container->get( 'woocommerce.logger.woocommerce' )
|
127 |
+
);
|
128 |
+
},
|
129 |
+
'api.endpoint.identity-token' => static function ( $container ) : IdentityToken {
|
130 |
+
|
131 |
+
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
132 |
+
$prefix = $container->get( 'api.prefix' );
|
133 |
+
return new IdentityToken(
|
134 |
+
$container->get( 'api.host' ),
|
135 |
+
$container->get( 'api.bearer' ),
|
136 |
+
$logger,
|
137 |
+
$prefix
|
138 |
+
);
|
139 |
+
},
|
140 |
+
'api.endpoint.payments' => static function ( $container ): PaymentsEndpoint {
|
141 |
+
$authorizations_factory = $container->get( 'api.factory.authorization' );
|
142 |
+
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
143 |
+
|
144 |
+
return new PaymentsEndpoint(
|
145 |
+
$container->get( 'api.host' ),
|
146 |
+
$container->get( 'api.bearer' ),
|
147 |
+
$authorizations_factory,
|
148 |
+
$logger
|
149 |
+
);
|
150 |
+
},
|
151 |
+
'api.endpoint.login-seller' => static function ( $container ) : LoginSeller {
|
152 |
+
|
153 |
+
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
154 |
+
return new LoginSeller(
|
155 |
+
$container->get( 'api.paypal-host' ),
|
156 |
+
$container->get( 'api.partner_merchant_id' ),
|
157 |
+
$logger
|
158 |
+
);
|
159 |
+
},
|
160 |
+
'api.endpoint.order' => static function ( $container ): OrderEndpoint {
|
161 |
+
$order_factory = $container->get( 'api.factory.order' );
|
162 |
+
$patch_collection_factory = $container->get( 'api.factory.patch-collection-factory' );
|
163 |
+
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
164 |
+
|
165 |
+
/**
|
166 |
+
* The settings.
|
167 |
+
*
|
168 |
+
* @var Settings $settings
|
169 |
+
*/
|
170 |
+
$settings = $container->get( 'wcgateway.settings' );
|
171 |
+
$intent = $settings->has( 'intent' ) && strtoupper( (string) $settings->get( 'intent' ) ) === 'AUTHORIZE' ? 'AUTHORIZE' : 'CAPTURE';
|
172 |
+
$application_context_repository = $container->get( 'api.repository.application-context' );
|
173 |
+
$paypal_request_id = $container->get( 'api.repository.paypal-request-id' );
|
174 |
+
return new OrderEndpoint(
|
175 |
+
$container->get( 'api.host' ),
|
176 |
+
$container->get( 'api.bearer' ),
|
177 |
+
$order_factory,
|
178 |
+
$patch_collection_factory,
|
179 |
+
$intent,
|
180 |
+
$logger,
|
181 |
+
$application_context_repository,
|
182 |
+
$paypal_request_id
|
183 |
+
);
|
184 |
+
},
|
185 |
+
'api.repository.paypal-request-id' => static function( $container ) : PayPalRequestIdRepository {
|
186 |
+
return new PayPalRequestIdRepository();
|
187 |
+
},
|
188 |
+
'api.repository.application-context' => static function( $container ) : ApplicationContextRepository {
|
189 |
+
|
190 |
+
$settings = $container->get( 'wcgateway.settings' );
|
191 |
+
return new ApplicationContextRepository( $settings );
|
192 |
+
},
|
193 |
+
'api.repository.partner-referrals-data' => static function ( $container ) : PartnerReferralsData {
|
194 |
+
|
195 |
+
$merchant_email = $container->get( 'api.merchant_email' );
|
196 |
+
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
197 |
+
return new PartnerReferralsData( $merchant_email, $dcc_applies );
|
198 |
+
},
|
199 |
+
'api.repository.cart' => static function ( $container ): CartRepository {
|
200 |
+
$factory = $container->get( 'api.factory.purchase-unit' );
|
201 |
+
return new CartRepository( $factory );
|
202 |
+
},
|
203 |
+
'api.repository.payee' => static function ( $container ): PayeeRepository {
|
204 |
+
$merchant_email = $container->get( 'api.merchant_email' );
|
205 |
+
$merchant_id = $container->get( 'api.merchant_id' );
|
206 |
+
return new PayeeRepository( $merchant_email, $merchant_id );
|
207 |
+
},
|
208 |
+
'api.factory.application-context' => static function ( $container ) : ApplicationContextFactory {
|
209 |
+
return new ApplicationContextFactory();
|
210 |
+
},
|
211 |
+
'api.factory.payment-token' => static function ( $container ) : PaymentTokenFactory {
|
212 |
+
return new PaymentTokenFactory();
|
213 |
+
},
|
214 |
+
'api.factory.webhook' => static function ( $container ): WebhookFactory {
|
215 |
+
return new WebhookFactory();
|
216 |
+
},
|
217 |
+
'api.factory.capture' => static function ( $container ): CaptureFactory {
|
218 |
+
|
219 |
+
$amount_factory = $container->get( 'api.factory.amount' );
|
220 |
+
return new CaptureFactory( $amount_factory );
|
221 |
+
},
|
222 |
+
'api.factory.purchase-unit' => static function ( $container ): PurchaseUnitFactory {
|
223 |
+
|
224 |
+
$amount_factory = $container->get( 'api.factory.amount' );
|
225 |
+
$payee_repository = $container->get( 'api.repository.payee' );
|
226 |
+
$payee_factory = $container->get( 'api.factory.payee' );
|
227 |
+
$item_factory = $container->get( 'api.factory.item' );
|
228 |
+
$shipping_factory = $container->get( 'api.factory.shipping' );
|
229 |
+
$payments_factory = $container->get( 'api.factory.payments' );
|
230 |
+
$prefix = $container->get( 'api.prefix' );
|
231 |
+
|
232 |
+
return new PurchaseUnitFactory(
|
233 |
+
$amount_factory,
|
234 |
+
$payee_repository,
|
235 |
+
$payee_factory,
|
236 |
+
$item_factory,
|
237 |
+
$shipping_factory,
|
238 |
+
$payments_factory,
|
239 |
+
$prefix
|
240 |
+
);
|
241 |
+
},
|
242 |
+
'api.factory.patch-collection-factory' => static function ( $container ): PatchCollectionFactory {
|
243 |
+
return new PatchCollectionFactory();
|
244 |
+
},
|
245 |
+
'api.factory.payee' => static function ( $container ): PayeeFactory {
|
246 |
+
return new PayeeFactory();
|
247 |
+
},
|
248 |
+
'api.factory.item' => static function ( $container ): ItemFactory {
|
249 |
+
return new ItemFactory();
|
250 |
+
},
|
251 |
+
'api.factory.shipping' => static function ( $container ): ShippingFactory {
|
252 |
+
$address_factory = $container->get( 'api.factory.address' );
|
253 |
+
return new ShippingFactory( $address_factory );
|
254 |
+
},
|
255 |
+
'api.factory.amount' => static function ( $container ): AmountFactory {
|
256 |
+
$item_factory = $container->get( 'api.factory.item' );
|
257 |
+
return new AmountFactory( $item_factory );
|
258 |
+
},
|
259 |
+
'api.factory.payer' => static function ( $container ): PayerFactory {
|
260 |
+
$address_factory = $container->get( 'api.factory.address' );
|
261 |
+
return new PayerFactory( $address_factory );
|
262 |
+
},
|
263 |
+
'api.factory.address' => static function ( $container ): AddressFactory {
|
264 |
+
return new AddressFactory();
|
265 |
+
},
|
266 |
+
'api.factory.payment-source' => static function ( $container ): PaymentSourceFactory {
|
267 |
+
return new PaymentSourceFactory();
|
268 |
+
},
|
269 |
+
'api.factory.order' => static function ( $container ): OrderFactory {
|
270 |
+
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
|
271 |
+
$payer_factory = $container->get( 'api.factory.payer' );
|
272 |
+
$application_context_repository = $container->get( 'api.repository.application-context' );
|
273 |
+
$application_context_factory = $container->get( 'api.factory.application-context' );
|
274 |
+
$payment_source_factory = $container->get( 'api.factory.payment-source' );
|
275 |
+
return new OrderFactory(
|
276 |
+
$purchase_unit_factory,
|
277 |
+
$payer_factory,
|
278 |
+
$application_context_repository,
|
279 |
+
$application_context_factory,
|
280 |
+
$payment_source_factory
|
281 |
+
);
|
282 |
+
},
|
283 |
+
'api.factory.payments' => static function ( $container ): PaymentsFactory {
|
284 |
+
$authorizations_factory = $container->get( 'api.factory.authorization' );
|
285 |
+
$capture_factory = $container->get( 'api.factory.capture' );
|
286 |
+
return new PaymentsFactory( $authorizations_factory, $capture_factory );
|
287 |
+
},
|
288 |
+
'api.factory.authorization' => static function ( $container ): AuthorizationFactory {
|
289 |
+
return new AuthorizationFactory();
|
290 |
+
},
|
291 |
+
'api.helpers.dccapplies' => static function ( $container ) : DccApplies {
|
292 |
+
return new DccApplies();
|
293 |
+
},
|
294 |
+
);
|
modules/ppcp-api-client/src/Authentication/class-bearer.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The bearer interface.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Authentication
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Authentication;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\Token;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Interface Bearer
|
16 |
+
*/
|
17 |
+
interface Bearer {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Returns the bearer.
|
21 |
+
*
|
22 |
+
* @return Token
|
23 |
+
*/
|
24 |
+
public function bearer(): Token;
|
25 |
+
}
|
modules/ppcp-api-client/src/Authentication/class-connectbearer.php
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The connect dummy bearer.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Authentication
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Authentication;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\Token;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class ConnectBearer
|
16 |
+
*/
|
17 |
+
class ConnectBearer implements Bearer {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Returns the bearer.
|
21 |
+
*
|
22 |
+
* @return Token
|
23 |
+
*/
|
24 |
+
public function bearer(): Token {
|
25 |
+
$data = (object) array(
|
26 |
+
'created' => time(),
|
27 |
+
'expires_in' => 3600,
|
28 |
+
'token' => 'token',
|
29 |
+
);
|
30 |
+
return new Token( $data );
|
31 |
+
}
|
32 |
+
}
|
modules/ppcp-api-client/src/Authentication/class-paypalbearer.php
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PayPal bearer.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Authentication
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Authentication;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\RequestTrait;
|
13 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\Token;
|
14 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
15 |
+
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
16 |
+
use Psr\Log\LoggerInterface;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Class PayPalBearer
|
20 |
+
*/
|
21 |
+
class PayPalBearer implements Bearer {
|
22 |
+
|
23 |
+
use RequestTrait;
|
24 |
+
|
25 |
+
const CACHE_KEY = 'ppcp-bearer';
|
26 |
+
|
27 |
+
/**
|
28 |
+
* The cache.
|
29 |
+
*
|
30 |
+
* @var Cache
|
31 |
+
*/
|
32 |
+
private $cache;
|
33 |
+
|
34 |
+
/**
|
35 |
+
* The host.
|
36 |
+
*
|
37 |
+
* @var string
|
38 |
+
*/
|
39 |
+
private $host;
|
40 |
+
|
41 |
+
/**
|
42 |
+
* The client key.
|
43 |
+
*
|
44 |
+
* @var string
|
45 |
+
*/
|
46 |
+
private $key;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* The client secret.
|
50 |
+
*
|
51 |
+
* @var string
|
52 |
+
*/
|
53 |
+
private $secret;
|
54 |
+
|
55 |
+
/**
|
56 |
+
* The logger.
|
57 |
+
*
|
58 |
+
* @var LoggerInterface
|
59 |
+
*/
|
60 |
+
private $logger;
|
61 |
+
|
62 |
+
/**
|
63 |
+
* PayPalBearer constructor.
|
64 |
+
*
|
65 |
+
* @param Cache $cache The cache.
|
66 |
+
* @param string $host The host.
|
67 |
+
* @param string $key The key.
|
68 |
+
* @param string $secret The secret.
|
69 |
+
* @param LoggerInterface $logger The logger.
|
70 |
+
*/
|
71 |
+
public function __construct(
|
72 |
+
Cache $cache,
|
73 |
+
string $host,
|
74 |
+
string $key,
|
75 |
+
string $secret,
|
76 |
+
LoggerInterface $logger
|
77 |
+
) {
|
78 |
+
|
79 |
+
$this->cache = $cache;
|
80 |
+
$this->host = $host;
|
81 |
+
$this->key = $key;
|
82 |
+
$this->secret = $secret;
|
83 |
+
$this->logger = $logger;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Returns a bearer token.
|
88 |
+
*
|
89 |
+
* @return Token
|
90 |
+
* @throws RuntimeException When request fails.
|
91 |
+
*/
|
92 |
+
public function bearer(): Token {
|
93 |
+
try {
|
94 |
+
$bearer = Token::from_json( (string) $this->cache->get( self::CACHE_KEY ) );
|
95 |
+
return ( $bearer->is_valid() ) ? $bearer : $this->newBearer();
|
96 |
+
} catch ( RuntimeException $error ) {
|
97 |
+
return $this->newBearer();
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Creates a new bearer token.
|
103 |
+
*
|
104 |
+
* @return Token
|
105 |
+
* @throws RuntimeException When request fails.
|
106 |
+
*/
|
107 |
+
private function newBearer(): Token {
|
108 |
+
$url = trailingslashit( $this->host ) . 'v1/oauth2/token?grant_type=client_credentials';
|
109 |
+
$args = array(
|
110 |
+
'method' => 'POST',
|
111 |
+
'headers' => array(
|
112 |
+
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
113 |
+
'Authorization' => 'Basic ' . base64_encode( $this->key . ':' . $this->secret ),
|
114 |
+
),
|
115 |
+
);
|
116 |
+
$response = $this->request(
|
117 |
+
$url,
|
118 |
+
$args
|
119 |
+
);
|
120 |
+
|
121 |
+
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
|
122 |
+
$error = new RuntimeException(
|
123 |
+
__( 'Could not create token.', 'woocommerce-paypal-payments' )
|
124 |
+
);
|
125 |
+
$this->logger->log(
|
126 |
+
'warning',
|
127 |
+
$error->getMessage(),
|
128 |
+
array(
|
129 |
+
'args' => $args,
|
130 |
+
'response' => $response,
|
131 |
+
)
|
132 |
+
);
|
133 |
+
throw $error;
|
134 |
+
}
|
135 |
+
|
136 |
+
$token = Token::from_json( $response['body'] );
|
137 |
+
$this->cache->set( self::CACHE_KEY, $token->as_json() );
|
138 |
+
return $token;
|
139 |
+
}
|
140 |
+
}
|
modules/ppcp-api-client/src/Endpoint/class-identitytoken.php
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Fetches identity tokens.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
13 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\Token;
|
14 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
15 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
16 |
+
use Psr\Log\LoggerInterface;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Class IdentityToken
|
20 |
+
*/
|
21 |
+
class IdentityToken {
|
22 |
+
|
23 |
+
use RequestTrait;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* The Bearer.
|
27 |
+
*
|
28 |
+
* @var Bearer
|
29 |
+
*/
|
30 |
+
private $bearer;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* The host.
|
34 |
+
*
|
35 |
+
* @var string
|
36 |
+
*/
|
37 |
+
private $host;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* The logger.
|
41 |
+
*
|
42 |
+
* @var LoggerInterface
|
43 |
+
*/
|
44 |
+
private $logger;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* The prefix.
|
48 |
+
*
|
49 |
+
* @var string
|
50 |
+
*/
|
51 |
+
private $prefix;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* IdentityToken constructor.
|
55 |
+
*
|
56 |
+
* @param string $host The host.
|
57 |
+
* @param Bearer $bearer The bearer.
|
58 |
+
* @param LoggerInterface $logger The logger.
|
59 |
+
* @param string $prefix The prefix.
|
60 |
+
*/
|
61 |
+
public function __construct( string $host, Bearer $bearer, LoggerInterface $logger, string $prefix ) {
|
62 |
+
$this->host = $host;
|
63 |
+
$this->bearer = $bearer;
|
64 |
+
$this->logger = $logger;
|
65 |
+
$this->prefix = $prefix;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Generates a token for a specific customer.
|
70 |
+
*
|
71 |
+
* @param int $customer_id The id of the customer.
|
72 |
+
*
|
73 |
+
* @return Token
|
74 |
+
* @throws RuntimeException If the request fails.
|
75 |
+
*/
|
76 |
+
public function generate_for_customer( int $customer_id ): Token {
|
77 |
+
|
78 |
+
$bearer = $this->bearer->bearer();
|
79 |
+
$url = trailingslashit( $this->host ) . 'v1/identity/generate-token';
|
80 |
+
$args = array(
|
81 |
+
'method' => 'POST',
|
82 |
+
'headers' => array(
|
83 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
84 |
+
'Content-Type' => 'application/json',
|
85 |
+
),
|
86 |
+
);
|
87 |
+
if ( $customer_id && defined( 'PPCP_FLAG_SUBSCRIPTION' ) && PPCP_FLAG_SUBSCRIPTION ) {
|
88 |
+
$args['body'] = wp_json_encode( array( 'customer_id' => $this->prefix . $customer_id ) );
|
89 |
+
}
|
90 |
+
|
91 |
+
$response = $this->request( $url, $args );
|
92 |
+
|
93 |
+
if ( is_wp_error( $response ) ) {
|
94 |
+
$error = new RuntimeException(
|
95 |
+
__(
|
96 |
+
'Could not create identity token.',
|
97 |
+
'woocommerce-paypal-payments'
|
98 |
+
)
|
99 |
+
);
|
100 |
+
|
101 |
+
$this->logger->log(
|
102 |
+
'warning',
|
103 |
+
$error->getMessage(),
|
104 |
+
array(
|
105 |
+
'args' => $args,
|
106 |
+
'response' => $response,
|
107 |
+
)
|
108 |
+
);
|
109 |
+
throw $error;
|
110 |
+
}
|
111 |
+
|
112 |
+
$json = json_decode( $response['body'] );
|
113 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
114 |
+
if ( 200 !== $status_code ) {
|
115 |
+
$error = new PayPalApiException(
|
116 |
+
$json,
|
117 |
+
$status_code
|
118 |
+
);
|
119 |
+
$this->logger->log(
|
120 |
+
'warning',
|
121 |
+
$error->getMessage(),
|
122 |
+
array(
|
123 |
+
'args' => $args,
|
124 |
+
'response' => $response,
|
125 |
+
)
|
126 |
+
);
|
127 |
+
throw $error;
|
128 |
+
}
|
129 |
+
|
130 |
+
$token = Token::from_json( $response['body'] );
|
131 |
+
return $token;
|
132 |
+
}
|
133 |
+
}
|
modules/ppcp-api-client/src/Endpoint/class-loginseller.php
ADDED
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Fetches credentials for an instance.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
13 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
14 |
+
use Psr\Log\LoggerInterface;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Class LoginSeller
|
18 |
+
*/
|
19 |
+
class LoginSeller {
|
20 |
+
|
21 |
+
use RequestTrait;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* The host.
|
25 |
+
*
|
26 |
+
* @var string
|
27 |
+
*/
|
28 |
+
private $host;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* The partner merchant id.
|
32 |
+
*
|
33 |
+
* @var string
|
34 |
+
*/
|
35 |
+
private $partner_merchant_id;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* The logger.
|
39 |
+
*
|
40 |
+
* @var LoggerInterface
|
41 |
+
*/
|
42 |
+
private $logger;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* LoginSeller constructor.
|
46 |
+
*
|
47 |
+
* @param string $host The host.
|
48 |
+
* @param string $partner_marchant_id The partner merchant id.
|
49 |
+
* @param LoggerInterface $logger The logger.
|
50 |
+
*/
|
51 |
+
public function __construct(
|
52 |
+
string $host,
|
53 |
+
string $partner_marchant_id,
|
54 |
+
LoggerInterface $logger
|
55 |
+
) {
|
56 |
+
|
57 |
+
$this->host = $host;
|
58 |
+
$this->partner_merchant_id = $partner_marchant_id;
|
59 |
+
$this->logger = $logger;
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Fetches credentials for a shared id, auth code and seller nonce.
|
64 |
+
*
|
65 |
+
* @param string $shared_id The shared id.
|
66 |
+
* @param string $auth_code The auth code.
|
67 |
+
* @param string $seller_nonce The seller nonce.
|
68 |
+
*
|
69 |
+
* @return \stdClass
|
70 |
+
* @throws RuntimeException If the request fails.
|
71 |
+
*/
|
72 |
+
public function credentials_for(
|
73 |
+
string $shared_id,
|
74 |
+
string $auth_code,
|
75 |
+
string $seller_nonce
|
76 |
+
): \stdClass {
|
77 |
+
|
78 |
+
$token = $this->generate_token_for( $shared_id, $auth_code, $seller_nonce );
|
79 |
+
$url = trailingslashit( $this->host ) .
|
80 |
+
'v1/customer/partners/' . $this->partner_merchant_id .
|
81 |
+
'/merchant-integrations/credentials/';
|
82 |
+
$args = array(
|
83 |
+
'method' => 'GET',
|
84 |
+
'headers' => array(
|
85 |
+
'Authorization' => 'Bearer ' . $token,
|
86 |
+
'Content-Type' => 'application/json',
|
87 |
+
),
|
88 |
+
);
|
89 |
+
$response = $this->request( $url, $args );
|
90 |
+
if ( is_wp_error( $response ) ) {
|
91 |
+
$error = new RuntimeException(
|
92 |
+
__( 'Could not fetch credentials.', 'woocommerce-paypal-payments' )
|
93 |
+
);
|
94 |
+
$this->logger->log(
|
95 |
+
'warning',
|
96 |
+
$error->getMessage(),
|
97 |
+
array(
|
98 |
+
'args' => $args,
|
99 |
+
'response' => $response,
|
100 |
+
)
|
101 |
+
);
|
102 |
+
throw $error;
|
103 |
+
}
|
104 |
+
$json = json_decode( $response['body'] );
|
105 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
106 |
+
if ( ! isset( $json->client_id ) || ! isset( $json->client_secret ) ) {
|
107 |
+
$error = isset( $json->details ) ?
|
108 |
+
new PayPalApiException(
|
109 |
+
$json,
|
110 |
+
$status_code
|
111 |
+
) : new RuntimeException(
|
112 |
+
__( 'Credentials not found.', 'woocommerce-paypal-payments' )
|
113 |
+
);
|
114 |
+
$this->logger->log(
|
115 |
+
'warning',
|
116 |
+
$error->getMessage(),
|
117 |
+
array(
|
118 |
+
'args' => $args,
|
119 |
+
'response' => $response,
|
120 |
+
)
|
121 |
+
);
|
122 |
+
throw $error;
|
123 |
+
}
|
124 |
+
|
125 |
+
return $json;
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Generates a token for a shared id and auth token and seller nonce.
|
130 |
+
*
|
131 |
+
* @param string $shared_id The shared id.
|
132 |
+
* @param string $auth_code The auth code.
|
133 |
+
* @param string $seller_nonce The seller nonce.
|
134 |
+
*
|
135 |
+
* @return string
|
136 |
+
* @throws RuntimeException If the request fails.
|
137 |
+
*/
|
138 |
+
private function generate_token_for(
|
139 |
+
string $shared_id,
|
140 |
+
string $auth_code,
|
141 |
+
string $seller_nonce
|
142 |
+
): string {
|
143 |
+
|
144 |
+
$url = trailingslashit( $this->host ) . 'v1/oauth2/token/';
|
145 |
+
$args = array(
|
146 |
+
'method' => 'POST',
|
147 |
+
'headers' => array(
|
148 |
+
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
|
149 |
+
'Authorization' => 'Basic ' . base64_encode( $shared_id . ':' ),
|
150 |
+
),
|
151 |
+
'body' => array(
|
152 |
+
'grant_type' => 'authorization_code',
|
153 |
+
'code' => $auth_code,
|
154 |
+
'code_verifier' => $seller_nonce,
|
155 |
+
),
|
156 |
+
);
|
157 |
+
$response = $this->request( $url, $args );
|
158 |
+
|
159 |
+
if ( is_wp_error( $response ) ) {
|
160 |
+
$error = new RuntimeException(
|
161 |
+
__( 'Could not create token.', 'woocommerce-paypal-payments' )
|
162 |
+
);
|
163 |
+
$this->logger->log(
|
164 |
+
'warning',
|
165 |
+
$error->getMessage(),
|
166 |
+
array(
|
167 |
+
'args' => $args,
|
168 |
+
'response' => $response,
|
169 |
+
)
|
170 |
+
);
|
171 |
+
throw $error;
|
172 |
+
}
|
173 |
+
|
174 |
+
$json = json_decode( $response['body'] );
|
175 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
176 |
+
if ( ! isset( $json->access_token ) ) {
|
177 |
+
$error = isset( $json->details ) ?
|
178 |
+
new PayPalApiException(
|
179 |
+
$json,
|
180 |
+
$status_code
|
181 |
+
) : new RuntimeException(
|
182 |
+
__( 'No token found.', 'woocommerce-paypal-payments' )
|
183 |
+
);
|
184 |
+
$this->logger->log(
|
185 |
+
'warning',
|
186 |
+
$error->getMessage(),
|
187 |
+
array(
|
188 |
+
'args' => $args,
|
189 |
+
'response' => $response,
|
190 |
+
)
|
191 |
+
);
|
192 |
+
throw $error;
|
193 |
+
}
|
194 |
+
return (string) $json->access_token;
|
195 |
+
}
|
196 |
+
}
|
modules/ppcp-api-client/src/Endpoint/class-orderendpoint.php
ADDED
@@ -0,0 +1,538 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The order endpoint.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
13 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
14 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
15 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
16 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
|
17 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentMethod;
|
18 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
19 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
20 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
21 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
22 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
|
23 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\PatchCollectionFactory;
|
24 |
+
use WooCommerce\PayPalCommerce\ApiClient\Helper\ErrorResponse;
|
25 |
+
use WooCommerce\PayPalCommerce\ApiClient\Repository\ApplicationContextRepository;
|
26 |
+
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
|
27 |
+
use Psr\Log\LoggerInterface;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Class OrderEndpoint
|
31 |
+
*/
|
32 |
+
class OrderEndpoint {
|
33 |
+
|
34 |
+
use RequestTrait;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* The host.
|
38 |
+
*
|
39 |
+
* @var string
|
40 |
+
*/
|
41 |
+
private $host;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* The bearer.
|
45 |
+
*
|
46 |
+
* @var Bearer
|
47 |
+
*/
|
48 |
+
private $bearer;
|
49 |
+
|
50 |
+
/**
|
51 |
+
* The order factory.
|
52 |
+
*
|
53 |
+
* @var OrderFactory
|
54 |
+
*/
|
55 |
+
private $order_factory;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* The patch collection factory.
|
59 |
+
*
|
60 |
+
* @var PatchCollectionFactory
|
61 |
+
*/
|
62 |
+
private $patch_collection_factory;
|
63 |
+
|
64 |
+
/**
|
65 |
+
* The intent.
|
66 |
+
*
|
67 |
+
* @var string
|
68 |
+
*/
|
69 |
+
private $intent;
|
70 |
+
|
71 |
+
/**
|
72 |
+
* The logger.
|
73 |
+
*
|
74 |
+
* @var LoggerInterface
|
75 |
+
*/
|
76 |
+
private $logger;
|
77 |
+
|
78 |
+
/**
|
79 |
+
* The application context repository.
|
80 |
+
*
|
81 |
+
* @var ApplicationContextRepository
|
82 |
+
*/
|
83 |
+
private $application_context_repository;
|
84 |
+
|
85 |
+
/**
|
86 |
+
* The BN Code.
|
87 |
+
*
|
88 |
+
* @var string
|
89 |
+
*/
|
90 |
+
private $bn_code;
|
91 |
+
|
92 |
+
/**
|
93 |
+
* The paypal request id repository.
|
94 |
+
*
|
95 |
+
* @var PayPalRequestIdRepository
|
96 |
+
*/
|
97 |
+
private $paypal_request_id_repository;
|
98 |
+
|
99 |
+
/**
|
100 |
+
* OrderEndpoint constructor.
|
101 |
+
*
|
102 |
+
* @param string $host The host.
|
103 |
+
* @param Bearer $bearer The bearer.
|
104 |
+
* @param OrderFactory $order_factory The order factory.
|
105 |
+
* @param PatchCollectionFactory $patch_collection_factory The patch collection factory.
|
106 |
+
* @param string $intent The intent.
|
107 |
+
* @param LoggerInterface $logger The logger.
|
108 |
+
* @param ApplicationContextRepository $application_context_repository The application context repository.
|
109 |
+
* @param PayPalRequestIdRepository $paypal_request_id_repository The paypal request id repository.
|
110 |
+
* @param string $bn_code The BN Code.
|
111 |
+
*/
|
112 |
+
public function __construct(
|
113 |
+
string $host,
|
114 |
+
Bearer $bearer,
|
115 |
+
OrderFactory $order_factory,
|
116 |
+
PatchCollectionFactory $patch_collection_factory,
|
117 |
+
string $intent,
|
118 |
+
LoggerInterface $logger,
|
119 |
+
ApplicationContextRepository $application_context_repository,
|
120 |
+
PayPalRequestIdRepository $paypal_request_id_repository,
|
121 |
+
string $bn_code = ''
|
122 |
+
) {
|
123 |
+
|
124 |
+
$this->host = $host;
|
125 |
+
$this->bearer = $bearer;
|
126 |
+
$this->order_factory = $order_factory;
|
127 |
+
$this->patch_collection_factory = $patch_collection_factory;
|
128 |
+
$this->intent = $intent;
|
129 |
+
$this->logger = $logger;
|
130 |
+
$this->application_context_repository = $application_context_repository;
|
131 |
+
$this->bn_code = $bn_code;
|
132 |
+
$this->paypal_request_id_repository = $paypal_request_id_repository;
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Changes the used BN Code.
|
137 |
+
*
|
138 |
+
* @param string $bn_code The new BN Code to use.
|
139 |
+
*
|
140 |
+
* @return OrderEndpoint
|
141 |
+
* @throws RuntimeException If the request fails.
|
142 |
+
*/
|
143 |
+
public function with_bn_code( string $bn_code ): OrderEndpoint {
|
144 |
+
|
145 |
+
$this->bn_code = $bn_code;
|
146 |
+
return $this;
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Creates an order.
|
151 |
+
*
|
152 |
+
* @param PurchaseUnit[] $items The purchase unit items for the order.
|
153 |
+
* @param Payer|null $payer The payer off the order.
|
154 |
+
* @param PaymentToken|null $payment_token The payment token.
|
155 |
+
* @param PaymentMethod|null $payment_method The payment method.
|
156 |
+
* @param string $paypal_request_id The paypal request id.
|
157 |
+
*
|
158 |
+
* @return Order
|
159 |
+
* @throws RuntimeException If the request fails.
|
160 |
+
*/
|
161 |
+
public function create(
|
162 |
+
array $items,
|
163 |
+
Payer $payer = null,
|
164 |
+
PaymentToken $payment_token = null,
|
165 |
+
PaymentMethod $payment_method = null,
|
166 |
+
string $paypal_request_id = ''
|
167 |
+
): Order {
|
168 |
+
|
169 |
+
$contains_physical_goods = false;
|
170 |
+
$items = array_filter(
|
171 |
+
$items,
|
172 |
+
static function ( $item ) use ( &$contains_physical_goods ): bool {
|
173 |
+
$is_purchase_unit = is_a( $item, PurchaseUnit::class );
|
174 |
+
/**
|
175 |
+
* A purchase unit.
|
176 |
+
*
|
177 |
+
* @var PurchaseUnit $item
|
178 |
+
*/
|
179 |
+
if ( $is_purchase_unit && $item->contains_physical_goods() ) {
|
180 |
+
$contains_physical_goods = true;
|
181 |
+
}
|
182 |
+
|
183 |
+
return $is_purchase_unit;
|
184 |
+
}
|
185 |
+
);
|
186 |
+
$shipping_preferences = $contains_physical_goods
|
187 |
+
? ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE
|
188 |
+
: ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
|
189 |
+
$bearer = $this->bearer->bearer();
|
190 |
+
$data = array(
|
191 |
+
'intent' => $this->intent,
|
192 |
+
'purchase_units' => array_map(
|
193 |
+
static function ( PurchaseUnit $item ): array {
|
194 |
+
return $item->to_array();
|
195 |
+
},
|
196 |
+
$items
|
197 |
+
),
|
198 |
+
'application_context' => $this->application_context_repository
|
199 |
+
->current_context( $shipping_preferences )->to_array(),
|
200 |
+
);
|
201 |
+
if ( $payer ) {
|
202 |
+
$data['payer'] = $payer->to_array();
|
203 |
+
}
|
204 |
+
if ( $payment_token ) {
|
205 |
+
$data['payment_source']['token'] = $payment_token->to_array();
|
206 |
+
}
|
207 |
+
if ( $payment_method ) {
|
208 |
+
$data['payment_method'] = $payment_method->to_array();
|
209 |
+
}
|
210 |
+
$url = trailingslashit( $this->host ) . 'v2/checkout/orders';
|
211 |
+
$args = array(
|
212 |
+
'method' => 'POST',
|
213 |
+
'headers' => array(
|
214 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
215 |
+
'Content-Type' => 'application/json',
|
216 |
+
'Prefer' => 'return=representation',
|
217 |
+
),
|
218 |
+
'body' => wp_json_encode( $data ),
|
219 |
+
);
|
220 |
+
|
221 |
+
$paypal_request_id = $paypal_request_id ? $paypal_request_id : uniqid( 'ppcp-', true );
|
222 |
+
$args['headers']['PayPal-Request-Id'] = $paypal_request_id;
|
223 |
+
if ( $this->bn_code ) {
|
224 |
+
$args['headers']['PayPal-Partner-Attribution-Id'] = $this->bn_code;
|
225 |
+
}
|
226 |
+
$response = $this->request( $url, $args );
|
227 |
+
if ( is_wp_error( $response ) ) {
|
228 |
+
$error = new RuntimeException(
|
229 |
+
__( 'Could not create order.', 'woocommerce-paypal-payments' )
|
230 |
+
);
|
231 |
+
$this->logger->log(
|
232 |
+
'warning',
|
233 |
+
$error->getMessage(),
|
234 |
+
array(
|
235 |
+
'args' => $args,
|
236 |
+
'response' => $response,
|
237 |
+
)
|
238 |
+
);
|
239 |
+
throw $error;
|
240 |
+
}
|
241 |
+
$json = json_decode( $response['body'] );
|
242 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
243 |
+
if ( 201 !== $status_code ) {
|
244 |
+
$error = new PayPalApiException(
|
245 |
+
$json,
|
246 |
+
$status_code
|
247 |
+
);
|
248 |
+
$this->logger->log(
|
249 |
+
'warning',
|
250 |
+
$error->getMessage(),
|
251 |
+
array(
|
252 |
+
'args' => $args,
|
253 |
+
'response' => $response,
|
254 |
+
)
|
255 |
+
);
|
256 |
+
throw $error;
|
257 |
+
}
|
258 |
+
$order = $this->order_factory->from_paypal_response( $json );
|
259 |
+
$this->paypal_request_id_repository->set_for_order( $order, $paypal_request_id );
|
260 |
+
return $order;
|
261 |
+
}
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Captures an order.
|
265 |
+
*
|
266 |
+
* @param Order $order The order.
|
267 |
+
*
|
268 |
+
* @return Order
|
269 |
+
* @throws RuntimeException If the request fails.
|
270 |
+
*/
|
271 |
+
public function capture( Order $order ): Order {
|
272 |
+
if ( $order->status()->is( OrderStatus::COMPLETED ) ) {
|
273 |
+
return $order;
|
274 |
+
}
|
275 |
+
$bearer = $this->bearer->bearer();
|
276 |
+
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $order->id() . '/capture';
|
277 |
+
$args = array(
|
278 |
+
'method' => 'POST',
|
279 |
+
'headers' => array(
|
280 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
281 |
+
'Content-Type' => 'application/json',
|
282 |
+
'Prefer' => 'return=representation',
|
283 |
+
'PayPal-Request-Id' => $this->paypal_request_id_repository->get_for_order( $order ),
|
284 |
+
),
|
285 |
+
);
|
286 |
+
if ( $this->bn_code ) {
|
287 |
+
$args['headers']['PayPal-Partner-Attribution-Id'] = $this->bn_code;
|
288 |
+
}
|
289 |
+
$response = $this->request( $url, $args );
|
290 |
+
|
291 |
+
if ( is_wp_error( $response ) ) {
|
292 |
+
$error = new RuntimeException(
|
293 |
+
__( 'Could not capture order.', 'woocommerce-paypal-payments' )
|
294 |
+
);
|
295 |
+
$this->logger->log(
|
296 |
+
'warning',
|
297 |
+
$error->getMessage(),
|
298 |
+
array(
|
299 |
+
'args' => $args,
|
300 |
+
'response' => $response,
|
301 |
+
)
|
302 |
+
);
|
303 |
+
throw $error;
|
304 |
+
}
|
305 |
+
|
306 |
+
$json = json_decode( $response['body'] );
|
307 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
308 |
+
if ( 201 !== $status_code ) {
|
309 |
+
$error = new PayPalApiException(
|
310 |
+
$json,
|
311 |
+
$status_code
|
312 |
+
);
|
313 |
+
// If the order has already been captured, we return the updated order.
|
314 |
+
if ( strpos( $response['body'], ErrorResponse::ORDER_ALREADY_CAPTURED ) !== false ) {
|
315 |
+
return $this->order( $order->id() );
|
316 |
+
}
|
317 |
+
$this->logger->log(
|
318 |
+
'warning',
|
319 |
+
$error->getMessage(),
|
320 |
+
array(
|
321 |
+
'args' => $args,
|
322 |
+
'response' => $response,
|
323 |
+
)
|
324 |
+
);
|
325 |
+
throw $error;
|
326 |
+
}
|
327 |
+
$order = $this->order_factory->from_paypal_response( $json );
|
328 |
+
return $order;
|
329 |
+
}
|
330 |
+
|
331 |
+
/**
|
332 |
+
* Authorize an order.
|
333 |
+
*
|
334 |
+
* @param Order $order The order.
|
335 |
+
*
|
336 |
+
* @return Order
|
337 |
+
* @throws RuntimeException If the request fails.
|
338 |
+
*/
|
339 |
+
public function authorize( Order $order ): Order {
|
340 |
+
$bearer = $this->bearer->bearer();
|
341 |
+
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $order->id() . '/authorize';
|
342 |
+
$args = array(
|
343 |
+
'method' => 'POST',
|
344 |
+
'headers' => array(
|
345 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
346 |
+
'Content-Type' => 'application/json',
|
347 |
+
'Prefer' => 'return=representation',
|
348 |
+
'PayPal-Request-Id' => $this->paypal_request_id_repository->get_for_order( $order ),
|
349 |
+
),
|
350 |
+
);
|
351 |
+
if ( $this->bn_code ) {
|
352 |
+
$args['headers']['PayPal-Partner-Attribution-Id'] = $this->bn_code;
|
353 |
+
}
|
354 |
+
$response = $this->request( $url, $args );
|
355 |
+
|
356 |
+
if ( is_wp_error( $response ) ) {
|
357 |
+
$error = new RuntimeException(
|
358 |
+
__(
|
359 |
+
'Could not authorize order.',
|
360 |
+
'woocommerce-paypal-payments'
|
361 |
+
)
|
362 |
+
);
|
363 |
+
$this->logger->log(
|
364 |
+
'warning',
|
365 |
+
$error->getMessage(),
|
366 |
+
array(
|
367 |
+
'args' => $args,
|
368 |
+
'response' => $response,
|
369 |
+
)
|
370 |
+
);
|
371 |
+
throw $error;
|
372 |
+
}
|
373 |
+
$json = json_decode( $response['body'] );
|
374 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
375 |
+
if ( 201 !== $status_code ) {
|
376 |
+
if ( false !== strpos( $response['body'], ErrorResponse::ORDER_ALREADY_AUTHORIZED ) ) {
|
377 |
+
return $this->order( $order->id() );
|
378 |
+
}
|
379 |
+
$error = new PayPalApiException(
|
380 |
+
$json,
|
381 |
+
$status_code
|
382 |
+
);
|
383 |
+
$this->logger->log(
|
384 |
+
'warning',
|
385 |
+
$error->getMessage(),
|
386 |
+
array(
|
387 |
+
'args' => $args,
|
388 |
+
'response' => $response,
|
389 |
+
)
|
390 |
+
);
|
391 |
+
throw $error;
|
392 |
+
}
|
393 |
+
$order = $this->order_factory->from_paypal_response( $json );
|
394 |
+
return $order;
|
395 |
+
}
|
396 |
+
|
397 |
+
/**
|
398 |
+
* Fetches an order for a given ID.
|
399 |
+
*
|
400 |
+
* @param string $id The ID.
|
401 |
+
*
|
402 |
+
* @return Order
|
403 |
+
* @throws RuntimeException If the request fails.
|
404 |
+
*/
|
405 |
+
public function order( string $id ): Order {
|
406 |
+
$bearer = $this->bearer->bearer();
|
407 |
+
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $id;
|
408 |
+
$args = array(
|
409 |
+
'headers' => array(
|
410 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
411 |
+
'Content-Type' => 'application/json',
|
412 |
+
'PayPal-Request-Id' => $this->paypal_request_id_repository->get_for_order_id( $id ),
|
413 |
+
),
|
414 |
+
);
|
415 |
+
if ( $this->bn_code ) {
|
416 |
+
$args['headers']['PayPal-Partner-Attribution-Id'] = $this->bn_code;
|
417 |
+
}
|
418 |
+
$response = $this->request( $url, $args );
|
419 |
+
if ( is_wp_error( $response ) ) {
|
420 |
+
$error = new RuntimeException(
|
421 |
+
__( 'Could not retrieve order.', 'woocommerce-paypal-payments' )
|
422 |
+
);
|
423 |
+
$this->logger->log(
|
424 |
+
'warning',
|
425 |
+
$error->getMessage(),
|
426 |
+
array(
|
427 |
+
'args' => $args,
|
428 |
+
'response' => $response,
|
429 |
+
)
|
430 |
+
);
|
431 |
+
throw $error;
|
432 |
+
}
|
433 |
+
$json = json_decode( $response['body'] );
|
434 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
435 |
+
if ( 404 === $status_code || empty( $response['body'] ) ) {
|
436 |
+
$error = new RuntimeException(
|
437 |
+
__( 'Could not retrieve order.', 'woocommerce-paypal-payments' ),
|
438 |
+
404
|
439 |
+
);
|
440 |
+
$this->logger->log(
|
441 |
+
'warning',
|
442 |
+
$error->getMessage(),
|
443 |
+
array(
|
444 |
+
'args' => $args,
|
445 |
+
'response' => $response,
|
446 |
+
)
|
447 |
+
);
|
448 |
+
throw $error;
|
449 |
+
}
|
450 |
+
if ( 200 !== $status_code ) {
|
451 |
+
$error = new PayPalApiException(
|
452 |
+
$json,
|
453 |
+
$status_code
|
454 |
+
);
|
455 |
+
$this->logger->log(
|
456 |
+
'warning',
|
457 |
+
$error->getMessage(),
|
458 |
+
array(
|
459 |
+
'args' => $args,
|
460 |
+
'response' => $response,
|
461 |
+
)
|
462 |
+
);
|
463 |
+
throw $error;
|
464 |
+
}
|
465 |
+
$order = $this->order_factory->from_paypal_response( $json );
|
466 |
+
return $order;
|
467 |
+
}
|
468 |
+
|
469 |
+
/**
|
470 |
+
* Patches an order.
|
471 |
+
*
|
472 |
+
* @param Order $order_to_update The order to patch.
|
473 |
+
* @param Order $order_to_compare The target order.
|
474 |
+
*
|
475 |
+
* @return Order
|
476 |
+
* @throws RuntimeException If the request fails.
|
477 |
+
*/
|
478 |
+
public function patch_order_with( Order $order_to_update, Order $order_to_compare ): Order {
|
479 |
+
$patches = $this->patch_collection_factory->from_orders( $order_to_update, $order_to_compare );
|
480 |
+
if ( ! count( $patches->patches() ) ) {
|
481 |
+
return $order_to_update;
|
482 |
+
}
|
483 |
+
|
484 |
+
$bearer = $this->bearer->bearer();
|
485 |
+
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $order_to_update->id();
|
486 |
+
$args = array(
|
487 |
+
'method' => 'PATCH',
|
488 |
+
'headers' => array(
|
489 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
490 |
+
'Content-Type' => 'application/json',
|
491 |
+
'Prefer' => 'return=representation',
|
492 |
+
'PayPal-Request-Id' => $this->paypal_request_id_repository->get_for_order(
|
493 |
+
$order_to_update
|
494 |
+
),
|
495 |
+
),
|
496 |
+
'body' => wp_json_encode( $patches->to_array() ),
|
497 |
+
);
|
498 |
+
if ( $this->bn_code ) {
|
499 |
+
$args['headers']['PayPal-Partner-Attribution-Id'] = $this->bn_code;
|
500 |
+
}
|
501 |
+
$response = $this->request( $url, $args );
|
502 |
+
|
503 |
+
if ( is_wp_error( $response ) ) {
|
504 |
+
$error = new RuntimeException(
|
505 |
+
__( 'Could not retrieve order.', 'woocommerce-paypal-payments' )
|
506 |
+
);
|
507 |
+
$this->logger->log(
|
508 |
+
'warning',
|
509 |
+
$error->getMessage(),
|
510 |
+
array(
|
511 |
+
'args' => $args,
|
512 |
+
'response' => $response,
|
513 |
+
)
|
514 |
+
);
|
515 |
+
throw $error;
|
516 |
+
}
|
517 |
+
$json = json_decode( $response['body'] );
|
518 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
519 |
+
if ( 204 !== $status_code ) {
|
520 |
+
$error = new PayPalApiException(
|
521 |
+
$json,
|
522 |
+
$status_code
|
523 |
+
);
|
524 |
+
$this->logger->log(
|
525 |
+
'warning',
|
526 |
+
$error->getMessage(),
|
527 |
+
array(
|
528 |
+
'args' => $args,
|
529 |
+
'response' => $response,
|
530 |
+
)
|
531 |
+
);
|
532 |
+
throw $error;
|
533 |
+
}
|
534 |
+
|
535 |
+
$new_order = $this->order( $order_to_update->id() );
|
536 |
+
return $new_order;
|
537 |
+
}
|
538 |
+
}
|
modules/ppcp-api-client/src/Endpoint/class-partnerreferrals.php
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The partner referrals endpoint.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
13 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
14 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
15 |
+
use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
|
16 |
+
use Psr\Log\LoggerInterface;
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Class PartnerReferrals
|
20 |
+
*/
|
21 |
+
class PartnerReferrals {
|
22 |
+
|
23 |
+
use RequestTrait;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* The host.
|
27 |
+
*
|
28 |
+
* @var string
|
29 |
+
*/
|
30 |
+
private $host;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* The bearer.
|
34 |
+
*
|
35 |
+
* @var Bearer
|
36 |
+
*/
|
37 |
+
private $bearer;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* The PartnerReferralsData.
|
41 |
+
*
|
42 |
+
* @var PartnerReferralsData
|
43 |
+
*/
|
44 |
+
private $data;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* The logger.
|
48 |
+
*
|
49 |
+
* @var LoggerInterface
|
50 |
+
*/
|
51 |
+
private $logger;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* PartnerReferrals constructor.
|
55 |
+
*
|
56 |
+
* @param string $host The host.
|
57 |
+
* @param Bearer $bearer The bearer.
|
58 |
+
* @param PartnerReferralsData $data The partner referrals data.
|
59 |
+
* @param LoggerInterface $logger The logger.
|
60 |
+
*/
|
61 |
+
public function __construct(
|
62 |
+
string $host,
|
63 |
+
Bearer $bearer,
|
64 |
+
PartnerReferralsData $data,
|
65 |
+
LoggerInterface $logger
|
66 |
+
) {
|
67 |
+
|
68 |
+
$this->host = $host;
|
69 |
+
$this->bearer = $bearer;
|
70 |
+
$this->data = $data;
|
71 |
+
$this->logger = $logger;
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Fetch the signup link.
|
76 |
+
*
|
77 |
+
* @return string
|
78 |
+
* @throws RuntimeException If the request fails.
|
79 |
+
*/
|
80 |
+
public function signup_link(): string {
|
81 |
+
$data = $this->data->data();
|
82 |
+
$bearer = $this->bearer->bearer();
|
83 |
+
$args = array(
|
84 |
+
'method' => 'POST',
|
85 |
+
'headers' => array(
|
86 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
87 |
+
'Content-Type' => 'application/json',
|
88 |
+
'Prefer' => 'return=representation',
|
89 |
+
),
|
90 |
+
'body' => wp_json_encode( $data ),
|
91 |
+
);
|
92 |
+
$url = trailingslashit( $this->host ) . 'v2/customer/partner-referrals';
|
93 |
+
$response = $this->request( $url, $args );
|
94 |
+
|
95 |
+
if ( is_wp_error( $response ) ) {
|
96 |
+
$error = new RuntimeException(
|
97 |
+
__( 'Could not create referral.', 'woocommerce-paypal-payments' )
|
98 |
+
);
|
99 |
+
$this->logger->log(
|
100 |
+
'warning',
|
101 |
+
$error->getMessage(),
|
102 |
+
array(
|
103 |
+
'args' => $args,
|
104 |
+
'response' => $response,
|
105 |
+
)
|
106 |
+
);
|
107 |
+
throw $error;
|
108 |
+
}
|
109 |
+
$json = json_decode( $response['body'] );
|
110 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
111 |
+
if ( 201 !== $status_code ) {
|
112 |
+
$error = new PayPalApiException(
|
113 |
+
$json,
|
114 |
+
$status_code
|
115 |
+
);
|
116 |
+
$this->logger->log(
|
117 |
+
'warning',
|
118 |
+
$error->getMessage(),
|
119 |
+
array(
|
120 |
+
'args' => $args,
|
121 |
+
'response' => $response,
|
122 |
+
)
|
123 |
+
);
|
124 |
+
throw $error;
|
125 |
+
}
|
126 |
+
|
127 |
+
foreach ( $json->links as $link ) {
|
128 |
+
if ( 'action_url' === $link->rel ) {
|
129 |
+
return (string) $link->href;
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
$error = new RuntimeException(
|
134 |
+
__( 'Action URL not found.', 'woocommerce-paypal-payments' )
|
135 |
+
);
|
136 |
+
$this->logger->log(
|
137 |
+
'warning',
|
138 |
+
$error->getMessage(),
|
139 |
+
array(
|
140 |
+
'args' => $args,
|
141 |
+
'response' => $response,
|
142 |
+
)
|
143 |
+
);
|
144 |
+
throw $error;
|
145 |
+
}
|
146 |
+
}
|
modules/ppcp-api-client/src/Endpoint/class-partnersendpoint.php
ADDED
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The Partners Endpoint.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare( strict_types=1 );
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
11 |
+
|
12 |
+
use Psr\Log\LoggerInterface;
|
13 |
+
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
14 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatus;
|
15 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
16 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
17 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\SellerStatusFactory;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Class PartnersEndpoint
|
21 |
+
*/
|
22 |
+
class PartnersEndpoint {
|
23 |
+
|
24 |
+
use RequestTrait;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* The Host URL.
|
28 |
+
*
|
29 |
+
* @var string
|
30 |
+
*/
|
31 |
+
private $host;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* The bearer.
|
35 |
+
*
|
36 |
+
* @var Bearer
|
37 |
+
*/
|
38 |
+
private $bearer;
|
39 |
+
|
40 |
+
/**
|
41 |
+
* The logger.
|
42 |
+
*
|
43 |
+
* @var LoggerInterface
|
44 |
+
*/
|
45 |
+
private $logger;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* The seller status factory.
|
49 |
+
*
|
50 |
+
* @var SellerStatusFactory
|
51 |
+
*/
|
52 |
+
private $seller_status_factory;
|
53 |
+
|
54 |
+
/**
|
55 |
+
* The partner ID.
|
56 |
+
*
|
57 |
+
* @var string
|
58 |
+
*/
|
59 |
+
private $partner_id;
|
60 |
+
|
61 |
+
/**
|
62 |
+
* The merchant ID.
|
63 |
+
*
|
64 |
+
* @var string
|
65 |
+
*/
|
66 |
+
private $merchant_id;
|
67 |
+
|
68 |
+
/**
|
69 |
+
* PartnersEndpoint constructor.
|
70 |
+
*
|
71 |
+
* @param string $host The host.
|
72 |
+
* @param Bearer $bearer The bearer.
|
73 |
+
* @param LoggerInterface $logger The logger.
|
74 |
+
* @param SellerStatusFactory $seller_status_factory The seller status factory.
|
75 |
+
* @param string $partner_id The partner ID.
|
76 |
+
* @param string $merchant_id The merchant ID.
|
77 |
+
*/
|
78 |
+
public function __construct(
|
79 |
+
string $host,
|
80 |
+
Bearer $bearer,
|
81 |
+
LoggerInterface $logger,
|
82 |
+
SellerStatusFactory $seller_status_factory,
|
83 |
+
string $partner_id,
|
84 |
+
string $merchant_id
|
85 |
+
) {
|
86 |
+
$this->host = $host;
|
87 |
+
$this->bearer = $bearer;
|
88 |
+
$this->logger = $logger;
|
89 |
+
$this->seller_status_factory = $seller_status_factory;
|
90 |
+
$this->partner_id = $partner_id;
|
91 |
+
$this->merchant_id = $merchant_id;
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Returns the current seller status.
|
96 |
+
*
|
97 |
+
* @return SellerStatus
|
98 |
+
* @throws RuntimeException When request could not be fullfilled.
|
99 |
+
*/
|
100 |
+
public function seller_status() : SellerStatus {
|
101 |
+
$url = trailingslashit( $this->host ) . 'v1/customer/partners/' . $this->partner_id . '/merchant-integrations/' . $this->merchant_id;
|
102 |
+
$bearer = $this->bearer->bearer();
|
103 |
+
$args = array(
|
104 |
+
'method' => 'GET',
|
105 |
+
'headers' => array(
|
106 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
107 |
+
'Content-Type' => 'application/json',
|
108 |
+
),
|
109 |
+
);
|
110 |
+
$response = $this->request( $url, $args );
|
111 |
+
if ( is_wp_error( $response ) ) {
|
112 |
+
|
113 |
+
$error = new RuntimeException(
|
114 |
+
__(
|
115 |
+
'Could not fetch sellers status.',
|
116 |
+
'woocommerce-paypal-payments'
|
117 |
+
)
|
118 |
+
);
|
119 |
+
|
120 |
+
$this->logger->log(
|
121 |
+
'warning',
|
122 |
+
$error->getMessage(),
|
123 |
+
array(
|
124 |
+
'args' => $args,
|
125 |
+
'response' => $response,
|
126 |
+
)
|
127 |
+
);
|
128 |
+
throw $error;
|
129 |
+
}
|
130 |
+
|
131 |
+
$json = json_decode( wp_remote_retrieve_body( $response ) );
|
132 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
133 |
+
if ( 200 !== $status_code ) {
|
134 |
+
$error = new PayPalApiException( $json, $status_code );
|
135 |
+
$this->logger->log(
|
136 |
+
'warning',
|
137 |
+
$error->getMessage(),
|
138 |
+
array(
|
139 |
+
'args' => $args,
|
140 |
+
'response' => $response,
|
141 |
+
)
|
142 |
+
);
|
143 |
+
throw $error;
|
144 |
+
}
|
145 |
+
|
146 |
+
$status = $this->seller_status_factory->from_paypal_reponse( $json );
|
147 |
+
return $status;
|
148 |
+
}
|
149 |
+
}
|
modules/ppcp-api-client/src/Endpoint/class-paymentsendpoint.php
ADDED
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The payments endpoint.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
13 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
|
14 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\Refund;
|
15 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
16 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
17 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\AuthorizationFactory;
|
18 |
+
use Psr\Log\LoggerInterface;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Class PaymentsEndpoint
|
22 |
+
*/
|
23 |
+
class PaymentsEndpoint {
|
24 |
+
|
25 |
+
use RequestTrait;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* The host.
|
29 |
+
*
|
30 |
+
* @var string
|
31 |
+
*/
|
32 |
+
private $host;
|
33 |
+
|
34 |
+
/**
|
35 |
+
* The bearer.
|
36 |
+
*
|
37 |
+
* @var Bearer
|
38 |
+
*/
|
39 |
+
private $bearer;
|
40 |
+
|
41 |
+
/**
|
42 |
+
* The authorization factory.
|
43 |
+
*
|
44 |
+
* @var AuthorizationFactory
|
45 |
+
*/
|
46 |
+
private $authorizations_factory;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* The logger.
|
50 |
+
*
|
51 |
+
* @var LoggerInterface
|
52 |
+
*/
|
53 |
+
private $logger;
|
54 |
+
|
55 |
+
/**
|
56 |
+
* PaymentsEndpoint constructor.
|
57 |
+
*
|
58 |
+
* @param string $host The host.
|
59 |
+
* @param Bearer $bearer The bearer.
|
60 |
+
* @param AuthorizationFactory $authorization_factory The authorization factory.
|
61 |
+
* @param LoggerInterface $logger The logger.
|
62 |
+
*/
|
63 |
+
public function __construct(
|
64 |
+
string $host,
|
65 |
+
Bearer $bearer,
|
66 |
+
AuthorizationFactory $authorization_factory,
|
67 |
+
LoggerInterface $logger
|
68 |
+
) {
|
69 |
+
|
70 |
+
$this->host = $host;
|
71 |
+
$this->bearer = $bearer;
|
72 |
+
$this->authorizations_factory = $authorization_factory;
|
73 |
+
$this->logger = $logger;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Fetch an authorization by a given id.
|
78 |
+
*
|
79 |
+
* @param string $authorization_id The id.
|
80 |
+
*
|
81 |
+
* @return Authorization
|
82 |
+
* @throws RuntimeException If the request fails.
|
83 |
+
*/
|
84 |
+
public function authorization( string $authorization_id ): Authorization {
|
85 |
+
$bearer = $this->bearer->bearer();
|
86 |
+
$url = trailingslashit( $this->host ) . 'v2/payments/authorizations/' . $authorization_id;
|
87 |
+
$args = array(
|
88 |
+
'headers' => array(
|
89 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
90 |
+
'Content-Type' => 'application/json',
|
91 |
+
'Prefer' => 'return=representation',
|
92 |
+
),
|
93 |
+
);
|
94 |
+
|
95 |
+
$response = $this->request( $url, $args );
|
96 |
+
$json = json_decode( $response['body'] );
|
97 |
+
|
98 |
+
if ( is_wp_error( $response ) ) {
|
99 |
+
$error = new RuntimeException(
|
100 |
+
__( 'Could not get authorized payment info.', 'woocommerce-paypal-payments' )
|
101 |
+
);
|
102 |
+
$this->logger->log(
|
103 |
+
'warning',
|
104 |
+
$error->getMessage(),
|
105 |
+
array(
|
106 |
+
'args' => $args,
|
107 |
+
'response' => $response,
|
108 |
+
)
|
109 |
+
);
|
110 |
+
throw $error;
|
111 |
+
}
|
112 |
+
|
113 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
114 |
+
if ( 200 !== $status_code ) {
|
115 |
+
$error = new PayPalApiException(
|
116 |
+
$json,
|
117 |
+
$status_code
|
118 |
+
);
|
119 |
+
$this->logger->log(
|
120 |
+
'warning',
|
121 |
+
$error->getMessage(),
|
122 |
+
array(
|
123 |
+
'args' => $args,
|
124 |
+
'response' => $response,
|
125 |
+
)
|
126 |
+
);
|
127 |
+
throw $error;
|
128 |
+
}
|
129 |
+
|
130 |
+
$authorization = $this->authorizations_factory->from_paypal_response( $json );
|
131 |
+
return $authorization;
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Capture an authorization by a given ID.
|
136 |
+
*
|
137 |
+
* @param string $authorization_id The id.
|
138 |
+
*
|
139 |
+
* @return Authorization
|
140 |
+
* @throws RuntimeException If the request fails.
|
141 |
+
*/
|
142 |
+
public function capture( string $authorization_id ): Authorization {
|
143 |
+
$bearer = $this->bearer->bearer();
|
144 |
+
$url = trailingslashit( $this->host ) . 'v2/payments/authorizations/' . $authorization_id . '/capture';
|
145 |
+
$args = array(
|
146 |
+
'method' => 'POST',
|
147 |
+
'headers' => array(
|
148 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
149 |
+
'Content-Type' => 'application/json',
|
150 |
+
'Prefer' => 'return=representation',
|
151 |
+
),
|
152 |
+
);
|
153 |
+
|
154 |
+
$response = $this->request( $url, $args );
|
155 |
+
$json = json_decode( $response['body'] );
|
156 |
+
|
157 |
+
if ( is_wp_error( $response ) ) {
|
158 |
+
$error = new RuntimeException(
|
159 |
+
__( 'Could not capture authorized payment.', 'woocommerce-paypal-payments' )
|
160 |
+
);
|
161 |
+
$this->logger->log(
|
162 |
+
'warning',
|
163 |
+
$error->getMessage(),
|
164 |
+
array(
|
165 |
+
'args' => $args,
|
166 |
+
'response' => $response,
|
167 |
+
)
|
168 |
+
);
|
169 |
+
throw $error;
|
170 |
+
}
|
171 |
+
|
172 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
173 |
+
if ( 201 !== $status_code ) {
|
174 |
+
$error = new PayPalApiException(
|
175 |
+
$json,
|
176 |
+
$status_code
|
177 |
+
);
|
178 |
+
$this->logger->log(
|
179 |
+
'warning',
|
180 |
+
$error->getMessage(),
|
181 |
+
array(
|
182 |
+
'args' => $args,
|
183 |
+
'response' => $response,
|
184 |
+
)
|
185 |
+
);
|
186 |
+
throw $error;
|
187 |
+
}
|
188 |
+
|
189 |
+
$authorization = $this->authorizations_factory->from_paypal_response( $json );
|
190 |
+
return $authorization;
|
191 |
+
}
|
192 |
+
|
193 |
+
/**
|
194 |
+
* Refunds a payment.
|
195 |
+
*
|
196 |
+
* @param Refund $refund The refund to be processed.
|
197 |
+
*
|
198 |
+
* @return bool
|
199 |
+
* @throws RuntimeException If the request fails.
|
200 |
+
*/
|
201 |
+
public function refund( Refund $refund ) : bool {
|
202 |
+
$bearer = $this->bearer->bearer();
|
203 |
+
$url = trailingslashit( $this->host ) . 'v2/payments/captures/' . $refund->for_capture()->id() . '/refund';
|
204 |
+
$args = array(
|
205 |
+
'method' => 'POST',
|
206 |
+
'headers' => array(
|
207 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
208 |
+
'Content-Type' => 'application/json',
|
209 |
+
'Prefer' => 'return=representation',
|
210 |
+
),
|
211 |
+
'body' => wp_json_encode( $refund->to_array() ),
|
212 |
+
);
|
213 |
+
|
214 |
+
$response = $this->request( $url, $args );
|
215 |
+
$json = json_decode( $response['body'] );
|
216 |
+
|
217 |
+
if ( is_wp_error( $response ) ) {
|
218 |
+
$error = new RuntimeException(
|
219 |
+
__( 'Could not refund payment.', 'woocommerce-paypal-payments' )
|
220 |
+
);
|
221 |
+
$this->logger->log(
|
222 |
+
'warning',
|
223 |
+
$error->getMessage(),
|
224 |
+
array(
|
225 |
+
'args' => $args,
|
226 |
+
'response' => $response,
|
227 |
+
)
|
228 |
+
);
|
229 |
+
throw $error;
|
230 |
+
}
|
231 |
+
|
232 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
233 |
+
if ( 201 !== $status_code ) {
|
234 |
+
$error = new PayPalApiException(
|
235 |
+
$json,
|
236 |
+
$status_code
|
237 |
+
);
|
238 |
+
$this->logger->log(
|
239 |
+
'warning',
|
240 |
+
$error->getMessage(),
|
241 |
+
array(
|
242 |
+
'args' => $args,
|
243 |
+
'response' => $response,
|
244 |
+
)
|
245 |
+
);
|
246 |
+
throw $error;
|
247 |
+
}
|
248 |
+
|
249 |
+
return true;
|
250 |
+
}
|
251 |
+
}
|
modules/ppcp-api-client/src/Endpoint/class-paymenttokenendpoint.php
ADDED
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The payment token endpoint.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
13 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
14 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
15 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
16 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\PaymentTokenFactory;
|
17 |
+
use Psr\Log\LoggerInterface;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Class PaymentTokenEndpoint
|
21 |
+
*/
|
22 |
+
class PaymentTokenEndpoint {
|
23 |
+
|
24 |
+
use RequestTrait;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* The bearer.
|
28 |
+
*
|
29 |
+
* @var Bearer
|
30 |
+
*/
|
31 |
+
private $bearer;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* The host.
|
35 |
+
*
|
36 |
+
* @var string
|
37 |
+
*/
|
38 |
+
private $host;
|
39 |
+
|
40 |
+
/**
|
41 |
+
* The payment token factory.
|
42 |
+
*
|
43 |
+
* @var PaymentTokenFactory
|
44 |
+
*/
|
45 |
+
private $factory;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* The logger.
|
49 |
+
*
|
50 |
+
* @var LoggerInterface
|
51 |
+
*/
|
52 |
+
private $logger;
|
53 |
+
/**
|
54 |
+
* The prefix.
|
55 |
+
*
|
56 |
+
* @var string
|
57 |
+
*/
|
58 |
+
private $prefix;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* PaymentTokenEndpoint constructor.
|
62 |
+
*
|
63 |
+
* @param string $host The host.
|
64 |
+
* @param Bearer $bearer The bearer.
|
65 |
+
* @param PaymentTokenFactory $factory The payment token factory.
|
66 |
+
* @param LoggerInterface $logger The logger.
|
67 |
+
* @param string $prefix The prefix.
|
68 |
+
*/
|
69 |
+
public function __construct(
|
70 |
+
string $host,
|
71 |
+
Bearer $bearer,
|
72 |
+
PaymentTokenFactory $factory,
|
73 |
+
LoggerInterface $logger,
|
74 |
+
string $prefix
|
75 |
+
) {
|
76 |
+
|
77 |
+
$this->host = $host;
|
78 |
+
$this->bearer = $bearer;
|
79 |
+
$this->factory = $factory;
|
80 |
+
$this->logger = $logger;
|
81 |
+
$this->prefix = $prefix;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Returns the payment tokens for a user.
|
86 |
+
*
|
87 |
+
* @param int $id The user id.
|
88 |
+
*
|
89 |
+
* @return PaymentToken[]
|
90 |
+
* @throws RuntimeException If the request fails.
|
91 |
+
*/
|
92 |
+
public function for_user( int $id ): array {
|
93 |
+
$bearer = $this->bearer->bearer();
|
94 |
+
|
95 |
+
$customer_id = $this->prefix . $id;
|
96 |
+
$url = trailingslashit( $this->host ) . 'v2/vault/payment-tokens/?customer_id=' . $customer_id;
|
97 |
+
$args = array(
|
98 |
+
'method' => 'GET',
|
99 |
+
'headers' => array(
|
100 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
101 |
+
'Content-Type' => 'application/json',
|
102 |
+
),
|
103 |
+
);
|
104 |
+
|
105 |
+
$response = $this->request( $url, $args );
|
106 |
+
if ( is_wp_error( $response ) ) {
|
107 |
+
$error = new RuntimeException(
|
108 |
+
__( 'Could not fetch payment token.', 'woocommerce-paypal-payments' )
|
109 |
+
);
|
110 |
+
$this->logger->log(
|
111 |
+
'warning',
|
112 |
+
$error->getMessage(),
|
113 |
+
array(
|
114 |
+
'args' => $args,
|
115 |
+
'response' => $response,
|
116 |
+
)
|
117 |
+
);
|
118 |
+
throw $error;
|
119 |
+
}
|
120 |
+
$json = json_decode( $response['body'] );
|
121 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
122 |
+
if ( 200 !== $status_code ) {
|
123 |
+
$error = new PayPalApiException(
|
124 |
+
$json,
|
125 |
+
$status_code
|
126 |
+
);
|
127 |
+
$this->logger->log(
|
128 |
+
'warning',
|
129 |
+
$error->getMessage(),
|
130 |
+
array(
|
131 |
+
'args' => $args,
|
132 |
+
'response' => $response,
|
133 |
+
)
|
134 |
+
);
|
135 |
+
throw $error;
|
136 |
+
}
|
137 |
+
|
138 |
+
$tokens = array();
|
139 |
+
foreach ( $json->payment_tokens as $token_value ) {
|
140 |
+
$tokens[] = $this->factory->from_paypal_response( $token_value );
|
141 |
+
}
|
142 |
+
if ( empty( $tokens ) ) {
|
143 |
+
$error = new RuntimeException(
|
144 |
+
sprintf(
|
145 |
+
// translators: %d is the customer id.
|
146 |
+
__( 'No token stored for customer %d.', 'woocommerce-paypal-payments' ),
|
147 |
+
$id
|
148 |
+
)
|
149 |
+
);
|
150 |
+
$this->logger->log(
|
151 |
+
'warning',
|
152 |
+
$error->getMessage(),
|
153 |
+
array(
|
154 |
+
'args' => $args,
|
155 |
+
'response' => $response,
|
156 |
+
)
|
157 |
+
);
|
158 |
+
throw $error;
|
159 |
+
}
|
160 |
+
return $tokens;
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Deletes a payment token.
|
165 |
+
*
|
166 |
+
* @param PaymentToken $token The token to delete.
|
167 |
+
*
|
168 |
+
* @return bool
|
169 |
+
* @throws RuntimeException If the request fails.
|
170 |
+
*/
|
171 |
+
public function delete_token( PaymentToken $token ): bool {
|
172 |
+
|
173 |
+
$bearer = $this->bearer->bearer();
|
174 |
+
|
175 |
+
$url = trailingslashit( $this->host ) . 'v2/vault/payment-tokens/' . $token->id();
|
176 |
+
$args = array(
|
177 |
+
'method' => 'DELETE',
|
178 |
+
'headers' => array(
|
179 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
180 |
+
'Content-Type' => 'application/json',
|
181 |
+
),
|
182 |
+
);
|
183 |
+
|
184 |
+
$response = $this->request( $url, $args );
|
185 |
+
|
186 |
+
if ( is_wp_error( $response ) ) {
|
187 |
+
$error = new RuntimeException(
|
188 |
+
__( 'Could not delete payment token.', 'woocommerce-paypal-payments' )
|
189 |
+
);
|
190 |
+
$this->logger->log(
|
191 |
+
'warning',
|
192 |
+
$error->getMessage(),
|
193 |
+
array(
|
194 |
+
'args' => $args,
|
195 |
+
'response' => $response,
|
196 |
+
)
|
197 |
+
);
|
198 |
+
throw $error;
|
199 |
+
}
|
200 |
+
|
201 |
+
return wp_remote_retrieve_response_code( $response ) === 204;
|
202 |
+
}
|
203 |
+
}
|
modules/ppcp-api-client/src/Endpoint/class-requesttrait.php
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The RequestTrait wraps the wp_remote_get functionality for the API client.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Trait RequestTrait
|
14 |
+
*/
|
15 |
+
trait RequestTrait {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Performs a request
|
19 |
+
*
|
20 |
+
* @param string $url The URL to request.
|
21 |
+
* @param array $args The arguments by which to request.
|
22 |
+
*
|
23 |
+
* @return array|\WP_Error
|
24 |
+
*/
|
25 |
+
private function request( string $url, array $args ) {
|
26 |
+
|
27 |
+
/**
|
28 |
+
* This filter can be used to alter the request args.
|
29 |
+
* For example, during testing, the PayPal-Mock-Response header could be
|
30 |
+
* added here.
|
31 |
+
*/
|
32 |
+
$args = apply_filters( 'ppcp_request_args', $args, $url );
|
33 |
+
if ( ! isset( $args['headers']['PayPal-Partner-Attribution-Id'] ) ) {
|
34 |
+
$args['headers']['PayPal-Partner-Attribution-Id'] = 'Woo_PPCP';
|
35 |
+
}
|
36 |
+
|
37 |
+
return wp_remote_get( $url, $args );
|
38 |
+
}
|
39 |
+
}
|
modules/ppcp-api-client/src/Endpoint/class-webhookendpoint.php
ADDED
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The webhook endpoint.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Endpoint
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Endpoint;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
13 |
+
use WooCommerce\PayPalCommerce\ApiClient\Entity\Webhook;
|
14 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
15 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
16 |
+
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory;
|
17 |
+
use Psr\Log\LoggerInterface;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Class WebhookEndpoint
|
21 |
+
*/
|
22 |
+
class WebhookEndpoint {
|
23 |
+
|
24 |
+
use RequestTrait;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* The host.
|
28 |
+
*
|
29 |
+
* @var string
|
30 |
+
*/
|
31 |
+
private $host;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* The bearer.
|
35 |
+
*
|
36 |
+
* @var Bearer
|
37 |
+
*/
|
38 |
+
private $bearer;
|
39 |
+
|
40 |
+
/**
|
41 |
+
* The webhook factory.
|
42 |
+
*
|
43 |
+
* @var WebhookFactory
|
44 |
+
*/
|
45 |
+
private $webhook_factory;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* The logger.
|
49 |
+
*
|
50 |
+
* @var LoggerInterface
|
51 |
+
*/
|
52 |
+
private $logger;
|
53 |
+
|
54 |
+
/**
|
55 |
+
* WebhookEndpoint constructor.
|
56 |
+
*
|
57 |
+
* @param string $host The host.
|
58 |
+
* @param Bearer $bearer The bearer.
|
59 |
+
* @param WebhookFactory $webhook_factory The webhook factory.
|
60 |
+
* @param LoggerInterface $logger The logger.
|
61 |
+
*/
|
62 |
+
public function __construct(
|
63 |
+
string $host,
|
64 |
+
Bearer $bearer,
|
65 |
+
WebhookFactory $webhook_factory,
|
66 |
+
LoggerInterface $logger
|
67 |
+
) {
|
68 |
+
|
69 |
+
$this->host = $host;
|
70 |
+
$this->bearer = $bearer;
|
71 |
+
$this->webhook_factory = $webhook_factory;
|
72 |
+
$this->logger = $logger;
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Creates a webhook with PayPal.
|
77 |
+
*
|
78 |
+
* @param Webhook $hook The webhook to create.
|
79 |
+
*
|
80 |
+
* @return Webhook
|
81 |
+
* @throws RuntimeException If the request fails.
|
82 |
+
*/
|
83 |
+
public function create( Webhook $hook ): Webhook {
|
84 |
+
/**
|
85 |
+
* An hook, which has an ID has already been created.
|
86 |
+
*/
|
87 |
+
if ( $hook->id() ) {
|
88 |
+
return $hook;
|
89 |
+
}
|
90 |
+
$bearer = $this->bearer->bearer();
|
91 |
+
$url = trailingslashit( $this->host ) . 'v1/notifications/webhooks';
|
92 |
+
$args = array(
|
93 |
+
'method' => 'POST',
|
94 |
+
'headers' => array(
|
95 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
96 |
+
'Content-Type' => 'application/json',
|
97 |
+
),
|
98 |
+
'body' => wp_json_encode( $hook->to_array() ),
|
99 |
+
);
|
100 |
+
$response = $this->request( $url, $args );
|
101 |
+
|
102 |
+
if ( is_wp_error( $response ) ) {
|
103 |
+
$error = new RuntimeException(
|
104 |
+
__( 'Not able to create a webhook.', 'woocommerce-paypal-payments' )
|
105 |
+
);
|
106 |
+
$this->logger->log(
|
107 |
+
'warning',
|
108 |
+
$error->getMessage(),
|
109 |
+
array(
|
110 |
+
'args' => $args,
|
111 |
+
'response' => $response,
|
112 |
+
)
|
113 |
+
);
|
114 |
+
throw $error;
|
115 |
+
}
|
116 |
+
|
117 |
+
$json = json_decode( $response['body'] );
|
118 |
+
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
119 |
+
if ( 201 !== $status_code ) {
|
120 |
+
$error = new PayPalApiException(
|
121 |
+
$json,
|
122 |
+
$status_code
|
123 |
+
);
|
124 |
+
$this->logger->log(
|
125 |
+
'warning',
|
126 |
+
$error->getMessage(),
|
127 |
+
array(
|
128 |
+
'args' => $args,
|
129 |
+
'response' => $response,
|
130 |
+
)
|
131 |
+
);
|
132 |
+
throw $error;
|
133 |
+
}
|
134 |
+
|
135 |
+
$hook = $this->webhook_factory->from_paypal_response( $json );
|
136 |
+
return $hook;
|
137 |
+
}
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Deletes a webhook.
|
141 |
+
*
|
142 |
+
* @param Webhook $hook The webhook to delete.
|
143 |
+
*
|
144 |
+
* @return bool
|
145 |
+
* @throws RuntimeException If the request fails.
|
146 |
+
*/
|
147 |
+
public function delete( Webhook $hook ): bool {
|
148 |
+
if ( ! $hook->id() ) {
|
149 |
+
return false;
|
150 |
+
}
|
151 |
+
|
152 |
+
$bearer = $this->bearer->bearer();
|
153 |
+
$url = trailingslashit( $this->host ) . 'v1/notifications/webhooks/' . $hook->id();
|
154 |
+
$args = array(
|
155 |
+
'method' => 'DELETE',
|
156 |
+
'headers' => array(
|
157 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
158 |
+
),
|
159 |
+
);
|
160 |
+
$response = $this->request( $url, $args );
|
161 |
+
|
162 |
+
if ( is_wp_error( $response ) ) {
|
163 |
+
$error = new RuntimeException(
|
164 |
+
__( 'Not able to delete the webhook.', 'woocommerce-paypal-payments' )
|
165 |
+
);
|
166 |
+
$this->logger->log(
|
167 |
+
'warning',
|
168 |
+
$error->getMessage(),
|
169 |
+
array(
|
170 |
+
'args' => $args,
|
171 |
+
'response' => $response,
|
172 |
+
)
|
173 |
+
);
|
174 |
+
throw $error;
|
175 |
+
}
|
176 |
+
return wp_remote_retrieve_response_code( $response ) === 204;
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Verifies if a webhook event is legitimate.
|
181 |
+
*
|
182 |
+
* @param string $auth_algo The auth algo.
|
183 |
+
* @param string $cert_url The cert URL.
|
184 |
+
* @param string $transmission_id The transmission id.
|
185 |
+
* @param string $transmission_sig The transmission signature.
|
186 |
+
* @param string $transmission_time The transmission time.
|
187 |
+
* @param string $webhook_id The webhook id.
|
188 |
+
* @param \stdClass $webhook_event The webhook event.
|
189 |
+
*
|
190 |
+
* @return bool
|
191 |
+
* @throws RuntimeException If the request fails.
|
192 |
+
*/
|
193 |
+
public function verify_event(
|
194 |
+
string $auth_algo,
|
195 |
+
string $cert_url,
|
196 |
+
string $transmission_id,
|
197 |
+
string $transmission_sig,
|
198 |
+
string $transmission_time,
|
199 |
+
string $webhook_id,
|
200 |
+
\stdClass $webhook_event
|
201 |
+
): bool {
|
202 |
+
|
203 |
+
$bearer = $this->bearer->bearer();
|
204 |
+
$url = trailingslashit( $this->host ) . 'v1/notifications/verify-webhook-signature';
|
205 |
+
$args = array(
|
206 |
+
'method' => 'POST',
|
207 |
+
'headers' => array(
|
208 |
+
'Authorization' => 'Bearer ' . $bearer->token(),
|
209 |
+
'Content-Type' => 'application/json',
|
210 |
+
),
|
211 |
+
'body' => wp_json_encode(
|
212 |
+
array(
|
213 |
+
'transmission_id' => $transmission_id,
|
214 |
+
'transmission_time' => $transmission_time,
|
215 |
+
'cert_url' => $cert_url,
|
216 |
+
'auth_algo' => $auth_algo,
|
217 |
+
'transmission_sig' => $transmission_sig,
|
218 |
+
'webhook_id' => $webhook_id,
|
219 |
+
'webhook_event' => $webhook_event,
|
220 |
+
)
|
221 |
+
),
|
222 |
+
);
|
223 |
+
$response = $this->request( $url, $args );
|
224 |
+
if ( is_wp_error( $response ) ) {
|
225 |
+
$error = new RuntimeException(
|
226 |
+
__( 'Not able to verify webhook event.', 'woocommerce-paypal-payments' )
|
227 |
+
);
|
228 |
+
$this->logger->log(
|
229 |
+
'warning',
|
230 |
+
$error->getMessage(),
|
231 |
+
array(
|
232 |
+
'args' => $args,
|
233 |
+
'response' => $response,
|
234 |
+
)
|
235 |
+
);
|
236 |
+
throw $error;
|
237 |
+
}
|
238 |
+
$json = json_decode( $response['body'] );
|
239 |
+
return isset( $json->verification_status ) && 'SUCCESS' === $json->verification_status;
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Verifies if the current request is a legit webhook event.
|
244 |
+
*
|
245 |
+
* @param Webhook $webhook The webhook.
|
246 |
+
*
|
247 |
+
* @return bool
|
248 |
+
* @throws RuntimeException If the request fails.
|
249 |
+
*/
|
250 |
+
public function verify_current_request_for_webhook( Webhook $webhook ): bool {
|
251 |
+
|
252 |
+
if ( ! $webhook->id() ) {
|
253 |
+
$error = new RuntimeException(
|
254 |
+
__( 'Not a valid webhook to verify.', 'woocommerce-paypal-payments' )
|
255 |
+
);
|
256 |
+
$this->logger->log( 'warning', $error->getMessage(), array( 'webhook' => $webhook ) );
|
257 |
+
throw $error;
|
258 |
+
}
|
259 |
+
|
260 |
+
$expected_headers = array(
|
261 |
+
'PAYPAL-AUTH-ALGO' => '',
|
262 |
+
'PAYPAL-CERT-URL' => '',
|
263 |
+
'PAYPAL-TRANSMISSION-ID' => '',
|
264 |
+
'PAYPAL-TRANSMISSION-SIG' => '',
|
265 |
+
'PAYPAL-TRANSMISSION-TIME' => '',
|
266 |
+
);
|
267 |
+
$headers = getallheaders();
|
268 |
+
foreach ( $headers as $key => $header ) {
|
269 |
+
$key = strtoupper( $key );
|
270 |
+
if ( isset( $expected_headers[ $key ] ) ) {
|
271 |
+
$expected_headers[ $key ] = $header;
|
272 |
+
}
|
273 |
+
};
|
274 |
+
|
275 |
+
foreach ( $expected_headers as $key => $value ) {
|
276 |
+
if ( ! empty( $value ) ) {
|
277 |
+
continue;
|
278 |
+
}
|
279 |
+
|
280 |
+
$error = new RuntimeException(
|
281 |
+
sprintf(
|
282 |
+
// translators: %s is the headers key.
|
283 |
+
__(
|
284 |
+
'Not a valid webhook event. Header %s is missing',
|
285 |
+
'woocommerce-paypal-payments'
|
286 |
+
),
|
287 |
+
$key
|
288 |
+
)
|
289 |
+
);
|
290 |
+
$this->logger->log( 'warning', $error->getMessage(), array( 'webhook' => $webhook ) );
|
291 |
+
throw $error;
|
292 |
+
}
|
293 |
+
|
294 |
+
$request_body = json_decode( file_get_contents( 'php://input' ) );
|
295 |
+
return $this->verify_event(
|
296 |
+
$expected_headers['PAYPAL-AUTH-ALGO'],
|
297 |
+
$expected_headers['PAYPAL-CERT-URL'],
|
298 |
+
$expected_headers['PAYPAL-TRANSMISSION-ID'],
|
299 |
+
$expected_headers['PAYPAL-TRANSMISSION-SIG'],
|
300 |
+
$expected_headers['PAYPAL-TRANSMISSION-TIME'],
|
301 |
+
$webhook->id(),
|
302 |
+
$request_body ? $request_body : new \stdClass()
|
303 |
+
);
|
304 |
+
}
|
305 |
+
}
|
modules/ppcp-api-client/src/Entity/class-address.php
ADDED
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The address object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Address
|
14 |
+
*/
|
15 |
+
class Address {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The country code.
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
private $country_code;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The 1st address line.
|
26 |
+
*
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
private $address_line_1;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* The 2nd address line.
|
33 |
+
*
|
34 |
+
* @var string
|
35 |
+
*/
|
36 |
+
private $address_line_2;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* The admin area 1.
|
40 |
+
*
|
41 |
+
* @var string
|
42 |
+
*/
|
43 |
+
private $admin_area_1;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* The admin area 2.
|
47 |
+
*
|
48 |
+
* @var string
|
49 |
+
*/
|
50 |
+
private $admin_area_2;
|
51 |
+
|
52 |
+
/**
|
53 |
+
* The postal code.
|
54 |
+
*
|
55 |
+
* @var string
|
56 |
+
*/
|
57 |
+
private $postal_code;
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Address constructor.
|
61 |
+
*
|
62 |
+
* @param string $country_code The country code.
|
63 |
+
* @param string $address_line_1 The 1st address line.
|
64 |
+
* @param string $address_line_2 The 2nd address line.
|
65 |
+
* @param string $admin_area_1 The admin area 1.
|
66 |
+
* @param string $admin_area_2 The admin area 2.
|
67 |
+
* @param string $postal_code The postal code.
|
68 |
+
*/
|
69 |
+
public function __construct(
|
70 |
+
string $country_code,
|
71 |
+
string $address_line_1 = '',
|
72 |
+
string $address_line_2 = '',
|
73 |
+
string $admin_area_1 = '',
|
74 |
+
string $admin_area_2 = '',
|
75 |
+
string $postal_code = ''
|
76 |
+
) {
|
77 |
+
|
78 |
+
$this->country_code = $country_code;
|
79 |
+
$this->address_line_1 = $address_line_1;
|
80 |
+
$this->address_line_2 = $address_line_2;
|
81 |
+
$this->admin_area_1 = $admin_area_1;
|
82 |
+
$this->admin_area_2 = $admin_area_2;
|
83 |
+
$this->postal_code = $postal_code;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Returns the country code.
|
88 |
+
*
|
89 |
+
* @return string
|
90 |
+
*/
|
91 |
+
public function country_code(): string {
|
92 |
+
return $this->country_code;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Returns the 1st address line.
|
97 |
+
*
|
98 |
+
* @return string
|
99 |
+
*/
|
100 |
+
public function address_line_1(): string {
|
101 |
+
return $this->address_line_1;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Returns the 2nd address line.
|
106 |
+
*
|
107 |
+
* @return string
|
108 |
+
*/
|
109 |
+
public function address_line_2(): string {
|
110 |
+
return $this->address_line_2;
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Returns the admin area 1.
|
115 |
+
*
|
116 |
+
* @return string
|
117 |
+
*/
|
118 |
+
public function admin_area_1(): string {
|
119 |
+
return $this->admin_area_1;
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Returns the admin area 2.
|
124 |
+
*
|
125 |
+
* @return string
|
126 |
+
*/
|
127 |
+
public function admin_area_2(): string {
|
128 |
+
return $this->admin_area_2;
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Returns the postal code.
|
133 |
+
*
|
134 |
+
* @return string
|
135 |
+
*/
|
136 |
+
public function postal_code(): string {
|
137 |
+
return $this->postal_code;
|
138 |
+
}
|
139 |
+
|
140 |
+
/**
|
141 |
+
* Returns the object as array.
|
142 |
+
*
|
143 |
+
* @return array
|
144 |
+
*/
|
145 |
+
public function to_array(): array {
|
146 |
+
return array(
|
147 |
+
'country_code' => $this->country_code(),
|
148 |
+
'address_line_1' => $this->address_line_1(),
|
149 |
+
'address_line_2' => $this->address_line_2(),
|
150 |
+
'admin_area_1' => $this->admin_area_1(),
|
151 |
+
'admin_area_2' => $this->admin_area_2(),
|
152 |
+
'postal_code' => $this->postal_code(),
|
153 |
+
);
|
154 |
+
}
|
155 |
+
}
|
modules/ppcp-api-client/src/Entity/class-amount.php
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The amount object
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Amount
|
14 |
+
*/
|
15 |
+
class Amount {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The money.
|
19 |
+
*
|
20 |
+
* @var Money
|
21 |
+
*/
|
22 |
+
private $money;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The breakdown.
|
26 |
+
*
|
27 |
+
* @var AmountBreakdown
|
28 |
+
*/
|
29 |
+
private $breakdown;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Amount constructor.
|
33 |
+
*
|
34 |
+
* @param Money $money The money.
|
35 |
+
* @param AmountBreakdown|null $breakdown The breakdown.
|
36 |
+
*/
|
37 |
+
public function __construct( Money $money, AmountBreakdown $breakdown = null ) {
|
38 |
+
$this->money = $money;
|
39 |
+
$this->breakdown = $breakdown;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Returns the currency code.
|
44 |
+
*
|
45 |
+
* @return string
|
46 |
+
*/
|
47 |
+
public function currency_code(): string {
|
48 |
+
return $this->money->currency_code();
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Returns the value.
|
53 |
+
*
|
54 |
+
* @return float
|
55 |
+
*/
|
56 |
+
public function value(): float {
|
57 |
+
return $this->money->value();
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Returns the breakdown.
|
62 |
+
*
|
63 |
+
* @return AmountBreakdown|null
|
64 |
+
*/
|
65 |
+
public function breakdown() {
|
66 |
+
return $this->breakdown;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Returns the object as array.
|
71 |
+
*
|
72 |
+
* @return array
|
73 |
+
*/
|
74 |
+
public function to_array(): array {
|
75 |
+
$amount = array(
|
76 |
+
'currency_code' => $this->currency_code(),
|
77 |
+
'value' => $this->value(),
|
78 |
+
);
|
79 |
+
if ( $this->breakdown() && count( $this->breakdown()->to_array() ) ) {
|
80 |
+
$amount['breakdown'] = $this->breakdown()->to_array();
|
81 |
+
}
|
82 |
+
return $amount;
|
83 |
+
}
|
84 |
+
}
|
modules/ppcp-api-client/src/Entity/class-amountbreakdown.php
ADDED
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The Amount Breakdown object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class AmountBreakdown
|
14 |
+
*/
|
15 |
+
class AmountBreakdown {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The item total.
|
19 |
+
*
|
20 |
+
* @var Money
|
21 |
+
*/
|
22 |
+
private $item_total;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The shipping.
|
26 |
+
*
|
27 |
+
* @var Money
|
28 |
+
*/
|
29 |
+
private $shipping;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* The tax total.
|
33 |
+
*
|
34 |
+
* @var Money
|
35 |
+
*/
|
36 |
+
private $tax_total;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* The handling.
|
40 |
+
*
|
41 |
+
* @var Money
|
42 |
+
*/
|
43 |
+
private $handling;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* The insurance.
|
47 |
+
*
|
48 |
+
* @var Money
|
49 |
+
*/
|
50 |
+
private $insurance;
|
51 |
+
|
52 |
+
/**
|
53 |
+
* The shipping discount.
|
54 |
+
*
|
55 |
+
* @var Money
|
56 |
+
*/
|
57 |
+
private $shipping_discount;
|
58 |
+
|
59 |
+
/**
|
60 |
+
* The discount.
|
61 |
+
*
|
62 |
+
* @var Money
|
63 |
+
*/
|
64 |
+
private $discount;
|
65 |
+
|
66 |
+
/**
|
67 |
+
* AmountBreakdown constructor.
|
68 |
+
*
|
69 |
+
* @param Money|null $item_total The item total.
|
70 |
+
* @param Money|null $shipping The shipping.
|
71 |
+
* @param Money|null $tax_total The tax total.
|
72 |
+
* @param Money|null $handling The handling.
|
73 |
+
* @param Money|null $insurance The insurance.
|
74 |
+
* @param Money|null $shipping_discount The shipping discount.
|
75 |
+
* @param Money|null $discount The discount.
|
76 |
+
*/
|
77 |
+
public function __construct(
|
78 |
+
Money $item_total = null,
|
79 |
+
Money $shipping = null,
|
80 |
+
Money $tax_total = null,
|
81 |
+
Money $handling = null,
|
82 |
+
Money $insurance = null,
|
83 |
+
Money $shipping_discount = null,
|
84 |
+
Money $discount = null
|
85 |
+
) {
|
86 |
+
|
87 |
+
$this->item_total = $item_total;
|
88 |
+
$this->shipping = $shipping;
|
89 |
+
$this->tax_total = $tax_total;
|
90 |
+
$this->handling = $handling;
|
91 |
+
$this->insurance = $insurance;
|
92 |
+
$this->shipping_discount = $shipping_discount;
|
93 |
+
$this->discount = $discount;
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Returns the item total.
|
98 |
+
*
|
99 |
+
* @return Money|null
|
100 |
+
*/
|
101 |
+
public function item_total() {
|
102 |
+
return $this->item_total;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Returns the shipping.
|
107 |
+
*
|
108 |
+
* @return Money|null
|
109 |
+
*/
|
110 |
+
public function shipping() {
|
111 |
+
return $this->shipping;
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Returns the tax total.
|
116 |
+
*
|
117 |
+
* @return Money|null
|
118 |
+
*/
|
119 |
+
public function tax_total() {
|
120 |
+
return $this->tax_total;
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Returns the handling.
|
125 |
+
*
|
126 |
+
* @return Money|null
|
127 |
+
*/
|
128 |
+
public function handling() {
|
129 |
+
return $this->handling;
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Returns the insurance.
|
134 |
+
*
|
135 |
+
* @return Money|null
|
136 |
+
*/
|
137 |
+
public function insurance() {
|
138 |
+
return $this->insurance;
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Returns the shipping discount.
|
143 |
+
*
|
144 |
+
* @return Money|null
|
145 |
+
*/
|
146 |
+
public function shipping_discount() {
|
147 |
+
return $this->shipping_discount;
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Returns the discount.
|
152 |
+
*
|
153 |
+
* @return Money|null
|
154 |
+
*/
|
155 |
+
public function discount() {
|
156 |
+
return $this->discount;
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* Returns the object as array.
|
161 |
+
*
|
162 |
+
* @return array
|
163 |
+
*/
|
164 |
+
public function to_array() {
|
165 |
+
$breakdown = array();
|
166 |
+
if ( $this->item_total ) {
|
167 |
+
$breakdown['item_total'] = $this->item_total->to_array();
|
168 |
+
}
|
169 |
+
if ( $this->shipping ) {
|
170 |
+
$breakdown['shipping'] = $this->shipping->to_array();
|
171 |
+
}
|
172 |
+
if ( $this->tax_total ) {
|
173 |
+
$breakdown['tax_total'] = $this->tax_total->to_array();
|
174 |
+
}
|
175 |
+
if ( $this->handling ) {
|
176 |
+
$breakdown['handling'] = $this->handling->to_array();
|
177 |
+
}
|
178 |
+
if ( $this->insurance ) {
|
179 |
+
$breakdown['insurance'] = $this->insurance->to_array();
|
180 |
+
}
|
181 |
+
if ( $this->shipping_discount ) {
|
182 |
+
$breakdown['shipping_discount'] = $this->shipping_discount->to_array();
|
183 |
+
}
|
184 |
+
if ( $this->discount ) {
|
185 |
+
$breakdown['discount'] = $this->discount->to_array();
|
186 |
+
}
|
187 |
+
|
188 |
+
return $breakdown;
|
189 |
+
}
|
190 |
+
}
|
modules/ppcp-api-client/src/Entity/class-applicationcontext.php
ADDED
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The application context object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class ApplicationContext
|
16 |
+
*/
|
17 |
+
class ApplicationContext {
|
18 |
+
|
19 |
+
const LANDING_PAGE_LOGIN = 'LOGIN';
|
20 |
+
const LANDING_PAGE_BILLING = 'BILLING';
|
21 |
+
const LANDING_PAGE_NO_PREFERENCE = 'NO_PREFERENCE';
|
22 |
+
const VALID_LANDING_PAGE_VALUES = array(
|
23 |
+
self::LANDING_PAGE_LOGIN,
|
24 |
+
self::LANDING_PAGE_BILLING,
|
25 |
+
self::LANDING_PAGE_NO_PREFERENCE,
|
26 |
+
);
|
27 |
+
|
28 |
+
const SHIPPING_PREFERENCE_GET_FROM_FILE = 'GET_FROM_FILE';
|
29 |
+
const SHIPPING_PREFERENCE_NO_SHIPPING = 'NO_SHIPPING';
|
30 |
+
const SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS = 'SET_PROVIDED_ADDRESS';
|
31 |
+
const VALID_SHIPPING_PREFERENCE_VALUES = array(
|
32 |
+
self::SHIPPING_PREFERENCE_GET_FROM_FILE,
|
33 |
+
self::SHIPPING_PREFERENCE_NO_SHIPPING,
|
34 |
+
self::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS,
|
35 |
+
);
|
36 |
+
|
37 |
+
const USER_ACTION_CONTINUE = 'CONTINUE';
|
38 |
+
const USER_ACTION_PAY_NOW = 'PAY_NOW';
|
39 |
+
const VALID_USER_ACTION_VALUES = array(
|
40 |
+
self::USER_ACTION_CONTINUE,
|
41 |
+
self::USER_ACTION_PAY_NOW,
|
42 |
+
);
|
43 |
+
|
44 |
+
/**
|
45 |
+
* The brand name.
|
46 |
+
*
|
47 |
+
* @var string
|
48 |
+
*/
|
49 |
+
private $brand_name;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* The locale.
|
53 |
+
*
|
54 |
+
* @var string
|
55 |
+
*/
|
56 |
+
private $locale;
|
57 |
+
|
58 |
+
/**
|
59 |
+
* The landing page.
|
60 |
+
*
|
61 |
+
* @var string
|
62 |
+
*/
|
63 |
+
private $landing_page;
|
64 |
+
|
65 |
+
/**
|
66 |
+
* The shipping preference.
|
67 |
+
*
|
68 |
+
* @var string
|
69 |
+
*/
|
70 |
+
private $shipping_preference;
|
71 |
+
|
72 |
+
/**
|
73 |
+
* The user action.
|
74 |
+
*
|
75 |
+
* @var string
|
76 |
+
*/
|
77 |
+
private $user_action;
|
78 |
+
|
79 |
+
/**
|
80 |
+
* The return url.
|
81 |
+
*
|
82 |
+
* @var string
|
83 |
+
*/
|
84 |
+
private $return_url;
|
85 |
+
|
86 |
+
/**
|
87 |
+
* The cancel url.
|
88 |
+
*
|
89 |
+
* @var string
|
90 |
+
*/
|
91 |
+
private $cancel_url;
|
92 |
+
|
93 |
+
/**
|
94 |
+
* The payment method.
|
95 |
+
*
|
96 |
+
* @var null
|
97 |
+
*/
|
98 |
+
private $payment_method;
|
99 |
+
|
100 |
+
/**
|
101 |
+
* ApplicationContext constructor.
|
102 |
+
*
|
103 |
+
* @param string $return_url The return URL.
|
104 |
+
* @param string $cancel_url The cancel URL.
|
105 |
+
* @param string $brand_name The brand name.
|
106 |
+
* @param string $locale The locale.
|
107 |
+
* @param string $landing_page The landing page.
|
108 |
+
* @param string $shipping_preference The shipping preference.
|
109 |
+
* @param string $user_action The user action.
|
110 |
+
*
|
111 |
+
* @throws RuntimeException When values are not valid.
|
112 |
+
*/
|
113 |
+
public function __construct(
|
114 |
+
string $return_url = '',
|
115 |
+
string $cancel_url = '',
|
116 |
+
string $brand_name = '',
|
117 |
+
string $locale = '',
|
118 |
+
string $landing_page = self::LANDING_PAGE_NO_PREFERENCE,
|
119 |
+
string $shipping_preference = self::SHIPPING_PREFERENCE_NO_SHIPPING,
|
120 |
+
string $user_action = self::USER_ACTION_CONTINUE
|
121 |
+
) {
|
122 |
+
|
123 |
+
if ( ! in_array( $landing_page, self::VALID_LANDING_PAGE_VALUES, true ) ) {
|
124 |
+
throw new RuntimeException( 'Landingpage not correct' );
|
125 |
+
}
|
126 |
+
if ( ! in_array( $shipping_preference, self::VALID_SHIPPING_PREFERENCE_VALUES, true ) ) {
|
127 |
+
throw new RuntimeException( 'Shipping preference not correct' );
|
128 |
+
}
|
129 |
+
if ( ! in_array( $user_action, self::VALID_USER_ACTION_VALUES, true ) ) {
|
130 |
+
throw new RuntimeException( 'User action preference not correct' );
|
131 |
+
}
|
132 |
+
$this->return_url = $return_url;
|
133 |
+
$this->cancel_url = $cancel_url;
|
134 |
+
$this->brand_name = $brand_name;
|
135 |
+
$this->locale = $locale;
|
136 |
+
$this->landing_page = $landing_page;
|
137 |
+
$this->shipping_preference = $shipping_preference;
|
138 |
+
$this->user_action = $user_action;
|
139 |
+
|
140 |
+
// Currently we have not implemented the payment method.
|
141 |
+
$this->payment_method = null;
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Returns the brand name.
|
146 |
+
*
|
147 |
+
* @return string
|
148 |
+
*/
|
149 |
+
public function brand_name(): string {
|
150 |
+
return $this->brand_name;
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Returns the locale.
|
155 |
+
*
|
156 |
+
* @return string
|
157 |
+
*/
|
158 |
+
public function locale(): string {
|
159 |
+
return $this->locale;
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Returns the landing page.
|
164 |
+
*
|
165 |
+
* @return string
|
166 |
+
*/
|
167 |
+
public function landing_page(): string {
|
168 |
+
return $this->landing_page;
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Returns the shipping preference.
|
173 |
+
*
|
174 |
+
* @return string
|
175 |
+
*/
|
176 |
+
public function shipping_preference(): string {
|
177 |
+
return $this->shipping_preference;
|
178 |
+
}
|
179 |
+
|
180 |
+
/**
|
181 |
+
* Returns the user action.
|
182 |
+
*
|
183 |
+
* @return string
|
184 |
+
*/
|
185 |
+
public function user_action(): string {
|
186 |
+
return $this->user_action;
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Returns the return URL.
|
191 |
+
*
|
192 |
+
* @return string
|
193 |
+
*/
|
194 |
+
public function return_url(): string {
|
195 |
+
return $this->return_url;
|
196 |
+
}
|
197 |
+
|
198 |
+
/**
|
199 |
+
* Returns the cancel URL.
|
200 |
+
*
|
201 |
+
* @return string
|
202 |
+
*/
|
203 |
+
public function cancel_url(): string {
|
204 |
+
return $this->cancel_url;
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Returns the payment method.
|
209 |
+
*
|
210 |
+
* @return PaymentMethod|null
|
211 |
+
*/
|
212 |
+
public function payment_method() {
|
213 |
+
return $this->payment_method;
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Returns the object as array.
|
218 |
+
*
|
219 |
+
* @return array
|
220 |
+
*/
|
221 |
+
public function to_array(): array {
|
222 |
+
$data = array();
|
223 |
+
if ( $this->user_action() ) {
|
224 |
+
$data['user_action'] = $this->user_action();
|
225 |
+
}
|
226 |
+
if ( $this->payment_method() ) {
|
227 |
+
$data['payment_method'] = $this->payment_method();
|
228 |
+
}
|
229 |
+
if ( $this->shipping_preference() ) {
|
230 |
+
$data['shipping_preference'] = $this->shipping_preference();
|
231 |
+
}
|
232 |
+
if ( $this->landing_page() ) {
|
233 |
+
$data['landing_page'] = $this->landing_page();
|
234 |
+
}
|
235 |
+
if ( $this->locale() ) {
|
236 |
+
$data['locale'] = $this->locale();
|
237 |
+
}
|
238 |
+
if ( $this->brand_name() ) {
|
239 |
+
$data['brand_name'] = $this->brand_name();
|
240 |
+
}
|
241 |
+
if ( $this->return_url() ) {
|
242 |
+
$data['return_url'] = $this->return_url();
|
243 |
+
}
|
244 |
+
if ( $this->cancel_url() ) {
|
245 |
+
$data['cancel_url'] = $this->cancel_url();
|
246 |
+
}
|
247 |
+
return $data;
|
248 |
+
}
|
249 |
+
}
|
modules/ppcp-api-client/src/Entity/class-authorization.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The Authorization object
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Authorization
|
14 |
+
*/
|
15 |
+
class Authorization {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The Id.
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
private $id;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The status.
|
26 |
+
*
|
27 |
+
* @var AuthorizationStatus
|
28 |
+
*/
|
29 |
+
private $authorization_status;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Authorization constructor.
|
33 |
+
*
|
34 |
+
* @param string $id The id.
|
35 |
+
* @param AuthorizationStatus $authorization_status The status.
|
36 |
+
*/
|
37 |
+
public function __construct(
|
38 |
+
string $id,
|
39 |
+
AuthorizationStatus $authorization_status
|
40 |
+
) {
|
41 |
+
|
42 |
+
$this->id = $id;
|
43 |
+
$this->authorization_status = $authorization_status;
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Returns the Id.
|
48 |
+
*
|
49 |
+
* @return string
|
50 |
+
*/
|
51 |
+
public function id(): string {
|
52 |
+
return $this->id;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Returns the status.
|
57 |
+
*
|
58 |
+
* @return AuthorizationStatus
|
59 |
+
*/
|
60 |
+
public function status(): AuthorizationStatus {
|
61 |
+
return $this->authorization_status;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Returns the object as array.
|
66 |
+
*
|
67 |
+
* @return array
|
68 |
+
*/
|
69 |
+
public function to_array(): array {
|
70 |
+
return array(
|
71 |
+
'id' => $this->id,
|
72 |
+
'status' => $this->authorization_status->name(),
|
73 |
+
);
|
74 |
+
}
|
75 |
+
}
|
modules/ppcp-api-client/src/Entity/class-authorizationstatus.php
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The AuthorizationStatus object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class AuthorizationStatus
|
16 |
+
*/
|
17 |
+
class AuthorizationStatus {
|
18 |
+
|
19 |
+
const INTERNAL = 'INTERNAL';
|
20 |
+
const CREATED = 'CREATED';
|
21 |
+
const CAPTURED = 'CAPTURED';
|
22 |
+
const COMPLETED = 'COMPLETED';
|
23 |
+
const DENIED = 'DENIED';
|
24 |
+
const EXPIRED = 'EXPIRED';
|
25 |
+
const PARTIALLY_CAPTURED = 'PARTIALLY_CAPTURED';
|
26 |
+
const VOIDED = 'VOIDED';
|
27 |
+
const PENDING = 'PENDING';
|
28 |
+
const VALID_STATUS = array(
|
29 |
+
self::INTERNAL,
|
30 |
+
self::CREATED,
|
31 |
+
self::CAPTURED,
|
32 |
+
self::COMPLETED,
|
33 |
+
self::DENIED,
|
34 |
+
self::EXPIRED,
|
35 |
+
self::PARTIALLY_CAPTURED,
|
36 |
+
self::VOIDED,
|
37 |
+
self::PENDING,
|
38 |
+
);
|
39 |
+
|
40 |
+
/**
|
41 |
+
* The status.
|
42 |
+
*
|
43 |
+
* @var string
|
44 |
+
*/
|
45 |
+
private $status;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* AuthorizationStatus constructor.
|
49 |
+
*
|
50 |
+
* @param string $status The status.
|
51 |
+
* @throws RuntimeException When the status is not valid.
|
52 |
+
*/
|
53 |
+
public function __construct( string $status ) {
|
54 |
+
if ( ! in_array( $status, self::VALID_STATUS, true ) ) {
|
55 |
+
throw new RuntimeException(
|
56 |
+
sprintf(
|
57 |
+
// translators: %s is the current status.
|
58 |
+
__( '%s is not a valid status', 'woocommerce-paypal-payments' ),
|
59 |
+
$status
|
60 |
+
)
|
61 |
+
);
|
62 |
+
}
|
63 |
+
$this->status = $status;
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Returns an AuthorizationStatus as Internal.
|
68 |
+
*
|
69 |
+
* @return AuthorizationStatus
|
70 |
+
*/
|
71 |
+
public static function as_internal(): AuthorizationStatus {
|
72 |
+
return new self( self::INTERNAL );
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Compares the current status with a given one.
|
77 |
+
*
|
78 |
+
* @param string $status The status to compare with.
|
79 |
+
*
|
80 |
+
* @return bool
|
81 |
+
*/
|
82 |
+
public function is( string $status ): bool {
|
83 |
+
return $this->status === $status;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Returns the status.
|
88 |
+
*
|
89 |
+
* @return string
|
90 |
+
*/
|
91 |
+
public function name(): string {
|
92 |
+
return $this->status;
|
93 |
+
}
|
94 |
+
}
|
modules/ppcp-api-client/src/Entity/class-capture.php
ADDED
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The capture entity.
|
4 |
+
*
|
5 |
+
* @link https://developer.paypal.com/docs/api/orders/v2/#definition-capture
|
6 |
+
*
|
7 |
+
* @package Woocommerce\PayPalCommerce\ApiClient\Entity
|
8 |
+
*/
|
9 |
+
|
10 |
+
declare( strict_types=1 );
|
11 |
+
|
12 |
+
namespace Woocommerce\PayPalCommerce\ApiClient\Entity;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class Capture
|
16 |
+
*/
|
17 |
+
class Capture {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* The ID.
|
21 |
+
*
|
22 |
+
* @var string
|
23 |
+
*/
|
24 |
+
private $id;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* The status.
|
28 |
+
*
|
29 |
+
* @var string
|
30 |
+
*/
|
31 |
+
private $status;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* The status details.
|
35 |
+
*
|
36 |
+
* @var string
|
37 |
+
*/
|
38 |
+
private $status_details;
|
39 |
+
|
40 |
+
/**
|
41 |
+
* The amount.
|
42 |
+
*
|
43 |
+
* @var Amount
|
44 |
+
*/
|
45 |
+
private $amount;
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Whether this is the final capture or not.
|
49 |
+
*
|
50 |
+
* @var bool
|
51 |
+
*/
|
52 |
+
private $final_capture;
|
53 |
+
|
54 |
+
/**
|
55 |
+
* The seller protection.
|
56 |
+
*
|
57 |
+
* @var string
|
58 |
+
*/
|
59 |
+
private $seller_protection;
|
60 |
+
|
61 |
+
/**
|
62 |
+
* The invoice id.
|
63 |
+
*
|
64 |
+
* @var string
|
65 |
+
*/
|
66 |
+
private $invoice_id;
|
67 |
+
|
68 |
+
/**
|
69 |
+
* The custom id.
|
70 |
+
*
|
71 |
+
* @var string
|
72 |
+
*/
|
73 |
+
private $custom_id;
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Capture constructor.
|
77 |
+
*
|
78 |
+
* @param string $id The ID.
|
79 |
+
* @param string $status The status.
|
80 |
+
* @param string $status_details The status details.
|
81 |
+
* @param Amount $amount The amount.
|
82 |
+
* @param bool $final_capture The final capture.
|
83 |
+
* @param string $seller_protection The seller protection.
|
84 |
+
* @param string $invoice_id The invoice id.
|
85 |
+
* @param string $custom_id The custom id.
|
86 |
+
*/
|
87 |
+
public function __construct(
|
88 |
+
string $id,
|
89 |
+
string $status,
|
90 |
+
string $status_details,
|
91 |
+
Amount $amount,
|
92 |
+
bool $final_capture,
|
93 |
+
string $seller_protection,
|
94 |
+
string $invoice_id,
|
95 |
+
string $custom_id
|
96 |
+
) {
|
97 |
+
|
98 |
+
$this->id = $id;
|
99 |
+
$this->status = $status;
|
100 |
+
$this->status_details = $status_details;
|
101 |
+
$this->amount = $amount;
|
102 |
+
$this->final_capture = $final_capture;
|
103 |
+
$this->seller_protection = $seller_protection;
|
104 |
+
$this->invoice_id = $invoice_id;
|
105 |
+
$this->custom_id = $custom_id;
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Returns the ID.
|
110 |
+
*
|
111 |
+
* @return string
|
112 |
+
*/
|
113 |
+
public function id() : string {
|
114 |
+
return $this->id;
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Returns the status.
|
119 |
+
*
|
120 |
+
* @return string
|
121 |
+
*/
|
122 |
+
public function status() : string {
|
123 |
+
return $this->status;
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Returns the status details object.
|
128 |
+
*
|
129 |
+
* @return \stdClass
|
130 |
+
*/
|
131 |
+
public function status_details() : \stdClass {
|
132 |
+
return (object) array( 'reason' => $this->status_details );
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Returns the amount.
|
137 |
+
*
|
138 |
+
* @return Amount
|
139 |
+
*/
|
140 |
+
public function amount() : Amount {
|
141 |
+
return $this->amount;
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Returns whether this is the final capture or not.
|
146 |
+
*
|
147 |
+
* @return bool
|
148 |
+
*/
|
149 |
+
public function final_capture() : bool {
|
150 |
+
return $this->final_capture;
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Returns the seller protection object.
|
155 |
+
*
|
156 |
+
* @return \stdClass
|
157 |
+
*/
|
158 |
+
public function seller_protection() : \stdClass {
|
159 |
+
return (object) array( 'status' => $this->seller_protection );
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Returns the invoice id.
|
164 |
+
*
|
165 |
+
* @return string
|
166 |
+
*/
|
167 |
+
public function invoice_id() : string {
|
168 |
+
return $this->invoice_id;
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Returns the custom id.
|
173 |
+
*
|
174 |
+
* @return string
|
175 |
+
*/
|
176 |
+
public function custom_id() : string {
|
177 |
+
return $this->custom_id;
|
178 |
+
}
|
179 |
+
|
180 |
+
/**
|
181 |
+
* Returns the entity as array.
|
182 |
+
*
|
183 |
+
* @return array
|
184 |
+
*/
|
185 |
+
public function to_array() : array {
|
186 |
+
return array(
|
187 |
+
'id' => $this->id(),
|
188 |
+
'status' => $this->status(),
|
189 |
+
'status_details' => (array) $this->status_details(),
|
190 |
+
'amount' => $this->amount()->to_array(),
|
191 |
+
'final_capture' => $this->final_capture(),
|
192 |
+
'seller_protection' => (array) $this->seller_protection(),
|
193 |
+
'invoice_id' => $this->invoice_id(),
|
194 |
+
'custom_id' => $this->custom_id(),
|
195 |
+
);
|
196 |
+
}
|
197 |
+
}
|
modules/ppcp-api-client/src/Entity/class-cardauthenticationresult.php
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The CardauthenticationResult object
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class CardAuthenticationResult
|
14 |
+
*/
|
15 |
+
class CardAuthenticationResult {
|
16 |
+
|
17 |
+
|
18 |
+
const LIABILITY_SHIFT_POSSIBLE = 'POSSIBLE';
|
19 |
+
const LIABILITY_SHIFT_NO = 'NO';
|
20 |
+
const LIABILITY_SHIFT_UNKNOWN = 'UNKNOWN';
|
21 |
+
|
22 |
+
const ENROLLMENT_STATUS_YES = 'Y';
|
23 |
+
const ENROLLMENT_STATUS_NO = 'N';
|
24 |
+
const ENROLLMENT_STATUS_UNAVAILABLE = 'U';
|
25 |
+
const ENROLLMENT_STATUS_BYPASS = 'B';
|
26 |
+
|
27 |
+
const AUTHENTICATION_RESULT_YES = 'Y';
|
28 |
+
const AUTHENTICATION_RESULT_NO = 'N';
|
29 |
+
const AUTHENTICATION_RESULT_REJECTED = 'R';
|
30 |
+
const AUTHENTICATION_RESULT_ATTEMPTED = 'A';
|
31 |
+
const AUTHENTICATION_RESULT_UNABLE = 'U';
|
32 |
+
const AUTHENTICATION_RESULT_CHALLENGE_REQUIRED = 'C';
|
33 |
+
const AUTHENTICATION_RESULT_INFO = 'I';
|
34 |
+
const AUTHENTICATION_RESULT_DECOUPLED = 'D';
|
35 |
+
|
36 |
+
/**
|
37 |
+
* The liability shift.
|
38 |
+
*
|
39 |
+
* @var string
|
40 |
+
*/
|
41 |
+
private $liability_shift;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* The enrollment status.
|
45 |
+
*
|
46 |
+
* @var string
|
47 |
+
*/
|
48 |
+
private $enrollment_status;
|
49 |
+
|
50 |
+
/**
|
51 |
+
* The authentication result.
|
52 |
+
*
|
53 |
+
* @var string
|
54 |
+
*/
|
55 |
+
private $authentication_result;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* CardAuthenticationResult constructor.
|
59 |
+
*
|
60 |
+
* @param string $liability_shift The liability shift.
|
61 |
+
* @param string $enrollment_status The enrollment status.
|
62 |
+
* @param string $authentication_result The authentication result.
|
63 |
+
*/
|
64 |
+
public function __construct(
|
65 |
+
string $liability_shift,
|
66 |
+
string $enrollment_status,
|
67 |
+
string $authentication_result
|
68 |
+
) {
|
69 |
+
|
70 |
+
$this->liability_shift = strtoupper( $liability_shift );
|
71 |
+
$this->enrollment_status = strtoupper( $enrollment_status );
|
72 |
+
$this->authentication_result = strtoupper( $authentication_result );
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Returns the liability shift.
|
77 |
+
*
|
78 |
+
* @return string
|
79 |
+
*/
|
80 |
+
public function liability_shift(): string {
|
81 |
+
|
82 |
+
return $this->liability_shift;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Returns the enrollment status.
|
87 |
+
*
|
88 |
+
* @return string
|
89 |
+
*/
|
90 |
+
public function enrollment_status(): string {
|
91 |
+
|
92 |
+
return $this->enrollment_status;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Returns the authentication result.
|
97 |
+
*
|
98 |
+
* @return string
|
99 |
+
*/
|
100 |
+
public function authentication_result(): string {
|
101 |
+
|
102 |
+
return $this->authentication_result;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Returns the object as array.
|
107 |
+
*
|
108 |
+
* @return array
|
109 |
+
*/
|
110 |
+
public function to_array(): array {
|
111 |
+
$data = array();
|
112 |
+
$data['liability_shift'] = $this->liability_shift();
|
113 |
+
$data['three_d_secure'] = array(
|
114 |
+
'enrollment_status' => $this->enrollment_status(),
|
115 |
+
'authentication_result' => $this->authentication_result(),
|
116 |
+
);
|
117 |
+
return $data;
|
118 |
+
}
|
119 |
+
}
|
modules/ppcp-api-client/src/Entity/class-item.php
ADDED
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The item object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Item
|
14 |
+
*/
|
15 |
+
class Item {
|
16 |
+
|
17 |
+
|
18 |
+
const PHYSICAL_GOODS = 'PHYSICAL_GOODS';
|
19 |
+
const DIGITAL_GOODS = 'DIGITAL_GOODS';
|
20 |
+
|
21 |
+
/**
|
22 |
+
* The name.
|
23 |
+
*
|
24 |
+
* @var string
|
25 |
+
*/
|
26 |
+
private $name;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* The unit amount.
|
30 |
+
*
|
31 |
+
* @var Money
|
32 |
+
*/
|
33 |
+
private $unit_amount;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* The quantity.
|
37 |
+
*
|
38 |
+
* @var int
|
39 |
+
*/
|
40 |
+
private $quantity;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* The description.
|
44 |
+
*
|
45 |
+
* @var string
|
46 |
+
*/
|
47 |
+
private $description;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* The tax.
|
51 |
+
*
|
52 |
+
* @var Money|null
|
53 |
+
*/
|
54 |
+
private $tax;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* The SKU.
|
58 |
+
*
|
59 |
+
* @var string
|
60 |
+
*/
|
61 |
+
private $sku;
|
62 |
+
|
63 |
+
/**
|
64 |
+
* The category.
|
65 |
+
*
|
66 |
+
* @var string
|
67 |
+
*/
|
68 |
+
private $category;
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Item constructor.
|
72 |
+
*
|
73 |
+
* @param string $name The name.
|
74 |
+
* @param Money $unit_amount The unit amount.
|
75 |
+
* @param int $quantity The quantity.
|
76 |
+
* @param string $description The description.
|
77 |
+
* @param Money|null $tax The tax.
|
78 |
+
* @param string $sku The SKU.
|
79 |
+
* @param string $category The category.
|
80 |
+
*/
|
81 |
+
public function __construct(
|
82 |
+
string $name,
|
83 |
+
Money $unit_amount,
|
84 |
+
int $quantity,
|
85 |
+
string $description = '',
|
86 |
+
Money $tax = null,
|
87 |
+
string $sku = '',
|
88 |
+
string $category = 'PHYSICAL_GOODS'
|
89 |
+
) {
|
90 |
+
|
91 |
+
$this->name = $name;
|
92 |
+
$this->unit_amount = $unit_amount;
|
93 |
+
$this->quantity = $quantity;
|
94 |
+
$this->description = $description;
|
95 |
+
$this->tax = $tax;
|
96 |
+
$this->sku = $sku;
|
97 |
+
$this->category = ( self::DIGITAL_GOODS === $category ) ?
|
98 |
+
self::DIGITAL_GOODS : self::PHYSICAL_GOODS;
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Returns the name of the item.
|
103 |
+
*
|
104 |
+
* @return string
|
105 |
+
*/
|
106 |
+
public function name(): string {
|
107 |
+
return $this->name;
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Returns the unit amount.
|
112 |
+
*
|
113 |
+
* @return Money
|
114 |
+
*/
|
115 |
+
public function unit_amount(): Money {
|
116 |
+
return $this->unit_amount;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Returns the quantity.
|
121 |
+
*
|
122 |
+
* @return int
|
123 |
+
*/
|
124 |
+
public function quantity(): int {
|
125 |
+
return $this->quantity;
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Returns the description.
|
130 |
+
*
|
131 |
+
* @return string
|
132 |
+
*/
|
133 |
+
public function description(): string {
|
134 |
+
return $this->description;
|
135 |
+
}
|
136 |
+
|
137 |
+
/**
|
138 |
+
* Returns the tax.
|
139 |
+
*
|
140 |
+
* @return Money|null
|
141 |
+
*/
|
142 |
+
public function tax() {
|
143 |
+
return $this->tax;
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Returns the SKU.
|
148 |
+
*
|
149 |
+
* @return string
|
150 |
+
*/
|
151 |
+
public function sku() {
|
152 |
+
return $this->sku;
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Returns the category.
|
157 |
+
*
|
158 |
+
* @return string
|
159 |
+
*/
|
160 |
+
public function category() {
|
161 |
+
return $this->category;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Returns the object as array.
|
166 |
+
*
|
167 |
+
* @return array
|
168 |
+
*/
|
169 |
+
public function to_array() {
|
170 |
+
$item = array(
|
171 |
+
'name' => $this->name(),
|
172 |
+
'unit_amount' => $this->unit_amount()->to_array(),
|
173 |
+
'quantity' => $this->quantity(),
|
174 |
+
'description' => $this->description(),
|
175 |
+
'sku' => $this->sku(),
|
176 |
+
'category' => $this->category(),
|
177 |
+
);
|
178 |
+
|
179 |
+
if ( $this->tax() ) {
|
180 |
+
$item['tax'] = $this->tax()->to_array();
|
181 |
+
}
|
182 |
+
|
183 |
+
return $item;
|
184 |
+
}
|
185 |
+
}
|
modules/ppcp-api-client/src/Entity/class-money.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The money object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Money
|
14 |
+
*/
|
15 |
+
class Money {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The currency code.
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
private $currency_code;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The value.
|
26 |
+
*
|
27 |
+
* @var float
|
28 |
+
*/
|
29 |
+
private $value;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Money constructor.
|
33 |
+
*
|
34 |
+
* @param float $value The value.
|
35 |
+
* @param string $currency_code The currency code.
|
36 |
+
*/
|
37 |
+
public function __construct( float $value, string $currency_code ) {
|
38 |
+
$this->value = $value;
|
39 |
+
$this->currency_code = $currency_code;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* The value.
|
44 |
+
*
|
45 |
+
* @return float
|
46 |
+
*/
|
47 |
+
public function value(): float {
|
48 |
+
return $this->value;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* The currency code.
|
53 |
+
*
|
54 |
+
* @return string
|
55 |
+
*/
|
56 |
+
public function currency_code(): string {
|
57 |
+
return $this->currency_code;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Returns the object as array.
|
62 |
+
*
|
63 |
+
* @return array
|
64 |
+
*/
|
65 |
+
public function to_array(): array {
|
66 |
+
return array(
|
67 |
+
'currency_code' => $this->currency_code(),
|
68 |
+
'value' => number_format( $this->value(), 2 ),
|
69 |
+
);
|
70 |
+
}
|
71 |
+
}
|
modules/ppcp-api-client/src/Entity/class-order.php
ADDED
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The order object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Order
|
14 |
+
*/
|
15 |
+
class Order {
|
16 |
+
|
17 |
+
|
18 |
+
/**
|
19 |
+
* The ID.
|
20 |
+
*
|
21 |
+
* @var string
|
22 |
+
*/
|
23 |
+
private $id;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* The create time.
|
27 |
+
*
|
28 |
+
* @var \DateTime|null
|
29 |
+
*/
|
30 |
+
private $create_time;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* The purchase units.
|
34 |
+
*
|
35 |
+
* @var PurchaseUnit[]
|
36 |
+
*/
|
37 |
+
private $purchase_units;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* The payer.
|
41 |
+
*
|
42 |
+
* @var Payer|null
|
43 |
+
*/
|
44 |
+
private $payer;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* The order status.
|
48 |
+
*
|
49 |
+
* @var OrderStatus
|
50 |
+
*/
|
51 |
+
private $order_status;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* The intent.
|
55 |
+
*
|
56 |
+
* @var string
|
57 |
+
*/
|
58 |
+
private $intent;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* The update time.
|
62 |
+
*
|
63 |
+
* @var \DateTime|null
|
64 |
+
*/
|
65 |
+
private $update_time;
|
66 |
+
|
67 |
+
/**
|
68 |
+
* The application context.
|
69 |
+
*
|
70 |
+
* @var ApplicationContext|null
|
71 |
+
*/
|
72 |
+
private $application_context;
|
73 |
+
|
74 |
+
/**
|
75 |
+
* The payment source.
|
76 |
+
*
|
77 |
+
* @var PaymentSource|null
|
78 |
+
*/
|
79 |
+
private $payment_source;
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Order constructor.
|
83 |
+
*
|
84 |
+
* @see https://developer.paypal.com/docs/api/orders/v2/#orders-create-response
|
85 |
+
*
|
86 |
+
* @param string $id The ID.
|
87 |
+
* @param PurchaseUnit[] $purchase_units The purchase units.
|
88 |
+
* @param OrderStatus $order_status The order status.
|
89 |
+
* @param ApplicationContext|null $application_context The application context.
|
90 |
+
* @param PaymentSource|null $payment_source The payment source.
|
91 |
+
* @param Payer|null $payer The payer.
|
92 |
+
* @param string $intent The intent.
|
93 |
+
* @param \DateTime|null $create_time The create time.
|
94 |
+
* @param \DateTime|null $update_time The update time.
|
95 |
+
*/
|
96 |
+
public function __construct(
|
97 |
+
string $id,
|
98 |
+
array $purchase_units,
|
99 |
+
OrderStatus $order_status,
|
100 |
+
ApplicationContext $application_context = null,
|
101 |
+
PaymentSource $payment_source = null,
|
102 |
+
Payer $payer = null,
|
103 |
+
string $intent = 'CAPTURE',
|
104 |
+
\DateTime $create_time = null,
|
105 |
+
\DateTime $update_time = null
|
106 |
+
) {
|
107 |
+
|
108 |
+
$this->id = $id;
|
109 |
+
$this->application_context = $application_context;
|
110 |
+
$this->purchase_units = array_values(
|
111 |
+
array_filter(
|
112 |
+
$purchase_units,
|
113 |
+
static function ( $unit ): bool {
|
114 |
+
return is_a( $unit, PurchaseUnit::class );
|
115 |
+
}
|
116 |
+
)
|
117 |
+
);
|
118 |
+
$this->payer = $payer;
|
119 |
+
$this->order_status = $order_status;
|
120 |
+
$this->intent = ( 'CAPTURE' === $intent ) ? 'CAPTURE' : 'AUTHORIZE';
|
121 |
+
$this->purchase_units = $purchase_units;
|
122 |
+
$this->create_time = $create_time;
|
123 |
+
$this->update_time = $update_time;
|
124 |
+
$this->payment_source = $payment_source;
|
125 |
+
}
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Returns the ID.
|
129 |
+
*
|
130 |
+
* @return string
|
131 |
+
*/
|
132 |
+
public function id(): string {
|
133 |
+
return $this->id;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Returns the create time.
|
138 |
+
*
|
139 |
+
* @return \DateTime|null
|
140 |
+
*/
|
141 |
+
public function create_time() {
|
142 |
+
return $this->create_time;
|
143 |
+
}
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Returns the update time.
|
147 |
+
*
|
148 |
+
* @return \DateTime|null
|
149 |
+
*/
|
150 |
+
public function update_time() {
|
151 |
+
return $this->update_time;
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Returns the intent.
|
156 |
+
*
|
157 |
+
* @return string
|
158 |
+
*/
|
159 |
+
public function intent() {
|
160 |
+
return $this->intent;
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Returns the payer.
|
165 |
+
*
|
166 |
+
* @return Payer|null
|
167 |
+
*/
|
168 |
+
public function payer() {
|
169 |
+
return $this->payer;
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Returns the purchase units.
|
174 |
+
*
|
175 |
+
* @return PurchaseUnit[]
|
176 |
+
*/
|
177 |
+
public function purchase_units() {
|
178 |
+
return $this->purchase_units;
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Returns the order status.
|
183 |
+
*
|
184 |
+
* @return OrderStatus
|
185 |
+
*/
|
186 |
+
public function status() {
|
187 |
+
return $this->order_status;
|
188 |
+
}
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Returns the application context.
|
192 |
+
*
|
193 |
+
* @return ApplicationContext|null
|
194 |
+
*/
|
195 |
+
public function application_context() {
|
196 |
+
|
197 |
+
return $this->application_context;
|
198 |
+
}
|
199 |
+
|
200 |
+
/**
|
201 |
+
* Returns the payment source.
|
202 |
+
*
|
203 |
+
* @return PaymentSource|null
|
204 |
+
*/
|
205 |
+
public function payment_source() {
|
206 |
+
|
207 |
+
return $this->payment_source;
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Returns the object as array.
|
212 |
+
*
|
213 |
+
* @return array
|
214 |
+
*/
|
215 |
+
public function to_array() {
|
216 |
+
$order = array(
|
217 |
+
'id' => $this->id(),
|
218 |
+
'intent' => $this->intent(),
|
219 |
+
'status' => $this->status()->name(),
|
220 |
+
'purchase_units' => array_map(
|
221 |
+
static function ( PurchaseUnit $unit ): array {
|
222 |
+
return $unit->to_array();
|
223 |
+
},
|
224 |
+
$this->purchase_units()
|
225 |
+
),
|
226 |
+
);
|
227 |
+
if ( $this->create_time() ) {
|
228 |
+
$order['create_time'] = $this->create_time()->format( 'Y-m-d\TH:i:sO' );
|
229 |
+
}
|
230 |
+
if ( $this->payer() ) {
|
231 |
+
$order['payer'] = $this->payer()->to_array();
|
232 |
+
}
|
233 |
+
if ( $this->update_time() ) {
|
234 |
+
$order['update_time'] = $this->update_time()->format( 'Y-m-d\TH:i:sO' );
|
235 |
+
}
|
236 |
+
if ( $this->application_context() ) {
|
237 |
+
$order['application_context'] = $this->application_context()->to_array();
|
238 |
+
}
|
239 |
+
if ( $this->payment_source() ) {
|
240 |
+
$order['payment_source'] = $this->payment_source()->to_array();
|
241 |
+
}
|
242 |
+
|
243 |
+
return $order;
|
244 |
+
}
|
245 |
+
}
|
modules/ppcp-api-client/src/Entity/class-orderstatus.php
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The OrderStatus object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class OrderStatus
|
16 |
+
*/
|
17 |
+
class OrderStatus {
|
18 |
+
|
19 |
+
|
20 |
+
const INTERNAL = 'INTERNAL';
|
21 |
+
const CREATED = 'CREATED';
|
22 |
+
const SAVED = 'SAVED';
|
23 |
+
const APPROVED = 'APPROVED';
|
24 |
+
const VOIDED = 'VOIDED';
|
25 |
+
const COMPLETED = 'COMPLETED';
|
26 |
+
const VALID_STATI = array(
|
27 |
+
self::INTERNAL,
|
28 |
+
self::CREATED,
|
29 |
+
self::SAVED,
|
30 |
+
self::APPROVED,
|
31 |
+
self::VOIDED,
|
32 |
+
self::COMPLETED,
|
33 |
+
);
|
34 |
+
|
35 |
+
/**
|
36 |
+
* The status.
|
37 |
+
*
|
38 |
+
* @var string
|
39 |
+
*/
|
40 |
+
private $status;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* OrderStatus constructor.
|
44 |
+
*
|
45 |
+
* @param string $status The status.
|
46 |
+
* @throws RuntimeException When the status is not valid.
|
47 |
+
*/
|
48 |
+
public function __construct( string $status ) {
|
49 |
+
if ( ! in_array( $status, self::VALID_STATI, true ) ) {
|
50 |
+
throw new RuntimeException(
|
51 |
+
sprintf(
|
52 |
+
// translators: %s is the current status.
|
53 |
+
__( '%s is not a valid status', 'woocommerce-paypal-payments' ),
|
54 |
+
$status
|
55 |
+
)
|
56 |
+
);
|
57 |
+
}
|
58 |
+
$this->status = $status;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Creates an OrderStatus "Internal"
|
63 |
+
*
|
64 |
+
* @return OrderStatus
|
65 |
+
*/
|
66 |
+
public static function as_internal(): OrderStatus {
|
67 |
+
return new self( self::INTERNAL );
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Compares the current status with a given one.
|
72 |
+
*
|
73 |
+
* @param string $status The status to compare with.
|
74 |
+
*
|
75 |
+
* @return bool
|
76 |
+
*/
|
77 |
+
public function is( string $status ): bool {
|
78 |
+
return $this->status === $status;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Returns the status.
|
83 |
+
*
|
84 |
+
* @return string
|
85 |
+
*/
|
86 |
+
public function name(): string {
|
87 |
+
return $this->status;
|
88 |
+
}
|
89 |
+
}
|
modules/ppcp-api-client/src/Entity/class-patch.php
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The Patch object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Patch
|
14 |
+
*/
|
15 |
+
class Patch {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The operation.
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
private $op;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The path to the change.
|
26 |
+
*
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
private $path;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* The new value.
|
33 |
+
*
|
34 |
+
* @var array
|
35 |
+
*/
|
36 |
+
private $value;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Patch constructor.
|
40 |
+
*
|
41 |
+
* @param string $op The operation.
|
42 |
+
* @param string $path The path.
|
43 |
+
* @param array $value The new value.
|
44 |
+
*/
|
45 |
+
public function __construct( string $op, string $path, array $value ) {
|
46 |
+
$this->op = $op;
|
47 |
+
$this->path = $path;
|
48 |
+
$this->value = $value;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Returns the operation.
|
53 |
+
*
|
54 |
+
* @return string
|
55 |
+
*/
|
56 |
+
public function op(): string {
|
57 |
+
return $this->op;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Returns the path.
|
62 |
+
*
|
63 |
+
* @return string
|
64 |
+
*/
|
65 |
+
public function path(): string {
|
66 |
+
return $this->path;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Returns the value.
|
71 |
+
*
|
72 |
+
* @return array
|
73 |
+
*/
|
74 |
+
public function value() {
|
75 |
+
return $this->value;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Returns the object as array.
|
80 |
+
*
|
81 |
+
* @return array
|
82 |
+
*/
|
83 |
+
public function to_array(): array {
|
84 |
+
return array(
|
85 |
+
'op' => $this->op(),
|
86 |
+
'value' => $this->value(),
|
87 |
+
'path' => $this->path(),
|
88 |
+
);
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Needed for the move operation. We currently do not
|
93 |
+
* support the move operation.
|
94 |
+
*
|
95 |
+
* @return string
|
96 |
+
*/
|
97 |
+
public function from(): string {
|
98 |
+
return '';
|
99 |
+
}
|
100 |
+
}
|
modules/ppcp-api-client/src/Entity/class-patchcollection.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The Patch collection object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class PatchCollection
|
14 |
+
*/
|
15 |
+
class PatchCollection {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The patches.
|
19 |
+
*
|
20 |
+
* @var Patch[]
|
21 |
+
*/
|
22 |
+
private $patches;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* PatchCollection constructor.
|
26 |
+
*
|
27 |
+
* @param Patch ...$patches The patches.
|
28 |
+
*/
|
29 |
+
public function __construct( Patch ...$patches ) {
|
30 |
+
$this->patches = $patches;
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Returns the patches.
|
35 |
+
*
|
36 |
+
* @return Patch[]
|
37 |
+
*/
|
38 |
+
public function patches(): array {
|
39 |
+
return $this->patches;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Returns the object as array.
|
44 |
+
*
|
45 |
+
* @return array
|
46 |
+
*/
|
47 |
+
public function to_array(): array {
|
48 |
+
return array_map(
|
49 |
+
static function ( Patch $patch ): array {
|
50 |
+
return $patch->to_array();
|
51 |
+
},
|
52 |
+
$this->patches()
|
53 |
+
);
|
54 |
+
}
|
55 |
+
}
|
modules/ppcp-api-client/src/Entity/class-payee.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The payee object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Payee
|
14 |
+
* The entity, which receives the money.
|
15 |
+
*/
|
16 |
+
class Payee {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* The email address.
|
20 |
+
*
|
21 |
+
* @var string
|
22 |
+
*/
|
23 |
+
private $email;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* The merchant id.
|
27 |
+
*
|
28 |
+
* @var string
|
29 |
+
*/
|
30 |
+
private $merchant_id;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Payee constructor.
|
34 |
+
*
|
35 |
+
* @param string $email The email.
|
36 |
+
* @param string $merchant_id The merchant id.
|
37 |
+
*/
|
38 |
+
public function __construct(
|
39 |
+
string $email,
|
40 |
+
string $merchant_id
|
41 |
+
) {
|
42 |
+
|
43 |
+
$this->email = $email;
|
44 |
+
$this->merchant_id = $merchant_id;
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Returns the email.
|
49 |
+
*
|
50 |
+
* @return string
|
51 |
+
*/
|
52 |
+
public function email(): string {
|
53 |
+
return $this->email;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Returns the merchant id.
|
58 |
+
*
|
59 |
+
* @return string
|
60 |
+
*/
|
61 |
+
public function merchant_id(): string {
|
62 |
+
return $this->merchant_id;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Returns the object as array.
|
67 |
+
*
|
68 |
+
* @return array
|
69 |
+
*/
|
70 |
+
public function to_array(): array {
|
71 |
+
$data = array(
|
72 |
+
'email_address' => $this->email(),
|
73 |
+
);
|
74 |
+
if ( $this->merchant_id ) {
|
75 |
+
$data['merchant_id'] = $this->merchant_id();
|
76 |
+
}
|
77 |
+
return $data;
|
78 |
+
}
|
79 |
+
}
|
modules/ppcp-api-client/src/Entity/class-payer.php
ADDED
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The payer object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Payer
|
14 |
+
* The customer who sends the money.
|
15 |
+
*/
|
16 |
+
class Payer {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* The name.
|
20 |
+
*
|
21 |
+
* @var PayerName
|
22 |
+
*/
|
23 |
+
private $name;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* The email address.
|
27 |
+
*
|
28 |
+
* @var string
|
29 |
+
*/
|
30 |
+
private $email_address;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* The payer id.
|
34 |
+
*
|
35 |
+
* @var string
|
36 |
+
*/
|
37 |
+
private $payer_id;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* The birth date.
|
41 |
+
*
|
42 |
+
* @var \DateTime|null
|
43 |
+
*/
|
44 |
+
private $birthdate;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* The address.
|
48 |
+
*
|
49 |
+
* @var Address
|
50 |
+
*/
|
51 |
+
private $address;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* The phone.
|
55 |
+
*
|
56 |
+
* @var PhoneWithType|null
|
57 |
+
*/
|
58 |
+
private $phone;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* The tax info.
|
62 |
+
*
|
63 |
+
* @var PayerTaxInfo|null
|
64 |
+
*/
|
65 |
+
private $tax_info;
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Payer constructor.
|
69 |
+
*
|
70 |
+
* @param PayerName $name The name.
|
71 |
+
* @param string $email_address The email.
|
72 |
+
* @param string $payer_id The payer id.
|
73 |
+
* @param Address $address The address.
|
74 |
+
* @param \DateTime|null $birthdate The birth date.
|
75 |
+
* @param PhoneWithType|null $phone The phone.
|
76 |
+
* @param PayerTaxInfo|null $tax_info The tax info.
|
77 |
+
*/
|
78 |
+
public function __construct(
|
79 |
+
PayerName $name,
|
80 |
+
string $email_address,
|
81 |
+
string $payer_id,
|
82 |
+
Address $address,
|
83 |
+
\DateTime $birthdate = null,
|
84 |
+
PhoneWithType $phone = null,
|
85 |
+
PayerTaxInfo $tax_info = null
|
86 |
+
) {
|
87 |
+
|
88 |
+
$this->name = $name;
|
89 |
+
$this->email_address = $email_address;
|
90 |
+
$this->payer_id = $payer_id;
|
91 |
+
$this->birthdate = $birthdate;
|
92 |
+
$this->address = $address;
|
93 |
+
$this->phone = $phone;
|
94 |
+
$this->tax_info = $tax_info;
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Returns the name.
|
99 |
+
*
|
100 |
+
* @return PayerName
|
101 |
+
*/
|
102 |
+
public function name(): PayerName {
|
103 |
+
return $this->name;
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Returns the email address.
|
108 |
+
*
|
109 |
+
* @return string
|
110 |
+
*/
|
111 |
+
public function email_address(): string {
|
112 |
+
return $this->email_address;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Returns the payer id.
|
117 |
+
*
|
118 |
+
* @return string
|
119 |
+
*/
|
120 |
+
public function payer_id(): string {
|
121 |
+
return $this->payer_id;
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Returns the birth date.
|
126 |
+
*
|
127 |
+
* @return \DateTime|null
|
128 |
+
*/
|
129 |
+
public function birthdate() {
|
130 |
+
return $this->birthdate;
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Returns the address.
|
135 |
+
*
|
136 |
+
* @return Address
|
137 |
+
*/
|
138 |
+
public function address(): Address {
|
139 |
+
return $this->address;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Returns the phone.
|
144 |
+
*
|
145 |
+
* @return PhoneWithType|null
|
146 |
+
*/
|
147 |
+
public function phone() {
|
148 |
+
return $this->phone;
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Returns the tax info.
|
153 |
+
*
|
154 |
+
* @return PayerTaxInfo|null
|
155 |
+
*/
|
156 |
+
public function tax_info() {
|
157 |
+
return $this->tax_info;
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* Returns the object as array.
|
162 |
+
*
|
163 |
+
* @return array
|
164 |
+
*/
|
165 |
+
public function to_array() {
|
166 |
+
$payer = array(
|
167 |
+
'name' => $this->name()->to_array(),
|
168 |
+
'email_address' => $this->email_address(),
|
169 |
+
'address' => $this->address()->to_array(),
|
170 |
+
);
|
171 |
+
if ( $this->payer_id() ) {
|
172 |
+
$payer['payer_id'] = $this->payer_id();
|
173 |
+
}
|
174 |
+
|
175 |
+
if ( $this->phone() ) {
|
176 |
+
$payer['phone'] = $this->phone()->to_array();
|
177 |
+
}
|
178 |
+
if ( $this->tax_info() ) {
|
179 |
+
$payer['tax_info'] = $this->tax_info()->to_array();
|
180 |
+
}
|
181 |
+
if ( $this->birthdate() ) {
|
182 |
+
$payer['birth_date'] = $this->birthdate()->format( 'Y-m-d' );
|
183 |
+
}
|
184 |
+
return $payer;
|
185 |
+
}
|
186 |
+
}
|
modules/ppcp-api-client/src/Entity/class-payername.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PayerName object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class PayerName
|
14 |
+
*/
|
15 |
+
class PayerName {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The given name.
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
private $given_name;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The surname.
|
26 |
+
*
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
private $surname;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* PayerName constructor.
|
33 |
+
*
|
34 |
+
* @param string $given_name The given name.
|
35 |
+
* @param string $surname The surname.
|
36 |
+
*/
|
37 |
+
public function __construct(
|
38 |
+
string $given_name,
|
39 |
+
string $surname
|
40 |
+
) {
|
41 |
+
|
42 |
+
$this->given_name = $given_name;
|
43 |
+
$this->surname = $surname;
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Returns the given name.
|
48 |
+
*
|
49 |
+
* @return string
|
50 |
+
*/
|
51 |
+
public function given_name(): string {
|
52 |
+
return $this->given_name;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Returns the surname.
|
57 |
+
*
|
58 |
+
* @return string
|
59 |
+
*/
|
60 |
+
public function surname(): string {
|
61 |
+
return $this->surname;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Returns the object as array.
|
66 |
+
*
|
67 |
+
* @return array
|
68 |
+
*/
|
69 |
+
public function to_array(): array {
|
70 |
+
return array(
|
71 |
+
'given_name' => $this->given_name(),
|
72 |
+
'surname' => $this->surname(),
|
73 |
+
);
|
74 |
+
}
|
75 |
+
}
|
modules/ppcp-api-client/src/Entity/class-payertaxinfo.php
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PayerTaxInfo object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class PayerTaxInfo
|
16 |
+
*/
|
17 |
+
class PayerTaxInfo {
|
18 |
+
|
19 |
+
|
20 |
+
const VALID_TYPES = array(
|
21 |
+
'BR_CPF',
|
22 |
+
'BR_CNPJ',
|
23 |
+
);
|
24 |
+
|
25 |
+
/**
|
26 |
+
* The tax id.
|
27 |
+
*
|
28 |
+
* @var string
|
29 |
+
*/
|
30 |
+
private $tax_id;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* The type.
|
34 |
+
*
|
35 |
+
* @var string
|
36 |
+
*/
|
37 |
+
private $type;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* PayerTaxInfo constructor.
|
41 |
+
*
|
42 |
+
* @param string $tax_id The tax id.
|
43 |
+
* @param string $type The type.
|
44 |
+
* @throws RuntimeException When the type is not valid.
|
45 |
+
*/
|
46 |
+
public function __construct(
|
47 |
+
string $tax_id,
|
48 |
+
string $type
|
49 |
+
) {
|
50 |
+
|
51 |
+
if ( ! in_array( $type, self::VALID_TYPES, true ) ) {
|
52 |
+
throw new RuntimeException(
|
53 |
+
sprintf(
|
54 |
+
// translators: %s is the current type.
|
55 |
+
__( '%s is not a valid tax type.', 'woocommerce-paypal-payments' ),
|
56 |
+
$type
|
57 |
+
)
|
58 |
+
);
|
59 |
+
}
|
60 |
+
$this->tax_id = $tax_id;
|
61 |
+
$this->type = $type;
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Returns the type.
|
66 |
+
*
|
67 |
+
* @return string
|
68 |
+
*/
|
69 |
+
public function type(): string {
|
70 |
+
return $this->type;
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Returns the tax id
|
75 |
+
*
|
76 |
+
* @return string
|
77 |
+
*/
|
78 |
+
public function tax_id(): string {
|
79 |
+
return $this->tax_id;
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Returns the object as array.
|
84 |
+
*
|
85 |
+
* @return array
|
86 |
+
*/
|
87 |
+
public function to_array(): array {
|
88 |
+
return array(
|
89 |
+
'tax_id' => $this->tax_id(),
|
90 |
+
'tax_id_type' => $this->type(),
|
91 |
+
);
|
92 |
+
}
|
93 |
+
}
|
modules/ppcp-api-client/src/Entity/class-paymentmethod.php
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PaymentMethod object
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class PaymentMethod
|
14 |
+
*/
|
15 |
+
class PaymentMethod {
|
16 |
+
|
17 |
+
|
18 |
+
const PAYER_SELECTED_DEFAULT = 'PAYPAL';
|
19 |
+
|
20 |
+
const PAYEE_PREFERRED_UNRESTRICTED = 'UNRESTRICTED';
|
21 |
+
const PAYEE_PREFERRED_IMMEDIATE_PAYMENT_REQUIRED = 'IMMEDIATE_PAYMENT_REQUIRED';
|
22 |
+
|
23 |
+
/**
|
24 |
+
* The preferred value.
|
25 |
+
*
|
26 |
+
* @var string
|
27 |
+
*/
|
28 |
+
private $preferred;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* The selected value.
|
32 |
+
*
|
33 |
+
* @var string
|
34 |
+
*/
|
35 |
+
private $selected;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* PaymentMethod constructor.
|
39 |
+
*
|
40 |
+
* @param string $preferred The preferred value.
|
41 |
+
* @param string $selected The selected value.
|
42 |
+
*/
|
43 |
+
public function __construct(
|
44 |
+
string $preferred = self::PAYEE_PREFERRED_UNRESTRICTED,
|
45 |
+
string $selected = self::PAYER_SELECTED_DEFAULT
|
46 |
+
) {
|
47 |
+
|
48 |
+
$this->preferred = $preferred;
|
49 |
+
$this->selected = $selected;
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Returns the payer preferred value.
|
54 |
+
*
|
55 |
+
* @return string
|
56 |
+
*/
|
57 |
+
public function payee_preferred(): string {
|
58 |
+
return $this->preferred;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Returns the payer selected value.
|
63 |
+
*
|
64 |
+
* @return string
|
65 |
+
*/
|
66 |
+
public function payer_selected(): string {
|
67 |
+
return $this->selected;
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Returns the object as array.
|
72 |
+
*
|
73 |
+
* @return array
|
74 |
+
*/
|
75 |
+
public function to_array(): array {
|
76 |
+
return array(
|
77 |
+
'payee_preferred' => $this->payee_preferred(),
|
78 |
+
'payer_selected' => $this->payer_selected(),
|
79 |
+
);
|
80 |
+
}
|
81 |
+
}
|
modules/ppcp-api-client/src/Entity/class-payments.php
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The Payments object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Payments
|
14 |
+
*/
|
15 |
+
class Payments {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The Authorizations.
|
19 |
+
*
|
20 |
+
* @var Authorization[]
|
21 |
+
*/
|
22 |
+
private $authorizations;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The Captures.
|
26 |
+
*
|
27 |
+
* @var Capture[]
|
28 |
+
*/
|
29 |
+
private $captures;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Payments constructor.
|
33 |
+
*
|
34 |
+
* @param array $authorizations The Authorizations.
|
35 |
+
* @param array $captures The Captures.
|
36 |
+
*/
|
37 |
+
public function __construct( array $authorizations, array $captures ) {
|
38 |
+
foreach ( $authorizations as $key => $authorization ) {
|
39 |
+
if ( is_a( $authorization, Authorization::class ) ) {
|
40 |
+
continue;
|
41 |
+
}
|
42 |
+
unset( $authorizations[ $key ] );
|
43 |
+
}
|
44 |
+
foreach ( $captures as $key => $capture ) {
|
45 |
+
if ( is_a( $capture, Capture::class ) ) {
|
46 |
+
continue;
|
47 |
+
}
|
48 |
+
unset( $captures[ $key ] );
|
49 |
+
}
|
50 |
+
$this->authorizations = $authorizations;
|
51 |
+
$this->captures = $captures;
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Returns the object as array.
|
56 |
+
*
|
57 |
+
* @return array
|
58 |
+
*/
|
59 |
+
public function to_array(): array {
|
60 |
+
return array(
|
61 |
+
'authorizations' => array_map(
|
62 |
+
static function ( Authorization $authorization ): array {
|
63 |
+
return $authorization->to_array();
|
64 |
+
},
|
65 |
+
$this->authorizations()
|
66 |
+
),
|
67 |
+
'captures' => array_map(
|
68 |
+
static function ( Capture $capture ): array {
|
69 |
+
return $capture->to_array();
|
70 |
+
},
|
71 |
+
$this->captures()
|
72 |
+
),
|
73 |
+
);
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Returns the Authoriatzions.
|
78 |
+
*
|
79 |
+
* @return Authorization[]
|
80 |
+
**/
|
81 |
+
public function authorizations(): array {
|
82 |
+
return $this->authorizations;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Returns the Captures.
|
87 |
+
*
|
88 |
+
* @return Capture[]
|
89 |
+
**/
|
90 |
+
public function captures(): array {
|
91 |
+
return $this->captures;
|
92 |
+
}
|
93 |
+
}
|
modules/ppcp-api-client/src/Entity/class-paymentsource.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PaymentSource object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class PaymentSource
|
14 |
+
*/
|
15 |
+
class PaymentSource {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The card.
|
19 |
+
*
|
20 |
+
* @var PaymentSourceCard|null
|
21 |
+
*/
|
22 |
+
private $card;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The wallet.
|
26 |
+
*
|
27 |
+
* @var PaymentSourceWallet|null
|
28 |
+
*/
|
29 |
+
private $wallet;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* PaymentSource constructor.
|
33 |
+
*
|
34 |
+
* @param PaymentSourceCard|null $card The card.
|
35 |
+
* @param PaymentSourceWallet|null $wallet The wallet.
|
36 |
+
*/
|
37 |
+
public function __construct(
|
38 |
+
PaymentSourceCard $card = null,
|
39 |
+
PaymentSourceWallet $wallet = null
|
40 |
+
) {
|
41 |
+
|
42 |
+
$this->card = $card;
|
43 |
+
$this->wallet = $wallet;
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Returns the card.
|
48 |
+
*
|
49 |
+
* @return PaymentSourceCard|null
|
50 |
+
*/
|
51 |
+
public function card() {
|
52 |
+
|
53 |
+
return $this->card;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Returns the wallet.
|
58 |
+
*
|
59 |
+
* @return PaymentSourceWallet|null
|
60 |
+
*/
|
61 |
+
public function wallet() {
|
62 |
+
|
63 |
+
return $this->wallet;
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Returns the array of the object.
|
68 |
+
*
|
69 |
+
* @return array
|
70 |
+
*/
|
71 |
+
public function to_array(): array {
|
72 |
+
|
73 |
+
$data = array();
|
74 |
+
if ( $this->card() ) {
|
75 |
+
$data['card'] = $this->card()->to_array();
|
76 |
+
}
|
77 |
+
if ( $this->wallet() ) {
|
78 |
+
$data['wallet'] = $this->wallet()->to_array();
|
79 |
+
}
|
80 |
+
return $data;
|
81 |
+
}
|
82 |
+
}
|
modules/ppcp-api-client/src/Entity/class-paymentsourcecard.php
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PaymentSourceCard object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class PaymentSourceCard
|
14 |
+
*/
|
15 |
+
class PaymentSourceCard {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The last digits of the card.
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
private $last_digits;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The brand.
|
26 |
+
*
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
private $brand;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* The type.
|
33 |
+
*
|
34 |
+
* @var string
|
35 |
+
*/
|
36 |
+
private $type;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* The authentication result.
|
40 |
+
*
|
41 |
+
* @var CardAuthenticationResult|null
|
42 |
+
*/
|
43 |
+
private $authentication_result;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* PaymentSourceCard constructor.
|
47 |
+
*
|
48 |
+
* @param string $last_digits The last digits of the card.
|
49 |
+
* @param string $brand The brand of the card.
|
50 |
+
* @param string $type The type of the card.
|
51 |
+
* @param CardAuthenticationResult|null $authentication_result The authentication result.
|
52 |
+
*/
|
53 |
+
public function __construct(
|
54 |
+
string $last_digits,
|
55 |
+
string $brand,
|
56 |
+
string $type,
|
57 |
+
CardAuthenticationResult $authentication_result = null
|
58 |
+
) {
|
59 |
+
|
60 |
+
$this->last_digits = $last_digits;
|
61 |
+
$this->brand = $brand;
|
62 |
+
$this->type = $type;
|
63 |
+
$this->authentication_result = $authentication_result;
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Returns the last digits.
|
68 |
+
*
|
69 |
+
* @return string
|
70 |
+
*/
|
71 |
+
public function last_digits(): string {
|
72 |
+
|
73 |
+
return $this->last_digits;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Returns the brand.
|
78 |
+
*
|
79 |
+
* @return string
|
80 |
+
*/
|
81 |
+
public function brand(): string {
|
82 |
+
|
83 |
+
return $this->brand;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Returns the type.
|
88 |
+
*
|
89 |
+
* @return string
|
90 |
+
*/
|
91 |
+
public function type(): string {
|
92 |
+
|
93 |
+
return $this->type;
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Returns the authentication result.
|
98 |
+
*
|
99 |
+
* @return CardAuthenticationResult|null
|
100 |
+
*/
|
101 |
+
public function authentication_result() {
|
102 |
+
|
103 |
+
return $this->authentication_result;
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Returns the object as array.
|
108 |
+
*
|
109 |
+
* @return array
|
110 |
+
*/
|
111 |
+
public function to_array(): array {
|
112 |
+
|
113 |
+
$data = array(
|
114 |
+
'last_digits' => $this->last_digits(),
|
115 |
+
'brand' => $this->brand(),
|
116 |
+
'type' => $this->type(),
|
117 |
+
);
|
118 |
+
if ( $this->authentication_result() ) {
|
119 |
+
$data['authentication_result'] = $this->authentication_result()->to_array();
|
120 |
+
}
|
121 |
+
return $data;
|
122 |
+
}
|
123 |
+
}
|
modules/ppcp-api-client/src/Entity/class-paymentsourcewallet.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PaymentSourcewallet.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class PaymentSourceWallet
|
14 |
+
*/
|
15 |
+
class PaymentSourceWallet {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Returns the object as array.
|
19 |
+
*
|
20 |
+
* @return array
|
21 |
+
*/
|
22 |
+
public function to_array(): array {
|
23 |
+
return array();
|
24 |
+
}
|
25 |
+
}
|
modules/ppcp-api-client/src/Entity/class-paymenttoken.php
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PaymentToken object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class PaymentToken
|
16 |
+
*/
|
17 |
+
class PaymentToken {
|
18 |
+
|
19 |
+
|
20 |
+
const TYPE_PAYMENT_METHOD_TOKEN = 'PAYMENT_METHOD_TOKEN';
|
21 |
+
const VALID_TYPES = array(
|
22 |
+
self::TYPE_PAYMENT_METHOD_TOKEN,
|
23 |
+
);
|
24 |
+
|
25 |
+
/**
|
26 |
+
* The Id.
|
27 |
+
*
|
28 |
+
* @var string
|
29 |
+
*/
|
30 |
+
private $id;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* The type.
|
34 |
+
*
|
35 |
+
* @var string
|
36 |
+
*/
|
37 |
+
private $type;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* PaymentToken constructor.
|
41 |
+
*
|
42 |
+
* @param string $id The Id.
|
43 |
+
* @param string $type The type.
|
44 |
+
* @throws RuntimeException When the type is not valid.
|
45 |
+
*/
|
46 |
+
public function __construct( string $id, string $type = self::TYPE_PAYMENT_METHOD_TOKEN ) {
|
47 |
+
if ( ! in_array( $type, self::VALID_TYPES, true ) ) {
|
48 |
+
throw new RuntimeException(
|
49 |
+
__( 'Not a valid payment source type.', 'woocommerce-paypal-payments' )
|
50 |
+
);
|
51 |
+
}
|
52 |
+
$this->id = $id;
|
53 |
+
$this->type = $type;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Returns the ID.
|
58 |
+
*
|
59 |
+
* @return string
|
60 |
+
*/
|
61 |
+
public function id(): string {
|
62 |
+
return $this->id;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Returns the type.
|
67 |
+
*
|
68 |
+
* @return string
|
69 |
+
*/
|
70 |
+
public function type(): string {
|
71 |
+
return $this->type;
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Returns the object as array.
|
76 |
+
*
|
77 |
+
* @return array
|
78 |
+
*/
|
79 |
+
public function to_array(): array {
|
80 |
+
return array(
|
81 |
+
'id' => $this->id(),
|
82 |
+
'type' => $this->type(),
|
83 |
+
);
|
84 |
+
}
|
85 |
+
}
|
modules/ppcp-api-client/src/Entity/class-phone.php
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The Phone object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Phone
|
14 |
+
*/
|
15 |
+
class Phone {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The number.
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
private $national_number;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Phone constructor.
|
26 |
+
*
|
27 |
+
* @param string $national_number The number.
|
28 |
+
*/
|
29 |
+
public function __construct( string $national_number ) {
|
30 |
+
$this->national_number = $national_number;
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Returns the number.
|
35 |
+
*
|
36 |
+
* @return string
|
37 |
+
*/
|
38 |
+
public function national_number(): string {
|
39 |
+
return $this->national_number;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Returns the object as array.
|
44 |
+
*
|
45 |
+
* @return array
|
46 |
+
*/
|
47 |
+
public function to_array(): array {
|
48 |
+
return array(
|
49 |
+
'national_number' => $this->national_number(),
|
50 |
+
);
|
51 |
+
}
|
52 |
+
}
|
modules/ppcp-api-client/src/Entity/class-phonewithtype.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The PhoneWithType object
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class PhoneWithType
|
14 |
+
*/
|
15 |
+
class PhoneWithType {
|
16 |
+
|
17 |
+
const VALLID_TYPES = array(
|
18 |
+
'FAX',
|
19 |
+
'HOME',
|
20 |
+
'MOBILE',
|
21 |
+
'OTHER',
|
22 |
+
'PAGER',
|
23 |
+
);
|
24 |
+
|
25 |
+
/**
|
26 |
+
* The type.
|
27 |
+
*
|
28 |
+
* @var string
|
29 |
+
*/
|
30 |
+
private $type;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* The phone.
|
34 |
+
*
|
35 |
+
* @var Phone
|
36 |
+
*/
|
37 |
+
private $phone;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* PhoneWithType constructor.
|
41 |
+
*
|
42 |
+
* @param string $type The type.
|
43 |
+
* @param Phone $phone The phone.
|
44 |
+
*/
|
45 |
+
public function __construct( string $type, Phone $phone ) {
|
46 |
+
$this->type = in_array( $type, self::VALLID_TYPES, true ) ? $type : 'OTHER';
|
47 |
+
$this->phone = $phone;
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Returns the type.
|
52 |
+
*
|
53 |
+
* @return string
|
54 |
+
*/
|
55 |
+
public function type(): string {
|
56 |
+
return $this->type;
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Returns the phone.
|
61 |
+
*
|
62 |
+
* @return Phone
|
63 |
+
*/
|
64 |
+
public function phone(): Phone {
|
65 |
+
return $this->phone;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Returns the object as array.
|
70 |
+
*
|
71 |
+
* @return array
|
72 |
+
*/
|
73 |
+
public function to_array(): array {
|
74 |
+
return array(
|
75 |
+
'phone_type' => $this->type(),
|
76 |
+
'phone_number' => $this->phone()->to_array(),
|
77 |
+
);
|
78 |
+
}
|
79 |
+
}
|
modules/ppcp-api-client/src/Entity/class-purchaseunit.php
ADDED
@@ -0,0 +1,358 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The purchase unit object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class PurchaseUnit
|
14 |
+
*/
|
15 |
+
class PurchaseUnit {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The amount.
|
19 |
+
*
|
20 |
+
* @var Amount
|
21 |
+
*/
|
22 |
+
private $amount;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The Items.
|
26 |
+
*
|
27 |
+
* @var Item[]
|
28 |
+
*/
|
29 |
+
private $items;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* The shipping.
|
33 |
+
*
|
34 |
+
* @var Shipping|null
|
35 |
+
*/
|
36 |
+
private $shipping;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* The reference id.
|
40 |
+
*
|
41 |
+
* @var string
|
42 |
+
*/
|
43 |
+
private $reference_id;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* The description.
|
47 |
+
*
|
48 |
+
* @var string
|
49 |
+
*/
|
50 |
+
private $description;
|
51 |
+
|
52 |
+
/**
|
53 |
+
* The Payee.
|
54 |
+
*
|
55 |
+
* @var Payee|null
|
56 |
+
*/
|
57 |
+
private $payee;
|
58 |
+
|
59 |
+
/**
|
60 |
+
* The custom id.
|
61 |
+
*
|
62 |
+
* @var string
|
63 |
+
*/
|
64 |
+
private $custom_id;
|
65 |
+
|
66 |
+
/**
|
67 |
+
* The invoice id.
|
68 |
+
*
|
69 |
+
* @var string
|
70 |
+
*/
|
71 |
+
private $invoice_id;
|
72 |
+
|
73 |
+
/**
|
74 |
+
* The soft descriptor.
|
75 |
+
*
|
76 |
+
* @var string
|
77 |
+
*/
|
78 |
+
private $soft_descriptor;
|
79 |
+
|
80 |
+
/**
|
81 |
+
* The Payments.
|
82 |
+
*
|
83 |
+
* @var Payments|null
|
84 |
+
*/
|
85 |
+
private $payments;
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Whether the unit contains physical goods.
|
89 |
+
*
|
90 |
+
* @var bool
|
91 |
+
*/
|
92 |
+
private $contains_physical_goods = false;
|
93 |
+
|
94 |
+
/**
|
95 |
+
* PurchaseUnit constructor.
|
96 |
+
*
|
97 |
+
* @param Amount $amount The Amount.
|
98 |
+
* @param Item[] $items The Items.
|
99 |
+
* @param Shipping|null $shipping The Shipping.
|
100 |
+
* @param string $reference_id The reference ID.
|
101 |
+
* @param string $description The description.
|
102 |
+
* @param Payee|null $payee The Payee.
|
103 |
+
* @param string $custom_id The custom ID.
|
104 |
+
* @param string $invoice_id The invoice ID.
|
105 |
+
* @param string $soft_descriptor The soft descriptor.
|
106 |
+
* @param Payments|null $payments The Payments.
|
107 |
+
*/
|
108 |
+
public function __construct(
|
109 |
+
Amount $amount,
|
110 |
+
array $items = array(),
|
111 |
+
Shipping $shipping = null,
|
112 |
+
string $reference_id = 'default',
|
113 |
+
string $description = '',
|
114 |
+
Payee $payee = null,
|
115 |
+
string $custom_id = '',
|
116 |
+
string $invoice_id = '',
|
117 |
+
string $soft_descriptor = '',
|
118 |
+
Payments $payments = null
|
119 |
+
) {
|
120 |
+
|
121 |
+
$this->amount = $amount;
|
122 |
+
$this->shipping = $shipping;
|
123 |
+
$this->reference_id = $reference_id;
|
124 |
+
$this->description = $description;
|
125 |
+
//phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
|
126 |
+
$this->items = array_values(
|
127 |
+
array_filter(
|
128 |
+
$items,
|
129 |
+
function ( $item ): bool {
|
130 |
+
$is_item = is_a( $item, Item::class );
|
131 |
+
/**
|
132 |
+
* The item.
|
133 |
+
*
|
134 |
+
* @var Item $item
|
135 |
+
*/
|
136 |
+
if ( $is_item && Item::PHYSICAL_GOODS === $item->category() ) {
|
137 |
+
$this->contains_physical_goods = true;
|
138 |
+
}
|
139 |
+
|
140 |
+
return $is_item;
|
141 |
+
}
|
142 |
+
)
|
143 |
+
);
|
144 |
+
$this->payee = $payee;
|
145 |
+
$this->custom_id = $custom_id;
|
146 |
+
$this->invoice_id = $invoice_id;
|
147 |
+
$this->soft_descriptor = $soft_descriptor;
|
148 |
+
$this->payments = $payments;
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Returns the amount.
|
153 |
+
*
|
154 |
+
* @return Amount
|
155 |
+
*/
|
156 |
+
public function amount(): Amount {
|
157 |
+
return $this->amount;
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* Returns the shipping.
|
162 |
+
*
|
163 |
+
* @return Shipping|null
|
164 |
+
*/
|
165 |
+
public function shipping() {
|
166 |
+
return $this->shipping;
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Returns the reference id.
|
171 |
+
*
|
172 |
+
* @return string
|
173 |
+
*/
|
174 |
+
public function reference_id(): string {
|
175 |
+
return $this->reference_id;
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Returns the description.
|
180 |
+
*
|
181 |
+
* @return string
|
182 |
+
*/
|
183 |
+
public function description(): string {
|
184 |
+
return $this->description;
|
185 |
+
}
|
186 |
+
|
187 |
+
/**
|
188 |
+
* Returns the custom id.
|
189 |
+
*
|
190 |
+
* @return string
|
191 |
+
*/
|
192 |
+
public function custom_id(): string {
|
193 |
+
return $this->custom_id;
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Returns the invoice id.
|
198 |
+
*
|
199 |
+
* @return string
|
200 |
+
*/
|
201 |
+
public function invoice_id(): string {
|
202 |
+
return $this->invoice_id;
|
203 |
+
}
|
204 |
+
|
205 |
+
/**
|
206 |
+
* Returns the soft descriptor.
|
207 |
+
*
|
208 |
+
* @return string
|
209 |
+
*/
|
210 |
+
public function soft_descriptor(): string {
|
211 |
+
return $this->soft_descriptor;
|
212 |
+
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Returns the Payee.
|
216 |
+
*
|
217 |
+
* @return Payee|null
|
218 |
+
*/
|
219 |
+
public function payee() {
|
220 |
+
return $this->payee;
|
221 |
+
}
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Returns the Payments.
|
225 |
+
*
|
226 |
+
* @return Payments|null
|
227 |
+
*/
|
228 |
+
public function payments() {
|
229 |
+
return $this->payments;
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Returns the Items.
|
234 |
+
*
|
235 |
+
* @return Item[]
|
236 |
+
*/
|
237 |
+
public function items(): array {
|
238 |
+
return $this->items;
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Whether the unit contains physical goods.
|
243 |
+
*
|
244 |
+
* @return bool
|
245 |
+
*/
|
246 |
+
public function contains_physical_goods(): bool {
|
247 |
+
return $this->contains_physical_goods;
|
248 |
+
}
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Returns the object as array.
|
252 |
+
*
|
253 |
+
* @return array
|
254 |
+
*/
|
255 |
+
public function to_array(): array {
|
256 |
+
$purchase_unit = array(
|
257 |
+
'reference_id' => $this->reference_id(),
|
258 |
+
'amount' => $this->amount()->to_array(),
|
259 |
+
'description' => $this->description(),
|
260 |
+
'items' => array_map(
|
261 |
+
static function ( Item $item ): array {
|
262 |
+
return $item->to_array();
|
263 |
+
},
|
264 |
+
$this->items()
|
265 |
+
),
|
266 |
+
);
|
267 |
+
if ( $this->ditch_items_when_mismatch( $this->amount(), ...$this->items() ) ) {
|
268 |
+
unset( $purchase_unit['items'] );
|
269 |
+
unset( $purchase_unit['amount']['breakdown'] );
|
270 |
+
}
|
271 |
+
|
272 |
+
if ( $this->payee() ) {
|
273 |
+
$purchase_unit['payee'] = $this->payee()->to_array();
|
274 |
+
}
|
275 |
+
|
276 |
+
if ( $this->payments() ) {
|
277 |
+
$purchase_unit['payments'] = $this->payments()->to_array();
|
278 |
+
}
|
279 |
+
|
280 |
+
if ( $this->shipping() ) {
|
281 |
+
$purchase_unit['shipping'] = $this->shipping()->to_array();
|
282 |
+
}
|
283 |
+
if ( $this->custom_id() ) {
|
284 |
+
$purchase_unit['custom_id'] = $this->custom_id();
|
285 |
+
}
|
286 |
+
if ( $this->invoice_id() ) {
|
287 |
+
$purchase_unit['invoice_id'] = $this->invoice_id();
|
288 |
+
}
|
289 |
+
if ( $this->soft_descriptor() ) {
|
290 |
+
$purchase_unit['soft_descriptor'] = $this->soft_descriptor();
|
291 |
+
}
|
292 |
+
return $purchase_unit;
|
293 |
+
}
|
294 |
+
|
295 |
+
/**
|
296 |
+
* All money values send to PayPal can only have 2 decimal points. WooCommerce internally does
|
297 |
+
* not have this restriction. Therefore the totals of the cart in WooCommerce and the totals
|
298 |
+
* of the rounded money values of the items, we send to PayPal, can differ. In those cases,
|
299 |
+
* we can not send the line items.
|
300 |
+
*
|
301 |
+
* @param Amount $amount The amount.
|
302 |
+
* @param Item ...$items The items.
|
303 |
+
* @return bool
|
304 |
+
*/
|
305 |
+
private function ditch_items_when_mismatch( Amount $amount, Item ...$items ): bool {
|
306 |
+
$fee_items_total = ( $amount->breakdown() && $amount->breakdown()->item_total() ) ?
|
307 |
+
$amount->breakdown()->item_total()->value() : null;
|
308 |
+
$fee_tax_total = ( $amount->breakdown() && $amount->breakdown()->tax_total() ) ?
|
309 |
+
$amount->breakdown()->tax_total()->value() : null;
|
310 |
+
|
311 |
+
foreach ( $items as $item ) {
|
312 |
+
if ( null !== $fee_items_total ) {
|
313 |
+
$fee_items_total -= $item->unit_amount()->value() * $item->quantity();
|
314 |
+
}
|
315 |
+
if ( null !== $fee_tax_total ) {
|
316 |
+
$fee_tax_total -= $item->tax()->value() * $item->quantity();
|
317 |
+
}
|
318 |
+
}
|
319 |
+
|
320 |
+
$fee_items_total = round( $fee_items_total, 2 );
|
321 |
+
$fee_tax_total = round( $fee_tax_total, 2 );
|
322 |
+
|
323 |
+
if ( 0.0 !== $fee_items_total || 0.0 !== $fee_tax_total ) {
|
324 |
+
return true;
|
325 |
+
}
|
326 |
+
|
327 |
+
$breakdown = $this->amount()->breakdown();
|
328 |
+
if ( ! $breakdown ) {
|
329 |
+
return false;
|
330 |
+
}
|
331 |
+
$amount_total = 0;
|
332 |
+
if ( $breakdown->shipping() ) {
|
333 |
+
$amount_total += $breakdown->shipping()->value();
|
334 |
+
}
|
335 |
+
if ( $breakdown->item_total() ) {
|
336 |
+
$amount_total += $breakdown->item_total()->value();
|
337 |
+
}
|
338 |
+
if ( $breakdown->discount() ) {
|
339 |
+
$amount_total -= $breakdown->discount()->value();
|
340 |
+
}
|
341 |
+
if ( $breakdown->tax_total() ) {
|
342 |
+
$amount_total += $breakdown->tax_total()->value();
|
343 |
+
}
|
344 |
+
if ( $breakdown->shipping_discount() ) {
|
345 |
+
$amount_total -= $breakdown->shipping_discount()->value();
|
346 |
+
}
|
347 |
+
if ( $breakdown->handling() ) {
|
348 |
+
$amount_total += $breakdown->handling()->value();
|
349 |
+
}
|
350 |
+
if ( $breakdown->insurance() ) {
|
351 |
+
$amount_total += $breakdown->insurance()->value();
|
352 |
+
}
|
353 |
+
|
354 |
+
$amount_value = $this->amount()->value();
|
355 |
+
$needs_to_ditch = (string) $amount_total !== (string) $amount_value;
|
356 |
+
return $needs_to_ditch;
|
357 |
+
}
|
358 |
+
}
|
modules/ppcp-api-client/src/Entity/class-refund.php
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The refund object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare( strict_types=1 );
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Refund
|
14 |
+
*/
|
15 |
+
class Refund {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The Capture.
|
19 |
+
*
|
20 |
+
* @var Capture
|
21 |
+
*/
|
22 |
+
private $capture;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The invoice id.
|
26 |
+
*
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
private $invoice_id;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* The note to the payer.
|
33 |
+
*
|
34 |
+
* @var string
|
35 |
+
*/
|
36 |
+
private $note_to_payer;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* The Amount.
|
40 |
+
*
|
41 |
+
* @var Amount|null
|
42 |
+
*/
|
43 |
+
private $amount;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Refund constructor.
|
47 |
+
*
|
48 |
+
* @param Capture $capture The capture where the refund is supposed to be applied at.
|
49 |
+
* @param string $invoice_id The invoice id.
|
50 |
+
* @param string $note_to_payer The note to the payer.
|
51 |
+
* @param Amount|null $amount The Amount.
|
52 |
+
*/
|
53 |
+
public function __construct(
|
54 |
+
Capture $capture,
|
55 |
+
string $invoice_id,
|
56 |
+
string $note_to_payer = '',
|
57 |
+
Amount $amount = null
|
58 |
+
) {
|
59 |
+
$this->capture = $capture;
|
60 |
+
$this->invoice_id = $invoice_id;
|
61 |
+
$this->note_to_payer = $note_to_payer;
|
62 |
+
$this->amount = $amount;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Returns the capture for the refund.
|
67 |
+
*
|
68 |
+
* @return Capture
|
69 |
+
*/
|
70 |
+
public function for_capture() : Capture {
|
71 |
+
return $this->capture;
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Return the invoice id.
|
76 |
+
*
|
77 |
+
* @return string
|
78 |
+
*/
|
79 |
+
public function invoice_id() : string {
|
80 |
+
return $this->invoice_id;
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Returns the note to the payer.
|
85 |
+
*
|
86 |
+
* @return string
|
87 |
+
*/
|
88 |
+
public function note_to_payer() : string {
|
89 |
+
return $this->note_to_payer;
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Returns the Amount.
|
94 |
+
*
|
95 |
+
* @return Amount|null
|
96 |
+
*/
|
97 |
+
public function amount() {
|
98 |
+
return $this->amount;
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Returns the object as array.
|
103 |
+
*
|
104 |
+
* @return array
|
105 |
+
*/
|
106 |
+
public function to_array() : array {
|
107 |
+
$data = array(
|
108 |
+
'invoice_id' => $this->invoice_id(),
|
109 |
+
);
|
110 |
+
if ( $this->note_to_payer() ) {
|
111 |
+
$data['note_to_payer'] = $this->note_to_payer();
|
112 |
+
}
|
113 |
+
if ( $this->amount() ) {
|
114 |
+
$data['amount'] = $this->amount()->to_array();
|
115 |
+
}
|
116 |
+
return $data;
|
117 |
+
}
|
118 |
+
}
|
modules/ppcp-api-client/src/Entity/class-sellerstatus.php
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The seller status entity.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare( strict_types=1 );
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class SellerStatus
|
14 |
+
*/
|
15 |
+
class SellerStatus {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The products.
|
19 |
+
*
|
20 |
+
* @var SellerStatusProduct[]
|
21 |
+
*/
|
22 |
+
private $products;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* SellerStatus constructor.
|
26 |
+
*
|
27 |
+
* @param SellerStatusProduct[] $products The products.
|
28 |
+
*/
|
29 |
+
public function __construct( array $products ) {
|
30 |
+
foreach ( $products as $key => $product ) {
|
31 |
+
if ( is_a( $product, SellerStatusProduct::class ) ) {
|
32 |
+
continue;
|
33 |
+
}
|
34 |
+
unset( $products[ $key ] );
|
35 |
+
}
|
36 |
+
$this->products = $products;
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Returns the products.
|
41 |
+
*
|
42 |
+
* @return SellerStatusProduct[]
|
43 |
+
*/
|
44 |
+
public function products() : array {
|
45 |
+
return $this->products;
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Returns the enitity as array.
|
50 |
+
*
|
51 |
+
* @return array
|
52 |
+
*/
|
53 |
+
public function to_array() : array {
|
54 |
+
$products = array_map(
|
55 |
+
function( SellerStatusProduct $product ) : array {
|
56 |
+
return $product->to_array();
|
57 |
+
},
|
58 |
+
$this->products()
|
59 |
+
);
|
60 |
+
|
61 |
+
return array(
|
62 |
+
'products' => $products,
|
63 |
+
);
|
64 |
+
}
|
65 |
+
}
|
modules/ppcp-api-client/src/Entity/class-sellerstatusproduct.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The products of a seller status.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare( strict_types=1 );
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class SellerStatusProduct
|
14 |
+
*/
|
15 |
+
class SellerStatusProduct {
|
16 |
+
|
17 |
+
const VETTING_STATUS_APPROVED = 'APPROVED';
|
18 |
+
const VETTING_STATUS_PENDING = 'PENDING';
|
19 |
+
const VETTING_STATUS_DECLINED = 'DECLINED';
|
20 |
+
const VETTING_STATUS_SUBSCRIBED = 'SUBSCRIBED';
|
21 |
+
const VETTING_STATUS_IN_REVIEW = 'IN_REVIEW';
|
22 |
+
const VETTING_STATUS_DENIED = 'DENIED';
|
23 |
+
/**
|
24 |
+
* The name of the product.
|
25 |
+
*
|
26 |
+
* @var string
|
27 |
+
*/
|
28 |
+
private $name;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* The vetting status of the product.
|
32 |
+
*
|
33 |
+
* @var string
|
34 |
+
*/
|
35 |
+
private $vetting_status;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* The capabilities of the product.
|
39 |
+
*
|
40 |
+
* @var string[]
|
41 |
+
*/
|
42 |
+
private $capabilities;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* SellerStatusProduct constructor.
|
46 |
+
*
|
47 |
+
* @param string $name The name of the product.
|
48 |
+
* @param string $vetting_status The vetting status of the product.
|
49 |
+
* @param string[] $capabilities The capabilities of the product.
|
50 |
+
*/
|
51 |
+
public function __construct(
|
52 |
+
string $name,
|
53 |
+
string $vetting_status,
|
54 |
+
array $capabilities
|
55 |
+
) {
|
56 |
+
foreach ( $capabilities as $key => $capability ) {
|
57 |
+
if ( is_string( $capability ) ) {
|
58 |
+
continue;
|
59 |
+
}
|
60 |
+
unset( $capabilities[ $key ] );
|
61 |
+
}
|
62 |
+
$this->name = $name;
|
63 |
+
$this->vetting_status = $vetting_status;
|
64 |
+
$this->capabilities = $capabilities;
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Returns the name of the product.
|
69 |
+
*
|
70 |
+
* @return string
|
71 |
+
*/
|
72 |
+
public function name() : string {
|
73 |
+
return $this->name;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Returns the vetting status for this product.
|
78 |
+
*
|
79 |
+
* @return string
|
80 |
+
*/
|
81 |
+
public function vetting_status() : string {
|
82 |
+
return $this->vetting_status;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Returns the capabilities of this product.
|
87 |
+
*
|
88 |
+
* @return string[]
|
89 |
+
*/
|
90 |
+
public function capabilities() : array {
|
91 |
+
return $this->capabilities;
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Returns the entity as array.
|
96 |
+
*
|
97 |
+
* @return array
|
98 |
+
*/
|
99 |
+
public function to_array() : array {
|
100 |
+
return array(
|
101 |
+
'name' => $this->name(),
|
102 |
+
'vetting_status' => $this->vetting_status(),
|
103 |
+
'capabilities' => $this->capabilities(),
|
104 |
+
);
|
105 |
+
}
|
106 |
+
|
107 |
+
|
108 |
+
}
|
modules/ppcp-api-client/src/Entity/class-shipping.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The Shipping object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Shipping
|
14 |
+
*/
|
15 |
+
class Shipping {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The name.
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
private $name;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The address.
|
26 |
+
*
|
27 |
+
* @var Address
|
28 |
+
*/
|
29 |
+
private $address;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Shipping constructor.
|
33 |
+
*
|
34 |
+
* @param string $name The name.
|
35 |
+
* @param Address $address The address.
|
36 |
+
*/
|
37 |
+
public function __construct( string $name, Address $address ) {
|
38 |
+
$this->name = $name;
|
39 |
+
$this->address = $address;
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Returns the name.
|
44 |
+
*
|
45 |
+
* @return string
|
46 |
+
*/
|
47 |
+
public function name(): string {
|
48 |
+
return $this->name;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Returns the shipping address.
|
53 |
+
*
|
54 |
+
* @return Address
|
55 |
+
*/
|
56 |
+
public function address(): Address {
|
57 |
+
return $this->address;
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Returns the object as array.
|
62 |
+
*
|
63 |
+
* @return array
|
64 |
+
*/
|
65 |
+
public function to_array(): array {
|
66 |
+
return array(
|
67 |
+
'name' => array(
|
68 |
+
'full_name' => $this->name(),
|
69 |
+
),
|
70 |
+
'address' => $this->address()->to_array(),
|
71 |
+
);
|
72 |
+
}
|
73 |
+
}
|
modules/ppcp-api-client/src/Entity/class-token.php
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The Token object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Class Token
|
16 |
+
*/
|
17 |
+
class Token {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* The Token data.
|
21 |
+
*
|
22 |
+
* @var \stdClass
|
23 |
+
*/
|
24 |
+
private $json;
|
25 |
+
|
26 |
+
/**
|
27 |
+
* The timestamp when the Token was created.
|
28 |
+
*
|
29 |
+
* @var int
|
30 |
+
*/
|
31 |
+
private $created;
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Token constructor.
|
35 |
+
*
|
36 |
+
* @param \stdClass $json The JSON object.
|
37 |
+
* @throws RuntimeException When The JSON object is not valid.
|
38 |
+
*/
|
39 |
+
public function __construct( \stdClass $json ) {
|
40 |
+
if ( ! isset( $json->created ) ) {
|
41 |
+
$json->created = time();
|
42 |
+
}
|
43 |
+
if ( ! $this->validate( $json ) ) {
|
44 |
+
throw new RuntimeException( 'Token not valid' );
|
45 |
+
}
|
46 |
+
$this->json = $json;
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Returns the timestamp when the Token is expired.
|
51 |
+
*
|
52 |
+
* @return int
|
53 |
+
*/
|
54 |
+
public function expiration_timestamp(): int {
|
55 |
+
|
56 |
+
return $this->json->created + $this->json->expires_in;
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Returns the token.
|
61 |
+
*
|
62 |
+
* @return string
|
63 |
+
*/
|
64 |
+
public function token(): string {
|
65 |
+
return (string) $this->json->token;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Returns whether the Token is still valid.
|
70 |
+
*
|
71 |
+
* @return bool
|
72 |
+
*/
|
73 |
+
public function is_valid(): bool {
|
74 |
+
return time() < $this->json->created + $this->json->expires_in;
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Returns the Token as JSON string.
|
79 |
+
*
|
80 |
+
* @return string
|
81 |
+
*/
|
82 |
+
public function as_json(): string {
|
83 |
+
return wp_json_encode( $this->json );
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Returns a Token based off a JSON string.
|
88 |
+
*
|
89 |
+
* @param string $json The JSON string.
|
90 |
+
*
|
91 |
+
* @return static
|
92 |
+
*/
|
93 |
+
public static function from_json( string $json ): self {
|
94 |
+
$json = (object) json_decode( $json );
|
95 |
+
if ( isset( $json->access_token ) || isset( $json->client_token ) ) {
|
96 |
+
$json->token = isset( $json->access_token ) ? $json->access_token : $json->client_token;
|
97 |
+
}
|
98 |
+
|
99 |
+
return new Token( $json );
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Validates whether a JSON object can be transformed to a Token object.
|
104 |
+
*
|
105 |
+
* @param \stdClass $json The JSON object.
|
106 |
+
*
|
107 |
+
* @return bool
|
108 |
+
*/
|
109 |
+
private function validate( \stdClass $json ): bool {
|
110 |
+
$property_map = array(
|
111 |
+
'created' => 'is_int',
|
112 |
+
'expires_in' => 'is_int',
|
113 |
+
'token' => 'is_string',
|
114 |
+
);
|
115 |
+
|
116 |
+
foreach ( $property_map as $property => $validator ) {
|
117 |
+
if ( ! isset( $json->{$property} ) || ! $validator( $json->{$property} ) ) {
|
118 |
+
return false;
|
119 |
+
}
|
120 |
+
}
|
121 |
+
return true;
|
122 |
+
}
|
123 |
+
}
|
modules/ppcp-api-client/src/Entity/class-webhook.php
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* The Webhook object.
|
4 |
+
*
|
5 |
+
* @package WooCommerce\PayPalCommerce\ApiClient\Entity
|
6 |
+
*/
|
7 |
+
|
8 |
+
declare(strict_types=1);
|
9 |
+
|
10 |
+
namespace WooCommerce\PayPalCommerce\ApiClient\Entity;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Class Webhook
|
14 |
+
*/
|
15 |
+
class Webhook {
|
16 |
+
|
17 |
+
/**
|
18 |
+
* The ID of the webhook.
|
19 |
+
*
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
private $id;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* The URL of the webhook.
|
26 |
+
*
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
private $url;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* The event types.
|
33 |
+
*
|
34 |
+
* @var string[]
|
35 |
+
*/
|
36 |
+
private $event_types;
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Webhook constructor.
|
40 |
+
*
|
41 |
+
* @param string $url The URL of the webhook.
|
42 |
+
* @param string[] $event_types The associated event types.
|
43 |
+
* @param string $id The id of the webhook.
|
44 |
+
*/
|
45 |
+
public function __construct( string $url, array $event_types, string $id = '' ) {
|
46 |
+
$this->url = $url;
|
47 |
+
$this->event_types = $event_types;
|
48 |
+
$this->id = $id;
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Returns the id of the webhook.
|
53 |
+
*
|
54 |
+
* @return string
|
55 |
+
*/
|
56 |
+
public function id(): string {
|
57 |
+
|
58 |
+
return $this->id;
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Returns the URL listening to the hook.
|
63 |
+
*
|
64 |
+
* @return string
|
65 |
+
*/
|
66 |
+
public function url(): string {
|
67 |
+
|
68 |
+
return $this->url;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Returns the event types.
|
73 |
+
*
|
74 |
+
* @return array
|
75 |
+
*/
|
76 |
+
public function event_types(): array {
|
77 |
+
|
78 |
+
return $this->event_types;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Returns the object as array.
|
83 |
+
*
|
84 |
+
* @return array
|
85 |
+
*/
|
86 |
+
public function to_array(): array {
|
87 |
+
|
88 |
+
$data = array(
|
89 |
+
'url' => $this->url(),
|
90 |
+
'event_types' => $this->event_types(),
|
91 |
+
);
|
92 |
+
if ( $this->id() ) {
|
93 |
+
$data['id'] = $this->id();
|
94 |
+
}
|
95 |
+
return $data;
|
96 |
+
}
|
97 |
+
}
|
modules/ppcp-api-client/src/Exception/class-notfoundexception.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|