Stripe Partial refund and full refund issue - php

Here is what i am trying to do. Total is $120
1 : First i did a Partial Refund with this charge ID ch_1AfNOwAWa9KSz110***** .
\Stripe\Refund::create(array(
"charge" => 'ch_1AfNOwAWa9KSz*******',
"amount" => 60 * 100,
));
2 : After that i want to refund full the amount that left in this chargeID ch_1AfNOwAWa9KSz110*********
\Stripe\Refund::create(array(
"charge" => 'ch_1AfNOwAWa9KSz1********'
));
I am getting error Charge ch_1AfNOwAWa9KSz110********* has already been refunded.
What should i do first i did partial and after full refund in stripe.?

According to the docs:
You can optionally refund only part of a charge. You can do so
multiple times, until the entire charge has been refunded.
So it seems you can create a refund without an amount (a full refund) only if you have not refunded already (partially), otherwise you need to specify the amount explicitly.
It would be great, though, if Stripe accepted refunding without an amount specified even after a partial refund, meaning to refund the remaining amount.

Based on the docs, I think you want to use the update refund endpoint instead of the create refund endpoint for the second call.

Related

Binance API - Account has insufficient balance for requested action

While trying to place an order, I'm receiving the following error:
Code: -2010 Account has insufficient balance for requested action
I'm requesting the POST endpoint https://api.binance.com/api/v3/order with the following parameters:
$params =
[
'symbol' => 'BTCUSDT',
'side' => 'BUY',
'type' => 'MARKET',
'quoteOrderQty' => 375.00,
'timestamp' => $timestamp,
];
And I just deposit 400$, which means I have enough funds to purchase 375$ worth of BTC.
What am I missing?
I have had this before numerous times and this is why it happens.
Say you have 0.007821 worth of BTC in your Binance Wallet. And you are trying to place a SELL order. Now, if you end up rounding your quantity to say 4 decimal places, your code would try and SELL 0.0079 BTC. This is obviously more than what you have in your Exchange Wallet. This will cause the "Account has insufficient balance for requested action" error.
Solution: Simply match or reduce the amount in your code that you are trying to SELL to match the amount in your exchange Wallet. So, in this case, try and use the correct rounding decimal places or try to SELL 0.0078 worth of BTC.
I suggest you find your money and convert it to USDT if you want. Check this page using your browser https://binance.com/en/my/wallet/account/main and find what currency do you have now. Keep in mind that USD != USDT
The other option is to make sure you have enough BNB in your account to pay for the fees:
https://dev.binance.vision/t/account-has-insufficient-balance-for-requested-action/2718/6
It is because you are trying to buy 375.00 bitcoin.
quoteOrderQty must reference to the amount of symbol you want to buy.
if you want to buy btc for a percentage of your total money you should use this formula: (YourTotalMoney / CurrentPrice) * (Percentage / 100)
Example: I want to buy BTC using 50% of my USDT
Quantity = (getBalanceUSDT() / getCurrentPriceBTC()) * (50 / 100)
getBalanceUSDT() and getCurrentPriceBTC() are functions you will have to create
Now you can use Quantity for the quoteOrderQty param.

How can I retrieve the net value of a payment intent once i've stored it on Stripe php

When storing a PaymentIntent Charge on Stripe lets say for 40.00 Stripe fee is $1.46 and the balance of that is 38.54 is there a way I can retrieve this 38.54 balance i've tried selected the PaymentIntent like how it shows in the Stripe Docs but I can only retrieve the price of the charge which is $40.00 not the balance
here's what it looks like
and here's my retrieving code
$order_total = sprintf('%.2f', $stripe->paymentIntents->retrieve(
''.$paymentIntent->id.'',
[]
)['amount'] / 100);
There is no direct way to get the net amount from the API call, however, you could easily obtain both the original charge amount and the fee amount from payment_intent.
Use Stripe PaymentIntent Retrieval API
Expand the payment_intent.charges.data.balance_transaction to get the balance transaction where you can find the fee parameter
e.g.
curl https://api.stripe.com/v1/payment_intents/pi_1GmxGNxxxxxWi \
-u sk_test_uxxxxxxL: \
-d "expand[]"="charges.data.balance_transaction"
You will just need to subtract the payment_intent amount from the fee parameter to get the net amount.

Paypal Recurring Payments without One-Time Purchase

I am attempting to set up a Paypal Recurring Profile, but I keep getting the error code 10525: "This transaction cannot be processed. The amount to be charged is zero." I only want to start the recurring billing, rather than charge them a one time payment amount and then the recurring billing on top of that. ($13 every month or $135 annually are the choices).
From the paypal knowledge (https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ1441&actp=LIST) I found:
"Use BillingType=RecurringPayments/MerchantInitiatedBilling instead for creating a Recurring Profile/Billing Agreement ID with no dollar amount."
However, I have already done so.
Also, in the paypal api(https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/) I found:
"Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored."
But it is set to "0", so I'm not sure what to do there.
Here is my debug list:
2017-11-08 19:39:28 - PayPal Express debug (Call data): {
"METHOD":"SetExpressCheckout",
"MAXAMT":0,
"RETURNURL":"***",
"CANCELURL":"***",
"REQCONFIRMSHIPPING":0,
"NOSHIPPING":1,
"LOCALECODE":"EN",
"LANDINGPAGE":"Login",
"HDRIMG":"***",
"PAYFLOWCOLOR":"FFFFFF",
"CHANNELTYPE":"Merchant",
"ALLOWNOTE":"1",
"PAYMENTREQUEST_0_SHIPPINGAMT":"",
"PAYMENTREQUEST_0_CURRENCYCODE":"USD",
"PAYMENTREQUEST_0_PAYMENTACTION":"Sale",
"L_PAYMENTREQUEST_0_DESC0":"Journal Inside Pages:Unlined, Journal Theme:Mom",
"L_PAYMENTREQUEST_0_NAME0":"The Gratitude Project",
"L_PAYMENTREQUEST_0_NUMBER0":"JNL103",
"L_PAYMENTREQUEST_0_AMT0":0,
"L_PAYMENTREQUEST_0_QTY0":"1",
"L_PAYMENTREQUEST_0_ITEMURL0":"***",
"L_PAYMENTREQUEST_0_ITEMLENGTHVALUE0":"8.00000000",
"L_PAYMENTREQUEST_0_ITEMLENGTHUNIT0":"in",
"L_PAYMENTREQUEST_0_ITEMWIDTHVALUE0":"10.00000000",
"L_PAYMENTREQUEST_0_ITEMWIDTHUNIT0":"in",
"L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE0":"0.00000000",
"L_PAYMENTREQUEST_0_ITEMHEIGHTUNIT0":"in",
"PAYMENTREQUEST_0_ITEMAMT":"0.00",
"PAYMENTREQUEST_0_AMT":0,
"L_BILLINGTYPE0":"RecurringPayments",
"L_BILLINGAGREEMENTDESCRIPTION0":"1 USD every 1 day"}
2017-11-08 19:39:29 - PayPal Express debug (Result):
"TOKEN=EC%2d67C48949S6014741D&TIMESTAMP=2017%2d11%2d08T19%3a39%3a29Z&CORRELATIONID=a278368193eb9&ACK=Success&VERSION=109%2e0&BUILD=40710629"
2017-11-08 19:39:47 - PayPal Express debug (Call data):
{"METHOD":"GetExpressCheckoutDetails",
"TOKEN":"EC-67C48949S6014741D"}
2017-11-08 19:39:48 - PayPal Express debug (Result): "TOKEN=***"
2017-11-08 19:39:48 - PayPal Express debug (Call data):
{"TOKEN":"EC-67C48949S6014741D",
"PAYERID":"8CKXXNF3MR26N",
"METHOD":"DoExpressCheckoutPayment",
"PAYMENTREQUEST_0_NOTIFYURL":"***",
"RETURNFMFDETAILS":1,
"PAYMENTREQUEST_0_SHIPPINGAMT":"",
"PAYMENTREQUEST_0_CURRENCYCODE":"USD",
"PAYMENTREQUEST_0_PAYMENTACTION":"Sale",
"L_PAYMENTREQUEST_0_DESC0":"Journal Inside Pages:Unlined, Journal Theme:Mom",
"L_PAYMENTREQUEST_0_NAME0":"The Gratitude Project",
"L_PAYMENTREQUEST_0_NUMBER0":"JNL103",
"L_PAYMENTREQUEST_0_AMT0":0,
"L_PAYMENTREQUEST_0_QTY0":"1",
"L_PAYMENTREQUEST_0_ITEMURL0":"***",
"L_PAYMENTREQUEST_0_ITEMLENGTHVALUE0":"8.00000000",
"L_PAYMENTREQUEST_0_ITEMLENGTHUNIT0":"in",
"L_PAYMENTREQUEST_0_ITEMWIDTHVALUE0":"10.00000000",
"L_PAYMENTREQUEST_0_ITEMWIDTHUNIT0":"in",
"L_PAYMENTREQUEST_0_ITEMHEIGHTVALUE0":"0.00000000",
"L_PAYMENTREQUEST_0_ITEMHEIGHTUNIT0":"in",
"PAYMENTREQUEST_0_ITEMAMT":"0.00",
"PAYMENTREQUEST_0_AMT":0,
"L_BILLINGTYPE0":"RecurringPayments",
"L_BILLINGAGREEMENTDESCRIPTION0":"1 USD every 1 day"}
If I do, however, set the PAYMENTREQUEST_0_AMT to "13.00", for instance, the call goes in correctly. However the customer would double pay for their first month (total of $26). I could set a trial period for "0", but that would only fix the monthly subscription, not the annual subscription.
I am using Paypal Express (Sandbox) with Opencart 2.3.0.2
This problem is known via Opencart, but no one has fixed it. So I was attempting to fix it myself. I have not used Paypal API before so I'm not sure where to look.
"Set this field to 0 if the transaction does not include a one-time purchase...." in the link
https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/ means that "n" in the parameter "PAYMENTREQUEST_n_AMT" is set to "0" instead of you set total amount into "0".
So, "MAXAMT" and "L_PAYMENTREQUEST_0_AMT0" cannot be "0 but should be more than 0 to match your total amount.
You are request to firstly call SetExpressCheckout API (BillingType=RecurringPayments), and got response with EC token and use it in CreateRecurringPaymentsProfile API
https://developer.paypal.com/docs/classic/api/merchant/CreateRecurringPaymentsProfile_API_Operation_NVP/

paypal express checkout set paypal fee additional

I have integrate paypal express checkout in our website. as i know and get information from paypal documentation.
Need to set Amount parameter in request input and paypal deduct fee based on amount, but i want paypal add fee additional on amount.
Example :
Product amount : $100.00;
Paypal deduct fee 2.9% on $100.00 but i want add aditional 2.9% on main amount, like :
Amount = 100.00
Fee = 2.9%
Than Total amount is = $100.00 + 2.9% = $102.90
means i want paypal automatically set his fee on checkout page and charge to user.
Can anyone help me.
Thanks in Advance.
If you want to add that fee on to your order you'll need to do so prior to sending the user to PayPal, or you could also do it on your review page after the user is returned from PayPal.
Most people just add this to their cart as a "handling fee" or whatever you want to call it. If you want to be more accurate you should use the 2.9% + .30 formula.

Creating a Stripe Summary Report

I've recently switched payment processing to Stripe. I now need to create a report for our finance department that shows a rollup of transactions within a specified date range. I've started to create a simple PHP web page (and using the Stripe PHP library) that will give the following summaries:
Transaction Count
Transaction Amount
Refund Count
Refund Amount
Fees
Net
I'm having some trouble figuring out how to properly query charges with Stripe for my reporting purposes.
I know I can retrieve charges with:
$charges = Stripe_Charge::all();
And from the returned set of charges, I can compute the summary information that I need in the report. However, this will only return me a maximum of 100 charges, and I don't know how to return the charges within a specified date range.
I'm hoping more experienced Stripe developers can point me to the correct method of building the report I need.
How can I return all charges within a specified date range?
Is there a better way to get this summary information from Stripe?
You could use webhooks to be notified when a charge.succeeded or charge.refunded event occurs and store the relevant information in a database you control. That will give you flexibility to do the reporting you need. You can download charges that have already occurred as a CSV from the Stripe dashboard.
You can paginate through the charges by using the count and offset parameters (documented at https://stripe.com/docs/api?lang=php#list_charges). I would suggest using these to process 100 charges at a time. Then you can stop iterating through your charges once you get a charge beyond your date range.
I received confirmation from a Stripe employee that the only two options are in fact the ones described in the answers from #dwhalen and #Saikat Chakrabarti.
Quoting from the Stripe employee to the same question I asked on Stripe:
Other than the options you described (retrieving all charges, or
tracking in your database as charges come in) there isn't any
alternative way of producing the stats that you want there.
Realize this is old-ish, but.. this is now possible, a php example:
$charges=Stripe_Charge::all(array("created" => array("gt" => $unix_time),"limit" => 100));
You can use offset like
$return = Stripe_Charge::all(array("count" => 100, 'offset' => 0)); // set count
$return = Stripe_Charge::all(array("count" => 100, 'offset' => 100)); // set count
$return = Stripe_Charge::all(array("count" => 100, 'offset' => 200)); // set count

Categories