private IPaymentResponse EndExpressCheckout(IPaymentRequest request) { PaymentResponse response = new PaymentResponse (); GetExpressCheckoutDetailsReq req = new GetExpressCheckoutDetailsReq() { GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType() { Version = this._paymentGateway.APIVersion, Token = request.Token, } }; // query PayPal for transaction details GetExpressCheckoutDetailsResponseType paypalResp = BuildPayPalWebservice().GetExpressCheckoutDetails(req); //handle error if (paypalResp.Errors != null && paypalResp.Errors.Length > 0) { response.IsSuccess = false; response.Message = paypalResp.Errors[0].LongMessage; return response; } GetExpressCheckoutDetailsResponseDetailsType respDetails = paypalResp.GetExpressCheckoutDetailsResponseDetails; PaymentDetailsType[] sPaymentDetails = new PaymentDetailsType[1]; sPaymentDetails[0] = new PaymentDetailsType() { OrderTotal = new BasicAmountType() { currencyID = respDetails.PaymentDetails.FirstOrDefault().OrderTotal.currencyID, Value = respDetails.PaymentDetails.FirstOrDefault().OrderTotal.Value }, /*must specify PaymentAction and PaymentActionSpecific, or it'll fail with PaymentAction : Required parameter missing (error code: 81115)*/ PaymentAction = PaymentActionCodeType.Sale, // Recurring = RecurringFlagType.Y, PaymentActionSpecified = true }; // prepare for commiting transaction DoExpressCheckoutPaymentReq payReq = new DoExpressCheckoutPaymentReq() { DoExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType() { Version = this._paymentGateway.APIVersion, DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType() { Token = paypalResp.GetExpressCheckoutDetailsResponseDetails.Token, /*must specify PaymentAction and PaymentActionSpecific, or it'll fail with PaymentAction : Required parameter missing (error code: 81115)*/ PaymentAction = PaymentActionCodeType.Sale, PaymentActionSpecified = true, PayerID = paypalResp.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID, PaymentDetails = sPaymentDetails } } }; // commit transaction and display results to user DoExpressCheckoutPaymentResponseType doResponse = BuildPayPalWebservice().DoExpressCheckoutPayment(payReq); try { //handle error if (paypalResp.Errors != null && paypalResp.Errors.Length > 0) { response.IsSuccess = false; response.Message = paypalResp.Errors[0].LongMessage; return response; } } catch (Exception ex) { } if (!string.IsNullOrEmpty(doResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID) && doResponse.Ack == AckCodeType.Success) { response.TransactionId = doResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID; } else { response.IsSuccess = false; response.Message = "No Transaction id returned"; return response; } // Create Recurring profile. var pp_response = CreateRecurringPaymentsProfile(paypalResp.GetExpressCheckoutDetailsResponseDetails.Token, respDetails.PaymentDetails.FirstOrDefault().OrderTotal, respDetails.PaymentDetails[0], request); string profileId = pp_response.CreateRecurringPaymentsProfileResponseDetails.ProfileID; return null; }
private CreateRecurringPaymentsProfileResponseType CreateRecurringPaymentsProfile(string token, BasicAmountType OrderTotal, PaymentDetailsType paymentDetailsType, IPaymentRequest request) { CreateRecurringPaymentsProfileReq pp_request = new CreateRecurringPaymentsProfileReq() { CreateRecurringPaymentsProfileRequest = new CreateRecurringPaymentsProfileRequestType() { Version = "64.0", CreateRecurringPaymentsProfileRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType() { Token = token, RecurringPaymentsProfileDetails = new RecurringPaymentsProfileDetailsType() { BillingStartDate = DateTime.Now.AddDays(1), //SubscriberName = registrationData.UserName }, ScheduleDetails = new ScheduleDetailsType() { Description = paymentDetailsType.OrderDescription,//"Test-Account", MaxFailedPayments = 6, MaxFailedPaymentsSpecified = true, AutoBillOutstandingAmount = AutoBillType.AddToNextBilling, AutoBillOutstandingAmountSpecified = true, PaymentPeriod = new BillingPeriodDetailsType() { Amount = new BasicAmountType() { Value = OrderTotal.Value, currencyID = CurrencyCodeType.USD }, BillingFrequency = 1, BillingPeriod = BillingPeriodType.Day, }, ActivationDetails = new ActivationDetailsType() { InitialAmount = OrderTotal, FailedInitialAmountAction = FailedPaymentActionType.ContinueOnFailure } } } } }; CreateRecurringPaymentsProfileResponseType pp_response = new CreateRecurringPaymentsProfileResponseType(); pp_response = BuildPayPalWebservice().CreateRecurringPaymentsProfile(pp_request); return pp_response; }