ich entwickle hybrid mobile Anwendung für Magento Website. Jetzt muss ich Programme programmatisch erstellen. Ich bin in der Lage, paypal zu integrieren und paypal Erfolgsantwort zu bekommen. Sobald ich eine Paypal-Antwort bekommen habe, poste ich Daten auf Magento. hier bekomme ich Fehler alsPaypal Buchungsfehler in Magento Auftragserstellung programmatisch
Uncaught exception 'Mage_Core_Exception' with message 'PayPal gateway has rejected request.
Invalid token (#10410: Invalid token).' in public_html/app/code/core/Mage/Paypal/Model/Api/Nvp.php:1062
Unten ist meine Bestellung Erstellung Code.
<?php
// Mage Path
require_once(dirname(__FILE__).'/../app/Mage.php');
umask(0);
// Initialize Magento ...
Mage::app("default");
$id=11; // get Customer Id
$customer = Mage::getModel('customer/customer')->load($id);
$transaction = Mage::getModel('core/resource_transaction');
$storeId = $customer->getStoreId();
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);
$order = Mage::getModel('sales/order')
->setIncrementId($reservedOrderId)
->setStoreId($storeId)
->setQuoteId(0)
->setGlobal_currency_code('USD')
->setBase_currency_code('USD')
->setStore_currency_code('USD')
->setOrder_currency_code('USD');
//Set your store currency USD or any other
// set Customer data
$order->setCustomer_email($customer->getEmail())
->setCustomerFirstname($customer->getFirstname())
->setCustomerLastname($customer->getLastname())
->setCustomerGroupId($customer->getGroupId())
->setCustomer_is_guest(0)
->setCustomer($customer);
// set Billing Address
$billing = $customer->getDefaultBillingAddress();
$billingAddress = Mage::getModel('sales/order_address')
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
->setCustomerId($customer->getId())
->setCustomerAddressId($customer->getDefaultBilling())
->setCustomer_address_id($billing->getEntityId())
->setPrefix($billing->getPrefix())
->setFirstname($billing->getFirstname())
->setMiddlename($billing->getMiddlename())
->setLastname($billing->getLastname())
->setSuffix($billing->getSuffix())
->setCompany($billing->getCompany())
->setStreet($billing->getStreet())
->setCity($billing->getCity())
->setCountry_id($billing->getCountryId())
->setRegion($billing->getRegion())
->setRegion_id($billing->getRegionId())
->setPostcode($billing->getPostcode())
->setTelephone($billing->getTelephone())
->setFax($billing->getFax());
$order->setBillingAddress($billingAddress);
$shipping = $customer->getDefaultShippingAddress();
$shippingAddress = Mage::getModel('sales/order_address')
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setCustomerId($customer->getId())
->setCustomerAddressId($customer->getDefaultShipping())
->setCustomer_address_id($shipping->getEntityId())
->setPrefix($shipping->getPrefix())
->setFirstname($shipping->getFirstname())
->setMiddlename($shipping->getMiddlename())
->setLastname($shipping->getLastname())
->setSuffix($shipping->getSuffix())
->setCompany($shipping->getCompany())
->setStreet($shipping->getStreet())
->setCity($shipping->getCity())
->setCountry_id($shipping->getCountryId())
->setRegion($shipping->getRegion())
->setRegion_id($shipping->getRegionId())
->setPostcode($shipping->getPostcode())
->setTelephone($shipping->getTelephone())
->setFax($shipping->getFax());
$order->setShippingAddress($shippingAddress)
->setShipping_method('flatrate_flatrate');
/*->setShippingDescription($this->getCarrierName('flatrate'));*/
/*some error i am getting here need to solve further*/
//you can set your payment method name here as per your need
$orderPayment = Mage::getModel('sales/order_payment')
->setStoreId($storeId)
->setCustomerPaymentId("PAY-9G20599927263253EK6BC2SA")
->setMethod('paypal_express')
->setPo_number('8EV04718DA563240K');
$order->setPayment($orderPayment);
// let say, we have 2 products
//check that your products exists
//need to add code for configurable products if any
$subTotal = 0;
$products = array(
'1' => array(
'qty' => 2
));
foreach ($products as $productId=>$product) {
//$_product = Mage::getModel('catalog/product')->load($productId);
$id = Mage::getModel('catalog/product')->getResource()->getIdBySku('property_415682');
if ($id) {
$_product = Mage::getModel('catalog/product')->load($id);
}
$rowTotal = $_product->getPrice() * $product['qty'];
$orderItem = Mage::getModel('sales/order_item')
->setStoreId($storeId)
->setQuoteItemId(0)
->setQuoteParentItemId(NULL)
->setProductId($productId)
->setProductType($_product->getTypeId())
->setQtyBackordered(NULL)
->setTotalQtyOrdered($product['rqty'])
->setQtyOrdered($product['qty'])
->setName($_product->getName())
->setSku($_product->getSku())
->setPrice($_product->getPrice())
->setBasePrice($_product->getPrice())
->setOriginalPrice($_product->getPrice())
->setRowTotal($rowTotal)
->setBaseRowTotal($rowTotal);
$subTotal += $rowTotal;
$order->addItem($orderItem);
}
$order->setSubtotal($subTotal)
->setBaseSubtotal($subTotal)
->setGrandTotal($subTotal)
->setBaseGrandTotal($subTotal);
$transaction->addObject($order);
$transaction->addCommitCallback(array($order, 'place'));
$transaction->addCommitCallback(array($order, 'save'));
$transaction->save();
Referenz i i dieses Plugin
https://github.com/paypal/PayPal-Cordova-Plugin
Ich bin neu zu magento und ionische App-Entwicklung so Jede Art von Hilfe zu schätzen verwendet
http://pragneshkaria.com/programmatically-create-order-in-magento/
Für PayPal-Zahlung Integration folgt .
Vielen Dank im Voraus.
Aber erwarten Sie, dass Sie einen echten PayPal-Account mit diesem Code bezahlen? Magento bei jedem Modell speichern können Beobachter ausführen, die eine Verbindung mit dem echten Paypal-Gateway herstellen können, und PayPal erfordert natürlich eine Art von Authentifizierungs-Token. Wenn Sie nur alte Daten importieren möchten, sollten Sie einfachere Abfragen durchlaufen. –
@PawelDubiel Ich habe versucht, mit einfachen Abfragen, aber ich habe auch Schwierigkeiten dabei.können Sie bitte ein beliebiges Beispiel oder Referenzen angeben, um Bestellungen mit DB-Abfragen zu erstellen. – venkatesh