omise/omise-php

Need example on php

Closed this issue · 15 comments

Hello,

Can I get one end to end to example in php for accepting credit card details and charging the payment and capturing response back.

Regards,
Tejas

Hello @tvadalia

For now,

You can read more information about how to integrate our service via https://docs.omise.co/ only.
We will add more example and practice code into omise-php lib soon!

For you

Collecting a card details
https://docs.omise.co/collecting-card-information/
noted: For best practice, use Omise-js (with Jquery) from client side to collect customer card information, we will create some Token for you, then use Charge API from server side to charge a card from your customer card. For more information please click the link above

Charging the payment
https://docs.omise.co/charging-cards/

Thanks for your interest.
Guzzilar

Hi Guzzilar,

Thanks for sharing the detalis.

Couple of points:
I tried attach sample file provided in the link. One is to generate token
but when it generate token it seems there is no way to get token details
back. If so then how do we proceed with payment?

Omise.createToken("card", card, function (statusCode, response)
{
if (response.object == "error") {
// Display an error message.
$("#token_errors").html(response.message);

  // Re-enable the submit button.
  form.find("input[type=submit]").prop("disabled", false);
} else {
  // Then fill the omise_token.
  form.find("[name=omise_token]").val(response.id);

  // And submit the form.
  form.get(0).submit();
};

});

Other is pay now:
If We want to use that directly can you please let me know test security
key and expiration details which can be use with Credit card ID :
42424242424242

Regards,
Tejas

On Sun, Apr 5, 2015 at 5:47 PM, Nuttanon Trapnirundon <
notifications@github.com> wrote:

Hello @tvadalia https://github.com/tvadalia
For now,

You can read more information about how to integrate our service via
https://docs.omise.co/ only.
We will add more example and practice code into omise-php lib soon!
For you

Collecting a card details
https://docs.omise.co/collecting-card-information/
noted: For best practice, use Omise-js
https://github.com/omise/omise.js (with Jquery
https://github.com/jquery/jquery) from client side to collect customer
card information, we will create some Token for you, then use Charge API
https://docs.omise.co/api/charges/ from server side to charge a card from
your customer card. For more information please click the link above

Charging the payment
https://docs.omise.co/charging-cards/

Thanks for your interest.
Guzzilar


Reply to this email directly or view it on GitHub
#8 (comment).

Tejas Vadalia
Cell: +919820984387
tejas_vadalia@yahoo.com, tejas.vadalia@gmail.com

sirn commented

@tvadalia

Hi,

Regarding the test number, you can use any CVC and expiration date for the test card in test mode. It will be considered valid if expiration date is later than the current date. There are few numbers that could be used in test, please see test card section in the documentation.

For creating a payment, normally you will have to use Omise.js to tokenize the card detail via JavaScript in HTML form (or Omise-Android/Omise-iOS if you're building native app.)

In the Omise.js, you can retrieve a token information via response. You will want to pass response.id to a hidden field in a form and re-submit it to your server for further processing. In summary, the flow is usually:

  1. In the frontend: tokenize the card and submit response.id (token id) to the backend.
  2. In the backend: use the submitted response.id to create customer and/or create a charge.

For the (1) please see example.html for a detailed example. For (2) if you submit the token to your server as token parameter (e.g. $_POST['token']), then to make a charge, you would do something similar to this in your backend code:

<?php

$charge = OmiseCharge::create(array(
  'amount' => 100000,
  'currency' => 'thb',
  'card' => $_POST['token']
));

Please note that amount must be in Satang. You can check whether the charge went successfully or not by checking $charge['authorized'] && $charge['captured'] which should both be true in case the charge was successful.

We're looking to improve our documentation in couple of weeks. Stay tuned!

Hi,

This is great. Can you please also share an example of charging card with
return URL after accepting token value. That will help give end to end
example.

Regards,
Tejas

On Sun, Apr 5, 2015 at 11:34 PM, Kridsada Thanabulpong <
notifications@github.com> wrote:

@tvadalia https://github.com/tvadalia

Hi,

Regarding the test number, you can use any CVC and expiration date for the
test card in test mode. It will be considered valid if expiration date is
later than the current date. There are few numbers that could be used in
test, please see test card https://docs.omise.co/api/tests/ section in
the documentation.

For creating a payment, normally you will have to use Omise.js
https://docs.omise.co/omise-js/ to tokenize the card detail via
JavaScript in HTML form (or Omise-Android
https://github.com/omise/omise-android/Omise-iOS
https://github.com/omise/omise-ios if you're building native app.)

In the Omise.js, you can retrieve a token information via response. You
will want to pass response.id to a hidden field in a form and re-submit
it to your server for further processing. In summary, the flow is usually:

  1. In the frontend: tokenize the card and submit response.id (token
    id) to the backend.
  2. In the backend: use the submitted response.id to create customer
    and/or create a charge.

For the (1) please see example.html
https://github.com/omise/omise.js/blob/5c816e9fc50d7585e8855f73e57ddcd6682cb7d1/examples/index.html
for a detailed example. For (2) if you submit the token to your server as
token parameter (e.g. $_POST['token']), then to make a charge, you would
do something similar to this in your backend code:

100000, 'currency' => 'thb', 'card' => $_POST['token'])); Please note that amount must be in Satang. You can check whether the charge went successfully or not by checking $charge['authorized'] && $charge['captured'] which should both be true in case the charge was successful. We're looking to improve our documentation in couple of weeks. Stay tuned! — Reply to this email directly or view it on GitHub https://github.com//issues/8#issuecomment-89822105.

Tejas Vadalia
Cell: +919820984387
tejas_vadalia@yahoo.com, tejas.vadalia@gmail.com

zdk commented

@tvadalia There was a return_uri attribute for a charge. But it has been deprecated now. So you might have to handle url redirect within your code, with php http_redirect() for instance.

Hi,

Thanks for the update. I was actually looking on example of passing token
to charge credit card. Is it possible to share one example that can help.

Regards,
Tejas

On Tue, Apr 7, 2015 at 9:01 AM, Di Warachet notifications@github.com
wrote:

@tvadalia https://github.com/tvadalia There was a return_uri attribute
for a charge. But it has been deprecated now. So you might have to handle
url redirect within your code, with php http_redirect() for instance.


Reply to this email directly or view it on GitHub
#8 (comment).

Tejas Vadalia
Cell: +919820984387
tejas_vadalia@yahoo.com, tejas.vadalia@gmail.com

zdk commented

@tvadalia
You could check that out in https://docs.omise.co/api/charges/ and see illustrated PHP code example in "charge a card using token"

That said, you can pass the token as card attribute, like so:

$charge = OmiseCharge::create(array(
  'amount' => 100000,
  'currency' => 'thb',
  'card' => 'tokn_test_4xs9408a642a1htto8z'
));

Hi,

I tried following approach but it's failing. Please advise:

<script>
  (function($, window, undefined) {
    "use strict";
    $(document).ready(function () {
      // The public key could be found in Omise Dashboard. You must set
      // the public key before calling Omise.createToken otherwise
      // it will result in authentication error.
      Omise.setPublicKey("pkey_test_4z71v4cxi9f9h52dvcs");
      // When the card form is submitted, we call Omise.createToken to
      // turn the card information to one-time token.
      $("#card").submit(function() {
        // Create a token with Omise. Form data is retrieved from

data-omise
// set in attribute. Please note that it is important
that
// form inputs DO NOT have "name" attribute.
Omise.createToken("card", {
"name": $("[data-omise=card_name]").val(),
"number": $("[data-omise=card_number]").val(),
"expiration_month": $("[data-omise=card_expm]").val(),
"expiration_year": $("[data-omise=card_expy]").val(),
"security_code": $("[data-omise=security_code]").val()
}, function(statusCode, response) {
// This callback will be called regardless of token creation
// was success or not. You may check the status of token
// creation with statusCode or by checking response.object.
//
// In case of an error, an "error" object will be returned.
// The error messages are retrieveable from response.message
// in such case.
//
// In an actual credit card form, you will want to store the
// token id in a hidden form field and submit it to your web
// server for further processing.
alert(response.code+": "+response.message +"==>"+ response.id)
if (response.object == "token") {
$("#response").html(response.id);
} else {
$("#response").html(response.code+": "+response.message)
};
// document.card.token.value = response.id
});

omise.charges.create({
'amount': '100000',
'currency': 'thb',
'card': 'tokn_test_4xs9408a642a1htto8z'
}, function(err, charge) {
/**/
});
// Skip submitting form.
return false;
});
});
})(jQuery, window);

</script>

Regards,
Tejas

On Tue, Apr 7, 2015 at 10:58 AM, Di Warachet notifications@github.com
wrote:

@tvadalia https://github.com/tvadalia
You could check that out in https://docs.omise.co/api/charges/ and see
illustrated PHP code example in "charge a card using token"

That said, you can pass the token as card attribute, like so:

$charge = OmiseCharge::create(array(
'amount' => 100000,
'currency' => 'thb',
'card' => 'tokn_test_4xs9408a642a1htto8z'
));


Reply to this email directly or view it on GitHub
#8 (comment).

Tejas Vadalia
Cell: +919820984387
tejas_vadalia@yahoo.com, tejas.vadalia@gmail.com

@tvadalia Could you tell me more about your error or failed message that you have received?

Regards,
Guzzilar

Hi,

Functionality is not working to charge card. Please find the attached file.
Please help to understand what is wrong.

Also, I tried submitting forms directly to https://api.omise.co/charges but
even that fails with message stating Authentication Failed.

Regards,
Tejas

On Sat, Apr 11, 2015 at 11:01 PM, Nuttanon Trapnirundon <
notifications@github.com> wrote:

@tvadalia https://github.com/tvadalia Could you tell me more about your
error or failed message that you have received?

Regards,
Guzzilar


Reply to this email directly or view it on GitHub
#8 (comment).

Tejas Vadalia
Cell: +919820984387
tejas_vadalia@yahoo.com, tejas.vadalia@gmail.com

Hi @tvadalia

From your code

omise.charges.create({
  'amount': '100000',
  'currency': 'thb',
  'card': 'tokn_test_4xs9408a642a1htto8z'
}, function(err, charge) {
  /**/
});

This line should move into Back-end layer, not Front-end.

After Omise.createToken return some token to you, you should append this token back to your form,
something like

<form id="your-form">
  <input type="hidden" name="omise_token">
</form>
$('#your-form').find("[name=omise_token]").val(the_token);

and re-submit your form again like

$('#your-form').submit();

So, everything I said in above should be done in (from your code)...

Omise.createToken("card", {
  "name": $("[data-omise=card_name]").val(),
  "number": $("[data-omise=card_number]").val(),
  "expiration_month": $("[data-omise=card_expm]").val(),
  "expiration_year": $("[data-omise=card_expy]").val(),
  "security_code": $("[data-omise=security_code]").val()
}, function(statusCode, response) {
  // ... HERE :)
});

This's how to collect your customer card in Front-end layer.

For charge a card please look at link https://docs.omise.co/charging-cards/
and It should code in Back-end layer side (this's mean in PHP language, not Javascript)

Regards,
Guzzilar

Hi,

While using Payment gateway am getting below error:
Token was not found.

Please access below URL and click submit will throw the exception.
https://www.guest2go.com/hotel/payment/index.php

Could you please help me understand what is missing.

Regards,
Tejas

On Mon, May 11, 2015 at 11:27 AM, Robin Clart notifications@github.com
wrote:

Closed #8 #8.


Reply to this email directly or view it on GitHub
#8 (comment).

Tejas Vadalia
Cell: +919820984387
tejas_vadalia@yahoo.com, tejas.vadalia@gmail.com

Hi,

Could you give me some part of your code inside try { } catch() { } block ?

Regards,
Nam

Please find the attached file. Checkout.php has the code.

Regards,
Tejas

On Fri, Oct 9, 2015 at 12:05 AM, Nuttanon Trapnirundon <
notifications@github.com> wrote:

Hi,

Could you give me some part of your code inside try { } catch() { } block
?

Regards,
Nam


Reply to this email directly or view it on GitHub
#8 (comment).

Tejas Vadalia
Cell: +919820984387
tejas_vadalia@yahoo.com, tejas.vadalia@gmail.com

Hi,

Could you please send it again to our support email (support@omise.co) ?
Sorry for your inconvenience.

Regards,
Nam