private void EmailPersonRefundError(string personEmail, RefundStatusSEnum refundStatus) { // TODO: Email person about the happened refund error }
/// <summary> /// Refunds the payment. /// </summary> /// <param name="p">The parameters.</param> /// <exception cref="UserException">If refund was not suceessful, it throws an exception for the user</exception> public void RefundPayment(RefundParameters p) { // error language : (Required) RFC 3066 language in which error messages are returned; by default it is en_US, which is the only language currently supported. RefundRequest request = new RefundRequest(new RequestEnvelope("en_US")); request.payKey = p.payKey; request.currencyCode = p.currencyCode; List <Receiver> receivers = new List <Receiver>(); request.receiverList = new ReceiverList(receivers); if (p.receiver1amount != 0) { AddReceiver(p.receiver1amount, p.receiver1email, request.receiverList); } if (p.receiver2amount != 0) { AddReceiver(p.receiver2amount, p.receiver2email, request.receiverList); } AdaptivePaymentsService service = null; RefundResponse response = null; // Configuration map containing signature credentials and other required configuration. // For a full list of configuration parameters refer in wiki page // (https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters) Dictionary <string, string> configurationMap = FWUtils.ConfigUtils.GetAppSettings().Paypal.GetAcctAndConfig(); // Creating service wrapper object to make an API call and loading // configuration map for your credentials and endpoint service = new AdaptivePaymentsService(configurationMap); response = service.Refund(request); string ack = response.responseEnvelope.ack.ToString().Trim().ToUpper(); // if no error happened if (!ack.Equals(AckCode.FAILURE.ToString()) && !ack.Equals(AckCode.FAILUREWITHWARNING.ToString())) { StringBuilder sbErrors = new StringBuilder(); bool hasError = false; foreach (RefundInfo refund in response.refundInfoList.refundInfo) { RefundStatusSEnum refundStatus = new RefundStatusSEnum(refund.refundStatus); if (refundStatus != RefundStatusSEnum.REFUNDED && refundStatus != RefundStatusSEnum.REFUNDED_PENDING) { sbErrors.Append(refundStatus.GetUserFriendlyMessage()); hasError = true; if (refundStatus == RefundStatusSEnum.NO_API_ACCESS_TO_RECEIVER) { EmailPersonRefundError(refund.receiver.email, refundStatus); } } } if (hasError) { throw new UserException(sbErrors.ToString()); } } else { throw new UserException(GetPayPalErrorString(response.error)); } }