SDK Sale

Document created by gjsissons on May 6, 2016Last modified by swapnil.hande on Nov 26, 2018
Version 2Show Document
  • View in full screen mode

The Sale transaction enables you to both authorize fund availability and deposit those funds by means of a single transaction. The Sale transaction is also known as a conditional deposit, because the deposit takes place only if the Authorization succeeds. If the Authorization is declined, the deposit will not be processed.

 

Note: If the Authorization succeeds, the deposit will be processed automatically, regardless of the AVS or CVV2 response.

 

 

 

PHP example

 

<?php

require __DIR__ . "/path/to/vendor/autoload.php";

use cnp\sdk\CnpOnlineRequest;
use cnp\sdk\XmlParser;

$hash_in = array(
'card' => array('type' => 'VI',
'number' => '4100000000000000',
'expDate' => '1213',
'cardValidationNum' => '1213'),
'id' => '1211',
'orderId' => '2111',
'reportGroup' => 'Planets',
'orderSource' => 'ecommerce',
'amount' => '123');

$initialize = new CnpOnlineRequest();
$saleResponse = $initialize->saleRequest($hash_in);
$response = XmlParser::getDomDocumentAsString($saleResponse);

print_r($response);
?>

 

Java example

 

package com.cnp.sdk;

import com.cnp.sdk.generate.*;

public class Example {
public static void main(String[] args){

CnpOnline cnp = new CnpOnline();
Sale sale = new Sale();
sale.setAmount(106L);
sale.setCnpTxnId(123456L);
sale.setOrderId("12344");
sale.setOrderSource(OrderSourceType.ECOMMERCE);
CardType card = new CardType();
card.setType(MethodOfPaymentTypeEnum.VI);
card.setNumber("4100000000000000");
card.setExpDate("1210");
sale.setCard(card);
sale.setId("id");
SaleResponse response = cnp.sale(sale);

System.out.println("Response:"+response.getResponse());
System.out.println("Message:"+response.getMessage());
System.out.println("Transaction ID:"+response.getCnpTxnId());
}
}

 

.NET example

 

using Cnp.Sdk;
using System;

namespace CNP_Examples
{
class Program
{
public static void SimpleSaleWithCard()
{
CnpOnline _cnp = new CnpOnline();
var saleObj = new sale
{
id = "1",
amount = 106,
cnpTxnId = 123456,
orderId = "12344",
orderSource = orderSourceType.ecommerce,
card = new cardType
{
type = methodOfPaymentTypeEnum.VI,
number = "4100000000000000",
expDate = "1210"
}
};
Console.WriteLine(saleObj.Serialize());
var responseObj = _cnp.Sale(saleObj);
}

static void Main(string[] args)
{
SimpleSaleWithCard();
Console.ReadLine();
}
}
}

 

Ruby example

 

require 'CnpOnline'
include CnpOnline

hash = {
'merchantId' => '101',
'id' => 'test',
'version'=>'8.8',
'reportGroup'=>'Planets',
'cnpTxnId'=>'123456',
'orderId'=>'12344',
'amount'=>'106',
'orderSource'=>'ecommerce',
'card'=>{
'type'=>'VI',
'number' =>'4100000000000002',
'expDate' =>'1210'
}}

response= CnpOnlineRequest.new.sale(hash)
puts response.message

 

Python Example

 

from vantivsdk import fields, online, utils

conf = utils.Configuration()

transaction = fields.sale()
transaction.reportGroup = 'Planets'
transaction.orderId = '12344'
transaction.amount = 106
transaction.orderSource = 'ecommerce'
transaction.id = 'ThisIsID'

card = fields.cardType()
card.number = '4100000000000000'
card.expDate = '1210'
card.type = 'VI'

transaction.card = card

response = online.request(transaction, conf)
2 people found this helpful

Attachments

    Outcomes