Is it possible to trigger recurring payments (subscriptions / billing agreements) using checkout.js?
If so, can you please provide a working example?
Yes its possible. I just created a POC for this.
Create a BillingPlan and activate it
plan = Plan.new(PlanAttributes)
plan.create
patch = Patch.new
patch.op = "replace"
patch.path = "/";
patch.value = { :state => "ACTIVE" }
plan.update( patch )
inside the payment function of paypal.Button call your server to create a BillingAgreement. The user will then authorize the payment.
agreement = Agreement.new(agreement_attributes)
agreement.plan = Plan.new( :id => "<the_plan_id>" )
agreement.create
inside the onAuthorize function of paypal.Button call your server to execute the BillingAgreement
agreement.execute
Following the example in
Checkout https://github.com/chibeepatag/paypal_poc
Related
i installed the .net sdk of paypal and created an app in sandbox environment
next i picked up the clientId and secret and used the following sample code to make a payment.
static void Main(string[] args)
{
// Get a reference to the config
var config = ConfigManager.Instance.GetProperties();
// Use OAuthTokenCredential to request an access token from PayPal
var accessToken = new OAuthTokenCredential(config["clientId"], config["clientSecret"]);
var apiContext = new APIContext(accessToken.GetAccessToken());
var payment = Payment.Create(apiContext, new Payment
{
intent = "sale",
payer = new Payer
{
payment_method = "paypal"
},
transactions = new List<Transaction>
{
new Transaction
{
description = "Test",
invoice_number = "009",
amount = new Amount
{
currency = "EUR",
total = "41.00",
details = new Details
{
tax = "0",
shipping = "0",
subtotal = "40",
handling_fee = "1"
}
},
item_list = new ItemList
{
items = new List<Item>
{
new Item
{
name = "Room 12",
currency = "EUR",
price = "10",
quantity = "4",
}
}
}
}
},
redirect_urls = new RedirectUrls
{
return_url = "https://google.de/",
cancel_url = "https://google.de/"
}
});
}
in the transaction i have to pass Tax information.
Is there was that i let paypal calculate the tax and i just pass amount information along with address and some other information if required ?
No, you must calculate the tax yourself.
By default the user will be able to select their shipping address at PayPal, which is recommended as this saves them from having to type it manually. Given that their address can change during the PayPal checkout, you may wish to calculate a new tax amount and/or shipping amount based on the selected address. You can do this using the JS SDK's onShippingChange callback.
Firstly, though, it appears you may be using a deprecated SDK and deprecated v1/payments API, and also a redirect away from your site to PayPal, all of which is old. Don't do any of this.
Instead: follow the PayPal Checkout integration guide and make 2 routes on your server, one for 'Create Order' and one for 'Capture Order' (see the optional step 5 in 'Add and modify the code'). Both of these routes should return only JSON data (no HTML or text). There is a Checkout-Java-SDK you can use, or integrate with your own direct HTTPS API calls (obtain an access_token first, it can be cached but expires in 9 hours).
Inside the 2nd capture route on your server, when the capture API call is successful you should store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, which is the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) immediately before forwarding your return JSON to the frontend caller.
Pair those 2 routes with the frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
Is it possible to allow partial payments using the PayPal Invoicing SDK?
I have tried setting the allowPartialPayments attribute to true on the InvoiceType object(see below) although once the invoice has been received there is no option to change the amount being paid.
InvoiceItemListType itemList = new InvoiceItemListType(invoiceItemList);
InvoiceType invoice = new InvoiceType(_MerchantEmailAddress, payerEmailAddress, itemList, "GBP");
invoice.number = brightStartInvoiceId.ToString();
invoice.merchantMemo = brightStartChildId.ToString();
invoice.allowPartialPayments = true;
CreateAndSendInvoiceRequest requestCreateAndSendInvoice = new CreateAndSendInvoiceRequest(envelopeRequest, invoice);
I need to refund payment to a customer on behalf of a third party. I have studied permission APIs how to get access token and verification code to use it in authentication API to generate signature and timestamp. But after this i am still confused as to how to use this in Refund API. Currently this is my refund paypal code
CallerServices caller = new CallerServices();
APIProfile profile = ProfileFactory.createSignatureAPIProfile();
if(Configuration.getProperty("PaypalEnvironment").equals("sandbox"))
{
profile.setAPIUsername(Configuration.getProperty("PaypalAPIUsername"));
profile.setAPIPassword(Configuration.getProperty("PaypalAPIPassword"));
profile.setSignature(Configuration.getProperty("PaypalSignature"));
profile.setEnvironment(Configuration.getProperty("PaypalEnvironment"));
caller.setAPIProfile(profile);
}
RefundTransactionRequestType pprequest = new RefundTransactionRequestType();
if ((amount != null && amount.length() > 0)
&& (refundType.equals("Partial"))) {
BasicAmountType amtType = new BasicAmountType();
amtType.set_value(amount);
amtType.setCurrencyID(CurrencyCodeType.fromString(currencyCode));
pprequest.setAmount(amtType);
}
pprequest.setVersion("63.0");
pprequest.setTransactionID(transactionId);
pprequest.setMemo(note);
pprequest.setRefundType(RefundType.fromString(refundType));
RefundTransactionResponseType ppresponse = (RefundTransactionResponseType) caller
.call("RefundTransaction", pprequest);
In this code how do i embed the signature?
For refund it is simple. Once you get the request token and verification code that's it. You don't need to pass this to refund API. All you have to above is just add this line
profile.setSubject(emailid);
and it then it gets refunded.
Can anyone tell me how to automatically execute a delayed payment (let's say it's 5 days after the primary receiver receive the payment) in a chained payment manner? The key is automatic execution, not having to manually approve and pay the secondary receiver. Please illuminate with some sample code.
I have used "actionType" => "PAY_PRIMARY" so that primary receiver get money.
But how can I code so that secondary receiver get money?
Check this answer for the solution. Basically you just need to execute an ExecutePayment operation with the payKey within 90 days to send the payment to the secondary party.
actionType is PAY_PPRIMARY
you then trigger this payment within 90 days.
Its delayed but not time-elapsed.
https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_AdaptivePayments.pdf
well may be its too late but it will help someone in future for sure.
As we integrated paypal delayed chained payment, you can set a primary account in which all the amount will go and you can also set secondary account in which account will be transfered once they approved by primary account holder.
string endpoint = Constants_Common.endpoint + "Pay";
NVPHelper NVPRequest = new NVPHelper();
NVPRequest[SampleNVPConstant.requestEnvelopeerrorLanguage] = "en_US";
//NVPRequest[SampleNVPConstant.Pay2.actionType] = "PAY";
//the above one is for simple adoptive payment payment
NVPRequest[SampleNVPConstant.Pay2.actionType] = "PAY_PRIMARY";
//the above one for deleayed chained payment
NVPRequest[SampleNVPConstant.Pay2.currencyCode] = "USD";
NVPRequest[SampleNVPConstant.Pay2.feesPayer] = "EACHRECEIVER";
NVPRequest[SampleNVPConstant.Pay2.memo] = "XXXXXXXX";
Now we have to set primary and secondary receivers:
//primary account
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveramount_0] = TotalAmount;
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveremail_0] = "XXXx.xxxxx.com";
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiverprimary_0] = "true";
//secondary accounts
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveramount_1] = (somemoney out of total amount);
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveremail_1] = "xxxxx.xxxx.com";
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiverprimary_1] = "false";
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveramount_2] = (somemoney out of total amount);
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveremail_2] = x.x.com;
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiverprimary_2] = "false";
Don't forget that you have to give a valid paypal account while using delayed chained payment.
Now you get your pay_key which you have to use to execute your payment whithin 90 days so that other secondary receivers get money.
Here is the working code:
String endpoint = Constants_Common.endpoint + "ExecutePayment";
NVPHelper NVPRequest = new NVPHelper();
//requestEnvelope.errorLanguage is common for all the request
NVPRequest[SampleNVPConstant.requestEnvelopeerrorLanguage] = "en_US";
NVPRequest[SampleNVPConstant.ExecutePayment.payKey] = "your pay key";
string strrequestforNvp = NVPRequest.Encode();
//calling Call method where actuall API call is made, NVP string, header value adne end point are passed as the input.
CallerServices_NVP CallerServices = new CallerServices_NVP();
string stresponsenvp = CallerServices.Call(strrequestforNvp, Constants_Common.headers(), endpoint);
//Response is send to Decoder method where it is decoded to readable hash table
NVPHelper decoder = new NVPHelper();
decoder.Decode(stresponsenvp);
if (decoder != null && decoder["responseEnvelope.ack"].Equals("Success") && decoder["paymentExecStatus"].Equals("COMPLETED"))
{
//do something
}
Hope it will help someone.
I'm using Paypal Express Checkout system on my website. But I want to put a coupon (discount) code area. It will make a reduction if code is true. (Like GoDaddy.com's cart system)
Have you any idea, where should I start for this?
(I'm not using any eCommerce framework)
I know this is an old thread but wanted to put here my experience for others looking for the same thing, and maybe this did not apply then but it does apply now, at least on the sandbox meaning I have not tested this in a real transaction
When adding items that you send to paypal you basically send this
L_PAYMENTREQUEST_0_QTY0 = 1
L_PAYMENTREQUEST_0_AMT0 = 1.00
L_PAYMENTREQUEST_0_NAME0 = my item 0 name
L_PAYMENTREQUEST_0_NUMBER0 = myitem0id
Then we add another item
L_PAYMENTREQUEST_0_QTY1 = 1
L_PAYMENTREQUEST_0_AMT1 = 1.00
L_PAYMENTREQUEST_0_NAME1 = my item 1 name
L_PAYMENTREQUEST_0_NUMBER1 = myitem1id
And now we add the coupon
L_PAYMENTREQUEST_0_QTY2 = 1
L_PAYMENTREQUEST_0_AMT2 = -0.50
L_PAYMENTREQUEST_0_NAME2 = my coupon name
L_PAYMENTREQUEST_0_NUMBER2 = mycouponcode
And then we add the subtotal and total values
PAYMENTREQUEST_0_AMT = 1.50
AMT = 1.50
What I think paypal does is ads up all item totals so it would do for this order something like
1.00+1.00-0.50 = 1.50
Then compares it to your total amounts
if they match then it is a go, the customer sees this as an extra item, but obviously with the minus sign, this picture below is from a paypal sandbox express checkout transaction
One approach is to have a shopping cart on your site where the user can enter a promo code. Once they've entered their promo codes, and are ready to begin the checkout process, this is when you redirect them to the Express Checkout (where you send Paypal the final amount of your order, etc).
According to this post on Paypal forum, they do not have a feature to pass the discount details to the checkout process: https://www.x.com/thread/39681 ("With express checkout all discount calculations will need to be done on your site.")
How to calculate before sending price to paypal
1) Add a SEPARATE form for the promo code to your page:
<form method="GET">
<input type="text" name="promocode">
<input type="submit" value="Add Promo">
</form>
2) On the server side, check the code, update the page accordingly with new prices (e.g. re-build your select menu with new prices). Example with PHP:
<?
if(isset($_GET('promocode')) {
$prices = processPromo($_GET('promocode'));
}
else {
$prices = array(2000, 4000, 6000);
}
?>
If you don't have access to the server, you would have to do this with JavaScript I guess (i.e. have your promo-code and price hard-coded into the page)
To initiate express checkout on server side
Download PHP NVP SDK & examples from Paypal's website:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/library_download_sdks
<?php
require_once 'CallerService.php';
session_start();
ini_set('session.bug_compat_42',0);
ini_set('session.bug_compat_warn',0);
/* Gather the information to make the final call to
finalize the PayPal payment. The variable nvpstr
holds the name value pairs
*/
$token =urlencode( $_SESSION['token']);
$paymentAmount =urlencode ($_SESSION['TotalAmount']);
$paymentType = urlencode($_SESSION['paymentType']);
$currCodeType = urlencode($_SESSION['currCodeType']);
$payerID = urlencode($_SESSION['payer_id']);
$serverName = urlencode($_SERVER['SERVER_NAME']);
$nvpstr='&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTACTION='.$paymentType.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currCodeType.'&IPADDRESS='.$serverName ;
/* Make the call to PayPal to finalize payment
If an error occured, show the resulting errors
*/
$resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);
/* Display the API response back to the browser.
If the response from PayPal was a success, display the response parameters'
If the response was an error, display the errors received using APIError.php.
*/
$ack = strtoupper($resArray["ACK"]);
if($ack != 'SUCCESS' && $ack != 'SUCCESSWITHWARNING'){
$_SESSION['reshash']=$resArray;
$location = "APIError.php";
header("Location: $location");
}
?>