I am really getting confused with BillingFrequency , BillingPeriod , TotalBillingCycles , What i am trying to achive is set up monthly billing for 12 months.
$paymentBillingPeriod = new BillingPeriodDetailsType();
$paymentBillingPeriod->BillingFrequency = "1"; //can not be more than a year
$paymentBillingPeriod->BillingPeriod = "Year";
$paymentBillingPeriod->TotalBillingCycles ="12";
$paymentBillingPeriod->Amount = new BasicAmountType($currencyCode, 18); // GET Amount from Session
$paymentBillingPeriod->ShippingAmount = new BasicAmountType($currencyCode, "0");
$paymentBillingPeriod->TaxAmount = new BasicAmountType($currencyCode, "0");
This is the error response from API
Billing period must be one of Day, Week, SemiMonth, or Year Billing
frequency must be > 0 and be less than or equal to one year
What i am doing wrong ?
Source
$currencyCode = "USD";
$billingStartDate = date("Y-m-d\TH:i:s\Z");
$subscriberName = "Name";// Session var
$token = "" ; //
$amount = "10.00"
$RPProfileDetails = new RecurringPaymentsProfileDetailsType();
$RPProfileDetails->SubscriberName = $subscriberName;
$RPProfileDetails->BillingStartDate = $billingStartDate;
$activationDetails = new ActivationDetailsType();
$paymentBillingPeriod = new BillingPeriodDetailsType();
$paymentBillingPeriod->BillingFrequency = '12';
$paymentBillingPeriod->BillingPeriod = 'Month';
$paymentBillingPeriod->Amount = new BasicAmountType($currencyCode, $amount);
$paymentBillingPeriod->ShippingAmount = new BasicAmountType($currencyCode, 0.0);
$paymentBillingPeriod->TaxAmount = new BasicAmountType($currencyCode, 0.0);
$scheduleDetails = new ScheduleDetailsType();
$scheduleDetails->Description = "This is recurring payment";
$scheduleDetails->ActivationDetails = $activationDetails;
$createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
$createRPProfileRequestDetail->Token = $token;
$createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
$createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
$createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
$createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
$createRPProfileReq = new CreateRecurringPaymentsProfileReq();
$createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
$paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
try {
/* wrap API method calls on the service object with a try catch */
$createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
} catch (Exception $ex) {
include_once("Error.php");
exit;
}
Responce
Ack :
Failure
ProfileID :
PayPal\PayPalAPI\CreateRecurringPaymentsProfileResponseType Object
(
[CreateRecurringPaymentsProfileResponseDetails] => PayPal\EBLBaseComponents\CreateRecurringPaymentsProfileResponseDetailsType Object
(
[ProfileID] =>
[ProfileStatus] =>
[TransactionID] =>
[DCCProcessorResponse] =>
[DCCReturnCode] =>
)
[Timestamp] => 2015-10-07T09:14:22Z
[Ack] => Failure
[CorrelationID] => 1d7177ca754
[Errors] => Array
(
[0] => PayPal\EBLBaseComponents\ErrorType Object
(
[ShortMessage] => Invalid billing period.
[LongMessage] => Billing period must be one of Day, Week, SemiMonth, or Year
[ErrorCode] => 11518
[SeverityCode] => Error
[ErrorParameters] =>
)
[1] => PayPal\EBLBaseComponents\ErrorType Object
(
[ShortMessage] => Invalid billing frequency
[LongMessage] => Billing frequency must be > 0 and be less than or equal to one year
[ErrorCode] => 11516
[SeverityCode] => Error
[ErrorParameters] =>
)
[2] => PayPal\EBLBaseComponents\ErrorType Object
(
[ShortMessage] => Invalid amount
[LongMessage] => Bill amount must be greater than 0
[ErrorCode] => 11519
[SeverityCode] => Error
[ErrorParameters] =>
)
)
[Version] => 106.0
[Build] => 000000
)
It will work if you modified the BillingFrequency and BillingPeriod combination and leave all the rest parameters as below,
$paymentBillingPeriod = new BillingPeriodDetailsType();
//$paymentBillingPeriod->BillingFrequency = $_REQUEST['billingFrequency'];
//$paymentBillingPeriod->BillingPeriod = $_REQUEST['billingPeriod'];
$paymentBillingPeriod->BillingFrequency = "12";
$paymentBillingPeriod->BillingPeriod = "Month";
$paymentBillingPeriod->TotalBillingCycles = $_REQUEST['totalBillingCycles'];
$paymentBillingPeriod->Amount = new BasicAmountType($currencyCode, $_REQUEST['paymentAmount']);
$paymentBillingPeriod->ShippingAmount = new BasicAmountType($currencyCode, $_REQUEST['paymentShippingAmount']);
$paymentBillingPeriod->TaxAmount = new BasicAmountType($currencyCode, $_REQUEST['paymentTaxAmount']);
In your case, the explanation would be (you may find the same in the code comments right above the lines you've modified):
BillingFrequency: "How many periods you want to charge the customer"
BillingPeriod: "Define your unit of period"
TotalBillingCycles: "Optional in this case, as the combiniation of the above 2 cannot exceed one year"
*Be noted that the SDK sample invokes the CreateRecurringPaymentsProfile API with form data posted from merchant-sdk-php/samples/RecurringPayments/CreateRecurringPaymentsProfile.html.php, so if you'd like to customized your own payload function, please make sure all the mandatory paramerters are passed.
Refer to the API Specs Here, look for all the "(Required)" parameters in the description, and cross-check with your codes.
Judging by the documentation from paypal;
https://developer.paypal.com/docs/classic/api/merchant/CreateRecurringPaymentsProfile_API_Operation_NVP/
Your variables should be looking like;
$paymentBillingPeriod->BillingFrequency = "12"; //can not be more than a year
$paymentBillingPeriod->BillingPeriod = "Month";
This is because the period of payment is monthly and the frequency is 12, which rounds to 1 year.
As per the documentation quote;
The combination of billing frequency and billing period must be less than or equal to one year. For example, if the billing cycle is Month, the maximum value for billing frequency is 12. Similarly, if the billing cycle is Week, the maximum value for billing frequency is 52.
Edit
Doing it this way means you can omit the TOTALBILLINGCYCLES value, which cleans up the code as you have one less line to contend with.
Related
I use this code to retrieve product quantity by given id
$stockItem = $objectManager->get('\Magento\CatalogInventory\Model\Stock\StockItemRepository');
$productId = 10858;
$productStock = $stockItem->get($productId);
$productStock->getData();
This code work and return this results
array (
'item_id' => '10858',
'product_id' => '10962',
'stock_id' => '1',
'qty' => '0.0000',
'min_qty' => '0.0000',
...
)
But I need to retrieve information by stock_id = 2 instead of default stock (id: 1)
There's a way to do this, using this code?
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productId = 1;
$StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
$product_qty = $StockState->getStockQty($productId);
I'm having troubles with the PayPal callback feature, i can't for the life of me get it to work at all. I have double checked the callback URL path, it's correct. When the user logs into paypal, it always just returns the default shipping rate. I'm just really not sure what i am missing here, if anyone can help out. Also, i have the callback timeout set to 6, though it seems it only takes about 3 - 4 seconds for it to fail and return the default shipping rate.
I've followed the documentation here https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECInstantUpdateAPI/ and applied it to my website. I've also made sure i am logged into sandbox too.
SetExpressCheckout params:
// SetExpressCheckout
$params = array (
'METHOD' => 'SetExpressCheckout',
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
'VERSION' => $version, // 124.0
'USER' => $paypal_user,
'PWD' => $paypal_password,
'SIGNATURE' => $signature,
'L_SHIPPINGOPTIONNAME0' => 'Flat',
'L_SHIPPINGOPTIONLABEL0' => 'N/A',
'L_SHIPPINGOPTIONAMOUNT0' => '6.99',
'L_SHIPPINGOPTIONISDEFAULT0' => 'true',
'PAYMENTREQUEST_0_INSURANCEOPTIONSOFFERED' => 'false',
'PAYMENTREQUEST_0_SHIPPINGAMT' => $shipping_default, // 6.99
'PAYMENTREQUEST_0_ITEMAMT' => $cart_total,
'PAYMENTREQUEST_0_AMT' => $cart_total + $shipping_default,
'MAXAMT' => $cart_total + 30, // 30 is the total possible shipping amount
'PAYMENTREQUEST_0_CURRENCYCODE' => $paypal_currency, // AUD
'RETURNURL' => $paypal_return,
'CANCELURL' => $paypal_cancel,
'CALLBACK' => 'HTTP://localhost/moes/php/paypal_callback_php.php',
'CALLBACKTIMEOUT' => 6,
'CALLBACKVERSION' => '61.0',
'ALLOWNOTE' => 1,
'PAYMENTREQUEST_0_INVNUM' => '123' /*$invoice_number*/,
'PAYMENTREQUEST_0_TAXAMT' => $tax, // 0.00
);
// List each product and add to exress check-out array
foreach ($paypal_products as $k => $product){
$params["L_PAYMENTREQUEST_0_NAME$k"] = $product['name'];
$params["L_PAYMENTREQUEST_0_AMT$k"] = number_format($product['price'],2);
$params["L_PAYMENTREQUEST_0_QTY$k"] = $product['qty'];
$params["L_PAYMENTREQUEST_0_NUMBER$k"] = $product['code'];
$params["L_PAYMENTREQUEST_0_DESC$k"] = '1';
/* Optional shipping options to calculate shipping costs on callback
Option weight (L_PAYMENTREQUEST_n_ITEMWEIGHTVALUEm, L_PAYMENTREQUEST_n_ITEMWEITHTUNITm)
Option height (L_PAYMENTREQUEST_n_ITEMHEIGHTVALUEm, L_PAYMENTREQUEST_n_ITEMHEIGHTUNITm)
Option length (L_PAYMENTREQUEST_n_ITEMLENGTHVALUEm, L_PAYMENTREQUEST_n_ITEMLENGTHUNITm)
Option width (L_PAYMENTREQUEST_n_ITEMWIDTHVALUEm, L_PAYMENTREQUEST_n_ITEMWIDTHUNITm)*/
}
Callback script:
<?php
// Populate variables into local variables
$method = $_POST['METHOD'];
$version = $_POST['CALLBACKVERSION'];
$token = $_POST['TOKEN'];
$currencycode = $_POST['CURRENCYCODE'];
$localecode = $_POST['LOCALECODE'];
$street = $_POST['SHIPTOSTREET'];
$street2 = $_POST['SHIPTOSTREET2'];
$city = $_POST['SHIPTOCITY'];
$state = $_POST['SHIPTOSTATE'];
$country = $_POST['SHIPTOCOUNTRY'];
$zip = $_POST['SHIPTOZIP'];
// Setting shipping rate based on country [Test only]
if ($country == "US"){
echo "METHOD=CallbackResponse&OFFERINSURANCEOPTION=false&L_SHIPPINGOPTIONNAME0=FLat&L_SHIPPINGOPTIONLABEL0=N/A&L_SHIPPINGOPTIONAMOUNT0=10.00&L_TAXAMT0=1.00&L_INSURANCEAMOUNT0=9.00&L_SHIPPINGOPTIONISDEFAULT0=true";
} else {
echo "METHOD=CallbackResponse&OFFERINSURANCEOPTION=false&L_SHIPPINGOPTIONNAME0=FLat&L_SHIPPINGOPTIONLABEL0=N/A&L_SHIPPINGOPTIONAMOUNT0=30.00&L_TAXAMT0=1.00&L_INSURANCEAMOUNT0=9.00&L_SHIPPINGOPTIONISDEFAULT0=true";
}
?>
I'm guessing i missing something fundamental here, or i'm going about it completely the wrong way.
The solution to my problem was :
localhost/moes/php/paypal_callback_php.php
Obviously PayPal can't send a HTTP request to 'localhost'. My WAMP server is not configured to be accessible over the internet.
I use api classic and operation TransactionSearch and GetTransactionDetails for searches transaction
$transactionSearchRequest = new TransactionSearchRequestType();
$transactionSearchRequest->StartDate = Utils::DateConvert($start_date);
$transactionSearchRequest->EndDate = Utils::DateConvert($start_date + $interval);
$tranSearchReq = new TransactionSearchReq();
$tranSearchReq->TransactionSearchRequest = $transactionSearchRequest;
$paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
$transactionSearchResponse = $paypalService->TransactionSearch($tranSearchReq);
$paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
$transactionSearchResponse = $paypalService->TransactionSearch($tranSearchReq);
print_r($transactionSearchResponse);
response:
[0] => PaymentTransactionSearchResultType Object (
[Timestamp] => 2015-07-09T01:20:10Z
[Timezone] => GMT
[Type] => Payment
[Payer] => xxx#xxx.com
[PayerDisplayName] => Xxx Inc.
[TransactionID] => xxxxxxxxxxxxxxxxxx
[Status] => Completed
[GrossAmount] => BasicAmountType Object ([currencyID] => USD, [value] => -129.38)
[FeeAmount] => BasicAmountType Object ([currencyID] => USD, [value] => 0)
[NetAmount] => BasicAmountType Object ([currencyID] => USD, [value] => -129.38)
)
But this function (TransactionSearch and GetTransactionDetails(very large array, i will not write a response)) dont have funding source, how to i get transaction funding source?
image http://i60.tinypic.com/30trq0m.png
P.S. Sorry for my bad English
You don't have access to funding source information for transactions you receive.
That is private to the sender.
I'm writing a module for PRESTASHOP 1.6. One of the task of this module is to give a customer DISCOUNT for whole order in the CART and display it. The question is which method should I use to get total value of all products in the cart and then add a single DISCOUNT for whole order?
Check this code to create a new cart rule:
$cart_rule = new CartRule();
$cart_rule->id_customer = $this->context->cart->id_customer;
$cart_rule->name = array(
Configuration::get('PS_LANG_DEFAULT') => $this->l('CartRule title')
);
$cart_rule->date_from = date('Y-m-d H:i:s', time());
$cart_rule->date_to = date('Y-m-d H:i:s', time() + 24 * 3600);
$cart_rule->quantity = 1;
$cart_rule->quantity_per_user = 1;
$cart_rule->minimum_amount_currency = $this->context->cart->id_currency;
$cart_rule->reduction_currency = $this->context->cart->id_currency;
$cart_rule->free_shipping = true;
$cart_rule->reduction_amount = 50; #discount value
$cart_rule->active = 1;
$cart_rule->add();
// Add cart rule to cart and in order
$values = array(
'tax_incl' => $cart_rule->getContextualValue(true),
'tax_excl' => $cart_rule->getContextualValue(false)
);
$this->context->cart->addCartRule($cart_rule->id, $cart_rule->name[Configuration::get('PS_LANG_DEFAULT')], $values);
I am calling SetExpressCheckout and handing in some tax. The Grand total in the paypal checkout screen reflects the tax (as expected) but there is no line item showing the tax. This is very confusing for customers. It appears like the grand total is "just higher" than the item price, for no apparent reason. I can't believe paypal would build it this way, so I assume I must be doing something wrong.
Here's a screenshot:
Here is my REQUEST:
VERSION = 97.0
METHOD = SetExpressCheckout
RETURNURL = http://[removed...]
CANCELURL = http://[removed...]
PAYMENTREQUEST_0_PAYMENTACTION = Sale
PAYMENTREQUEST_0_CURRENCYCODE = USD
PAYMENTREQUEST_0_ITEMAMT = 1
L_PAYMENTREQUEST_0_NAME0 = Widget1
L_PAYMENTREQUEST_0_NUMBER0 = Widget1
L_PAYMENTREQUEST_0_AMT0 = 1
PAYMENTREQUEST_0_TAXAMT = 0.06
PAYMENTREQUEST_0_AMT = 1.06
L_PAYMENTREQUEST_0_QTY0 = 1
L_PAYMENTREQUEST_0_ITEMCATEGORY0 = Digital
SOLUTIONTYPE = Sole
REQCONFIRMSHIPPING = 0
NOSHIPPING = 1
I also tried adding tax as an add'l "L_" line item for tax, but that makes it worse. It increases the line item itself by the tax amount, so the customer doesn't know they're paying tax, they just think the item price is higher.
Please help.
Don't know if you still need help but I found a way to add tax simply by adding the tax as an additional item.
This also allowed me to name the tax....:
// to add anothe item, uncomment the lines below and comment the line above
$items[] = array('name' => 'TVA', 'amt' => $tvaAmount1, 'qty' => 1);
// $items[] = array('name' => 'Item Name2', 'amt' => $itemAmount2, 'qty' => 1);
$paymentAmount = $paymentAmount + $tvaAmount1;