<commit_before>MangoPaySDK.card = {

    /**
     * Types of card
     */
    type: {
        diners: 'DINERS',
        maestro: 'MAESTRO',
        visaMastercard: 'CB_VISA_MASTERCARD'
    },

    /**
     * Creates a new card
     * @param obj
     * @param callback
     */
    create: function (obj, callback) {
        if (!(obj instanceof MangoPaySDK.card.Card)) {
            throw new Error('obj is not instance of Card');
        }

        // Cast Card to CardRegistration
        var cr = new MangoPaySDK.card.CardRegistration(obj);

        // Create the card registration
        MangoPaySDK.card.createRegistration(cr, function (err, result) {
            if (err) {
                handleAPIResponse(err, result);
            } else {
                console.log('CR', result);

                console.log({
                    data: result.PreregistrationData,
                    accessKeyRef: result.AccessKey,
                    cardNumber: obj.CardNumber,
                    cardExpirationDate: obj.CardExpirationDate,
                    cardCvx: obj.CardCvx
                });

                // Send card details
                HTTP.post(result.CardRegistrationURL, {
                    data: {
                        data: result.PreregistrationData,
                        accessKeyRef: result.AccessKey,
                        cardNumber: obj.CardNumber,
                        cardExpirationDate: obj.CardExpirationDate,
                        cardCvx: obj.CardCvx
                    }
                }, function (err, result2) {
                    if (err) {
                        handleAPIResponse(err, result2);
                    } else {
                        console.log('RD', result2);

                        var data2 = result2.data;

                        // Save registration data
                        MangoPaySDK.card.update(result.Id, {
                            RegistrationData: data2
                        }, callback);
                    }
                });
            }
        });
    },

    /**
     * Creates a new card registration
     * @param obj
     * @param callback
     */
    createRegistration: function (obj, callback) {
        if (!(obj instanceof MangoPaySDK.card.CardRegistration)) {
            throw new Error('obj is not instance of CardRegistration');
        }
        HttpClient.post('/cardregistrations', obj, callback);
    },

    /**
     * Updates the card by Id
     * @param id
     * @param obj
     * @param callback
     */
    update: function (id, obj, callback) {
        if (typeof id !== 'number' && typeof id !== 'string') {
            throw new Error('id is not valid');
        }
        if (typeof obj !== 'object' || obj === null) {
            throw new Error('obj is not valid');
        }
        HttpClient.post('/cardregistrations/' + id, obj, callback);
    },

    /**
     * A payment card
     * @param options
     * @constructor
     */
    Card: function (options) {
        this.CardCvx = null;
        this.CardExpirationDate = null;
        this.CardNumber = null;
        this.CardType = null;
        this.Currency = null;
        this.UserId = null;

        _.extend(this, options);
    },

    /**
     * A payment card
     * @param options
     * @constructor
     */
    CardRegistration: function (options) {
        this.CardType = null;
        this.Currency = null;
        this.UserId = null;

        _.extend(this, options);
    }
};<commit_msg>- moved CardRegistration in MangoPay.cardRegistration - fixed the code that sends card details in MangoPay.card.create()<commit_after>MangoPaySDK.card = {

    /**
     * Types of card
     */
    type: {
        DINERS: 'DINERS',
        IDEAL: 'IDEAL',
        MAESTRO: 'MAESTRO',
        MASTERPASS: 'MASTERPASS',
        P24: 'P24',
        VISA_MASTERCARD: 'CB_VISA_MASTERCARD'
    },

    /**
     * Creates a new card
     * @param obj
     * @param callback
     */
    create: function (obj, callback) {
        if (!(obj instanceof MangoPaySDK.card.Card)) {
            throw new Error('obj is not instance of Card');
        }

        // Cast Card to CardRegistration
        var cr = new MangoPaySDK.cardRegistraton.CardRegistration(obj);

        // Create the card registration
        MangoPaySDK.cardRegistraton.create(cr, function (err, result) {
            if (err || !result || result.Status !== MangoPaySDK.cardRegistraton.status.CREATED) {
                handleAPIResponse(err, result);
            } else {
                // Send card details
                HTTP.post(result.CardRegistrationURL, {
                    params: {
                        data: result.PreregistrationData,
                        accessKeyRef: result.AccessKey,
                        cardNumber: obj.CardNumber,
                        cardExpirationDate: obj.CardExpirationDate,
                        cardCvx: obj.CardCvx
                    }
                }, function (err, result2) {
                    if (err || !result2 || result2.statusCode !== 200 || !result2.content) {
                        handleAPIResponse(err, result2);
                    } else {
                        // Save registration data
                        MangoPaySDK.cardRegistraton.update(result.Id, {
                            RegistrationData: result2.content
                        }, callback);
                    }
                });
            }
        });
    },

    /**
     * Fetches the card by Id
     * @param cardId
     * @param callback
     */
    fetch: function (cardId, callback) {
        if (typeof cardId !== 'number' && typeof cardId !== 'string') {
            throw new Error('cardId is not valid');
        }
        HttpClient.get('/cards/' + cardId, callback);
    },

    /**
     * Updates the card by Id
     * @param cardId
     * @param obj
     * @param callback
     */
    update: function (cardId, obj, callback) {
        if (typeof cardId !== 'number' && typeof cardId !== 'string') {
            throw new Error('cardId is not valid');
        }
        if (typeof obj !== 'object' || obj === null) {
            throw new Error('obj is not valid');
        }
        HttpClient.put('/cards/' + cardId, obj, callback);
    },

    /**
     * A payment card
     * @param options
     * @constructor
     */
    Card: function (options) {
        this.CardCvx = null;
        this.CardExpirationDate = null;
        this.CardNumber = null;
        this.CardType = null;
        this.Currency = null;
        this.UserId = null;

        _.extend(this, options);
    }
};

MangoPaySDK.cardRegistraton = {

    /**
     * Status of the Card Registration
     */
    status: {
        CREATED: 'CREATED',
        ERROR: 'ERROR',
        VALIDATED: 'VALIDATED'
    },

    /**
     * Creates a new card registration
     * @param obj
     * @param callback
     */
    create: function (obj, callback) {
        if (!(obj instanceof MangoPaySDK.cardRegistraton.CardRegistration)) {
            throw new Error('obj is not instance of CardRegistration');
        }
        HttpClient.post('/cardregistrations', obj, callback);
    },

    /**
     * Updates the card registration by Id
     * @param cardRegistrationId
     * @param obj
     * @param callback
     */
    update: function (cardRegistrationId, obj, callback) {
        if (typeof cardRegistrationId !== 'number' && typeof cardRegistrationId !== 'string') {
            throw new Error('cardRegistrationId is not valid');
        }
        if (typeof obj !== 'object' || obj === null) {
            throw new Error('obj is not valid');
        }
        HttpClient.put('/cardregistrations/' + cardRegistrationId, obj, callback);
    },

    /**
     * A payment card registration
     * @param options
     * @constructor
     */
    CardRegistration: function (options) {
        this.CardType = null;
        this.Currency = null;
        this.UserId = null;

        _.extend(this, options);
    }
};
{'fraction_non_alphanumeric': 0.10961298377028714, 'fraction_numerical': 0.002372034956304619, 'mean_word_length': 1.4855724480297858, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '558018', 'n_tokens_mistral': 2179, 'n_tokens_neox': 2084, 'n_words': 531}