Fatal error with Stripe Checkout: Class 'Stripe' not found - payment

I'm trying to implement Stripe Checkout into my website. I am using Composer, everything seems to go right, but when I add my private key into init.php line 17:
Stripe::setApiKey($stripe['private']);
PHP shows me the following error:
Fatal error: Class 'Stripe' not found in/Applications/MAMP/htdocs/stripe_payment/app/init.php on line 17
Here is the full file:
<?php
session_start();
//composer auto load
require_once 'vendor/autoload.php';
$_SESSION['user_id'] = 3;
$stripe = [
'publishable' => '..... my test key.....',
'private' => '..... my test key.....'
];
//when added brakes the code
Stripe::setApiKey($stripe['private']);
$db = new PDO('mysql:host=localhost;dbname=stripe_custom;','root','root');
$userQuery = $db->prepare("
SELECT id, username, email, premium
FROM users
WHERE id = :user_id
");
$userQuery->execute(['user_id' => $_SESSION['user_id']]);
$user = $userQuery->fetchObject();
?>
I presume that this is something small, but I'm a beginner and I can't figure it out. What am I doing wrong?

The latest releases of Stripe's PHP bindings (2.*) are now using Namespaces. This means that most of the API calls have now changed and for example:
Stripe::setApiKey("sk_test_XXX");
Stripe_Customer::create();
would become:
\Stripe\Stripe::setApiKey("sk_test_XXX");
\Stripe\Customer::create();
Otherwise, if you don't want to have to update your code you need to make sure that you download the legacy version (1.18.0).

Related

PHP Stripe customers->search not finding accurate results

I'm having difficulty with STRIPE customer->search returning incorrect results sometimes.
If I search for a customer, and if it does not exist then add it, then repeat - I can find it adds the customer a second/third/fourth/etc times - for a while. Meanwhile on the stripe dashboard, I can see the customers appearing [multiple times].
If I waited a few minutes between initial refreshes - it seems ok.
Perhaps there's a cache, or a lag or something between adding a customer and the search finding it but this is not very helpful. Am I wrong - or is there something I'm not doing?
The relevant PHP code is here:
$stripe = new \Stripe\StripeClient($stripe_secretkey);
echo "<LI>Searching for $customerNm...</LI>";
$json = $stripe->customers->search(['query' => 'name:\'' . $customerNm . '\'']);
foreach ($json->data as $key) {
echo "<LI>Found id:[" . $key->id . "]";
if (strcmp($key->name, $customerNm) == 0) {
$customerId = $key->id;
$email = $key->email;
break;
}
}
echo "<hr>";
if (strcmp($customerId, "") == 0) {
echo "<LI>Result to search is <PRE style='margin-left:20px'>$json</PRE>";
$email = str_replace(" ", "", str_replace(" ", "", "abc#$customerNm.com"));
$json = $stripe->customers->create(
[
'email' => $email,
'name' => $customerNm,
]);
$customerId = $json->id;
echo "<UL>Created New STRIPE customer id: [$customerId]</UL>\n";
}
}
This code can be found running on a sandbox here** where if you were to run the page multiple times - it will keep creating customers [for a while].
(Note, this page will create a cookie "posterUID" which is used as the customer name; once it's created then it stays until expiry or manual deletion).
** The full source to this can be seen here
This is expected behavior per Stripe's Search documentation:
Don’t use search for read-after-write flows (for example, searching immediately after a charge is made) because the data won’t be immediately available to search. Under normal operating conditions, data is searchable in under 1 minute. Propagation of new or updated data could be more delayed during an outage.

Project Server Online CSOM - GeneralSecurityAccessDenied while reading TimePhase Assignments

This is my first SO question so please let me know if this question is not very clear or if I am missing anything.
FYI SO prevented me from attaching links, so sorry for all the bad formatting.
Overview
I'm trying to read (and write) the "Actual work" for a resource in Project Server Online by using the CSOM library available by Microsoft. Reading and writing the assignments and Actual work is working perfectly, as long as I am reading the assignments for the currently authenticated user. If I attempt to read this for another resource, I receive a GeneralSecurityAccessDenied error.
I've done this in the past using Impersonation, which is supposed to be called transparently in the background if the user has the StatusBrokerPermission, but it doesn't seem to be working for me. Impersonation has been removed in 2013+, so that's no longer an option.
Problem summary
The CSOM is supposed to transparently enable statusing extensions to allow status updates to be made for resources other than the currently authenticated user (as long as the user has the status broker permission). This works fine for adding new assignments, but does not work when trying to update actual TimePhased hours via the TimePhased assignments. The assignments cannot be queried, and thus, we cannot call SubmitAllStatusUpdates to submit the hours.
Research
Usage scenarios for the CSOM: https:// msdn.microsoft.com/en-us/library/office/jj163082(v=office.15).aspx#pj15_WhatTheCSOM_UsageScenarios
Impersonation Deprecated: https:// msdn.microsoft.com/en-us/library/office/ee767690(v=office.15).aspx#pj15_WhatsNew_Deprecated)
Picture: Supposed to read on behalf of another user...
People with the same problem # 1: https:// social.technet.microsoft.com/Forums/projectserver/en-US/dccdb543-18a1-4a0e-a948-5d861305516e/how-to-get-resource-assignments-summary-view-data-project-server-online-2013?forum=projectonline)
People with the same problem # 2: http:// uzzai.com/ZB43wp95/ps2013-app-how-to-read-and-update-timephased-data-with-jsom-javascript-csom.html
People with the same problem # 4: https:// social.technet.microsoft.com/Forums/Sharepoint/en-US/be27d497-e959-44b6-97cb-8f19fe0278fe/csom-how-to-set-timephase-data-on-an-assignment?forum=project2010custprog
Other things I've tried
Using the CSOM with the MsOnlineClaimsHelper to retrieve the FedAuth cookies for a user (and assigning them using the CookieContainer).
Using the REST/OData API.
a) https:// URL.sharepoint.com/sites/pwa/_api/ProjectServer/EnterpriseResources('c39ba8f1-00fe-e311-8894-00155da45f0e')/Assignments/GetTimePhaseByUrl(start='2014-12-09',end='2014-12-09')/assignments
Enabling the "StatusBrokerPermission" for the user
Unchecking the “Only allow task updates via Tasks and Timesheets.” Option within the server settings screen (Task settings and display).
Creating a SharePoint-hosted app and using JSOM code equivalent to the CSOM code above.
a) The code we wrote was JavaScript being executed from within SharePoint app, so we did not need to provide authentication. The user who was logged in had the StatusBrokerPermission.
Using a Provider-hosted SharePoint app and using the CSOM code above. We tried using all authentication methods for CSOM above, with an additional test:
a) using Fiddler to view the FedAuth cookies being set by the SharePoint app authentication, and overriding the WebRequest to manually insert the FedAuth/rtFA cookies: webRequestEventArgs.WebRequestExecutor.WebRequest.CookieContainer = getStaticCookieContainer();
Using timesheets to submit time phased data.
a) We can only create a timesheet for the currently-authenticated user, and cannot populate timesheet lines with projects / assignments not available to him (or a GeneralItemDoesNotExist error is thrown).
Manually issuing a “SubmitAllStatusUpdates” CSOM request using fiddler, as a different user.
a) The purpose of this test was to determine if we can write time phased data, even if we can’t read it.
Making sure the project was checked out to the current user.
Using administrative delegation for a resource.
Setting all available options within project permissions.
Using the Project Web UI to enter the TimePhased data for other resources.
Using SharePoint permission mode instead of Project Permission Mode.
The code
See failing code screenshot here
using System;
using System.Security;
using Microsoft.ProjectServer.Client;
using Microsoft.SharePoint.Client;
namespace ProjectOnlineActuals
{
static class Program
{
const string projectSite = "https://URL.sharepoint.com/sites/pwa/";
private const string edward = "c39ba8f1-00fe-e311-8894-00155da45f0e";
private const string admin = "8b1bcfa4-1b7f-e411-af75-00155da4630b";
static void Main(string[] args)
{
TestActuals();
}
private static void TestActuals()
{
Console.WriteLine("Attempting test # 1 (login: admin, resource: admin)");
TestActuals("admin#URL.onmicrosoft.com", "123", admin);
Console.WriteLine("Attempting test # 2 (login: admin, resource: edward)");
TestActuals("adminy#hmssoftware.onmicrosoft.com", "123", edward);
Console.ReadLine();
}
private static void TestActuals(string username, string password, string resourceID)
{
try
{
using (ProjectContext context = new ProjectContext(projectSite))
{
DateTime startDate = DateTime.Now.Date;
DateTime endDate = DateTime.Now.Date;
Login(context, username, password);
context.Load(context.Web); // Query for Web
context.ExecuteQuery(); // Execute
Guid gResourceId = new Guid(resourceID);
EnterpriseResource enterpriseResource = context.EnterpriseResources.GetByGuid(gResourceId);
context.Load(enterpriseResource, p => p.Name, p => p.Assignments, p => p.Email);
Console.Write("Loading resource...");
context.ExecuteQuery();
Console.WriteLine("done! {0}".FormatWith(enterpriseResource.Name));
Console.Write("Adding new resource assignment to collection...");
enterpriseResource.Assignments.Add(new StatusAssignmentCreationInformation
{
Comment = "testing comment - 2016-02-17",
ProjectId = new Guid("27bf182c-2339-e411-8e76-78e3b5af0525"),
Task = new StatusTaskCreationInformation
{
Start = DateTime.Now,
Finish = DateTime.Now.AddDays(2),
Name = "testing - 2016-02-17",
}
});
Console.WriteLine("done!");
Console.Write("Trying to save new resource assignment...");
enterpriseResource.Assignments.Update();
context.ExecuteQuery();
Console.WriteLine("done!");
Console.Write("Loading TimePhase...");
TimePhase timePhase = enterpriseResource.Assignments.GetTimePhase(startDate.Date, endDate.Date);
context.ExecuteQuery();
Console.WriteLine("done!");
Console.Write("Loading TimePhase assignments...");
context.Load(timePhase.Assignments);
context.ExecuteQuery();
Console.WriteLine("done! Found {0} assignments.".FormatWith(timePhase.Assignments.Count));
Console.WriteLine("Updating TimePhase assignments...");
foreach (var assignment in timePhase.Assignments)
{
Console.WriteLine("Updating assignment: {0}. ActualWork: {1}".FormatWith(assignment.Name, assignment.ActualWork));
assignment.ActualWork = "9h";
assignment.RegularWork = "3h";
assignment.RemainingWork = "0h";
}
timePhase.Assignments.SubmitAllStatusUpdates("Status update comment test 2016-02-17");
context.ExecuteQuery();
Console.WriteLine("done!");
Console.WriteLine("Success (retrieved & updated {0} time phase assignments)!".FormatWith(timePhase.Assignments.Count));
}
}
catch (Exception ex)
{
if (ex.ToString().Contains("GeneralSecurityAccessDenied"))
Console.WriteLine("ERROR! - GeneralSecurityAccessDenied");
else
throw;
}
finally
{
Console.WriteLine();
Console.WriteLine();
}
}
private static void Login(ProjectContext projContext, string username, string password)
{
var securePassword = new SecureString();
foreach (char c in password)
securePassword.AppendChar(c);
projContext.Credentials = new SharePointOnlineCredentials(username, securePassword);
}
static string FormatWith(this string str, params object[] args)
{
return String.Format(str, args);
}
}
}
Can anyone help??

Scheduled CSV Import's Deployement Error In Netsuite

I tried to update the employees record in an Netsuite system using the Scheduled CSV Import.
while deploying the Scheduled Script, I put the status has "Testing" and click "Save & Execute" Button for testing purpose.
And then I checked the Execution Log in the Log it shows the following error message:
" com.netledger.app.common.scripting.version1.nlobjCSVImportImplV1"
Scheduled Script Code:
function scheduled(type) {
var fileId = nlapiGetContext().getSetting('SCRIPT', 'custscript_sfg_customer_rec_cus_param');
nlapiLogExecution('DEBUG','fileId:',fileId);
var import1 = nlapiCreateCSVImport();
nlapiLogExecution('DEBUG','import1:',import1);
var mapping = import1.setMapping('CUSTIMPORT_emp_rec_imp');
// Internal id for mapping
nlapiLogExecution('DEBUG','mapping:',mapping);
var setPrimary = import1.setPrimaryFile(nlapiLoadFile(fileId));
// id is Internal id for Employee file
nlapiLogExecution('DEBUG','setPrimary:',setPrimary);
var submitImport = nlapiSubmitCSVImport(import1);
// Importing is Done
nlapiLogExecution('DEBUG','submitImport:',submitImport);
}
Help me to find the solution for creating the scheduled CSV Import.
Thanks in Advance.
There are a couple of possible issues with your code:
When I have done this I've used all lower case for the import id. e.g. use 'customimport_emp_rec_imp' not 'CUSTIMPORT_emp_rec_imp'
Make sure the saved csv import definition is public
Set a job name with import1.setOption("jobName", "Employee Import");

Class 'Horde_String' not found in \pear\Horde\Text\Diff.php

I am trying to set up a class for tracking changes in the content by different authors. I did RnD and found text_Diff is the pear package which is responsible for the same. Later, text_diff is maintained at
'http://pear.horde.org/'
I am now trying to run the example
include_once "Text/Diff.php";
include_once "Text/Diff/Renderer.php";
$from_text=file('file.html');
$to_text=file('file_edited.html');
$diff = new Horde_Text_Diff($from_text, $to_text);
$renderer = new Horde_Text_Diff_Renderer();
echo $renderer->render($diff);
and I am getting the error 'Horde_String'
I am not able to find class, any one has idea about this class?. There are multiple Engine like "Native","XDiff","String" and "Shell" ...but I am not able to find what are they and when you use which one..
any help to resolve this error will be a great help.
Thanks
I struggled for hours trying to get this to work. In the end I had to install Horde_Text_Diff by entering the commands (installs the Autoloader described in the linked question in the comment by Keelan):
pear install Horde_Autoloader
pear install Horde_Text_Diff
This installs the packages I believe you need. Then, you need to properly call the autoloader package by tweaking the following code to match the paths for your system.
require_once 'Horde/Autoloader.php';
require_once 'Horde/Autoloader/ClassPathMapper.php';
require_once 'Horde/Autoloader/ClassPathMapper/Default.php';
$autoloader = new Horde_Autoloader();
$autoloader->addClassPathMapper( new Horde_Autoloader_ClassPathMapper_Default('/usr/share/pear') );
$autoloader->registerAutoloader();
Then, if all goes well you should be able to call and use the class by doing something like the following:
$check_diff = new Horde_Text_Diff( $engine = 'auto', $params = array( $from_text, $to_text ) );
$renderer = new Horde_Text_Diff_Renderer_Inline();
echo $renderer->render($check_diff);
Although this isn't totally working for me yet as I'm finding that it only compares the first characters in the strings. Which is a new problem unrelated to getting the class to work :)
Here is my approach, which does not use the Hoard autoloader:
spl_autoload_register(function ($class_name) {
if (substr($class_name, 0, strlen('Horde_')) != 'Horde_')
return false;
$file = substr($class_name, strlen('Horde_')); // omit if not needed
$file = str_replace("_", DIRECTORY_SEPARATOR, $file);
return include_once($file . '.php');
});
function diff($old, $new)
{
$td = new Horde_Text_Diff('auto', array($old, $new));
$rend = new Horde_Text_Diff_Renderer_Unified();
return $rend->render($td);
}

Drupal autocomplete fails to pull out data as a subdomain

I managed to pull out data using autocomplete at my local (http://mysite.dev/swan/autocomplete). The json data is displayed.
But when I applied the same module at live (now a subdomain: http://test.mysite.com/swan/autocomplete with different drupal installs), this autocomplete fails to pull out data. No json data is displayed.
Do you have any idea if this is related to cross domain issue, or any possible cause I might not be aware of?
This is the callback:
/**
* Callback to allow autocomplete of organisation profile text fields.
*/
function swan_autocomplete($string) {
$matches = array();
$result = db_query("SELECT nid, title FROM {node} WHERE status = 1 AND type='organisation' AND title LIKE LOWER ('%s%%')", $string, 0, 40);
while ($obj = db_fetch_object($result)) {
$title = check_plain($obj->title);
//$matches[$obj->nid] = $title;
$matches[$title] = $title;
}
//drupal_json($matches); // fails at safari for first timers
print drupal_to_js($matches);
exit();
}
Any hint would be very much appreciated.
Thanks
It's the conflict with password_policy.module. Other similar modules just do the same blocking. These modules stop any autocomplete query.

Resources