Recurly subscription object not found - php

I have a form where the user can enter their credit information. When they submit I keep getting 'Object not found'.
I checked the keys and subdomain everything is correct. What could be the issue?
public function createSubscription($plan,$token,$email,$fname,$lname,$currency,$starts_at,$company_name)
{
try {
$subscription = new \Recurly_Subscription();
$subscription->plan_code = $plan;
$subscription->currency = $currency;
$subscription->starts_at = $starts_at;
$account = new \Recurly_Account();
$account->account_code = $email;
$account->first_name = $fname;
$account->last_name = $lname;
$account->email = $email;
$account->company_name = $company_name;
$billing_info = new \Recurly_BillingInfo();
$billing_info->token_id = $token;
$account->billing_info = $billing_info;
$subscription->account = $account;
$subscription->create();
}
catch (\Recurly_ValidationError $e){
throw new CreditDeclined($e->getMessage());
}
catch ( \Exception $e) {
throw new InvalidGeneral($e->getMessage());
}
}

The two things I'd check first are that the plan code and billing token are valid.
The other thing to check is that you've loaded our PHP libraries. You need to have this someplace in your code:
require_once('lib/recurly.php');

Require the lib/recurly.php script and setup your authentication credentials:
<?php
require_once('lib/recurly.php');
// Required for the API
Recurly_Client::$subdomain = 'your-subdomain';
Recurly_Client::$apiKey = 'abcdef01234567890abcdef01234567890';
?>
It should be correct.Please re-check.

Related

PHP: Script failing after PDO query

During my create user process I make a few queries to various database's to get the new user setup. This script has been working fine for about a year and a half, but now something is off.
So the first thing I do is I check to see if a user exists with the credentials being submitted. I've thoroughly tested the check and I'm confident my issue isn't there.
If that check comes back false then the script continues to create the user.
public function registerUser() {
parse_str($_SERVER['QUERY_STRING'], $data);
$data = (object) $data;
$check = json_decode($this->checkUserExists($data->email));
if ($check->res) {
$res = new \stdClass();
$res->res = false;
$res->user_status = $check->user_status;
$res->msg = 'User exists.';
echo json_encode($res);
}
if (!$check->res) {
$this->createUser($data);
}
}
The problem arises after all the queries have been completed, the script does not seem to want to run the if statement at the bottom. I marked it with comment characters so it's easier to find, but I included the entire function for clarity, maybe I'm doing something that is causing the issue.
I tried invoking an error manually at various points during the script. And I am able to trigger an error all the way down to the bottom of the script.
private function createUser($data) {
$Crypt = new CryptController();
$AuthSelect = new AuthController();
$Time = new TimeController();
$remote_address = new RemoteAddressController();
$Session = new SessionController();
$AuthInsert = new AuthModel_Insert();
$hashed_password = $Crypt->create_hash($data->password);
$data->password = '';
$AuthData = json_decode($AuthSelect->getAuth());
$system_auth_id = $AuthData->system_auth_id;
$user_id = $Crypt->get_uuid();
$user_auth_id = $Crypt->get_uuid();
$user_createddate = $Time->time();
$user_updateddate = $Time->time();
$user_lastupdateddate = $Time->time();
$agent_ip = $remote_address->getIpAddress();
$userData = $this->createUserObject(
$user_id,
$user_auth_id,
$system_auth_id,
$hashed_password,
$user_createddate,
$user_updateddate,
$user_lastupdateddate,
$data
);
$agentData = $this->createAgentObject(
$user_id,
$agent_ip,
$data
);
//////////////////////////////////////////
$create_user = $AuthInsert->createNewUser(
$userData
);
$create_user_agent = $this->setUserAgent(
$agentData
);
$sessionKeyData = new \stdClass();
$sessionKeyData->user_id = $user_id;
$sessionKeyData->user_auth_id = $user_auth_id;
$sessionKeyData->system_auth_id = $system_auth_id;
$sessionKeyData->agent_id = $create_user_agent->agent->agent_id;
$set_session_key = $Session->setSessionKey(
$sessionKeyData
);
$send_activation_email = $this->createUserActivation(
$userData
);
if (
$create_user &&
$create_user_agent->res &&
$set_session_key->res &&
$send_activation_email->res) {
$res = new \stdClass();
$res->res = true;
$res->msg = 'New user successfully created.';
echo json_encode($res);
} else {
$res = new \stdClass();
$res->res = false;
$res->msg = 'Error: User creation process incomplete.';
echo json_encode($res);
}
//////////////////////////////////////////
trigger_error("Invoked Error: ",E_USER_ERROR);
}
The queries themselves go through just fine, all the tables are populated just fine. The issue is that after that happens the script doesn't finish. It seems to end the createUser() function and return to the registerUser() function at which point the user will exist so it will return false and echo that back to the client.
In my testing it seems my issue might be at the bottom with that if statement. But I've tested each of those queries individually and they do return the desired booleans to get the true condition. But, even the false condition doesn't go through which should return 'Error: User creation process incomplete.'. That doesn't happen either.
I'm hoping someone sees something I'm missing because I've been stuck on this problem for too long. I appreciate any guidance that might lead me to an answer. Thanks in advance.
Just for clarification the message I'm getting back is $res->msg = 'User exists.'; which comes from registeruser(). The message I'm expecting back is $res->msg = 'New user successfully created.'; which should come from createUser().

PHP vTiger6 Issue creating account with vtwsclib

I am trying to figure out how to programmatically create a "Account" in vTiger6.5 using its Web Services API.
I am currently using the official vtwsclib v1.5 PHP Library. The log in, appears to succeed and I can also successfully perform a doDescribe on the module, however doCreate returns 'false' no matter what I do.
Sample below. Am I missing anything?
$url = 'http://vtiger.mydomain.com/';
$client = new Vtiger_WSClient($url);
$login = $client -> doLogin('systemuser', 'O8nFgnotrealkey');
if (!$login)
echo 'Login Failed';
else {
$module = "Accounts";
$record = $client -> doCreate($module, Array('accountname'=>'S1',
'account_type'=>'Prospect', 'phone'=>'75584'));
if ($record) {
$recordid = $client -> getRecordId($record['id']);
}
}
Returns:
$record: bool(false)
With $client->lastError() i now what my error ,I have create same mandatory fields
$module = 'Accounts';
$record = $client->doCreate($module, Array('accountname'=>'c2', 'account_type'=>'Prospect', 'industry'=>'444', 'phone'=>'4555',cf_753=>'Code',cf_755=>'45588','assigned_user_id' => '14x4'));
if($record) {
echo "done";
//$recordid = $client->getRecordId($record['id']);
//echo "Record ".$recordid;
}
else {
$wasError= $client->lastError();
if($wasError) {
echo "</br>last error : ".$wasError['code'] . ':' . $wasError['message'];
}
}

Magento forget Password soap API

everyone I am new here.
I stuck with Magento API.I am creating Magento API for my e-commerece site.I have created all API but for forget password API I am not getting any solution. I have used default forget password controller but it didn't send me an email with change password link check my code and please help me to set this forget password API.I have also search all the documents but getting any answer. I have also post my code so please refer it and let me know that where is I have mistake.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$email = $_REQUEST['email'];
require_once ('../app/Mage.php');
Mage::app();
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->loadByEmail($email);
//print_r($customer);
if ($customer->getId()) {
try {
$newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();
$customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
$customer->setStoreId(Mage::app()->getStore()->getId());
$customer->sendPasswordResetConfirmationEmail();
$response['response'] = "success";
$response['message']="Password Reset Link Has Been Sent to Your Email Please Check, Your Mail Box!";
echo json_encode($response);
} catch (Exception $exception) {
Mage::log($exception);
}
}else{
$response['response'] = "failed";
$response['message']="Please Enter a Valid Email!";
echo json_encode($response);
}
?>
Recently i worked on forget password magento api it work fine but only difficult i find that i have to save my forget password file name to index.php. make one api folder and save it with name of index.php
<?php
if(!empty($_REQUEST['email']))
{
$yourCustomerEmail=$postcode = $_REQUEST['email'];
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->loadByEmail($yourCustomerEmail);
//echo $customer->getId();
if ($customer->getId()) {
try {
$newResetPasswordLinkToken = Mage::helper('customer')->generateResetPasswordLinkToken();
$customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
$customer->sendPasswordResetConfirmationEmail();
$result = array('action'=> 'send','statuscode'=> '200');
echo json_encode($result);
} catch (Exception $exception) {
//echo "Exception";
Mage::log($exception);
}
}
else
{
$result = array('action'=> 'failed','statuscode'=> '300');
echo json_encode($result);
}
}
else
{
$result = array('action'=> 'failed','statuscode'=> '300');
echo json_encode($result);
}
?>

Undefined variable with OpenID

I have a website running on a less well known CMS called Ushahidi. There is built in OpenID functionality where folk can login with Facebook or Google.
I don't have enough dev skills to understand whats happening here but, it appears that I've almost got it working, except, I'm receiving the following error when trying to test it out on my own Google login:
An error was detected which prevented the loading of this page. If
this problem persists, please contact the website administrator.
application/controllers/login.php [503]: Undefined variable: user
I suspect, but am not sure, that defining a variable is easy enough but since I lack the knowledge I hoped to ask someone on here if they could see where I need to define the variable. Line 503 is part of a larger code block of about 100 lines, I know that it's not good practice to post larger chunks of code on here but I'm really unsure of what is and is not relevant. So forgive me. I have highlighted in bold where line 503 is. Can anyone point out what I must do here?
// OpenID Post
try
{
$openid = new OpenID;
// Retrieve the Name (if available) and Email
$openid->required = array("namePerson", "contact/email");
if( ! $openid->mode)
{
if(isset($_POST["openid_identifier"]))
{
$openid->identity = $_POST["openid_identifier"];
header("Location: " . $openid->authUrl());
}
}
elseif ($openid->mode == "cancel")
{
$openid_error = TRUE;
$message_class = 'login_error';
$message = "You have canceled authentication!";
}
else
{
if ($openid->validate())
{
// Does User Exist?
$openid_user = ORM::factory("openid")
->where("openid", $openid->identity)
->find();
if ($openid_user->loaded AND $openid_user->user)
{
// First log all other sessions out
$auth->logout();
// Initiate Ushahidi side login + AutoLogin
$auth->force_login($openid_user->user->username);
// Exists Redirect to Dashboard
**(THIS IS LINE 503)** url::redirect($user->dashboard());
}
else
{
// Does this openid have the required email??
$new_openid = $openid->getAttributes();
if ( ! isset($new_openid["contact/email"]) OR
empty($new_openid["contact/email"]))
{
$openid_error = TRUE;
$message_class = 'login_error';
$message = $openid->identity . " has not been logged in. No Email Address Found.";
}
else
{
// Create new User and save OpenID
$user = ORM::factory("user");
// But first... does this email address already exist
// in the system?
if ($user->email_exists($new_openid["contact/email"]))
{
$openid_error = TRUE;
$message_class = 'login_error';
$message = $new_openid["contact/email"] . " is already registered in our system.";
}
else
{
$username = "user".time(); // Random User Name from TimeStamp - can be changed later
$password = text::random("alnum", 16); // Create Random Strong Password
// Name Available?
$user->name = (isset($new_openid["namePerson"]) AND ! empty($new_openid["namePerson"]))
? $new_openid["namePerson"]
: $username;
$user->username = $username;
$user->password = $password;
$user->email = $new_openid["contact/email"];
// Add New Roles
$user->add(ORM::factory('role', 'login'));
$user->add(ORM::factory('role', 'member'));
$user->save();
// Save OpenID and Association
$openid_user->user_id = $user->id;
$openid_user->openid = $openid->identity;
$openid_user->openid_email = $new_openid["contact/email"];
$openid_user->openid_server = $openid->server;
$openid_user->openid_date = date("Y-m-d H:i:s");
$openid_user->save();
// Initiate Ushahidi side login + AutoLogin
$auth->login($username, $password, TRUE);
// Redirect to Dashboard
url::redirect($user->dashboard());
}
}
}
}
else
{
$openid_error = TRUE;
$message_class = 'login_error';
$message = $openid->identity . "has not been logged in.";
}
}
}
catch (ErrorException $e)
{
$openid_error = TRUE;
$message_class = 'login_error';
$message = $e->getMessage();
}
The problem is that the code is using $user several lines before it's actually defined. It might be a typo, though - maybe $openid_user->user->dashboard() at line 503 might work, though it's a WAG.

PHP Worldpay Payment Response Example

I am developing a site for a client and one of the requirements is to integrate worldpay payments for the purchasing process.
Once the user has completed payment for a product I need to alert a licencing system to the completed payment. The worldpay documentation gives an overview of the payment response service but does not give a code example.
I have had the client set up the payment response option in their test installation but would rather not have to go about coding my own page to handle the response if someone else has already done it. Does anyone have a link to a good code example (in php)?? I have had a decent look online and have not turned up much.
Thanks!
Problem solved. I ended up creating a custom class to handle the response from worldpay. Here is a simplified version of my handler page in case anyone else might find it useful.
(Note: I am not really a php developer so some syntax might be a bit dodgy!)
<?php //Worldpay
// class definition
class WorldPay_Response {
// define properties
public $transaction_id = null;
public $transaction_status = null;
public $transaction_time = null;
public $authorisation_amount = null;
public $authorisation_currency = null;
public $authorisation_amount_string = null;
public $raw_auth_message = null;
public $raw_auth_code = null;
public $callback_password = null;
public $card_type = null;
public $authentication = null;
public $ip_address = null;
public $character_encoding = null;
public $future_payment_id = null;
public $future_payment_status_change = null;
//custom properties not included by worldpay
public $mc_custom_property = null;
// constructor
public function __construct() {
$this->transaction_id = $_POST['transId'];
$this->transaction_status = $_POST['transStatus']; //should be either Y (successful) or C (cancelled)
$this->transaction_time = $_POST['transTime'];
$this->authorisation_amount = $_POST['authAmount'];
$this->authorisation_currency = $_POST['authCurrency'];
$this->authorisation_amount_string = $_POST['authAmountString'];
$this->raw_auth_message = $_POST['rawAuthMessage'];
$this->raw_auth_code = $_POST['rawAuthCode'];
$this->callback_password = $_POST['callbackPW'];
$this->card_type = $_POST['cardType'];
$this->country_match = $_POST['countryMatch']; //Y - Match, N - Mismatch, B - Not Available, I - Country not supplied, S - Issue Country not available
$this->waf_merchant_message = $_POST['wafMerchMessage'];
$this->authentication = $_POST['authentication'];
$this->ip_address = $_POST['ipAddress'];
$this->character_encoding = $_POST['charenc'];
$this->future_payment_id = $_POST['futurePayId'];
$this->future_payment_status_change = $_POST['futurePayStatusChange'];
//custom properties
$this->mc_custom_property = $_POST['MC_custom_property'];
}
}
?>
<html>
<head><title>Thank you for your payment</title></head>
<WPDISPLAY FILE="header.html">
<?php
//Response from Worldpay
$wp_response = new WorldPay_Response();
if($wp_response->transaction_status == "Y"){ ?>
<strong>Transaction Details</strong><br />
<?php
echo "Worldpay Transaction id: " . $wp_response->transaction_id . "<br />";
echo "Payment Status: " . $wp_response->transaction_status . "<br />";
echo "Transaction Time: " . $wp_response->transaction_time . "<br />";
echo "Amount: " . $wp_response->authorisation_amount_string . "<br />";
echo "IP Address: " . $wp_response->ip_address . "<br /><br />";
}else if($wp_response->transaction_status == "C") { ?>
<strong>Transaction Cancelled</strong>
<?php } else { ?>
Your transaction was unsuccessful.
<?php } ?>
<WPDISPLAY ITEM="banner">
<WPDISPLAY FILE="footer.html">
</html>
For others who are reading this from a Google search, re: worldpay Payment response.
March 2015:
I am setting up a worldpay online payment system for a client and damn, it's terrible. They have made a mediocre system in 2011 and not bothered updating it since. It is tedious and the code examples and documentation leaves a LOT to be desired.
Worldpay still use MD5() hashing as a "highly secure method of encryption" and are still referencing various resources and server concepts that are no longer used. From a practical programming point of view DO NOT USE WORLDPAY .
They have no documentation to handle dynamic payments and still expect each payment to be completed by me sending them a .html file for them to display, rather than them sending the customer back to my website to output dynamic code.
I would never touch WorldPay after this work, but my client has already paid them for signing up with them, and so I have to implement this for him. :-/
Their customer service (UK) is also very poor.
looks a lot like paypal. basically server<>server stuff. they have their 9 yards here. http://www.worldpay.com/support/kb/bg/pdf/custa.pdf are you looking for a full blown buy service center? b/c just receiving with a simple notification is a page or so. google has some open source stuff. http://code.google.com/p/opencart/source/browse/trunk/upload/catalog/language/english/payment/worldpay.php?spec=svn694&r=694. just google worldpay.php. if you find something, LET US KNOW. we have been considering offering WORLDPAY to our clients. My how they have changed in the last 5 years.
small class extension to the TGuimond - WorldPay_Response class:
<?php //Worldpay
class WorldPay_Response {
// define properties
public $transaction_id = null;
public $transaction_status = null;
public $transaction_time = null;
public $authorisation_amount = null;
public $authorisation_currency = null;
public $authorisation_amount_string = null;
public $raw_auth_message = null;
public $raw_auth_code = null;
public $callback_password = null;
public $card_type = null;
public $authentication = null;
public $ip_address = null;
public $character_encoding = null;
public $future_payment_id = null;
public $future_payment_status_change = null;
/* extension */
public $name = null;
public $address = null;
public $town = null;
public $email = null;
public $desc = null;
//custom properties not included by worldpay
public $mc_custom_property = null;
// constructor
public function __construct() {
$this->transaction_id = $_POST['transId'];
$this->transaction_status = $_POST['transStatus']; //should be either Y (successful) or C (cancelled)
$this->transaction_time = $_POST['transTime'];
$this->authorisation_amount = $_POST['authAmount'];
$this->authorisation_currency = $_POST['authCurrency'];
$this->authorisation_amount_string = $_POST['authAmountString'];
$this->raw_auth_message = $_POST['rawAuthMessage'];
$this->raw_auth_code = $_POST['rawAuthCode'];
$this->callback_password = $_POST['callbackPW'];
$this->card_type = $_POST['cardType'];
$this->country_match = $_POST['countryMatch']; //Y - Match, N - Mismatch, B - Not Available, I - Country not supplied, S - Issue Country not available
$this->waf_merchant_message = $_POST['wafMerchMessage'];
$this->authentication = $_POST['authentication'];
$this->ip_address = $_POST['ipAddress'];
$this->character_encoding = $_POST['charenc'];
$this->future_payment_id = $_POST['futurePayId'];
$this->future_payment_status_change = $_POST['futurePayStatusChange'];
if(isset($_POST['name'])){
$this->name = $_POST['name'];
}
if(isset($_POST['address'])){
$this->address = $_POST['address'];
}
if(isset($_POST['town'])){
$this->town = $_POST['town'];
}
if(isset($_POST['email'])){
$this->email = $_POST['email'];
}
if(isset($_POST['desc'])){
$this->desc = $_POST['desc'];
}
//custom properties
$this->mc_custom_property = $_POST['MC_custom_property'];
}
}

Categories