I am integrating Paypal into an ASP.NET MVC 5 application, and I followed the steps in this post: PayPal Integration.
I signed up on Paypal developer(Paypal New Zealand, and thus the default currency is NZD) with my email:
my-name#hotmail.com. And two sandbox accounts were generated:
buniness: my-name-facilitator#hotmail.com
personal: my-name-buyer#hotmail.com (with balance 9999.00)
Created a REST App in dashboard:
Copied the client id and client secret to appsettings.json:
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=_CHANGE_ME;Trusted_Connection=True;"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Verbose",
"System": "Information",
"Microsoft": "Information"
}
},
"PayPal": {
"clientId": "AZbTe-V1UhGgPkdALRNyIWAN5IZB9kfhYneI1iL-P5dnsE3IHbDyAjj5MeNFH_cNKl7eK2GVqCf5AJ_K",
"clientSecret": "EFK1VysVtlj69_Wg9Zj7FTQi5jEb0nUF-cFORJ2cpIwP6j9fLaQTBsQy9V_Mo3DP9QcWT3zdZ6H3jZB4"
}
}
}
I updated the clientid and secret in PayPalConfiguration.cs as well:
public static Dictionary<string, string> GetConfig()
{
// ConfigManager.Instance.GetProperties(); // it doesn't work on ASPNET 5
return new Dictionary<string, string>() {
{ "clientId", "AZbTe-V1UhGgPkdALRNyIWAN5IZB9kfhYneI1iL-P5dnsE3IHbDyAjj5MeNFH_cNKl7eK2GVqCf5AJ_K" },
{ "clientSecret", "EFK1VysVtlj69_Wg9Zj7FTQi5jEb0nUF-cFORJ2cpIwP6j9fLaQTBsQy9V_Mo3DP9QcWT3zdZ6H3jZB4" }
};
}
Anyway, I used checkpoint to make sure that the program uses my new clientid and clientsecret when calling Paypal API.
When testing the Paypal program, I used the personal sandbox account to pay 100 dollars, and I can view that transaction record on https://www.sandbox.paypal.com/myaccount/
However, I cannot see any transaction record for the business account. What did I miss? Thanks in advance.
Related
I am trying to create Paypal subscription through its Rest API using live client and secret.
The API returns success message. The GET subscription API returns the active subscription created, however I don't see any active subscription in my Paypal dashbaord.
Paypal support says the subscription ID does not exist.
Has anyone encountered such issue with Paypal API?
I have attached API JSON response and snapshot herewith.
{
"plans": [
{
"id": "P-4UJ45561KJ704964LMJ2QDZQ",
"product_id": "PROD-4EX86934CR7151923",
"name": "Certified business economist IHK | VO 2022",
"status": "ACTIVE",
"description": "The business economist IHK is divided into the following five subjects with the new examination regulations 2022",
"usage_type": "LICENSED",
"create_time": "2022-05-06T11:09:26Z",
"links": [
{
"href": "https://api.paypal.com/v1/billing/plans/P-4UJ45561KJ704964LMJ2QDZQ",
"rel": "self",
"method": "GET",
"encType": "application/json"
}
]
}
],
"total_items": 1,
"total_pages": 1,
"links": [
{
"href": "https://api.paypal.com/v1/billing/plans?product_id=PROD-4EX86934CR7151923&page_size=2&page=1",
"rel": "self",
"method": "GET",
"encType": "application/json"
}
]
}
First of all, everything in your question shows creating a plan. A plan is not a subscription, it is the cycle details to be able to create a subscription.
Secondly, creating a subscription still will not do anything unless a payer signs in to approve it. For a payer to approve a subscription, use a PayPal button. This is detailed in the Subscriptions Integration Guide.
Note that the createSubscription function can create a subscription for approval itself, by passing it an object with a plan_id (and optionally a plan object to override some part of that plan_id). This is the most simple method.
Alternatively, the subscription can be created via API, at a route on your server which that function will fetch when the button is clicked. Something like:
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID_GOES_HERE&vault=true&intent=subscription"></script>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
style: {
label:'subscribe' //Optional text in button
},
createSubscription: function(data, actions) {
return fetch('/path/on/your/server/paypal/subscription/create/', {
method: 'post'
}).then(function(res) {
return res.json();
}).then(function(serverData) {
console.log(serverData);
return serverData.id;
});
},
onApprove: function(data, actions) {
/* Optional: At this point, notify your server of the activated subscription...
fetch('/path/on/your/server/paypal/subscription/activated/' + data.subscriptionID , {
method: 'post'
}).then(function(res) {
return res.json();
}).then(function(serverData) {
//
});
*/
//You could additionally subscribe to a webhook for the BILLING.SUBSCRIPTION.ACTIVATED event (just in case), as well as other future subscription events
//Ref: https://developer.paypal.com/api-basics/notifications/webhooks/event-names/#subscriptions
// Show a message to the buyer, or redirect to a success page
alert('You successfully subscribed! ' + data.subscriptionID);
}
}).render('#paypal-button-container');
</script>
I am using my paypal sandbox, and I am trying to use v2/vault/payment-tokens API to tokenize a credit card
Url:https://api.sandbox.paypal.com/v2/vault/payment-tokens
Method: POST
RequestBody(fake credit card that sandbox generated):
{
"source": {
"card": {
"number": "40320382525xxxx",
"expiry": "2022-11"
}
}
}
I can make sure that my sandbox have full scopes, my access token is right.
Below is the response:
{
"name": "UNPROCESSABLE_ENTITY",
"message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id": "15c1b3e9d8161",
"details": [
{
"issue": "UNKNOWN_BUSINESS_ERROR",
"description": "There was an issue while processing your request."
}
],
"links": [
{
"href": "https://developer.paypal.com/docs/api/vault/v2/#error-UNKNOWN_BUSINESS_ERROR",
"rel": "information_link",
"method": "GET"
}
]
}
Does any one meet the same issue?
Will you have permissions to use /v2/vault/payment-tokens in live mode? This API shouldn't be integrated without guidance from PayPal
Try using a test credit card from https://developers.braintreepayments.com/guides/credit-cards/testing-go-live/node
I am using sandbox environment and PayPal Server side Java SDK V2
I have created an order with OrdersCreateRequest() API then i get this classical response including required links
{
"id": "xxxxxxxxxxxxxxxx",
"status": "CREATED",
"links": [
{ xxxxxxxxx },
{
"href": "https://www.sandbox.paypal.com/checkoutnow?token=XXXXXXXXXX",
"rel": "approve",
"method": "GET"
} ,
{ xxxxxxxxx },
{ xxxxxxxxx },
{ xxxxxxxxx },
]
}
In my business use case , I need to redirect the buyer after he goes to approval page , put his credentials and confirm , i want to get token as parameter from redirected link
So i tested this process , the order status become approved but the page doesn't redirect and it just reloads.
I have tried to add this parameter to body of OrdersCreateRequest
"application_context": {
"return_url ": "http://xxx.xx.xxx.x:9000/invoice/10/view"
}
but the page still reloads after approvement.
In this situation I can't know when the buyer has approved the order in my app .
I'm developing a digital subscription model using Paypal's rest API. I'm following https://developer.paypal.com/docs/subscriptions/ as well as referencing the API doc for more details.
I'm having difficulty figuring out how to omit the shipping address requirement entirely. When the customer is on paypal's subscription approval page (on paypal.com), shipping address selection is always shown. I've already tried not entering shipping_address as well as omitting the tax charge_model. Neither of these change anything on the approval page. Companies like Netflix, Hulu, and all other sites I've checked don't require a shipping address when the customer is on the approval page. Any ideas?
Within the subscription payload, just set the shipping option to NO_SHIPPING like so:
"shipping_preference": "NO_SHIPPING"
Here's an example of a complete payload:
subscriptionBodyPayload = {
"plan_id": `${subscriptionId}`,
"start_time": `${startDate}`,
"subscriber": {
"name": {
"given_name": `${first_name}`,
},
"email_address": `${userEmail}`
},
"application_context": {
"brand_name": "SerpWorx",
"locale": "en-US",
"shipping_preference": "NO_SHIPPING",
"user_action": "SUBSCRIBE_NOW",
"payment_method": {
"payer_selected": "PAYPAL",
"payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
},
"return_url": "https://example.com/success/",
"cancel_url": "https://example.com/checkout/"
}
I'm trying to use PayPal REST API instead of PayPal Classic API but it seems that the REST API is lacking two features that the Classic API has:
immediate payment: when the user goes to PayPal page show him a "Pay now" button instead of a "Continue" button and "You’re almost done. You will confirm your payment on ..." phrase.
no shipping address: avoid asking the user to confirm his shipping address while on PayPal page (in Classic API is done with NOSHIPPING=1 parameter, if I remember well)
So my question is: is it possibile do perform an immediate payment without asking for shipping address using REST API? Do I have to go back to Classic API?
I provide here a little more informations about how I'm using the PayPal REST API.
I'm using the PayPal REST Java SDK.
This is a sample request:
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"currency": "USD",
"total": "5",
"details": {
"subtotal": "5"
}
},
"description": "This is the payment transaction description.",
"item_list": {
"items": [
{
"quantity": "1",
"name": "Item 1",
"price": "5",
"currency": "USD"
}
]
}
}
],
"redirect_urls": {
"return_url": "http://XXX/handlePayment.jsp?guid\u003dXXX",
"cancel_url": "http://XXX/cancelPayment.jsp?guid\u003dXXX"
}
}
And its response:
{
"id": "XXX",
"create_time": "2014-06-29T08:52:55Z",
"update_time": "2014-06-29T08:52:55Z",
"state": "created",
"intent": "sale",
"payer": {
"payment_method": "paypal",
"payer_info": {
"shipping_address": {}
}
},
"transactions": [
{
"amount": {
"total": "5.00",
"currency": "USD",
"details": {
"subtotal": "5.00"
}
},
"description": "This is the payment transaction description.",
"item_list": {
"items": [
{
"name": "Item 1",
"price": "5.00",
"currency": "USD",
"quantity": "1"
}
]
}
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/XXX",
"rel": "self",
"method": "GET"
},
{
"href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=XXX",
"rel": "approval_url",
"method": "REDIRECT"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/XXX/execute",
"rel": "execute",
"method": "POST"
}
]
}
While delving through the REST API I came across this
I believe this means you don't have to go about creating any "Profiles" as such, and can just pass them along with the payment call...
Further explanation as requested :)
Below is an example of passing PayPal experience parameters along with a particular payment call using the Client-side JS method for Express checkout.
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '1.00', currency: 'USD' }
}
]
},
experience: {
input_fields: {
no_shipping: 1
}
}
});
},
Hope that makes enough sense to you guys! :)
Unfortunately, the REST API is still a long ways behind the Classic API with features it provides. These features you mentioned are things I've seen come up quite a bit, and to my knowledge they are not yet available with the REST services.
I personally have stuck with Classic as they provide everything and I really see no advantage to using REST myself. If you happen to be working with PHP (which I always do) you may be interested in my class library for PayPal. It makes all of the Classic API calls very quick and easy for you, and it's available on Packagist so you can use with Composer easily.
The REST API now supports no-shipping with the Payment Experience APIs.
You need to create a web experience profile and supply no_shipping as an input field. Then use the profile ID when creating the payment.
The profile ID doesn't need to be recreated every time.
appreciate that this post hasn't had any activity for a while but...
i hit on the exact same problem and used this post as a start point for my own question:
paypal api: take immediate payment without a shipping address
it's taken a bit of trial and error but i you can create a one off web profile with 'no_shipping' set to 1, store the id that it creates and then pass that in with future payments that don't require a shipping address.
still haven't figured out how to get rid of the 'You're almost done. You will confirm your payment on xxx.' but my payment process is a far better place than it was!
hope this helps someone out there as this no shipping issue is one that a lot of people appear to be hitting with the paypal api...
I tried using the experience section of the API and apart from still not being able to force a locale code have been able to disable shipping and go straight to billing:
payment: {
transactions: [{
invoice_number: document.getElementById("ReqTxt").value,
amount: {
total: document.getElementById("InvoiceAmt").innerText,
currency: document.getElementById("Currency").innerText
}
}]
},
experience: {
input_fields: {
no_shipping: 1
},
flow_config: {
landing_page_type:'billing'
}
}
you can also see this page. It is possible to set the user action in the flow_config section too
For 'Pay Now' instead of 'Continue' on Paypal I use a special param in approval url:
$approvalUrl = $payment->getApprovalLink().'&useraction=commit';
Result:
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=TOKEN&useraction=commit