How to Specify NoShipping 1 with Express Checkout checkout.js v4 - paypal

I have express checkout working with the latest checkout.js but do not need to show any shipping address. Since it's a digital good, the docs say I need noshipping set to 1. However, I can't figure out how that goes into the javascript.
I followed the basic integration steps and then used the REST API to execute the payment so I can charge to my server.
I've tried adding noshipping:1 all over the place within the javascript to create the payment with no luck. Here's what it looks like ( ignore compile issues as I'm just trying to show how I tried adding the noshipping:1 information):
payment: function() {
var env = this.props.env;
var client = this.props.client;
return paypal.rest.payment.create(env, client, {
transactions: [
{
amount: { total: '4.99', currency: 'USD' }
DOESNT WORK-->noshipping: 1
}
],
DOESNT WORK-->noshipping: 1
});
},
Does anyone know how to properly pass the noshipping information using the latest checkout.js?

OK, it appears that they have finally added support for this. It looks like this:
payment: {
transactions: [
{
amount: { total: '19.99', currency: 'USD' }
// Possibly there is also a 'custom' field we can specify here;
// https://stackoverflow.com/questions/46320753/
}
],
application_context: {
shipping_preference: 'NO_SHIPPING'
}
}

Got an "official" response from paypal support a week later:
Thank you for contacting PayPal Merchant Technical Services.
Unfortunately we do not have an option for the noshipping when using
REST API. That option is only available on the classic express
checkout which uses the NVP/SOAP API.
There it is. This fairly simple concept isn't possible with their latest SDK.

Yes, there's a way to specify NOSHIPPING as follows on PayPal-Python-SDK, as per your code:
payment: function() {
var env = this.props.env;
var client = this.props.client;
return paypal.rest.payment.create(env, client, {
transactions: [
{
amount: { total: '4.99', currency: 'USD' }
}
],
application_context: {
shipping_preferences: 'NO_SHIPPING',
}
});
},
I hope it helps.

Related

How to setup Paypal subscriptions with multiple currencies?

For each product we do the following:
When a new product is added, create a new Product with POST /v1/catalogs/products
Using the product_id from step 1, create a new plan POST /v1/billing/plans
Whenever a customer clicks "Subscribe" button, we create a new subscription using plan_id from step 2 with POST /v1/billing/subscriptions
Problem: When creating the subscription we are able to change the price the customer will be billed by passing the plan object to POST /v1/billing/subscriptions endpoint to override the amount of the plan. However passing in a different currency throws an error:
"The currency code is different from the plan's currency code."
With that being said, is thereĀ a way to setup paypal subscriptions where we can pass in a different currency? Is it required to create a new plan for each currency because this does not seem like a good solution
We create a billing plan with the following body:
{
product_id: productId,
name: planName,
status: 'ACTIVE',
billing_cycles: [
{
frequency: {
interval_unit: 'MONTH',
interval_count: 1
},
tenure_type: 'REGULAR',
sequence: 1,
// Create a temporary pricing_scheme. This will be replaced
// with a variable amount when a subscription is created.
pricing_scheme: {
fixed_price: {
value: '1',
currency_code: 'CAD'
}
},
total_cycles: 0
}
],
payment_preferences: {
auto_bill_outstanding: true,
payment_failure_threshold: 2
}
}
We create subscription with the following body (however passing in a different currency than the plan (CAD) throws an error):
{
plan_id: planId,
subscriber: {
email_address: email
},
plan: {
billing_cycles: [
{
sequence: 1,
pricing_scheme: {
fixed_price: {
value: amount,
currency_code: currency
}
}
}
]
},
custom_id: productId
};
Is it required to create a new plan for each currency
Yes

I don't understand how to get a token to make API calls

I'm using the Payouts API and to do so I have to specify an access token when calling https://api-m.sandbox.paypal.com/v1/payments/payouts
To get an access token, as specified here I have to send a POST request with Postman to https://developer.paypal.com/docs/api/overview/#get-an-access-token and it returns in the response the token
My problem is that this token has an expiration time, which is an issue because I can't go in my app every 15 minutes to change the token in the Authorization header. How can I get a "permanent" or rather an "auto refreshed" token ?
I tried to make a call from my app instead of Postman but it doesn't seem to work, it says my credentials are invalid
This is my code in case it can be useful (I'm managing everything from the front-end):
window.paypal
.Buttons({
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [
{
description: this.product.description,
amount: {
value: this.product.price
}
}
]
});
},
onApprove: (data, actions) => {
const timestamp = new Date().getUTCMilliseconds();
const id = timestamp;
return actions.order.capture().then(details => {
axios
.post(
"https://api-m.sandbox.paypal.com/v1/payments/payouts",
{
sender_batch_header: {
sender_batch_id: id,
email_subject: "You have a payout!",
email_message:
"You have received a payout! Thanks for using our service!",
recipient_type: "EMAIL"
},
items: [
{
amount: {
value: this.product.price,
currency: "USD"
},
note: "congrats someone bought your stuff",
sender_item_id: id,
receiver: "john#doe.com"
}
]
},
{
headers: {
Authorization:
"Bearer <my token that I get from postman>"
}
}
)
.then(() => {
alert(
"Transaction completed by " + details.payer.name.given_name
);
})
.catch(err => console.log(err));
});
}
})
.render(".paypal");
}
},
Update
Reading the code a second time and noticing how your Payout is for the same this.product.price as the original payment, that makes no sense. Don't use payouts at all for this use case. The full amount will go to your account normally, but if you want the full amount to go somewhere else instead, set the payee variable for this checkout: https://developer.paypal.com/docs/checkout/integration-features/pay-another-account/
(original answer below)
Using Payouts from the client side is an absolutely terrible idea, anyone with your client credentials will be able to send money from your account to wherever they want
The payouts API must be used from your server only. Your server needs to do an API call to get an access token, similar to what you mention about postman -- except using whatever backend environment you have. You can integrate direct HTTPS calls, or there are also Payouts SDKs available which will handle getting the access token automatically.
As for how to trigger that backend action when capturing a payment, use a proper server integration:
Create two routes, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return JSON data. Before returning JSON data, that last route (the capture one) should record the successful transaction in your database and trigger any Payout logic you want.
Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

Magento2 - How to place order using graphql?

I am following this tutorial to process cart / checkout for placing orders using graphql. Magento GraphQl Tutorial. And we have installed stripe on magento(backend).
So we are facing issue while placing order, we have done few steps upto point 5.
Customer logs in get a authentication token
Create empty cart
Add product to cart
Set billing and shipping address for cart
Set payment method to stripe_payments (without card details)
How to set payment information and where to set ?
Placing order receiving error here
How can I set payment method and debit card details to cart using graphql and place an successful test order?
Make sure all steps ( 1 to 5 ) have been done without any issue. Please check the below steps for the mutation by which you can set the payment method and place the order.
Example: Use the setPaymentMethodOnCart mutation to set the payment method for your order. The value checkmo ("Check / Money order" payment method code) was returned in the query.
mutation {
setPaymentMethodOnCart(input: {
cart_id: "{ CART_ID }"
payment_method: {
code: "checkmo"
}
}) {
cart {
selected_payment_method {
code
}
}
}
}
Response:
If the operation is successful, the response contains the code of the selected payment method.
{
"data": {
"setPaymentMethodOnCart": {
"cart": {
"selected_payment_method": {
"code": "checkmo"
}
}
}
}
}
Set payment method and place order
Use the setPaymentMethodAndPlaceOrder mutation to set the payment method and place the order.
Request:
mutation {
setPaymentMethodAndPlaceOrder(input: {
cart_id: "{ CART_ID }"
payment_method: {
code: "checkmo"
}
}) {
order {
order_id
}
}
}
Response:
If the operation is successful, the response contains the order ID.
{
"data": {
"setPaymentMethodAndPlaceOrder": {
"order": {
"order_id": "000000001"
}
}
}
}
Note: Make sure "setPaymentMethodAndPlaceOrder mutation" is not deprecated in the current version of Magento 2.
First check the available payment method ( added from magneto dashboard only)
Then set that payment method and post the query
https://devdocs.magento.com/guides/v2.4/graphql/tutorials/checkout/checkout-payment-method.html

Paypal Smart Buttons Metadata - Webhook

I'm using the Paypal Javascript SDK to render smart buttons and capture and authorize all client side. Everything is working great except for the occasional customer not waiting around for processing to complete on our side.
I have set up webhooks and subscribed to all events but am not able to/or not sure how to define and receive any of my custom data IDs etc.
I've attempted several different configurations to pass my data to the order from create order - mainly following this guide https://developer.paypal.com/docs/commerce-platform/v1/reference/orders-integration-guide/#create-order
Which adds custom data to purchase_units as custom and also a metadata json object with supplementary_data and postback_data
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
intent: 'CAPTURE',
purchase_units : [{
items : ....,
description : ...,
amount : ...,
custom : 'purchase_units_data'
}],
metadata : {
supplementary_data : [{
data : 'supplementary_data'
}],
postback_data : [{
data : 'postback_data'
}]
}
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
....
});
}
}).render('#paypal-button-container');
Would hope to find a way to pass a bit of custom data to a webhook payload.
The answer appears to be that I was looking at the wrong version of the API.
https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit_request
While I can't create a nicely formed metadata object I can however add data to the purchase_units object with reference_id and custom_id.
I'll just have to get a bit creative.

YouTrack email notification using custom fields

I've added a custom field for 'interested parties' (users) in a particular issue, not project specific, and it works fine.
I would like YouTrack to generate emails to their email address on update or change of the issue, like they do to the person who it is assigned to, is this possible?
Let's say you want to send notifications by e-mail when a ticket is ready to be reviewed. People responsible for the review are set via a Reviewer custom field (which can contain multiple values). Then you can send notifications as follows:
var entities = require('#jetbrains/youtrack-scripting-api/entities');
exports.rule = entities.Issue.stateMachine({
title: 'Workflow',
fieldName: 'State',
states: {
'To Be Reviewed': {
onEnter: function(ctx) {
var issue = ctx.issue;
issue.fields.Reviewer.forEach(function(user) {
user.notify("Reminder", "This is a reminder", true);
});
},
transitions: {}
},
},
requirements: {
Reviewer: {
type: entities.User.fieldType,
multi: true
}
}
});
You can create a custom workflow like the following one:
when {
if (Interested Parties.isNotEmpty) {
for each user in Interested Parties {
user.notify("subj", "body");
}
}
}
Another point is that you probably do not need this field since you can 'star' an issue on behalf of a user and the user thus will be notified about any changes. Just type star user_name in the command window.