/// <summary> /// Function for running sample CreditCardPayment /// </summary> /// <returns></returns> public ActionResult PaymentWithCreditCard() { //Create sample payment in local model CreditCardPaymentBean samplePayment = ModelFactory.createSampleCreditCardPayment(); //Translate to paypal payment Payment translatedPayment = ModelFactory.translateToPayPalPayment(samplePayment); //Executes payment return(ExecutePayment(translatedPayment)); }
/// <summary> /// /// </summary> /// <returns></returns> public static Payment translateToPayPalPayment(CreditCardPaymentBean creditPayment) { //Sync transaction object to bean data Transaction transaction = new Transaction(); transaction.amount = creditPayment.amount; transaction.description = creditPayment.description; transaction.invoice_number = creditPayment.invoice_number; //Create itemlist, add item objects to it and add it to transaction transaction.item_list = new ItemList() { items = new List <Item>() { creditPayment.item } }; // Now we need to specify the FundingInstrument of the Payer // for credit card payments, set the CreditCard which we made above FundingInstrument fundInstrument = new FundingInstrument(); fundInstrument.credit_card = creditPayment.creditCard; // The Payment creation API requires a list of FundingIntrument List <FundingInstrument> fundingInstrumentList = new List <FundingInstrument>(); fundingInstrumentList.Add(fundInstrument); // Now create Payer object and assign the fundinginstrument list to the object Payer payr = new Payer(); payr.funding_instruments = fundingInstrumentList; payr.payment_method = "credit_card"; // finally create the payment object and assign the payer object & transaction list to it return(new Payment() { intent = "sale", payer = payr, transactions = new List <Transaction>() { transaction } }); }