# File Based Scoring Calculation
source: https://developer.mastercard.com/carbon-calculator/documentation/use-cases/file_based_scoring/index.md

The **File Based Scoring Calculation** service allows the issuer to calculate the file based scoring transaction footprint option based on the customer's payment transactions. This service does not require any payment card registration.

By enabling the file based scoring option, the issuer can upload a maximum of 1,00,000 transactions via a CSV file. Issuers can upload the CSV files containing transactions to [NGFT(Mastercard File Exchange Service)](https://techdocs.mastercard.com/bundle/p_FXUSG/page/yyf1676873871848.html). The file is scored in real time, and the scored file is uploaded back to NGFT. Issuers do not need to integrate with any API.
Note:   

* This feature is only applicable for existing NGFT users Globally.
* This feature is not applicable to On-Soil Customers on NGFT. Work is currently in progress.
* This feature is not applicable to GFT users at the moment. Work is currently in progress for GFT customers.

## Pre-requisites {#pre-requisites}

Following are the pre-requisites for the issuer to use this service:  

* Mastercard Connect account and should be an existing customer of NGFT.
* Issuers need to have an existing logical address with their organization name in the alias part called customer logical name. Kindly note that the terms "**Sender Id** " and "**Customer logical name**" are used interchangeably.
* Issuers can now request an exchange mapping from the [Mastercard File Exchange Onboarding Guide](https://techdocs.mastercard.com/bundle/p_FXUSG/page/yyf1676873871848.html) service and map their customer logical name with the customer logical name of Mastercard. This request will be reviewed and approved by the Mastercard contact.
* Issuers need to create a new project in Mastercard Developers. Kindly share the same customer logical name with Mastercard Carbon Calculator applications via the Mastercard Developers form or [Update Service Provider](https://developer.mastercard.com/carbon-calculator/documentation/use-cases/service_provider_details/index.md) API.

## Selection Criteria {#selection-criteria}

* Issuers need to set up exchange mapping to the **cc-file-processor@mastercard** as customer logical name in both the Sandbox/MTF and Production environments.
* Issuers need to select **carbon_calculator_file_scoring** as a **File Profile** for Actions (PRODUCES, CONSUMES), while adding a new product.
* Issuers need to select **Web UI** , **Push** and **Pull** as options under the connections tab. This will make the selections look like **Customer logical name** will use **Web UI** to **Push** -**Pull** files to Mastercard.

## Sequence Diagram {#sequence-diagram}

The following sequence diagram shows the order of events for a solution that uses the `file based scoring` service.

Diagram file-based-scoring

**Following are the execution steps:**

1. If an issuer is new to the Mastercard Carbon Calculator applications, then the issuer sends the customer logical name using the Mastercard Developers form while onboarding for Carbon Calculator.
2. The file based scoring service receives the customer logical name from submission request via Mastercard Developers.
3. The file based scoring service creates the service provider and adds the customer logical name for the issuer.
4. An issuer sends the update service provider request for the customer logical name if the issuer already exists within the system.
5. The file based scoring service updates the service provider.
6. The issuer receives the confirmation message as updated or rejected.
7. An issuer uploads a file that includes transaction records with the transaction ID, amount, currency code, and MCC (Merchant Category Code).
8. NGFT publishes the notification to the file based scoring service.
9. The file based scoring service downloads the file and scores the valid transaction records.
10. The file based scoring service uploads the file back to NGFT with the scored records.
11. The file based scoring service will send an error code along with a description if the currency or MCC is either not supported, or the transaction ID is duplicate.

<br />

**Field Constraints**

|  Field Names   |                                                                      Field Constraints                                                                       |
|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Transaction ID | Should be unique and between 1-100 characters only in the same file.                                                                                         |
| Currency       | Should be in ISO 4217 format up to three characters.                                                                                                         |
| Amount         | Should be numeric only with max two decimal places.                                                                                                          |
| File name      | Should be 200 characters only including the extension ".csv".                                                                                                |
| CardBrand      | Should be max three characters: MA or NC or OTH. If either the value is not 'MA' or 'NC' or not present, the transaction is considered a non-MA transaction. |

Note:   

* Issuers need to set up exchange mapping to the **cc-file-processor@mastercard** as customer logical name in both the Sandbox/MTF and Production environments.
* Issuers need to select **carbon_calculator_file_scoring** as a **File Profile** for Actions (PRODUCES, CONSUMES), while adding a new product.
* An issuer can upload up to a maximum of 15 files with every 1,00,000 transactions in one day. If issuers upload more files, the files can still be processed, but the SLAs will not be applicable.
* The content of the file should only be in CSV format. The file should have a ".csv" extension.
* No ',' (comma) character is allowed in any field value. This will break the number of expected parameters as it is in CSV file format.
* The response file name will be original_file_name+\< UUID \>.csv.
* In the file name, "." is not allowed except at the end of the name for the ".csv" extension.
* Extra fields in any record at the end are skipped.
* Existing issuers can use the [Update Service Provider](https://developer.mastercard.com/carbon-calculator/documentation/use-cases/update_service_provider_details/index.md) API to configure their customer logical name.
* [Refer](https://developer.mastercard.com/carbon-calculator/documentation/use-cases/file_based_scoring/index.md#sample-input-output-file-format) to the sample request and response files and send files accordingly.

## Sample Input/Output File Format {#sample-inputoutput-file-format}

Following is the format of the sample input/output:
* Input
* Output

```Input
transactionId,mcc,amountValue,amountCurrencyCode,cardBrand
ee421c25-f5-b8-3600b76b8811,3857,999,EUR,MA
ee421c25-f5-b8-3600b76b8812,3857,1324,EUR,MA
ee421c25-f5-b8-3600b76b8813,5436,537,IN,MA
ee421c25-f5-b8-3600b76b8814,2323,3434,IN,OTH
ee421c25-f5-b8-3600b76b8815,4324,20004,USD,MA
ee421c25-f5-b8-3600b76b8816,6433,4332,IN,OTH
ee421c25-f5-b8-3600b76b8817,8844,23,USD,MA
ee421c25-f5-b8-3600b76b8818,9777,9897,USD,MA
ee421c25-f5-b8-3600b76b8819,4324,20004,USD,NC
```

```Output
txId, mcc, amount, currency, fileId, carbonEmissionInGrams, carbonEmissionInOunces, sectorCode, sector, subCategory, mainCategory, errorCode, errorDescription
ee421c25-f5-b8-3600b76b8811,3857,999,EUR,d026d85d-2ac7-4c4b-83b2-71596019ef1b,253145.42,8929.45,604,Hotels, Motels & Resorts,Hotels & Vacation ,,
ee421c25-f5-b8-3600b76b8812,3857,1324,EUR,d026d85d-2ac7-4c4b-83b2-71596019ef1b,3423.2,234.2,543,Hardware Stores & Contractor Services, Hardware & Construction,Home & Garden ,,
ee421c25-f5-b8-3600b76b8813,5436,537,IN,d026d85d-2ac7-4c4b-83b2-71596019ef1b,654.34,231.3,87,Garden Supply Stores & Services, Garden Supply,Home & Garden ,,
ee421c25-f5-b8-3600b76b8814,2323,3434,IN,d026d85d-2ac7-4c4b-83b2-71596019ef1b,2342.23,134.2,343,Equipment,  Furniture & Home Furnishings,Furniture & Decoration ,,
ee421c25-f5-b8-3600b76b8815,4324,20004,USD,d026d85d-2ac7-4c4b-83b2-71596019ef1b,54643.4,3453.3,5342,Grocery Stores & Supermarkets, Groceries,Food & Beverages ,,
ee421c25-f5-b8-3600b76b8816,6433,4332,IN,d026d85d-2ac7-4c4b-83b2-71596019ef1b,975.3,234.2,453,Restaurants, Restaurants & Fast Food,Food & Beverages ,,
ee421c25-f5-b8-3600b76b8817,8844,23,USD,d026d85d-2ac7-4c4b-83b2-71596019ef1b,6532.1,546.21,213,Railroads & Freight, Train,Transportation ,,
ee421c25-f5-b8-3600b76b8818,9777,9897,USD,d026d85d-2ac7-4c4b-83b2-71596019ef1b,234234.2,3423.3,6343,Airlines, Flights,Transportation ,,
ee421c25-f5-b8-3600b76b8819,4324,20004,USD,d026d85d-2ac7-4c4b-83b2-71596019ef1b,66752.5,4564.4,5342,Grocery Stores & Supermarkets, Groceries,Food & Beverages ,,
```

## How to Upload a File {#how-to-upload-a-file}

1. Once login is successful, the company ID for the logged in user appears in the top right corner of the screen.

2. Select the **Transfers** tab.

   ![Upload Transfer Tab](https://static.developer.mastercard.com/content/carbon-calculator/Images/usecases/file-based-scoring/upload_transfer.png)
3. Search your logical address, for example, **cc-file-processor@mastercard**.

   ![Upload Search](https://static.developer.mastercard.com/content/carbon-calculator/Images/usecases/file-based-scoring/upload_search_new.png)
4. Click **Send** to upload files via **Drag and drop** or the **Choose a File** option.

   ![Upload Sent Option](https://static.developer.mastercard.com/content/carbon-calculator/Images/usecases/file-based-scoring/upload_sent_new.png)
5. Click **Choose a File** or **Drag and drop** to select the file from your local machine.

   ![Upload Sent Option](https://static.developer.mastercard.com/content/carbon-calculator/Images/usecases/file-based-scoring/upload_choose_file_new.png)
6. After uploading a file, the success screen appears.

   ![Upload Success](https://static.developer.mastercard.com/content/carbon-calculator/Images/usecases/file-based-scoring/upload_success_new.png)

## How to Download a File {#how-to-download-a-file}

1. On the **Transfer** tab, click **Received** to see all the files available for download.

   ![Download File](https://static.developer.mastercard.com/content/carbon-calculator/Images/usecases/file-based-scoring/download_file.png)
2. Click **Download** to view the transaction scoring details against each transaction.

