I used to have a cron script that runs every week to withdraw cash from my Stripe balance to my bank account. We are now re-visiting Stripe (we left them for a diff payment processor, but we are returning back to them), and I've come to learn that the Recipients object is now deprecated. I've been unable to find a simple way to do this with the new method they are suggesting (via Connect).
This was my old code:
$stripe_bal = Stripe_Balance::retrieve();
$stripe_avail = $stripe_bal['available'][0]['amount'];
if($stripe_avail > 1) {
$transfer = Stripe_Transfer::create(array(
'amount' => $stripe_avail, // amount in cents
'currency' => 'usd',
'recipient' => 'self',
'statement_descriptor' => 'stripe balance cash out'
));
}
How do I do the same exact code above for their latest API using Connect? I'm unable to find an exact example or documentation that covers or even mentions this. I know how to do it manually on their GUI, but I'd like to automate it using their API, since it's going to be tedious to have to log in every week to clean my account. I don't want to clean it out everyday either; I want to stick to doing it once a week.
For those who are curious, I finally figured this one out. Here's how to do it using API version 2017-01-27:
$stripe_bal = \Stripe\Balance::retrieve();
$stripe_avail = $stripe_bal['available'][0]['amount'];
if($stripe_avail > 1) {
$transfer = \Stripe\Transfer::create([
'amount' => $stripe_avail, // amount in cents
'currency' => 'usd',
'destination' => 'default_for_currency',
'statement_descriptor' => 'stripe balance cash out'
]);
}
Related
I'm using Stripe's PHP SDK in a Laravel project, and I'm having a weird issue with 3d secure payments.
PHP Version : 7.4
Stripe-PHP : 7.75.0
When creating a PaymentIntent on behlaf of a connected stripe account using the stripe_account parameter, and the confirmation_method: 'manual' parameter, there's alway an error stating:
This PaymentIntent pi_XXXXXX cannot be confirmed using your publishable key because its confirmation_method is set to manual. Please use your secret key instead, or create a PaymentIntent with confirmation_method set to automatic.
This is how I created my intent:
$paymentIntentParameters = array(
'amount' => $priceAsCents,
'currency' => 'eur',
'payment_method' => $paymentMethodId,
'confirmation_method' => 'manual',
'confirm' => true,
);
$paymentIntent = StripePaymentIntent::create(
$paymentIntentParameters,
['stripe_account' => $store->stripe_token]
);
I followed everything said here: https://github.com/stripe-samples/accept-a-card-payment/tree/master/without-webhooks
I'm in a case where the webhook doesn't work for me, and where the confirmation_method: 'automatic' doesn't do the job too, because the confirmation is done on the frontend, and we only want cofirmations on the backend.
Is there any quick fix for this?
In order to perform server-side (manual) confirmation, you want to follow this doc. Specifically, instead of using handleCardPayment on the frontend, you use createPaymentMethod on the frontend, use the resulting PaymentMethod with a PaymentIntent on the backend, and then confirm on the backend. The linked doc shows the exact steps.
And for the 3d secure, you need to add handleCardPayment.
For my shopping site I have a fairy simple stripe implementation on the frontend where user hits "pay through stripe" button fills in CC details in a popup and hits proceed. If all goes well I get a token as $_POST['stripeToken'] which I process like below (for web payments)
try
{
$stripe = new Stripe();
$stripe = Stripe::make();
$customer = $stripe->customers()->create([
'email' => $_POST['email_id'],
'source' => $_POST['stripeToken']
]);
$charge = $stripe->charges()->create([
'customer' => $customer['id'],
'amount' => $total_amount, // note this is calculated again on server to prevent fraud
'currency' => 'sgd'
]);
}
catch (\Cartalyst\Stripe\Exception\CardErrorException $e)
{
return view('front.payment_error')->with('message', $e->getMessage());
}
Thing is we cannot rely on $total_amount coming from frontend form submission as user can easily spoof this amount and pay just $1 in stripe and get a token and spoof $total_amount to 1 thus getting products at whatever price he wants ,that's why I need to calculate his `$total_amount again on the server (from his cart) and use that to process stripe on the server.If that amount doesn't match what the token stands for , stripe would automatically raise an exception and prevent fraud.
So far good.. but the problem comes when dealing with API , mobile app will process stripe using their own libs. on the client side they would just send the final (for recording in db) but obviously I cannot use it to charge since that is already done on the mobile.Since these days it's very easy to change app behaviour (by patching apks) or craft custom HTTP request (postman) , server check is a must in case of payments.
So my question is how can I verify from the token the actual amount user paid
ie. reverse convert stripeToken => actual paid amount
Update:
This is what I am looking in case of Stripe
https://developer.paypal.com/docs/integration/mobile/verify-mobile-payment/
I'm currently setting a recurring paypal payment.
I'm not sure to understand when the first payment is done.
In my case, I want to first payment to be done when the user subscribe, and automaticaly renew after 3 month.
I'm not sure if the "INITAMT" parameter if the good way to do that.
Moreover, when I try to set the parameter "INITAMT" in sandbox, the résulting profile is always "PengindProfile"
Here is my parameters :
'METHOD' => 'CreateRecurringPaymentsProfile',
'TOKEN' => $token,
'PAYERID' => $payerId,
'USER' => $user,
'SIGNATURE' => $signature,
'PWD' =>$password,
'VERSION' => 74.0,
'PROFILESTARTDATE' => gmdate("Y-m-d\TH:i:s\Z"),
'DESC' => 'My subscription',
'BILLINGPERIOD' => 'Month',
'BILLINGFREQUENCY' => '3',
'AMT' => 10,
'CURRENCYCODE' => 'EUR',
'PAYERID' => XXX,
'MAXFAILEDPAYMENTS' => 3,
'INITAMT' => 10
And a finale question, how does the reccuring Payment works ? Paypal send the money on my account each 3 month ? It is possible to get a notification on a PHP serveur to update the subscription status ?
Thanks for your help !
I'd definitely look into using the PayPal PHP SDK instead of trying to use their REST API directly or via some minimal library. Their SDK provides much convenience working with the service and has plenty of use-case based examples including recurring billing and subscriptions.
I'm trying to tame the PayPal API with moderate success. I use PHP for sending the request and processing the response. So far I've managed to compose a valid array containing the request parameters and send it to the Paypal for validation. The request goes through validation and returns transaction token as expected. Here's my array:
$requestParams = array(
'RETURNURL' => 'http://www.myurl.com/#success',
'CANCELURL' => 'http://www.myurl.com/#cancel',
'PAYMENTREQUEST_0_AMT' => 30,
'PAYMENTREQUEST_0_SHIPPINGAMT' => '10',
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
'PAYMENTREQUEST_0_ITEMAMT' => '20',
'ALLOWNOTE' => 1,
'L_PAYMENTREQUEST_0_NAME1' => 'Black kitten',
'L_PAYMENTREQUEST_0_DESC1' => 'Nice and fluffy cute guy',
'L_PAYMENTREQUEST_0_QTY1' => '1',
'L_PAYMENTREQUEST_0_AMT1' => '10',
'L_PAYMENTREQUEST_0_NAME0' => 'Ginger kitten',
'L_PAYMENTREQUEST_0_DESC0' => 'Super cute ginger dude',
'L_PAYMENTREQUEST_0_QTY0' => '1',
'L_PAYMENTREQUEST_0_AMT0' => '10'
);
THE QUESTION
I want to send the same request but to form a recurring payment. Which means I want to charge the user's PayPal account every month. I was surfing throught PayPal API docs, but the way it's written seems super confusing for me and provides no answers whatsoever.
Maybe I should just insert another parameter to the $requestParams or maybe I should compose a completely different array or what? Please assist!
I actually just wrote an article about this a few days ago. It's a pretty quick run-through of the process so if you have more questions let me know, but I'd definitely recommend taking a look as it lays out everything you'll need to do, and it does it with my class library which makes this all very simple for you.
One of the way to implement recurring payment is using Express Checkout with creation of Billing Agreement and Reference Transactions. You can find details in official documentation here and here.
I am trying to integrate Pin.net.au CC processing into my site. I am using Omnipay library to make the calls.
To not store CC details in my server, I am using the Pin.js token method.
On form submit page (after user fills in personal and CC details) javascript does a 'prevent default' and sends the data from forms (browser) straight to pin.net.au servers. Server sends a card_token in response and resubmits the form to my server.
This token is recieved successfully and I can output it in my tests.
I get into trouble when I take that token and send a purchase request to pin.net.au. According to the API docs, I need not send user and card details when I send the token (the entire point of the token, really). I send this token along with other compulsory bits like email, amount, description etc.
This works when I cURL on my terminal and I get a charge success.
However, sending this purchase/charge request using the Omnipay library, each time I get a 422 (invalid resource) that asks for the user details and CC information. It should have populated this stuff from the token I sent.
I have scoured the API docs of both Omnipay and Pin.net.au. I don't seem to be doing anything wrong. What am I missing?
Here's my charge request:
$gateway = GatewayFactory::create('Pin');
$gateway->setSecretKey('MY_SECRET_KEY');
$response = $gateway->purchase([
'email' => 'user#email.com',
'description' => 'Package',
'amount' => '99',
'currency' => 'AUD',
'card_token' => Input::get('card_token'),
'ip_address' => Input::get('ip_address')
])->send();
Finally, it shouldn't really matter but if you'd like to know, I'm using Laravel 4.
Your example request has an amount of 99, the minimum amount for a Pin Payments charge is $1 (amount = 100).
I don't think this is the problem you are referring to though, it looks like Omnipay does not support using the card_token gear. If you go look over here - https://github.com/adrianmacneil/omnipay/blob/master/src/Omnipay/Pin/Message/PurchaseRequest.php#L34 - you can see Omnipay isn't sending the card_token field with it's request, it only tries to send card details, which obviously aren't present from your example!
Perhaps you could get in touch with the Omnipay developers or write a pull request yourself!
This is fixed in Omnipay v1.0.4 - you should be able to use the token like this:
$gateway = GatewayFactory::create('Pin');
$gateway->setSecretKey('MY_SECRET_KEY');
$response = $gateway->purchase([
'description' => 'Package',
'amount' => '99.00',
'currency' => 'AUD',
'token' => Input::get('token'),
'ip_address' => Input::get('ip_address'),
'card' => ['email' => 'user#email.com'],
])->send();