What values can we send to Stripe using Omnipay - php

I have two questions
One:
What values can we send to Stripe using Omnipay authorize(), example below is only sending amount and description
$response = $gateway->authorize([
'amount' => '10.00',
'currency' => 'USD',
'description' => 'This is a test purchase transaction.',
'paymentMethod' => $paymentMethod,
'returnUrl' => $completePaymentUrl,
'confirm' => true,
])->send();
what if we want name and email to be sent, how can we achieve this also
Two:
the payment intent we get back from the above request, is generating error log on Godaddy server, I am using the following code;
$paymentIntentReference = $response->getPaymentIntentReference();
$response = $gateway->confirm([
'paymentIntentReference' => $paymentIntentReference,
'returnUrl' => $completePaymentUrl,
])->send();
error log: PHP Fatal error: Uncaught Omnipay\Common\Exception\InvalidRequestException: The paymentIntentReference parameter is required
by my confusion is that in spite of this error log the payment process is being complete, so should I worry about this error or not,
and I hope this time I asked my question in the right manner
thanks in advance

Related

Laravel, soap API required login

I am having a little trouble with the SOAP API I need to consume. It requires authorization, so I log in with the following.
Basically, I need to log in with the following, I don't get a "Login Required", which is fine.
$client = new \SoapClient('localwsdlfile.wsdl', array(
'local_cert' => 'localcert.pem',
'passphrase' => 'passphrase',
'location' => 'https://wsmurl/login/'
));
$response = $client->Get(array(
"AccessKey" => "accesskey",
"ProductID" => "SOMEPRODUCT",
"Scope" => "SOMESCOPE",
"Parameters" => array('Param' => array('_' => 'DATATOLOOKUP', 'id'=>'MOREDATATOLOOKUP'))
));
print_r($response);
So, basically, in the client, I need to uncomment the line
'location' => 'https://wsmurl/login/'
If I don't, I get this login error. The server I am trying to consume has a cache, so I no longer need to send this login for future operations for the next 10 minutes.
So, now, I have logged in, I can go the following, with success.
$client = new \SoapClient('localwsdlfile.wsdl', array(
'local_cert' => 'localcert.pem',
'passphrase' => 'passphrase',
// 'location' => 'https://wsmurl/login/' // Uncomment to login
));
$response = $client->Get(array(
"AccessKey" => "accesskey",
"ProductID" => "SOMEPRODUCT",
"Scope" => "SOMESCOPE",
"Parameters" => array('Param' => array('_' => 'DATATOLOOKUP', 'id'=>'MOREDATATOLOOKUP'))
));
print_r($response);
If I keep 'location' => 'https://wsmurl/login/' uncommented, I get errors about not sending a valid WSDL.
So in summary:-
I am consuming this soap API in Laravel, using PHP's SoapClinet per the above code.
My understanding is that the soap service I am trying to consume required login first.
After quite a lot of testing, I managed to get to the point there were no errors by including the line 'location' => 'https://wsmurl/login/' as shown above in the call to SoapClient.
This seems to be required the first time I call this soap service I guess it is logging me in. If I don't include it, I get the error
"SoapFault
Login Required"
So, if I include the line 'location' => 'https://wsmurl/login/', it appears to log me in, but I now get the error
"SoapFault
looks like we got no XML document"
If I keep the line, I continue to get this error
"SoapFault
looks like we got no XML document"
Removing the line then gives me the expected SOAP response and all is ok.
I have tried catching for errors using try{} ... catch{} looking for exceptions/errors etc, but it isn't catching the "Login Required" or "Looks like we got no XML document" as faults.
So, I guess, is there a better way to detect this condition so I can either send or not without the line or is there a better way to login to the service (note, it just uses the cert and passphrase).
Thanks in advance, I hope the little re-write above makes it clearer.
Because the location for the login and localwsdlfile.wsdl is different, I could not do it with one call. So we created a function using curl to login and if login is successful it will proceed to the soap client. Thanks to Brian from freelancer for his assistance here.
$client = new SoapClient('wsdl/VocusSchemas/localwsdlfile.wsdl', array(
'trace' => 1,
'exception' => true
));
try {
$response = $client->Get(array(
// "AccessKey" => "MADAITABNSAATOT1",
"AccessKey" => "accesskey",
"ProductID" => "SOMEPRODUCT",
"Scope" => "SOMESCOPE",
"Parameters" => array('Param' => array('_' => 'DATATOLOOKUP', 'id' => 'MOREDATATOLOOKUP'))
));

a similar object exists in live mode, but a test mode key was used to make this request. thrown in php

I am trying to make payment in stripe live mode but the following error displayed:
PHP Fatal error: Uncaught (Status 400) (Request req_uocWWxAIPTJ6ZR)
No such token: tok_1FbZniE3n36TXaJ5sMm5KSsX; a similar object exists
in live mode, but a test mode key was used to make this request.
thrown in
I have read several tutorials online but still no head-on.
require_once "vendor/autoload.php";
\Stripe\Stripe::setApiKey('sk_live_xxxxxxxxxxxxxxxxxxxxxx');
$token = $_POST['stripeToken'];
// Add customer to stripe
$customer = \Stripe\Customer::create(array(
'email' => $email,
'source' => $token
));
// Unique order ID
$orderID = strtoupper(str_replace('.','',uniqid('', true)));
// Charge a credit or a debit card
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amt,
"currency" => "usd",
'description' => "Payment for ". $rooms,
'metadata' => array(
'order_id' => $orderID
)
));
// Retrieve charge details
$chargeJson = $charge->jsonSerialize();
Please, what can I do to solve this issue?
This error indicates that client-side you used the Live Publishable API key (pk_live_123) to create the Token but server-side you used the Test Secret API key (sk_test_123) to create the Charge.
I know your code shows you are using the Live Secret key but it's definitely not the case. What I'd recommend here is adding logs to your PHP code server-side to ensure that the code you are running is the same as the one you are reading and to confirm you are using the correct API key.

Amazon AWS SNS Delivery Status For SMS has random Log Streams

I am using Amazon's php sdk.
I use Amazon SNS service to send direct sms. When I send an sms from my php application it gives me a message ID.
I have to track the delivery status of each of my message. I have enabled cloud watch logs for Text Messaging using Manage text messaging preferences settings. The IAM role is properly configured and logs end in Cloudwatch.
Now the problem I am facing is that the system creates a random log stream for every message i send.
Here is a screen shot.
I have sent six messages and all of them has been successful( I am sending them to myself). And against every message a single log stream exists.
API gives me a function to get logs based upon LogGroupName and LogGroupStream. The LogGroupName remains the same but LogGroupStream is differnt for every message.
here is the sdk call
$result = $client->getLogEvents([
'endTime' => <integer>,
'limit' => <integer>,
'logGroupName' => '<string>', // REQUIRED
'logStreamName' => '<string>', // REQUIRED
'nextToken' => '<string>',
'startFromHead' => true || false,
'startTime' => <integer>,
]);
How should i get the Logs? Is there a way to tell amazon to log all of sms deliveries to a single LOG STREAM. So i know the stream and can query for logs.
With a Query:
$result = $CloudWatchclient->startQuery([
'endTime' => strtotime("+5 minutes", strtotime($creation_date)) * 1000,
'limit' => 1,
'logGroupName' => '.....DirectPublishToPhoneNumber',
'queryString' => 'field #message like /'.$awsmessageid.'/',
'startTime' => strtotime($creation_date)*1000,
]);
$queryid = $result->get('queryId');
sleep(2);
$result = $CloudWatchclient->getQueryResults([
'queryId' => $queryid, // REQUIRED
]);
$result = $result->get('results');
The result containt the event log with sms data success
You could use filterLogEventsMethod from CloudWatchLogsClient:
$result = $client->filterLogEvents(array(
'logGroupName' => 'string', //Required
'startTime' => integer,
'endTime' => integer,
'filterPattern' => 'string',
'nextToken' => 'string',
'limit' => integer,
'interleaved' => true || false));
Reference: Aws Docs

PayPal Sandbox "Sorry, we can’t complete your purchase at this time "

I have set up PayPal Sandbox to test my PayPal Express integration, but whenever I log in to the sandbox from the payment page, I get greeted by the following error message;
I am using laravel-omnipay and omnipay-paypal with the PayPal_Express gateway.
I think this is likely to be a configuration issue (or a bug..? Although I'm hoping it's not.) in PayPal, but this is the piece of code I am using to initiate the payment:
public function checkout ()
{
$cart = Cart::forSession ();
$response = Omnipay::purchase
(
[
'amount' => $cart->getPrice (),
'currency' => preferred_currency ()->name,
'description' => (string) $cart,
'returnUrl' => URL::action ('OrderController#checkoutReturn'),
'cancelUrl' => URL::action ('OrderController#checkoutCancel')
]
)->send ();
if ($response->isSuccessful ())
dd ('successful', $response);
else if ($response->isRedirect ())
return $response->getRedirectResponse ();
else
return Redirect::to ('/cart')->with ('alerts', [new Alert ('An error occurred while attempting to process your order: ' . $response->getMessage (), Alert::TYPE_ALERT)]);
}
And the omnipay.php configuration file:
return array(
'gateway' => 'PayPal_Express',
'defaults' => array(
'testMode' => true,
),
'gateways' => array(
'PayPal_Express' => array(
'username' => '<>',
'password' => '<>',
'signature' => '<>',
'landingPage' => array('billing', 'login'),
),
),
);
The username, password and signature I am using are the ones I created in the PayPal Sandbox for my account.
The sandbox account I am using to test this is a "personal"/buyer account, with funding sources and "Payment Review" disabled. The Sandbox Accounts overview on the PayPal Developer website indicates the sandbox account's status as "complete".
I'm hoping I didn't miss something obvious. I checked out some of the other answers on Stack Overflow but none of those seemed to offer a solution for this exact problem.
Contact PayPal support, as there is something wrong on their end.

AWS SDK Guzzle error when sending email with SES

I am attempting to send mail using AWS SES sendEmail method, and I'm having trouble with an error. I have read this question: AWS SDK Guzzle error when trying to send a email with SES
I am dealing with a very similar issue. The original poster indicates that they have a solution, but did not post the solution.
My code:
$response = $this->sesClient->sendEmail('example#example.com',
array('ToAddresses' => array($to)),
array('Subject.Data' => array($subject), 'Body.Text.Data' => array($message)));
Guzzle code producing the error (from aws/Guzzle/Service/Client.php):
return $this->getCommand($method, isset($args[0]) ? $args[0] : array())->getResult();
Error produced:
Catchable fatal error: Argument 2 passed to Guzzle\Service\Client::getCommand() must be of the type array, string given
Looking at the Guzzle code, I can see that the call to getCommand will send a string if args[0] is set and is a string. If args[0] is NOT set then an empty array is sent.
What am I missing here please?
SOLUTION:
It turns out I was trying to use SDK1 data structures on the SDK2 code base. Thanks to Charlie Smith for helping me to understand what I was doing wrong.
For others (using AWS SDK for PHP 2) :
Create the client -
$this->sesClient = \Aws\Ses\SesClient::factory(array(
'key' =>AWS_ACCESS_KEY_ID,
'secret' => AWS_SECRET_KEY,
'region' => Region::US_EAST_1
));
Now, structure the email (don't forget that if you're using the sandbox you will need to verify any addresses you send to. This restriction doesn't apply if you have been granted production status) -
$from = "Example name <example#example.com>";
$to ="example#verified.domain.com";
$subject = "Testing AWS SES SendEmail()";
$response = $this->sesClient->getCommand('SendEmail', array(
'Source' => $from,
'Destination' => array(
'ToAddresses' => array($to)
),
'Message' => array(
'Subject' => array(
'Data' => $subject
),
'Body' => array(
'Text' => array(
'Data' => "Hello World!\n Testing AWS email sending."
),
'Html' => array(
'Data' => "<h1>Hello World!</h1><p>Testing AWS email sending</p>"
)
),
),
))->execute();
That should work now.
Here is the relevant section in the AWS SDK for PHP 2 documentation:
http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.Ses.SesClient.html#_sendEmail

Categories