receive more response data in ci-merchant library codeigniter - codeigniter

How can I receive more response data in the ci-merchant codeigniter library ?
I am using the Paypal Express checkout payment method.
And I am passing the following parameters:
$params = array(
'amount' => 100.00,
'currency' => 'USD',
'return_url' => my return url,
'cancel_url' => my cancel url );
Right now am getting just the following response
Merchant_paypal_api_response Object
(
[_status:protected] => complete
[_message:protected] =>
[_reference:protected] => 1K088384XU0947545
[_data:protected] =>
[_redirect_url:protected] =>
[_redirect_method:protected] => GET
[_redirect_message:protected] =>
[_redirect_data:protected] =>
)
How can I get the data like paypal id, shipping address, item name and other stuff that paypal returns in the DoExpressCheckoutPayment response ?

Actually, that info wouldn't come back in the DECP response. It would come back in GetExpressCheckoutDetails.
Your library should provide some way to see the RAW API requests and responses. If it's not parsing out all of the details for you you'll need to do that on your own.

This isn't exactly an answer to your question, but you should try using Omnipay instead. Omnipay is basically CI-Merchant V2 (I'm the author of both libraries).
Omnipay lets you have direct access to the raw response. E.g. you would do something like this:
$params = array( 'amount' => 1000, 'currency' => 'USD', 'returnUrl' => 'my return url', 'cancelUrl' => 'my cancel url' );
$response = $gateway->completePurchase($params)->send();
$reference = $response->getTransactionReference(); // paypal transaction id
$data = $response->getData(); // this is the raw response object

Related

Sending automated email with dynamic content template

Well, I want to send an automated email every Friday using MailChimp/Mandrill.
Email Template :
Hi {{firstName}},
You weekly weekend pass is {{code}}.
Here, My email content is dynamically generated. So, before sending automated email, there should be some mechanism where I call the rest api from where I get the firstName and code. Then email is sent to different user.
{
[{
firstName: 'test',
code: 'Xewetwerx'
},
{
firstName: 'test2',
code: 'Xewetwrtd'
}]
}
I know we can write code in our backend server and call the API every Friday using cronjob(to send an email every Friday) but I don't want to use any cronjob.
Is it possible to make API call and send automated mail using MailChimp or mandrill ???
Outcome:
2 email should be sent with different code.
Mandrill implements scheduled emails through the sent_at parameter.
It's possible to send an email using a template and specify date and time when the message should be sent as a UTC timestamp in YYYY-MM-DD HH:MM:SS format. If you specify a time in the past, the message will be sent immediately. Note that for the sent_at feature you will need a paid (non free) account
If you choose PHP as the programming language for your backend,
you can use the official PHP API library.
example: (the code is not tested and could contain errors)
require_once '/path/to/MailchimpTransactional/vendor/autoload.php';
$mailchimp = new MailchimpTransactional\ApiClient();
$mailchimp->setApiKey('YOUR_API_KEY');
$msg = array(
'subject' => 'My subject',
'from_email' => 'ellery#example.com',
'to' => array(array('email' => 'recipient1#example.com', 'name' => 'Recipient 1'),array('email' => 'recipient2#example.com', 'name' => 'Recipient 2')),
'merge_vars' => array(array(
'rcpt' => 'recipient1#example.com',
'vars' =>
array(
array(
'name' => 'firstName',
'content' => 'test'),
array(
'name' => 'code',
'content' => 'Xewetwerx')
)),
array(
'rcpt' => 'recipient2#example.com',
'vars' =>
array(
array(
'name' => 'firstName',
'content' => 'test2'),
array(
'name' => 'code',
'content' => 'Xewetwrtd')
))));
$response = $mailchimp->messages->sendTemplate([
"template_name" => "template_name",
"template_content" => [[]],
"message" => $msg,
"send_at" => "2021-06-23 09:05:00" ,
]);
print_r($response);

Laravel - Payone

Is there an easy wrapper for the payone(https://www.payone.de/) API for Laravel? I only found one company who sells a package but nothing that is open source. I would appreciate any help.
You should consider Omnipay: http://omnipay.thephpleague.com/
Because:
It is gateway independent.
It is framework independent. It works well with Laravel but also Symfony, Yii, etc.
There is an Omnipay plugin for PayOne: https://github.com/academe/OmniPay-Payone
The code to make a purchase via Omnipay is pretty much the same regardless of the gateway. Here is some sample code that should work, although you should check the details of the Payone classes for other information that you need to send. The Payone gateway can work in multiple different ways depending on how your account is set up.
$gateway = Omnipay::create('Payone_ShopServer');
$card = new CreditCard(array(
'firstName' => 'Example',
'lastName' => 'User',
'number' => '4111111111111111',
// ... etc
));
$transaction = $gateway->purchase(array(
'amount' => '10.00',
'currency' => 'USD',
'description' => 'This is a test purchase transaction.',
'card' => $card,
));
$response = $transaction->send();
if ($response->isSuccessful()) {
echo "Purchase transaction was successful!\n";
}
// At this point you should get $response->getTransactionReference()
// and store that or something similar.

Laravel Payum Omnipay Bridge Logic Exception

I've been getting this error from omnipay bridge whenever I try to capture credit card payment:
Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.
Here's my code:
//...
$payum = (new PayumBuilder())
->addDefaultStorages()
->addGateway('paymentexpress_pxpost', ['factory' => 'omnipay_paymentexpress_pxpost', 'username' => 'some_username', 'password'=>'some_password'])
->getPayum();
$card = [
'number' => $request->input('cc_number'),
'expiryMonth' => $request->input('expiry_month'),
'expiryYear' => $request->input('expiry_year'),
'cvv' => $request->input('cvv'),
'name' => $request->input('card_name')
];
$payment = new ArrayObject(['amount' => '1.00', 'currency' => 'AUD', 'card' => $card]);
if ($reply = $payum->getGateway('paymentexpress_pxpost')->execute(new Capture($payment), true)) {
// convert reply to http response
}
//...
The ->execute() function is the one that throws an error. I also referred to the same issue from Error: Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.
Why do you create a new payum builder instead of using the one from laravel package. The one from package have some additional stuff set (like obtain credit card action).
Accoding to the docs you should do something like this
App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
$payumBuilder
->addGateway('paymentexpress_pxpost', [
'factory' => 'omnipay_paymentexpress_pxpost',
'username' => 'some_username',
'password'=>'some_password'
])
;
});

how to construct an https POST request with drupal_http_request?

I want to send a POST request to an https server.
$data = 'name=value&name1=value1';
$options = array(
'method' => 'POST',
'data' => $data,
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$result = drupal_http_request('http://somewhere.com', $options);
I can't figure out out to implement the https options in the POST example code above.
Can anyone please explain me how to do this? I am quite new to PHP coding with Drupal, and I could definitely use the guidance.
I found that all is needed is to set it in the protocol. So I got to this code.
$data = 'access_token=455754hhnaI&href=fb&template=You have people waiting to play with you, play now!';
$options = array(
'method' => 'POST',
'data' => $data,
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$result = drupal_http_request('https://graph.facebook.com/1000721/notifications?', $options);
It still doesn't work. If I post via Firefox with https://graph.facebook.com/1000080521/notifications?access_token=45575FpHfhnaI&href=fb&template=You have people waiting to play with you, play now! it works.
I am probably not constructing the request properly in Drupal.
What am I doing wrong? How can I get my code to work?
There is no difference between using drupal_http_request() with a secure connection (https://), or without a secure connection (http://).
PHP must be compiled with support for OpenSSL; otherwise, drupal_http_request() doesn't support secure connections. Apart that, the only issue could be the proxy server not supporting a secure connection.
As side note, you are using https://graph.facebook.com/1000721/notifications? as URL for the request. The question mark should not be part of the URL.
I would also use drupal_http_build_query() to build the data to use for the request.
$data = array(
'access_token' => '455754hhnaI',
'href' => 'fb',
'template' => 'You have people waiting to play with you, play now!'
);
$options = array(
'method' => 'POST',
'data' => drupal_http_build_query($data),
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$result = drupal_http_request('https://graph.facebook.com/1000721/notifications', $options);

CodeIgniter Payments Getting a Success Response but not Working

I'm using CodeIgniter Payments to integrate with the Paypal API. I believe I am calling the right methods because I'm getting a response of "Success" but I don't see the transaction in the Sandbox. When I use the sample DoDirectPayment file from Paypal I complete the transaction and I can see it in the sandbox.
Here is my code using CodeIgniter Payments:
//load the payment library
$this->load->spark('codeigniter-payments/0.1.4/');
//configure the parameters for the payment request
$paymentParameters = array(
'cc_type' => 'foo',
'cc_number' => 'foo',
'cc_exp' => 'foo',
'first_name' => 'foo',
'last_name' => 'foo',
'street' => 'foo',
'street2' => 'foo',
'city' => 'foo',
'state' => 'foo',
'country' => 'foo',
'postal_code' => 'foo',
'amt' => 'foo',
'currency_code' => 'USD'
);
//make the call
$paymentResponse = $this->payments->oneoff_payment('paypal_paymentspro', $paymentParameters);
//print the response
print_r($paymentResponse);
Here is the response:
stdClass Object
(
[type] => gateway_response
[status] => Success
[response_code] => 100
[response_message] => The authorization was successful.
[details] => stdClass Object
(
[gateway_response] => stdClass Object
(
[TIMESTAMP] => 2012-05-22T19:18:17Z
[CORRELATIONID] => 7939eeaa6c0c0
[ACK] => Success
[VERSION] => 66.0
[BUILD] => 2929894
[AMT] => 20.89
[CURRENCYCODE] => USD
[AVSCODE] => X
[CVV2MATCH] => M
[TRANSACTIONID] => 4RS01101TL8204042
)
[timestamp] => 2012-05-22T19:18:17Z
[identifier] => 4RS01101TL8204042
)
)
You can just switch into using other Paypal libraries. It might save you time than figuring out this problem. http://codeigniter.com/wiki/PayPal_Lib
I had this problem too.
In my case, I did not set my config driver correctly and it ended up sending all my transactions to Calvin's (Author's) default paypal sandbox account.
Double check to make sure that your API tokens are set correctly with:
$gateway_name = 'paypal_paymentspro';
$params = array(
'identifier' => *Your transaction ID from above*
);
$response = $this->payments->get_transaction_details($gateway_name, $params);
print_r($results);
Also, if you don't want to set the driver and want to do everything from your PHP file, you can always pass in your API tokens like so:
$gateway_name = 'paypal_paymentspro';
$params = array(
'identifier' => *Your transaction ID from above*
);
$config['api_username'] = *Your api username*;
$config['api_password'] = *Your api password*;
$config['api_signature'] = *Your sig*;
$response = $this->payments->get_transaction_details($gateway_name, $params);
print_r($results);

Resources