Пример #1
0
 /// <remarks/>
 public System.IAsyncResult BeginRefundTransaction(RefundTransactionReq RefundTransactionReq, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("RefundTransaction", new object[] {
                 RefundTransactionReq}, callback, asyncState);
 }
Пример #2
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="transactionIdToRefund"></param>
    /// <param name="refundType">If the type of partial, then you need to give an amount for the amount to refund. If it's full, the full amount will be refunded</param>
    /// <param name="amountToRefund">Only used for partial refunds.</param>
    /// <param name="refundMemo">The memo to include with the refunded amount.</param>
    /// <param name="transactionIdOfRefund">The transaction ID of the refund that was just processed. This is returned to us from PayPal.</param>
    /// <returns></returns>
    public static bool DoRefund(string transactionIdToRefund, PayPalServices.RefundType refundType, decimal amountToRefund, string refundMemo, out string transactionIdOfRefund, ref string errorMessages)
    {
        PayPalServices.UserIdPasswordType user = new PayPalServices.UserIdPasswordType();
        user.Username = APIUsername;
        user.Password = APIPassword;
        user.Signature = APISignature;

        PayPalServices.PayPalAPISoapBinding PPInterface = new PayPalServices.PayPalAPISoapBinding();
        PPInterface.RequesterCredentials = new PayPalServices.CustomSecurityHeaderType();
        PPInterface.RequesterCredentials.Credentials = user;
        PPInterface.RequestEncoding = System.Text.Encoding.UTF8;
        PPInterface.Url = APIUrl;

        PayPalServices.RefundTransactionReq refund = new PayPalServices.RefundTransactionReq();
        refund.RefundTransactionRequest = new PayPalServices.RefundTransactionRequestType();
        if (refundType == PayPalServices.RefundType.Partial)
        {
            PayPalServices.BasicAmountType refundBasicAmount = new PayPalServices.BasicAmountType();
            refundBasicAmount.currencyID = PayPalServices.CurrencyCodeType.USD;
            refundBasicAmount.Value = amountToRefund.ToString("0.00");

            refund.RefundTransactionRequest.Amount = refundBasicAmount;
        }
        refund.RefundTransactionRequest.Memo = refundMemo;
        refund.RefundTransactionRequest.RefundType = refundType;
        refund.RefundTransactionRequest.TransactionID = transactionIdToRefund;
        refund.RefundTransactionRequest.Version = APIVersion;

        PayPalServices.RefundTransactionResponseType response = PPInterface.RefundTransaction(refund);

        if (response.Ack == PayPalServices.AckCodeType.Success)
        {
            transactionIdOfRefund = response.RefundTransactionID;
            errorMessages = string.Empty;
            return true;
        }

        string errorsMessages = "Status: " + response.Ack.ToString() + " <br/>";
        foreach (PayPalServices.ErrorType error in response.Errors)
        {
            errorsMessages += error.ErrorCode + " - " + error.LongMessage + " " + error.ShortMessage + "<br/>";
        }
        errorMessages = errorsMessages;
        transactionIdOfRefund = string.Empty;
        return false;
    }