How to display customer saved cards on checkout page in Joomla Payment Plugin

  • Posts: 21
  • Thank you received: 0
4 years 4 months ago #321682

-- HikaShop version -- : 4.3.0
-- Joomla version -- : 3.9.19
-- PHP version -- : 7.3

Hello all,

I am working on a custom third party payment plugin and I manage to make payment using this. Now in this payment gateway, there is a functionality to make payment using card token so I am saving card token with customer id in a db table.

Now what I want is, I want to fetch customer saved cards and want to display when my payment gateway is selected on checkout page. Please see attached image for example.



Now once any one card token is selected, payment should be made using this selected card token.

I'll be very thankful if anyone can help me out.

Thanks in advance !

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
4 years 4 months ago #321683

Hello,

We'll need more information about your code, what you want to achieve and what you actually have please.

Kind regards,
Mohamed.

Please Log in or Create an account to join the conversation.

  • Posts: 21
  • Thank you received: 0
4 years 4 months ago #321699

Actually, When customer make payment using credit card, then in response, I get their credit card token and I save this token and card info into table.

$card = new stdClass();
$card->id = $card_id;
$card->customer_id = $customer_id;
$card->card_type = $cardType;
$card->card_acquirer = $cardAcquirer;
$card->card_brand = $cardBrand;
$card->credit_company = $creditCompany;
$card->card_token = $card_token;

Now what I want is when this customer purchase again on site then I want to show his saved card listing on checkout page under my payment option and when he selects any of his saved card then I'll process the payment using card token instead of redirecting him to payment gateway.



I hope this clears what I want to implement.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 21
  • Thank you received: 0
4 years 4 months ago #321705

Hello Mohamed,
I posted how I am going to implement that. Please see my reply in thread and let me know if can help me out.

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 4 months ago #321709

Hi,

What you want to do is two things:
- implement the onPaymentSave function in your plugin to retrieve the selected card (token) and store that in the session of the user so that you know which one was selected
- implement the onBeforeOrderCreate function to process the payment and set $do to false if there is an error (or the onAfterOrderConfirm function and redirect to the cancel url of HikaShop so that the order is cancelled and the user goes back to the checkout)

Please Log in or Create an account to join the conversation.

  • Posts: 21
  • Thank you received: 0
4 years 4 months ago #321711

Hello Nicolas,
Thanks for replying.

What I am facing issue is that I don’t know how to show listing of saved card on checkout page.

I just created above images using photoshop to explain what I want to implement.

So if you can let me know first that How to show saved card listing on checkout page that would be helpful for me to proceed further.

Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 4 months ago #321715

Hi,

Oh, I thought you already had that covered.
In that case, I would recommend you to check the plugins/hikashoppayment/purchaseorder folder.
That's a payment plugin which is by default in HikaShop and when selected, it displays an input field where the customer can enter something and then it will get that value and save it in the order when the order is created.
So I think it's a good base for your payment plugin.

Please Log in or Create an account to join the conversation.

  • Posts: 21
  • Thank you received: 0
4 years 4 months ago #321727

Hello Nicolas,

I tried the suggestion you told me in above reply and now I understood that how to show list here. I need to use below function but as you can see it only support only one parameter which is "$method" which does not give me logged in customer id in this function.

Because I want to fetch card list based on logged in customer. Like if John Doe is logged in then I want to fetch only his saved card. I hope you understand what I am trying to say.

public function needCC(&$method) {
		$method->custom_html = '<span style="margin-left:10%">' . JText::_('PURCHASE_ORDER_NUMBER') .
			'<input type="text" class="hikashop_purchase_order_number inputbox required" name="hikashop_purchase_order_number" value="'.@$_SESSION['hikashop_purchase_order_number'].'"/> *</span>';
	}


So If there is any way to get customer id in this function, please let me know.
Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 4 months ago #321757

Hi,

Well, it depends what user id you're talking about.
If you're talking about the Joomla user id from the #__users table, you can get it with :
$user = JFactory::getUser();
echo $user->id;
And if it's the user_id of the HikaShop user entry in the #__hikashop_user table, you can get it with:
echo hikashop_loadUser();

The following user(s) said Thank You: ajdev33

Please Log in or Create an account to join the conversation.

  • Posts: 21
  • Thank you received: 0
4 years 4 months ago #321823

Hello Nicolas,
Thanks for providing needed answer. Now I am able to display listing of saved card of users.

However I am facing another issue of getting cart total / order total in needCC function. So is there a way to get cart total or order total in needCC function ? If yes then please let me know.

Thanks

Last edit: 4 years 4 months ago by ajdev33.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 4 months ago #321841

Hi,

Yes. You can use such code to get the cart data object:

hikashop_get('helper.checkout');
$checkoutHelper = hikashopCheckoutHelper::get();
$cart = $checkoutHelper->getCart();

And then you can get the total price with:
echo $cart->full_total->prices[0]->price_value_with_tax;

Note that this includes the coupon, the shipping cost, the taxes and the payment fee.

The following user(s) said Thank You: ajdev33

Please Log in or Create an account to join the conversation.

Time to create page: 0.090 seconds
Powered by Kunena Forum