Integrate Least Cost Routing
Last updated: Aug 15th, 5:54am
This page shows you how to integrate Least Cost Routing.
How it works
PayPal checks if the transaction is eligible for Least Cost Routing. For more information, see Eligibility.
- If the transaction is eligible, it will be routed to debit networks through the Pay Secure Processor.
- If the transaction is ineligible, the transaction will go through Visa or Mastercard through the First Data processor.
Note: There is no change in the checkout experience for buyers.
1. Tokenize your card
Make your card into a token. Tokenizing the card can happen with or without a billing address. The CVV field is also optional.
Query
1mutation TokenizeCreditCard($input: TokenizeCreditCardInput!) {2 tokenizeCreditCard(input: $input) {3 paymentMethod {4 id5 legacyId6 }7 }8 }
Variable
1{2 "input": {3 "creditCard": {4 "number": "5208233085365191",5 "expirationYear": "2024",6 "expirationMonth": "12",7 "cvv": "123",8 "billingAddress": {9 "firstName": "John",10 "lastName":"Smith",11 "streetAddress": "500 Main St",12 "region":"CA",13 "postalCode": "95131",14 "countryCodeAlpha2":"US"15 }16 }17 }18}
2. Create a transaction
Make a transaction with your tokenized card details.
Query
1mutation chargePaymentMethod($input: ChargePaymentMethodInput!) {2 chargePaymentMethod(input: $input) {3 transaction {4 id,5 status,6 debitNetwork7 }8 }9}
Variable
1{2 "input": {3 "paymentMethodId": "cGF5bWVudG1ldGhvZF9jY19uM3BxZzIz",4 "transaction": {5 "amount": "1.00"6 }7 }8}
Search for a transaction
Least Cost Routing transactions can be searched by transaction ID or by the Least Cost Routing network that the transaction passed through.
Query
1query Search($input: TransactionSearchInput!) {2 search {3 transactions(input: $input) {4 pageInfo {5 hasNextPage6 hasPreviousPage7 startCursor8 endCursor9 }10 edges {11 node {12 id13 createdAt14 paymentInitiatedAt15 status16 source17 debitNetwork18 amount {19 value20 currencyIsoCode21 currencyCode22 }23 merchantAccountId24 orderId25 customer {26 id27 }28 disbursementDetails {29 date30 amount {31 value32 currencyIsoCode33 currencyCode34 }35 exchangeRate36 fundsHeld37 }38 riskData {39 id40 decision41 deviceDataCaptured42 fraudServiceProvider43 }44 facilitatorDetails {45 oauthApplication {46 clientId47 name48 }49 }50 statusHistory {51 __typename52 status53 timestamp54 source55 terminal56 amount {57 value58 currencyIsoCode59 currencyCode60 }61 ... on AuthorizedEvent {62 processorResponse {63 legacyCode64 message65 cvvResponse66 avsPostalCodeResponse67 avsStreetAddressResponse68 authorizationId69 }70 networkResponse {71 code72 message73 }74 riskDecision75 }76 ... on GatewayRejectedEvent {77 gatewayRejectionReason78 processorResponse {79 cvvResponse80 avsPostalCodeResponse81 avsStreetAddressResponse82 authorizationId83 }84 networkResponse {85 code86 message87 }88 riskDecision89 }90 ... on ProcessorDeclinedEvent {91 declineType92 processorResponse {93 legacyCode94 message95 cvvResponse96 avsPostalCodeResponse97 avsStreetAddressResponse98 authorizationId99 }100 networkResponse {101 code102 message103 }104 }105 ... on FailedEvent {106 processorResponse {107 legacyCode108 message109 cvvResponse110 avsPostalCodeResponse111 avsStreetAddressResponse112 authorizationId113 }114 networkResponse {115 code116 message117 }118 riskDecision119 }120 ... on SettlementDeclinedEvent {121 processorResponse {122 legacyCode123 message124 }125 }126 ... on SettlementPendingEvent {127 processorResponse {128 legacyCode129 message130 }131 }132 }133 paymentMethodSnapshot {134 __typename135 ... on CreditCardDetails {136 brand137 brandCode138 last4139 expirationMonth140 expirationYear141 bin142 binData {143 prepaid144 healthcare145 debit146 durbinRegulated147 commercial148 payroll149 issuingBank150 countryOfIssuance151 productId152 }153 uniqueNumberIdentifier154 cardholderName155 }156 }157 customFields {158 name159 value160 }161 processorResponse {162 legacyCode163 message164 avsPostalCodeResponse165 avsStreetAddressResponse166 cvvResponse167 }168 }169 cursor170 }171 }172 }173 }
Variable
Searching by Transaction ID
1{2 "input": {3 "id": {4 "is": "dHJhbnNhY3Rpb25fbW5rZGFzMWc"5 }6 }7}
Searching by Network
1{2 "input": {3 "debitNetwork": {4 "is": "STAR"5 },6 "createdAt": {7 "greaterThanOrEqualTo": "2022-03-20T11:52:26+00:00",8 "lessThanOrEqualTo":"2022-03-30T11:52:26+00:00"9 }10 }11 }
Reversing a transaction
Reversal API can be called at any point after a transaction is made. Calling Reversal API within a 20-minute window on a transaction with the status "SUBMITTED_FOR_SETTLEMENT" will result in void. Calling Reversal API after a 20-minute window on a transaction with the status "SETTLED" or "SETTLING" will result in a refund.
Query
1mutation ($input: ReverseTransactionInput!) {2 reverseTransaction(input: $input) {3 reversal {4 __typename5 ... on Transaction {6 id7 legacyId8 createdAt9 paymentMethodSnapshot {10 __typename11 ... on CreditCardDetails {12 brandCode13 last414 bin15 expirationMonth16 expirationYear17 }18 ... on UsBankAccountDetails {19 accountType20 ownershipType21 bankName22 last423 routingNumber24 verified25 }26 ... on PayPalTransactionDetails {27 payer {28 billingAgreementId29 email30 payerId31 }32 }33 ... on VenmoAccountDetails {34 username35 venmoUserId36 }37 }38 amount {39 value40 currencyIsoCode41 }42 merchantAccountId43 orderId44 status45 statusHistory {46 __typename47 status48 timestamp49 amount {50 value51 currencyIsoCode52 }53 source54 terminal55 ... on AuthorizedEvent {56 processorResponse {57 legacyCode58 message59 cvvResponse60 avsPostalCodeResponse61 avsStreetAddressResponse62 authorizationId63 additionalInformation64 }65 networkResponse {66 code67 message68 }69 }70 ... on ProcessorDeclinedEvent {71 declineType72 processorResponse {73 legacyCode74 message75 cvvResponse76 avsPostalCodeResponse77 avsStreetAddressResponse78 authorizationId79 additionalInformation80 }81 networkResponse {82 code83 message84 }85 riskDecision86 }87 ... on SettlementPendingEvent {88 processorResponse {89 legacyCode90 message91 }92 }93 ... on SettledEvent {94 processorResponse {95 legacyCode96 message97 }98 }99 ... on SettlementDeclinedEvent {100 processorResponse {101 legacyCode102 message103 }104 }105 ... on FailedEvent {106 processorResponse {107 legacyCode108 message109 cvvResponse110 avsPostalCodeResponse111 avsStreetAddressResponse112 authorizationId113 additionalInformation114 }115 networkResponse {116 code117 message118 }119 riskDecision120 }121 ... on GatewayRejectedEvent {122 gatewayRejectionReason123 processorResponse {124 legacyCode125 message126 cvvResponse127 avsPostalCodeResponse128 avsStreetAddressResponse129 authorizationId130 additionalInformation131 }132 networkResponse {133 code134 message135 }136 riskDecision137 }138 }139 source140 paymentMethod {141 id142 }143 channel144 }145 ... on Refund {146 id147 legacyId148 createdAt149 paymentMethodSnapshot {150 __typename151 ... on CreditCardDetails {152 brandCode153 last4154 bin155 expirationMonth156 expirationYear157 }158 ... on UsBankAccountDetails {159 accountType160 ownershipType161 bankName162 last4163 routingNumber164 verified165 }166 ... on PayPalTransactionDetails {167 payer {168 billingAgreementId169 email170 payerId171 }172 }173 ... on VenmoAccountDetails {174 username175 venmoUserId176 }177 }178 amount {179 value180 currencyIsoCode181 }182 merchantAccountId183 orderId184 status185 statusHistory {186 __typename187 status188 timestamp189 amount {190 value191 currencyIsoCode192 }193 source194 terminal195 ... on AuthorizedEvent {196 processorResponse {197 legacyCode198 message199 cvvResponse200 avsPostalCodeResponse201 avsStreetAddressResponse202 authorizationId203 additionalInformation204 }205 networkResponse {206 code207 message208 }209 }210 ... on ProcessorDeclinedEvent {211 declineType212 processorResponse {213 legacyCode214 message215 cvvResponse216 avsPostalCodeResponse217 avsStreetAddressResponse218 authorizationId219 additionalInformation220 }221 networkResponse {222 code223 message224 }225 riskDecision226 }227 ... on SettlementPendingEvent {228 processorResponse {229 legacyCode230 message231 }232 }233 ... on SettledEvent {234 processorResponse {235 legacyCode236 message237 }238 }239 ... on SettlementDeclinedEvent {240 processorResponse {241 legacyCode242 message243 }244 }245 ... on FailedEvent {246 processorResponse {247 legacyCode248 message249 cvvResponse250 avsPostalCodeResponse251 avsStreetAddressResponse252 authorizationId253 additionalInformation254 }255 networkResponse {256 code257 message258 }259 riskDecision260 }261 ... on GatewayRejectedEvent {262 gatewayRejectionReason263 processorResponse {264 legacyCode265 message266 cvvResponse267 avsPostalCodeResponse268 avsStreetAddressResponse269 authorizationId270 additionalInformation271 }272 networkResponse {273 code274 message275 }276 riskDecision277 }278 }279 source280 paymentMethod {281 id282 }283 }284 }285 }286}
Variable
1{2 "input": {3 "transactionId": "dHJhbnNhY3Rpb25fMDJzY21wcW4"4 }5}
Test
The sandbox environment only accepts the below test credit card numbers to process Least Cost Routing transactions. While we use these test cards, the test biller account will need to be configured with the Least Cost Routing feature to get a debitNetwork=STAR on the API response. Transactions are routed to any one of the STAR, ACCEL, NYCE or PULSE debit networks based on the least cost routing. This depends on the transaction amount sent in the transaction sale request and the merchant category code of the merchant account.
5208233085365191(Master card) or 4070021557035923 (Visa)
When a transaction fails in the debit network, the transaction will be retried in the credit network such as Visa or Mastercard. The merchant account should have pinless retry debit enabled as the credit field and some retry configurations for the retry to happen.
If you want to retry a Least Cost Routing transaction in sandbox, the transaction amount will need to be set to 2046.
When the retry is successfully processed, the debitNetwork field will be null as the retry is not processed through the Least Cost Routing network.
1"transaction": {2 "id": "5p4z558e",3.4.5.67"retriedTransactionId": "79cv9vpc", // this shows the parent transaction that failed initially8 "retried": true,9 "debitNetwork": null10}
For a failed retry, the original transaction will show up with the original ID and all the retry IDs.
1"transaction": {2 "id": "79cv9vpc",3.4.5.6"retryIds": [7 "02scmpqn",8 "5p4z558e"9 ],10.11.1213 "retried": true,14}
Processing debit as credit
Optionally, we can send a transaction to be processed as credit to override the eligibility check and process the transaction through the Least Cost Routing network.
Query
1mutation chargePaymentMethod($input: ChargePaymentMethodInput!) {2 chargePaymentMethod(input: $input) {3 transaction {4 id,5 status,6 debitNetwork7 }8 }9}
Variable
1{2 "input": {3 "paymentMethodId": "tokencc_bf_qcfgdt_68ypv9_hhz6kx_jzwrtp_7my",4 "transaction": {5 "amount": "10.00",6 "merchantAccountId": "pgne15"7 },8 "options": {9 "processDebitAsCredit": false10 }11 }12}
Go live
To go live with the Least Cost Routing feature, contact your Technical Account Manager.