Пример #1
0
 private void GetCaptureResult(PaypalCapturePaymentResponse paypalCapturePaymentResponse)
 {
     dto.paypalRecordPayload.paypalCaptureId = paypalCapturePaymentResponse.paypalPurchaseUnitList.First()
                                               .payments.paypalCaptureList.First().captureId;
     dto.paypalRecordPayload.amount = paypalCapturePaymentResponse.paypalPurchaseUnitList.First()
                                      .payments.paypalCaptureList.First().amount.value;
     dto.paypalRecordPayload.currencyCode = paypalCapturePaymentResponse.paypalPurchaseUnitList.First()
                                            .payments.paypalCaptureList.First().amount.currencyCode.ToLower();
 }
Пример #2
0
        public async Task <ActionResult <object> > paypal(PaypalOrderParamterModel par)
        {
            _myDbContext.Add(par);
            _myDbContext.SaveChanges();

            //取TOKEN
            var token = await GetPaypalAccessToken();

            PaypalRecordPayload paypalTransaction = new PaypalRecordPayload {
                paypalOrderId = par.orderID
            };

            dto = new PaypalRecordDto {
                paypalRecordPayload = paypalTransaction
            };
            PaypalAccessTokenResponse paypalAccessTokenResponse = new PaypalAccessTokenResponse();

            paypalAccessTokenResponse     = token;
            dto.paypalAccessTokenResponse = paypalAccessTokenResponse;
            //取ORDER資訊
            PaypalCapturePaymentResponse paypalCapturePaymentResponse = new PaypalCapturePaymentResponse();

            paypalCapturePaymentResponse = await CapturePaymentForOrder(par.orderID, token.accessToken);

            dto.paypalCapturePaymentResponse = paypalCapturePaymentResponse;
            if (paypalCapturePaymentResponse.name.IsNullOrEmpty())
            {
                GetCaptureResult(paypalCapturePaymentResponse);
            }

            ApiResponse response = new ApiResponse()
            {
                meta = new ApiResponseMeta()
            };

            if (CapturePaypalPaymentSuccess(response, dto))
            {
                //給公司代號
                dto.paypalRecordPayload.companyId = 1;
                //把資料存入PaypalRecord
                if (AddPaypalRecordSuccess(response, dto))
                {
                    try
                    {
                        var             apikey = _myDbContext.Apis.FirstOrDefault();
                        PaypalRecordDto dto2   = await TopUpApiBalance(apikey.apiKey.ToString(), dto);

                        if (AddApiTransactionSuccess(response, dto2))
                        {
                            if (await UpdatePaypalRecordSuccess(response, dto2))
                            {
                                return(dto);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var aa = ex.ToString();
                    }
                }
            }

            return(dto);
        }