Is it possible to retrieve refund details such as the parent transaction ID with the PayPal NVP API? So far I know it's possible to retrieve the details of a "Received" transaction by using "GetTransactionDetails" but for refunds it seems that method doesn't work.
body = {
USER: user_id,
PWD: password,
SIGNATURE: signature,
METHOD: 'GetTransactionDetails',
TRANSACTIONID: refund_id
VERSION: 204
}
response = HTTParty.post('https://api-3t.sandbox.paypal.com/nvp', body: body).
#Parsed response:
{
"ADDRESSOWNER"=>"PayPal", "ADDRESSSTATUS"=>"None",
"TIMESTAMP"=>"2018-03-15T11:04:45Z",
"CORRELATIONID"=>"97e8f9e1e9921", "ACK"=>"Failure",
"VERSION"=>"204", "BUILD"=>"39949200", "L_ERRORCODE0"=>"10004",
"L_SHORTMESSAGE0"=>"Invalid transaction type",
"L_LONGMESSAGE0"=>"You can not get the details for this type of transaction",
"L_SEVERITYCODE0"=>"Error",
"PENDINGREASON"=>"None",
"REASONCODE"=>"None",
"L_TAXABLE0"=>"false"
}
I've tested it again with another refund ID and I think my example from above failed as refunds for PayPal fees cannot be retrieved. Regular refunds can be retrieved with the GetTransactionDetails.
Related
This is a follow up to the successful call using Netsuite Token Based Authentication (TBA) REST webservice,
I would like to get some guidance on how to perform a query.
I am supposed to read records like this (please see screenshot)
how can I perform a specifc query (by table for a list of records and also specific record) ?
https://gist.github.com/axilaris/4386c3537d04737d3775c156562b7545 <-- here is the python code for the TBA that has worked successful. I would like to know how to construct the next step on how to perform the query and read specific record (as shown in the screenshot).
This is a custom record with an ID like this customrecord1589
To query a specific record: You're going to need to create/ deploy a RESTlet in Netsuite similar to the following:
/**
* #NApiVersion 2.1
* #NScriptType Restlet
*/
define([
"N/log",
"N/search",
], function (log, search) {
function post(context) {
return JSON.stringify(getCustomRecords(context));
}
function getCustomRecords(context) {
log.debug('POST Context', context);
return search.lookupFields({
//Change CUSTOM_RECORD to the type of custom record you are querying
type: search.Type.CUSTOM_RECORD + '1589',
id: context.id,
columns: context.fields,
});
}
return {
post: post,
};
});
In your Python Script: Make sure you change the URL of the request to the deployment URL of this new RESTlet. Also, make sure to pass any parameters you need (like 'id' or 'fields' in my example) in your POST request payload. So instead of:
payload = {
"name":"value",
"foo":"bar",
"duck":"hunt",
}
pass
payload = {
"id":"9999999",
"fields": ["custrecord_field1", "custrecord_field2"],
}
where id is the internalid of the record you want to query and the fields array are the internalids of the fields you want values from.
If this goes successfully, the result should show up as conn.text in your python script!
I'm trying to update my SendGrid contacts and can't figure out why my attempts to update my contacts' custom fields are not working. My reserved fields (first_name, last_name, email) update, but my custom fields do not. Any ideas why?
Documentation here: https://sendgrid.api-docs.io/v3.0/contacts/add-or-update-a-contact
try:
headers = {
'authorization': f"Bearer {settings.SENDGRID_API_KEY}",
}
data = {
"list_ids": [
# "Users" list
"7c2...d20"
],
"contacts": [{
"email": user.email,
"first_name": user.first_name,
"last_name": user.last_name,
"custom_fields": {
"educator_role": user.educator_role,
}
}]
}
response = requests.put("https://api.sendgrid.com/v3/marketing/contacts", headers=headers, data=json.dumps(data))
if(response.status_code != 202):
capture_message(f"Could not add user with email {user.email} to Sendgrid.", level="error")
except:
capture_message(f"Adding/updating SendGrid contact failed for {user.email}.", level="error")```
Unlike reserved fields, updating a custom field requires you pass the custom field id instead of the field name in your call. So instead of educator_role, use the id, it will be something random like e1_T.
You can get the id via the /marketing/field_definitions endpoint.
As said by #Matt, to update a custom field value via SendGrid API, we need to refer to the custom field by its ID, not by the field name.
To get a list with your custom field IDs, do:
from sendgrid import SendGridAPIClient
SENDGRID_API_KEY="print-your-key-here"
sg = SendGridAPIClient(SENDGRID_API_KEY)
response = sg.client.marketing.field_definitions.get()
print(response.body)
Also, take a look at the docs: https://docs.sendgrid.com/api-reference/custom-fields/get-all-field-definitions.
The custom field ID has logic
For custom fields, the unique ID always starts with the suffix e. Followed by an integer number that represents the creation order of the custom fields on the SendGrid platform, p.e. 1, 2, 3. Followed by underscore _. Followed by a letter that represents the custom field type:
N - Number
T - Text
D - Date
Here is an example of a custom field ID list:
{
"custom_fields":[
{"id":"e1_N","name":"number_field_test","field_type":"Number"},
{"id":"e2_T","name":"text_field_test","field_type":"Text"},
{"id":"e3_D","name":"data_field_test","field_type":"Date"}
]
}
I am implementing spring-social-facebook 2.0.3.RELEASE, however I would like to know how to retrieve the access token expiry time?
Below is the code to access facebook to fetch user profile, but how to retrieve the access token expiry time?
Facebook facebook = new FacebookTemplate(accessToken);
String[] fields = { "id", "email", "first_name", "last_name" };
User userProfile = facebook.fetchObject("me", User.class, fields);
I'm currently trying to figure out a way for my MEAN stack application to keep track of which users have paid to grant them access to a certain portion of my webpage. I've considered several options: Stripe customer ID, MongoDB record, And HTML attribute I can update.
My mean stack keeps track of users by JWT, and it appears stripe assigns them their own customer ID which isn't ideal. Can it done with JWT as opposed to their forced cutomer ID?
MongoDB record. Which is what I'm thinking might be the best option. When a new user has been created, i'll give it an attribute of hasPaid = no. Then update the record of that customer when a payment is submitted. Then I guess run a script to set everyone back to unpaid each day?
HTML element/attribute. I don't know if this is even possible; but it would be cool to create a key that is carried during the HTML session after payment is received. If the person closers the browser then the session would be closed?
I'm looking for guidance on my 3 options to determine if they're the best solution. Also, if anyone has any suggestions as to alternatives, I'm all ears!
Thanks in advance.
Speaking generally, the most common approach would be the second one: use an attribute in your data model that indicates whether the user has paid/should be granted access. When a charge is created [0] successfully, update the model to indicate so, then filter access based on this attribute.
[0] https://stripe.com/docs/api/node#create_charge
Use a Boolean value in your user model.
var UserSchema = new Schema({
name: String,
hasPaid: {type: Boolean, default: false} //set this false
});
then in your REST API routes, the user buys the product; now set hasPaid to true
// req.user._id is passport config
User.findOneAndUpdate({_id: req.user._id}, {$set: {"hasPaid":istrue}}).exec(function(err) {
if(err) {
throw err;
}else {
req.flash('success', 'Thank you for submitting the form.');
res.render('charge', {
layout: 'dash',
user: req.user,
success: req.flash('success')
});
}
});
Now you can keep track of the users that purchased your products to grant them access to other parts of your site.
Stripe.js comes with Checkout.js which makes it even easier to use Stripe's service.
Copy and paste this into your html/jade/handlebars or view file. This will display a popup form to let the user type in his or her cc information.
<form action="/charge" method="POST">
<script
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="pk_test_bla3hf&kc033"
data-image="/square-image.png"
data-name="Demo Site"
data-description="2 widgets ($20.00)"
data-amount="2000">
</script>
</form>
You will receive a token once the user presses submit that you grab on your server. From inside your REST API route, you can charge the customer:
var token = req.body.stripeToken; // Using Express
// Create a charge: this will charge the user's card
var charge = stripe.charges.create({
amount: 1999, // Amount in cents
currency: "usd",
source: token,
metadata: {
user: req.user._id,
email: req.user.local.email
}
description: "Example charge" //keep track by writing a description or you can use the metadata property Stripe has to offer in the charges object
},function(err, charge) {
if (err && err.type === 'StripeCardError') {
// The card has been declined
}else {
res.redirect('/thanks-for-your-order');
console.log('charge here ' + charge.id); //store the id
console.log('charge here ' + charge.invoice); //store the invoice
console.log('charge here ' + charge.customer); //store the customer id
}
});
You can now track each order by storing the properties of the charge object in any model you wish.
I've been unable to find an accurate answer for this.
As we know already, PayPal's REST API doesn't have a option for applying discount code. However, we can append another item to the item_list with a description of a I.e. Promo / Discount code.
So e.g. breaking this into human readable data, here's what I'm passing to the API.
Transaction
Amount: 100
item_list: [ product1, 60 ], [ product2, 60 ], [ coupon_code, -20 ]
Visually, This route should work (as it does in the classic API). However, the PayPal API doesn't allow negative numbers.
Ideally, we want to use the signed / OAuth route via PayPal REST API Vs. the open / classic API.
Update 1/13/2014
I noticed Storenvy has the ability to apply discounts to their connected user's PayPal accounts. However, If I recall Storenvy has a partnership with PayPal - I'm wondering if they're on a specific internal rest API version for the discount support?
I do it creating another item, and giving a negative price.
$item = new Item();
$price = -11.20;
......
$item->setName($name)
->setCurrency($currency)
->setQuantity($quantity)
->setSku($sku)
->setPrice($price);
For this example I have a Promo code of -11.20 euro:
What worked for me:
Add a discount field to the breakdown:
'discount' => [
'currency_code' => $order->currency,
'value' => $order->coupon_total,
]
See PayPal's docs: https://developer.paypal.com/docs/api/orders/v2/#definition-amount_breakdown
The discount will the show up as discount in the price breakdown.
Make negative value of coupon discount amount. It worked for me.
$itemArray = array();
if (isset($request->couponId)) {
// coupon object
$coupon = (new Promocodes())->check($request->couponId);
if (isset($coupon->code)) {
$item = new Item();
$item->setName('Coupon Discount')
->setCurrency('GBP')
->setQuantity(1)
->setPrice(($coupon->reward * (-1)));
// to reduce reward amount from total
$totalAmount -= $coupon->reward;
array_push($itemArray, $item);
}
}
For discount we do have the discount variables discount_amount and discount_percentage where you can get:
The amount and currency of the discount applied to the payment.
See the reference https://developer.paypal.com/docs/api/payments/ and search for the term "discount" there.
I hope this helps.