C# PayPal REST Api (.NET SDK) - c#

I am using the .NET PayPal SDK (github.com/paypal/PayPal-NET-SDK) and am able to successfully create a paypal request, redirect the user, the user completes payment and all is well.
For the life of me, I can't figure out how to show the "Credit Card / No Paypal Account" screen instead of the "Login with paypal ... or click here if you don't have paypal to pay with credit card" screen.
Most of my users don't have paypal and just want to pay with a credit card (and I'd like to process it all through paypal, directly through their site so that users never give me their credit card number).
Here is the code I have that work for paying with paypal, but how can I tell it to show the "credit card/guest checkout" on paypal's landing page?
string PaypalRedirectURL(string returnURL, string cancelURL)
{
// create the transaction list
var trans = new List<Transaction>();
// make the actual transaction
var t = new Transaction()
{
description = "Payment For Something",
invoice_number = "inv1234",
amount = new Amount()
{
currency = "USD",
total = "2.00",
details = new Details
{
tax = "0",
shipping = "0",
subtotal = "2.00"
}
}
};
t.item_list = new ItemList();
t.item_list.items = new List<Item>();
Item i = new Item();
i.name = "Something I charge for";
i.quantity = "1";
i.sku = "item0001";
i.currency = "USD";
i.price = "2.00";
// Add item to item list
t.item_list.items.Add(i);
//add transaction to transaction list
trans.Add(t);
// create the payment
var payment = Payment.Create(GetAPIContext(), new Payment
{
intent = "sale",
payer = new Payer
{
payment_method = "paypal"
},
transactions = trans,
redirect_urls = new RedirectUrls
{
return_url = returnURL,
cancel_url = cancelURL
}
});
var links = payment.links.GetEnumerator();
string paypalRedirectUrl = null;
while (links.MoveNext())
{
Links lnk = links.Current;
// get the payment redirect link
if (lnk.rel.ToLower().Trim().Equals("approval_url"))
{
//saving the payapalredirect URL to which user will be redirected for payment
paypalRedirectUrl = lnk.href;
}
}
return paypalRedirectUrl;
}
I've tried numerous variations of [payment_method = "paypal"] (like (="credit_card", etc) but nothing seems to work. Again, I don't want to provide the credit card to this, I want the credit card "guest checkout" on paypal's site to show by default.
This is the screen the user gets on paypal (they can click the "pay with credit card" but I want to know if I can send them directly to the credit card screen without them having to click anything.
Current Page they are sent to:
Default paypal screen
Page I'd like the user to see by default (with the credit card fields displayed):
Desired default paypal page
Any help would be greatly appreciated .. thanks in advance

Related

Add a description to a stripe product at checkout

I am working on a C# application where the app users will purchase a subscription for their clients. Since they will buy multiple subscriptions, I need to add a description (client name) to a product so it shows up in the billing portal along with the price. My current checkout code works fine and the relevant part is here:
var options = new Stripe.Checkout.SessionCreateOptions
{
LineItems = new List<SessionLineItemOptions>
{
new SessionLineItemOptions
{
Price = priceId,
Quantity = 1
},
},
PaymentMethodTypes = new List<string>
{
"card",
},
Mode = "subscription",
SuccessUrl = string.Concat("https://", domain, "/success/", hhid, "?session_id={CHECKOUT_SESSION_ID}"),
CancelUrl = string.Concat("https://", domain),
Customer = customerId,
SubscriptionData = new SessionSubscriptionDataOptions()
{
Metadata = new Dictionary<string, string>()
{
{ "userId", userId.ToString() }
}
}
};
if (!string.IsNullOrEmpty(user.PaymentCustomerId))
options.Customer = user.PaymentCustomerId;
var service = new Stripe.Checkout.SessionService();
Stripe.Checkout.Session session = await service.CreateAsync(options);
Response.Headers.Add("Location", session.Url);
I contacted Stripe support and their response was
In this particular case we do not have an option that allow you to add a description, but you are able to add the name with price_data parameter into the Checkout, Invoice Items, and Subscription Schedule APIs.
https://stripe.com/docs/api/subscription_items/create
https://stripe.com/docs/billing/prices-guide
They provided links to the two articles which I have read and re-read and don't understand how to implement it. If anyone can help it would be greatly appreciated.
Unfortunately, the Billing Portal does not show a description for the Product.
If you want to use the Billing Portal, then you would need to specify the client name in the name for the Product e.g. [client name] Product #1, and this would require you to create a new Product and Price for every client.
You can do it in the Checkout Session creation :
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product_data-name
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
Or, create the Product and Price separately :
https://stripe.com/docs/api/products/create
https://stripe.com/docs/api/prices/create

Paypal .Net SDK implementation

Dear StackOverflow Community,
We have started to implement the PayPal .Net SDK in our project.
We create a Payment with the following Code:
var payment = Payment.Create(GetDefaultApiContext(), new Payment
{
intent = "sale",
payer = new Payer
{
payment_method = "paypal"
},
transactions = new List<Transaction>
{
new Transaction
{
description = "Test",
invoice_number = "009",
amount = new Amount
{
currency = "EUR",
total = "41.00",
details = new Details
{
tax = "0",
shipping = "0",
subtotal = "40",
handling_fee = "1"
}
},
item_list = new ItemList
{
items = new List<Item>
{
new Item
{
name = "Room 12",
currency = "EUR",
price = "10",
quantity = "4",
}
}
}
}
},
redirect_urls = new RedirectUrls
{
return_url = "https://google.de/",
cancel_url = "https://google.de/"
}
});
The payment is also created and a corresponding link is generated. If we now pay with our test account, the money is not debited and nothing more happens, the forwarding also works normally. However, no transaction is reported to PayPal.
It would be very nice if someone could help us with this Problem.
Thank you!
After the redirect back to the return_url you provided, you are expected to present an order review page and then when the user confirms the order you must do a payment Execute API call, which will result in the PayPal transaction. If you do not do the Execute API call, there will be no transaction.
Do not worry about money being debited from the payer account, since payer accounts have funding sources with infinite funds in sandbox.
Note also that the v1/payments SDK you are using is deprecated, you should upgrade to the current v2/checkout/orders Checkout-NET-SDK and use it to create two routes on your server, one for 'Create Transaction' and one for 'Capture Transaction', documented here.
The best approval flow to pair with your two new routes is https://developer.paypal.com/demo/checkout/#/pattern/server

How can I use the Mollie Order API?

Anyone who is familliar with the Mollie API?
I am trying to set up a payment for a webshop, but I don't have much knowledge of the Mollie API.
So I got 2 questions:
The Order API of Mollie is like the Payment API, but the order API is a bit more "advanced" and more made for a webshop with products? Is that correct?
I got the following code, I assume (according to the Mollie documentation of how a payment works)
that I can set up a payment (order) with an amount and other additional information, the user will than be redirected to the Mollie platform where he can choose a payment method.
List<OrderLineRequest> OrderLineList = new List<OrderLineRequest>();
foreach(product in cart) {
OrderLineRequest Orderline = new OrderLineRequest();
Orderline.Name = B.GetProductName(ProductID);
Orderline.Quantity = Amount;
Orderline.UnitPrice = new Amount(Currency.EUR, ProductPrice.ToString());
Orderline.TotalAmount = new Amount(Currency.EUR, (Amount * ProductPrice).ToString());
Orderline.VatRate = "21.00";
Orderline.VatAmount = new Amount(Currency.EUR, ((Amount * ProductPrice)*0,21).ToString());
OrderLineList.Add(Orderline);
}
IOrderClient orderClient = new OrderClient("my API key");
OrderRequest orderRequest = new OrderRequest()
{
Amount = new Amount(Currency.EUR, "Amount needs to be paid"),
OrderNumber = OrderID.ToString(),
Lines = OrderLineList,
BillingAddress = new OrderAddressDetails()
{
GivenName = FirstName,
FamilyName = LastName,
Email = Email,
City = City,
Country = Country,
PostalCode = PostalCode,
StreetAndNumber = Street + " " + HouseNumber
},
RedirectUrl = "URL I want to redirect to when payment is done",
Locale = Locale.en_US
};
What else do I have to do for the user to be redirected to the Mollie platform to pay?
Thanks alot for taking time to read this, I hope you can help me out!
Thanks in advance!

INTERNAL_SERVICE_ERROR while creating payment in PayPal SandBox, MVC

I have ran out of ideas and none of the answers for the similar question was helpful, hence I am desperate now. I am trying to integrate paypal payment into my app. I have set negative testing to off in my sandbox account. I am using visual studio 2013, here is my example code:
Address billingAddress = new Address();
billingAddress.line1 = "52 N Main ST";
billingAddress.city = "Johnstown";
billingAddress.country_code = "US";
billingAddress.postal_code = "43210";
billingAddress.state = "OH";
CreditCard creditCard = new CreditCard();
creditCard.number = "4417119669820331";
creditCard.type = "visa";
creditCard.expire_month = 11;
creditCard.expire_year = 2018;
creditCard.cvv2 = "874";
creditCard.first_name = "Joe";
creditCard.last_name = "Shopper";
creditCard.billing_address = billingAddress;
var amountDetails = new Details();
amountDetails.subtotal = "7.41";
amountDetails.tax = "0.03";
amountDetails.shipping = "0.03";
Amount amount = new Amount();
amount.total = "7.47";
amount.currency = "USD";
amount.details = amountDetails;
Transaction transaction = new Transaction();
transaction.amount = amount;
transaction.description = "This is the payment transaction description.";
List<Transaction> transactions = new List<Transaction>();
transactions.Add(transaction);
FundingInstrument fundingInstrument = new FundingInstrument();
fundingInstrument.credit_card = creditCard;
List<FundingInstrument> fundingInstruments = new List<FundingInstrument>();
fundingInstruments.Add(fundingInstrument);
Payer payer = new Payer();
payer.funding_instruments = fundingInstruments;
payer.payment_method = "credit_card";
Payment payment = new Payment();
payment.intent = "sale";
payment.payer = payer;
payment.transactions = transactions;
var config = ConfigManager.Instance.GetProperties();
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
try
{
var apiContext = new APIContext(accessToken);
var createdPayment = payment.Create(apiContext);
}
catch (PayPal.HttpException e)
{
return Json(e.InnerException, JsonRequestBehavior.AllowGet);
}
Now each time I am attempting to create the payment, I am getting the following:
"{\"name\":\"INTERNAL_SERVICE_ERROR\",\"message\":\"An internal service error has occurred\",\"information_link\":\"https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR\",\"debug_id\":\"f0d2f70ac4693\"}"
debug_id changes each time i attempt. any help would be hugely appreciated.
Try changing the credit card number you're using to a different number. This error has been happening a lot in the recent weeks on PayPal's sandbox environment and is (most of the time) related to overusing a credit card number. The best thing to try would be to create a new Sandbox test account via the Developer Dashboard and generate a new credit card number there.
The PayPal payments team is currently working on a solution on sandbox to return a more meaningful error when this happens.
EDIT:
As an alternative to creating a new Sandbox test account to get a new credit card number for testing, you can also try the credit card number generator available in the following FAQ on the PayPal Technical Support site:
Sandbox - Generate an Additional Credit Card Number for a Sandbox account.
Scroll down to Step 4 on that page to find the generator.

Error in transaction processing when using SetPaymentsOptionsRequest

I'm working on integrating PayPal into a client's ecommerce site. Using the sandbox, we got everything working fine. I now need to add in SetPaymentOptionsRequest to prevent the user from changing his shipping address (they enter it on our site, so they can't change it at PayPal due to different shipping costs calculated on our site). It appears to work fine, but I get a 3005 error when logging into the PayPal sandbox site to confirm the transaction. Below is the relevant code (C#):
public string MakeChainedPayment(params params) {
var request = new PayRequest {
requestEnvelope = new RequestEnvelope("en_us"),
actionType = "CREATE",
cancelUrl = this._cancelUrl,
currencyCode = this._currencyCode,
returnUrl = this._returnUrl,
ipnNotificationUrl = this._ipnNotificationUrl
};
// Some code to generate receivers, not important for this problem, I don't think
var response = this._paymentService.Pay(request);
switch (response.paymentExecStatus) {
// This always returns "CREATED", as I'd want, so good up to here.
case "CREATED":
// If I leave this code out, PayPal works fine, but I need
// this part to do the shipping address verification.
var p = new SetPaymentOptionsRequest();
p.senderOptions = new SenderOptions();
p.senderOptions.addressOverride = false;
p.senderOptions.shippingAddress = new ShippingAddressInfo {
// Setting from params: city, country, zip, state, street1, street2
};
p.payKey = response.payKey;
p.requestEnvelope = request.requestEnvelope;
SetPaymentOptionsResponse r = _paymentService.SetPaymentOptions(payOptsReq);
break;
// This always retuns r.error.Count = 0, r.responseEnvelope.ack = "SUCCESS",
// so I think I'm good to go.
}
if (this._useSandbox) {
return string.Concat("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=", response.payKey);
}
return string.Concat("https://www.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=", response.payKey);
}
Paypal returns this message when your Paypal account's email address has not been verified. To verify your Paypal Email account, please follow the following steps:
Log into your Paypal Account. You should be in the “Overview” tab.
Click on your Email address, under “Business account overview”, you will be taken to a Web page listing your Paypal Email addresses.
Select your Primary Adress.
Click on the “Confirm” button.
Follow the rest of the Paypal instructions.
The problem was what I was passing in for the country; I was sending in "USA", and it should be "US".

Categories

Resources