0

Here is my code for checking out with a credit card. Using PayPal Trans works fine but I am missing something for credit card trans.

HttpContext CurrContext = HttpContext.Current; APIContext apiContext = Configuration.GetAPIContext(); Item item = new Item(); item.name = _ItemDescription; item.currency = "USD"; item.price = _Amount; item.quantity = "1"; item.sku = _UPC; List<Item> itms = new List<Item>(); itms.Add(item); ItemList itemList = new ItemList(); itemList.items = itms; Address billingAddress = new Address(); billingAddress.city = ciTxBx.Text; billingAddress.country_code = "US"; billingAddress.line1 = ad1TxBx.Text; billingAddress.line2 = ad2TxBx.Text; billingAddress.postal_code = pcTxBx.Text; billingAddress.state = stRcb.SelectedValue.ToString(); CreditCard crdtCard = new CreditCard(); crdtCard.billing_address = billingAddress; crdtCard.cvv2 = scTxBx.Text; crdtCard.expire_month = Convert.ToInt32(emonthTxBx.Text); crdtCard.expire_year = Convert.ToInt32(eyearTxBx.Text); crdtCard.first_name = ccfnTxBx.Text; crdtCard.last_name = cclnTxBx.Text; crdtCard.number = ccnTxBx.Text; crdtCard.type = ConvertLower(cctRcb.SelectedValue.ToString()); Details details = new Details(); details.tax = "0"; details.shipping = "0"; details.subtotal = _Amount; Amount amont = new Amount(); amont.currency = "USD"; amont.total = _Amount; amont.details = details; Transaction tran = new Transaction(); tran.amount = amont; tran.description = _ItemDescription; tran.item_list = itemList; List<Transaction> transactions = new List<Transaction>(); transactions.Add(tran); FundingInstrument fundInstrument = new FundingInstrument(); fundInstrument.credit_card = crdtCard; List<FundingInstrument> fundingInstrumentList = new List<FundingInstrument>(); fundingInstrumentList.Add(fundInstrument); PayerInfo pi = new PayerInfo(); pi.email = emTxBx.Text; pi.first_name = fnTxBx.Text; pi.last_name = lnTxBx.Text; pi.shipping_address = billingAddress; Payer payr = new Payer(); payr.funding_instruments = fundingInstrumentList; payr.payment_method = "credit_card"; payr.payer_info = pi; Payment paymnt = new Payment(); paymnt.intent = "sale"; paymnt.payer = payr; paymnt.transactions = transactions; try { Payment createdPayment = paymnt.Create(apiContext); CurrContext.Items.Add("ResponseJson", JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented)); } catch (PayPal.Exception.PayPalException ex) { if (ex.InnerException is PayPal.Exception.ConnectionException) { CurrContext.Response.Write(((PayPal.Exception.ConnectionException)ex.InnerException).Response); } else { CurrContext.Response.Write(ex.Message); } } CurrContext.Items.Add("RequestJson", JObject.Parse(paymnt.ConvertToJson()).ToString(Formatting.Indented)); 

Anyone know why I am receiving a "No payload for this request" message?

6
  • Seems you have no PayerInfo for your Payer. Hth... Commented Apr 7, 2015 at 14:09
  • I have made edits to my original post. Thanks for posting. Still no joy though. Commented Apr 8, 2015 at 16:12
  • So after examining the sandbox I see the credit card transaction listed but still the website showing error "No payload for this request". Any other ideas? Commented Apr 9, 2015 at 16:10
  • Can anyone help me. I'm desperate to get this working. Thank you. Commented Apr 16, 2015 at 14:18
  • Does the above actually compile? pi.shipping_address = billingAddress; re: Address vs. ShippingAddress (PayerInfo) Commented Apr 16, 2015 at 15:32

1 Answer 1

1

Well after mocking your code (and hard-coding values), the line that I commented on is the only thing I corrected to make it work (I don't know how/why your code would compile):

pi.shipping_address = new ShippingAddress { city = "San Mateo", country_code = "US", line1 = "SO TEST", line2 = "", postal_code = "94002", state = "CA", }; 

And finally the (successful) response from PayPal (ResponseJson):

ResponseJson: { "id": "PAY-8EU11336Y2032051SKUYZZOQ", "intent": "sale", "payer": { "payment_method": "credit_card", "funding_instruments": [{ "credit_card": { "number": "xxxxxxxxxxxx2274", "type": "visa", "expire_month": 1, "expire_year": 2018, "first_name": "Stack", "last_name": "Overflow", "billing_address": { "line1": "SO TEST", "line2": "", "city": "San Mateo", "country_code": "US", "postal_code": "94002", "state": "CA" } } }] }, "transactions": [{ "related_resources": [{ "sale": { "id": "1Y28050325502832C", "amount": { "currency": "USD", "total": "99.00" }, "state": "completed", "parent_payment": "PAY-8EU11336Y2032051SKUYZZOQ", "create_time": "2015-04-17T23:52:26Z", "update_time": "2015-04-17T23:52:28Z", "links": [{ "href": "https://api.sandbox.paypal.com/v1/payments/sale/1Y28050325502832C", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/sale/1Y28050325502832C/refund", "rel": "refund", "method": "POST" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-8EU11336Y2032051SKUYZZOQ", "rel": "parent_payment", "method": "GET" }] } }], "amount": { "currency": "USD", "total": "99.00", "details": { "subtotal": "99.00" } }, "description": "trnx desc", "item_list": { "items": [{ "quantity": "1", "name": "foo", "price": "99.00", "currency": "USD", "sku": "fooSku" }] } }], "state": "approved", "create_time": "2015-04-17T23:52:26Z", "update_time": "2015-04-17T23:52:28Z", "links": [{ "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-8EU11336Y2032051SKUYZZOQ", "rel": "self", "method": "GET" }] } 

And shown in Paypal developer Sandbox Transactions:

screen shot paypal developer

Hth...

Sign up to request clarification or add additional context in comments.

11 Comments

Would you mind posting your code so that I may do a comparison to mine. thank you.
This is so frustrating! I am still receiving the same error that there is no payload. Does anyone have C# code for PayPal using a credit card? I would hate to have to go back to classic PayPal.
@RooGuru I used your code, except for the variables coming from controls (I just provided hard coded values). The only other thing I changed was the line for ShippingAddress. Are you doing the above in an asp.net app context? I am (and that maybe where we differ?). Another assumption is that you are using the .Net SDK (based on the methods and object names you used, still its just my assumption).
I am using context and I do have the SDK installed. Should I not be using the SDK?
@RooGuru - use the SDK (I am). Where exactly to you hit that error? As you can tell, I can't seem to repro it....
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.