From c93b3cf64339bcac84f10b08688a2d52034fe950 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Wed, 10 Aug 2022 19:49:23 +0800 Subject: [PATCH] add paypal --- composer.json | 1 + composer.lock | 73 ++++++++++++++++++- .../Paypal/Controllers/PaypalController.php | 65 +++++++++++++++++ .../Paypal/Views/checkout/payment.blade.php | 1 + plugins/Paypal/columns.php | 52 +++++++++++++ plugins/Paypal/config.json | 12 +++ resources/lang/en/admin/plugin.php | 4 +- 7 files changed, 205 insertions(+), 3 deletions(-) create mode 100644 plugins/Paypal/Controllers/PaypalController.php create mode 100644 plugins/Paypal/Views/checkout/payment.blade.php create mode 100644 plugins/Paypal/columns.php create mode 100644 plugins/Paypal/config.json diff --git a/composer.json b/composer.json index 287125b4..6b22cd21 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "laravel/framework": "^9.0", "laravel/tinker": "^2.7", "spatie/laravel-permission": "^5.5", + "srmklive/paypal": "^3.0", "stripe/stripe-php": "^8.8", "tormjens/eventy": "^0.8.0", "zanysoft/laravel-zip": "^1.0" diff --git a/composer.lock b/composer.lock index fd7a6073..5d873065 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1d6f93c19127c046e4f6e1f02e446e1d", + "content-hash": "baf9504253adfc5cc3fd0b9e881f26a1", "packages": [ { "name": "asm89/stack-cors", @@ -3923,6 +3923,77 @@ ], "time": "2022-06-29T23:11:42+00:00" }, + { + "name": "srmklive/paypal", + "version": "3.0.16", + "source": { + "type": "git", + "url": "https://github.com/srmklive/laravel-paypal.git", + "reference": "7138c3b6665d270c40e0df603b8f0c07fc583ca3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/srmklive/laravel-paypal/zipball/7138c3b6665d270c40e0df603b8f0c07fc583ca3", + "reference": "7138c3b6665d270c40e0df603b8f0c07fc583ca3", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-curl": "*", + "guzzlehttp/guzzle": "~7.0", + "illuminate/support": "~6.0|~7.0|~8.0|~9.0", + "nesbot/carbon": "~2.0", + "php": ">=7.2|^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.0|^9.0", + "symfony/var-dumper": "~5.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Srmklive\\PayPal\\Providers\\PayPalServiceProvider" + ], + "aliases": { + "PayPal": "Srmklive\\PayPal\\Facades\\PayPal" + } + } + }, + "autoload": { + "psr-4": { + "Srmklive\\PayPal\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Raza Mehdi", + "email": "srmk@outlook.com" + } + ], + "description": "Laravel plugin For Processing Payments Through Paypal Express Checkout. Can Be Used Independently With Other Applications.", + "keywords": [ + "http", + "laravel paypal", + "paypal", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/srmklive/laravel-paypal/issues", + "source": "https://github.com/srmklive/laravel-paypal/tree/3.0.16" + }, + "time": "2022-08-01T08:42:16+00:00" + }, { "name": "stripe/stripe-php", "version": "v8.12.0", diff --git a/plugins/Paypal/Controllers/PaypalController.php b/plugins/Paypal/Controllers/PaypalController.php new file mode 100644 index 00000000..1df5a3bb --- /dev/null +++ b/plugins/Paypal/Controllers/PaypalController.php @@ -0,0 +1,65 @@ + + * @created 2022-08-10 18:57:56 + * @modified 2022-08-10 18:57:56 + * + * https://www.zongscan.com/demo333/1311.html + * https://clickysoft.com/how-to-integrate-paypal-payment-gateway-in-laravel/ + * https://www.positronx.io/how-to-integrate-paypal-payment-gateway-in-laravel/ + * + */ + +namespace Plugin\Paypal\Controllers; + +use Srmklive\PayPal\Services\PayPal; + +class PaypalController +{ + public function handlePayment() + { + $product = []; + $product['items'] = [ + [ + 'name' => 'Nike Joyride 2', + 'price' => 112, + 'desc' => 'Running shoes for Men', + 'qty' => 2 + ] + ]; + + $product['invoice_id'] = 1; + $product['invoice_description'] = "Order #{$product['invoice_id']} Bill"; + $product['return_url'] = route('success.payment'); + $product['cancel_url'] = route('cancel.payment'); + $product['total'] = 224; + + $paypalModule = new PayPal(); + + $res = $paypalModule->setExpressCheckout($product); + $res = $paypalModule->setExpressCheckout($product, true); + + return redirect($res['paypal_link']); + } + + public function paymentCancel() + { + dd('Your payment has been declend. The payment cancelation page goes here!'); + } + + public function paymentSuccess(Request $request) + { + $paypalModule = new ExpressCheckout; + $response = $paypalModule->getExpressCheckoutDetails($request->token); + + if (in_array(strtoupper($response['ACK']), ['SUCCESS', 'SUCCESSWITHWARNING'])) { + dd('Payment was successfull. The payment success page goes here!'); + } + + dd('Error occured!'); + } +} diff --git a/plugins/Paypal/Views/checkout/payment.blade.php b/plugins/Paypal/Views/checkout/payment.blade.php new file mode 100644 index 00000000..902d5ea4 --- /dev/null +++ b/plugins/Paypal/Views/checkout/payment.blade.php @@ -0,0 +1 @@ +PAYPAL diff --git a/plugins/Paypal/columns.php b/plugins/Paypal/columns.php new file mode 100644 index 00000000..fd5e9441 --- /dev/null +++ b/plugins/Paypal/columns.php @@ -0,0 +1,52 @@ + + * @created 2022-06-29 21:16:23 + * @modified 2022-06-29 21:16:23 + */ + +return [ + [ + 'name' => 'sandbox_client_id', + 'label' => 'Sandbox Client ID', + 'type' => 'string', + 'required' => true, + 'description' => '沙盒模式 Client ID', + ], + [ + 'name' => 'sandbox_Secret', + 'label' => 'Sandbox Secret', + 'type' => 'string', + 'required' => true, + 'description' => '沙盒模式 Secret', + ], + [ + 'name' => 'live_client_id', + 'label' => 'Live Client ID', + 'type' => 'string', + 'required' => true, + 'description' => '正式环境 Client ID', + ], + [ + 'name' => 'live_Secret', + 'label' => 'Live Secret', + 'type' => 'string', + 'required' => true, + 'description' => '正式环境 Secret', + ], + [ + 'name' => 'sandbox_mode', + 'label' => '沙盒模式', + 'type' => 'select', + 'options' => [ + ['value' => '1', 'label' => '开启'], + ['value' => '0', 'label' => '关闭'] + ], + 'required' => true, + 'description' => '', + ] +]; diff --git a/plugins/Paypal/config.json b/plugins/Paypal/config.json new file mode 100644 index 00000000..b4aca971 --- /dev/null +++ b/plugins/Paypal/config.json @@ -0,0 +1,12 @@ +{ + "code": "paypal", + "name": "PayPal", + "description": "PayPal 支付 PayPal Developer", + "type": "payment", + "version": "v1.0.0", + "icon": "https://via.placeholder.com/100x100.png/99ee66?text=STRIPE", + "author": { + "name": "成都光大网络科技有限公司", + "email": "yangjin@opencart.cn" + } +} diff --git a/resources/lang/en/admin/plugin.php b/resources/lang/en/admin/plugin.php index 650f2447..c838e64e 100644 --- a/resources/lang/en/admin/plugin.php +++ b/resources/lang/en/admin/plugin.php @@ -24,8 +24,8 @@ return [ 'plugin_description' => 'Description', 'plugin_upload' => 'Upload(Only for zip file)', - 'shipping' => 'Payment', - 'payment' => 'Shipping', + 'shipping' => 'Shipping', + 'payment' => 'Payment', 'total' => 'Total', 'view' => 'View', ];