Refund stripe payment - javascript

I am using the stripe connect feature. The payment feature is working fine but when I run stripe.refunds.create() method to refund the payment, though it returns successful status but the stripe dashboard does not update.
Request:
const intent = await stripe.refunds.create({
payment_intent: booking.paymentIntent,
reason: 'requested_by_customer',
});
Response:
{
id: 're_*********************',
object: 'refund',
amount: 20000,
balance_transaction: 'txn_*********************',
charge: 'ch_*********************',
created: 1670775881,
currency: 'usd',
metadata: {},
payment_intent: 'pi_*********************',
reason: 'requested_by_customer',
receipt_number: null,
source_transfer_reversal: null,
status: 'succeeded',
transfer_reversal: null
}
Dashboard:
I am new to stripe. If I am doing anything wrong please help me to find it or give me any article or doc. The stripe doc seems huge and confusing to me.

Related

Cannot charge a customer that has no active card

So I am getting the error in Stripe that "Cannot charge a customer that has no active cards".
I am using node js for this
Payment Code is given below
try {
const customer = await stripe.customers.create({
email: req.body.email,
source: req.body.id,
});
const payment = await stripe.charges.create(
{
amount: req.body.totalAmount * 100,
currency: "inr",
customer: customer.id,
receipt_email: req.body.email,
confirm: true,
off_session: true,
},
{
idempotencyKey: uuidv4(),
}
);
And I am getting the following error
type: 'StripeCardError',
raw: {
code: 'missing',
doc_url: 'https://stripe.com/docs/error-codes/missing',
message: 'Cannot charge a customer that has no active card',
param: 'card',
type: 'card_error',
}
Log out req.body.id as that might be null and then investigate why your frontend is not passing that parameter to your backend.
Second, confirm and off_session are not supported parameters on the /v1/charges endpoint.

Stripe Payments Add Payment Source / Card / Method using NodeJS / Vue

I am building a simple SaaS application with recurring payments using NodeJS with Express for the API and Vue for the UI. I have code written to add a customer and link a subscription and plan as well as a few other routines. We allow users to sign up without entering a payment method so now, I need to add a way for a user to add a payment method. I have been through so much documentation that my head is spinning and Stripe support (or lack thereof) has been no help.
I have tried everything from createSource, createToken, and createPaymentMethod in the UI and then submitted that to the API where I have tried using everything from stripeapi.customers.createSource to stripe.paymentMethods.create and nothing works. Everything returns an error about either something missing in the object or the object being incorrect. I have attempted to look at the payment intents API however, this seems like overkill to just simply add a card to a customer.
Here is my latest code.
UI : Create Element
this.stripe = await loadStripe('pk_test_');
let stripeElem = this.stripe.elements();
this.card = stripeElem.create('card', { hideIcon: true, hidePostalCode: false, style: { base: { color: '#363636', fontSize: '22px', fontSmoothing: 'antialiased' }}});
this.card.mount(this.$refs.card);
UI: Submit to API
await this.stripe.createSource(this.card, { type: 'card' } ).then((source) => {
this.$http.post(`/api/route`, source).then((response) => {
if (response.status === 200) {
} else {
}
}).catch(() => {
});
API
await stripeapi.customers.createSource(customer_id, { source: card });
This code produces this object:
{ source:
{ id: 'src_1HLFsEDfvqoM1TxYXmFvlcK9',
object: 'source',
amount: null,
card:
{ exp_month: 1,
exp_year: 2022,
last4: '4242',
country: 'US',
brand: 'Visa',
address_zip_check: 'unchecked',
cvc_check: 'unchecked',
funding: 'credit',
three_d_secure: 'optional',
name: null,
address_line1_check: null,
tokenization_method: null,
dynamic_last4: null },
client_secret: 'src_client_secret_VILuqM6ZikLzp9nMq4gizfN8',
created: 1598653002,
currency: null,
flow: 'none',
livemode: false,
metadata: {},
owner:
{ address: [Object],
email: null,
name: null,
phone: null,
verified_address: null,
verified_email: null,
verified_name: null,
verified_phone: null },
statement_descriptor: null,
status: 'chargeable',
type: 'card',
usage: 'reusable' } }
This code and object produce this error:
(node:352976) UnhandledPromiseRejectionWarning: Error: The source hash must include an 'object' key indicating what type of source to create.
at Function.generate (/data/api/node_modules/stripe/lib/Error.js:39:16)
at IncomingMessage.res.once (/data/api/docroot/node_modules/stripe/lib/StripeResource.js:190:33)
at Object.onceWrapper (events.js:286:20)
at IncomingMessage.emit (events.js:203:15)
at IncomingMessage.EventEmitter.emit (domain.js:448:20)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
All I want to do is take an element, create a payment source/method (whatever it's called) and then associate that with a customer. Any help is appreciated. I have look at so many examples but nothing has worked for me. Everything seems to produce an error about the object or what not.
After more hours of development I finally figured it out! The API reference is severely lacking but this article here explains what to do: https://stripe.com/docs/payments/save-card-without-authentication
Essentially, you create and mount the element. Then, you use the createPaymentMethod in the UI and pass the card element to it. From there, you submit the paymentMethod.id string to your API and then use strip.paymentMethods.attach to attach it to a customer by passing the paymentMethod.id and the Stripe customer ID.
Front End HTML
<div ref="card" class="credit-card"></div>
Front End Create and Mount
this.stripe = await loadStripe('pk_test_YOURKEY');
let stripeElem = this.stripe.elements();
this.card = stripeElem.create('card', { hideIcon: true, hidePostalCode: false, style: { base: { color: '#363636', fontSize: '22px', fontSmoothing: 'antialiased' }}});
this.card.mount(this.$refs.card);
Front End Create Payment Method and Submit to Back End
await this.stripe.createPaymentMethod({ type: 'card', card: this.card }).then((method) => {
this.$http.post(`/users/billing/cards`, { id: method.paymentMethod.id }).then((response) => {
}).catch(() => {
});
}).catch(() => {
});
Please note: this code is NOT complete, it's just meant to give you an example for those that have struggled like I have.
The NodeJS error message reads:
The source hash must include an 'object' key indicating what type of source to create.
It can also be found here, but I'm not certain, if not this is a bogus error message. If this should indeed apply, it would be object: 'card' instead of object: 'source'; but I don't think so.
With Stripe there sometimes is more than one way to get something done:
The source should definitely be a client-side generated card token,
but your client-side doesn't have any code that would token-ize the card.
For reference, these would have to be combined:
https://stripe.com/docs/js/tokens_sources/create_token?type=cardElement
https://stripe.com/docs/api/cards/create

Stripe Checkout session applies coupon to the one-time fee instead of the subscription

I'm following the official Stripe checkout guide for subscriptions, and specifically trying to have a checkout session for a subscription with the following features:
14 Free trial
$1 one-time fee
Coupon code that applies to the subscription
the following code snippet is typescript and creates the checkout session successfully. However when checking out, the coupon applies to the one time fee instead of the subscription.
const params: Stripe.Checkout.SessionCreateParams = {
customer_email: req.body.email,
payment_method_types: ["card"],
line_items: [
{
price: "price_HLcJok7ggz03hn",
quantity: 1,
},
{
price: "price_HLD1Vu4SyAn8uQ",
quantity: 1,
},
],
mode: "subscription",
subscription_data: {
trial_period_days: 14,
coupon: req.body.name,
},
success_url: `http://localhost:3000/success?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `http://localhost:3000/success?session_id={CHECKOUT_SESSION_ID}`,
}
const checkoutSession: Stripe.Checkout.Session = await stripe.checkout.sessions.create(
params
)
I'm following the Stripe section on adding one time fees, AND the section about adding coupons. It seems silly that the coupon code would only apply to the one time fee and not the subscription. I'd like to have the coupon work only for the subscription, not the one time fee.
https://stripe.com/docs/payments/checkout/set-up-a-subscription#adding-setup-fee
https://stripe.com/docs/payments/checkout/set-up-a-subscription#coupons
This is a screenshot of the checkout screen after the redirect from my site to Stripe:

Facebook Messenger, Temporary send message failure when sending receipt

I want to send to user my receipt with dummy data.
I use this library which simplifies message sending to Facebook.
The structure of my payload is this:
var payload = {
template_type: 'receipt',
recipient_name: '#' + user.name + ' ' + user.surname,
order_number: (new Date).getTime(),
currency: 'USD',
payment_method: 'Наличными',
order_url: 'http://www.example.com',
timestamp: (new Date).getTime() + '',
elements: [
{
title: title,
subtitle: subtitle,
quantity: 1,
price: 20,
currency: 'USD',
image_url: image_url
}
],
address: {
street_1:"Nurly tau",
street_2:"",
city:"Almaty",
postal_code:"050000",
state:"KZ",
country:"KZ"
},
summary: {
subtotal: 20,
shipping_cost: 0,
total_tax: 0,
total_cost: 20
},
adjustments: []
};
I have just filled receipt fields with simple fake data. Also, Facebook tracks the uniqueness of order_numbers of all sent recepts.
When I try to send this receipt I receive an error message:
{ message: '(#1200) Temporary send message failure. Please try again later',
type: 'OAuthException',
code: 1200,
fbtrace_id: 'BHmHRCEQUC4' }
What does this error mean? Facebook's error messages are so enigmatic?
I just had the same problem and after some fiddling I figured it out! The problem is that when you construct the timestamp using (new Date).getTime() it returns the amount of miliseconds since epoch. However, Facebook requires it to be in seconds.
I had the same problem, after a lot of tries, I figured out that the problem is with the timestamp parameter passed with the JSON payload.
I have no clue about what it could be, but it worked for me removing that. (Maybe, the timestamp should be for a moment before the API call, I don't know).

eBay Trading API addFixedPriceItem Call Error

I'm trying to make a call to addFixedPriceItem in NodeJS. I'm using the NodeJS eBay API. My code is the following:
var ebay = require('ebay-api');
ebay.ebayApiPostXmlRequest({
serviceName: 'Trading',
opType: 'AddFixedPriceItem',
devName: myDevId,
cert: myCertId,
appName: myAppId,
sandbox: true,
title: title,
params: {
'authToken': myClientAuthToken,
version: EBAY_API_VERSION,
Item: {
Country: 'EBAY-US',
Currency: 'USD',
Description: description,
ListingType: 'FixedPriceItem',
PictureDetails: picturesArray,
Quantity: '5',
StartPrice: price
},
}
}, function (error, results) {
if (error) {
console.dir(error);
process.exit(1);
}
console.dir(results);
});
Ultimately, I cannot seem to get it to call. It's not a verification issue or anything, console is stating that No Item.Country exists, and No Item.Currency exists, although I have specifically placed these in my parameters. Any clue why this would occur?
If not, how could I make a call to this in nodeJS without this API? I appreciate any help! :)
Your country code is wrong. It should be 'US' or one of the other CountryCodeType's.

Categories