migs (MasterCard Virtual Payment Client) integration php

后端 未结 4 1030
既然无缘
既然无缘 2021-02-06 05:31

Can any body help me about how to integrate migs (MasterCard Virtual Payment Client) in a php website !

I have read the reference guide but it\

4条回答
  •  时光取名叫无心
    2021-02-06 06:13

    I tried MIGS mastercard intergration in python django. I went through lot of problems. Here is my experience with integrating MIGS with My web application. I was using VPC Integration reference 3.1.21.1

    1. While implementing Mode1 VPC: I got 400 Bad request. Which is due to Secure hash code for my case. This error occurs if user is sending wrong fields names or non sorted order.

    2. Once I resolved Mode1 error, I used external payment selection(EPS), Where I send VPC_card and VPC_gateway additional field with Mode1 VPC parameters. I got 400 Bad request. So after long discussion with MIGS support team. We resolve it by changing vpc_card to vpc_Card and vpc_Gateway. Which was document error.

    3. Once I able to bypass card type page. I tried to complete Mode 2 VPC implementation.So, In this case I added vpc_CardNum,vpc_vpc_CardExp,vpc_CardSecurityCode additional fields with above point request. I send GET request. It didnot work. For card details or Mode2 we have to use POST request.

    4. For mode2 VPC, we should use POST request with HTTPS not HTTP. Self-signed certificate will be fine. So, I send HTTPS POST request with additional parameter, But It still didnot work, I got 403 forbidden error. Because, Content-type is application/json for my ajax call. So after using default POST content-type. It worked fine.

    Sample code for python developer: Here in migs.config.app I am adding system variable which nothing to do with Migs. So User can ignore it.

    import hashlib
    import urllib, urllib2
    from migs.config.app_config import *
    
    
    '''
    This method is for sorting the fields and creating an MD5 secure hash.
    @param fields is a map of all the incoming hey-value pairs from the VPC
    @param buf is the hash being returned for comparison to the incoming hash
    '''
    
    
    class MigsClient(object):
    
    def __init__(self, secure_token, vpc_url, server_name):
        self.secure_secret  = secure_token
        self.vpcURL = vpc_url
        self.server_name = server_name    
    
    def hash_all_fields(self,fields):
        buf = ""
        # create a list and sort it
        fieldNames = fields.keys();
        fieldNames.sort()
        # create a buffer for the md5 input and add the secure secret first
        buf = buf + self.secure_secret
        for key in fieldNames:
            print key,fields[key]
            buf = buf + fields[key] 
        # iterate through the list and add the remaining field values
        # create the md5 hash and UTF-8 encode it
        try:
            m = hashlib.md5()
            m.update(buf)
            ba = m.hexdigest()
            ba = ba.upper()
            return ba
    
        except Exception,e:
            import traceback 
            traceback.print_exc()
    
    
    def setup(self, fields,additional_fields=None):
        #The Page does a redirect to the Virtual Payment Client
        #retrieve all the parameters into a hash map
        # no need to send the vpc url, EnableAVSdata and submit button to the vpc
    
        '''
        Retrieve the order page URL from the incoming order page and add it to 
        the hash map. This is only here to give the user the easy ability to go 
        back to the Order page. This would not be required in a production system
        NB. Other merchant application fields can be added in the same manner
        '''
    
        '''
        Create MD5 secure hash and insert it into the hash map if it was created
        created. Remember if self.secure_secret = "" it will not be created
        '''
        if self.secure_secret:
            secureHash = self.hash_all_fields(fields);
            fields["vpc_SecureHash"] = secureHash;
    
        # Create a redirection URL
        buf = self.vpcURL+'?';
        if not additional_fields:
            buf  = buf + urllib.urlencode(fields)
        else:
            buf  = buf + urllib.urlencode(fields)+"&"+urllib.urlencode(additional_fields) 
        return buf
        #return fields["vpc_ReturnURL"], buf
    
    
    def post_setup(self,fields, additional_fields=None):
    
        try:
            if self.secure_secret:
                secureHash = self.hash_all_fields(fields);
                fields["vpc_SecureHash"] = secureHash;
    
            return self.vpcURL,fields
        except:
            import traceback
            traceback.print_exc()
    

    Above is sample code which user can use to sort and create Get request and POST request and post dictionary.

提交回复
热议问题