Skip to content

Commit

Permalink
Merge pull request #58 from bernardarhia:charge-reponse-correction
Browse files Browse the repository at this point in the history
fix charge api response
  • Loading branch information
Bernard Arhia authored Dec 27, 2023
2 parents 2313315 + 8715975 commit e326e9b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-fans-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"paystackly": patch
---

fix charge api response
44 changes: 28 additions & 16 deletions src/charge/Charge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ export class Charges extends BaseCharges {
}
async chargeWithMobileMoney(
payload: ChargeWithMobileMoneyPayload
): Promise<BaseChargeResponse | TransactionResponse> {
): Promise<BaseChargeResponse> {
return await this.basePostChargeRequest<ChargeWithMobileMoneyPayload>(
this.endpoint,
payload
);
}
async chargeWithBank(
payload: ChargeWithBankPayload
): Promise<BaseChargeResponse | TransactionResponse> {
): Promise<BaseChargeResponse> {
return await this.basePostChargeRequest<ChargeWithBankPayload>(
this.endpoint,
payload
);
}
async chargeWithUssd(
payload: ChargeWithUSSDPayload
): Promise<BaseChargeResponse | TransactionResponse> {
): Promise<BaseChargeResponse> {
return await this.basePostChargeRequest<ChargeWithUSSDPayload>(
this.endpoint,
payload
);
}
async chargeWithCard(
payload: ChargeWithCardPayload
): Promise<BaseChargeResponse | TransactionResponse> {
): Promise<BaseChargeResponse> {
return await this.basePostChargeRequest<ChargeWithCardPayload>(
this.endpoint,
payload
Expand All @@ -55,41 +55,41 @@ export class Charges extends BaseCharges {

async submitPin(
payload: SubmitChargePinPayload
): Promise<BaseChargeResponse | TransactionResponse> {
return await this.basePostChargeRequest<SubmitChargePinPayload>(
): Promise<TransactionResponse> {
return await this.basePostChargeFinalizeRequest<SubmitChargePinPayload>(
`${this.endpoint}/submit_pin`,
payload
);
}

async submitOTP(
payload: SubmitChargeOTPPayload
): Promise<BaseChargeResponse | TransactionResponse> {
return await this.basePostChargeRequest<SubmitChargeOTPPayload>(
): Promise<TransactionResponse> {
return await this.basePostChargeFinalizeRequest<SubmitChargeOTPPayload>(
`${this.endpoint}/submit_otp`,
payload
);
}
async submitPhone(
payload: SubmitChargePhonePayload
): Promise<BaseChargeResponse | TransactionResponse> {
return await this.basePostChargeRequest<SubmitChargePhonePayload>(
): Promise<TransactionResponse> {
return await this.basePostChargeFinalizeRequest<SubmitChargePhonePayload>(
`${this.endpoint}/submit_phone`,
payload
);
}
async submitBirthday(
payload: SubmitChargeBirthdayPayload
): Promise<BaseChargeResponse | TransactionResponse> {
return await this.basePostChargeRequest<SubmitChargeBirthdayPayload>(
): Promise<TransactionResponse> {
return await this.basePostChargeFinalizeRequest<SubmitChargeBirthdayPayload>(
`${this.endpoint}/submit_birthday`,
payload
);
}
async submitAddress(
payload: SubmitChargeAddressPayload
): Promise<BaseChargeResponse | TransactionResponse> {
return await this.basePostChargeRequest<SubmitChargeAddressPayload>(
): Promise<TransactionResponse> {
return await this.basePostChargeFinalizeRequest<SubmitChargeAddressPayload>(
`${this.endpoint}/submit_address`,
payload
);
Expand All @@ -102,11 +102,23 @@ export class Charges extends BaseCharges {
async basePostChargeRequest<T>(
url: string,
payload: PayloadWithAmount<T>
): Promise<BaseChargeResponse | TransactionResponse> {
): Promise<BaseChargeResponse> {
if (payload && "amount" in payload) {
payload.amount = (payload?.amount as number) * 100;
}
return await Http.post<T, BaseChargeResponse | TransactionResponse>(
return await Http.post<T, BaseChargeResponse>(
url,
payload
);
}
async basePostChargeFinalizeRequest<T>(
url: string,
payload: PayloadWithAmount<T>
): Promise<TransactionResponse> {
if (payload && "amount" in payload) {
payload.amount = (payload?.amount as number) * 100;
}
return await Http.post<T, TransactionResponse>(
url,
payload
);
Expand Down

0 comments on commit e326e9b

Please sign in to comment.