Example #1
0
 /// <remarks/>
 public System.IAsyncResult BeginDoDirectPayment(DoDirectPaymentReq DoDirectPaymentReq, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("DoDirectPayment", new object[] {
                 DoDirectPaymentReq}, callback, asyncState);
 }
Example #2
0
    /// <summary>
    /// Bills the user for something
    /// </summary>
    /// <param name="b"></param>
    /// <param name="ErrorMessages">If there were any error messages, they'll be in this varable.</param>
    /// <returns>Determines if this was a success.</returns>
    public static bool BillUser(BillUserParams b, PayPalServices.PaymentActionCodeType PaymentActionType, out string ErrorMessages, out string TransactionId)
    {
        PayPalServices.UserIdPasswordType user = new PayPalServices.UserIdPasswordType();
        user.Username = APIUsername;
        user.Password = APIPassword;
        user.Signature = APISignature;

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

        PayPalServices.DoDirectPaymentReq paymentReq = new PayPalServices.DoDirectPaymentReq();

        PayPalServices.PersonNameType personNameType = new PayPalServices.PersonNameType();
        personNameType.FirstName = b.PayerFirstName;
        personNameType.LastName = b.PayerLastName;

        PayPalServices.AddressType payerBillingAddress = new PayPalServices.AddressType();
        payerBillingAddress.CityName = b.ShippingCity;
        payerBillingAddress.CountryName = b.ShippingCountry;
        payerBillingAddress.Country = b.ShippingCountryType;
        payerBillingAddress.CountrySpecified = true;
        payerBillingAddress.StateOrProvince = b.ShippingState;
        payerBillingAddress.Street1 = b.ShippingAddress;
        payerBillingAddress.PostalCode = b.ShippingZipCode;
        payerBillingAddress.Phone = b.PhoneNumber;
        payerBillingAddress.Name = b.PayerFirstName + " " + b.PayerLastName;

        PayPalServices.PayerInfoType payerInfo = new PayPalServices.PayerInfoType();
        payerInfo.Address = payerBillingAddress;
        payerInfo.ContactPhone = b.PhoneNumber;
        payerInfo.Payer = b.EmailAddress;  // Max length 127 characters
        payerInfo.PayerBusiness = b.BusinessName; // Max length 127 characters
        payerInfo.PayerCountry = b.PayerCountry;
        payerInfo.PayerCountrySpecified = true;
        payerInfo.PayerName = personNameType;

        PayPalServices.CreditCardDetailsType cc = new PayPalServices.CreditCardDetailsType();
        cc.CardOwner = payerInfo;
        cc.CreditCardNumber = b.CreditCardNumber;
        cc.CreditCardType = b.CreditCardType;
        cc.CreditCardTypeSpecified = true;
        cc.CVV2 = b.CVV2;
        cc.ExpMonth = b.CreditCardExpirMonth;
        cc.ExpMonthSpecified = true;
        cc.ExpYear = b.creditCardExpirYear;
        cc.ExpYearSpecified = true;
        cc.IssueNumber = string.Empty;

        paymentReq.DoDirectPaymentRequest = new PayPalServices.DoDirectPaymentRequestType();
        paymentReq.DoDirectPaymentRequest.Version = APIVersion;
        paymentReq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = new PayPalServices.DoDirectPaymentRequestDetailsType();
        paymentReq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.CreditCard = cc;
        paymentReq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.IPAddress = b.IPAddress;
        paymentReq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentAction = PaymentActionType;

        PayPalServices.BasicAmountType subAmount = new PayPalServices.BasicAmountType();
        subAmount.currencyID = b.CurrencyType;
        subAmount.Value = b.RecurringBillingAmount.ToString("0.00");

        PayPalServices.PaymentDetailsType paymentDetails = new PayPalServices.PaymentDetailsType();
        paymentDetails.InvoiceID = b.InvoiceId;
        paymentDetails.ItemTotal = subAmount;
        paymentDetails.OrderDescription = b.SubscriptionDescription;
        paymentDetails.OrderTotal = subAmount;

        paymentReq.DoDirectPaymentRequest.DoDirectPaymentRequestDetails.PaymentDetails = paymentDetails;
        PayPalServices.DoDirectPaymentResponseType response = PPInterface.DoDirectPayment(paymentReq);

        if (response.Ack == PayPalServices.AckCodeType.Success)
        {
            TransactionId = response.TransactionID;
            ErrorMessages = string.Empty;
            return true;
        }

        // Build the error message to display to the user.
        string errorsMessages;

        if (response.Ack == PayPalServices.AckCodeType.SuccessWithWarning)
        {
            errorsMessages = "Status: " + "Error" + " <br/>";
        }
        else
        {
            errorsMessages = "Status: " + response.Ack.ToString() + " <br/>";
        }

        foreach (PayPalServices.ErrorType error in response.Errors)
        {
            errorsMessages += error.ErrorCode + " - " + error.LongMessage + " " + error.ShortMessage + "<br/>";
        }
        ErrorMessages = errorsMessages;
        TransactionId = string.Empty;
        return false;
    }