Skip to content

Commit

Permalink
paypal 支付升级处理
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyecommerce committed Aug 12, 2021
1 parent 9ef4f3a commit c6d94b6
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 16 deletions.
10 changes: 10 additions & 0 deletions app/appadmin/modules/Config/block/paymentpaypal/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Manager extends AppadminbaseBlockEdit implements AppadminbaseBlockEditInte
'paypal_account',
'paypal_password',
'paypal_signature',
'paypal_client_id',
'paypal_env',
];

Expand Down Expand Up @@ -142,6 +143,15 @@ public function getEditArr()
'remark' => '【选填】Paypal Api 签名'
],

[
'label' => Yii::$service->page->translate->__('Paypal Client Id'),
'name' => 'paypal_client_id',
'display' => [
'type' => 'inputString',
],
'remark' => '【选填】Paypal Client ID'
],


];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<b>注意1</b>:对于个人paypal账户收款,只需要填写<b>Paypal账户</b>即可,个人账户不支持paypal快捷支付(从购物车页面点击paypal按钮发起支付)
<br/><br/>
<b>注意2</b>:对于商户paypal账户收款,支持api授权,请您填写<b>Api账号信息</b>(就是尾部的三个api选项),支付功能更为完善。
<br/><br/>
<b>注意3</b>:如果开启快捷支付,在购物车页面直接发起paypal支付,那么必须填写Paypal Client Id
<br/><br/>
关于paypal设置的更多资料,请参看:<a style="text-decoration: underline;" target="_blank" href="https://www.fecmall.com/doc/fecshop-guide/instructions/cn-2.0/guide-fecmall_payment_paypal_method.html">商户paypal账户收款配置</a>
</div>
<?= $lang_attr ?>
<?= $textareas ?>
Expand Down
24 changes: 24 additions & 0 deletions app/appfront/modules/Payment/block/paypal/express/Start.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
class Start extends \yii\base\BaseObject
{

public function startButtonPayment()
{
$methodName_ = 'SetExpressCheckout';
$nvpStr_ = Yii::$service->payment->paypal->getExpressTokenNvpStr();
//echo $nvpStr_;exit;
$checkoutReturn = Yii::$service->payment->paypal->PPHttpPost5($methodName_, $nvpStr_);
//var_dump($checkoutReturn);
if (strtolower($checkoutReturn['ACK']) == 'success') {
$token = $checkoutReturn['TOKEN'];
if($token){
if(!Yii::$service->order->generatePPExpressOrder($token)){
return false;
}
echo '"'.$token.'"';
}

} elseif (strtolower($checkoutReturn['ACK']) == 'failure') {
echo $checkoutReturn['L_LONGMESSAGE0'];
} else {
var_dump($checkoutReturn);
}
}


public function startPayment()
{
$checkStatus = $this->checkStockQty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public function actionStart()
Yii::$service->payment->setPaymentMethod($payment_method);
$data = $this->getBlock()->startPayment();
}


public function actionButton()
{
$payment_method = Yii::$service->payment->paypal->express_payment_method;
Yii::$service->payment->setPaymentMethod($payment_method);
$this->getBlock('start')->startButtonPayment();
}

// 2.Review 从paypal确认后返回
public function actionReview()
{
Expand Down
45 changes: 39 additions & 6 deletions app/appfront/theme/base/front/checkout/cart/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use fec\helpers\CRequest;
?>
<div class="main container one-column">
<script src="<?= Yii::$service->payment->paypal->getPaypalSdkJsUrl($currency_info['code']) ?>"> </script>
<div class="col-main">
<?= Yii::$service->page->widget->render('base/breadcrumbs',$this); ?>
<?= Yii::$service->page->widget->render('base/flashmessage'); ?>
Expand Down Expand Up @@ -250,14 +251,46 @@
</table>
</div>
<div class="proceed_to_checkout">

<button onclick="location.href='<?= Yii::$service->url->getUrl('checkout/onepage'); ?>'" type="button" title="Proceed to Checkout" class="button btn-proceed-checkout btn-checkout"><span><span><?= Yii::$service->page->translate->__('Proceed to Pay');?></span></span></button>
<?php if ($enablePaypalExpress): ?>
<span class="or">- <?= Yii::$service->page->translate->__('OR');?> - </span>
<a class="express_paypal" href="<?= Yii::$service->url->getUrl('payment/paypal/express/start'); ?>">

</a>
<div style="clear: both; position: relative; z-index: 0;" id="paypal-button-container"></div>
<div id="onestepcheckout-place-order-loading" class="onestepcheckout-place-order-loading" style="font-size:1rem;display:none;color:#777"><img src="<?= Yii::$service->image->getImgUrl('images/opc-ajax-loader.gif') ?>">&nbsp;&nbsp;Please wait, processing your order...</div>
<script>
paypal.Buttons({
style: {
layout: 'vertical', // horizontal | vertical
size: 'medium', // small | medium | large | responsive
shape: 'rect', // pill | rect
color: 'gold', // gold | blue | silver | black
label: 'buynow',
//height:35, //35-55
},
createOrder: function () {
return fetch('<?= Yii::$service->url->getUrl('payment/paypal/express/button') ?>', {
method: 'post',
body: JSON.stringify({}),
headers: {
'content-type': 'application/json'
}
}).then(function (res) {
return res.json();
}).then(function (data) {
return data;
});
},
onApprove: function(data, actions) {
var postData = { token: data.orderID, PayerID: data.payerID, isAjax: true};
var dom=document.getElementById("onestepcheckout-place-order-loading");
dom.style.display="block";
window.location.href="<?= Yii::$service->url->getUrl('payment/paypal/express/review') ?>?token="+data.orderID+"&PayerID="+data.payerID;
}
}).render('#paypal-button-container');
</script>

<span style="float:none;" class="or">- <?= Yii::$service->page->translate->__('OR');?> - </span>
<?php endif; ?>

<button onclick="location.href='<?= Yii::$service->url->getUrl('checkout/onepage'); ?>'" type="button" title="Proceed to Checkout" class="button btn-proceed-checkout btn-checkout"><span><span><?= Yii::$service->page->translate->__('Proceed to Pay');?></span></span></button>

</div>
</div>
<div class="clear"></div>
Expand Down
23 changes: 23 additions & 0 deletions app/apphtml5/modules/Payment/block/paypal/express/Start.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@
*/
class Start extends \yii\base\BaseObject
{
public function startButtonPayment()
{
$methodName_ = 'SetExpressCheckout';
$nvpStr_ = Yii::$service->payment->paypal->getExpressTokenNvpStr();
//echo $nvpStr_;exit;
$checkoutReturn = Yii::$service->payment->paypal->PPHttpPost5($methodName_, $nvpStr_);
//var_dump($checkoutReturn);
if (strtolower($checkoutReturn['ACK']) == 'success') {
$token = $checkoutReturn['TOKEN'];
if($token){
if(!Yii::$service->order->generatePPExpressOrder($token)){
return false;
}
echo '"'.$token.'"';
}

} elseif (strtolower($checkoutReturn['ACK']) == 'failure') {
echo $checkoutReturn['L_LONGMESSAGE0'];
} else {
var_dump($checkoutReturn);
}
}

public function startPayment()
{
$checkStatus = $this->checkStockQty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public function actionStart()
Yii::$service->payment->setPaymentMethod($payment_method);
$data = $this->getBlock()->startPayment();
}


public function actionButton()
{
$payment_method = Yii::$service->payment->paypal->express_payment_method;
Yii::$service->payment->setPaymentMethod($payment_method);
$this->getBlock('start')->startButtonPayment();
}

// 2.Review 从paypal确认后返回
public function actionReview()
{
Expand Down
51 changes: 43 additions & 8 deletions app/apphtml5/theme/base/html5/checkout/cart/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
?>
<div class="main container one-column">
<div class="col-main">
<script src="<?= Yii::$service->payment->paypal->getPaypalSdkJsUrl($currency_info['code']) ?>"> </script>
<?= Yii::$service->page->widget->render('base/flashmessage'); ?>
<?php if(is_array($cart_info) && !empty($cart_info)): ?>

Expand Down Expand Up @@ -128,16 +129,50 @@
<div class="totals cart-totals">
<div class="proceed_to_checkout">
<div class="row no-gutter">
<div class="col-50">
<button onclick="location.href='<?= Yii::$service->url->getUrl('checkout/onepage'); ?>'" type="button" title="Proceed to Checkout" class="button btn-proceed-checkout btn-checkout"><span><span><?= Yii::$service->page->translate->__('Proceed to Pay');?></span></span></button>
</div>

<?php if ($enablePaypalExpress): ?>
<div class="col-50">
<a external class="express_paypal" href="<?= Yii::$service->url->getUrl('payment/paypal/express/start'); ?>">
<img src="<?= Yii::$service->image->getImgUrl('/images/pay.png') ?>" />
</a>
</div>
<div style="clear: both; position: relative; z-index: 0;" id="paypal-button-container"></div>
<div id="onestepcheckout-place-order-loading" class="onestepcheckout-place-order-loading" style="font-size:0.6rem;display:none;color:#777"><img src="<?= Yii::$service->image->getImgUrl('images/opc-ajax-loader.gif') ?>">&nbsp;&nbsp;Please wait, processing your order...</div>
<script>
paypal.Buttons({
style: {
layout: 'vertical', // horizontal | vertical
size: 'medium', // small | medium | large | responsive
shape: 'rect', // pill | rect
color: 'gold', // gold | blue | silver | black
label: 'buynow',
//height:35, //35-55
},
createOrder: function () {
return fetch('<?= Yii::$service->url->getUrl('payment/paypal/express/button') ?>', {
method: 'post',
body: JSON.stringify({}),
headers: {
'content-type': 'application/json'
}
}).then(function (res) {
return res.json();
}).then(function (data) {
return data;
});
},
onApprove: function(data, actions) {
var postData = { token: data.orderID, PayerID: data.payerID, isAjax: true};
var dom=document.getElementById("onestepcheckout-place-order-loading");
dom.style.display="block";
window.location.href="<?= Yii::$service->url->getUrl('payment/paypal/express/review') ?>?token="+data.orderID+"&PayerID="+data.payerID;
}
}).render('#paypal-button-container');
</script>

<span style="display:block;text-align:center;" class="or">- <?= Yii::$service->page->translate->__('OR');?> - </span>
<br/>
<?php endif; ?>

<div >
<button onclick="location.href='<?= Yii::$service->url->getUrl('checkout/onepage'); ?>'" type="button" title="Proceed to Checkout" class="button btn-proceed-checkout btn-checkout"><span><span><?= Yii::$service->page->translate->__('Proceed to Pay');?></span></span></button>
</div>

</div>
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions services/payment/Paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Paypal extends Service
protected $_password;
protected $_signature;
protected $_env;
protected $_client_id;

public function init()
{
Expand All @@ -93,13 +94,25 @@ public function init()
$this->_password = Yii::$app->store->get('payment_paypal', 'paypal_password');
$this->_signature = Yii::$app->store->get('payment_paypal', 'paypal_signature');
$this->_env = Yii::$app->store->get('payment_paypal', 'paypal_env');
$this->_client_id = Yii::$app->store->get('payment_paypal', 'paypal_client_id');

list($this->_ipnMessageModelName, $this->_ipnMessageModel) = \Yii::mapGet($this->_ipnMessageModelName);
$this->_allowChangOrderStatus = [
Yii::$service->order->payment_status_pending,
Yii::$service->order->payment_status_processing,
];
}

public function getPaypalSdkJsUrl($currencyCode)
{
if ($this->_client_id) {

return 'https://www.paypal.com/sdk/js?commit=false&currency='.$currencyCode.'&client-id='.$this->_client_id;
}

return '';
}

public function getPaypayLoginAccount()
{

Expand Down

0 comments on commit c6d94b6

Please sign in to comment.