2
votes

I am trying to implement 2checkout payment gateway with my django Application.I have created a simple django application with help of this 2Checkout Documentation

This is my javascript code:

`window.onload=function(){
   var successCallback = function(data) {
   var myForm = document.getElementById('myCCForm');
   myForm.token.value = data.response.token.token;
   myForm.submit();
};
var errorCallback = function(data) {
alert("ERROR CODE:"+data.errorCode);
  if (data.errorCode === 200) {
        alert('success');
        tokenRequest();
  } 
  else {
   alert(data.errorMsg);
 }
};
  var tokenRequest = function() {
   var args = {
        sellerId: "#mysellerid",
        publishableKey: "mypublishkey",
        ccNo: $("#ccNo").val(),
        cvv: $("#cvv").val(),
        expMonth: $("#expMonth").val(),
        expYear: $("#expYear").val()
    };
    TCO.requestToken(successCallback, errorCallback, args);
};

$(function() {
 $.getScript('https://www.2checkout.com/checkout/api/2co.min.js',   
   function()
   {
     try {
            TCO.loadPubKey('sandbox');

     } 
     catch(e) 
     {
      alert(e.toSource());
     }
   });
   $("#myCCForm").submit(function(e) {
           tokenRequest();
           return false;
   });
});
}`

This is my view function for processing the order:

 def order(request):
print('i am here')
# Setup credentials and environment
twocheckout.Api.auth_credentials({
    'private_key': 'privatekey',
    'seller_id': '#sellerid',
    'mode': 'sandbox'
})

# Setup arguments for authorization request
args = {
    'merchantOrderId': '123',
    'token': request.POST.get("token"),
    'currency': 'INR',
    'total': '1.00',
    'billingAddr': {
        'name': 'TEJKANWAR',
        'addrLine1': 'myaddressline1',
        'city': 'mycity',
        'state': 'mystate',
        'zipCode': 'pin',
        'country': 'IN',
        'email': '[email protected]',
        'phoneNumber': '+9199999999'
    }
}

# Make authorization request
try:
    result = twocheckout.Charge.authorize(args)
    return HttpResponse(result.responseMsg)
except TwocheckoutError as error:
    return HttpResponse(error.msg)

This is urls.py:

    from django.conf.urls import patterns, url
    from twochek import views

urlpatterns = patterns('',
                       url(r'^$', views.index, name='index'),
                       url(r'^order/$', views.order, name='order'),

                       )

I have made this form for getting payement info:

<form id="myCCForm" action="order/" method="post">
     {% csrf_token %}
    <div class="form-group">
    <input id="token" name="token"  class="form-control" value="">
    </div>
    <div class="form-group">
        <input  class="form-control" id="ccNo" type="text" size="20" value="" autocomplete="off" placeholder="Card number" required />
    </div>
    <div class="form-group form-inline">
        <input  class="form-control" type="text" size="25" id="expMonth" placeholder="Expiration Month(MM)" required />

        <input class="form-control" type="text" size="25" id="expYear" required placeholder="Expiration year(YYYY)"/>
    </div>
    <div class="form-group">
        <input class="form-control" id="cvv" size="4" type="text" value="" autocomplete="off" placeholder="CVC" required />
    </div>
    <input type="submit" value="Submit Payment" class="btn btn-success btn-md">
</form>

I have included jquery and 2co.min.js properly and tested them working in other conditions.But as soon as I click o submit payment I am getting error in debugger and i get this error:https://sandbox.2checkout.com/checkout/api/1/#10312645666554/rs/preTokenService? Saying [HTTP/1.1 404 Not found]

1

1 Answers

0
votes

The URL should not have the '#' in it. The merchant ID does not begin with a #, which is why the route was not found.

https://sandbox.2checkout.com/checkout/api/1/#10312645666554/rs/preTokenService

Note: 2checkout has now discontinued it's sandbox.