Need Your Advise on Recurring Payments With Paypal API on PHP - php

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.

Related

How to withdraw Stripe balance to own bank account using API?

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'
]);
}

First payment for reccuring payment on Paypal

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.

IPN Listener is not returning Variables in response: Sandbox

I have a working application that makes payments via adaptive chained payments. This works fine, however I'm now implementing an IPN Listener to handle refunds. I'm testing in the sandbox.
I've confirmed that when a refund is made in PayPal directly the IPN Listener gets a refund message however I don't see any of the Variables that the document talks about regarding refund amounts.
The response I see is in the post data is:
11/Mar/2015:09:33:01] (ipn_handler) [-1-] : POST
array (
'transaction' =>
array (
0 => 'NONE',
1 => 'Refunded',
),
'log_default_shipping_address_in_transaction' => 'false',
'action_type' => 'PAY',
'ipn_notification_url' => 'http://example.com/paypal/ipn_handler.php',
'charset' => 'windows-1252',
'transaction_type' => 'Adjustment',
'notify_version' => 'UNVERSIONED',
'reason_code' => 'Refund',
'cancel_url' => 'http://example.com/paymentCancel.php',
'verify_sign' => 'AFcWxxxxxxxxxxxxxxxxxxxxwy5O5OqOKKa.xxxx',
'sender_email' => 'zakbuyer#gmail.com',
'fees_payer' => 'EACHRECEIVER',
'return_url' => 'http://example.com/paymentSuccess.php',
'memo' => 'purchase of item Gear Shift cufflink',
'reverse_all_parallel_payments_on_error' => 'false',
'pay_key' => 'AP-5KHxxxxxxxxxxxxxxx',
'status' => 'COMPLETED',
'test_ipn' => '1',
'payment_request_date' => 'Thu Mar 05 01:09:00 PST 2015',
)
I was expecting to find mc_gross and mc_currency etc.
With the data provided I can look up the transaction no problem but I can't handle if a partial refund is done.
I'm finding my information at https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/
When working with Adaptive Payments there are actually two separate IPN listeners that need to be acknowledged.
The value that you're setting in the IPNNotificationURL parameter of your Adaptive Payments API requests is an application specific IPN. The data sent to that listener is data that an application owner might want to help track transactions that are getting run through their app, but this data is very limited in terms of actual transaction details.
To get the parameters you're expecting, IPN would need to be configured in the seller account (in this case, the refunder's account). Then when the refund takes place PayPal would send an IPN to that listener with the parameters you're expecting to see.

Venmo - Braintree payment - Server Integration

Using Venmo Touch, I'd client side validation and post the encrypted credit card details to our application server.
Application server retrieves the params inside the post method, and posts the retrieved params to Braintree server.
<?php $result = Braintree_Transaction::sale(array(
'amount' => '10.00',
'credit_card' => array(
'number' => $_POST['encrypted_card_number'],
'expirationMonth' => $_POST['encrypted_expiration_month'],
'expirationYear' => $_POST['encrypted_expiration_year']
),
'options' => array(
'venmo_sdk_session' => $_POST['venmo_sdk_session']
)));?>
If we ignore the 'options' tag, payment is successful. Upon introducing the 'options' array with element venmo_sdk_session Braintree server doesn't responds.
I'd doubt the key spelling/case sensitive "venmo_sdk_session".
Problem is not within the code.
We need to enable Venmo Touch, Payment Method Verification on settings screen of Braintree site using our account.

Creating a coupon via API

Currently when attempting a coupon (POST) at resource "/coupon.json" we are getting the following return JSON:
Response Code:
{"status":400,"message":"The field 'id' cannot be written to. Please remove it from your request before trying again."}
The "ID" field is obviously no where in our code but we are still receiving this error.
In to this addition we thought it might be from the "applies_to" as that object resource contains an "ids" element but we disabled that and still received the same effect.
At this time it is our best guess that this is a bug on the server side that is registering incoming JSON for the coupon resource with an "ID" point on it.
Question: Is creating a coupon currently possible?
It is possible to create coupons. I got it working both from a php script and using the developer playground at https://developer.bigcommerce.com/console
$coupon = array('name' => 'FJKDJFKD', 'type' => 'percentage_discount', 'amount' => 50.0, 'code' => 'JFKDFE', 'enabled' => true, 'applies_to' => array('entity' => 'products', 'ids' => array(32)), 'shipping_methods' => array());
print_r($coupon);
Screenshots from the playground -

Categories