bk stripe
This commit is contained in:
parent
8b072bbb3c
commit
6a5aebce69
|
|
@ -13,8 +13,9 @@ namespace Beike\Repositories;
|
|||
|
||||
use Carbon\Carbon;
|
||||
use Beike\Models\Order;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
class OrderRepo
|
||||
{
|
||||
|
|
@ -57,6 +58,13 @@ class OrderRepo
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过订单号获取订单
|
||||
*
|
||||
* @param $number
|
||||
* @param $customer
|
||||
* @return Builder|Model|object|null
|
||||
*/
|
||||
public static function getOrderByNumber($number, $customer)
|
||||
{
|
||||
$order = Order::query()
|
||||
|
|
@ -67,6 +75,26 @@ class OrderRepo
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过订单ID或者订单号获取订单
|
||||
*
|
||||
* @param $number
|
||||
* @param $customer
|
||||
* @return Builder|Model|object|null
|
||||
*/
|
||||
public static function getOrderByIdOrNumber($number, $customer)
|
||||
{
|
||||
$order = Order::query()
|
||||
->where(function ($query) use ($number) {
|
||||
$query->where('number', $number)
|
||||
->orWhere('id', $number);
|
||||
})
|
||||
->where('customer_id', $customer->id)
|
||||
->first();
|
||||
return $order;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return Order
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ namespace Beike\Shop\Http\Controllers\Account;
|
|||
use Illuminate\Http\Request;
|
||||
use Beike\Repositories\OrderRepo;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Beike\Shop\Services\PaymentService;
|
||||
use Beike\Shop\Http\Controllers\Controller;
|
||||
use Beike\Shop\Http\Resources\Account\OrderList;
|
||||
|
||||
|
|
@ -49,10 +51,34 @@ class OrderController extends Controller
|
|||
return view('account/order_info', ['order' => $order]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单提交成功页
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $number
|
||||
* @return View
|
||||
*/
|
||||
public function success(Request $request, $number): View
|
||||
{
|
||||
$customer = current_customer();
|
||||
$order = OrderRepo::getOrderByNumber($number, $customer);
|
||||
return view('account/order_success', ['order' => $order]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单支付页面
|
||||
*
|
||||
* @param Request $request
|
||||
* @param $number
|
||||
* @return Factory|View
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function pay(Request $request, $number)
|
||||
{
|
||||
$customer = current_customer();
|
||||
$order = OrderRepo::getOrderByNumber($number, $customer);
|
||||
return (new PaymentService($order))->pay();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ Route::prefix('/')
|
|||
Route::get('checkout', [CheckoutController::class, 'index'])->name('checkout.index');
|
||||
Route::put('checkout', [CheckoutController::class, 'update'])->name('checkout.update');
|
||||
Route::post('checkout/confirm', [CheckoutController::class, 'confirm'])->name('checkout.confirm');
|
||||
|
||||
Route::get('orders/{number}/success', [OrderController::class, 'success'])->name('orders.success');
|
||||
Route::get('orders/{number}/pay', [OrderController::class, 'pay'])->name('orders.pay');
|
||||
});
|
||||
|
||||
Route::prefix('account')
|
||||
|
|
@ -58,8 +61,6 @@ Route::prefix('/')
|
|||
Route::get('orders', [OrderController::class, 'index'])->name('account.order.index');
|
||||
Route::get('orders/{number}', [OrderController::class, 'show'])->name('account.order.show');
|
||||
});
|
||||
|
||||
Route::get('orders/{number}/success', [OrderController::class, 'success'])->name('account.order_success.index');
|
||||
});
|
||||
|
||||
Route::get('/{url_key}', [PagesController::class, 'show'])->name('pages.show');
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* PaymentService.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @created 2022-07-06 17:33:06
|
||||
* @modified 2022-07-06 17:33:06
|
||||
*/
|
||||
|
||||
namespace Beike\Shop\Services;
|
||||
|
||||
use Beike\Models\Order;
|
||||
use Beike\Repositories\OrderRepo;
|
||||
use Cartalyst\Stripe\Stripe;
|
||||
|
||||
class PaymentService
|
||||
{
|
||||
private $order;
|
||||
|
||||
private $orderId;
|
||||
|
||||
private $paymentMethodCode;
|
||||
|
||||
public function __construct($order)
|
||||
{
|
||||
$customer = current_customer();
|
||||
if (is_numeric($order)) {
|
||||
$this->order = OrderRepo::getOrderByIdOrNumber($this->orderId, $customer);
|
||||
} elseif ($order instanceof Order) {
|
||||
$this->order = $order;
|
||||
}
|
||||
if (empty($this->order)) {
|
||||
throw new \Exception("无效订单");
|
||||
}
|
||||
$this->orderId = (int)$this->order->id;
|
||||
$this->paymentMethodCode = $this->order->payment_method_code;
|
||||
}
|
||||
|
||||
|
||||
public function pay()
|
||||
{
|
||||
if ($this->paymentMethodCode == 'bk_stripe') {
|
||||
$apiKey = setting('bk_stripe.secret_key');
|
||||
$stripe = Stripe::make($apiKey, '2020-08-27');
|
||||
|
||||
/**
|
||||
$customer = $stripe->customers()->create([
|
||||
'email' => $this->order->email,
|
||||
]);
|
||||
|
||||
$customers = $stripe->customers()->all();
|
||||
|
||||
$charge = $stripe->charges()->create([
|
||||
'customer' => $customer['id'],
|
||||
'currency' => 'USD',
|
||||
'amount' => 50.49,
|
||||
]);
|
||||
**/
|
||||
|
||||
return view("checkout.payment.{$this->paymentMethodCode}");
|
||||
// echo $charge['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,10 +7,12 @@
|
|||
"require": {
|
||||
"php": "^7.3|^8.0",
|
||||
"ext-json": "*",
|
||||
"cartalyst/stripe": "^2.4",
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"laravel/framework": "^8.65",
|
||||
"laravel/tinker": "^2.5"
|
||||
"laravel/tinker": "^2.5",
|
||||
"stripe/stripe-php": "^8.8"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-debugbar": "^3.6",
|
||||
|
|
|
|||
|
|
@ -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": "68f4bf8fac13d522214b959517c97b44",
|
||||
"content-hash": "3e50a922b00db84582eaa827333fe7da",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
|
|
@ -134,6 +134,69 @@
|
|||
],
|
||||
"time": "2021-08-15T20:50:18+00:00"
|
||||
},
|
||||
{
|
||||
"name": "cartalyst/stripe",
|
||||
"version": "v2.4.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cartalyst/stripe.git",
|
||||
"reference": "e75b4d714fec5f034d533e55f5365f0229b5686d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/cartalyst/stripe/zipball/e75b4d714fec5f034d533e55f5365f0229b5686d",
|
||||
"reference": "e75b4d714fec5f034d533e55f5365f0229b5686d",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "~6.0|~7.0",
|
||||
"php": ">=5.5.9"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.0",
|
||||
"phpunit/phpunit": "^9.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"component": "package",
|
||||
"branch-alias": {
|
||||
"dev-master": "2.4.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Cartalyst\\Stripe\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Cartalyst LLC",
|
||||
"email": "help@cartalyst.com",
|
||||
"homepage": "https://cartalyst.com"
|
||||
}
|
||||
],
|
||||
"description": "A comprehensive Stripe API package.",
|
||||
"keywords": [
|
||||
"cartalyst",
|
||||
"php",
|
||||
"stripe"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/cartalyst/stripe/issues",
|
||||
"source": "https://github.com/cartalyst/stripe/tree/v2.4.6"
|
||||
},
|
||||
"time": "2021-10-09T10:40:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dflydev/dot-access-data",
|
||||
"version": "v3.0.1",
|
||||
|
|
@ -3008,6 +3071,72 @@
|
|||
],
|
||||
"time": "2021-09-25T23:10:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "stripe/stripe-php",
|
||||
"version": "v8.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/stripe/stripe-php.git",
|
||||
"reference": "06bfb65639cfecae7c2b57d340f740599c548753"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/stripe/stripe-php/zipball/06bfb65639cfecae7c2b57d340f740599c548753",
|
||||
"reference": "06bfb65639cfecae7c2b57d340f740599c548753",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*",
|
||||
"php": ">=5.6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "3.5.0",
|
||||
"phpstan/phpstan": "^1.2",
|
||||
"phpunit/phpunit": "^5.7 || ^9.0",
|
||||
"squizlabs/php_codesniffer": "^3.3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Stripe\\": "lib/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Stripe and contributors",
|
||||
"homepage": "https://github.com/stripe/stripe-php/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Stripe PHP Library",
|
||||
"homepage": "https://stripe.com/",
|
||||
"keywords": [
|
||||
"api",
|
||||
"payment processing",
|
||||
"stripe"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/stripe/stripe-php/issues",
|
||||
"source": "https://github.com/stripe/stripe-php/tree/v8.8.0"
|
||||
},
|
||||
"time": "2022-06-23T16:42:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "swiftmailer/swiftmailer",
|
||||
"version": "v6.3.0",
|
||||
|
|
@ -8719,8 +8848,9 @@
|
|||
"prefer-stable": true,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": "^7.3|^8.0"
|
||||
"php": "^7.3|^8.0",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.0.0"
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
dd
|
||||
Loading…
Reference in New Issue