i can't send shipping options to paypal with rest api sdk
This is #payment.error.inspect
{
"name"=>"VALIDATION_ERROR",
"details"=>[
{
"field"=>"payer.payer_info.phone",
"issue"=>"This field currently not supported in this request" },
{
"field"=>"payer.payer_info.first_name",
"issue"=>"Not valid to specify this field in a request" },
{
"field"=>"payer.payer_info.last_name",
"issue"=>"Not valid to specify this field in a request" },
{
"field"=>"payer.payer_info.email",
"issue"=>"This field currently not supported in this request" },
{
"field"=>"payer.payer_info.shipping_address",
"issue"=>"Not valid to specify this field in a request" }
],
"message"=>"Invalid request - see details",
"information_link"=>"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR",
"debug_id"=>"2139ec6f8c916"
}
when i do:
shipping_address = {
recipient_name: self.order.fullname,
type: self.order.address_type,
line1: self.order.street1,
line2: self.order.street2,
city: self.order.city,
country_code: self.order.country_code,
postal_code: self.order.zip,
state: self.order.state,
phone: self.order.phone_number }
payer_info = {
email: self.order.email,
first_name: self.order.fullname.split(" ").first,
last_name: self.order.fullname.split(" ").last,
phone: self.order.phone_number,
shipping_address: shipping_address }
self.payment = Payment.new({
:intent => "sale",
:payer => {
:payment_method => "paypal",
:payer_info => payer_info },
:redirect_urls => {
:return_url => return_url,
:cancel_url => cancel_url },
:transactions => [{
:item_list => {
:shipping_address => shipping_address,
:items => self.order.order_items.map do |item|
{
:name => _("T-shirts %{size} size") % {size: item.size},
:sku => "item",
:price => self.order.campaign.price_for_size(item.size),
:currency => "HKD",
:quantity => item.count,
:amount => item.price
}
end},
:amount => {
:total => self.order.price,
:currency => "HKD" },
:description => _("This is the payment transaction description.") }]})
self.payment.create
self.payment.error.inspect
i'm use paypal-rest-sdk and need to send information about buyer to paypal for precomplete fields with address and buyer information.
how to send to paypal shipping address and payer_info ?
When your payment_method is "paypal", the payer_info object is pre-filled. payer_info only needs to be submitted when payment_method is credit_card
Related
I'm trying to default the billing country to the UK, but no matter what i try it always defaults to the US.
Any ideas?
Note, that we do not require the customer to enter a shipping address so this has been hidden as per the json but have tried setting this to see if it makes a difference with no joy.
I've tried the following:
json_patch_request: [
{
op: 'replace',
path: '/payer/payer_info/billing_address',
value: {
country_code: 'GB',
}
}
],
payer: {
payer_info: {
country_code: 'GB',
billing_address: {
country_code: 'GB',
},
shipping_address: {
country_code: 'GB',
}
}
},
payment: {
transactions: [
{
amount: {
total: 10,
currency: 'GBP'
},
custom: 'x',
},
],
},
experience: {
input_fields: {
no_shipping: 1
},
flow_config: {
landing_page_type: "billing",
},
presentation: {
locale_code: "GB",
},
}
You need to set that in your seller profile:
Log in to your PayPal account
Click Money at the top of the page
Click Manage Currency
Choose the currency to make Primary
Click Make Primary
See https://www.paypal-community.com/t5/About-Payments-Archive/How-to-change-Paypal-default-currency-to-USD/td-p/616528
I've just started playing with this module:
https://github.com/paypal/paypal-checkout
I'm trying to work out how to can turn off the shipping address for clients. I know in order versions you could do &NOSHIPPING=1 in the URL, but I can't find anything about the API 4 version. My code is:
paypal.Button.render({
// Pass the client ids to use to create your transaction on sandbox and production environments
locale: 'fr_FR',
//env: 'production',
env: 'sandbox',
client: {
sandbox: "...",
production: "..."
},
// Pass the payment details for your transaction
// See https://developer.paypal.com/docs/api/payments/#payment_create for the expected json parameters
payment: function() {
return paypal.rest.payment.create(this.props.env, this.props.client, {
transactions: [
{
amount: {
total: window.my_config.grand_total,
currency: 'EUR',
details: {
"subtotal": window.my_config.price,
"tax": window.my_config.vat_amount
}
},
}
]
});
},
// Display a "Pay Now" button rather than a "Continue" button
commit: true,
// Pass a function to be called when the customer completes the payment
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function() {
console.log('The payment was completed!');
console.log(data, actions)
if (error === 'INSTRUMENT_DECLINED') {
actions.restart();
}
});
},
// Pass a function to be called when the customer cancels the payment
onCancel: function(data) {
console.log('The payment was cancelled!');
},
style: {
shape: 'rect',
size: "medium"
}
}, '#paypalContainerEl');
Use "shipping_preference: 'NO_SHIPPING'."
createOrder: function(data, actions) {
$('#paypalmsg').html('<b>' + 'WAITING ON AUTHORIZATION TO RETURN...' + '</b>');
$('#chkoutmsg').hide()
return actions.order.create({
purchase_units: [{
description: 'GnG Order',
amount: {
value: cartTotal
}
}],
application_context: {
shipping_preference: 'NO_SHIPPING'
}
});
},
You need to pass the no_shipping option under experience in the payment function, like so:
return actions.payment.create(
{
payment:
{
transactions: [
{
amount:
{
total: "10",
currency: 'EUR'
}
}]
},
experience:
{
input_fields:
{
no_shipping: 1
}
}
});
In the docs, here and here. A quick note though, guests will still be asked for their billing address, even though their shipping address will no longer be asked.
For those of you integrating via PayPal REST API in PHP, to set the no_shipping attribute:
apiContext = $this->apiContext;
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$inputFields = new \PayPal\Api\InputFields();
$inputFields->setNoShipping(1); //<-- NO SHIPPING!!!!!!!!!!
$webProfile = new \PayPal\Api\WebProfile();
$webProfile->setName($uid); // <-- UNIQUE NAME FOR THE TRANSACTION
$webProfile->setInputFields($inputFields);
$createProfileResponse = $webProfile->create($apiContext);
$webProfile = \PayPal\Api\WebProfile::get($createProfileResponse->getId(), $apiContext);
$amount = new \PayPal\Api\Amount();
$amount->setCurrency('EUR')
->setTotal($this->deposit_eur);
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl($this->return_url)
->setCancelUrl($this->cancel_url);
$payment = new \PayPal\Api\Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction))
->setExperienceProfileId($webProfile->getId()); //<-- SET EXPERIENCE PROFILE
try{
$payment->create($apiContext);
} catch (\Exception $ex) {
debug($ex);
exit;
}
$approvalUrl = $payment->getApprovalLink();
For the unlucky lads integrating this via PayPal REST API, using C#, this is a bit trickier.
You create a WebProfile as in the Paypal Repo Example.
var experienceProfile = new WebProfile()
{
name = Guid.NewGuid().ToString(), // required field
input_fields = new InputFields()
{
no_shipping = 1
}
};
var experienceId = experienceProfile .Create(_apiContext).id;
new Payment
{
intent = "sale",
payer = new Payer
{
payment_method = "paypal"
},
transactions = new List<Transaction>
{
// ...
},
redirect_urls = new RedirectUrls
{
return_url = "..",
cancel_url = ".."
},
experience_profile_id = experienceId
};
If anyone runs into this problem with the v2 API REST approach, setting application_context with shipping_preference on create order in the body did work for me.
https://developer.paypal.com/docs/api/orders/v2/#definition-experience_context_base
const response = await fetch(url, {
method: 'post',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({
intent: 'CAPTURE',
application_context: {
shipping_preference: 'NO_SHIPPING',
},
purchase_units: []
})
For the new API you need to set the parameter no_shipping=1
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
I wanna create a creative with api. When i post object_story_spec parameter, i got this error 'Creative spec must be an associative array (optionally json-encoded)'
this is my json value it is valid.
{ "page_id" : "103830656322074", "link_data": { "call_to_action": {"type":"LEARN_MORE","value":{"link":"facebook.com/"}}, "caption": "Reklam #1", "name": "Reklam #1", "link": "facebook.com/", "message": "facebook.com/" }}
developers.facebook.com/docs/marketing-api/reference/ad-creative#Creating
you should url enocde the $object_story_spec before passing into the creative like below.
$object_story_spec = urlencode($object_story_spec);
$creative = new AdCreative(null, 'ad_Acount_id');
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
It should be like something.
object_story_spec={
"page_id": "<PAGE_ID>",
"video_data": {
"call_to_action": {"type":"LIKE_PAGE","value":{"page":"<PAGE_ID>"}},
"description": "try it out",
"image_url": "<THUMBNAIL_URL>",
"video_id": "<VIDEO_ID>"
}
}
Or
$object_story_spec = new ObjectStorySpec();
$object_story_spec->setData(array(
ObjectStorySpecFields::PAGE_ID => <PAGE_ID>,
ObjectStorySpecFields::LINK_DATA => <LINK_DATA>,
));
$creative = new AdCreative(null, 'ad_Acount_id');
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
Just cast the targeting field to string, For example, if you are using requests:
import requests
params = {
'name': 'My Ad Set',
'optimization_goal': 'LINK_CLICKS',
'billing_event': 'IMPRESSIONS',
'bid_amount': 2,
'daily_budget': 100,
'campaign_id': campaign_id,
"targeting": str({
"age_max": 65,
"age_min": 18,
"flexible_spec": [..]
}),
'start_time': datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
'status': 'PAUSED',
'access_token': access_token,
}
response = requests.post(
url=f'https://graph.facebook.com/v11.0/act_{ad_account_id}/adsets',
params=params
)
I could NOT get back the email information anymore with Omniauth.
I think the problem is duing to the API 2.4,
But I don't get how could I the the expected information
Devise config
config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], {
:scope => 'email',
:info_fields => 'id,email,gender,link,locale,name,timezone,updated_time,verified',
strategy_class: OmniAuth::Strategies::Facebook,
:provider_ignores_state => true}
Returned information not including email information
:1> env['omniauth.auth']
{
"provider" => "facebook",
"uid" => "xxxx",
"info" => {
"name" => "Eric Hsu",
"image" => "http://graph.facebook.com/xxxx/picture?type=square"
},
"credentials" => {
"token" => "CAAh",
"expires_at" => 1443066205,
"expires" => true
},
"extra" => {
"raw_info" => {
"name" => "Eric Hsu",
"id" => "xxxx"
}
}
}
I found the problem is that the dependency between FB API and omniauth-facebook version.
current i installed the gem omniauth-facebook (2.0.1)
We currently process USD payments via paypal's REST API using their ruby gem. I would like to accept other currencies and have set our account to auto-convert foreign currency payments to USD. I can successfully process these payments and can see in the sandbox web interface that they were converted, but it's unclear to me how to look the conversion transactions up via the API. Can anyone shed any light on this? See screenshot and completed payment + sale record below.
Response[200]: OK, Duration: 0.858s
{
"id" => "PAY-0XK33729VB648561PKV5SG6A",
"intent" => "sale",
"payer" => {
"payment_method" => "paypal",
"status" => "VERIFIED",
"payer_info" => {
"email" => "jack#example.com",
"first_name" => "Fake",
"last_name" => "Fakerson",
"payer_id" => "F2JC8YDQ6HDUA",
"shipping_address" => {
"line1" => "1 Main St",
"city" => "San Jose",
"state" => "CA",
"postal_code" => "95131",
"country_code" => "US",
"recipient_name" => "Fake Fakerson"
}
}
},
"transactions" => [
[0] {
"amount" => {
"currency" => "EUR",
"total" => "5.00",
"details" => {
"subtotal" => "5.00"
}
},
"description" => "Unlimited School - I'm a course",
"related_resources" => [
[0] {
"sale" => {
"id" => "24439073LW446012K",
"amount" => {
"currency" => "EUR",
"total" => "5.00"
},
"payment_mode" => "INSTANT_TRANSFER",
"state" => "completed",
"protection_eligibility" => "ELIGIBLE",
"protection_eligibility_type" => "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
"transaction_fee" => {
"currency" => "EUR",
"value" => "0.50"
},
"parent_payment" => "PAY-0XK33729VB648561PKV5SG6A",
"create_time" => "2015-06-12T18:22:48Z",
"update_time" => "2015-06-12T18:23:19Z",
"links" => [
[0] {
"href" => "https://api.sandbox.paypal.com/v1/payments/sale/24439073LW446012K",
"rel" => "self",
"method" => "GET"
},
[1] {
"href" => "https://api.sandbox.paypal.com/v1/payments/sale/24439073LW446012K/refund",
"rel" => "refund",
"method" => "POST"
},
[2] {
"href" => "https://api.sandbox.paypal.com/v1/payments/payment/PAY-0XK33729VB648561PKV5SG6A",
"rel" => "parent_payment",
"method" => "GET"
}
]
}
}
]
}
],
"state" => "approved",
"create_time" => "2015-06-12T18:22:48Z",
"update_time" => "2015-06-12T18:23:19Z",
"links" => [
[0] {
"href" => "https://api.sandbox.paypal.com/v1/payments/payment/PAY-0XK33729VB648561PKV5SG6A",
"rel" => "self",
"method" => "GET"
}
]
}
I don't think so that REST API has any API for fetching the currency conversion only at this moment .
However , you can use the PayPal's Classic API to achieve your goal . See the example below :
NVP Request:
USER=XXXX&PWD=XXXXX&SIGNATURE=XXXXXXXX&VERSION=109.0&METHOD=TransactionSearch&STARTDATE=2014-06-01T00:00:00Z&ENDDATE=2015-06-05T00:00:00Z&TRANSACTIONCLASS=CurrencyConversions
NVP Response:
L_TIMESTAMP0=2015-04-21T20:53:39Z
L_TIMESTAMP1=2015-04-21T20:53:39Z
L_TIMESTAMP2=2014-11-11T18:40:45Z
L_TIMESTAMP3=2014-11-11T18:40:45Z
L_TIMEZONE0=GMT
L_TIMEZONE1=GMT
L_TIMEZONE2=GMT
L_TIMEZONE3=GMT
L_TYPE0=Currency Conversion (credit)
L_TYPE1=Currency Conversion (debit)
L_TYPE2=Currency Conversion (credit)
L_TYPE3=Currency Conversion (debit)
L_NAME0=From British Pound
L_NAME1=To U.S. Dollar
L_NAME2=From U.S. Dollar
L_NAME3=To British Pound
L_TRANSACTIONID0=76K70596XX6169325
L_TRANSACTIONID1=7P3811819E363281J
L_TRANSACTIONID2=2GF65791PP4273901
L_TRANSACTIONID3=2K135972TE2156124
L_STATUS0=Completed
L_STATUS1=Completed
L_STATUS2=Completed
L_STATUS3=Completed
L_AMT0=4060.54
L_AMT1=-2626.32
L_AMT2=6.36
L_AMT3=-10.36
L_CURRENCYCODE0=USD
L_CURRENCYCODE1=GBP
L_CURRENCYCODE2=GBP
L_CURRENCYCODE3=USD
L_FEEAMT0=0.00
L_FEEAMT1=0.00
L_FEEAMT2=0.00
L_FEEAMT3=0.00
L_NETAMT0=4060.54
L_NETAMT1=-2626.32
L_NETAMT2=6.36
L_NETAMT3=-10.36
TIMESTAMP=2015-06-12T22:48:14Z
CORRELATIONID=f01a7f7fb27f2
ACK=Success
VERSION=109.0
BUILD=16964802