Missing CreditCard Class when using Omnipay Paypal for Laravel 5 - paypal

Here are the repo included in my composer:
omnipay &
paypal
In my config/laravel-omnipay.php:
'gateways' => [
'paypal' => [
'driver' => 'PayPal_Rest',
'options' => [
'solutionType' => '',
'landingPage' => '',
'headerImageUrl' => ''
]
]
]
Here is in my Controller:
// omnipay start
$gateway = Omnipay::create('PayPal_Rest');
// Initialise the gateway
$gateway->initialize(array(
'clientId' => 'xxxxxx',
'secret' => 'xxxxxx',
'testMode' => true, // Or false when you are ready for live transactions
));
// Create a credit card object
// DO NOT USE THESE CARD VALUES -- substitute your own
$card = new CreditCard(array(
'firstName' => $request->firstname,
'lastName' => $request->lastname,
'number' => $request->cardnumber,
'expiryMonth' => $month_year[0],
'expiryYear' => $month_year[1],
'cvv' => $request->ccv,
'billingAddress1' => $request->address
/*
'billingCountry' => 'AU',
'billingCity' => 'Scrubby Creek',
'billingPostcode' => '4999',
'billingState' => 'QLD',*/
));
// Do an authorisation transaction on the gateway
$transaction = $gateway->authorize(array(
'amount' => '100',
'currency' => 'USD',
'description' => $eventName->event_title,
'card' => $card,
));
$response = $transaction->send();
if ($response->isSuccessful()) {
echo "Authorize transaction was successful!\n";
// Find the authorization ID
$auth_id = $response->getTransactionReference();
}
I've got this error:
Class 'App\Http\Controllers\CreditCard' not found
Note: If I use RestGateway to replace PayPal_Rest, I get this error instead:
Class '\Omnipay\RestGateway\Gateway' not found
Searching an answer for a long time but didn't find a solution that works for me. So, not entirely sure how to proceed.

You need to have this at the top of your class file:
use Omnipay\Common\CreditCard;

$creditCard = new \Omnipay\Common\CreditCard([...]);
Backslash
Further reading: https://stackoverflow.com/questions/4790020/what-does-a-backslash-do-in-php-5-3#:~:text=%5C%20(backslash)%20is%20the%20namespace,name%20in%20the%20current%20namespace.
The issue is because it will fetch the class from the global namespace - rather than the current namespace.

Related

Request timeout - integrate third party library with codeigniter 3

Im working on API integration InPost API Create shippment. I try integrate third party library inpost with codeigniter 3 from GitHub.
https://github.com/imper86/php-inpost-api
I install this library via composer.
View:
<?php echo form_open('inpost_controller/inpost_shippment_post'); ?>
<div class="form-group">
</div>
</div>
<?php echo form_close(); ?><!-- form end -->
Then I call in controller:
require FCPATH . 'vendor/autoload.php';
Full code file Controller:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
require FCPATH . 'vendor/autoload.php';
use Imper86\PhpInpostApi\Enum\ServiceType;
use Imper86\PhpInpostApi\InpostApi;
class Inpost_controller extends Admin_Core_Controller
{
public function __construct()
{
parent::__construct();
}
/**
* Create shippment Inpost Post
*/
public function inpost_shippment_post()
{
$token = 'xxxxx';
$organizationId = 'xxxxx';
$isSandbox = true;
$api = new InpostApi($token, $isSandbox);
$response = $api->organizations()->shipments()->post($organizationId, [
'receiver' => [
'name' => 'Marek Kowalczyk',
'company_name' => 'Company name',
'first_name' => 'Jan',
'last_name' => 'Kowalski',
'email' => 'test#inpost.pl',
'phone' => '888888888',
'address' => [
'street' => 'Malborska',
'building_number' => '130',
'city' => 'Kraków',
'post_code' => '30-624',
'country_code' => 'PL',
],
],
'sender' => [
'name' => 'Marek Kowalczyk',
'company_name' => 'Company name',
'first_name' => 'Jan',
'last_name' => 'Kowalski',
'email' => 'test#inpost.pl',
'phone' => '888888888',
],
'parcels' => [
['template' => 'small'],
],
'insurance' => [
'amount' => 25,
'currency' => 'PLN',
],
'cod' => [
'amount' => 12.50,
'currency' => 'PLN',
],
'custom_attributes' => [
'sending_method' => 'parcel_locker',
'target_point' => 'KRA012',
],
'service' => ServiceType::INPOST_LOCKER_STANDARD,
'reference' => 'Test',
'external_customer_id' => '8877xxx',
]);
$shipmentData = json_decode($response->getBody()->__toString(), true);
while ($shipmentData['status'] !== 'confirmed') {
sleep(1);
$response = $api->shipments()->get($shipmentData['id']);
$shipmentData = json_decode($response->getBody()->__toString(), true);
}
$labelResponse = $api->shipments()->label()->get($shipmentData['id'], [
'format' => 'Pdf',
'type' => 'A6',
]);
file_put_contents('/tmp/inpost_label.pdf', $labelResponse->getBody()->__toString());
}
}
When I post form, after 30 sec I get error 500 Internar Error Server Request timout.
And now im not sure how to debug now. I enable error log in CI3 application/logs/ I open this file but I not see any error related to this.
Could be a defect, or missing http2 setup/cfg.
Since the header in https2 protocol has shorter header on packs.
Not sure doe
https://caniuse.com/http2 < short http2 (TLS, HTTPS) overview
https://factoryhr.medium.com/http-2-the-difference-between-http-1-1-benefits-and-how-to-use-it-38094fa0e95b < http2 as protocol overview in 5 min

Setting shipping info in OmniPay

I'm trying to set a shipping info (name,address, email, etc) using OmniPay for PayPal Express.
I've tried adding shipping info in options array in purchase($options) object:
$options = array(
// required fields (username, pass, etc)
// .....
'shippingAddress1' => 'Elm Street'
'shippingCity' => 'Elm',
'shippingPostcode' => '1000'
// etc.
);
I also tried passing this info to CreditCard object:
$card = new Omnipay\Common\CreditCard($card_options);
without any success. The code:
$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername(USERNAME);
$gateway->setPassword(PASS);
$gateway->setSignature(SIGNATURE);
$gateway->setTestMode(true);
$card_options = array(
'shippingAddress1' => 'Elm Street',
'shippingCity' => 'Elm',
'shippingPostcode' => '10000',
'shippingState' => '',
'shippingCountry' => 'NEverland',
'shippingPhone' => '123465789',
'company' => '',
'email' => 'shipping#test.com'
);
$card = new Omnipay\Common\CreditCard($card_options);
$response = $gateway->purchase(
array(
'cancelUrl'=>'http://localhost/laravel_paypal/',
'returnUrl'=>'http://localhost/laravel_paypal/public/paypalexpress_confirm',
'amount' => '0.99',
'currency' => 'USD',
'card' => $card
)
)->send();
How to add shipping info to PayPal Express using OmniPay?
BTW, I'm using Laravel with PayPal Sandbox.
This problem has recently been fixed (https://github.com/adrianmacneil/omnipay/pull/140) so it should now be possible to set shipping info properly.

Using Graph API to create an event with map

I am adding a new event via the graph API.
Is there a secret to making the map appear or does it has to be an official FB place?
This is what i am sending. Everything seems to work (kindof)
A couple of things.
When i view the event, no zip or map are displayed.
Any help/suggestions would be greatly appreciated
BTW all the fields are populated and correct
$fb = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true,
'fileUpload' => true
));
$fb->setAccessToken($_SESSION[ $eid.'_FB_USER_ACCESSCODE' ]);
$data = array( 'access_token' => $_SESSION[ $eid.'_FB_USER_ACCESSCODE' ],
'owner' => $_SESSION[ $eid.'_FB_USER_ACCESSCODE' ],
'latitude' => $event->getLat(),
'longitude' => $event->getLong(),
'name' => $event->getTitle(),
'description' => $description,
'start_time' => date('c', $event->getStart()),
'end_time' => date('c', $event->getEnd()),
'street' => $event->getAddress(),
'city' => $event->getCity(),
'state' => $event->getState(),
'zip' => $event->getZip(),
'location' => $event->getLocation(),
'privacy' => 'OPEN'
, basename($fileName) => '#'.$fileName
) ;
I'm not sure, but the map what you see isn't just an image?
The event documentation says: https://developers.facebook.com/docs/reference/api/event/ you able to submit the event's profil picture.

Insert email when creating account with rest api

I am faced with a Sugar 6.3 CE installation, trying to create new accounts through rest api.
I am still on the learning curve for a lot of the innards of the CRM, and cannot figure out how to have the email inserted whith the rest of the account info upon creation with a REST call.
I have tried many different field values, and after catching that $email1 was used in some snippet examples I saw on the sugarCRM site. I have not found other mentions in the forums or in the docs yet.
The $parameters array used to configure the usual rest call to create an account in php with REST api looks like this and works fine, except for the $email1:
$parameters = array(
'session' => $session,
'module' => 'Contacts',
'name_value_list' => array(
array('name' => 'first_name', 'value' =>
utf8_encode($contacts["Name"])),
array('name' => 'last_name', 'value' =>
utf8_encode($contacts["GivenName"])),
array('name' => 'phone_work', 'value' =>
utf8_encode($row->PrimaryPhoneAreaCode . ' ' . $row->PrimaryPhone)),
array('name' => 'phone_fax', 'value' =>
utf8_encode($row->PrimaryFaxAreaCode . ' ' . $row->PrimaryFaxNumber)),
array('name' => 'title', 'value' =>
utf8_encode($contacts["Title"])),
/*
* PROBLEM HERE!
*/
array('name' => 'email1', 'value' =>
utf8_encode($row->PrimaryEmail)),
array('name' => 'primary_address_street', 'value' =>
utf8_encode($row->Address1) . ' ' .
utf8_encode($row->Address2)),
array('name' => 'language', 'value' =>
utf8_encode($row->Language)),
array('name' => 'assigned_user_id', 'value' =>
get_rep_id($row->Salesperson1Name, $sugarlink)),
)
);
I would be curious, if someone has the trick. I tried to find to field for emails but it seems to be in separate tables. Any help / tips appreciated.
If you are using REST API the email1 will work for both set en get methods (just tested it).
Did not used the SOAP API as in your example, and suggest to migrate all to REST according to SugarCRM recommendations.
You must add the email into emailadress database first, create contact and set a relationship between both ;-)
$set_entry_parametersEADDR = array(
"session" => $session_id,
//The name of the module from which to retrieve records.
"module_name" => "EmailAddresses",
//Record attributes
"name_value_list" => array(
array('name' => 'email_address', 'value' => $email),
array('name' => 'email_address_caps', 'value' => strtoupper($email)),
array('name' => 'invalid_email' , 'value' => 0),
array('name' => 'opt_out', 'value' => 0),
array('name' => 'date_created' , 'value' => date('Y-m-d H:i:s')),
array('name' => 'date_modified', 'value' => date('Y-m-d H:i:s')),
array('name' => 'deleted' , 'value' => 0),
),
);
$set_entry_resultEmailsAdd = call("set_entry", $set_entry_parametersEADDR, $url);
print_r($set_entry_resultEmailsAdd);
$Email_id = $set_entry_resultEmailsAdd->id;
$set_entry_parameters_contact = array(
//session id
"session" => $session_id,
//The name of the module from which to retrieve records.
"module_name" => "Contacts",
//Record attributes
"name_value_list" => array(
//to update a record, you will nee to pass in a record id as commented below
//array("name" => "id", "value" => "9b170af9-3080-e22b-fbc1-4fea74def88f"),
array("name" => "first_name", "value" => $prof["Prenom"]),
array("name" => "last_name", "value" => $prof["Nom"]),
array("name" => "login_c", "value" => $prof["Login"]),
//array("name" => "email1", "value" => $email),
array("name" => "fonction_c", "value" => "prof")
),
);
$set_entry_result_contact = call("set_entry", $set_entry_parameters_contact, $url);
print_r($set_entry_result_contact);
$contact_id = $set_entry_result_contact->id;
$set_relationship_parameters_email = array(
'session' => $session_id,
'module_name' => 'Contacts',
'module_id' => $contact_id,
'link_field_name' => 'email_addresses',
'related_ids' => $Email_id,
);
$set_relationship_result_email = call("set_relationship", $set_relationship_parameters_email, $url);
print_r($set_relationship_result_email);
Currently I think that not works with REST api but works with SOAP API. Could you try to use email1_set_in_workflow key instead of email1?
It's not a very good solution but perhaps that could unlock you pending a better way to do that in future release

FedEx: Authentication Failed with test account

I'm trying to integrate FedEx with my application. I created a test account.
When I send RateRequest I got a response Authentication Failed (code is 1000).
I use v10 of Fedex Rate service. For SOAP I use Savon ruby gem.
Here is code I use:
require 'rubygems'
require 'savon'
TEST_URL = 'https://wsbeta.fedex.com:443/web-services/rate'
client = Savon::Client.new do
wsdl.document = File.expand_path("../rate_wsdl.xml", __FILE__)
wsdl.endpoint = TEST_URL
end
client.request "RateRequest" do
soap.body = {
'WebAuthenticationDetail' => {'Key' => KEY, 'Password' => PASSWORD},
'ClientDetail' => {'AccountNumber' => ACCOUNT_NUMBER, 'MeterNumber' => METER_NUMBER},
'RequestedShipment' => {
'PackagingType' => 'FODEX_BOX',
'Shipper' =>
{'Address' => {'PostalCode' => '90210', 'CountryCode' => 'US', 'Residential' => 'true'}
},
'Recipient' =>
{'Address' => {'PostalCode' => 'KIP 1J1', 'CountryCode' => 'CA', 'Residential' => 'true'}
},
'RateRequestTypes' => 'ACCOUNT',
'PackageCount' => '1',
'RequestedPackages' => {
'Weight' => {'Units' => 'LB', 'Value' => '7.5'},
'Dimensions' => {'Length' => '15', 'Width' => '10', 'Height' => '5', 'Units' => 'IN'}
}
#'LabelSpecification' => ''
}
}
end
I googled a lot about it. Some people had the same problem. People say it can be caused because of lack of permission of address validation, but I can't find how I can disable it if so.
I am sure that all credentials are OK (account number, meter number, key, password).
Also I tried "https://wsbeta.fedex.com:443/web-service" for endpoint url as well.
Figured out of was wrong. I sent invalid SOAP request. Thanks to SOAPUI tool, it helped me to validate my request.