public static GetPaypalCurrency ( string currencyIsoCode ) : CurrencyCodeType | ||
currencyIsoCode | string | |
return | CurrencyCodeType |
public ITransactionRefundResult Refund(ITransactionRefundRequest request) { //to refund a transaction, we'll need capture id previously obtained from paypal var captureId = request.GetParameterAs <string>(PaymentParameterNames.CaptureId); var paypalCurrency = PayPalHelper.GetPaypalCurrency(request.CurrencyIsoCode); //create a capture request for paypal var doRefundRequest = new RefundTransactionReq() { RefundTransactionRequest = new RefundTransactionRequestType() { Version = ApiVersion, TransactionID = captureId, Amount = new BasicAmountType() { value = Math.Round(request.Amount, 2).ToString("N", new CultureInfo("en-us")), currencyID = paypalCurrency }, RefundType = request.IsPartialRefund ? RefundType.PARTIAL : RefundType.FULL } }; //get the service for paypal api var service = GetPayPalApiInterfaceServiceService(); var paypalResponse = service.RefundTransaction(doRefundRequest); var result = new TransactionResult(); string error; var success = PayPalHelper.ParseResponseSuccess(paypalResponse, out error); if (success) { result.Success = true; result.SetParameter(PaymentParameterNames.RefundId, paypalResponse.RefundTransactionID); result.SetParameter(PaymentParameterNames.RefundResult, paypalResponse.Ack); } else { result.SetParameter(PaymentParameterNames.ErrorMessage, error); } return(result); }
public ITransactionCaptureResult Capture(ITransactionCaptureRequest request) { //to capture a transaction, we'll need authorization id previously obtained from paypal var authorizationId = request.GetParameterAs <string>(PaymentParameterNames.AuthorizationId); var paypalCurrency = PayPalHelper.GetPaypalCurrency(request.CurrencyIsoCode); //create a capture request for paypal var doCaptureRequest = new DoCaptureReq() { DoCaptureRequest = new DoCaptureRequestType() { Version = ApiVersion, AuthorizationID = authorizationId, Amount = new BasicAmountType() { value = Math.Round(request.Amount, 2).ToString("N", new CultureInfo("en-us")), currencyID = paypalCurrency }, CompleteType = CompleteCodeType.COMPLETE } }; //get the service for paypal api var service = GetPayPalApiInterfaceServiceService(); var paypalResponse = service.DoCapture(doCaptureRequest); var result = new TransactionResult(); string error; var success = PayPalHelper.ParseResponseSuccess(paypalResponse, out error); if (success) { result.Success = true; result.SetParameter(PaymentParameterNames.CaptureId, paypalResponse.DoCaptureResponseDetails.PaymentInfo.TransactionID); result.SetParameter(PaymentParameterNames.CaptureResult, paypalResponse.Ack); } else { result.SetParameter(PaymentParameterNames.ErrorMessage, error); } return(result); }
public ITransactionProcessResult Process(ITransactionProcessRequest request, bool authorizeOnly = false) { var user = _userService.Get(request.UserId); if (user == null) { throw new mobSocialException($"Can't find the user with Id {request.UserId}"); } var creditCard = new CreditCardDetailsType() { CreditCardNumber = request.GetParameterAs <string>(PaymentParameterNames.CardNumber), CVV2 = request.GetParameterAs <string>(PaymentParameterNames.SecurityCode), ExpMonth = request.GetParameterAs <int>(PaymentParameterNames.ExpireMonth), ExpYear = request.GetParameterAs <int>(PaymentParameterNames.ExpireYear), CreditCardType = PayPalHelper.GeCreditCardTypeType(request.GetParameterAs <string>(PaymentParameterNames.CardIssuerType)), CardOwner = new PayerInfoType() }; var paypalCurrency = PayPalHelper.GetPaypalCurrency(request.CurrencyIsoCode); var doDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType() { IPAddress = WebHelper.GetClientIpAddress(), PaymentAction = authorizeOnly ? PaymentActionCodeType.AUTHORIZATION : PaymentActionCodeType.SALE, CreditCard = creditCard, PaymentDetails = new PaymentDetailsType() { OrderTotal = new BasicAmountType() { value = Math.Round(request.Amount, 2).ToString("N", new CultureInfo("en-US")), currencyID = paypalCurrency }, Custom = request.TransactionUniqueId, ButtonSource = "mobSocial" } }; var doDirectPaymentRequest = new DoDirectPaymentRequestType { Version = ApiVersion, DoDirectPaymentRequestDetails = doDirectPaymentRequestDetails }; var paymentRequest = new DoDirectPaymentReq { DoDirectPaymentRequest = doDirectPaymentRequest }; var service = GetPayPalApiInterfaceServiceService(); var paypalResponse = service.DoDirectPayment(paymentRequest); var result = new TransactionResult(); string error; var success = PayPalHelper.ParseResponseSuccess(paypalResponse, out error); if (success) { result.Success = true; result.SetParameter(PaymentParameterNames.AvsCode, paypalResponse.AVSCode); result.SetParameter(PaymentParameterNames.Cvv2Code, paypalResponse.CVV2Code); if (authorizeOnly) { result.SetParameter(PaymentParameterNames.AuthorizationId, paypalResponse.TransactionID); result.SetParameter(PaymentParameterNames.AuthorizationResult, paypalResponse.Ack); } else { result.SetParameter(PaymentParameterNames.CaptureId, paypalResponse.TransactionID); result.SetParameter(PaymentParameterNames.CaptureResult, paypalResponse.Ack); } } else { result.SetParameter(PaymentParameterNames.ErrorMessage, error); } return(result); }