loadGateWay($orderSN, $payway); //构造要请求的参数数组,无需改动 switch ($payway) { case 'wx': case 'alipay': default: try { \Stripe\Stripe::setApiKey($this->payGateway->merchant_id); $amount = bcmul($this->order->actual_price, 100, 2); $price = $this->order->actual_price; $gbp = bcmul($this->getGbpCurrency($this->order->actual_price), 100, 2); $orderid = $this->order->order_sn; $pk = $this->payGateway->merchant_id; $return_url = site_url() . $this->payGateway->pay_handleroute . '/return_url/?orderid=' . $this->order->order_sn; $html = " 收银台

收银台


付款信息
¥{$price}

订单编号:$orderid

支付失败,请更换卡片或检查输入信息
"; return $html; } catch (\Exception $e) { throw new RuleValidationException(__('dujiaoka.prompt.abnormal_payment_channel') . $e->getMessage()); } break; } } public function returnUrl(Request $request) { $data = $request->all(); $cacheord = $this->orderService->detailOrderSN($data['orderid']); if (!$cacheord) { return redirect(url('detail-order-sn', ['orderSN' => $data['orderid']])); } $payGateway = $this->payService->detail($cacheord->pay_id); \Stripe\Stripe::setApiKey($payGateway -> merchant_pem); $source_object = \Stripe\Source::retrieve($data['source']); //die($source_object); if ($source_object->status == 'chargeable') { \Stripe\Charge::create([ 'amount' => $source_object->amount, 'currency' => $source_object->currency, 'source' => $data['source'], ]); if ($source_object->owner->name == $data['orderid']) { $this->orderProcessService->completedOrder($data['orderid'], $cacheord->actual_price, $source_object->id); } } return redirect(url('detail-order-sn', ['orderSN' => $data['orderid']])); } public function check(Request $request) { $data = $request->all(); $cacheord = $this->orderService->detailOrderSN($data['orderid']); if (!$cacheord) { //可能已异步回调成功,跳转 return 'fail'; } else { $payGateway = $this->payService->detail($cacheord->pay_id); \Stripe\Stripe::setApiKey($payGateway -> merchant_pem); $source_object = \Stripe\Source::retrieve($data['source']); if ($source_object->status == 'chargeable') { \Stripe\Charge::create([ 'amount' => $source_object->amount, 'currency' => $source_object->currency, 'source' => $data['source'], ]); } if ($source_object->status == 'consumed' && $source_object->owner->name == $data['orderid']) { $this->orderProcessService->completedOrder($data['orderid'], $cacheord->actual_price, $source_object->id); return 'success'; } else { return 'fail'; } } } public function charge(Request $request) { $data = $request->all(); $cacheord = $this->orderService->detailOrderSN($data['orderid']); if (!$cacheord) { //可能已异步回调成功,跳转 return 'fail'; } else { try { $payGateway = $this->payService->detail($cacheord->pay_id); \Stripe\Stripe::setApiKey($payGateway -> merchant_pem); $result = \Stripe\Charge::create([ 'amount' => bcmul($this->getGbpCurrency($cacheord->actual_price), 100,0), 'currency' => 'gbp', 'source' => $data['stripeToken'], ]); if ($result->status == 'succeeded') { $this->orderProcessService->completedOrder($data['orderid'], $cacheord->actual_price, $data['stripeToken']); return 'success'; } return $result; } catch (\Exception $e) { return $e->getMessage(); } } } /** * 根据RMB获取英镑 * @param $cny * @return float|int * @throws \Exception */ public function getGbpCurrency($cny) { $client = new Client(); $res = $client->get('https://api.dov.moe/exchange?src=cny&dst=gbp'); $fxrate = json_decode($res->getBody(), true); if ($fxrate['code'] != 1) { $dfFxrate = 0.12; } else { $dfFxrate = $fxrate['data']['value'] * 1.029; } return bcmul($cny , $dfFxrate, 2) + 0.2; } }