/// <remarks/> public void DoDirectPaymentAsync(DoDirectPaymentReq DoDirectPaymentReq) { this.DoDirectPaymentAsync(DoDirectPaymentReq, null); }
/// <remarks/> public void DoDirectPaymentAsync(DoDirectPaymentReq DoDirectPaymentReq, object userState) { if ((this.DoDirectPaymentOperationCompleted == null)) { this.DoDirectPaymentOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDoDirectPaymentOperationCompleted); } this.InvokeAsync("DoDirectPayment", new object[] { DoDirectPaymentReq}, this.DoDirectPaymentOperationCompleted, userState); }
public TransactionResult SubmitPaymentTransaction(CheckoutDetails details) { //init result structure TransactionResult ret = new TransactionResult(); //set up Request //instantiate DoDirectPaymentRequestType and RequestDetails objects DoDirectPaymentRequestType request = new DoDirectPaymentRequestType(); request.Version = PROCESSOR_VERSION; DoDirectPaymentRequestDetailsType requestDetails = new DoDirectPaymentRequestDetailsType(); request.DoDirectPaymentRequestDetails = requestDetails; //set payment action requestDetails.PaymentAction = PaymentActionCodeType.Sale; //set IP //requestDetails.IPAddress = Request.UserHostAddress; requestDetails.IPAddress = details[CheckoutKeys.IPAddress]; //set CreditCard info CreditCardDetailsType creditCardDetails = new CreditCardDetailsType(); requestDetails.CreditCard = creditCardDetails; creditCardDetails.CreditCardNumber = details[CheckoutKeys.CardNumber]; creditCardDetails.CreditCardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), details[CheckoutKeys.CardType], true); creditCardDetails.CVV2 = details[CheckoutKeys.VerificationCode]; creditCardDetails.ExpMonth = Int32.Parse(details[CheckoutKeys.ExpireMonth]); creditCardDetails.ExpYear = Int32.Parse(details[CheckoutKeys.ExpireYear]); // Switch/Solo if (creditCardDetails.CreditCardType == CreditCardTypeType.Solo || creditCardDetails.CreditCardType == CreditCardTypeType.Switch) { creditCardDetails.StartMonth = Int32.Parse(details[CheckoutKeys.StartMonth]); creditCardDetails.StartYear = Int32.Parse(details[CheckoutKeys.StartYear]); creditCardDetails.IssueNumber = details[CheckoutKeys.IssueNumber]; } //set billing address PayerInfoType cardOwner = new PayerInfoType(); creditCardDetails.CardOwner = cardOwner; cardOwner.PayerName = new PersonNameType(); cardOwner.PayerName.FirstName = details[CheckoutKeys.FirstName]; cardOwner.PayerName.LastName = details[CheckoutKeys.LastName]; cardOwner.Address = new AddressType(); cardOwner.Address.Street1 = details[CheckoutKeys.Address]; //??? cardOwner.Address.Street2 = ""; cardOwner.Address.CityName = details[CheckoutKeys.City]; cardOwner.Address.StateOrProvince = details[CheckoutKeys.State]; cardOwner.Address.PostalCode = details[CheckoutKeys.Zip]; cardOwner.Address.CountrySpecified = true; cardOwner.Address.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), details[CheckoutKeys.Country], true); //set payment Details PaymentDetailsType paymentDetails = new PaymentDetailsType(); requestDetails.PaymentDetails = paymentDetails; paymentDetails.OrderTotal = new BasicAmountType(); //TODO: Add currency support paymentDetails.OrderTotal.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), details[CheckoutKeys.Currency]); //paymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD; //No currency symbol. Decimal separator must be a period (.), and the thousands separator must be a comma (,) paymentDetails.OrderTotal.Value = details[CheckoutKeys.Amount]; DoDirectPaymentReq paymentRequest = new DoDirectPaymentReq(); paymentRequest.DoDirectPaymentRequest = request; //FINISH set up req //setup request Header, API credentials PayPalAPIAASoapBinding paypalInterface = new PayPalAPIAASoapBinding(); UserIdPasswordType user = new UserIdPasswordType(); //set api credentials - username, password, signature user.Username = Username; user.Password = Password; user.Signature = Signature; // setup service url paypalInterface.Url = ServiceUrl; paypalInterface.RequesterCredentials = new CustomSecurityHeaderType(); paypalInterface.RequesterCredentials.Credentials = user; //make call return response DoDirectPaymentResponseType paymentResponse = new DoDirectPaymentResponseType(); paymentResponse = paypalInterface.DoDirectPayment(paymentRequest); //write response xml to the ret object ret.RawResponse = SerializeObject(paymentResponse); switch (paymentResponse.Ack) { case AckCodeType.Success: case AckCodeType.SuccessWithWarning: ret.Succeed = true; ret.TransactionId = paymentResponse.TransactionID; ret.TransactionStatus = TransactionStatus.Approved; break; default: // show errors if Ack is NOT Success ret.Succeed = false; ret.TransactionStatus = TransactionStatus.Declined; if (paymentResponse.Errors != null && paymentResponse.Errors.Length > 0) { ret.StatusCode = PayPalProKeys.ErrorPrefix + paymentResponse.Errors[0].ErrorCode; } break; } return ret; }