Creating item with podio api for PHP - php

I am trying to Create an item in the podio API for PHP. Here is my code:
Podio::setup($client_id, $client_secret);
Podio::authenticate_with_app($app_id, $app_token);
// Create a field collection with some fields.
// Be sure to use the external_ids of your specific fields
$fields = new PodioItemFieldCollection(array(
new PodioTextItemField(array("external_id"=>"first", "values"=> "Han")),
new PodioTextItemField(array("external_id"=>"last", "values"=> "Solo"))
));
// Create the item object with fields
// Be sure to add an app or podio-php won't know where to create the item
$item = new PodioItem(array(
'app' => new PodioApp($app_id), // Attach to app with app_id=$app_id
'fields' => $fields
));
// Save the new item
$item->save();
But I get error
Notice: Undefined index: request in C:\xampp\htdocs\PodioAPITesting\vendor\podio\podio-php\lib\PodioError.php on line 11
Fatal error: Uncaught PodioMissingRelationshipError: "Item is missing
relationship to app" Request URL: Stack Trace: #0 C:\xampp\htdocs\PodioAPITesting\testPodioAPI.php(66): PodioItem->save() #1 {main} thrown in C:\xampp\htdocs\PodioAPITesting\vendor\podio\podio-php\models\PodioItem.php on line 75
Am I creating the item properly? Could it be because this app has more that two fields? ( I want to set 'first' and 'last', and leave the other fields blank for now)

The problem was that my $app_id was a string when it should have been an integer.

Related

Cannot retrieve Stripe data on success page

I have followed the Stripe documentation, trying to get the e-mail address of a customer but it fails with the following error:
PHP Fatal error: Uncaught exception 'Stripe\Exception\InvalidArgumentException'
with message 'The resource ID cannot be null or whitespace.' in /home/phuketto/public_html/stripe-php/lib/Service/AbstractService.php:99
Stack trace:
#0 /home/phuketto/public_html/stripe-php/lib/Service/Checkout/SessionService.php(90): Stripe\Service\AbstractService->buildPath('/v1/checkout/se...', NULL)
#1 /home/phuketto/public_html/ipnstripe.php(9): Stripe\Service\Checkout\SessionService->retrieve(NULL)
#2 {main}
thrown in /home/phuketto/public_html/stripe-php/lib/Service/AbstractService.php on line 99
In my create session script I am using:
'success_url' => 'https://www.example.com/ipnstripe.php?session_id={CHECKOUT_SESSION_ID}',
In my success_url I am trying to get the customer e-mail to be used further down the script but something goes wrong and the rest of the script is not executed:
require_once('./stripe-php/init.php');
$stripe = new \Stripe\StripeClient('sk_live_xxxxx');
$session = $stripe->checkout->sessions->retrieve($_GET['session_id']);
$customer = $stripe->customers->retrieve($session->customer);
$payeremail = $customer->email;

Stripe API Update DRAFT invoice for subscription (PHP)

I am using PHP and have a webhook generated with invoice.created. When the invoice is created, Stripe lets the draft invoice sit there for about an hour which gives us time to edit the invoice or adjust it. I use this time to check the database (via webhook) to see how many referrals this person has in the system to the adjust the coupons accordingly. I can't seem to adjust the invoice properly as I get errors in all the ways I have tried, which are:
$inv = {the invoice id and I get no error from the invoice ID being incorrect
define('STRIPE_API_KEY', 'sk_test_******************');
$stripe = new \Stripe\StripeClient(
STRIPE_API_KEY
);
$stripe->invoices->update(
$inv,
['discounts.coupon' => '20OFF']
);
Error is unknown object discounts.coupon
and
$stripe->invoices->update(
$inv,
['discount' => '20OFF']
);
Error = Fatal error: Uncaught (Status 400) (Request req_hsX1QTOxzWMiQn) Received unknown parameter: discount. Did you mean discounts? thrown in /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
and
$stripe->invoices->update(
$inv,
['coupon' => '20OFF']
);
ERROR = Fatal error: Uncaught (Status 400) (Request req_yEwwOLoukR6j6Z) Received unknown parameter: coupon thrown in /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
$stripe->invoices->update(
$inv,
['discounts' => ['coupon' => '20OFF']]
);
Fatal error: Uncaught (Status 400) (Request req_IDRP1Rjv1YoBZR) Invalid array thrown in /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
I'm pretty sure I need to use 'discounts' but don't know how to structure the array to pass the coupon properly.
Trying to predict some questions or comments:
Yes, I do have an existing coupon with id of 20OFF. This is for 20% off
$inv does fetch the correct ID of the invoice at the time the webhook is sent.
Here is the link of the API documentation that I've been reading, but it isn't very helpful.
Instead of:
$stripe->invoices->update(
$inv,
['discounts.coupon' => '20OFF']
);
try:
$stripe->invoices->update(
$inv,
['discounts' => ['coupon' => $couponId]]
);
It looks like it must be the id of the coupon and not the customer facing code, e.g. 20OFF.
You would be able to get the id of the coupon from the dashboard (https://dashboard.stripe.com/coupons/) or by making another api request.
It's
$stripe->invoices->update(
$inv,
[
'discounts' => [
['coupon' => '20OFF']
]
]
);
As in, it's an array that then contains objects (in PHP those are both square brackets) and the objects refer to the coupon.

Fatal Error PHP Class not found but it's included in the project

I'm trying to test Stripe Checkout on my virtual server but when i try return this error:
Fatal error: Class 'Stripe\Customer' not found in
/home/user/public_html/charge.php on line 8
As suggested here I verified if the file ./config.php was existing with:
var_dump(file_exists("./config.php"));
It returns bool(true) being a PhP beginner im not sure what i'm doing wrong.
charge.php
<?php
require_once('./config.php');
var_dump(file_exists("./config.php"));
$token = $_POST['stripeToken'];
$customer = \Stripe\Customer::create(array(
'email' => 'customer#example.com',
'source' => $token
));
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 2000,
'currency' => 'usd'
));
echo '<h1>Successfully charged $20.00!</h1>';
?>
config.php
<?php
require_once('vendor/stripe/init.php');
$stripe = array(
secret_key => getenv('sk_test_PidozakrX1NIEf8YM9TBDMl8'),
publishable_key => getenv('pk_test_pCzekEHR4Io5YFJhrzFE7Koe')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
Directory:
>public_html
>vendor
>stripe
>lib
>Charge.php
>Customer.php
>Stripe.php
UPDATE
Okay so with changes suggested by Matthew getting new error. But i'm not sure where should I set the API key Stripe::setApiKey(<API-KEY>)? It's aleady set in config.php...
Fatal error: Uncaught exception 'Stripe\Error\Authentication' with
message 'No API key provided. (HINT: set your API key using
"Stripe::setApiKey()".in
/home/user/public_html/vendor/stripe/lib/ApiRequestor.php:127 Stack
trace: #0
/home/user/public_html/vendor/stripe/lib/ApiRequestor.php(59):
Stripe\ApiRequestor->_requestRaw('post', '/v1/customers', Array,
Array) #1
/home/user/public_html/vendor/stripe/lib/ApiResource.php(115):
Stripe\ApiRequestor->request('post', '/v1/customers', Array, Array) #2
/home/user/public_html/vendor/stripe/lib/ApiResource.php(155):
Stripe\ApiResource::_staticRequest('post', '/v1/customers', Array,
NULL) #3 /home/user/public_html/vendor/stripe/lib/Customer.php(37):
Stripe\ApiResource::_create(Array, NULL) #4
/home/user/public_html/charge.php(9): Stripe\Customer::create(Array)
5 {main} thrown in /home/user/public_html/vendor/stripe/lib/ApiRequestor.php on line 127
I'm not sure but it looks like due to the composer, If you haven't check path yet , please first look them in composer.json
{
"autoload": {
"psr-0": {
"Sub-folder/path": "class's parent directory "
}
}
NOTE: If the problem occurs due to this one , You should re-install websocketOR you can arrange path to this structure
Yesterday I emailed stripe support. I could of never figured the answer out...! So turns out the issue here is the way I've setup the API keys in config.php. This code will not do what we think... It's trying to retrieve an environment variable set with the variable name as the API key which will just return an empty string...
config.php
<?php
require_once('vendor/stripe/init.php');
$stripe = array(
secret_key => getenv('sk_test_PidozakrX1NIEf8YM9TBDMl8'),
publishable_key => getenv('pk_test_pCzekEHR4Io5YFJhrzFE7Koe')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
should be
<?php
require_once('vendor/stripe/init.php');
$stripe = array(
secret_key => ('sk_test_PidozakrX1NIEf8YM9TBDMl8'),
publishable_key => ('pk_test_pCzekEHR4Io5YFJhrzFE7Koe')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
Basically, just remove getenv after each arrow. For me it works! The customer is created and the amount is charged! Nothing fancy. Simple solution.

How to delete an event in vtiger using REST APIs and where to get WEBSERVICE_ID from?

I want to delete an event in Vtiger Calendar using REST APIs. I'm trying the following:
POST /webservice.php HTTP/1.1
operation=delete
sessionName=sessionId // Obtained through Login Operation
id=<WEBSERVICE_ID>
but I don't know what WEBSERVICE_ID is and where to find it.
When I create an event using REST-API it returns an array with the following data:
{"subject":"Follow up Test","assigned_user_id":"49x1","date_start":"2016-06-17","time_start":"09:00:00","time_end":"18:00:00","due_date":"2016-06-17","recurringtype":"","parent_id":"","contact_id":"","taskstatus":"","eventstatus":"Planned","taskpriority":"High","sendnotification":"0","createdtime":"2016-06-23 11:18:20","modifiedtime":"2016-06-23 11:18:20","activitytype":"Event","visibility":"","duration_hours":"9","duration_minutes":"0","location":"","notime":"0","modifiedby":"49x1","created_user_id":"49x1","source":"WEBSERVICE","starred":"0","tags":"","reminder_time":"","description":"Test Description","id":"1x5748","label":"Follow up Test"}
There is an id in the array ("id":"1x5748"), but when I try to use the id as a WEBSERVICE_ID in the delete operation I'm getting the following error:
Fatal error: Uncaught exception 'Exception' with message 'Error: Id specified is incorrect'
Run this query: SELECT id, nameFROM vtiger_ws_entity
Whith this your objectTypeId is a id for module
Get the record id
concatenate 1And2 for example: EVENTS module='18' AND record id=61900, then the ID that you need is: 18x61900;
I use this code for delete entity
$params = array(
//"id" => "35789",
"id" => "18x61900",
);
$record = $client->doInvoke("delete", $params, "POST");

php salesforce novice INVALID_FIELD: No such column 'fields' on entity 'Contact'

I am having a tough time and have spent like 4 hrs trying to debug this. I am new to PHP, but did not expect this to be so hard.
This is the code, i am trying to update a contact table. i tried upsert and update nothign seems to work
this is the update" version of the code.
$id = '003A000000XRVFxIAP';
$updateFields = array (
'Id' => $id,
'MailingCity' => 'New York',
'MailingState' => 'NY'
);
$sObject1 = new SObject();
//$sObject1->fields = $updateFields;
//$sObject1->MailingCity= 'New York';
$sObject1->type = 'Contact';
try{
$updateResponse = $client->update(array($sObject1),'Contact');
$myID = $updateResponse->id;
}
Strict Standards: Creating default object from empty value in C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceEnterpriseClient.php on line 89 INVALID_FIELD: No such column 'fields' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. Error Info SoapFault exception: [sf:INVALID_FIELD] INVALID_FIELD: No such column 'fields' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. in C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceBaseClient.php:508 Stack trace: #0 C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceBaseClient.php(508): SoapClient->__call('update', Array) #1 C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceBaseClient.php(508): SoapClient->update(Object(stdClass))
#2 C:\xampp\htdocs\Proj1\ForceToolkit\soapclient\SforceEnterpriseClient.php(90): SforceBaseClient->_update(Object(stdClass))
#3 C:\xampp\htdocs\Proj1\createAccount.php(95): SforceEnterpriseClient->update(Array, 'Contact') #4 {main}
Looking at your trace you appear to be using the enterprise client and I can assume enterprise WSDL. This is strongly typed and you should be using the WSDL specific to your Salesforce org. If you are not using the WSDL downloaded from your org it will not have the correct objects and fields defined within it.
I would recommend using the partner client and partner WSDL. This is loosely typed and far more flexible. It would be easier to work with particularly if you aren't familiar with the PHP or the webservices.
The following should do your update...
$sObject1 = new stdClass();
$sObject1->type = 'Contact';
$sObject1->Id = $id;
$sObject1->fields['MailingCity'] = 'New York';
$sObject1->fields['MailingState'] = 'NY';
try
{
$updateResponse = $client->update( array( $sObject1 ) );
}
catch( Exception $exception )
{
// Do something
}
Note that the Id is a property of $sObject and not a value in the fields array. Also there is no need to specify the 'Contact' in your update call as you have it set in the type property of $sObject.
When using the Enterprise WSDL, don't create a new SObject, just create a new stdClass. See the examples in the PHP Getting Started Guide; SObjects are only for use with the partner WSDL.
I have encountered the same issue updating while using the Enterprise client. I experienced the same issue while updating a custom field on an Account object.
The issue that I had with the SObject was that it tried to update a parameter called 'fields' during the update. With the Enterprise WSDL not including that field, I used unset() to remove the 'fields' attribute from the SObject.
I appreciate this is a bit of a hacky solution, but it could come in useful for others that encounter this issue.
$sUpdateObject = new SObject();
$sUpdateObject->id = $record->Id;
$sUpdateObject->MyCustomField__c = 0;
unset($sUpdateObject->fields);
$updateResponse = $mySforceConnection->update(array($sUpdateObject), 'Account');
print_r($upsertResponse);

Categories