提交 ceb6884c 编写于 作者: R root

paypal standard payment

上级 11d53bf1
......@@ -18,42 +18,116 @@ use yii\base\InvalidValueException;
class Start {
public function getLastData(){
$increment_id = Yii::$service->order->getSessionIncrementId();
$loaderImg = Yii::$service->image->getImgUrl('images/loader.gif','appfront');
$paypalLogoImg = Yii::$service->image->getImgUrl('custom/logo.png','appfront');
/*
$store_name = Store::getCurrentStoreLabel();
$paypal = Config::param("payment_method");
$submitAction = $paypal['paypal']['payments_standard']['redirect_url'];
$paypal_account = $paypal['paypal']['payments_standard']['user'];
$order_increment_id = $this->_order['increment_id'];
$order_currency = $this->_order['order_currency_code'];
$paymentaction = "sale";
$cmd = '_cart';
$upload = 1;
$increment_id = Yii::$service->order->getSessionIncrementId();
$order = Yii::$service->order->getInfoByIncrementId($increment_id);
//var_dump($order);
//exit;
Yii::$service->payment->setPaymentMethod($order['payment_method']);
$success_redirect_url = Yii::$service->payment->getStandardSuccessRedirectUrl();
$cancel_url = Yii::$service->payment->getStandardCancelUrl();
$ipn_url = Yii::$service->payment->getStandardIpnUrl();
$store_name = Yii::$service->store->currentStore;
$return_url = Url::getUrl('paypal/standard/success');
$cancel_url = Url::getUrl('paypal/standard/cancel');
$notify_url = Url::getUrl('paypal/ipn');
$payment_action = "sale";
$cmd = '_cart';
$upload = 1;
$tax = 0.00;
$tax_cart = 0.00;
$tax = 0.00;
$tax_cart = 0.00;
$payment_url = Yii::$service->payment->getStandardPaymentUrl();
$account = Yii::$service->payment->getStandardAccount();
$amount = $this->_order['grand_total'];
$shipping = $this->_order['shipping_total'];
$discount_amount = $this->_order['subtotal_with_discount'];
$discount_amount_cart = $discount_amount;
*/
return [
'loaderImg' => $loaderImg,
'paypalLogoImg' => $paypalLogoImg,
'loader_img' => $loaderImg,
'paypal_logo_img' => $paypalLogoImg,
'order' => $order,
'success_redirect_url' => $success_redirect_url,
'cancel_url' => $cancel_url,
'ipn_url' => $ipn_url,
'store_name' => $store_name,
'payment_action' => $payment_action,
'cmd' => $cmd,
'upload' => $upload,
'tax' => $tax,
'tax_cart' => $tax_cart,
'payment_url' => $payment_url,
'account' => $account,
'product_items_and_shipping' => $this->getProductItemsAndShipping($order),
'address_html' => $this->getAddressHtml($order),
];
}
public function getAddressHtml($order){
$stateCode = $order['customer_address_state'];
$countryCode = $order['customer_address_country'];
$country = Yii::$service->helper->country->getCountryNameByKey($countryCode);
$state = Yii::$service->helper->country->getStateByContryCode($countryCode,$stateCode);
$str = '
<input id="city" name="city" value="'.$order['customer_address_city'].'" type="hidden"/>
<input id="country" name="country" value="'.$countryCode.'" type="hidden"/>
<input id="email" name="email" value="'.$order['customer_email'].'" type="hidden"/>
<input id="first_name" name="first_name" value="'.$order['customer_firstname'].'" type="hidden"/>
<input id="last_name" name="last_name" value="'.$order['customer_lastname'].'" type="hidden"/>
<input id="zip" name="zip" value="'.$order['customer_address_zip'].'" type="hidden"/>
<input id="state" name="state" value="'.$state.'" type="hidden"/>
<input id="address1" name="address1" value="'.$order['customer_address_street1'].'" type="hidden"/>
<input id="address2" name="address2" value="'.$order['customer_address_street2'].'" type="hidden"/>
<input id="address_override" name="address_override" value="0" type="hidden"/>
';
return $str;
}
public function getProductItemsAndShipping($order){
$items = $order['items'];
$str = '';
$i = 1;
foreach($items as $item){
$sku = isset($item['sku']) ? $item['sku'] : '';
$name = isset($item['name']) ? $item['name'] : '';
$qty = isset($item['qty']) ? $item['qty'] : '';
$price = isset($item['price']) ? $item['price'] : '';
$custom_option_info = isset($item['custom_option_info']) ? $item['custom_option_info'] : '';
if($sku && $qty && $price){
$str .= '
<input id="item_number_'.$i.'" name="item_number_'.$i.'" value="'.$sku.'" type="hidden"/>
<input id="item_name_'.$i.'" name="item_name_'.$i.'" value="'.$name.'" type="hidden"/>
<input id="quantity_'.$i.'" name="quantity_'.$i.'" value="'.$qty.'" type="hidden"/>
<input id="amount_'.$i.'" name="amount_'.$i.'" value="'.$price.'" type="hidden"/>
';
if(is_array($custom_option_info) && !empty($custom_option_info)){
$j = 0;
foreach($custom_option_info as $co_label=>$co_value){
$str .= '
<input id="on'.$j.'_'.$i.'" name="on'.$j.'_'.$i.'" type="hidden" value="'.$co_label.'" />
<input id="os'.$j.'_'.$i.'" name="os'.$j.'_'.$i.'" type="hidden" value="'.$co_value.'" />
';
$j++;
}
}
}
$i++;
}
$shipping_total = $order['shipping_total'];
$shipping_method = $order['shipping_method'];
$shipping_label = Yii::$service->shipping->getShippingLabelByMethod($shipping_method);
$str .= '
<input id="item_number_'.$i.'" name="item_number_'.$i.'" value="'.$shipping_label.'" type="hidden"/>
<input id="item_name_'.$i.'" name="item_name_'.$i.'" value="'.$shipping_method.'" type="hidden"/>
<input id="quantity_'.$i.'" name="quantity_'.$i.'" value="1" type="hidden"/>
<input id="amount_'.$i.'" name="amount_'.$i.'" value="'.$shipping_total.'" type="hidden"/>
';
return $str;
}
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ class StandardController extends AppfrontController
public $enableCsrfValidation = true;
public function actionStart(){
Yii::$service->page->theme->layoutFile = 'blank.php';
$data = $this->getBlock()->getLastData();
return $this->render($this->action->id,$data);
}
......
<?php
/**
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
?><?= $content; ?>
\ No newline at end of file
<html>
<body>
You will be redirected to the PayPal website in a few seconds
<img src="<?= $loaderImg ?>" />
<img src="<?= $loader_img ?>" />
<?php // https://www.paypal.com/cgi-bin/webscr ?>
<form action="<?= $submitAction ?>" id="paypal_standard_checkout" name="paypal_standard_checkout" method="POST">
<input id="business" name="business" value="<?= $paypal_account ?>" type="hidden"/>
<form action="<?= $payment_url ?>" id="paypal_standard_checkout" name="paypal_standard_checkout" method="POST">
<input id="business" name="business" value="<?= $account ?>" type="hidden"/>
<input id="invoice" name="invoice" value="<?= $order_increment_id ?>" type="hidden"/>
<input id="currency_code" name="currency_code" value="<?= $order_currency ?>" type="hidden"/>
<input id="paymentaction" name="paymentaction" value="<?= $paymentaction ?>" type="hidden"/>
<input id="return" name="return" value="<?= $return_url ?>" type="hidden"/>
<input id="invoice" name="invoice" value="<?= $order['increment_id'] ?>" type="hidden"/>
<input id="currency_code" name="currency_code" value="<?= $order['order_currency_code'] ?>" type="hidden"/>
<input id="paymentaction" name="paymentaction" value="<?= $payment_action ?>" type="hidden"/>
<input id="return" name="return" value="<?= $success_redirect_url ?>" type="hidden"/>
<input id="cancel_return" name="cancel_return" value="<?= $cancel_url ?>" type="hidden"/>
<input id="notify_url" name="notify_url" value="<?= $notify_url ?>" type="hidden"/>
<input id="notify_url" name="notify_url" value="<?= $ipn_url ?>" type="hidden"/>
<input id="cpp_header_image" name="cpp_header_image" value="<?= $paypal_logo_img ?>" type="hidden"/>
<input id="item_name" name="item_name" value="<?= $store_name ?>" type="hidden"/>
<input id="charset" name="charset" value="utf-8" type="hidden"/>
<input id="amount" name="amount" value="<?= $amount ?>" type="hidden"/>
<input id="amount" name="amount" value="<?= $order['grand_total'] ?>" type="hidden"/>
<input id="tax" name="tax" value="<?= $tax ?>" type="hidden"/>
<input id="shipping" name="shipping" value="<?= $shipping ?>" type="hidden"/>
<input id="discount_amount" name="discount_amount" value="<?= $discount_amount ?>" type="hidden"/>
<?= $product_items ?>
<input id="shipping" name="shipping" value="<?= $order['shipping_total'] ? $order['shipping_total'] : 0 ?>" type="hidden"/>
<input id="discount_amount" name="discount_amount" value="<?= $order['subtotal_with_discount'] ? $order['subtotal_with_discount'] : 0 ?>" type="hidden"/>
<?= $product_items_and_shipping ?>
<input id="cmd" name="cmd" value="<?= $cmd ?>" type="hidden"/>
<input id="upload" name="upload" value="<?= $upload ?>" type="hidden"/>
<input id="tax_cart" name="tax_cart" value="<?= $tax_cart ?>" type="hidden"/>
<input id="discount_amount_cart" name="discount_amount_cart" value="<?= $discount_amount_cart ?>" type="hidden"/>
<?= $address_html ?>.'
<input id="discount_amount_cart" name="discount_amount_cart" value="<?= $order['subtotal_with_discount'] ? $order['subtotal_with_discount'] : 0 ?>" type="hidden"/>
<?= $address_html ?>
<span class="field-row">
<input id="submit_to_paypal_button_ffe6e6319afa1dc2e9e4d822e58ca9ca" name="" value="'.Translate::__("Click here if you are not redirected within 10 seconds").'..." type="submit" class=" submit"/>
<input id="submit_to_paypal_button" name="" value="Click here if you are not redirected within 10 seconds ..." type="submit" class=" submit"/>
</span>
</form>
<script type="text/javascript">
......
......@@ -22,16 +22,87 @@ return [
'label' => 'PayPal Website Payments Standard',
'image' => ['images/paypal_standard.png','common'], # 支付页面显示的图片。
'supplement' => 'You will be redirected to the PayPal website when you place an order. ', # 补充
# 选择支付后,进入到相应支付页面的start页面。
'start_url' => '@homeUrl/payment/paypal/standard/start',
# 接收IPN消息的页面。
'IPN_url' => '@homeUrl/payment/paypal/standard/ipn',
# 在第三方支付成功后,跳转到网站的页面
'success_redirect_url' => '@homeUrl/payment/paypal/standard/success',
# 进入paypal支付页面,点击取消进入网站的页面。
'cancel_url' => '@homeUrl/payment/paypal/standard/cancel',
# 第三方支付网站的url
'payment_url'=>'https://www.sandbox.paypal.com/cgi-bin/webscr',
# 用户名
'user' => 'zqy234api1-facilitator@126.com',
# 账号
'account'=> 'zqy234api1-facilitator@126.com',
# 密码
'password'=>'HF4TNTTXUD6YQREH',
# 签名
'signature'=>'An5ns1Kso7MWUdW4ErQKJJJ4qi4-ANB-xrkMmTHpTszFaUx2v4EHqknV',
//'info' => [
//'title'=>'PayPal Website Payments Standard',
//'enable'=> 1,
//'label'=>'PayPal Website Payments Standard',
//'description'=>'You will be redirected to the PayPal website when you place an order.',
//'image'=> 'images/hm.png',
//],
],
],
'express' => [
'paypal_express' =>[
'nvp_url' => 'https://api-3t.sandbox.paypal.com/nvp',
'api_url' => 'https://www.sandbox.paypal.com/cgi-bin/webscr',
'account'=> 'zqy234api1-facilitator_api1.126.com',
'password'=>'HF4TNTTXUD6YQREH',
'signature'=>'An5ns1Kso7MWUdW4ErQKJJJ4qi4-ANB-xrkMmTHpTszFaUx2v4EHqknV',
'enable'=> 1,
'label'=>'PayPal Express Payments',
],
],
]
]
];
\ No newline at end of file
];
/*
'payment_method'=>[
'merchant_country' => 'US',
'paypal'=>[
'payments_standard'=>[
'title'=>'PayPal Website Payments Standard',
'enable'=> 1,
'user' => 'zqy234api1-facilitator@126.com',
'redirect_url'=>'https://www.sandbox.paypal.com/cgi-bin/webscr',
'account'=> 'zqy234api1-facilitator@126.com',
'password'=>'HF4TNTTXUD6YQREH',
'signature'=>'An5ns1Kso7MWUdW4ErQKJJJ4qi4-ANB-xrkMmTHpTszFaUx2v4EHqknV',
'label'=>'PayPal Website Payments Standard',
'description'=>'You will be redirected to the PayPal website when you place an order.',
'image'=> 'images/hm.png',
],
'express_checkout' =>[
'nvp_url' => 'https://api-3t.sandbox.paypal.com/nvp',
'api_url' => 'https://www.sandbox.paypal.com/cgi-bin/webscr',
'account'=> 'zqy234api1-facilitator_api1.126.com',
'password'=>'HF4TNTTXUD6YQREH',
'signature'=>'An5ns1Kso7MWUdW4ErQKJJJ4qi4-ANB-xrkMmTHpTszFaUx2v4EHqknV',
'enable'=> 1,
'label'=>'PayPal Express Payments',
],
],
],
*/
\ No newline at end of file
......@@ -210,9 +210,37 @@ class Order extends Service
$primaryKey = $this->getPrimaryKey();
if($one[$primaryKey]){
return $one;
}else{
return false;
}
}
/**
* @property $increment_id | String , 订单号
* @return Object (MyOrder),返回 MyOrder model
* 通过订单号,得到订单以及订单产品信息。
*/
protected function actionGetInfoByIncrementId($increment_id){
//echo 1;exit;
$order = $this->getByIncrementId($increment_id);
$orderInfo = [];
if($order){
$primaryKey = $this->getPrimaryKey();
$order_id = $order[$primaryKey];
$items = Yii::$service->order->item->getByOrderId($order_id);
foreach($order as $k=>$v){
$orderInfo[$k] = $v;
}
$orderInfo['items'] = $items;
return $orderInfo;
}else{
return ;
}
}
/**
* @property $address | Array 货运地址
* @property $shipping_method | String 货运快递方式
......@@ -321,6 +349,8 @@ class Order extends Service
return $increment_id;
}
/**
* get order list by customer account id.
*/
......
......@@ -19,18 +19,26 @@ use fec\helpers\CUrl;
*/
class Payment extends Service
{
public $paymentConfig;
protected $_currentPaymentMethod;
/**
* @property $payment_method | string
* 设置当前的支付方式
*/
public function setPaymentMethod($payment_method){
$this->_currentPaymentMethod = $payment_method;
}
/**
* @return $payment_method | string
* 得到当前的支付方式
*/
public function getPaymentMethod(){
return $this->_currentPaymentMethod;
}
/**
* @property $payment_method | String 支付方式。
* @return 返回提交订单信息跳转到的第三方支付url,也就是第三方支付的url。
* #从配置信息中获取
*/
public function getStandardStartUrl($payment_method = ''){
if(!$payment_method){
......@@ -48,6 +56,7 @@ class Payment extends Service
/**
* @property $payment_method | String 支付方式。
* @return 第三方支付成功后,返回到网站的url
* #从配置信息中获取
*/
public function getStandardSuccessRedirectUrl($payment_method = ''){
if(!$payment_method){
......@@ -65,6 +74,7 @@ class Payment extends Service
/**
* @property $payment_method | String 支付方式。
* @return 第三方网站发送ipn消息,告诉网站支付成功的url。
* #从配置信息中获取
*/
public function getStandardIpnUrl($payment_method = ''){
if(!$payment_method){
......@@ -80,6 +90,106 @@ class Payment extends Service
}
}
/**
* @property $payment_method | String 支付方式。
* @return String 支付取消的url。
* #从配置信息中获取
*/
public function getStandardCancelUrl($payment_method = ''){
if(!$payment_method){
$payment_method = $this->getPaymentMethod();
}
if($payment_method){
$paymentConfig = $this->paymentConfig;
if(isset($paymentConfig['standard'][$payment_method]['cancel_url'])){
if(!empty($paymentConfig['standard'][$payment_method]['cancel_url'])){
return $this->getUrl($paymentConfig['standard'][$payment_method]['cancel_url']);
}
}
}
}
/**
* @property $payment_method | String 支付方式。
* @return String 得到跳转到第三方支付的url。
* #从配置信息中获取
*/
public function getStandardPaymentUrl($payment_method = ''){
if(!$payment_method){
$payment_method = $this->getPaymentMethod();
}
if($payment_method){
$paymentConfig = $this->paymentConfig;
if(isset($paymentConfig['standard'][$payment_method]['payment_url'])){
if(!empty($paymentConfig['standard'][$payment_method]['payment_url'])){
return $paymentConfig['standard'][$payment_method]['payment_url'];
}
}
}
}
/**
* @property $payment_method | String 支付方式。
* @return String 用户名
* #从配置信息中获取
*/
public function getStandardAccount($payment_method = ''){
if(!$payment_method){
$payment_method = $this->getPaymentMethod();
}
if($payment_method){
$paymentConfig = $this->paymentConfig;
if(isset($paymentConfig['standard'][$payment_method]['account'])){
if(!empty($paymentConfig['standard'][$payment_method]['account'])){
return $paymentConfig['standard'][$payment_method]['account'];
}
}
}
}
/**
* @property $payment_method | String 支付方式。
* @return String Password
* #从配置信息中获取
*/
public function getStandardPassword($payment_method = ''){
if(!$payment_method){
$payment_method = $this->getPaymentMethod();
}
if($payment_method){
$paymentConfig = $this->paymentConfig;
if(isset($paymentConfig['standard'][$payment_method]['password'])){
if(!empty($paymentConfig['standard'][$payment_method]['password'])){
return $paymentConfig['standard'][$payment_method]['password'];
}
}
}
}
/**
* @property $payment_method | String 支付方式。
* @return String Signature
* #从配置信息中获取
*/
public function getStandardSignature($payment_method = ''){
if(!$payment_method){
$payment_method = $this->getPaymentMethod();
}
if($payment_method){
$paymentConfig = $this->paymentConfig;
if(isset($paymentConfig['standard'][$payment_method]['signature'])){
if(!empty($paymentConfig['standard'][$payment_method]['signature'])){
return $paymentConfig['standard'][$payment_method]['signature'];
}
}
}
}
/**
* @property $url | String url的字符串
* @return String 根据传递的字符串格式,得到相应的url
*/
protected function getUrl($url){
$homeUrl = Yii::$service->url->homeUrl();
$url = str_replace('@homeUrl',$homeUrl,$url);
......@@ -87,7 +197,7 @@ class Payment extends Service
}
/**
* @return Array 得到所有支付的数组。
* @return Array 得到所有支付的数组,数组含有三个字段
*/
public function getStandardPaymentArr(){
$arr = [];
......@@ -116,8 +226,8 @@ class Payment extends Service
}
/**
* @property $shipping_method | String
* @return boolean 发货方式
* @property $payment_method | String , 支付方式
* @return boolean 判断传递的支付方式,是否在配置中存在,如果存在返回true。
*/
protected function actionIfIsCorrectStandard($payment_method){
$paymentConfig = $this->paymentConfig;
......@@ -129,4 +239,6 @@ class Payment extends Service
}
}
}
\ No newline at end of file
......@@ -145,7 +145,7 @@ class Shipping extends Service
* @property $shipping_method | String
* @return 得到货运方式的名字
*/
protected static function actionGetShippingLabelByMethod($shipping_method){
protected function actionGetShippingLabelByMethod($shipping_method){
$s = $this->getShippingMethod($shipping_method);
return $s['label'];
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册