Handling TAX with PayPal tax variable - php

In PHP I do a simple calculation. Where we are, tax (GST) is charged at 10%. So, What I'm doing in my php code is:
$a=$_REQUEST["amount"]; // this contains 504.95
$amount = $a*.10;
BUT, When I click "Purchase" and it takes me to PayPal, instead of showing up with order details, PayPal says:
"The link you have used to enter the
PayPal system contains an incorrectly
formatted item amount."
Here's what I've tried:
I have tried making a purchase WITHOUT tax. And it worked.
I have tried making a purchase with a value of 504 INSTEAD OF 504.95 and it worked.
So, how can I charge 10% tax on 504.95?
Here's my code:
$amnt = $_REQUEST['amount'];
$amount = $amnt*.10;
$p->add_field('tax', $amount);
Any help at all is appreciated.
Thank you
UPDATE:
Okay,
So I think I may have figured out how to get the right way to send the data, by using
number_format($price*0.10);
But, it's not calculating properly on the paypal webpage!
I have a sample item priced at $504.85, and it is supposed to be taxed 10%.
But PayPal is only charging $50 (that does not equal 10%)
What the!?

Ok cool, I've got it.
I am now using:
$amnt = $_REQUEST['amount'];
$ship = $_REQUEST['freight'];
$comb = $amnt+$ship;
$amount = $comb*0.10;
$p->add_field('tax', number_format($amount,2,'.',''));
And it works perfectly. Thanks!

Related

How to get WooCommerce cart subtotal value?

I am currently trying to make an if else check in the checkout of a WooCommerce site.
I need to know if the total is greater or less than 100, so that it will say "You need to call to negotiate a shipping fee".
The code:
$woocommerce->cart->get_cart_total()
shows the value, but adds HTML content.
I need only the value itself.
I kind of found out how to do this the hard way.
I searched google for over 2 hours and found this page: https://woocommerce.wp-a2z.org/oik_api/wc_cartget_cart_subtotal/
global $woocommerce;
$subtotal = $woocommerce->cart->get_subtotal();
$subtax = $woocommerce->cart->get_subtotal_tax();
$subtotaltax = $subtotal+$subtax;
echo with $subtotaltax shows the value with the tax added.

How do I apply multiple coupons to an account in Recurly?

Recurly Create Subscription. It doesn’t seem like they allow multiple coupons to be allowed added to the account during creation, but am I wrong? Or is there another way to add a coupon to the account subscription?
I already have multiple coupons setting in Recurly turned on, I'm just not sure how to apply them. I'm also using the PHP library if that makes any difference.
I found out you can actually create subscription with multiple coupons at once. All you need to do is organize coupon codes into comma separated list.
You must use the redeem subscription endpoint (rather than the create subscription endpoint) if you wish to apply multiple coupons
<?php
$coupon = Recurly_Coupon::get('special');
$redemption = $coupon->redeemCoupon('1', 'USD');
?>
More information here
You should work with Redeem a Coupon on an Account
Definition
https://:subdomain.recurly.com/v2/coupons/:coupon_code/redeem
PHP Examples
<?php
$coupon = Recurly_Coupon::get('special');
$redemption = $coupon->redeemCoupon('1', 'USD');
?>
Result Format
<redemption href="https://your-subdomain.recurly.com/v2/accounts/1/redemptions/316a4213e8fa9e97390aff4995bda9e6">
<coupon href="https://your-subdomain.recurly.com/v2/coupons/special"/>
<account href="https://your-subdomain.recurly.com/v2/accounts/1"/>
<subscription href="https://your-subdomain.recurly.com/v2/subscriptions/315fbd7a25b04f1333ea9f4418994fb5"/>
<uuid>316a4213e8fa9e97390aff4995bda9e6</uuid>
<single_use type="boolean">false</single_use>
<total_discounted_in_cents type="integer">0</total_discounted_in_cents>
<currency>USD</currency>
<state>active</state>
<created_at type="datetime">2015-09-23T17:13:30Z</created_at>
</redemption>

update stripe plan with incorrect amount due

I m using stripe for my payment. Everything works fine exept one thing.
I have 4 different plans : Free(0€) / free + extra (4,90€) / premium (49€) / premium + extra (53,90€).
The user can update the subsciption, like that :
// i get the $plan variable by my ajax request
$newPlan = $plan;
// i find the name of the current user's plan in my database
$payment = $em->getRepository('CacPaymentBundle:Payment')->findOneByUser($id);
$customerId = $payment->getCustomerId();
// i update my user's stripe plan
$cu = \Stripe\Customer::retrieve($customerId);
$planId = $cu->subscriptions->data[0]->id;
$subscription = $cu->subscriptions->retrieve($planId);
$subscription->plan = $newPlan;
// i update my plan in my database
$subscription->save();
$payment->setPlan($newPlan);
$em->persist($payment);
$em->flush();
Here is my probleme : In my stripe back office, the user has the right plan but the amount due is not correct.
When i update to free + extra to premium with extra, the amount due is 102€ and few cents
I don't understand why my amount is not correct and my plan is correct
Any idea is welcome :)
Thanks
Stripe calculates a percentage of the subscription with respect to time.
That's why the amount I get was not the one to which I wanted

Updating an order value with the PayPal PHP SDK

OK, I've been banging my head against this for a few days now. I'm building a payment process into a PHP application which will allow for upselling products after a customer approves a payment.
I can get the payment charged to the customer without an issue, but if they select any kind of upsell product which requires the order value to change, then I get errors even though it is following to the letter what was in the documentation I could find...
Below is the test function I'm using, this is the function which is called when the user is redirected back to the website AFTER approving the payment.
public function confirmOrder($payer_id, $payment_id, $incentives = false){
//GET PAYMENT
$payment = Payment::get($payment_id, $this->apiContext);
//CREATE EXECUTION WITH PAYER ID
$execution = new PaymentExecution();
$execution->setPayerId($payer_id);
//APPLY PAYMENT AMOUNT - Original amount was 7.00
$amount = new Amount();
$amount = $amount->setCurrency('GBP')->setTotal('8.00');
//PATCH REPLACE
$patchReplace = new Patch();
$patchReplace = $patchReplace->setOp('replace')->setPath('/transactions/0/amount')->setValue($amount);
//CREATE PATCH OBJECT
$patchRequest = new PatchRequest();
$patchRequest = $patchRequest->setPatches(array($patchReplace));
try {
$payment->update($patchRequest, $this->apiContext);
} catch (PayPalConnectionException $ex) {
return "PATCH ERROR: State(" . $payment->getState() . ") ".$ex->getData();
}
}
This isn't the final code I will use but right now I'm just trying to get an order updated before I build in more of the logic. This code gives me the following error:
PATCH ERROR: State(created) {"name":"PAYMENT_STATE_INVALID","message":"This request is invalid due to the current state of the payment","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_STATE_INVALID","debug_id":"9caacdc1d652b"}
You can see I'm outputting the getState() which is coming back as 'created' which would normally be fine for updating in everything I can find but it is still failing.
Does anyone else have experience with the PayPal PHP SDK and could help point me in the right direction?
In PayPal, once the user has approved the payment from the consent screen, the amount cannot be changed, as you can understand the user agreed to pay only the amount he/she saw on the consent screen. Modifying the amount after user approves it, is not allowed, and that's why you are seeing that state exception, as the state is already approved.
Anyway, looking at your scenario, I think you might be interested in either creating order, or capture, instead of sale.
Also, in our PayPal-PHP-SDK, there are a lot of interesting documents that could help you understand PHP-SDK better. We also provide a lot of runnable samples, that you could setup in your local machine, by one command only.

Opencart Paypal unsupported currency

Im trying to support the checkout of ZAR (South African Rand).
So far i have enabled $, this enables the paypal module however the conversion isn't being completed.
The site simply checkout to the value. Eg: R1500.00 = $1500.00 when checking out through paypal.
What is the correct way to do the currency conversion using the built in convertor?
Ok found the solution:
Taken from Opencart Forum by user Qphoria
Q: How can I use paypal if my currency isn't supported?
Q: How can I use a payment gateway that doesn't support my currency?
Q: Paypal doesn't support my currency?
A:
You are limited to what the payment gateway supports. However, you can add code to auto-convert your currency to the current exchange rate of a supported currency fairly easy.
(v1.5.x)
1. EDIT: catalog/controller/payment/.php
FIND (FIRST INSTANCE ONLY):
Code: Select all
$order_info = $this->model_checkout_order->getOrder
AFTER, ADD (Replace USD with your choice of valid currency):
Code: Select all
$order_info['currency_code'] = 'USD';
Whatever currency you choose to use, be sure you have it in your list of currencies on your store in the Admin->System->Localisation->Currency page. It doesn't need to be enabled, just has to exist so that the conversion calculation can be done.
This will then auto convert the amount before it is sent to the gateway. The customer won't likely notice this.
They will see, for example, 1000 AED on the checkout page
But you will see $272.25 USD (based on the current conversion rate) in your paypal account.
Up til 1.5.1.3, Paypal Standard did this automatically
In 1.5.2, it was changed (not for the better) to simply disable itself from the list of payments if using an unsupported currency. So that will need special instruction and maybe should be changed back in the core.
For now:
1. EDIT: catalog/model/payment/pp_standard.php
FIND AND REMOVE:
Code: Select all
if (!in_array(strtoupper($this->currency->getCode()), $currencies)) {
$status = false;
}
EDIT: catalog/controller/payment/pp_standard.php
FIND (THE FIRST INSTANCE ONLY):
Code: Select all
$order_info = $this->model_checkout_order->getOrder
AFTER, ADD:
Code: Select all
$currencies = array('AUD','CAD','EUR','GBP','JPY','USD','NZD','CHF','HKD','SGD','SEK','DKK','PLN','NOK','HUF','CZK','ILS','MXN','MYR','BRL','PHP','TWD','THB','TRY');
if (!in_array(strtoupper($this->currency->getCode()), $currencies)) {
$order_info['currency_code'] = 'USD';
}
Change "USD" with your choice of supported currency.
for opencart 2 or 3
the first step is the same
EDIT: catalog/model/extension/payment/pp_standard.php
FIND AND REMOVE:
if (!in_array(strtoupper($this->currency->getCode()), $currencies)) { $status = false; }
the second step is
at catalog/controller/extension/payment/pp_standard.php
find
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
after it ,and
$order_info['currency_code'] = 'USD';
this solution will exchange all currencies to USD and then go to paypal.com to pay

Categories