I'm in the process of writing some code that will submit an order to Paypal Express Checkout. Unforunately I can't seem to get the whole address thing to work, and I also can't seem to find much info on it in the API docs. Here's my code so far.
$config = array (
'mode' => 'sandbox' ,
'acct1.UserName' => '****removed*****',
'acct1.Password' => '******removed*******',
'acct1.Signature' => '*********removed***********'
);
$paypalService = new PayPal\Service\PayPalAPIInterfaceServiceService($config);
$paymentDetails= new PayPal\EBLBaseComponents\PaymentDetailsType();
// Dummy shipping address
// Obviously, in the final version, this would be passed in from a form
$shipping_address = new PayPal\EBLBaseComponents\AddressType();
$shipping_address->Name = "John Smith";
$shipping_address->Street1 = "123 Market Street";
$shipping_address->Street2 = "";
$shipping_address->CityName = "Columbus";
$shipping_address->StateOrProvince = "OH";
$shipping_address->PostalCode = "43017";
$shipping_address->Country = "US";
// A dummy item
// Once again, in a final version this would be passed in
$itemDetails = new PayPal\EBLBaseComponents\PaymentDetailsItemType();
$itemDetails->Name = 'Electro Lettuce Feeders';
$itemAmount = 1250.00;
$itemDetails->Amount = $itemAmount;
$itemQuantity = 1;
$itemDetails->Quantity = $itemQuantity;
// Add all items to the list
$paymentDetails->PaymentDetailsItem[0] = $itemDetails;
// The company is in NYS, so in the final version the
// sales tax rate will be passed in (NYS is destination-based)
$sales_tax_rate = 0.07;
// Order sub-total
$itemTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$itemTotal->currencyID = 'USD';
$itemTotal->value = ($itemAmount * $itemQuantity);
// Shipping total
$shippingTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$shippingTotal->currencyID = 'USD';
$shippingTotal->value = 2.00;
// Tax total
$taxTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$taxTotal->currencyID = 'USD';
$taxTotal->value = $itemTotal->value * $sales_tax_rate;
// Order total
$orderTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$orderTotal->currencyID = 'USD';
$orderTotal->value = $itemTotal->value + $taxTotal->value + $shippingTotal->value;
$paymentDetails->TaxTotal = $taxTotal;
$paymentDetails->ItemTotal = $itemTotal;
$paymentDetails->ShippingTotal = $shippingTotal;
$paymentDetails->OrderTotal = $orderTotal;
$paymentDetails->PaymentAction = 'Sale';
// ***** Is the address from this object passed to Paypal?
$paymentDetails->ShipToAddress = $shipping_address;
$setECReqDetails = new PayPal\EBLBaseComponents\SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[0] = $paymentDetails;
$setECReqDetails->CancelURL = 'https://devtools-paypal.com/guide/expresscheckout/php?cancel=true';
$setECReqDetails->ReturnURL = 'https://devtools-paypal.com/guide/expresscheckout/php?success=true';
// ***** Or is this the address that will be passed to Paypal?
$setECReqDetails->Address = $shipping_address;
// ***** And can you choose to not pass in the billing address? Or is it required? *****
$setECReqDetails->BillingAddress = $shipping_address;
// ***** If this is set to 0, will the previously provided shipping address be shown
// ***** at all? Or will it just be "modify-able" unless you set this to 1?
$setECReqDetails->AddressOverride = 1;
$setECReqType = new PayPal\PayPalAPI\SetExpressCheckoutRequestType();
$setECReqType->Version = '104.0';
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new PayPal\PayPalAPI\SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
//var_dump($setECResponse);
$redirect_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=".$setECResponse->Token;
return $app->redirect($redirect_url);
Summed up...
You'll see my questions distributed throughout the code, but here they are all summed up.
Both PaymentDetailsType() and SetExpressCheckoutRequestType() have address-ish properties. Which one will be passed on to Paypal?
Does the API require that you pass in a billing address if you pass in a shipping address?
If you don't set AddressOverride to 1, should it show the address that you passed in at all?
But in the end, I most importantly just want to know how to get address passing to work. =). Right now I can't seem to get any address to pass to Paypal no matter what I try.
It would help more to see the raw API requests getting generated as opposed to the code generating the requests. The library you're using should give you some way to see that. Then you just need to make sure the address parameters are getting passed correctly in DoExpressCheckoutPayment.
If you like, you might want to take a look at my PHP class library for PayPal. Might kinda suck to start over with another library, but it makes it very quick and easy. It has files prepared with all the parameters and everything ready to go so all you need to do is fill in the values and it'll work every time. :)
After some furious research, I was able to figure out the problem using Paypal's API explorer. As it turns out, setting ->Address on the SetExpressCheckoutRequestType() object is deprecated. The correct method is to set ->ShipToAddress for your PaymentDetailsType() object.
In my case, however, the reason that nothing was working was because I had my address wrong [slaps palm into forehead]. My zip, while in the region of Columbus, OH is technically in Dublin, OH. So, Paypal was generating an error.
Paypal wasn't showing me error information, however, so I had no way to know what in particular was causing the error. This is where the API explorer came in handy; I filled in the API explorer and tried my request--and it gave me detailed error information.
Since then, I've also found out that I can see detailed error information simply by using:
var_dump($setECResponse);
Related
I have a Custom Record Type and I am having trouble searching the barcode from the item value:
I am using the NetSuite PHPToolkit_2015_2 and this stackoverflow answer https://stackoverflow.com/a/13366947/2120512 and http://burnignorance.com/netsuite-tips-and-hacks/working-with-custom-records-in-suitetalk/ to attempt to build this request:
$service = new NetSuiteService();
// Perform an AdvancedSearch for Items
// https://netsuite.custhelp.com/app/answers/detail/a_id/12203/kw/php%20search%20criteria
$service->setSearchPreferences(false, 1000, false);
$savedSearchId = 'customsearch_barcode_view'; //customsearch## from UI ID field
$searchAdvanced = new CustomRecordSearchAdvanced();
setFields($searchAdvanced, array('savedSearchScriptId'=>$savedSearchId));
$request = new SearchRequest();
$request->searchRecord = $searchAdvanced;
// PHP Toolkit 2012.2: Sample Code to Perform Search that Uses a Custom Field as Filter
// https://netsuite.custhelp.com/app/answers/detail/a_id/25066/kw/php%20custom%20field
$custSearchField = new SearchMultiSelectCustomField();
$custSearchField->value = new ListOrRecordRef();
$custSearchField->value->internalId = "custrecord_barcode_item";
$custSearchField->value->value = "00001 Beer Mug";
$searchAdvanced->customFieldList = $custSearchField;
$results = $service->search($request);
I still get all the results for the Custom Record Type and never able to figure out how to search by the item. I have made changes and still receive the entire results.
I'm pretty sure this won't immediately solve your problem, but at the first glance I can see an error in your code.
The customFieldList is of type array, so you need to change this:
$searchAdvanced->customFieldList = $custSearchField;
To this
$searchAdvanced->customFieldList = [$custSearchField];
I am trying to integrate First Data e4 Gateway using PHP. I downloaded the VinceG/php-first-data-api PHP First Data Service API class. The code comes with some examples.
I have my Terminal ID (API_LOGIN) and Password (32 character string).
What confuses me is that when I use one of the examples, I don't know how to tell the class that I want to use the demo url, not the production url.
The class comes with two constants:
const LIVE_API_URL = 'https://api.globalgatewaye4.firstdata.com/transaction/';
const TEST_API_URL = 'https://api.demo.globalgatewaye4.firstdata.com/transaction/';
In the First Data console, when I generated my password, it said to use the v12 api, /transaction/v12, so I changed the protected $apiVersion = 'v12';
All I want to do is write my first development transaction using First Data e4. I have yet to get any kind of response. Obviously I need a lot of hand holding to get started.
When I set up a website to use BalancedPayments, they have a support forum that's pretty good, and I was able to get that running fairly quickly. First Data has a lot of documentation, but for some reason not much of it has good PHP examples.
My hope is that some expert has already mastered the VinceG/php-first-data-api, and can help me write one script that works.
Here's the pre-auth code I'm using, that invokes the FirstData class:
// Pre Auth Transaction Type
define("API_LOGIN", "B123456-01");
define("API_KEY", "xxxxxxxxxxyyyyyyyyyyyyzzzzzzzzzz");
$data = array();
$data['type'] = "00";
$data['number'] = "4111111111111111";
$data['name'] = "Cyrus Vance";
$data['exp'] = "0618";
$data['amount'] = "100.00";
$data['zip'] = "33333";
$data['cvv'] = "123";
$data['address'] = "1111 OCEAN BLVD MIAMI FL";
$orderId = "0001";
require_once("FirstData.php");
$firstData = new FirstData(API_LOGIN, API_KEY, true);
// Charge
$firstData->setTransactionType(FirstData::TRAN_PREAUTH);
$firstData->setCreditCardType($data['type'])
->setCreditCardNumber($data['number'])
->setCreditCardName($data['name'])
->setCreditCardExpiration($data['exp'])
->setAmount($data['amount'])
->setReferenceNumber($orderId);
if($data['zip']) {
$firstData->setCreditCardZipCode($data['zip']);
}
if($data['cvv']) {
$firstData->setCreditCardVerification($data['cvv']);
}
if($data['address']) {
$firstData->setCreditCardAddress($data['address']);
}
$firstData->process();
// Check
if($firstData->isError()) {
echo "!!!";
// there was an error
} else {
echo "###";
// transaction passed
}
My number one problem was that I had not created (applied for, with instant approval) a
demo account on First Data. I didn't realize this was a separate thing on First Data. On Balanced Payments, for instance, you have one account, and you can run your script on a test url with test values.
From the Administration panel, click "Terminals", then your Gateway number on the ECOMM row (will look something like AH1234-03), then you have to click "Generate" on password save it to your personal notes), then click UPDATE.
Now replace your parameter values in your test scripts. I use a variable assignment block that looks something like this:
define("API_LOGIN", "AH1234-05"); //fake
define("API_KEY", "44p7797xxx790098z1z2n6f270ys1z0x"); //fake
$data = array();
$data['type'] = "03";
$data['number'] = "4111111111111111";
$data['name'] = "Cyrus Vancce";
$data['exp'] = "0618";
$data['amount'] = "100.00";
$data['zip'] = "33320";
$data['cvv'] = "123";
$data['address'] = "1234 N OCEAN BLVD MIAMI BEACH FL";
$orderId = "0001";
require_once("FirstData.php");
$firstData = new FirstData(API_LOGIN, API_KEY, true);
at the end of the VinceG test scripts, I output my gateway response with a print_r, like this:
$firstData->process();
// Check
if($firstData->isError()) {
echo "!!!";
// there was an error
} else {
echo "###";
// transaction passed
}
echo "<pre>";
print_r($firstData);
Hi guys :) I am trying to take all meeting from resource meeting box, but when i try to take subject like this $subject = $event->Subject it displays name by whom meeting was created. $request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = "mail#domain.com" This is code how i select resource meeting box.
I want to take meeting subject by other way and i will be glad if you will help me :)
$request = new EWSType_FindItemType();
// Use this to search only the items in the parent directory in question or use ::SOFT_DELETED
// to identify "soft deleted" items, i.e. not visible and not in the trash can.
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
// This identifies the set of properties to return in an item or folder response
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::DEFAULT_PROPERTIES;
// Define the timeframe to load calendar items
$request->CalendarView = new EWSType_CalendarViewType();
$request->CalendarView->StartDate ='2014-03-28T15:00:00+04:00';// an ISO8601 date e.g. 2012-06-12T15:18:34+03:00 "Y-m-d\TH:i:sO"
$request->CalendarView->EndDate = '2015-03-28T15:00:00+04:00';// an ISO8601 date later than the above "Y-m-d\TH:i:sO"
// Only look in the "calendars folder"
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::CALENDAR;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = "meetingroom#gcfund.ge";
// Send request
$response = $ews->FindItem($request);
// Loop through each item if event(s) were found in the timeframe specified
if ($response->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView > 0){
$events = $response->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
// $db_selected = mysql_select_db('meeting_room',$con);
// $res=mysql_query("SELECT ID FROM meeting");
// while($row = mysql_fetch_array($res)){
// echo $row['ID'];
// echo "<br>";
// }
foreach ($events as $event){
$id = $event->ItemId->Id;
$change_key = $event->ItemId->ChangeKey;
$start = $event->Start;
$end = $event->End;
$subject = $event->Subject;
$location = $event->Location;
This subject displays by whom meeting was created. I want this info too but i want Subject too.. Please Help :)
This is an issue with Exchange (not your code, or the PHP library, or EWS)
Several blogs, such as this one: http://www.slipstick.com/exchange/cmdlets/meeting-organizers-name-appears-in-subject-line/ indicate that you can perform some PowerShell commands to change the Exchange server configuration. Note that if you change the configuration, it will apply for all new meetings/appointments added after the configuration change (existing meetings/appointments will stay as-is).
If you don't have PowerShell access to the Exchange server but do have administrator access via another system, you might be able to achieve the same configuration change through the interface for that system. For example, on a Parallels hosted exchange system, login to Parallels as administrator, go to Exchange, go to Resource mailboxes, edit the room resource, and untick the "Add organizer to subject" checkbox under the "Resource scheduling" tab. As far as I can tell, this just performs the same PowerShell action behind the scenes.
There may be similar options in other systems (e.g. Office 365) though I haven't looked into that.
Having said all that, I have found that making this configuration change didn't help in my case: I created a new meeting against a room resource, however the subject ended up as "" (empty string) instead of the correct subject or the organiser's name. In any case, give the configuration change a try, as other people have apparently had success with it.
I'm successfully adding a Customer to QuickBooks using QuickBooks_IPP, but I'm having difficulty setting the sales term for the customer. I've looked through the documentation and cannot find examples of setting the SalesTerm.
I've added these lines to the example code, but does not throw an error and does not add the sales term.
$Term = new QuickBooks_IPP_Object_SalesTerm();
$Term->setSalesTermRef(2); //15 days
$Customer->setSalesTermRef($Term);
This is the full Customer add code:
// Set the IPP version to v3
$IPP->version(QuickBooks_IPP_IDS::VERSION_3);
$CustomerService = new QuickBooks_IPP_Service_Customer();
$Customer = new QuickBooks_IPP_Object_Customer();
$Customer->setTitle('Ms');
$Customer->setGivenName('Shannon');
$Customer->setMiddleName('B');
$Customer->setFamilyName('Palmer');
$Customer->setDisplayName('Shannon B Palmer ' . mt_rand(0, 1000));
//set days due
$Term = new QuickBooks_IPP_Object_SalesTerm();
$Term->setSalesTermRef(2);
$Customer->setSalesTermRef($Term);
// Phone #
$PrimaryPhone = new QuickBooks_IPP_Object_PrimaryPhone();
$PrimaryPhone->setFreeFormNumber('860-532-0089');
$Customer->setPrimaryPhone($PrimaryPhone);
// Mobile #
$Mobile = new QuickBooks_IPP_Object_Mobile();
$Mobile->setFreeFormNumber('860-532-0089');
$Customer->setMobile($Mobile);
// Fax #
$Fax = new QuickBooks_IPP_Object_Fax();
$Fax->setFreeFormNumber('860-532-0089');
$Customer->setFax($Fax);
// Bill address
$BillAddr = new QuickBooks_IPP_Object_BillAddr();
$BillAddr->setLine1('72 E Blue Grass Road');
$BillAddr->setLine2('Suite D');
$BillAddr->setCity('Mt Pleasant');
$BillAddr->setCountrySubDivisionCode('MI');
$BillAddr->setPostalCode('48858');
$Customer->setBillAddr($BillAddr);
// Email
$PrimaryEmailAddr = new QuickBooks_IPP_Object_PrimaryEmailAddr();
$PrimaryEmailAddr->setAddress('support#consolibyte.com');
$Customer->setPrimaryEmailAddr($PrimaryEmailAddr);
if ($resp = $CustomerService->add($Context, $realm, $Customer))
{
print('Our new customer ID is: [' . $resp . ']');
}
else
{
print($CustomerService->lastError($Context));
}
I can query for the Customer after the add but it does not return the SalesTerm as I would expect. Do I need the SalesTerm Service instead of the Object?
The only time you'd wrap something in an object like you're doing with QuickBooks_IPP_Object_SalesTerm is if it's actually a full nested node in the XML request.
i.e. if you saw this in Intuit's documentation:
<Customer>
...
<SalesTermRef>
<Id>...</Id>
... other nested tags inside here ...
</SalesTermRef>
...
</Customer>
Then you would have been on the right track.
But per Intuit's docs, this is only a normal non-nested node:
<SalesTermRef>4</SalesTermRef>
So just use the ->setSalesTermRef($val) method:
// Terms (e.g. Net 30, etc.)
$Customer->setSalesTermRef(4);
Sometimes the easiest way to see this stuff is to examine the XML output. Look at what you're sending with:
print($CustomerService->lastRequest());
I am creating customers for NetSuite from my application by using the NetSuite PHP SDK, version 2013_2.
This mostly works, but I can not set a status for new Customers. No matter what, the status will always be CUSTOMER-Won Customer, which I don't want. I can't find any documentation about this, so I basically tried whatever seemed to make sense and tried to understand the code of the SDK. Here are some of the things I tried:
$customer->entityStatus = 17;
$customer->entityStatus = new \RecordRef(array('internalId' => 17, 'type' => 'customer'));
$customer->entityStatus = new \RecordRef();
$customer->entityStatus->internalId = 17;
All of these are simply ignored. I tried different internal IDs (and of course, I made sure all of them exist in the system). I tried using strings ('17' instead of 17), but nothing helped.
Documentation has nothing about this either.
Here's my full working code:
$ns = new \NS_NetSuiteService();
$customer = new \Customer();
$customer->companyName = $company->getName();
$customer->entityStatus = 17;
$customer->email = $user->getEmail();
$request = new \AddRequest();
$request->record = $customer;
$res = $ns->add($request);
I always create the RecordRef first, then set the field. Seems to keep things in order for me:
$entityStatus = new RecordRef();
$entityStatus->internalId = 17;
$entityStatus->recordType = "customerStatus";
$customer->entityStatus = $entityStatus;
Or, take my example and shorten the code once you see it working this way.