예제 #1
0
 public function handle($data)
 {
     parent::handle($data);
     # handle the wechat message
     LogUtil::info(['channel weconnect event' => $data], 'channel-webhook');
     if (empty($data)) {
         throw new BadRequestHttpException(Yii::t('channel', 'parameter_format_error'));
     }
     $data = $data['data'];
     $requiredParameters = ['outTradeNo', 'tradeNo', 'tradeStatus'];
     ValidatorUtil::fieldsRequired($data, $requiredParameters);
     $tradePayment = TradePayment::findOne(['orderNumber' => $data['outTradeNo']]);
     LogUtil::info(['tradePayment' => $tradePayment->toArray()], 'channel-webhook');
     if (empty($tradePayment)) {
         throw new InvalidParameterException(Yii::t('common', 'data_error'));
     }
     $memberId = $tradePayment['user']['memberId'];
     $couponId = $tradePayment['couponId'];
     LogUtil::info(['memberId' => $memberId, 'couponId' => $couponId], 'channel-webhook');
     if ($data['tradeStatus'] == 'PAY_SUCCESS') {
         $tradePayment->status = TradePayment::STATUS_PAID;
         $tradePayment->realAmount = intval($data['totalFee']) / 100;
         // Make coupon used
         if (!empty($couponId)) {
             Yii::$app->service->coupon->makeUsed($memberId, $couponId);
         }
     } else {
         if ($data['tradeStatus'] == 'PAY_ERROR') {
             $tradePayment->status = TradePayment::STATUS_FAILED;
         }
     }
     $tradePayment->paymentTime = MongodbUtil::msTimetamp2MongoDate($data['paymentTime']);
     $tradePayment->transactionId = $data['tradeNo'];
     return $tradePayment->save(true, ['paymentTime', 'status', 'transactionId', 'realAmount']);
 }
예제 #2
0
 public function refund($refundInfo)
 {
     $requiredFields = ['subject', 'orderNumber', 'expectedAmount', 'realAmount', 'admin', 'user', 'refundMode'];
     ValidatorUtil::fieldsRequired($refundInfo, $requiredFields);
     // TODO  1. Call weconnect to refund
     // Save refund message to tradeRefund.
     return ModelRefund::refund($this->accountId, $refundInfo);
 }
예제 #3
0
 public function offlinePayment($paymentInfo)
 {
     $requiredFields = ['user' => ['name', 'telephone'], 'orderNumber', 'payMode', 'expectedAmount', 'realAmount', 'payAccount', 'paymentTime', 'subject'];
     if (ValidatorUtil::fieldsRequired($paymentInfo, $requiredFields, false)) {
         return ModelPayment::offlinePayment($paymentInfo, $this->accountId);
     }
     return false;
 }