Missing "Buyer Information" in Recurring Payment - paypal

We're using the PayPal PHP SDK to create a "Recurring Payments Profile", but every profile is missing the "Buyer Information" (Name & Email) under "History" in our Sandbox account.
How can we add the buyer's name and email address to the request?
$firstName = $_POST[ 'firstName' ];
$lastName = $_POST[ 'lastName' ];
$email = $_POST[ 'email' ];
$installment_amount = ...;
$shippingAddress = new AddressType();
$shippingAddress->Name = $firstName . ' ' . $lastName;
$shippingAddress->Street1 = $_POST[ 'address1' ];
$shippingAddress->Street2 = $_POST[ 'address2' ];
$shippingAddress->CityName = $_POST[ 'city' ];
$shippingAddress->StateOrProvince = $_POST[ 'state' ];
$shippingAddress->PostalCode = $_POST[ 'zip' ];
$shippingAddress->Country = $_POST[ 'country' ];
$shippingAddress->Phone = $_POST[ 'phone' ];
$RPProfileDetails = new RecurringPaymentsProfileDetailsType();
$RPProfileDetails->SubscriberName = $firstName . ' ' . $lastName;
$RPProfileDetails->BillingStartDate = date( DATE_ATOM );
$RPProfileDetails->SubscriberShippingAddress = $shippingAddress;
$activationDetails = new ActivationDetailsType();
$activationDetails->InitialAmount = new BasicAmountType( 'USD', $installment_amount );
$activationDetails->FailedInitialAmountAction = 'CancelOnFailure';
$paymentBillingPeriod = new BillingPeriodDetailsType();
$paymentBillingPeriod->BillingFrequency = 1;
$paymentBillingPeriod->BillingPeriod = 'Day';
$paymentBillingPeriod->TotalBillingCycles = 2;
$paymentBillingPeriod->Amount = new BasicAmountType( 'USD', $installment_amount );
$scheduleDetails = new ScheduleDetailsType();
$scheduleDetails->Description = ...;
$scheduleDetails->ActivationDetails = $activationDetails;
$scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
$scheduleDetails->MaxFailedPayments = 3;
$scheduleDetails->AutoBillOutstandingAmount = 'AddToNextBilling';
$createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
$cardDetails = new CreditCardDetailsType();
$cardDetails->CreditCardNumber = $_POST[ 'creditCardNumber' ];
$cardDetails->CreditCardType = $_POST[ 'creditCardType' ];
$cardDetails->ExpMonth = $_POST[ 'expDateMonth' ];
$cardDetails->ExpYear = $_POST[ 'expDateYear' ];
$cardDetails->CVV2 = $_POST[ 'cvv2Number' ];
$createRPProfileRequestDetail->CreditCard = $cardDetails;
$createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
$createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
$createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
$createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
$createRPProfileReq = new CreateRecurringPaymentsProfileReq();
$createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
$paypalService = new PayPalAPIInterfaceServiceService( ... );
try {
$createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile( $createRPProfileReq );
} catch ( Exception $exception ) {
...
}

As long as you are passing the shipping information in the Profile Details it should get passed into the transaction information in Sandbox. Billing address is not stored in the PayPal Transactions.
Your code looks like it should be passing the information correctly. As a just in case, look over the below sample code from GitHub. I didn't paste all of the code in.
Merchant SDK php Sample for Recurring Billing
$shippingAddress = new AddressType();
$shippingAddress->Name = $_REQUEST['shippingName'];
$shippingAddress->Street1 = $_REQUEST['shippingStreet1'];
$shippingAddress->Street2 = $_REQUEST['shippingStreet2'];
$shippingAddress->CityName = $_REQUEST['shippingCity'];
$shippingAddress->StateOrProvince = $_REQUEST['shippingState'];
$shippingAddress->PostalCode = $_REQUEST['shippingPostalCode'];
$shippingAddress->Country = $_REQUEST['shippingCountry'];
$shippingAddress->Phone = $_REQUEST['shippingPhone'];
$RPProfileDetails = new RecurringPaymentsProfileDetailsType();
$RPProfileDetails->SubscriberName = $_REQUEST['subscriberName'];
$RPProfileDetails->BillingStartDate = $_REQUEST['billingStartDate'];
$RPProfileDetails->SubscriberShippingAddress = $shippingAddress;
$activationDetails = new ActivationDetailsType();

Related

on form submit user session data is lost

I am working on a codeigniter listing application, everything is working fine in the application but when I am submitting the listing form, the user session data is lost.
I am having: agentId in session, which is visible after login but after submitting it is not in the session data.
Code:
$agentId = $this->session->userdata('agentId');
var_dump($this->session->userdata);
die;
\\ This session showing all user data including agentId
$data['p_title'] = $this->project_model->projectName().' :: Property : Add New Property';
$data['Message'] = '';
$data['heading'] = 'Property: Add New Property';
$data['pageName'] = 'property';
$data['title'] = filter_value('title', '');
$data['meta_decription'] = filter_value('meta_decription', '');
$data['keywords'] = filter_value('keywords', '');
$data['type'] = filter_value('type', '');
$data['sub_type'] = filter_value('sub_type', '');
//$data['sub_type1'] = filter_value('sub_type1', '');
$data['bedrooms'] = filter_value('bedrooms', '');
$data['kitchen'] = filter_value('kitchen', '');
$data['parking'] = filter_value('parking', 'YES');
$data['bathrooms'] = filter_value('bathrooms', '');
$data['area'] = filter_value('area', '');
$data['price'] = filter_value('price', '0.00');
$data['location'] = filter_value('location', '');
$data['city'] = filter_value('city', 82);
$data['country'] = filter_value('country', 102);
$data['details'] = filter_value('details', '');
$data['featured'] = filter_value('featured', 'NO');
$data['countries'] = $this->general_model->listCountries($data['country']);
$data['cities'] = $this->general_model->listCities($data['country'], $data['city']);
$this->form_validation->set_rules('title', 'Property title', 'trim|required');
if($this->form_validation->run() === TRUE){
$agentId = $this->session->userdata('agentId');
var_dump($this->session->userdata);
die;
\\ but here the agent id and rest of user session data is removed.
$Date = getCurrentDate();
$Time = getCurrentTime();
$DbFieldsAry = array('agentId', 'title', 'meta_decription', 'keywords', 'type', 'sub_type', 'bedrooms', 'kitchen', 'parking', 'bathrooms', 'area', 'price', 'location', 'city', 'country', 'details', 'featured', 'date');
$InfoAry = array($this->session->userdata('agentId'), $data['title'], $data['meta_decription'], $data['keywords'], $data['type'], $data['sub_type'], $data['bedrooms'], $data['kitchen'], $data['parking'], $data['bathrooms'], $data['area'], $data['price'], $data['location'], $data['city'], $data['country'], $data['details'], $data['featured'], $Date);
if($this->general_model->addInfo_Simple($DbFieldsAry, $InfoAry, 'tbl_properties_list')){
$activityId = $this->general_model->getSingleValue($data['title'], 'title', 'property_id', 'tbl_properties_list');
setMessage('success_message', 'New property added successfully. Add pictures to property.');
redirect(base_url().'property/update/'.$activityId.'/0', 'refresh');
}
else{
setMessage('error_message', 'Unable to perofrm this operation, please try again later!');
redirect(base_url().'property/user_listing', 'refresh');
}
}
$data['allowed'] = true;
$data['warning'] = '';
if(!isSuperAdmin()){
$total_properties = $this->general_model->getTotalDataSimple1('property_id','tbl_properties_list');
if(allowed_properties() <= $total_properties){
$data['allowed'] = false;
$data['warning'] = '<br/>You have reached to maximum limit of your property upload listing.<br/>Click HERE to change payment plan.<br/><br/><br/><br/><br/>';
}
}
$this->load->view('add_property', $data);
The first var_dump for session check shows all session data, but why is all the user session data lost after submitting?

how to import a product programatically in magento 2

I tried importing a single product in magento 2..It failed..
I tried a script in magento 2 root directory and
My code is
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = true; // default false
$params[Bootstrap::PARAM_REQUIRE_IS_INSTALLED] = false; // default true
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$simple_product = $objectManager->create('\Magento\Catalog\Model\Product');
$simple_product->setSku('Tops');
$simple_product->setName('tops');
$simple_product->setAttributeSetCode('Default');
$simple_product->setCategories('Default Category/Women');
$simple_product->setStatus(1);
$simple_product->setTypeId('simple');
$simple_product->setPrice(10);
$simple_product->setProductWebsites('base');
$simple_product->setCategoryIds(array(31));
$simple_product->setUrlKey ('tops');
$simple_product->setColor('Red');
$simple_product->setStockData(array(
'use_config_manage_stock' => 0, //'Use config settings' checkbox
'manage_stock' => 1, //manage stock
'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart
'is_in_stock' => 1, //Stock Availability
'qty' => 100 //qty
)
);
$simple_product->save();
$simple_product_id = $simple_product->getId();
echo "simple product id: ".$simple_product_id."\n";
?>
and i am getting the following error
Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento`.`catalog_product_entity`, CONSTRAINT `CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID` FOREIGN KEY (`attribute_set_id`) REFERENCES `eav_attribute_set` (`attribute_set_id`) ON DELET) in /var/www/html/magento/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228 Stack trace: #0 /var/www/html/magento/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array) #1 /var/www/html/magento/vendor/magento/framework/DB/Statement/Pdo/Mysql.php(95): Zend_Db_Statement_Pdo->_execute(Array) #2 /var/www/html/magento/vendor/magento/zendframework1/library/Zend/Db/Statement.php(303): Magento\Framework\DB\Statement\Pdo\Mysql->_execute(Array) #3 /var/www/html/magento/vendor/magento/zendframework1/library/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array) #4 /var/www/html/magento/vendor/magento/zendframework1/ in /var/www/html/magento/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php on line 235
Can anyone give me a solution?
For Simple Product Working on M2
use Magento\Framework\App\Bootstrap;
include("../app/bootstrap.php");
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$simpleProduct = $objectManager->create('\Magento\Catalog\Model\Product');
$simpleProduct->setSku('Testing3');
$simpleProduct->setName('Testing3');
$simpleProduct->setAttributeSetId(9);
$simpleProduct->setCategoryIds(3);
$simpleProduct->setDescription('This is for testing');
$simpleProduct->setStatus(1);
$simpleProduct->setTypeId('simple');
$simpleProduct->setPrice(500);
$simpleProduct->setWebsiteIds(array(1));
$simpleProduct->setVisibility(4);
$simpleProduct->setUrlKey('Testing3');
$simpleProduct->setStockData(array(
'is_in_stock' => 1, //Stock Availability
'qty' => 100//qty
)
);
$attr = $simpleProduct->getResource()->getAttribute('color');
$attributeOptionId = $attr->getSource()->getOptionId('Red'); //name in Default Store View
$simpleProduct->setData('color', $attributeOptionId);
$simpleProduct->save();
$simpleProductId = $simpleProduct->getId();
echo "Simple Product ID: " . $simpleProductId . "\n";
?>
This is the updated version of your code. Please use this code to create product.
use Magento\Framework\App\Bootstrap;
include("app/bootstrap.php");
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$simple_product = $objectManager->create('\Magento\Catalog\Model\Product');
$simple_product->setSku('tops123');
$simple_product->setName('tops');
$simple_product->setAttributeSetId(4);;
$simple_product->setCategories('Default Category/Women');
$simple_product->setStatus(1);
$simple_product->setTypeId('simple');
$simple_product->setPrice(10);
$simple_product->setWebsiteIds(array(1));
$simple_product->setCategoryIds(array(31));
$simple_product->setUrlKey ('tops343225');
$simple_product->setColor('Red');
$simple_product->setStockData(array(
'use_config_manage_stock' => 0, //'Use config settings' checkbox
'manage_stock' => 1, //manage stock
'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart
'is_in_stock' => 1, //Stock Availability
'qty' => 100 //qty
)
);
$simple_product->save();
$simple_product_id = $simple_product->getId();
echo "simple product id: ".$simple_product_id."\n";
Thanks
For configurable product working on M2
<?php
use Magento\Framework\App\Bootstrap;
include("../app/bootstrap.php");
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$productId = 809; // Configurable Product Id
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($productId); // Load Configurable Product
$attributeModel = $objectManager->create('Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute');
$position = 0;
$attributes = array(93, 135); // Super Attribute Ids Used To Create Configurable Product
$associatedProductIds = array(806, 807); //Product Ids Of Associated Products
foreach ($attributes as $attributeId) {
$data = array('attribute_id' => $attributeId, 'product_id' => $productId, 'position' => $position);
$position++;
$attributeModel->setData($data)->save();
}
$product->setTypeId("configurable"); // Setting Product Type As Configurable
$product->setAffectConfigurableProductAttributes(4);
$objectManager->create('Magento\ConfigurableProduct\Model\Product\Type\Configurable')->setUsedProductAttributeIds($attributes, $product);
$product->setNewVariationsAttributeSetId(9); // Setting Attribute Set Id
$product->setAssociatedProductIds($associatedProductIds); // Setting Associated Products
$product->setCanSaveConfigurableAttributes(true);
$product->save();
$configProductId = $product->getId();
echo "Configurable product id: " . $configProductId . "\n";
?>
<?php
use Magento\Framework\App\Bootstrap;
include("./app/bootstrap.php");
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
// add logging capability
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/import-new.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$simpleProduct = $objectManager->create('\Magento\Catalog\Model\Product');
$simpleProduct->setSku('Testing5');
$simpleProduct->setName('Testing11115');
// $attributeSetId = $simpleProduct->getDefaultAttributeSetId();
$simpleProduct->setAttributeSetId(4);
$simpleProduct->setCategoryIds(3);
$simpleProduct->setDescription('This is for testing');
$simpleProduct->setStatus(1);
$simpleProduct->setTypeId('simple');
$simpleProduct->setPrice(500);
$simpleProduct->setWebsiteIds(array(1));
$simpleProduct->setVisibility(4);
$simpleProduct->setUrlKey('Testing445');
$simpleProduct->setStoreId(1);
$simpleProduct->setStockData(array(
'is_in_stock' => 1, //Stock Availability
'qty' => 100//qty
)
);
// $attr = $simpleProduct->getResource()->getAttribute('color');
// $attributeOptionId = $attr->getSource()->getOptionId('Red'); //name in Default Store View
// $simpleProduct->setData('color', $attributeOptionId);
$simpleProduct->save();
$simpleProductId = $simpleProduct->getId();
echo "Simple Product ID: " . $simpleProductId . "\n";
?>

How to set custmer id for an quote in magento?

I am adding product into cart and tried to map customer id,email to that quote
using the below code
$product_id = 123;
$qty = 1;
$product = Mage::getModel('catalog/product')->load($product_id);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$superAttributeArray = array('151' => '3');
$params = array(
'product' => $product_id,
'qty' => $qty,
'super_attribute' => $superAttributeArray
);
$cart->addProduct($product, $params);
$cart->save();
$currenQuoteId = Mage::getSingleton('checkout/session')->getQuoteId();
$store = Mage::getSingleton('core/store')->load(Mage::app()->getStore()->getId());
$quote = Mage::getModel('sales/quote')->setStore($store)->load($currenQuoteId);
$quote->setCustomerId('1')->setCustomerEmail('test#gmail.com')->setCustomerFirstname('firstname')->setCustomerLastname('lastname');
$quote->save();
When I try to set customerid,email,fname,lname am getting error as "Mage registry key "controller" already exists".
Can anyone help me in fixing this issue?
Something like this might work
$customerObj = Mage::getModel('customer/customer')->load($customerId);
$quoteObj = Mage::getModel('sales/quote')->assignCustomer($customerObj);
$storeId = Mage::app()->getStore()->getId();
$quoteObj->setStore(Mage::getSingleton('core/store')->load($storeId);
$productObj = Mage::getModel('catalog/product')->load($productId);
$quoteItem = Mage::getModel('sales/quote_item')->setProduct($productObj);
$quoteItem->setQuote($quoteObj);
$quoteItem->setQty('1');
$quoteItem->setStoreId($storeId);
$quoteObj->addItem($quoteItem);
$quoteObj->setStoreId($storeId);
$quoteObj->collectTotals();
$quoteObj->save();

PrestaShop 1.6 How to add a discount to order?

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);

Zend_Db_Select : multiple from clause

Hy,
I have some problem vith Zend_Db_Select.
I have 2 variable : category and city. These 2 variables may have a value or they may be unset.
So I verify:
$status = '`p`.status = 1';
if($catID){
$catSQL = "`p`.parent = {$catID}";
}else{
$catSQL = '1=1';
}
if($city){
$citySQL = "`pm`.`meta_key` = 'oras' and `pm`.`meta_value` = {$city}";
$citySelect = array('pm' => 'postsmeta');
$condCity = "`p`.`ID` = `pm`.`parent_id`";
}else{
$citySQL = '1=1';
$citySelect = NULL;
$condCity = '1=1';
}
Now here is my query:
$select = $db->select()
->from( array('p' => 'posts'))
->from($citySelect)
->where($status)
->where($catSQL)
->where($condCity)
->where($citySQL)
;
The problem is that if city is empty I have something like
$select = $db->select()
->from( array('p' => 'posts'))
->from('')
->where(1=1)
->where(1=1)
->where(1=1)
->where(1=1)
;
The questions is how can I remove from('') from my query if city is empty.
Thank you!
Simply,
$select = $db->select()
->from( array('p' => 'posts'));
if($someConditionIsTrue) {
$select->join($table, $condition);
}
$select->where('field_value = ?', 'value1');
if($someConditionIsTrue) {
$select->where('another_field = ?', 'value 2');
}
Hope it helps.
Please use this syntax $select->where('another_field = ?', 'value 2'); for proper escaping values to prevent SQL injections.