Notice
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 영수증검증
- 테이블인덱스
- 데이터베이스확인
- MySQL
- 아파치
- meta
- 클릭이벤트막기
- 영수증확인
- SQL
- 영수증인증
- how to slim install
- 리눅스
- 데이터베이스 지정하기
- slim install
- 업로드
- Google Pay
- CSV
- php
- subscriptionsv2
- Google_Service_AndroidPublisher
- Google_Client
- google purchases
- closest
- google_purchases
- purchases_subscriptions
- Database
- 몇번째행
- purchases
- TABLE
Archives
- Today
- Total
Web_developer
google 영수증검증 REST v2 class 본문
반응형
영수증검증 v2가 나오면서 조금더 명확하게 값을 준다.
기존 서버를 수정
<?php
class google_inapp
{
private $package_name;
private $product_id;
private $purchase_token;
private $developerPayload;
private $client;
private $service;
public function __construct($package_name,$product_id,$purchase_token,$developerPayload = null)
{
if($purchase_token)
{
$this->package_name = $package_name;
$this->product_id = $product_id;
$this->purchase_token = $purchase_token;
$this->developerPayload = $developerPayload;
$this->client = new Google_Client();
$this->client->setAuthConfig(' Auth json 파일 절대 경로 ');
$this->client->addScope('https://www.googleapis.com/auth/androidpublisher');
$this->service = new Google_Service_AndroidPublisher($this->client);
}
}
public function revoke()
{
return $this->service->purchases_subscriptions->revoke($this->package_name, $this->product_id, $this->purchase_token);
}
public function pay_acknowledge($developerPayload)
{
$postBody = new Google_Service_AndroidPublisher_SubscriptionPurchasesAcknowledgeRequest();
$postBody->setDeveloperPayload($developerPayload);
$this->service->purchases_subscriptions->acknowledge(
$this->package_name,
$this->product_id,
$this->purchase_token,
$postBody
);
}
public function certification()
{
$get = $this->service->purchases_subscriptionsv2->get($this->package_name, $this->purchase_token);
if($get->acknowledgementState == "ACKNOWLEDGEMENT_STATE_PENDING")
{
$this->pay_acknowledge($this->developerPayload);
}
return $get;
}
}
?>
1. revoke = 환불
2. pay_ackowledge = 결제승인
3. certification = 영수증 확인
사용법은 다음과 같다
<?php
//클라이언트에서 받은 패키지명,상품id,결제토큰을 받은후 셋팅
$google = new google_inapp($package_name,$product_id,$purchase_token,$developerPayload);
// try,catch로 에러 코드 분기처리
try
{
//class를 이용하여 영수증 검증 시작
$google_res = $google->certification();
if(empty($google_res))
{
throw new Exception();
}
else
{
if($google_res->subscriptionState == "SUBSCRIPTION_STATE_ACTIVE" || $google_res->subscriptionState == "SUBSCRIPTION_STATE_CANCELED")
{
//영수증 검증후 response 받은 값으로 세팅
//SUBSCRIPTION_STATE_ACTIVE 결제유효
//SUBSCRIPTION_STATE_CANCELED 사용자가 취소했지만 만료기간이 남아있음
}
}
}
catch (Exception $e)
{
//실패
//에러코드 출력
$msg = $e->getMessage();
error_log($msg['error']['errors'][0]['reason']);
}
?>
시작일,만료일 (Y-m-d H:i:s) 형식으로 출력은 하단에 코드 처럼 변환해서 db에 datetime 형식으로 저장할수있다.
//시작일
date("Y-m-d H:i:s", strtotime($google_res->startTime))
//만료일
date("Y-m-d H:i:s", strtotime($google_res->lineItems[0]->expiryTime))
자세한 내용은 구글api 문서 참조
https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2
REST Resource: purchases.subscriptionsv2 | Google Play Developer API | Google Developers
REST Resource: purchases.subscriptionsv2 Resource: SubscriptionPurchaseV2 Indicates the status of a user's subscription purchase. JSON representation { "kind": string, "regionCode": string, "latestOrderId": string, "lineItems": [ { object (SubscriptionPurc
developers.google.com
'PHP' 카테고리의 다른 글
google 결제 영수증 확인 (0) | 2021.07.07 |
---|---|
slim V4 - framework 설치하기 (0) | 2020.02.15 |
csv파일 행열 추가하기 fputcsv (0) | 2019.11.07 |
php에서 csv파일 로컬에 저장하기 (0) | 2019.11.04 |
file_put_contents(저장될tmp경로/저장될파일명, 파일경로) (0) | 2019.11.04 |
Comments