public PaypalPaymentResult Payment(string trans_desc, string currency, double amount, string ccNbr, string ccType, string firstName, string lastName, int expiry_month, int expiry_year, string cvv2, PaypalCreditCardAddressInfo addr) { V1PaypalPaymentResult result = _V1CCPayment(trans_desc, currency, amount, ccNbr, ccType, firstName, lastName, expiry_month, expiry_year, cvv2, addr); return(new PaypalPaymentResult { id = result.id, amount = double.Parse(result.transactions[0].amount.total), currency = result.transactions[0].amount.currency, state = result.state, create_time = DateTime.Parse(result.create_time), salesId = result.transactions[0].related_resources[0].sale.id, avs_code = result.transactions[0].related_resources[0].sale.processor_response["avs_code"], cvv_code = result.transactions[0].related_resources[0].sale.processor_response["cvv_code"] }); }
private V1PaypalPaymentResult _V1CCPayment(string trans_desc, string currency, double amount, string ccNbr, string ccType, string firstName, string lastName, int expiry_month, int expiry_year, string cvv2, PaypalCreditCardAddressInfo addr) { string url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "v1/payments/payment"; V1PaypalPayment payment = new V1PaypalPayment { intent = "sale", payer = new V1PaypalPayer { funding_instruments = new List <V1PaypalFundingInstrument> { new V1PaypalFundingInstrument { credit_card = new V1PaypalCCPayment { number = ccNbr, type = ccType, expire_month = expiry_month.ToString("D2"), expire_year = expiry_year.ToString() , cvv2 = cvv2 , first_name = firstName, last_name = lastName , billing_address = addr == null ? null : new V1PayPalAddressInfo { line1 = addr.line1, line2 = addr.line2, city = addr.city, country_code = addr.country_code, postal_code = addr.postal_code, state = addr.state, phone = addr.phone } } } }, payment_method = "credit_card" }, transactions = new List <V1PaypalTransaction> { new V1PaypalTransaction { amount = new V1PaypalAmount { currency = currency, total = amount.ToString("0.00") } , description = trans_desc } } }; JavaScriptSerializer serializer = new JavaScriptSerializer(); //serializer.RegisterConverters(new JavaScriptConverter[] { new NullPropertiesConverter() }); string payment_json = serializer.Serialize(payment); //payment_json = @"{'intent':'sale','payer':{'payment_method':'credit_card','funding_instruments':[{'credit_card':{'number':'5500005555555559','type':'mastercard','expire_month':12,'expire_year':2018,'cvv2':'111','first_name':'Betsy','last_name':'Buyer'}}]},'transactions':[{'amount':{'total':'7.47','currency':'USD'},'description':'This is the payment transaction description.'}]}"; string return_json = _V1Action(url, payment_json); V1PaypalPaymentResult result = serializer.Deserialize <V1PaypalPaymentResult>(return_json); return(result); }