Add zeros (00) to array - php

I got this php code. I am new in php and this is a very simple question.
As you can see in the amount, i am getting post from a before page.
My problem is the following
If the user add 300USD then payment provider understand it as 3USD. If user insert 3000USD payment provider understand it 30USD.
I want to add two extra zeros by default. How can I do it?
$params = array(
'site_id' => '231321',
'amount' => $_POST[amount],
'currency' => $_POST[currency],
'site_login' => $current_user->user_email,
'email' => $current_user->user_email,
'external_id' => $externalid ,
);

Are you able to access the $params array before you use it in the following steps? If so, why don't you just modify the content?
$params['amount'] *= 100;
You should check though that the contents really is a number, etc.

You can multiply the amount by 100 to obtain the result.
Example
$amount = $_POST[amount] * 100;
Code
$params = array(
'site_id' => '231321',
'amount' => $_POST[amount] * 100,
'currency' => $_POST[currency],
'site_login' => $current_user->user_email,
'email' => $current_user->user_email,
'external_id' => $externalid ,
);

Related

PayPal Orders V2 payee object in Checkout-PHP-SDK fails with amount error

I am integrating PayPal Checkout which works nicely unless I include a custom payee in the order body. I tried the PayPal PHP example at https://developer.paypal.com/docs/checkout/integration-features/custom-payee/ that looks like this:
return array(
'intent' => 'AUTHORIZE',
'purchase_units' =>
array(
0 =>
array(
'amount' =>
array(
'currency_code' => 'USD',
'value' => '220.00'
)
),
array(
'payee' =>
array(
'email_address' => 'payee#email.com'
)
)
)
);
Trying to create an order will lead to this error message (which seems to be completely wrong as it complaints about fields that are neither there nor needed):
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"65a47f1e8defd","details":[{"field":"/purchase_units/1/amount","value":"","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field / parameter is missing."}],"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-MISSING_REQUIRED_PARAMETER","rel":"information_link","encType":"application/json"}]} [/var/www/web15/htdocs/retroplace/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php:215]
If I remove the portion with the payee, everything works fine. But I need the payee in the order...
Do you have PHP errors/warnings enabled? that looks like it might be bad PHP syntax
Try putting:
'payee' =>
array(
'email_address' => 'payee#email.com'
)
Within the array above (second key, in the same array as 'amount')

How to Access Transaction Array Value from IPN

I am trying to parse an IPN callback from paypal. The type of payment is adaptive, so there is an array of transactions (even though I will only have 1).
Here is a sample IPN with some fields pruned for readability:
array (
'payment_request_date' => 'Fri Jan 30 22:28:54 PST 2015',
'verify_sign' => 'removed',
'transaction[0].id_for_sender_txn' => 'removed',
'transaction[0].receiver' => 'removed',
'cancel_url' => '#pruned',
'transaction[0].is_primary_receiver' => 'false',
'pay_key' => '#removed',
'action_type' => 'PAY',
'transaction[0].id' => 'id is here',
'transaction[0].status' => 'Completed',
'transaction[0].paymentType' => 'SERVICE',
)
I am trying to access the value of 'transaction[0].id' and cannot get it to dump. I have tried basically every possible way I can think of:
$id = $_POST['transaction'][0]['id'];
$id = $_POST['transaction[0].id'];
Also tried asking the array to a var and then using that:
$id = $array->transaction[0].id;
This should give you the info you need.

php fedex set signature Label ADULT

I am working on wordpress site and using woocommerce extension http://www.woothemes.com/products/fedex-shipping-module/
I am Passing the values Signature value to adults. But it is not working
Please correct me where i am wrong
$request['RequestedShipment']['RateRequestTypes'] = $this->request_type;
$request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
$request['RequestedShipment']['SpecialServicesRequested'][] = array(
'SpecialServiceTypes' => 'SIGNATURE_OPTION',
'SignatureOptionDetail' => array(
'OptionType' => 'ADULT'
)
);
`
Do i need to change something from the from the RateService_v13.wsdl file
Please suggest
Thanks
I resolved this issue
For further user having the same issue can resolve this by below code
$item['SpecialServicesRequested'] = array(
'SpecialServiceTypes' => 'SIGNATURE_OPTION',
'SignatureOptionDetail' => array(
'OptionType' => 'ADULT'
)
);
$request['RequestedShipment']['RequestedPackageLineItems'][] = $item;
If Suppose anyone is using Fedex Integration with Laravel you may use below code.
In place of _DIRECT you may use _ADULT or any other option.
$packageLineItem1 = new FedexShipServiceCT\RequestedPackageLineItem();
$packageLineItem1
->setSequenceNumber(1)
->setItemDescription('Product')
->setSpecialServicesRequested(new FedexShipServiceCT\PackageSpecialServicesRequested(array(
'SignatureOptionDetail' => new FedexShipServiceCT\SignatureOptionDetail(array(
'OptionType' => FedexShipServiceST\SignatureOptionType::_DIRECT
))
)))
->setDimensions(new FedexShipServiceCT\Dimensions(array(
'Width' => 1,
'Height' => 1,
'Length' => 1,
'Units' => FedexShipServiceST\LinearUnits::_IN
)))
->setWeight(new FedexShipServiceCT\Weight(array(
'Value' => 1,
'Units' => FedexShipServiceST\WeightUnits::_LB
)));
Thanks

PayPal Order Summary Using REST API - - cURL or PHP

I am working with the PayPal RESTful API.
https://developer.paypal.com/webapps/developer/docs/api/
How can I pass my consumers order items and purchase description to PayPal, so when my user is redirected to PayPal to approve the order by logging in, their order summary will show up on the left.
.
.
ORDER SUMMARY ON THE LEFT
I have tried to passing in the transactions.item_list.items but that information isn't showing up in the order summary still.
Any help how to get an order summary to appear on the paypal approval page using the PayPal RESTful API?
I haven't been to pleased with their documentation as it is lacking some information and also has a few mistakes which wasted decent amount of my time to debug.
//
// prepare paypal data
$payment = array(
'intent' => 'sale',
'redirect_urls' => array(
'return_url' => $url_success,
'cancel_url' => $url_cancel,
),
'payer' => array(
'payment_method' => 'paypal'
)
);
//
// prepare basic payment details
$payment['transactions'][0] = array(
'amount' => array(
'total' => '0.03',
'currency' => 'USD',
'details' => array(
'subtotal' => '0.02',
'tax' => '0.00',
'shipping' => '0.01'
)
),
'description' => 'This is the payment transaction description 1.'
);
//
// prepare individual items
$payment['transactions'][0]['item_list']['items'][] = array(
'quantity' => '1',
'name' => 'Womens Large',
'price' => '0.01',
'currency' => 'USD',
'sku' => '31Wf'
);
$payment['transactions'][0]['item_list']['items'][] = array(
'quantity' => '1',
'name' => 'Womens Medium',
'price' => '0.01',
'currency' => 'USD',
'sku' => '31WfW'
);
//
//format payment array to pass to cURL
$CURL_POST = json_encode($payment);
your code is good. This is actually a bug that will be fixed very soon. Regarding documentation, can you share how we can make it better? I want to make sure your feedback gets passed to our documentation team.
I experienced the same issue while trying it out today. What I did was add the Items like below.
$item = new Item();
$item->setQuantity($item_quantity);
$item->setName($item_name);
$item->setPrice($item_price);
$item->setCurrency($item_currency);
$item_list = new ItemList();
$item_list->setItems(array($item));
The $item_list is a property of transaction so you should add it after.
$transaction = new Transaction();
$transaction->setItemList($item_list);
....
That should show on the Order summary pane on PayPal page.
You can also check the answer here.
Try using the sample shown here : http://htmlpreview.github.io/?https://raw.githubusercontent.com/paypal/PayPal-PHP-SDK/master/sample/doc/payments/CreatePaymentUsingPayPal.html
It is a sample that comes along with the PayPal REST API SDK. You can try those samples out yourselves, by following instructions on readme.
This is how it would look like, when you run that sample:

Limiting resultset from Magento SOAP query

How can you specify a max result set for Magento SOAP queries?
I am querying Magento via SOAP API for a list of orders matching a given status. We have some remote hosts who are taking too long to return the list so I'd like to limit the result set however I don't see a parameter for this.
$orderListRaw = $proxy -> call ( $sessionId, 'sales_order.list', array ( array ( 'status' => array ( 'in' => $orderstatusarray ) ) ) );
I was able to see that we do get data back (6 minutes later) and have been able to deal with timeouts, etc. but would prefer to just force a max result set.
It doesn't seem like it can be done using limit, (plus you would have to do some complex pagination logic to get all records, because you would need know the total number of records and the api does not have a method for that) See api call list # http://www.magentocommerce.com/api/soap/sales/salesOrder/sales_order.list.html
But what you could do as a work around is use complex filters, to limit the result set base on creation date. (adjust to ever hour, day or week base on order volume).
Also, since you are using status type (assuming that you are excluding more that just cancel order), you may want to think about getting all order and keep track of the order_id/status locally (only process the ones with the above status) and the remainder that wasn't proceed would be a list of order id that may need your attention later on
Pseudo Code Example
$params = array(array(
'filter' => array(
array(
'key' => 'status',
'value' => array(
'key' => 'in',
'value' => $orderstatusarray,
),
),
),
'complex_filter' => array(
array(
'key' => 'created_at',
'value' => array(
'key' => 'gteq',
'value' => '2012-11-25 12:00:00'
),
),
array(
'key' => 'created_at',
'value' => array(
'key' => 'lteq',
'value' => '2012-11-26 11:59:59'
),
),
)
));
$orderListRaw = $proxy -> call ( $sessionId, 'sales_order.list', $params);
Read more about filtering # http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections

Categories