wojodesign / simplecart-js

A simple javascript shopping cart that easily integrates with your current website.
simplecartjs.org
1.79k stars 492 forks source link

Info Needed for 3rd Party Payment Solution #248

Open Swaartbaards opened 12 years ago

Swaartbaards commented 12 years ago

Hi - im trying to integrate CustomCart js with PayFast (a South African payment solution)

I know how to set up the 'sendform' option, but PayFast needs more information such as 'Merchat_ID' and 'Merchant_Key' which Payfast supplies me with when i open an account with them.

Where in the html or the simplecart.js would I supply the Merchant ID and Merchant Key so that when redirected from checkout to PayFast, it allows the redirection?

Ive been trying and trying but no luck yet

Help would be greatly appreciated!

Thanks, Dean

brettwejrowski commented 12 years ago

You can send any arbitrary information with the sendform option by using the 'beforeCheckout' method:

simpleCart.bind( 'beforeCheckout' , function( data ){
  data.Merchant_ID = "XXXXXXXX";
  data.Merchant_Key = "XXXXXXXXXXXXX";
});

Hope that helps you!

Swaartbaards commented 12 years ago

Hi Brett, thanks for the help!

The issue I have now is: The 3rd party payment gateway (PayFast) requires 4 variables in order to redirect to their site successfully: merchant_id, merchant_key, item_name and amount.

The problem is the amount. If I check out, the full price sent to PayFast is not the total price that was in my cart but rather the 'amount' that remains static. Hope that makes sense.

I need to send PayFast the cart value that will change depending on how many items a customer chooses rather than the static value of 10, in the example below.

The code im currently using is:

<script src="simpleCart.js"></script>
<script>
  simpleCart({
   checkout: {
     type: "SendForm",
     url: "https://www.payfast.co.za/eng/process",
     method: "Post",
     extra_data:{
       merchant_id: "XXXXX",
       merchant_key: "XXXXX",
       return_url: "http://www.sunshineinabottle.co.za/finish-url",
       cancel_url: "http://www.sunshineinabottle.co.za/cancel-url",
       item_name: "Sun Jar",
       amount: 10
     }
   }
 });
</script>

<div class="simpleCart_shelfItem">
  <h2 class="item_name"> Sun Jar </h2>
<p>  <input type="text" value="1" class="item_Quantity"/><br/>
  <span class="item_price">R200</span><br/>
  <a class="item_add" href="javascript:;"> ADD TO CART </a></p>
</div>a></p>
</div>
brettwejrowski commented 12 years ago

I am not positive that I follow, but you should be able to alter any of the data that needs to be sent to payfast with the beforeCheckout function. Try adding this:

simpleCart.bind( 'beforeCheckout' , function( data ){
  // have web inspector open so you can look through
  // all the data that will be sent
  console.log( data );  

  // then add any lines here that need to alter the data being sent
  data.amount = simpleCart.quantity(); // or whatever this needs to be

});
Swaartbaards commented 12 years ago

Hey thanks for the reply,

I was able to add the above into the simpleCart.js but it doesn't do anything. It still redirects to PayFast with whatever value is in in the html code ('amount: 10' in this instance)

If i leave 'amount:10' out of the code it returns with an error 'payfast requires amount in order to process'

Yeah i know, it is a bit confusing... thanks for the help though!

Bets cart solution ive ever come across - if i can get as far as I have, anyone should be able to!

brettwejrowski commented 12 years ago

Do you have a page I can take a look at to see whats happening?

Swaartbaards commented 12 years ago

Hi Brett, with absolute pleasure.

The page i'm using to test the cart is www.sunshineinabottle.co.za/test

Im a complete noob at html and java and have gotten as far as I can - thanks again for the assistance

Swaartbaards commented 12 years ago

Got it working thanks!

On Fri, Jun 15, 2012 at 4:23 AM, brettwejrowski < reply@reply.github.com

wrote:

Do you have a page I can take a look at to see whats happening?


Reply to this email directly or view it on GitHub: https://github.com/wojodesign/simplecart-js/issues/248#issuecomment-6348259