how to get payment information on Magento? - php

I have to export the orders to a file, here is my code to go through the orders:
$orders = Mage::getModel('sales/order')->getCollection()
->addAttributeToSelect(array('status', 'ncm'))
->addFieldToFilter(
array(
array('attribute' => 'status', 'eq' => 'complete')
)
);
$order = $orders->getFirstItem();
//print_r($order);
//exit;
//foreach($orders as $order){
$id = $order->getIncrementId();
$payment = $order->getPayment();
$method = $payment->getMethodInstance();
print_r($payment);
//}
I need to print some information about the payment
like the method, the amount, how many months it was split, if was credit card, i need the reutrning id of the transaction and so the list goes on
how can I do that?

I think it will be
$payment = $order->getPayment();
It will retrieve the current order payment instance.

//Get Payment
$payment = $order->getPayment()
//Get card type
$payment->getData('cc_type')
//Get Payment Info
$payment->getMethodInstance()->getCode();
$payment->getMethodInstance()->getTitle();
//Get Credit Card info
$payment->getMethodInstance()->getCardsStorage()
$payment->getMethodInstance()->getCardsStorage()->getCards() //array()

To get the method code only it's far safer to use
$order->getPayment()->getMethod();
Skipping instance object which can generate exception if the payment method was uninstalled.

Related

applying promotion code instead of coupon in laravel/cashier

i am trying to use Promotion code instead of coupon code in laravel cashier/stripe official package but i couldn't find any help in there on how to apply promotion code instead of coupon on subscription as i know how to apply coupon but i want to apply promotion code, how can i do it.
below is my code for applying coupon when creating new subscription but i don't know how can i achieve it using promotion code:
$subscription = $user->newSubscription($plan->name, $selectedPlan);
// Add the trial days if any
if ($plan->trial_days) {
$subscription = $subscription->trialDays($plan->trial_days);
}
// Add the coupon id if any
if ($request->input('coupon_id')) {
$subscription = $subscription->withCoupon($request->input('coupon_id'));
}
$subscription->create($paymentMethod->id, [
'email' => $user->email
]);
You can add promotion code by using the ->withPromotionCode() e.g.
if ($request->input('promotion_code_id')) {
$subscription = $subscription->withPromotionCode($request->input('promotion_code_id'));
}
However, this function requires the promotion code ID instead of the code, and most likely you want your user to key in the code, not the ID. In such case, you can retrieve all active promotion codes and match the code.
if ($request->has('promotion_code')) {
$stripeClient = new \Stripe\StripeClient(config('cashier.secret'));
$result = $this->stripe->promotionCodes->all(
['code' => $request->get("promotion_code"), 'active' => true]
);
if($result->isEmpty()){
// handle invalid promo code here
}
$promoCodeID = $result->first()->id;
$subscription = $subscription->withPromotionCode($promoCodeID);
}

Updating and Invoicing Stripe Subscription Quantity with Invoice description laravel cashier

Good Day,
I'm working on a project involving Laravel Cashier. I want to give user's the ability to update their subscription quantity and get charged immediately (which I have been able to achieve, using the code below)
$user = Auth::user()
$user->subscription('main')->incrementAndInvoice(10000);
As much as the above works as expected, the invoice returned doesn't include a description indicating the changes instead the invoice description is blank. But when I checked the Event Data on stripe the two descriptions are there [see below image]
The above images shows a user who was currently on a subscription plan with 5000 quantities but increased to 15000 quantities. Is there a way to include these descriptions in the invoice generated.
After i checked the incrementAndInvoice() method , it only accepts two parameter (1. count, 2. Plan) as seen below;
no option to include description like we have for the charge() method. Is there any workaround to this? Any ideas or pointers in the right direction would be really appreciated.
Thanks for your help in advance.
At the time being there is no implementation to include the description in incrementAndInvoice().
So we have to implement it and before we do that please checkout Update an invoice.
First change this line: $user->subscription('main')->incrementAndInvoice(10000); to $subscription = $user->subscription('main')->incrementAndInvoice(10000); (we are assigning it to $subscription variable)
then get the invoice as below:
$new_invoice = $user->invoices()->filter(function($invoice) use ($subscription) {
return $invoice->subscription === $subscription->stripe_id;
});
After updating the subscription quantity we will add the following:
$client = new \GuzzleHttp\Client();
$request = $client->post('https://api.stripe.com/v1/invoices/' . $invoice_id, [
'auth' => [$secret_key, null]
'json' => ['description' => 'your description']
]);
$response = json_decode($request->getBody());
Or the following:
$stripe = new \Stripe\StripeClient(
$secret_key
);
$stripe->invoices->update(
$invoice_id,
['description' => 'your description']
);
Please note that:
the $invoice_id is the id of the invoice.
the $secret_key is the API key.

Omnipay token billing not working with stripe

I am using ignited/laravel-omnipay package for omnipay in laravel.
I am trying to implement token billing using stripe as shown here https://github.com/thephpleague/omnipay#token-billing.
Customer are getting created successfully on stripe but i am not able to make payment with the returned customer id.
Here's my code
$token = Input::get('stripetoken');
$gateway = Omnipay::create('Stripe');
$gateway->setApiKey('My Key');
$gateway->setTestMode(true);
$cardresponse = $gateway->createCard(array('token' =>$token))->send();
if ($cardresponse->isSuccessful()) {
$card_id = $cardresponse->getCardReference();
$data = $cardresponse->getData();
$customerid = $data['id'];
$cardid = $data['default_source'];
}
$paymentresponse = $gateway->purchase(array('amount' => '10.00','currency' => 'USD', 'cardReference' => $card_id))->send();
echo $paymentresponse->getMessage();
I am getting following response.
No such token: cus_8FwPaLNKdWcfRW
And when i check my stripe dashboard then customer with this id exists and has a card assigned.
Thanks for helping.
Since you're creating a customer object, you need to update your charge creation request to pass the customer ID in the customer parameter rather than in the source parameter (which causes the error you're seeing).
I'm not familiar with Omnipay but I think this should work:
$paymentresponse = $gateway->purchase(array('amount' => '10.00','currency' => 'USD', 'customerReference' => $card_id))->send();

How to get a payment information from magento api?

$proxy = new SoapClient('http://magentolocal.com/mag/api/soap/?wsdl');
$sessionId = $proxy->login('test', 'test123');
$getorderid = "100000054";
$getdetails = $proxy->call($sessionId, 'sales_order.info', $getorderid);
print_r($getdetails);
it is return an array, it contain a payment_id,so where can i pass a payment_id and get a payment information of that order.
Magento don't have API methods to work with payments, but there is some usefull methods to work with invoices - http://www.magentocommerce.com/wiki/doc/webservices-api/api#mage_sales

Magento Questions get customer details and onepage/checkout/success doesn't sending email

How to get customers data so i can pass it to a gateway payment.
Here is my model:
public function getStandardCheckoutFormFields() {
$orderIncrementId = $this->getCheckout()->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
//$order = $this->get_sale_order($orderIncrementId);
echo Mage::getModel('customer/customer')->load($orderIncrementId);
$productArray = array();
foreach ($order->getAllItems() as $item) {
$productArray[] = array(
"product_name" => $item->getName(),
"product_qty" => $item->getQtyOrdered(),
"product_price" => $item->getPrice(),
);
}
return $productArray;
}
here is my controller:
public function redirectAction(){
$session = Mage::getSingleton('checkout/session');
$session->setAsurepayCustompayQuoteId($session->getQuoteId());
$this->getResponse()->setBody($this->getLayout()->createBlock('custompay/redirect')->toHtml());
$session->unsQuoteId();
$session->unsRedirectUrl();
}
This are running perfectly running, the problem is i can't get customer details such as customer name, address and etc.
I already tried this code
Mage::getSingleton(customer/customer)->getData();
There was a result but not printing.
In the checkout page success (onepage). When customer redirected here, There is no email will be send to the customer and the order was not update as completed.
You're trying to load a customer with an id that belongs to the order. This obviously doesn't work! You need to extract the customer_id from the order and load the customer model based on that.
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
You're also using Mage::getSingleton which is the wrong call. You want a new instance tailored to a specific customer, not the single permissible instance of the class.

Categories