Google Payment Card Recognition API는 카메라를 사용하여 결제 카드의 정보를 인식하는 기능을 제공합니다. API는 광학 문자 인식(OCR)을 통해 신용카드나 체크카드의 기본 계좌 번호(PAN) 및 만료일 인식을 지원합니다. API는 카드 스캔 작업을 Google Play 서비스에 위임합니다. 따라서 앱이 카메라 권한을 요청할 필요가 없으며 스캔 결과만 수신합니다. 모든 이미지 처리는 기기에서 실행되며 Google은 결과를 저장하거나 이미지 데이터를 공유하지 않습니다.
최적의 사용자 경험과 기능을 보장하기 위해 API에 다음과 같은 제약 조건이 있습니다.
기기가 대한민국, 네덜란드, 노르웨이, 뉴질랜드, 덴마크, 러시아, 미국, 브라질, 스위스, 스웨덴, 스페인, 싱가포르, 아랍에미리트, 아일랜드, 영국, 오스트레일리아, 일본, 체코, 캐나다, 타이완, 폴란드, 프랑스, 핀란드, 홍콩에 있습니다.
기기에 RAM이 1GB 이상 있습니다.
기기에 후면 카메라가 있습니다.
기기가 PORTRAIT 방향을 지원합니다.
요청 만들기
Activity의 onCreate 메서드에 PaymentsClient 인스턴스를 만듭니다. PaymentsClient를 사용하여 Google Pay API와 상호작용할 수 있습니다.
응답을 만든 후에는 PendingIntent에 대한 비동기식 요청을 전송할 수 있습니다. 이 요청을 사용하여 결제 카드 인식 활동을 시작할 수 있습니다.
요청이 항상 성공하는 것은 아닙니다. API가 사용 설정되지 않으면 요청이 실패합니다. 요청에 대한 응답에 따라 앱의 동작을 조정하는 것이 좋습니다. 샘플 앱에서는 성공적인 응답을 받은 후에만 버튼이 표시됩니다.
Kotlin
privatefunpossiblyShowPaymentCardOcrButton(){// The request can be used to configure the type of the payment card recognition. Currently// the only supported type is card OCR, so it is sufficient to call the getDefaultInstance()// method.valrequest=PaymentCardRecognitionIntentRequest.getDefaultInstance()paymentsClient.getPaymentCardRecognitionIntent(request).addOnSuccessListener{intentResponse->
cardRecognitionPendingIntent=intentResponse.paymentCardRecognitionPendingIntentpaymentCardOcrButton.visibility=View.VISIBLE}.addOnFailureListener{e->
// The API is not available either because the feature is not enabled on the device// or because your app is not registered.Log.e(TAG,"Payment card ocr not available.",e)}}
publicvoidpossiblyShowPaymentCardOcrButton(){// The request can be used to configure the type of the payment card recognition. Currently the// only supported type is card OCR, so it is sufficient to call the getDefaultInstance() method.PaymentCardRecognitionIntentRequestrequest=PaymentCardRecognitionIntentRequest.getDefaultInstance();paymentsClient.getPaymentCardRecognitionIntent(request).addOnSuccessListener(intentResponse->{cardRecognitionPendingIntent=intentResponse.getPaymentCardRecognitionPendingIntent();paymentCardOcrButton.setVisibility(View.VISIBLE);}).addOnFailureListener(e->{// The API is not available either because the feature is not enabled on the device// or because your app is not registered.Log.e(TAG,"Payment card ocr not available.",e);});}
인식 프로세스 중에 Google 알고리즘이 결제 카드를 인식하려고 시도합니다. 결과가 인식되면 API가 결과를 PaymentCardRecognitionResult로 반환합니다. 결과에는 항상 카드 번호가 포함됩니다. 알고리즘이 만료일을 감지하지 못하거나 카드 만료일이 지난 것으로 날짜가 표시되면 만료일이 없을 수 있습니다. 여러 가지 이유로 카드를 인식하지 못할 수 있습니다. 이 문제는 대개 사용자가 흐름을 취소하고 API가 Activity.RESULT_CANCELLED를 반환하면 발생합니다.
[null,null,["최종 업데이트: 2024-10-16(UTC)"],[[["\u003cp\u003eThe Google Pay payment card recognition API enables apps to scan credit and debit cards using the device's camera to extract PAN and expiration date information through OCR.\u003c/p\u003e\n"],["\u003cp\u003eThe API delegates scanning to Google Play services, eliminating the need for camera permissions within your app and ensuring data privacy as images are processed on-device and not stored by Google.\u003c/p\u003e\n"],["\u003cp\u003eCertain device constraints, such as having a Google account, minimum RAM, a back-facing camera, latest Google Play services, and portrait orientation support, must be met for the API to function.\u003c/p\u003e\n"],["\u003cp\u003eTo use the API, you need to create a \u003ccode\u003ePaymentsClient\u003c/code\u003e instance, request a \u003ccode\u003ePendingIntent\u003c/code\u003e, and handle the \u003ccode\u003ePaymentCardRecognitionResult\u003c/code\u003e to retrieve card information while acknowledging potential inaccuracies and the need for card network verification.\u003c/p\u003e\n"]]],["The Google payment card recognition API uses a device's camera to scan credit/debit card data (PAN and expiration date) via OCR. It requires production access to the Google Pay API for Android. Key actions include: creating a `PaymentsClient` instance, requesting a `PendingIntent`, and initiating card recognition. The API returns a `PaymentCardRecognitionResult` with the card number and, if available, the expiration date. Device constraints include having a Google account, RAM of 1GB or more, a back facing camera, and the latest Google Play Services.\n"],null,["# Debit and credit card recognition\n\n| **Important:** The payment card recognition API requires production access to [Google Pay API\n| for Android](https://developers.google.com/pay/api/android/overview).\n\n\nThe Google payment card recognition API provides the ability to use a camera\nto recognize information from payment cards. The API supports\nrecognition of the primary account number (PAN) and the expiration date from a credit card or a debit card\nthrough optical character recognition (OCR). The API delegates the task of\nscanning the card to Google Play services. Therefore, your app doesn't need\nto request camera permission and only receives the scan results. All image\nprocessing occurs on the device and Google doesn't store the results or share the image data.\n\n\nTo ensure the optimal user experience and functionality, the API has the following constraints:\n\n- The device has a Google account logged in.\n- The device has at least 1 GB of RAM.\n- The device has a back facing camera.\n- The device has the latest Google Play services version.\n- The device supports `PORTRAIT` orientation.\n\n| **Note:** In scenarios where these constraints aren't met, Google Play services disables the API. Google Play services automatically handle the enablement and disablement of the API with Google Play.\n\nCreate a request\n----------------\n\n\nCreate a\n[PaymentsClient](/android/reference/com/google/android/gms/wallet/PaymentsClient)\ninstance in the `onCreate` method in your `Activity`. You can use\n`PaymentsClient` to interact with the Google Pay API. \n\n### Kotlin\n\n```kotlin\n fun createPaymentsClient(activity: Activity): PaymentsClient {\n val walletOptions = Wallet.WalletOptions.Builder()\n .setEnvironment(Constants.PAYMENTS_ENVIRONMENT)\n .build()\n\n return Wallet.getPaymentsClient(activity, walletOptions)\n }https://github.com/google-pay/android-quickstart/blob/bdb0fd8e8d09a2e4f08faa428e852f748a233a3a/kotlin/app/src/main/java/com/google/android/gms/samples/wallet/PaymentsUtil.kt\n```\n\n### Java\n\n```java\n public static PaymentsClient createPaymentsClient(Activity activity) {\n Wallet.WalletOptions walletOptions =\n new Wallet.WalletOptions.Builder().setEnvironment(Constants.PAYMENTS_ENVIRONMENT).build();\n return Wallet.getPaymentsClient(activity, walletOptions);\n }https://github.com/google-pay/android-quickstart/blob/bdb0fd8e8d09a2e4f08faa428e852f748a233a3a/java/app/src/main/java/com/google/android/gms/samples/wallet/util/PaymentsUtil.java\n```\n| **Note:** When using `WalletConstants.ENVIRONMENT_TEST`, the API always returns a stub result if it recognizes the card.\n\n\nAfter you create the response, you can then send an asynchronous request for a `PendingIntent`,\nwhich you can use to start the payment card recognition activity.\n\n\nKeep in mind that the request doesn't always succeed. If there is no API enablement, the request\nfails. We suggest that you adjust your app's behavior according to the\nresponse to the request. In the sample app, we display the button only after\nwe receive a successful response. \n\n### Kotlin\n\n```kotlin\n private fun possiblyShowPaymentCardOcrButton() {\n // The request can be used to configure the type of the payment card recognition. Currently\n // the only supported type is card OCR, so it is sufficient to call the getDefaultInstance()\n // method.\n val request = PaymentCardRecognitionIntentRequest.getDefaultInstance()\n paymentsClient\n .getPaymentCardRecognitionIntent(request)\n .addOnSuccessListener { intentResponse -\u003e\n cardRecognitionPendingIntent = intentResponse.paymentCardRecognitionPendingIntent\n paymentCardOcrButton.visibility = View.VISIBLE\n }\n .addOnFailureListener { e -\u003e\n // The API is not available either because the feature is not enabled on the device\n // or because your app is not registered.\n Log.e(TAG, \"Payment card ocr not available.\", e)\n }\n }https://github.com/google-pay/android-quickstart/blob/bdb0fd8e8d09a2e4f08faa428e852f748a233a3a/kotlin/app/src/main/java/com/google/android/gms/samples/wallet/CheckoutActivity.kt\n```\n\n### Java\n\n```java\n public void possiblyShowPaymentCardOcrButton() {\n // The request can be used to configure the type of the payment card recognition. Currently the\n // only supported type is card OCR, so it is sufficient to call the getDefaultInstance() method.\n PaymentCardRecognitionIntentRequest request =\n PaymentCardRecognitionIntentRequest.getDefaultInstance();\n paymentsClient\n .getPaymentCardRecognitionIntent(request)\n .addOnSuccessListener(intentResponse -\u003e {\n cardRecognitionPendingIntent = intentResponse.getPaymentCardRecognitionPendingIntent();\n paymentCardOcrButton.setVisibility(View.VISIBLE);\n })\n .addOnFailureListener(e -\u003e {\n // The API is not available either because the feature is not enabled on the device\n // or because your app is not registered.\n Log.e(TAG, \"Payment card ocr not available.\", e);\n });\n }https://github.com/google-pay/android-quickstart/blob/bdb0fd8e8d09a2e4f08faa428e852f748a233a3a/java/app/src/main/java/com/google/android/gms/samples/wallet/activity/CheckoutActivity.java\n```\n\n\nTo start the payment card recognition activity, use the following code sample: \n\n### Kotlin\n\n```kotlin\n private fun startPaymentCardOcr() {\n try {\n ActivityCompat.startIntentSenderForResult(\n this@CheckoutActivity,\n cardRecognitionPendingIntent.intentSender,\n PAYMENT_CARD_RECOGNITION_REQUEST_CODE,\n null, 0, 0, 0, null\n )\n } catch (e: SendIntentException) {\n throw RuntimeException(\"Failed to start payment card recognition.\", e)\n }\n }https://github.com/google-pay/android-quickstart/blob/bdb0fd8e8d09a2e4f08faa428e852f748a233a3a/kotlin/app/src/main/java/com/google/android/gms/samples/wallet/CheckoutActivity.kt\n```\n\n### Java\n\n```java\n public void startPaymentCardOcr(View view) {\n try {\n ActivityCompat.startIntentSenderForResult(\n CheckoutActivity.this, cardRecognitionPendingIntent.getIntentSender(),\n PAYMENT_CARD_RECOGNITION_REQUEST_CODE,\n null, 0, 0, 0, null);\n } catch (SendIntentException e) {\n throw new RuntimeException(\"Failed to start payment card recognition.\", e);\n }\n }https://github.com/google-pay/android-quickstart/blob/bdb0fd8e8d09a2e4f08faa428e852f748a233a3a/java/app/src/main/java/com/google/android/gms/samples/wallet/activity/CheckoutActivity.java\n```\n\nInterpret the result\n--------------------\n\n\nDuring the recognition process, our algorithm attempts to recognize the\npayment card. If it successfully recognizes a result, then the API returns the result as a\n[PaymentCardRecognitionResult](/android/reference/com/google/android/gms/wallet/PaymentCardRecognitionResult). The result always contains a card number. The expiration date might\nnot be present if the algorithm fails to detect one, or if the date\nshows that the card is past its expiration date. For various reasons, a card might not be\nrecognizable. This usually results when a user cancels a flow and the API\nreturns `Activity.RESULT_CANCELLED`.\n**Caution:** On rare occasions, the results might be incorrect. It's your responsibility to verify the card information through the corresponding card network. \n\n### Kotlin\n\n```kotlin\n private fun handlePaymentCardRecognitionSuccess(\n cardRecognitionResult: PaymentCardRecognitionResult\n ) {\n val creditCardExpirationDate = cardRecognitionResult.creditCardExpirationDate\n val expirationDate = creditCardExpirationDate?.let { \"%02d/%d\".format(it.month, it.year) }\n val cardResultText = \"PAN: ${cardRecognitionResult.pan}\\nExpiration date: $expirationDate\"\n Toast.makeText(this, cardResultText, Toast.LENGTH_LONG).show()\n }https://github.com/google-pay/android-quickstart/blob/bdb0fd8e8d09a2e4f08faa428e852f748a233a3a/kotlin/app/src/main/java/com/google/android/gms/samples/wallet/CheckoutActivity.kt\n```\n\n### Java\n\n```java\n private void handleCardRecognitionSuccess(PaymentCardRecognitionResult cardResult) {\n\n String expirationDate = null;\n Locale locale = Locale.getDefault();\n CreditCardExpirationDate cardExpirationDate = cardResult.getCreditCardExpirationDate();\n if(cardExpirationDate != null) {\n expirationDate = String.format(locale,\n \"%02d/%d\", cardExpirationDate.getMonth(), cardExpirationDate.getYear());\n }\n\n String cardResultString = String.format(locale,\n \"PAN: %s\\nExpiration date: %s\", cardResult.getPan(), expirationDate);\n Toast.makeText(this, cardResultString, Toast.LENGTH_LONG).show();\n }https://github.com/google-pay/android-quickstart/blob/bdb0fd8e8d09a2e4f08faa428e852f748a233a3a/java/app/src/main/java/com/google/android/gms/samples/wallet/activity/CheckoutActivity.java\n```"]]