Authored by yyq

pay

... ... @@ -199,8 +199,8 @@ App({
getMiniappType:function(){
return config.constants.MINI_APP_TYPE
},
getAppId() {
return config.appid;
},
getUnionType() {
return config.unionType;
}
WeToast
});
... ...
... ... @@ -137,6 +137,7 @@ const api = {
},
addParams(params) {
return Object.assign({
business_line: config.apiParams.business_line,
client_type: config.apiParams.client_type,
app_version: config.apiParams.app_version,
union_type: config.unionType, // 渠道号
... ...
... ... @@ -5,6 +5,7 @@ const config = {
},
apiParams: {
client_type: 'miniapp',
business_line: 'miniappReds',
private_key: 'b43890b0a296ff3c7b8c260ca763980b',
app_version: '6.4.0'
},
... ...
... ... @@ -30,7 +30,9 @@ function redirectOrdersPage(confirm) {
}
}
function wechatPay(orderCode, orderAmount, callback) {
function wechatPay(order, callback) {
let orderCode = order.order_code,
orderAmount = order.order_amount;
if (!orderCode || !orderAmount) {
// TODO logger
... ... @@ -38,7 +40,9 @@ function wechatPay(orderCode, orderAmount, callback) {
return showErrorTip('支付失败,请求参数不完整.');
}
if (!app.globalData.WXThird_session) {
let wechatSession = app.getWechatThirdSession();
if (!wechatSession) {
// TODO logger
//
return showErrorTip('支付失败,用户session未获取到.');
... ... @@ -52,7 +56,8 @@ function wechatPay(orderCode, orderAmount, callback) {
payModel.wechatPay({
order_code: orderCode,
payment_code: PAYMENT_CODE
payment_code: PAYMENT_CODE,
'3rd_session': wechatSession
}).then(res => {
wx.hideToast();
... ... @@ -108,3 +113,7 @@ function wechatPay(orderCode, orderAmount, callback) {
return redirectOrdersPage('获取订单信息失败');
});
}
module.exports = {
wechatPay: wechatPay
};
... ...
... ... @@ -37,7 +37,7 @@ export default {
* @returns {*}
*/
buynowSubmit(params) {
return api.post({
return api.get({
url: '',
data: {
...params,
... ...
import ensureModel from '../../../models/cart/ensure';
import addressModel from '../../../models/home/address';
import wechatAddressUtil from '../../../utils/wechatAddress';
import { wechatPay } from '../../../common/pay/wechat';
const SKU_TYPE = 'O';
... ... @@ -35,24 +38,43 @@ function formatPaymentData(data) {
return value;
});
info.deliveryWayList.map(value => {
let selectWay,
selectTime;
if (info.deliveryWayList.length) {
info.deliveryWayList.map((value, index) => {
if (value.default === 'Y') {
value.checked = true;
info.deliveryWayText = `${value.delivery_way_name}:运费¥${value.delivery_way_cost}`;
selectWay = value;
}
return value;
});
info.deliveryTimeList.map(value => {
if (!selectWay) {
selectWay = info.deliveryWayList[0];
info.deliveryWayList[0].checked = true;
}
info.deliveryWayId = selectWay.delivery_way_id;
info.deliveryWayText = `${selectWay.delivery_way_name}:运费¥${selectWay.delivery_way_cost}`;
}
if (info.deliveryTimeList.length) {
info.deliveryTimeList.map((value, index) => {
if (value.default === 'Y') {
value.checked = true;
info.deliveryTimeText = value.delivery_time_string || '';
selectTime = value;
}
return value;
});
if (!selectTime) {
selectTime = info.deliveryTimeList[0];
info.deliveryTimeList[0].checked = true;
}
info.deliveryTimeId = selectTime.delivery_time_id;
info.deliveryTimeText = selectTime.delivery_time_string || '';
}
return info;
}
... ... @@ -77,28 +99,36 @@ Page({
this.orderData = {};
this.loadEnsurePayment({productSku: 2030762});
},
loadEnsurePayment(options) {
loadEnsurePayment(options, reload) {
if (options.productSku) {
this.orderType = ORDER_TYPE.BUYNOW;
Object.assign(this.orderData, {
productSku: options.productSku,
buyNumber: options.buyNumber || 1
});
ensureModel.buynowPayment({
sku_type: SKU_TYPE,
product_sku: this.orderData.productSku,
buy_number: this.orderData.buyNumber,
product_sku: options.productSku,
buy_number: options.buyNumber || 1,
yoho_coin_mode: 0,
is_support_apple_pay: 'N',
}).then(res => {
console.log(res)
if (res.code !== 200) {
wx.showModal({
content: res.message,
showCancel: false,
confirmText: '好的',
});
return;
}
this.setData(formatPaymentData(res.data));
let data = formatPaymentData(res.data);
Object.assign(this.orderData, {
productSku: options.productSku,
buyNumber: options.buyNumber || 1,
deliveryWayId: data.deliveryWayId,
deliveryTimeId: data.deliveryTimeId
});
this.setData(data);
});
}
},
... ... @@ -124,9 +154,7 @@ Page({
});
}
console.log(res);
});
},
navigateTo(url) {
wx.navigateTo({url: url});
... ... @@ -148,19 +176,19 @@ Page({
this.navigateTo(`/pages/home/address/list?type=add`);
},
chooseWechatAddress() {
wx.chooseAddress({
success(res) {
console.log(res);
// TODO
},
fail() {
wx.showModal({
content: '获取微信地址失败或未授权',
showCancel: false,
confirmText: '好的'
wechatAddressUtil.choose(res => {
addressModel.saveWechatAddressData(res).then(result => {
if (result.code === 200) {
this.chooseAddressCallback(result.data);
} else {
wx.showToast({
title: result.message,
icon: 'none',
duration: 1500
});
}
});
});
},
toggleDeliveryWayList() {
this.setData({deliveryWayEditStatus: !this.data.deliveryWayEditStatus});
... ... @@ -177,7 +205,6 @@ Page({
}
this.buynowCompute({deliveryWayId: id});
this.setData({
deliveryWayText: name,
deliveryWayEditStatus: false,
... ... @@ -250,23 +277,26 @@ Page({
} else {
// 普通购物车下单
}
console.log('submitOrder');
},
buynowOrderSubmit() {
if (this.orderSubmiting) {
return;
}
return wechatPay({
order_amount: 399,
order_code: 21551043925
});
let param = {
sku_type: SKU_TYPE,
product_sku: this.orderData.productSku,
buy_number: this.orderData.buyNumber,
payment_id: PAYMENT.ID,
payment_type: PAYMENT.TYPE,
// qhy_union: {client_id: app.getAppId()}
qhy_union: JSON.stringify({client_id: app.getUnionType()})
}
console.log({client_id: app.getAppId()});
if (this.orderData.deliveryWayId) {
param.delivery_way = this.orderData.deliveryWayId;
}
... ... @@ -278,7 +308,7 @@ console.log({client_id: app.getAppId()});
if (this.data.choosedAddress && this.data.choosedAddress.address_id) {
param.address_id = this.data.choosedAddress.address_id;
} else {
this.showToast('请选择收件地址');
return this.showToast('请选择收件地址');
}
if (this.data.invoiceNeedStatus) {
... ... @@ -295,7 +325,7 @@ console.log({client_id: app.getAppId()});
}
if (+param.invoices_type === 2 && !param.receiverMobile) {
this.showToast('请填写电子发票接收手机号');
return this.showToast('请填写电子发票接收手机号');
}
this.orderSubmiting = true;
... ... @@ -304,7 +334,7 @@ console.log({client_id: app.getAppId()});
this.orderSubmiting = false;
if (res.code === 200) {
wechatPay(res.data);
} else {
wx.showModal({
content: res.message,
... ...
import addressModel from '../../../models/home/address';
import wechatAddressUtil from '../../../utils/wechatAddress';
const PAGE_TYPE_ADD = 'add';
const PAGE_TYPE_SELECT = 'select';
... ... @@ -180,12 +181,16 @@ Page({
return;
}
let currentPages = getCurrentPages();
if (currentPages.length > 1 && currentPages[currentPages.length - 2].chooseAddressCallback) {
let selectIndex = e.currentTarget.dataset.key;
let address = this.data.addressList[selectIndex];
this.backToPrePage(this.data.addressList[selectIndex]);
},
backToPrePage(address) {
let currentPages = getCurrentPages();
if (address && currentPages.length > 1 &&
currentPages[currentPages.length - 2].chooseAddressCallback) {
currentPages[currentPages.length - 2].chooseAddressCallback(address);
}
... ... @@ -263,6 +268,8 @@ Page({
Object.assign(item, result.data || address);
}
});
} else if (this.loadOptions.type === PAGE_TYPE_ADD) {
this.backToPrePage(result.data);
} else {
addressList.unshift(result.data);
}
... ... @@ -275,48 +282,13 @@ Page({
}
},
addWechatAddr() {
const that = this;
if (wx.getSetting) {
wx.getSetting({
success(res) {
if (!res.authSetting['scope.address']) {
wx.authorize({
scope: 'scope.address',
success() {
that.chooseAddress();
},
fail() {
wx.showModal({
content: '获取微信地址授权失败,请重新授权',
showCancel: false,
confirmText: '好的'
});
}
})
} else {
that.chooseAddress();
}
}
});
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
});
}
},
chooseAddress() {
const that = this;
wx.chooseAddress({
success(res) {
wechatAddressUtil.choose(res => {
addressModel.saveWechatAddressData(res).then(result => {
if (result.code === 200) {
let addressList = that.data.addressList;
let addressList = this.data.addressList;
addressList.unshift(result.data);
that.setData({addressList});
this.setData({addressList});
} else {
wx.showToast({
title: result.message,
... ... @@ -325,14 +297,6 @@ Page({
});
}
});
},
fail() {
wx.showModal({
content: '获取微信地址失败或未授权',
showCancel: false,
confirmText: '好的'
});
}
});
},
hideAreaPicker() {
... ...
function choose(callback) {
wx.chooseAddress({
success(res) {
if (callback && typeof callback === 'function') {
callback(res);
}
}
});
}
function beforeChoose(callback) {
if (wx.getSetting) {
wx.getSetting({
success(res) {
if (!res.authSetting['scope.address']) {
wx.authorize({
scope: 'scope.address',
success() {
choose(callback);
},
fail() {
wx.showModal({
content: '获取微信地址授权失败,请重新授权',
showCancel: false,
confirmText: '好的'
});
}
})
} else {
choose(callback);
}
}
});
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
});
}
}
export default {
choose: beforeChoose
};
... ...